Skip to content

Commit da4bf16

Browse files
fix: merge only Stryker reports from a shard directory
The shard artifacts now carry the lane envelope beside mutation.json, and the merge globbed every .json under the download path, so the ratchet job fed the envelope to the report parser and died after the mutants had already run.
1 parent 8c1dbe7 commit da4bf16

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

‎scripts/mutation/envelope.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,56 @@ test('a crashed run still writes an envelope naming the stage it died in', () =>
9090
assert.match(envelope.configHash, /^sha256:/);
9191
});
9292

93+
// Shard artifacts carry the envelope next to the report, so merging "every JSON
94+
// under the shard directory" fed the envelope to the report parser and crashed
95+
// the ratchet job after the mutants had already run.
96+
test('merging shard reports ignores the envelope sitting beside them', () => {
97+
const shards = path.join(repoRoot, '.tmp/mutation/envelope-test-shards/shard-a');
98+
fs.mkdirSync(shards, { recursive: true });
99+
fs.writeFileSync(
100+
path.join(shards, 'mutation.json'),
101+
JSON.stringify({
102+
files: {
103+
'src/kernel/errors.ts': { mutants: [{ status: 'Killed' }, { status: 'Survived' }] },
104+
},
105+
}),
106+
);
107+
fs.writeFileSync(
108+
path.join(shards, 'lane-envelope.json'),
109+
JSON.stringify(
110+
laneEnvelope({
111+
lane: 'mutation-decision-kernels',
112+
commit: 'c'.repeat(40),
113+
tool: { stryker: '9.6.1' },
114+
configHash: 'sha256:abcdef123456',
115+
startedAtMs: 0,
116+
now: 0,
117+
result: 'pass',
118+
data: {},
119+
}),
120+
),
121+
);
122+
const result = runCmdSync(
123+
'node',
124+
[
125+
'--experimental-strip-types',
126+
'scripts/mutation/run.ts',
127+
'--report-dir',
128+
'.tmp/mutation/envelope-test-shards',
129+
'--modules',
130+
'kernel-errors',
131+
],
132+
{ cwd: repoRoot, allowFailure: true },
133+
);
134+
assert.match(result.stdout, /merging 1 shard report\(s\)/);
135+
assert.match(result.stdout, /kernel-errors/);
136+
assert.doesNotMatch(result.stderr, /Cannot convert undefined or null to object/);
137+
fs.rmSync(path.join(repoRoot, '.tmp/mutation/envelope-test-shards'), {
138+
recursive: true,
139+
force: true,
140+
});
141+
});
142+
93143
test('both mutation lanes publish the envelope', () => {
94144
for (const name of ['mutation-weekly.yml', 'mutation-affected.yml']) {
95145
assert.match(

‎scripts/mutation/run.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ function readReport(file: string): StrykerReport {
262262

263263
function readShardedReports(dir: string): StrykerReport {
264264
const root = path.isAbsolute(dir) ? dir : path.join(repoRoot, dir);
265+
// Shard artifacts also carry the lane envelope and the derived test scope, so
266+
// the report is selected by name rather than by "every .json here".
265267
const files = fs
266-
.globSync('**/*.json', { cwd: root })
267-
.filter((file) => !file.endsWith('proposed-baseline.json') && !file.endsWith('test-scope.json'))
268+
.globSync(`**/${path.basename(DEFAULT_REPORT_PATH)}`, { cwd: root })
268269
.map((file) => path.join(root, file))
269270
.sort();
270271
if (files.length === 0) throw new Error(`No Stryker JSON reports found under ${dir}`);

0 commit comments

Comments
 (0)