Skip to content

Commit bf6316e

Browse files
authored
ci: the pull-request comment marks a changed visual shot as inherited from main when a merged pull request in this head showed the same image (#11672)
* ci: the pull-request comment marks a changed visual shot another pull request also showed as inherited * ci: a failed inheritance lookup says so in the step summary and the pull-request comment * ci: a changed shot is inherited from main only when a merged pull request in the tested base showed the same image; otherwise it says it was not found * test: keep the unrelated test lines as they were * ci: an unproven same-image match says so, apart from a shot no report shows * ci: a broken report archive is no data, a run with no changed shot reads no manifest, and N counts only the reports read * Merge remote-tracking branch 'origin/main' into ci/visual-inherited-shots * ci: an inherited shot needs the witness's merge commit in this head, which the run renders The visual run renders a Storybook built at the head against the head's own baseline, so a pull request merged after this head forked is not in the rendered tree. markInherited now proves the witness against the head, not the recorded base, and no longer needs a base. The file header is shorter. * ci: the comment step and the call budget name this head, not the tested base
1 parent f8e350a commit bf6316e

6 files changed

Lines changed: 783 additions & 2 deletions

File tree

‎.github/scripts/lib/pr-preview.test.mjs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,30 @@ describe('trusted PR preview identity', () => {
574574
});
575575
});
576576

577+
describe('the comment job marks inherited visual changes', () => {
578+
it('runs the marker between the trusted report and the comment, as report text only', () => {
579+
const steps = PR_COMMENT_WORKFLOW.jobs.comment.steps;
580+
const at = name => steps.findIndex(step => step.name === name);
581+
const mark = steps[at('Mark inherited visual changes')];
582+
expect(mark).toBeDefined();
583+
expect(at('Prepare canonical visual report')).toBeLessThan(
584+
at('Mark inherited visual changes'),
585+
);
586+
expect(at('Mark inherited visual changes')).toBeLessThan(
587+
at('Generate and post PR comment'),
588+
);
589+
// A failure leaves the report as it was; it never fails the comment.
590+
expect(mark['continue-on-error']).toBe(true);
591+
expect(mark.if).toBe(
592+
"steps.identity.outputs.valid == 'true' && steps.visual.outcome == 'success'",
593+
);
594+
expect(mark.run).toContain('--verdict trusted-visual/verdict.json');
595+
expect(mark.run).toContain('--manifest visual-pr-report/manifest.json');
596+
expect(mark.run).toContain('--head-sha "$HEAD_SHA"');
597+
expect(PR_COMMENT_WORKFLOW.jobs.comment.permissions.actions).toBe('read');
598+
});
599+
});
600+
577601
describe('PR Comment keeps its outcome off main', () => {
578602
// workflow_run attaches these jobs to main's latest commit, so a failing step
579603
// here would turn main red for a pull request's problem.

‎.github/scripts/lib/pr-status.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,15 @@ function buildVisualDeltas({verdict, frames = null}) {
364364
.filter(Boolean)
365365
.map(inline)
366366
.join(', ');
367-
return variant ? `${story} (${variant})` : story;
367+
const shown = variant ? `${story} (${variant})` : story;
368+
// inherited-shots.mjs proves a change came from main, or says the
369+
// reports it read do not show it: unknown, never "made here".
370+
if (row.inherited?.from === 'main') return `${shown} · inherited from main`;
371+
if (row.inherited?.found === true)
372+
return `${shown} · same image also changed on another pull request, not proven from main`;
373+
if (row.inherited?.found === false)
374+
return `${shown} · inheritance unknown: not found in the ${num(verdict?.inheritedChecked)} newest reports of other pull requests`;
375+
return shown;
368376
};
369377
const published = new Set(frames?.published || []);
370378
const base =
@@ -395,7 +403,7 @@ function buildVisualDeltas({verdict, frames = null}) {
395403
.toLowerCase()
396404
.replace(/[^a-z0-9]/g, '');
397405
const components = new Set(all.map(componentOf));
398-
return `<details>\n<summary>Visual changes: ${num(all.length)} snapshot${all.length === 1 ? '' : 's'} in ${components.size} component${components.size === 1 ? '' : 's'}</summary>\n\nA change is a question for the reviewer, not a failure.\n\n${header}${rows.map(line).join('\n')}\n\n${unshown > 0 ? `${num(unshown)} more are in the run's visual report.\n\n` : ''}</details>\n\n`;
406+
return `<details>\n<summary>Visual changes: ${num(all.length)} snapshot${all.length === 1 ? '' : 's'} in ${components.size} component${components.size === 1 ? '' : 's'}</summary>\n\nA change is a question for the reviewer, not a failure.\n\n${header}${rows.map(line).join('\n')}\n\n${unshown > 0 ? `${num(unshown)} more are in the run's visual report.\n\n` : ''}${verdict?.inheritedLookupFailed ? `Inheritance lookup failed: ${inline(String(verdict.inheritedLookupFailed).slice(0, 200))}.\n\n` : ''}${verdict?.inheritedChecked != null && !verdict?.inheritedLookupFailed ? `Inheritance checked against the ${num(verdict.inheritedChecked)} newest reports of other pull requests.\n\n` : ''}</details>\n\n`;
399407
}
400408

401409
function previewLine(preview) {

‎.github/scripts/lib/pr-status.test.mjs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,45 @@ describe('buildVisualDeltas', () => {
301301
diffPixels,
302302
});
303303

304+
it('marks a change that came from main as inherited, keeps an unproven match apart from one not found, and counts the reports read', () => {
305+
const verdict = {
306+
status: 'changed',
307+
changes: [
308+
{...change('a', 30), inherited: {from: 'main'}},
309+
{...change('b', 20), inherited: {found: false}},
310+
{...change('d', 15), inherited: {found: true}},
311+
change('c', 10),
312+
],
313+
inheritedChecked: 11,
314+
};
315+
const section = buildVisualDeltas({verdict});
316+
expect(section).toContain(
317+
'| Card · a (neutral, light) · inherited from main |',
318+
);
319+
expect(section).toContain(
320+
'| Card · b (neutral, light) · inheritance unknown: not found in the 11 newest reports of other pull requests |',
321+
);
322+
expect(section).toContain(
323+
'| Card · d (neutral, light) · same image also changed on another pull request, not proven from main |',
324+
);
325+
expect(section).toContain('| Card · c (neutral, light) | changed');
326+
expect(section).toContain(
327+
'Inheritance checked against the 11 newest reports of other pull requests.',
328+
);
329+
expect(section).not.toMatch(/introduc/);
330+
});
331+
332+
it('says when the inheritance lookup failed, so a broken lookup is never silent', () => {
333+
const section = buildVisualDeltas({
334+
verdict: {
335+
status: 'changed',
336+
changes: [change('a', 30)],
337+
inheritedLookupFailed: 'HTTP 403',
338+
},
339+
});
340+
expect(section).toContain('Inheritance lookup failed: HTTP 403.');
341+
});
342+
304343
it('collapses the changed shots under their count, largest change first', () => {
305344
const verdict = {
306345
status: 'changed',

0 commit comments

Comments
 (0)