Skip to content

Commit fb8e440

Browse files
committed
test: each --repeat-each copy of an audit keeps its own evidence folder
Each component audit's beforeAll deleted its evidence folder, and its last case counted the receipts its cases wrote there. Copies of a file run by --repeat-each share that folder and can run at once in other workers, so a copy that started while another was finishing deleted the other's receipts before its count: "manifest is complete" failed under pressure though each copy passes (seen in ComplexSelector's and DropdownMenuItem's audits). One helper in the audit harness, resetAuditEvidence (exported as @astryxdesign/a11y-spec/evidence), empties and creates this copy's folder: the first copy keeps the folder CI uploads and audit pull requests read, and each further copy gets <folder>-repeat-<n>, keyed by test.info().repeatEachIndex. The 23 audit specs that cleared a shared folder call it. A plain run writes exactly what it wrote before. Tests: the helper's unit cases, and the audits' late-copy profile (--repeat-each=3 at 2 workers), which fails on main.
1 parent 6e5791c commit fb8e440

26 files changed

Lines changed: 201 additions & 69 deletions

‎internal/a11y-spec/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"exports": {
99
".": "./src/index.ts",
1010
"./chromium": "./src/harness/chromium.ts",
11+
"./evidence": "./src/evidence.ts",
1112
"./storybook": "./src/storybook.ts"
1213
},
1314
"scripts": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file evidence.test.ts
5+
* @input vitest, node:fs, resetAuditEvidence
6+
* @output Tests that each copy of an audit file gets its own evidence folder
7+
* and clears only that one
8+
* @position Unit coverage for evidence.ts
9+
*/
10+
11+
import fs from 'node:fs';
12+
import os from 'node:os';
13+
import path from 'node:path';
14+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15+
import {resetAuditEvidence} from './evidence';
16+
17+
let root = '';
18+
19+
beforeEach(() => {
20+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'audit-evidence-'));
21+
});
22+
23+
afterEach(() => {
24+
fs.rmSync(root, {recursive: true, force: true});
25+
});
26+
27+
describe('resetAuditEvidence', () => {
28+
it('gives the first copy the folder itself, emptied and created', () => {
29+
const folder = path.join(root, 'menu-audit-evidence');
30+
fs.mkdirSync(folder);
31+
fs.writeFileSync(path.join(folder, 'stale.sensors.json'), '{}');
32+
expect(resetAuditEvidence(folder, {repeatEachIndex: 0})).toBe(folder);
33+
expect(fs.readdirSync(folder)).toEqual([]);
34+
});
35+
36+
it('gives each further copy its own folder and leaves the others alone', () => {
37+
const folder = path.join(root, 'menu-audit-evidence');
38+
const first = resetAuditEvidence(folder, {repeatEachIndex: 0});
39+
fs.writeFileSync(path.join(first, 'a.sensors.json'), '{}');
40+
const second = resetAuditEvidence(folder, {repeatEachIndex: 1});
41+
fs.writeFileSync(path.join(second, 'a.sensors.json'), '{}');
42+
const third = resetAuditEvidence(folder, {repeatEachIndex: 2});
43+
expect(second).toBe(`${folder}-repeat-1`);
44+
expect(third).toBe(`${folder}-repeat-2`);
45+
expect(fs.readdirSync(first)).toEqual(['a.sensors.json']);
46+
expect(fs.readdirSync(second)).toEqual(['a.sensors.json']);
47+
expect(fs.readdirSync(third)).toEqual([]);
48+
});
49+
});

‎internal/a11y-spec/src/evidence.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file evidence.ts
5+
* @input Uses node:fs
6+
* @output `resetAuditEvidence`, the evidence folder for one copy of an audit
7+
* file, emptied and created
8+
* @position Binding infrastructure for the Playwright audit specs: where a
9+
* spec writes its screenshots and receipts.
10+
*/
11+
12+
import fs from 'node:fs';
13+
14+
/**
15+
* Empty and create this copy's evidence folder, and return it. The first copy
16+
* of a file keeps `folder`, which CI uploads and audit pull requests read.
17+
* Each further `--repeat-each` copy can run at the same time in another
18+
* worker, so it gets `<folder>-repeat-<n>`, and no copy deletes or counts
19+
* another copy's receipts.
20+
*/
21+
export function resetAuditEvidence(
22+
folder: string,
23+
copy: {readonly repeatEachIndex: number},
24+
): string {
25+
const own =
26+
copy.repeatEachIndex === 0
27+
? folder
28+
: `${folder}-repeat-${copy.repeatEachIndex}`;
29+
fs.rmSync(own, {recursive: true, force: true});
30+
fs.mkdirSync(own, {recursive: true});
31+
return own;
32+
}

‎packages/core/src/Chat/__tests__/ChatSendButton.a11y.chromium.spec.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ import {
2323
} from '@playwright/test';
2424
// @ts-expect-error -- pngjs ships no declarations; runtime support is pinned.
2525
import {PNG} from 'pngjs';
26+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
2627
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
2728
import {
2829
DEFAULT_STORYBOOK_DIR,
2930
serveStorybook,
3031
type StaticServer,
3132
} from '@astryxdesign/a11y-spec/storybook';
3233

33-
const OUTPUT = path.resolve('test-results/chat-send-button-audit-evidence');
34+
const EVIDENCE = path.resolve('test-results/chat-send-button-audit-evidence');
35+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
36+
let OUTPUT = EVIDENCE;
3437
const NARROW_STORY = 'core-chatcomposer--disabled-streaming-narrow';
3538
const SUBJECT = '.astryx-chat-send-button';
3639

@@ -1265,8 +1268,7 @@ test.beforeAll(async () => {
12651268
if (process.env.ASTRYX_HEAD_SHA && process.env.ASTRYX_HEAD_SHA !== head) {
12661269
throw new Error('PR head differs from the checked out source');
12671270
}
1268-
fs.rmSync(OUTPUT, {recursive: true, force: true});
1269-
fs.mkdirSync(OUTPUT, {recursive: true});
1271+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
12701272
server = await serveStorybook(
12711273
process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
12721274
);

‎packages/core/src/Chat/__tests__/ChatSystemMessage.a11y.chromium.spec.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ import * as path from 'node:path';
1515
import {expect, test, type Browser, type Page} from '@playwright/test';
1616
// @ts-expect-error -- pngjs ships no declarations; runtime support is pinned.
1717
import {PNG} from 'pngjs';
18+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
1819
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
1920
import {
2021
DEFAULT_STORYBOOK_DIR,
2122
serveStorybook,
2223
type StaticServer,
2324
} from '@astryxdesign/a11y-spec/storybook';
2425

25-
const OUTPUT = path.resolve('test-results/chat-system-message-audit-evidence');
26+
const EVIDENCE = path.resolve(
27+
'test-results/chat-system-message-audit-evidence',
28+
);
29+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
30+
let OUTPUT = EVIDENCE;
2631
const STATES_STORY = 'a11y-chatsystemmessage-audit--states';
2732
const NARROW_STORY = 'a11y-chatsystemmessage-audit--narrow';
2833

@@ -818,8 +823,7 @@ test.beforeAll(async () => {
818823
if (process.env.ASTRYX_HEAD_SHA && process.env.ASTRYX_HEAD_SHA !== head) {
819824
throw new Error('PR head differs from the checked out source');
820825
}
821-
fs.rmSync(OUTPUT, {recursive: true, force: true});
822-
fs.mkdirSync(OUTPUT, {recursive: true});
826+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
823827
server = await serveStorybook(
824828
process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
825829
);

‎packages/core/src/Chat/__tests__/ChatTokenizedText.a11y.chromium.spec.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ import * as path from 'node:path';
1515
import {expect, test, type Page} from '@playwright/test';
1616
// @ts-expect-error -- pngjs ships no declarations; runtime support is pinned.
1717
import {PNG} from 'pngjs';
18+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
1819
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
1920
import {
2021
DEFAULT_STORYBOOK_DIR,
2122
serveStorybook,
2223
type StaticServer,
2324
} from '@astryxdesign/a11y-spec/storybook';
2425

25-
const OUTPUT = path.resolve('test-results/chat-tokenized-text-audit-evidence');
26+
const EVIDENCE = path.resolve(
27+
'test-results/chat-tokenized-text-audit-evidence',
28+
);
29+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
30+
let OUTPUT = EVIDENCE;
2631
const TARGET = '.astryx-chat-tokenized-text';
2732

2833
type Mode = 'light' | 'dark';
@@ -451,8 +456,7 @@ test.beforeAll(async () => {
451456
if (process.env.ASTRYX_HEAD_SHA && process.env.ASTRYX_HEAD_SHA !== head) {
452457
throw new Error('PR head differs from the checked out source');
453458
}
454-
fs.rmSync(OUTPUT, {recursive: true, force: true});
455-
fs.mkdirSync(OUTPUT, {recursive: true});
459+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
456460
server = await serveStorybook(
457461
process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
458462
);

‎packages/core/src/CommandPalette/__tests__/CommandPaletteEmptyAudit.a11y.chromium.spec.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ import * as fs from 'node:fs';
1616
import * as path from 'node:path';
1717
import {inflateSync} from 'node:zlib';
1818
import {expect, test, type Locator, type Page} from '@playwright/test';
19+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
1920
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
2021
import {
2122
DEFAULT_STORYBOOK_DIR,
2223
serveStorybook,
2324
type StaticServer,
2425
} from '@astryxdesign/a11y-spec/storybook';
2526

26-
const OUTPUT = path.resolve('command-palette-empty-audit-evidence');
27+
const EVIDENCE = path.resolve('command-palette-empty-audit-evidence');
28+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
29+
let OUTPUT = EVIDENCE;
2730
const WIDE = {width: 1024, height: 768};
2831
const NARROW = {width: 320, height: 720};
2932
const QUERY = 'zzz';
@@ -335,8 +338,7 @@ async function readSettledRender(page: Page, subject: Locator) {
335338
}
336339

337340
test.beforeAll(async () => {
338-
fs.rmSync(OUTPUT, {recursive: true, force: true});
339-
fs.mkdirSync(OUTPUT, {recursive: true});
341+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
340342
checkoutSha = execFileSync('git', ['rev-parse', 'HEAD'], {
341343
encoding: 'utf8',
342344
}).trim();

‎packages/core/src/CommandPalette/__tests__/CommandPaletteInputAudit.a11y.chromium.spec.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ import {execFileSync} from 'node:child_process';
1313
import * as fs from 'node:fs';
1414
import * as path from 'node:path';
1515
import {expect, test, type Locator, type Page} from '@playwright/test';
16+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
1617
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
1718
import {
1819
DEFAULT_STORYBOOK_DIR,
1920
serveStorybook,
2021
type StaticServer,
2122
} from '@astryxdesign/a11y-spec/storybook';
2223

23-
const OUTPUT = path.resolve('command-palette-input-audit-evidence');
24+
const EVIDENCE = path.resolve('command-palette-input-audit-evidence');
25+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
26+
let OUTPUT = EVIDENCE;
2427
const WIDE = {width: 1024, height: 768};
2528
const NARROW = {width: 320, height: 720};
2629

@@ -141,8 +144,7 @@ async function focusFromPointer(input: Locator) {
141144
}
142145

143146
test.beforeAll(async () => {
144-
fs.rmSync(OUTPUT, {recursive: true, force: true});
145-
fs.mkdirSync(OUTPUT, {recursive: true});
147+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
146148
checkoutSha = execFileSync('git', ['rev-parse', 'HEAD'], {
147149
encoding: 'utf8',
148150
}).trim();

‎packages/core/src/CommandPalette/__tests__/CommandPaletteItemAudit.a11y.chromium.spec.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ import {
2121
type Locator,
2222
type Page,
2323
} from '@playwright/test';
24+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
2425
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
2526
import {
2627
DEFAULT_STORYBOOK_DIR,
2728
serveStorybook,
2829
type StaticServer,
2930
} from '@astryxdesign/a11y-spec/storybook';
3031

31-
const OUTPUT = path.resolve('command-palette-item-audit-evidence');
32+
const EVIDENCE = path.resolve('command-palette-item-audit-evidence');
33+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
34+
let OUTPUT = EVIDENCE;
3235
const WIDE = {width: 1024, height: 768};
3336
const NARROW = {width: 320, height: 720};
3437

@@ -202,8 +205,7 @@ async function highlightFromKeyboard(
202205
}
203206

204207
test.beforeAll(async () => {
205-
fs.rmSync(OUTPUT, {recursive: true, force: true});
206-
fs.mkdirSync(OUTPUT, {recursive: true});
208+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
207209
checkoutSha = execFileSync('git', ['rev-parse', 'HEAD'], {
208210
encoding: 'utf8',
209211
}).trim();

‎packages/core/src/ComplexSelector/__tests__/ComplexSelector.a11y.chromium.spec.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ import * as fs from 'node:fs';
1616
import * as path from 'node:path';
1717
import {inflateSync} from 'node:zlib';
1818
import {expect, test, type Locator, type Page} from '@playwright/test';
19+
import {resetAuditEvidence} from '@astryxdesign/a11y-spec/evidence';
1920
import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
2021
import {
2122
DEFAULT_STORYBOOK_DIR,
2223
serveStorybook,
2324
type StaticServer,
2425
} from '@astryxdesign/a11y-spec/storybook';
2526

26-
const OUTPUT = path.resolve('test-results/complex-selector-audit-evidence');
27+
const EVIDENCE = path.resolve('test-results/complex-selector-audit-evidence');
28+
// This copy's evidence folder, set in beforeAll (one per --repeat-each copy).
29+
let OUTPUT = EVIDENCE;
2730
const WIDE = {width: 1024, height: 900};
2831
const NARROW = {width: 320, height: 720};
2932
const SHORT = {width: 1024, height: 360};
@@ -487,8 +490,7 @@ async function readPopupScroll(page: Page, contentId: string | null) {
487490
}
488491

489492
test.beforeAll(async () => {
490-
fs.rmSync(OUTPUT, {recursive: true, force: true});
491-
fs.mkdirSync(OUTPUT, {recursive: true});
493+
OUTPUT = resetAuditEvidence(EVIDENCE, test.info());
492494
checkoutSha = execFileSync('git', ['rev-parse', 'HEAD'], {
493495
encoding: 'utf8',
494496
}).trim();

0 commit comments

Comments
 (0)