fix(ci): shard exact test specifications before execution (#14499)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-25 08:28:02 -05:00
1 parent 2f2a66f211
commit 0069feeccf
2 files changed
+48 -23

No files matched your search

+13 -1
View File
@@ -98,8 +98,20 @@ try {
throw new Error(
`Selected test files were not discovered: ${missing.join(", ")}`,
);
let specifications = [...selected];
const { shard, sequence, passWithNoTests } = vitest.config;
if (shard && shutdownSignal === undefined) {
if (!passWithNoTests && shard.count > specifications.length)
throw new Error(
`Cannot run ${shard.count} shards for ${specifications.length} selected test specifications`,
);
// runTestSpecifications takes the final inventory for this shard.
specifications = await new sequence.sequencer(vitest).shard(
specifications,
);
}
if (shutdownSignal === undefined)
await vitest.runTestSpecifications([...selected]);
await vitest.runTestSpecifications(specifications);
}
} finally {
await close();
+35 -22
View File
@@ -1,6 +1,6 @@
import { execFile } from "node:child_process";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
@@ -18,14 +18,14 @@ const group = fileURLToPath(
new URL("../../scripts/ci/test-group.mjs", import.meta.url),
);
const selectedEnvironment = (...files: string[]) => ({
const selectedEnvironment = (shards: number, ...files: string[]) => ({
...process.env,
CI_TEST_SELECTION: JSON.stringify({
version: 3,
mode: "selected",
reason: "Explicitly selected test files",
files,
shards: 1,
shards,
}),
});
@@ -707,6 +707,7 @@ it("parses only well-formed plans and derives the selected shard count", () => {
it("runs only a shard the plan defines", async () => {
const environment = selectedEnvironment(
1,
"tests/evaluation/reasonMarker.test.ts",
"tests/evaluation/recordPredicateGuard.test.ts",
);
@@ -751,7 +752,7 @@ it.each([
])("rejects a case filter in a selected shard: %j", async (...filter) => {
await expect(
execute(process.execPath, [group, "selected", "1/1", ...filter], {
env: selectedEnvironment("tests/evaluation/reasonMarker.test.ts"),
env: selectedEnvironment(1, "tests/evaluation/reasonMarker.test.ts"),
}),
).rejects.toMatchObject({
stderr: expect.stringContaining(
@@ -760,29 +761,41 @@ it.each([
});
});
it("runs every selected case and still permits developer name and tag filters", async () => {
it("runs each selected file on one shard and still permits developer case filters", async () => {
const exact = fileURLToPath(
new URL("../../scripts/run-exact-tests.mjs", import.meta.url),
);
const file = "tests/evaluation/reasonMarker.test.ts";
const files = [file, "tests/evaluation/recordPredicateGuard.test.ts"];
const root = await createTestTempDirectory("rea-selected-cases-");
const selectedReport = join(root, "selected.json");
await execute(
process.execPath,
[
group,
"selected",
"1/1",
"--reporter=json",
`--outputFile.json=${selectedReport}`,
],
{ env: selectedEnvironment(file) },
const passedByFile = new Map<string, number>();
for (const index of [1, 2]) {
const report = join(root, `selected-${index}.json`);
await execute(
process.execPath,
[
group,
"selected",
`${index}/2`,
"--reporter=json",
`--outputFile.json=${report}`,
],
{ env: selectedEnvironment(2, ...files) },
);
const selected = JSON.parse(await readFile(report, "utf8")) as {
numPassedTests: number;
testResults: { name: string }[];
};
expect(selected).toMatchObject({ numPendingTests: 0, numFailedTests: 0 });
expect(selected.testResults).toHaveLength(1);
for (const { name } of selected.testResults)
passedByFile.set(resolve(name), selected.numPassedTests);
}
expect([...passedByFile.keys()].toSorted()).toEqual(
files.map((path) => resolve(path)).toSorted(),
);
const selected = JSON.parse(await readFile(selectedReport, "utf8")) as {
numPassedTests: number;
};
expect(selected).toMatchObject({ numPendingTests: 0, numFailedTests: 0 });
expect(selected.numPassedTests).toBeGreaterThan(1);
const selectedCases = passedByFile.get(resolve(file))!;
expect(selectedCases).toBeGreaterThan(1);
const devReport = join(root, "developer.json");
await execute(process.execPath, [
@@ -798,6 +811,6 @@ it("runs every selected case and still permits developer name and tag filters",
const dev: unknown = JSON.parse(await readFile(devReport, "utf8"));
expect(dev).toMatchObject({
numPassedTests: 1,
numPendingTests: selected.numPassedTests - 1,
numPendingTests: selectedCases - 1,
});
});