Skip to content

Commit e61cba5

Browse files
thymikeeclaude
andcommitted
chore(gates): cap each kernel's mutation scope in the unit suite
A unit-suite test fails the PR that grows a kernel's owned tests past MAX_MUTATION_TEST_SCOPE_FILES, instead of the next weekly sweep timing out. The cap comes from the weekly shard timings on ubuntu-latest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 998d9b3 commit e61cba5

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import path from 'node:path';
2+
import { expect, test } from 'vitest';
3+
import { KERNEL_MODULES, MAX_MUTATION_TEST_SCOPE_FILES } from '../mutation/modules.ts';
4+
import { mutationTestScopes } from '../mutation/ownership.ts';
5+
6+
const repoRoot = path.resolve(import.meta.dirname, '../..');
7+
8+
test('every kernel mutation scope fits one weekly shard', { timeout: 30_000 }, () => {
9+
const scopes = mutationTestScopes(repoRoot);
10+
const oversized = KERNEL_MODULES.map((module) => ({
11+
module: module.id,
12+
testFiles: scopes.get(module.id)?.length ?? 0,
13+
})).filter((scope) => scope.testFiles > MAX_MUTATION_TEST_SCOPE_FILES);
14+
expect(
15+
oversized,
16+
`A kernel's owned tests exceed MAX_MUTATION_TEST_SCOPE_FILES (${MAX_MUTATION_TEST_SCOPE_FILES}). ` +
17+
'Every shard replays the whole scope, so more shards do not help. Split the kernel in ' +
18+
'scripts/mutation/modules.ts, or import it from fewer tests.',
19+
).toEqual([]);
20+
});

‎scripts/mutation/modules.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ export const KERNEL_MODULES: readonly KernelModule[] = [
9898
},
9999
];
100100

101+
/**
102+
* The most test files one kernel's mutation scope may hold. Every shard of a
103+
* module replays its whole scope in Stryker's dry run before the first mutant,
104+
* so this bounds a shard however many shards the module declares. Measured on
105+
* ubuntu-latest (weekly run 40164641005): a 684-file scope dry-ran in 4–7 min
106+
* and its shards finished in 9–19 min of the 22-minute step; a 1,471-file scope
107+
* dry-ran in 8–11 min and a shard outran the step. The unit suite enforces it
108+
* (`scripts/__tests__/mutation-scope-budget.test.ts`), so the PR that grows a
109+
* scope past it fails instead of the next weekly sweep.
110+
*/
111+
export const MAX_MUTATION_TEST_SCOPE_FILES = 600;
112+
101113
export const ALL_MODULE_IDS: readonly ModuleId[] = KERNEL_MODULES.map((module) => module.id);
102114

103115
export function moduleById(id: ModuleId): KernelModule {

‎vitest.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export default defineConfig({
154154
'scripts/__tests__/help-conformance-sample-outputs.test.ts',
155155
'scripts/__tests__/help-conformance-topic-coverage.test.ts',
156156
'scripts/__tests__/eager-closure-budgets.test.ts',
157+
'scripts/__tests__/mutation-scope-budget.test.ts',
157158
'scripts/__tests__/closure-growth-rule.test.ts',
158159
'scripts/__tests__/agent-setup-startup-contract.test.ts',
159160
'scripts/__tests__/npm-skills-exclusion.test.ts',

0 commit comments

Comments
 (0)