An open source design system that's fully customizable and agent ready
TypeScript
ci: the guard run leaves out the tests the changed run already ran (#9843)
Cindy Zhang5cc0620106fe
diff --git a/.github/scripts/ci-lab-only-routing.test.mjs b/.github/scripts/ci-lab-only-routing.test.mjsindex 9a0acac056..abdece37b0 100644--- a/.github/scripts/ci-lab-only-routing.test.mjs+++ b/.github/scripts/ci-lab-only-routing.test.mjs@@ -128,7 +128,11 @@ describe('Lab-only lane (spec:AST-030 FR26)', () => {// The Lab tests, not the module graph's --changed set, then the guards.expect(labBranch).not.toContain('pnpm test:ui --changed');expect(labBranch).toContain(- '-- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1',+ '-- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"',+ );+ // The guards leave out the Lab tests the run above already ran.+ expect(labBranch).toContain(+ '.github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project ui packages/lab/ --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"',);expect(labBranch).toContain('pnpm test:ui --passWithNoTests --shard=${{ matrix.shard }}/${{ strategy.job-total }} "${GUARDS[@]}"',diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjsindex fd4245e5bc..5f836b84f1 100644--- a/.github/scripts/ci-test-routing.test.mjs+++ b/.github/scripts/ci-test-routing.test.mjs@@ -184,7 +184,11 @@ describe.each(Object.entries(WORKFLOWS))(' # same legs, and the guards below as any scoped run does',' # (spec:AST-030 FR26).',` .github/scripts/run-named.sh "Lab tests" -- pnpm test:ui --passWithNoTests ${SHARD_ARG} packages/lab/`,- ' .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1',+ ' # The guard run leaves out the tests the run above already ran, so',+ ' # no test runs twice. Every leg splits the same reduced list, so a',+ ' # leg that cannot list them fails rather than split a different one.',+ ' .github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project ui packages/lab/ --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"',+ ' .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"',' mapfile -t GUARDS < "$RUNNER_TEMP/fs-guards.txt"',' if [ "${#GUARDS[@]}" -gt 0 ]; then',` .github/scripts/run-named.sh "Tests that read source files" -- pnpm test:ui --passWithNoTests ${SHARD_ARG} "\${GUARDS[@]}"`,@@ -195,7 +199,11 @@ describe.each(Object.entries(WORKFLOWS))(' # that read sources, and tests that load a changed package from',' # its build (by name or its dist/).',' # The list goes through a file so a failing lister fails the step.',- ' .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1',+ ' # The guard run leaves out the tests the run above already ran, so',+ ' # no test runs twice. Every leg splits the same reduced list, so a',+ ' # leg that cannot list them fails rather than split a different one.',+ ' .github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project ui --changed=HEAD^1 --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"',+ ' .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"',' mapfile -t GUARDS < "$RUNNER_TEMP/fs-guards.txt"',' if [ "${#GUARDS[@]}" -gt 0 ]; then',` .github/scripts/run-named.sh "Tests that read source files" -- pnpm test:ui --passWithNoTests ${SHARD_ARG} "\${GUARDS[@]}"`,@@ -220,7 +228,11 @@ describe.each(Object.entries(WORKFLOWS))(' # that read sources, and tests that load a changed package from',' # its build (by name or its dist/).',' # The list goes through a file so a failing lister fails the step.',- ' .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1',+ ' # The guard run leaves out the tests the run above already ran, so',+ ' # no test runs twice. Every leg splits the same reduced list, so a',+ ' # leg that cannot list them fails rather than split a different one.',+ ' .github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project node --changed=HEAD^1 --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"',+ ' .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"',' mapfile -t GUARDS < "$RUNNER_TEMP/fs-guards.txt"',' if [ "${#GUARDS[@]}" -gt 0 ]; then',` .github/scripts/run-named.sh "Tests that read source files" -- pnpm test:node --passWithNoTests ${SHARD_ARG} "\${GUARDS[@]}"`,diff --git a/.github/scripts/fs-guard-tests.mjs b/.github/scripts/fs-guard-tests.mjsindex 035d55938c..722ec1ad75 100644--- a/.github/scripts/fs-guard-tests.mjs+++ b/.github/scripts/fs-guard-tests.mjs@@ -23,7 +23,11 @@// Vitest test, so these are the ones its change can break// (spec:AST-030 FR2). `--project ui|node` keeps one Vitest project's.//-// Usage: node .github/scripts/fs-guard-tests.mjs [--spec-readers [--project ui|node]] [--changed <ref>]+// - With `--already-run <file>`: leaves out the tests that file lists (Vitest+// `list --json` output, or one path per line), so a test the `--changed`+// run already ran does not run a second time.+//+// Usage: node .github/scripts/fs-guard-tests.mjs [--spec-readers [--project ui|node]] [--changed <ref>] [--already-run <file>]// (newline-separated paths)import {execFileSync} from 'node:child_process';@@ -284,6 +288,35 @@ export function uiTestRoots(config) {return roots;}+/**+ * The repository-relative test paths in `text`: Vitest `list --json` output+ * (an array of `{file}`), or one path per line. Absolute paths under `root`+ * become relative.+ */+export function readTestList(text, root) {+ const trimmed = text.trim();+ if (trimmed === '') return [];+ const raw = trimmed.startsWith('[')+ ? JSON.parse(trimmed).map(entry =>+ typeof entry === 'string' ? entry : entry.file,+ )+ : trimmed.split('\n');+ return raw+ .filter(file => typeof file === 'string' && file.trim() !== '')+ .map(file => {+ const clean = file.trim();+ return path.isAbsolute(clean)+ ? path.relative(root, clean).split(path.sep).join('/')+ : clean.replace(/^\.\//, '');+ });+}++/** `tests` without the ones `alreadyRun` lists. */+export function withoutAlreadyRun(tests, alreadyRun) {+ const ran = new Set(alreadyRun);+ return tests.filter(test => !ran.has(test));+}+/*** The tests that read a record a spec-only change may touch: the import* closure (relative imports followed, as for the guards above) reads files@@ -400,5 +433,12 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {} else {tests = scopedExtraTests(files, read, changedFiles);}+ const alreadyRunFlag = process.argv.indexOf('--already-run');+ if (alreadyRunFlag !== -1) {+ tests = withoutAlreadyRun(+ tests,+ readTestList(read(process.argv[alreadyRunFlag + 1]), process.cwd()),+ );+ }process.stdout.write(tests.length > 0 ? `${tests.join('\n')}\n` : '');}diff --git a/.github/scripts/fs-guard-tests.test.mjs b/.github/scripts/fs-guard-tests.test.mjsindex 4887143466..b7bccb958e 100644--- a/.github/scripts/fs-guard-tests.test.mjs+++ b/.github/scripts/fs-guard-tests.test.mjs@@ -8,9 +8,11 @@ import path from 'node:path';import {fsGuardTests,+ readTestList,scopedExtraTests,specReaderTests,uiTestRoots,+ withoutAlreadyRun,} from './fs-guard-tests.mjs';import os from 'node:os';import yaml from 'yaml';@@ -472,3 +474,66 @@ describe('spec readers on this repository (contract)', () => {},);});++describe('a test the --changed run already ran runs once', () => {+ const root = '/repo';++ it('reads Vitest list JSON and plain lines as repository paths', () => {+ expect(+ readTestList(+ JSON.stringify([+ {file: '/repo/scripts/a.test.mjs', projectName: 'node'},+ {file: '/repo/packages/cli/b.test.mjs', projectName: 'node'},+ ]),+ root,+ ),+ ).toEqual(['scripts/a.test.mjs', 'packages/cli/b.test.mjs']);+ expect(+ readTestList('./scripts/a.test.mjs\nscripts/c.test.mjs\n', root),+ ).toEqual(['scripts/a.test.mjs', 'scripts/c.test.mjs']);+ expect(readTestList('', root)).toEqual([]);+ expect(readTestList('[]', root)).toEqual([]);+ });++ it('leaves out only the tests already run', () => {+ expect(+ withoutAlreadyRun(+ ['scripts/a.test.mjs', 'scripts/guard.test.mjs'],+ ['scripts/a.test.mjs', 'scripts/other.test.mjs'],+ ),+ ).toEqual(['scripts/guard.test.mjs']);+ });++ it('the lister drops a guard the changed run listed, and keeps the rest', () => {+ const repoRoot = path.resolve(import.meta.dirname, '../..');+ const script = path.join(repoRoot, '.github/scripts/fs-guard-tests.mjs');+ const lines = text => text.split('\n').filter(Boolean);+ const all = lines(+ execFileSync(process.execPath, [script, '--changed', 'HEAD'], {+ cwd: repoRoot,+ encoding: 'utf8',+ }),+ );+ expect(all.length).toBeGreaterThan(1);+ const [ran, ...rest] = all;+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'already-run-'));+ try {+ const list = path.join(dir, 'already-run.json');+ fs.writeFileSync(+ list,+ JSON.stringify([{file: path.join(repoRoot, ran), projectName: 'node'}]),+ );+ const guards = lines(+ execFileSync(+ process.execPath,+ [script, '--changed', 'HEAD', '--already-run', list],+ {cwd: repoRoot, encoding: 'utf8'},+ ),+ );+ expect(guards).not.toContain(ran);+ expect(guards).toEqual(rest);+ } finally {+ fs.rmSync(dir, {recursive: true, force: true});+ }+ });+});diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex f5deec5d20..1b412d4791 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -849,7 +849,11 @@ jobs:# same legs, and the guards below as any scoped run does# (spec:AST-030 FR26)..github/scripts/run-named.sh "Lab tests" -- pnpm test:ui --passWithNoTests --shard=${{ matrix.shard }}/${{ strategy.job-total }} packages/lab/- .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1+ # The guard run leaves out the tests the run above already ran, so+ # no test runs twice. Every leg splits the same reduced list, so a+ # leg that cannot list them fails rather than split a different one.+ .github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project ui packages/lab/ --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"+ .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"mapfile -t GUARDS < "$RUNNER_TEMP/fs-guards.txt"if [ "${#GUARDS[@]}" -gt 0 ]; then.github/scripts/run-named.sh "Tests that read source files" -- pnpm test:ui --passWithNoTests --shard=${{ matrix.shard }}/${{ strategy.job-total }} "${GUARDS[@]}"@@ -860,7 +864,11 @@ jobs:# that read sources, and tests that load a changed package from# its build (by name or its dist/).# The list goes through a file so a failing lister fails the step.- .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1+ # The guard run leaves out the tests the run above already ran, so+ # no test runs twice. Every leg splits the same reduced list, so a+ # leg that cannot list them fails rather than split a different one.+ .github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project ui --changed=HEAD^1 --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"+ .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"mapfile -t GUARDS < "$RUNNER_TEMP/fs-guards.txt"if [ "${#GUARDS[@]}" -gt 0 ]; then.github/scripts/run-named.sh "Tests that read source files" -- pnpm test:ui --passWithNoTests --shard=${{ matrix.shard }}/${{ strategy.job-total }} "${GUARDS[@]}"@@ -981,7 +989,11 @@ jobs:# that read sources, and tests that load a changed package from# its build (by name or its dist/).# The list goes through a file so a failing lister fails the step.- .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1+ # The guard run leaves out the tests the run above already ran, so+ # no test runs twice. Every leg splits the same reduced list, so a+ # leg that cannot list them fails rather than split a different one.+ .github/scripts/run-named.sh "List the tests the first run ran" -- pnpm exec vitest list --project node --changed=HEAD^1 --filesOnly --passWithNoTests --json="$RUNNER_TEMP/already-run.json"+ .github/scripts/run-named.sh "List the tests that read source files" --stdout "$RUNNER_TEMP/fs-guards.txt" -- node .github/scripts/fs-guard-tests.mjs --changed HEAD^1 --already-run "$RUNNER_TEMP/already-run.json"mapfile -t GUARDS < "$RUNNER_TEMP/fs-guards.txt"if [ "${#GUARDS[@]}" -gt 0 ]; then.github/scripts/run-named.sh "Tests that read source files" -- pnpm test:node --passWithNoTests --shard=${{ matrix.shard }}/${{ strategy.job-total }} "${GUARDS[@]}"