An open source design system that's fully customizable and agent ready
TypeScript
visual gate: verdict.json dates the baseline commit it names (#10499)
Cindy Zhangac8590a619b2
diff --git a/.github/scripts/visual-gate/lib/baseline.mjs b/.github/scripts/visual-gate/lib/baseline.mjsindex 717e735e7b..6ecc5bfdb6 100644--- a/.github/scripts/visual-gate/lib/baseline.mjs+++ b/.github/scripts/visual-gate/lib/baseline.mjs@@ -314,8 +314,8 @@ export function accept({manifest.platform = currentManifest.platform;manifest.browser = currentManifest.browser;manifest.viewport = currentManifest.viewport;- // The manifest's date is its oldest shot's, so it never claims that older- // pixels are newer than they are.+ // The manifest's date is its oldest shot's date. An undated shot counts at+ // the manifest's earlier date.manifest.capturedAt = oldestCapture(manifest.shots, earlierCapturedAt);manifest.context = currentManifest.context ?? null;manifest.decisions = [diff --git a/.github/scripts/visual-gate/lib/baseline.test.mjs b/.github/scripts/visual-gate/lib/baseline.test.mjsindex 3708a52486..7f32099c1d 100644--- a/.github/scripts/visual-gate/lib/baseline.test.mjs+++ b/.github/scripts/visual-gate/lib/baseline.test.mjs@@ -14,6 +14,7 @@ import {incomparable,readBaseline,} from './baseline.mjs';+import {buildVerdict} from './compare.mjs';describe('compact baseline manifest', () => {it('keeps comparison and ownership fields without generated story metadata', () => {@@ -249,6 +250,56 @@ describe('accept', () => {expect(manifest.capturedAt).toBe('2026-08-23T00:00:00.000Z');});+ it('names the date of the capture its commit came from, after an older capture is accepted on a newer one', () => {+ const read = () =>+ JSON.parse(+ fs.readFileSync(path.join(baselineDir, 'manifest.json'), 'utf8'),+ );+ const baselineOf = manifest =>+ buildVerdict({+ comparison: {changes: [], added: [], removed: [], unchanged: []},+ currentManifest: {shots: {}},+ baselineManifest: manifest,+ targeting: {},+ failures: [],+ context: {},+ }).baseline;+ promote({+ keys: ['a'],+ currentManifest: {+ ...currentManifest,+ capturedAt: '2026-11-06T00:00:00.000Z',+ context: {sha: 'newer', runId: '300'},+ },+ });+ promote({+ keys: ['b'],+ currentManifest: {+ ...currentManifest,+ capturedAt: '2026-10-20T00:00:00.000Z',+ context: {sha: 'older', runId: '200'},+ },+ });+ expect(baselineOf(read())).toMatchObject({+ sha: 'older',+ shaCapturedAt: '2026-10-20T00:00:00.000Z',+ });+ // An accept that only prunes names a capture no kept shot came from.+ promote({+ keys: [],+ prune: ['b'],+ reason: 'story deleted',+ currentManifest: {+ ...currentManifest,+ context: {sha: 'prune-capture', runId: '400'},+ },+ });+ expect(baselineOf(read())).toMatchObject({+ sha: 'prune-capture',+ shaCapturedAt: null,+ });+ });+it('dates an undated older shot by the manifest date it had', () => {fs.mkdirSync(path.join(baselineDir, 'shots'), {recursive: true});fs.writeFileSync(diff --git a/.github/scripts/visual-gate/lib/compare.mjs b/.github/scripts/visual-gate/lib/compare.mjsindex d8dd78ca0c..6164f864ec 100644--- a/.github/scripts/visual-gate/lib/compare.mjs+++ b/.github/scripts/visual-gate/lib/compare.mjs@@ -218,6 +218,26 @@ export function analyzeTargeting({observedTargets, targets, themeOverrides}) {};}+/**+ * The capture date of the run the manifest's context names: the date on the+ * shots that the last accept promoted from it. Null when no shot came from+ * that run, as after an accept that only pruned.+ * @param {{context?: {runId?: string | number}, shots?: Record<string, {capturedAt?: string, runId?: string | number}>}} manifest+ * @returns {string | null}+ */+function contextCapture(manifest) {+ const runId = manifest.context?.runId;+ if (runId === undefined || runId === null) return null;+ const shot = Object.values(manifest.shots ?? {}).find(+ candidate =>+ candidate.runId !== undefined &&+ candidate.runId !== null &&+ String(candidate.runId) === String(runId) &&+ typeof candidate.capturedAt === 'string',+ );+ return shot?.capturedAt ?? null;+}+/*** The verdict document. The release cron reads `status` and, when it is* `changed`, walks `changes` with the report open.@@ -264,7 +284,10 @@ export function buildVerdict({context,platform: currentManifest.platform,baseline: {+ // The oldest shot's date. `sha` names the commit of the capture that+ // the last accept read; `shaCapturedAt` is that capture's date.capturedAt: baselineManifest.capturedAt ?? null,+ shaCapturedAt: contextCapture(baselineManifest),sha: baselineManifest.context?.sha ?? null,platform: baselineManifest.platform ?? null,},diff --git a/.github/scripts/visual-gate/lib/compare.test.mjs b/.github/scripts/visual-gate/lib/compare.test.mjsindex 83bd5061f4..0d3357b77c 100644--- a/.github/scripts/visual-gate/lib/compare.test.mjs+++ b/.github/scripts/visual-gate/lib/compare.test.mjs@@ -383,6 +383,37 @@ describe('buildVerdict', () => {expect(verdict.status).toBe('failed');});+ it('dates the commit it names by that capture, not by the newest shot', () => {+ const shots = {+ a: {capturedAt: '2026-09-26T00:53:28.283Z', runId: '100'},+ // A newer capture accepted before the older one that `sha` names.+ b: {capturedAt: '2026-11-06T16:00:00.000Z', runId: '300'},+ c: {capturedAt: '2026-10-20T00:00:00.000Z', runId: '200'},+ d: {},+ };+ const baselineOf = context =>+ buildVerdict({+ ...base,+ baselineManifest: {+ capturedAt: '2026-09-26T00:53:28.283Z',+ context,+ platform: 'linux-arm64',+ shots,+ },+ comparison: {changes: [], added: [], removed: [], unchanged: ['a']},+ failures: [],+ }).baseline;+ expect(baselineOf({sha: 'later', runId: '200'})).toEqual({+ capturedAt: '2026-09-26T00:53:28.283Z',+ shaCapturedAt: '2026-10-20T00:00:00.000Z',+ sha: 'later',+ platform: 'linux-arm64',+ });+ // No shot came from the named run, or the manifest names no run.+ expect(baselineOf({sha: 'pruned', runId: '400'}).shaCapturedAt).toBeNull();+ expect(baselineOf({sha: 'old'}).shaCapturedAt).toBeNull();+ });+it('requires acceptance when stable shots are added or removed', () => {const verdict = buildVerdict({...base,