Repository navigation
fix(webgl): stop the weighted draw from sampling software renderers #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shauneccles
wants to merge
1
commit into
apify:master
Choose a base branch
from
shauneccles:fix/software-renderer-sampling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { getPossiblePairs, sampleWebGL } from "../src/webgl/sample"; | ||
|
|
||
| // Software rasterizers are legitimate dataset rows (the db is built from real | ||
| // user submissions) but must never win the weighted draw: pages can read the | ||
| // renderer string and a GPU-less software renderer is one of the strongest | ||
| // "this is a bot" signals there is. daijro/camoufox#743 applied the same rule | ||
| // to the python generator; #276 documents the dataset contamination. | ||
|
|
||
| const SOFTWARE_RENDERER_PATTERNS = [ | ||
| /llvmpipe/i, | ||
| /SwiftShader/i, | ||
| /Basic Render/i, | ||
| /Generic Renderer/i, | ||
| ]; | ||
|
|
||
| function isSoftwareRenderer(renderer: unknown): boolean { | ||
| return typeof renderer === "string" && SOFTWARE_RENDERER_PATTERNS.some((p) => p.test(renderer)); | ||
| } | ||
|
|
||
| // The sampled blob is the camoufox config fragment: the renderer strings live | ||
| // under the spoofing keys, not top-level. | ||
| function fingerprintRenderer(fp: { renderer?: unknown; "webGl:renderer"?: unknown }): string { | ||
| return typeof fp["webGl:renderer"] === "string" ? fp["webGl:renderer"] : String(fp.renderer); | ||
| } | ||
|
|
||
| describe("sampleWebGL weighted draw", () => { | ||
| test("never samples a software rasterizer", async () => { | ||
| const seen = new Set<string>(); | ||
| for (let i = 0; i < 500; i++) { | ||
| const fp = await sampleWebGL("lin"); | ||
| const renderer = fingerprintRenderer(fp); | ||
| expect(isSoftwareRenderer(renderer)).toBe(false); | ||
| seen.add(renderer); | ||
| } | ||
| // The filtered draw still covers the real hardware devices, it has not | ||
| // collapsed onto a single row. | ||
| expect(seen.size).toBeGreaterThan(2); | ||
| }, 60_000); | ||
|
|
||
| for (const os of ["win", "mac", "lin"] as const) { | ||
| test(`no software renderer wins the draw on ${os}`, async () => { | ||
| for (let i = 0; i < 300; i++) { | ||
| const fp = await sampleWebGL(os); | ||
| expect(isSoftwareRenderer(fingerprintRenderer(fp))).toBe(false); | ||
| } | ||
| }, 60_000); | ||
| } | ||
|
|
||
| test("explicit pairs still resolve, including software rows", async () => { | ||
| const pairs = await getPossiblePairs(); | ||
| const softwarePair = pairs.lin?.find((p) => isSoftwareRenderer(p.renderer)); | ||
| // The shipped dataset does contain llvmpipe rows for linux. | ||
| expect(softwarePair).toBeDefined(); | ||
| const fp = await sampleWebGL("lin", softwarePair!.vendor, softwarePair!.renderer); | ||
| expect(fingerprintRenderer(fp)).toBe(softwarePair!.renderer); | ||
| }, 30_000); | ||
|
|
||
| test("unknown explicit pairs still report the full (unfiltered) pair list", async () => { | ||
| const pairs = await getPossiblePairs(); | ||
| expect(Array.isArray(pairs.lin)).toBe(true); | ||
| expect(pairs.lin!.length).toBeGreaterThanOrEqual(11); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test never supplies an unknown explicit pair to
sampleWebGL; it only calls the independentgetPossiblePairs()API. Consequently, it would remain green if the error path’sSELECT DISTINCTquery were filtered or its reported pair list were otherwise broken, so the behavior named by the test is not actually protected. InvokesampleWebGLwith a nonexistent pair and assert that the rejected error contains a known software-renderer pair.Useful? React with 👍 / 👎.