Skip to content

Commit d2c36f9

Browse files
committed
fix(test): enforce diff dry-run exit code
1 parent fe07bc9 commit d2c36f9

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/commands/test.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,10 +3295,12 @@ describe('runDiff', () => {
32953295
expect(errs.join('\n')).toContain('different tests');
32963296
});
32973297

3298-
it('--dry-run returns the canned sample fully offline (no credentials, no fetch)', async () => {
3299-
// Dry-run must not require credentials or hit the network — it returns a
3300-
// canned CliRunDiff so `--dry-run` shows the shape offline.
3301-
const diff = await runDiff(
3298+
it('--dry-run prints the canned sample fully offline and exits 1 when verdicts differ', async () => {
3299+
// Dry-run must not require credentials or hit the network. It still emits a
3300+
// canned CliRunDiff so `--dry-run` shows the shape offline, then follows the
3301+
// same verdict-change exit contract as the real path.
3302+
const out: string[] = [];
3303+
const rejection = await runDiff(
33023304
{
33033305
profile: 'default',
33043306
output: 'json',
@@ -3307,8 +3309,15 @@ describe('runDiff', () => {
33073309
runA: 'run_aaa',
33083310
runB: 'run_bbb',
33093311
},
3310-
{ stdout: () => undefined, stderr: () => undefined },
3311-
);
3312+
{ stdout: line => out.push(line), stderr: () => undefined },
3313+
).catch((error: unknown) => error);
3314+
expect(rejection).toMatchObject({ exitCode: 1 });
3315+
const diff = JSON.parse(out.join('')) as {
3316+
runA: { runId: string };
3317+
runB: { runId: string };
3318+
verdictChanged: boolean;
3319+
changedSteps: Array<{ stepIndex: number; statusA: string; statusB: string }>;
3320+
};
33123321
expect(diff.runA.runId).toBe('run_aaa');
33133322
expect(diff.runB.runId).toBe('run_bbb');
33143323
expect(diff.verdictChanged).toBe(true);

src/commands/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,12 @@ export async function runDiff(opts: DiffOptions, deps: TestDeps = {}): Promise<C
39563956
changedSteps: [{ stepIndex: 2, statusA: 'passed', statusB: 'failed' }],
39573957
};
39583958
out.print(sample, () => renderRunDiffText(sample));
3959+
if (sample.verdictChanged) {
3960+
throw new CLIError(
3961+
`verdicts differ: ${sample.runA.runId}=${sample.runA.status} vs ${sample.runB.runId}=${sample.runB.status}`,
3962+
1,
3963+
);
3964+
}
39593965
return sample;
39603966
}
39613967

0 commit comments

Comments
 (0)