Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions .github/scripts/ci-swizzle-proof.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @file ci-swizzle-proof.test.mjs
* @input .github/workflows/ci.yml and the swizzle proof's slice files
* @output Proof that the swizzle proof runs in its own required legs, one
* slice each, exactly when its scope proves a target, and never inside the
* Node legs
* slice each under the Node legs' shard watchdog, exactly when its scope
* proves a target, and never inside the Node legs
* @position Beside the other ci.yml shape tests
*/

Expand Down Expand Up @@ -33,12 +33,45 @@ describe('the swizzle proof in CI', () => {
const job = ci.jobs['swizzle-proof'];
expect(job.strategy.matrix.slice).toEqual(sliceFiles.map((_, i) => i + 1));
expect(job.strategy['fail-fast']).toBe(false);
const run = job.steps.find(
const step = job.steps.find(
step => step.name === 'Run this slice of the swizzle proof',
).run;
expect(run).toBe(
`pnpm test:node ${SLICES}/swizzle-proof.\${{ matrix.slice }}.test.mjs`,
);
expect(step.run).toContain(
`pnpm test:node "\${WATCHDOG[@]}" ${SLICES}/swizzle-proof.\${{ matrix.slice }}.test.mjs`,
);
// Its own job runs the slice: never the setting that leaves it out.
expect(step.env?.VITEST_SWIZZLE_PROOF_OWN_JOB).toBeUndefined();
});

it('runs each slice under the shard watchdog, as the Node legs do, and checks its recorded time', () => {
const slice = ci.jobs['swizzle-proof'].steps.find(
step => step.name === 'Run this slice of the swizzle proof',
);
const node = ci.jobs['test-node'].steps.find(
step => step.name === 'Run this shard of the Node tests',
);
// The same limit, counted the same way, and the same reporters.
for (const line of node.run
.split('\n')
.filter(line =>
/^(started=|VITEST_SHARD_WATCHDOG_SECONDS=|export |WATCHDOG=)/.test(
line.trim(),
),
))
expect(slice.run).toContain(line.trim());
expect(ci.jobs['swizzle-proof']['timeout-minutes']).toBe(
ci.jobs['test-node']['timeout-minutes'],
);
expect(slice.env.VITEST_SHARD_TIMES_FILE).toBe(
node.env.VITEST_SHARD_TIMES_FILE,
);
const drift = ci.jobs['swizzle-proof'].steps.find(
step => step.name === 'Check the recorded time of this slice',
);
expect(drift.run).toBe(
'node .github/scripts/node-time-drift.mjs --times "$RUNNER_TEMP/node-file-times.json" --changed HEAD^1',
);
expect(drift.if).toContain("steps.slice.outcome != 'skipped'");
});

it('starts the legs exactly when the scope proves a target', () => {
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,26 @@ jobs:
- name: Build core package
run: pnpm -F @astryxdesign/core build

# The shard watchdog (scripts/vitest-shard-watchdog.mjs) fires a minute
# before the job's 15-minute limit, as in test-node, so a slow slice
# fails and names its file instead of being cancelled. It also writes
# the slice's seconds for the recorded-time check below.
- name: Run this slice of the swizzle proof
run: pnpm test:node packages/cli/test/swizzle-proof/swizzle-proof.${{ matrix.slice }}.test.mjs
id: slice
env:
VITEST_SHARD_TIMES_FILE: ${{ runner.temp }}/node-file-times.json
run: |
started=$(ps -o etimes= -C Runner.Worker 2>/dev/null | sort -n | tail -1 | tr -d ' ')
VITEST_SHARD_WATCHDOG_SECONDS=$(( 14 * 60 - ${started:-180} ))
export VITEST_SHARD_WATCHDOG_SECONDS
WATCHDOG=(--reporter=default --reporter=github-actions --reporter=./scripts/vitest-shard-watchdog.mjs)
pnpm test:node "${WATCHDOG[@]}" packages/cli/test/swizzle-proof/swizzle-proof.${{ matrix.slice }}.test.mjs

# As in test-node: a slice file this change touches that now runs far
# past its recorded time fails here, naming both times.
- name: Check the recorded time of this slice
if: always() && github.event_name == 'pull_request' && steps.slice.outcome != 'skipped'
run: node .github/scripts/node-time-drift.mjs --times "$RUNNER_TEMP/node-file-times.json" --changed HEAD^1

# The one pre-job left: a runner must be picked before its job starts, so
# this decides on a free slim runner whether native Swift changed, and
Expand Down
11 changes: 9 additions & 2 deletions scripts/vitest-shard-sequencer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ export function partitionByDuration(
* pull request's `test-node (2/5)` or a Main run's `test-node (2)`.
*/
const NODE_LEG_JOB = /^test-node \(\d+(?:\/\d+)?\)$/;
/** A swizzle-proof leg's job name, such as `swizzle-proof (3/8)`. */
const SWIZZLE_PROOF_JOB = /^swizzle-proof \(\d+(?:\/\d+)?\)$/;

/**
* Seconds per Node test file from Vitest's default reporter lines. A whole
* run's log (`gh run view --log`) names each line's job in its first
* tab-separated column: only the Node legs' lines count, since other jobs (the
* build job runs its own `--project node` tests, which the Node legs skip)
* would book time no leg spends. A single leg's own log has no job column.
* would book time no leg spends. The swizzle-proof legs' lines count for the
* slice files, which run there. A single leg's own log has no job column.
*/
export function recordDurations(text) {
const seconds = {};
Expand All @@ -100,7 +103,11 @@ export function recordDurations(text) {
const plain = text.replace(/(?:\x1b|\^\[)\[[0-9;]*m/g, '');
for (const line of plain.split('\n')) {
const columns = line.split('\t');
if (columns.length >= 3 && !NODE_LEG_JOB.test(columns[0])) continue;
if (columns.length >= 3 && !NODE_LEG_JOB.test(columns[0])) {
if (!SWIZZLE_PROOF_JOB.test(columns[0])) continue;
const file = /\s(\S+\.test\.mjs)\s/.exec(line)?.[1] ?? '';
if (!SWIZZLE_PROOF.test(file)) continue;
}
const match =
/[✓❯×]\s+\|?node\|?\s+(\S+\.(?:test|spec)\.[cm]?[jt]sx?)\s+\(\d+ tests?[^)]*\)\s+(\d+(?:\.\d+)?)(ms|s)\s*$/.exec(
line,
Expand Down
15 changes: 15 additions & 0 deletions scripts/vitest-shard-sequencer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,21 @@ describe('duration-balanced Node legs', () => {
});
});

it('books the slice files from the swizzle-proof legs, where they run, and nothing else there', () => {
const log = [
'swizzle-proof (3/8)\tRun this slice of the swizzle proof\t2026-11-14T11:04:57.18Z ✓ node packages/cli/test/swizzle-proof/swizzle-proof.3.test.mjs (1 test) 338400ms',
'swizzle-proof (5/8)\tRun this slice of the swizzle proof\t2026-11-14T11:04:57.18Z ^[[32m✓^[[39m ^[[30m^[[46m node ^[[49m^[[39m packages/cli/test/swizzle-proof/swizzle-proof.5.test.mjs ^[[2m(1 test)^[[22m^[[33m 122349^[[2mms^[[22m^[[39m',
// Any other file in that job is no Node leg's time.
'swizzle-proof (5/8)\tBuild core package\t2026-11-14T11:01:57.18Z ✓ node packages/cli/other.test.mjs (2 tests) 5000ms',
'test-node (1/5)\tRun tests\t2026-11-14T11:04:57.18Z ✓ node packages/cli/a.test.mjs (4 tests) 1200ms',
].join('\n');
expect(recordDurations(log)).toEqual({
'packages/cli/test/swizzle-proof/swizzle-proof.3.test.mjs': 338.4,
'packages/cli/test/swizzle-proof/swizzle-proof.5.test.mjs': 122.3,
'packages/cli/a.test.mjs': 1.2,
});
});

it('reads colour codes spelled out, as `gh run view --log` prints them', () => {
const log =
'test-node (1/5)\tstep\t2026-11-11T07:54:35.11Z ^[[32m✓^[[39m ^[[30m^[[46m node ^[[49m^[[39m packages/cli/a.test.mjs ^[[2m(12 tests)^[[22m^[[33m 542123^[[2mms^[[22m^[[39m';
Expand Down
Loading