- Notifications
You must be signed in to change notification settings - Fork 0
ci: report visual baseline drift without failing advisory checks#1791
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4e2d26e
ci: keep visual baseline drift advisory
BigSimmo cad1681
Merge branch 'main' into codex/visual-baseline-advisory-pr
BigSimmo 6bc5771
fix(ci): classify visual drift and harden formulation Clear→Draft
cursoragent ba78101
docs: record PR #1791 babysit unblock in review ledger
cursoragent 802c238
Merge branch 'main' into codex/visual-baseline-advisory-pr
cursoragent 4ad2014
Merge origin/main (incl. #1798) into codex/visual-baseline-advisory-pr
cursoragent cbb74f0
Merge origin/main after #1797 into codex/visual-baseline-advisory-pr
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -662,17 +662,19 @@ jobs: | ||
| # - Pixel comparison needs a soak before it can block a merge; this repo has | ||
| # already paid for a sub-pixel rounding flake (the min-h-11 -> min-h-12 change). | ||
| # Promote to a required check by adding it to `pr-required` once the baselines have | ||
| # held across a few runs, and drop `continue-on-error` at the same time. | ||
| # held across a few runs, and drop the pixel-step soft-fail / drift classifier then. | ||
| visual-baseline: | ||
| name: Visual baselines (advisory) | ||
| needs: changes | ||
| # Deliberately NOT on pull_request or merge_group. Owner decision, 2026-08-09: | ||
| # a pixel gate that reports on every UI pull request taxes exactly the work it | ||
| # exists to support. During a redesign the honest result is red on every push, | ||
| # and the baselines cannot be refreshed until a run has produced the new | ||
| # images, so that red is unavoidable rather than actionable. It never blocked | ||
| # a merge (`continue-on-error`, and absent from `pr-required`), but a red check | ||
| # nobody can act on mid-iteration is friction whether or not it gates. | ||
| # images, so that red is unavoidable rather than actionable. Pixel drift is | ||
| # soft-failed at the comparison step (and classified) rather than with a | ||
| # job-level continue-on-error that would also hide setup failures; the job | ||
| # remains absent from `pr-required`. A red check nobody can act on | ||
| # mid-iteration is friction whether or not it gates. | ||
| # `merge_group` is excluded for the same reason: queue runs are still | ||
| # pre-merge UI churn, not a post-land refresh point. | ||
| # | ||
| @@ -687,7 +689,8 @@ jobs: | ||
| if: > | ||
| needs.changes.outputs.ui_changed == 'true' && | ||
| contains(fromJSON('["push","schedule","workflow_dispatch"]'), github.event_name) | ||
| continue-on-error: true | ||
| # Deliberately NOT continue-on-error at the job: setup / artifact / non-drift | ||
| # failures must stay red. Only the pixel-comparison step soft-fails below. | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 45 | ||
| steps: | ||
| @@ -700,8 +703,29 @@ jobs: | ||
| uses: ./.github/actions/setup-ui-e2e | ||
| - name: Chromium visual baselines | ||
| id: visual-comparison | ||
| # Pixel drift is evidence, not an execution failure. Keeping this at the | ||
| # step (rather than only the job) prevents GitHub from publishing a red | ||
| # check for the expected stale-golden case demonstrated by PR #1743. | ||
| continue-on-error: true | ||
| run: npm run test:e2e:visual | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| - name: Report visual differences | ||
| if: steps.visual-comparison.outcome == 'failure' | ||
| run: | | ||
| if ! node scripts/classify-visual-baseline-outcome.mjs; then | ||
| echo "::error title=Visual baseline non-drift failure::Visual comparison failed for a reason other than pixel drift (missing baseline, setup/runtime, or assertion). See the visual-baseline-${{ github.run_id }} artifact." | ||
| exit 1 | ||
| fi | ||
| echo "::warning title=Visual baseline drift::Chromium pixels differ from the committed Linux baseline. Review the visual-baseline-${{ github.run_id }} artifact; this advisory comparison does not block merging." | ||
| { | ||
| echo "### Visual baseline drift detected" | ||
| echo | ||
| echo "The Chromium comparison found changed pixels. This is advisory: required interaction, accessibility, and style-contract checks remain separate." | ||
| echo | ||
| echo "Download \`visual-baseline-${{ github.run_id }}\` and review the expected, actual, and diff images before refreshing the Linux baseline." | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
| # The actual/diff/expected PNGs live here. On a first run these are the images | ||
| # to commit as the baseline; on a later run they are the evidence of what moved. | ||
| - name: Upload visual diffs | ||
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
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,154 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Decide whether a failed `test:e2e:visual` run was pixel drift (advisory) or an | ||
| * infrastructure / non-comparison failure that must stay red. | ||
| * | ||
| * Exit 0 → advisory drift only (or no failures found in an existing report). | ||
| * Exit 1 → missing report, missing baselines, runtime/assertion failures, or mixed. | ||
| */ | ||
| import { existsSync, readFileSync, readdirSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
| const DEFAULT_JUNIT = "test-results/playwright-junit.xml"; | ||
| const DEFAULT_RESULTS = "test-results/playwright-results.json"; | ||
| const decode = (value) => | ||
| value | ||
| .replaceAll(""", '"') | ||
| .replaceAll("'", "'") | ||
| .replaceAll("<", "<") | ||
| .replaceAll(">", ">") | ||
| .replaceAll("&", "&"); | ||
| const attribute = (attributes, name) => { | ||
| const match = attributes.match(new RegExp(`\\b${name}="([^"]*)"`)); | ||
| return match ? decode(match[1]) : ""; | ||
| }; | ||
| /** Failure/error bodies from a Playwright JUnit report. */ | ||
| export function failureBodiesFromJunit(xml) { | ||
| return [...xml.matchAll(/<testcase\b([^>]*)>([\s\S]*?)<\/testcase>/g)].flatMap((match) => { | ||
| const title = attribute(match[1], "name"); | ||
| const classname = attribute(match[1], "classname"); | ||
| return [...match[2].matchAll(/<(?:failure|error)\b([^>]*)>([\s\S]*?)<\/(?:failure|error)>/g)].map((failure) => ({ | ||
| title, | ||
| classname, | ||
| message: attribute(failure[1], "message"), | ||
| body: decode(failure[2]).trim(), | ||
| })); | ||
| }); | ||
| } | ||
| function collectErrorMessages(node, out = []) { | ||
| if (!node || typeof node !== "object") return out; | ||
| if (Array.isArray(node)) { | ||
| for (const item of node) collectErrorMessages(item, out); | ||
| return out; | ||
| } | ||
| if (node.error?.message) out.push(String(node.error.message)); | ||
| if (Array.isArray(node.errors)) { | ||
| for (const error of node.errors) { | ||
| if (error?.message) out.push(String(error.message)); | ||
| } | ||
| } | ||
| for (const value of Object.values(node)) collectErrorMessages(value, out); | ||
| return out; | ||
| } | ||
| export function failureMessagesFromResults(resultsJson) { | ||
| return collectErrorMessages(resultsJson); | ||
| } | ||
| /** Pixel-drift only: toHaveScreenshot mismatch with an existing baseline. */ | ||
| export function isPixelDriftFailure(text) { | ||
| const haystack = String(text ?? ""); | ||
| if (!haystack) return false; | ||
| if (/snapshot doesn't exist/i.test(haystack)) return false; | ||
| if (/AWAITING_BASELINE/i.test(haystack)) return false; | ||
| return /toHaveScreenshot/i.test(haystack) || /Screenshot comparison failed/i.test(haystack); | ||
| } | ||
| function listDiffPngs(root = "test-results") { | ||
| if (!existsSync(root)) return []; | ||
| const found = []; | ||
| const walk = (dir) => { | ||
| for (const entry of readdirSync(dir, { withFileTypes: true })) { | ||
| const full = join(dir, entry.name); | ||
| if (entry.isDirectory()) walk(full); | ||
| else if (entry.isFile() && /-diff\.png$/i.test(entry.name)) found.push(full); | ||
| } | ||
| }; | ||
| walk(root); | ||
| return found; | ||
| } | ||
| export function classifyVisualBaselineOutcome({ | ||
| junitPath = DEFAULT_JUNIT, | ||
| resultsPath = DEFAULT_RESULTS, | ||
| testResultsDir = "test-results", | ||
| } = {}) { | ||
| const hasJunit = existsSync(junitPath); | ||
| const hasResults = existsSync(resultsPath); | ||
| if (!hasJunit && !hasResults) { | ||
| return { | ||
| kind: "infrastructure", | ||
| reason: "No Playwright JUnit or JSON report after visual comparison failure.", | ||
| }; | ||
| } | ||
| const messages = []; | ||
| if (hasJunit) { | ||
| for (const failure of failureBodiesFromJunit(readFileSync(junitPath, "utf8"))) { | ||
| messages.push([failure.message, failure.body, failure.title].filter(Boolean).join("\n")); | ||
| } | ||
| } | ||
| if (hasResults) { | ||
| messages.push(...failureMessagesFromResults(JSON.parse(readFileSync(resultsPath, "utf8")))); | ||
| } | ||
| const unique = [...new Set(messages.map((message) => message.trim()).filter(Boolean))]; | ||
| if (unique.length === 0) { | ||
| const diffs = listDiffPngs(testResultsDir); | ||
| if (diffs.length > 0) { | ||
| return { | ||
| kind: "pixel-drift", | ||
| reason: `Found ${diffs.length} screenshot diff artifact(s) without parsed failure text.`, | ||
| }; | ||
| } | ||
| return { | ||
| kind: "infrastructure", | ||
| reason: "Visual comparison failed but the report contains no failed testcases.", | ||
| }; | ||
| } | ||
| const nonDrift = unique.filter((message) => !isPixelDriftFailure(message)); | ||
| if (nonDrift.length > 0) { | ||
| return { | ||
| kind: "non-drift", | ||
| reason: `Non-comparison failure(s) present (${nonDrift.length}/${unique.length}).`, | ||
| samples: nonDrift.slice(0, 3), | ||
| }; | ||
| } | ||
| return { | ||
| kind: "pixel-drift", | ||
| reason: `All ${unique.length} failure(s) are toHaveScreenshot pixel mismatches.`, | ||
| }; | ||
| } | ||
| function main() { | ||
| const outcome = classifyVisualBaselineOutcome(); | ||
| if (outcome.kind === "pixel-drift") { | ||
| console.log(`Visual baseline outcome: pixel-drift — ${outcome.reason}`); | ||
| process.exitCode = 0; | ||
| return; | ||
| } | ||
| console.error(`Visual baseline outcome: ${outcome.kind} — ${outcome.reason}`); | ||
| for (const sample of outcome.samples ?? []) { | ||
| console.error(`- ${sample.split("\n")[0].slice(0, 200)}`); | ||
| } | ||
| process.exitCode = 1; | ||
| } | ||
| if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main(); |
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.