Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(visual-gate): accept dates each promoted shot, and the baseline's date is its oldest shot's (#10339)

Cindy Zhang83e0d4e88e5c
diff --git a/.github/scripts/visual-gate/lib/baseline.mjs b/.github/scripts/visual-gate/lib/baseline.mjs
index 0e2885279f..717e735e7b 100644
--- a/.github/scripts/visual-gate/lib/baseline.mjs
+++ b/.github/scripts/visual-gate/lib/baseline.mjs
@@ -116,6 +116,10 @@ const BASELINE_SHOT_FIELDS = [
// These two preserve ownership when a story or theme leaves the current build.
'packageName',
'themePackageName',
+ // When this shot's pixels were captured, and by which run. Shots are
+ // promoted at different times, so one manifest-wide date cannot say this.
+ 'capturedAt',
+ 'runId',
];
/** Keep the baseline index reviewable; all other shot facts are derived per run. */
@@ -182,6 +186,25 @@ export function incomparable(baselineManifest, currentManifest) {
return null;
}
+/**
+ * The earliest capture date among the shots; a shot without one counts as
+ * `fallback`.
+ * @param {Record<string, {capturedAt?: string}>} shots
+ * @param {string | undefined} fallback
+ * @returns {string | undefined}
+ */
+function oldestCapture(shots, fallback) {
+ const dates = Object.values(shots)
+ .map(shot => shot.capturedAt ?? fallback)
+ .filter(
+ date => typeof date === 'string' && !Number.isNaN(Date.parse(date)),
+ );
+ if (dates.length === 0) return fallback;
+ return dates.reduce((oldest, date) =>
+ Date.parse(date) < Date.parse(oldest) ? date : oldest,
+ );
+}
+
/**
* Promote captured shots into the baseline. Nothing is written unless the
* capture's verdict is one the gate stood behind (see assertPromotableVerdict).
@@ -260,12 +283,20 @@ export function accept({
const shotsDir = path.join(baselineDir, 'shots');
fs.mkdirSync(shotsDir, {recursive: true});
+ // A shot from before per-shot dates carries the manifest's earlier date.
+ const earlierCapturedAt = manifest.capturedAt;
+ // The run that captured the pixels, not the run that accepts them.
+ const captureRunId = currentManifest.context?.runId ?? null;
const promoted = [];
for (const key of keys) {
const source = path.join(captureDir, 'shots', `${key}.png`);
if (!fs.existsSync(source)) continue;
fs.copyFileSync(source, path.join(shotsDir, `${key}.png`));
- manifest.shots[key] = currentManifest.shots[key];
+ manifest.shots[key] = {
+ ...currentManifest.shots[key],
+ capturedAt: currentManifest.capturedAt,
+ ...(captureRunId ? {runId: String(captureRunId)} : {}),
+ };
promoted.push(key);
}
@@ -283,7 +314,9 @@ export function accept({
manifest.platform = currentManifest.platform;
manifest.browser = currentManifest.browser;
manifest.viewport = currentManifest.viewport;
- manifest.capturedAt = currentManifest.capturedAt;
+ // The manifest's date is its oldest shot's, so it never claims that older
+ // pixels are newer than they are.
+ manifest.capturedAt = oldestCapture(manifest.shots, earlierCapturedAt);
manifest.context = currentManifest.context ?? null;
manifest.decisions = [
...(manifest.decisions ?? []),
diff --git a/.github/scripts/visual-gate/lib/baseline.test.mjs b/.github/scripts/visual-gate/lib/baseline.test.mjs
index 85d712ef24..3708a52486 100644
--- a/.github/scripts/visual-gate/lib/baseline.test.mjs
+++ b/.github/scripts/visual-gate/lib/baseline.test.mjs
@@ -39,6 +39,8 @@ describe('compact baseline manifest', () => {
membershipSource: 'current-story',
width: 1024,
height: 768,
+ capturedAt: '2026-11-06T00:00:00.000Z',
+ runId: '42',
},
},
});
@@ -49,6 +51,8 @@ describe('compact baseline manifest', () => {
mode: 'light',
packageName: '@astryxdesign/core',
themePackageName: '@astryxdesign/theme-neutral',
+ capturedAt: '2026-11-06T00:00:00.000Z',
+ runId: '42',
});
expect(JSON.stringify(compact)).not.toContain('Core/Button');
});
@@ -207,6 +211,74 @@ describe('accept', () => {
expect(readBaseline(baselineDir).manifest.decisions).toHaveLength(2);
});
+ it('dates each promoted shot by its capture and capture run, and dates the manifest by its oldest shot', () => {
+ // The first accept dates the whole manifest by its only capture.
+ promote({
+ keys: ['a', 'b'],
+ runId: 'accepting-job',
+ currentManifest: {...currentManifest, context: {runId: '100'}},
+ });
+ let manifest = JSON.parse(
+ fs.readFileSync(path.join(baselineDir, 'manifest.json'), 'utf8'),
+ );
+ expect(manifest.shots.a).toMatchObject({
+ capturedAt: '2026-08-23T00:00:00.000Z',
+ runId: '100',
+ });
+ expect(manifest.capturedAt).toBe('2026-08-23T00:00:00.000Z');
+ // A later accept of one shot dates that shot, not the manifest.
+ promote({
+ keys: ['b'],
+ currentManifest: {
+ ...currentManifest,
+ capturedAt: '2026-11-06T00:00:00.000Z',
+ context: {runId: '200'},
+ },
+ });
+ manifest = JSON.parse(
+ fs.readFileSync(path.join(baselineDir, 'manifest.json'), 'utf8'),
+ );
+ expect(manifest.shots.a).toMatchObject({
+ capturedAt: '2026-08-23T00:00:00.000Z',
+ runId: '100',
+ });
+ expect(manifest.shots.b).toMatchObject({
+ capturedAt: '2026-11-06T00:00:00.000Z',
+ runId: '200',
+ });
+ expect(manifest.capturedAt).toBe('2026-08-23T00:00:00.000Z');
+ });
+
+ it('dates an undated older shot by the manifest date it had', () => {
+ fs.mkdirSync(path.join(baselineDir, 'shots'), {recursive: true});
+ fs.writeFileSync(
+ path.join(baselineDir, 'manifest.json'),
+ JSON.stringify({
+ version: 1,
+ shots: {b: {sha256: 'old-b'}},
+ decisions: [],
+ platform: 'linux-arm64',
+ viewport: {width: 1024, height: 768},
+ capturedAt: '2026-09-30T00:00:00.000Z',
+ }),
+ );
+ promote({
+ keys: ['a'],
+ currentManifest: {
+ ...currentManifest,
+ capturedAt: '2026-11-06T00:00:00.000Z',
+ },
+ });
+ const manifest = JSON.parse(
+ fs.readFileSync(path.join(baselineDir, 'manifest.json'), 'utf8'),
+ );
+ expect(manifest.shots.b.capturedAt).toBeUndefined();
+ expect(manifest.shots.a.capturedAt).toBe('2026-11-06T00:00:00.000Z');
+ // A capture that names no run records none; the accepting run is not it.
+ expect(manifest.shots.a.runId).toBeUndefined();
+ expect(manifest.capturedAt).toBe('2026-09-30T00:00:00.000Z');
+ });
+
it('drops pruned shots from both the manifest and disk', () => {
promote({keys: ['a', 'b']});
promote({keys: [], prune: ['b'], reason: 'story deleted'});