From 5a84b804ce11473fb3f861b7c23828392fbb8d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 28 Oct 2026 20:55:33 -0400 Subject: [PATCH] ci(cli): teach the reachability check that a sharded vitest run selects the same files --- .github/workflows/ci.yml | 4 +++- scripts/check-test-reachability.mjs | 6 +++++- scripts/check-test-reachability.test.mjs | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b602bb8399..d9f4f1e58b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -577,7 +577,9 @@ jobs: with: lfs: true - uses: ./.github/actions/setup-test-workspace - - run: bun run --cwd packages/cli test -- --shard=${{ matrix.shard }} + - run: bun run --cwd packages/cli test --shard="$SHARD" + env: + SHARD: ${{ matrix.shard }} test-support: name: Test (support) diff --git a/scripts/check-test-reachability.mjs b/scripts/check-test-reachability.mjs index 7ea8773dc8..10d0d87abf 100644 --- a/scripts/check-test-reachability.mjs +++ b/scripts/check-test-reachability.mjs @@ -256,7 +256,11 @@ function runnerKind(command) { return undefined; } -function runnerCommand(command) { +// A shard runs part of the same file set; the matrix runs every shard, so it selects what the unsharded run does. +const SHARD_FLAG = /\s--shard=(?:"\$\w+"|\d+\/\d+)(?=\s|$)/; + +function runnerCommand(shardedCommand) { + const command = shardedCommand.replace(SHARD_FLAG, ""); const kind = runnerKind(command); if (!kind) return undefined; const tokens = command.match(/"[^"]*"|'[^']*'|\S+/g).map((s) => s.replace(/^["']|["']$/g, "")); diff --git a/scripts/check-test-reachability.test.mjs b/scripts/check-test-reachability.test.mjs index e4254978e8..3020858805 100644 --- a/scripts/check-test-reachability.test.mjs +++ b/scripts/check-test-reachability.test.mjs @@ -193,6 +193,15 @@ test("negated filter globs exclude only under some-with-excludes, and fail close assert.match(check(tree)["scripts/parity.test.mjs"].join("\n"), /CI filters exclude skills/); }); +test("a sharded vitest run selects what the unsharded run does", () => { + for (const flag of ['--shard="$SHARD"', "--shard=1/2"]) { + const tree = fixture(`vitest run ${flag}`, '"**"'); + assert.equal(check(tree)["scripts/parity.test.mjs"], undefined); + } + const tree = fixture('vitest run --shard="$SHARD" "$OTHER"', '"**"'); + assert.match(check(tree)["scripts/parity.test.mjs"][0], /no CI runner/); +}); + test("runner verbs must match exactly", () => { const tree = fixture("vitest run-anything", '"**"'); assert.match(check(tree)["scripts/parity.test.mjs"][0], /no CI runner/);