The `full test (windows-latest, *)` lane ran the entire unit suite (~740+ files) in one job whose wall-clock crept against the 20m cap and intermittently CANCELLED (false-negative gate, observed on PR #1207). Prior tactical fixes #869 (15→20m bump) and #1051 (handle-leak) deferred the cliff structurally. Shard the unit suite across 3 parallel runners per OS/node leg so per-job wall-clock is O(total/3) and stays under the cap as the suite grows. - scripts/run-tests.cjs: add `--shard <i>/<n>` — a deterministic, balanced round-robin partition (fileIndex % n === i-1) over the SORTED selected file list. parseShardArg strictly validates i∈1..n, n≥1, integer-only; n=1 is a pure no-op. The 28K Windows argv chunking is preserved within each shard. A legitimately-empty shard (n > file count) exits 0; a selection empty BEFORE sharding still hits the discovery hard error. Composes with --suite and is order-independent (sorted before partition). Exports selectShard/parseShardArg. - .github/workflows/test.yml: test-full becomes the 3 legs × 3 shards = 9-job cross-product (explicit include rows — a base shard dim does not cross-product with include legs, and a nested matrix.leg.os is unresolvable by the H1 shell-policy linter). Unit suite runs sharded; integration/security run once per leg (shard 1). The Required tests fan-in is unchanged: it already needs test-full and checks the matrix-aggregate result, so a failed/cancelled shard fails the gate; the branch-protection check name is preserved. - tests: partition/CLI + pure selectShard contract (completeness, disjointness, balance, determinism, boundaries, fast-check property) + parseShardArg validation, in run-tests-harness.test.cjs; a DEFECT.GENERATIVE-FIX parity guard (per-row shard values 1..N, every leg runs all shards, N == --shard /N denominator) + Required-tests name/needs pin, in ci-test-scope.test.cjs. Closes #1212 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -457,6 +457,96 @@ describe('test.yml changes job contract (#837)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('test-full shard matrix parity (#1212)', () => {
|
||||
// DEFECT.GENERATIVE-FIX: the sharded windows full-test lane has TWO surfaces
|
||||
// that must agree — the `shard:` matrix array (how many parallel jobs run)
|
||||
// and the `/N` denominator in `run-tests.cjs --suite unit --shard i/N` (how
|
||||
// many slices the runner partitions the suite into). If they diverge (e.g.
|
||||
// someone grows `shard: [1,2,3,4]` but leaves `--shard ${{ matrix.shard }}/3`),
|
||||
// shards silently overlap and one shard errors out. This parity assertion
|
||||
// fails the moment the two drift.
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
function loadTestFull() {
|
||||
const text = fs.readFileSync(path.join(WORKFLOWS_DIR, 'test.yml'), 'utf8');
|
||||
const doc = yaml.load(text);
|
||||
return { text, job: doc.jobs['test-full'] };
|
||||
}
|
||||
|
||||
test('distinct shard values are 1..N matching the --shard /N denominator, on every leg', () => {
|
||||
const { job } = loadTestFull();
|
||||
const include = job.strategy.matrix.include;
|
||||
assert.ok(Array.isArray(include), 'test-full matrix must enumerate `include:` rows');
|
||||
assert.ok(
|
||||
include.every(r => Number.isInteger(r.shard)),
|
||||
'every include row must carry an integer `shard:` key',
|
||||
);
|
||||
|
||||
const distinctShards = [...new Set(include.map(r => r.shard))].sort((a, b) => a - b);
|
||||
const n = distinctShards.length;
|
||||
|
||||
// Distinct shard values must be exactly 1..n (1-based, contiguous) so the
|
||||
// runner's round-robin selection covers every file with no gaps/overlaps.
|
||||
assert.deepStrictEqual(
|
||||
distinctShards,
|
||||
Array.from({ length: n }, (_, i) => i + 1),
|
||||
`distinct shard values must be 1..${n} (1-based, contiguous), got ${JSON.stringify(distinctShards)}`,
|
||||
);
|
||||
|
||||
// Every OS/node leg must appear once per shard (full cross-product) — no
|
||||
// leg may silently skip a shard, which would drop a third of its coverage.
|
||||
const legs = [...new Set(include.map(r => `${r.os}|${r['node-version']}`))];
|
||||
for (const leg of legs) {
|
||||
const [os, node] = leg.split('|');
|
||||
const shardsForLeg = include
|
||||
.filter(r => r.os === os && String(r['node-version']) === node)
|
||||
.map(r => r.shard)
|
||||
.sort((a, b) => a - b);
|
||||
assert.deepStrictEqual(
|
||||
shardsForLeg,
|
||||
distinctShards,
|
||||
`leg ${leg} must run all shards ${JSON.stringify(distinctShards)}, got ${JSON.stringify(shardsForLeg)}`,
|
||||
);
|
||||
}
|
||||
// Full cross-product: every (leg, shard) pair is present exactly once, so
|
||||
// the row count equals legs × shards with no duplicate/missing combination.
|
||||
const pairKey = r => `${r.os}|${r['node-version']}|${r.shard}`;
|
||||
assert.strictEqual(new Set(include.map(pairKey)).size, legs.length * n);
|
||||
assert.strictEqual(include.length, legs.length * n);
|
||||
|
||||
// Find the `--shard ${{ matrix.shard }}/<N>` denominator in the unit step.
|
||||
const unitStep = job.steps.find(
|
||||
s => typeof s.run === 'string' && s.run.includes('run-tests.cjs') && s.run.includes('--shard'),
|
||||
);
|
||||
assert.ok(unitStep, 'test-full must have a step running run-tests.cjs --shard');
|
||||
const m = /--shard\s+\$\{\{\s*matrix\.shard\s*\}\}\/(\d+)/.exec(unitStep.run);
|
||||
assert.ok(m, `could not parse --shard i/N denominator from: ${unitStep.run}`);
|
||||
const denominator = Number(m[1]);
|
||||
|
||||
assert.strictEqual(
|
||||
denominator,
|
||||
n,
|
||||
`shard count (${n}) and --shard /N denominator (${denominator}) must match — ` +
|
||||
`update both the per-row \`shard:\` values and the \`/N\` in the run command together.`,
|
||||
);
|
||||
});
|
||||
|
||||
test('required-tests fan-in still needs test-full and keeps the protected name', () => {
|
||||
// Hyrum's Law: branch protection requires a status check literally named
|
||||
// "Required tests". Renaming it (or dropping test-full from its needs)
|
||||
// would silently break the gate. Pin both.
|
||||
const text = fs.readFileSync(path.join(WORKFLOWS_DIR, 'test.yml'), 'utf8');
|
||||
const doc = yaml.load(text);
|
||||
const fanIn = doc.jobs['required-tests'];
|
||||
assert.ok(fanIn, 'required-tests job must exist');
|
||||
assert.strictEqual(fanIn.name, 'Required tests', 'the branch-protection check name must stay "Required tests"');
|
||||
assert.ok(
|
||||
Array.isArray(fanIn.needs) && fanIn.needs.includes('test-full'),
|
||||
'required-tests must `needs: test-full` so all shard legs aggregate into the gate',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('code_changed=false implies clean output invariant', () => {
|
||||
// Fix 1: when code_changed is false, full_matrix, targeted_tests, windows_tests
|
||||
// must ALL be empty/false — even if a docs path coincidentally
|
||||
|
||||
Reference in New Issue
Block a user