From a85122100da5fa49a90466a8493b6233c6d2e562 Mon Sep 17 00:00:00 2001 From: Huyvux12 Date: Fri, 20 Nov 2026 05:01:54 +0000 Subject: [PATCH] Fix #4550: a quarantined test skipped on the final attempt is a quarantined-fail A live quarantined test that never runs was dropped from the outcomes entirely, so gstack-flaky exited 0 with quarantined=0 and no ledger entry. The same happened when a whole-command retry skipped it after a first-run pass, and the quarantine report counted that run toward the clean streak. quarantinedStatus now requires the final attempt to be a pass, and runFlaky settles every non-failed quarantined test instead of filtering out all-skip reports, so both cases yield quarantined-fail, exit 1 and a ledger entry recording the skip. A test skipped first but passing on the retry still counts as a pass, and an ordinary skip still follows the runner verdict. --- docs/flaky.md | 2 +- lib/flaky-run.ts | 19 ++++++++++++++----- test/flaky-run.test.ts | 9 +++++++++ test/quarantine.test.ts | 29 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/docs/flaky.md b/docs/flaky.md index eeea3e8ab25..50c61f623f9 100644 --- a/docs/flaky.md +++ b/docs/flaky.md @@ -90,7 +90,7 @@ live quarantined test, and nothing else is wrong with that attempt (no kill, no failure outside the report, no first-run test missing), the whole command may run again, up to 3 attempts in total. The run is green only when one of those attempts is fully green. A quarantined test that fails all 3 is a **hard -break**, and the run is red. A test that is not quarantined keeps its one +break**, and the run is red. A quarantined test that is skipped on the final attempt is a **quarantined-fail**, and the run is red: a skip is not a run, so it never counts toward the clean streak. A test that is not quarantined keeps its one rerun. A red attempt never turns green because its only reported failure is a quarantined test, because the runner's exit status can come from things the report does not show (a coverage threshold, a fail-on-flaky policy, a global diff --git a/lib/flaky-run.ts b/lib/flaky-run.ts index f54db225565..4e3d232af70 100644 --- a/lib/flaky-run.ts +++ b/lib/flaky-run.ts @@ -297,10 +297,12 @@ function mayRunAgain(again: Ran, first: JunitReport, quarantined: ReadonlySet [...t.attempts, ...runs.flatMap(r => r.report?.tests.find(x => x.id === t.id)?.attempts ?? ['fail' as const])]; -/** A quarantined test passes only when it never failed or an attempt with the runner's full verdict cleared it. */ +/** A quarantined test passes only when its final attempt passed and it never failed, or an attempt with the runner's full verdict cleared it. A skip on the final attempt is not a run, so it fails; a test that failed every attempt is a hard break. */ const quarantinedStatus = (attempts: string[], cleared: boolean): 'quarantined-pass' | 'quarantined-fail' | 'hard-break' => - cleared || !attempts.includes('fail') ? 'quarantined-pass' - : attempts.length >= QUARANTINE_ATTEMPTS && attempts.every(a => a === 'fail') ? 'hard-break' : 'quarantined-fail'; + attempts.length >= QUARANTINE_ATTEMPTS && attempts.every(a => a === 'fail') ? 'hard-break' + : attempts.at(-1) !== 'pass' ? 'quarantined-fail' + : cleared || !attempts.includes('fail') ? 'quarantined-pass' + : 'quarantined-fail'; export async function runFlaky(opts: RunOptions): Promise { const cwd = opts.cwd ?? process.cwd(); @@ -363,7 +365,8 @@ export async function runFlaky(opts: RunOptions): Promise { if (why) settle(t, t.attempts, why); else eligible.push(t); } - const passedQ = report.tests.filter(t => isQ(t) && finalAttempt(t) !== 'fail' && t.attempts.some(a => a !== 'skip')); + // A quarantined test whose final attempt is a skip never ran on the attempt that decided the run; it is settled below as a quarantined-fail, not dropped silently. + const settledQ = report.tests.filter(t => isQ(t) && finalAttempt(t) !== 'fail'); const wholeRerun = !eligible.length ? undefined : opts.rerunScope !== 'test' ? 'the default; --rerun-scope test reruns the failed test alone' : incompleteRun(report.runner, first.output, first.exit, opts.command, runnerFlaky.length) ?? undefined; @@ -409,7 +412,13 @@ export async function runFlaky(opts: RunOptions): Promise { if (reruns) fs.writeFileSync(junit, firstXml); } const green = runs.length ? fullGreen(runs.at(-1)!, report) : reruns > 0 || first.exit === 0; - for (const t of passedQ) settleQ(t, history(t, runs), green, 'the attempt that decided the run was not a full green run', runs.length ? 'command' : undefined); + for (const t of settledQ) { + const attempts = history(t, runs); + const reason = attempts.at(-1) === 'skip' + ? 'quarantined, and skipped on the final attempt instead of running' + : 'the attempt that decided the run was not a full green run'; + settleQ(t, attempts, green, reason, runs.length ? 'command' : undefined); + } const red = !green || outcomes.some(o => !PASSING.has(o.status)); const q = outcomes.filter(o => o.status === 'quarantined-pass' || o.status === 'quarantined-fail' || o.status === 'hard-break').length; return { exitCode: red ? 1 : 0, tests: report.tests.length, commandExit: first.exit, outcomes, reruns, quarantined: q, ...(wholeRerun && reruns ? { wholeRerun } : {}), ledger }; diff --git a/test/flaky-run.test.ts b/test/flaky-run.test.ts index cd8f2e5b8ef..978050525b4 100644 --- a/test/flaky-run.test.ts +++ b/test/flaky-run.test.ts @@ -119,6 +119,7 @@ function fakeRun(reports: (argv: string[], n: number) => string | null, exits: ( const suite = (cases: string) => `${cases}`; const pass = (name: string) => ``; const fail = (name: string, msg = 'boom') => ``; +const skip = (name: string) => ``; describe('runFlaky', () => { const base = (spawn: ReturnType, dir: string, extra: Partial[0]> = {}) => @@ -131,6 +132,14 @@ describe('runFlaky', () => { expect(f.calls).toHaveLength(1); }); + test('an ordinary skipped test still follows the runner verdict', async () => { + const dir = tmp(); + const f = fakeRun(() => suite(skip('s') + pass('a')), () => 0); + const r = await base(f, dir); + expect(r).toMatchObject({ exitCode: 0, quarantined: 0, reruns: 0, ledger: [], outcomes: [] }); + expect(f.calls).toHaveLength(1); + }); + test('a coverage failure beside a flaky test is not cleared by a narrowed rerun', async () => { const dir = tmp(); const cov = () => '----|---------|---------|\nAll files | % Funcs | % Lines |\nRan 2 tests across 1 file.\n'; diff --git a/test/quarantine.test.ts b/test/quarantine.test.ts index 6d4b2ff20eb..d25b391d907 100644 --- a/test/quarantine.test.ts +++ b/test/quarantine.test.ts @@ -219,6 +219,7 @@ function fakeRun(reports: (n: number, argv: string[]) => string | null, exits: ( const suite = (cases: string, file = 'a.test.ts') => `${cases}`; const pass = (name: string) => ``; const fail = (name: string) => ``; +const skip = (name: string) => ``; const Q = new Set(['a.test.ts::::q']); const run = (f: ReturnType, extra: Partial[0]> = {}) => runFlaky({ command: ['bun', 'test'], junit: 'r.xml', maxReruns: 3, cwd: tmp(), spawn: f.spawn, env: {}, now: () => NOW, quarantined: Q, ...extra }); @@ -307,6 +308,34 @@ describe('the quarantine attempt budget under the full green verdict', () => { expect(renderResult(r, '/l').at(-1)).toContain('failed=0 flaky=0 quarantined=1'); }); + test('a quarantined test that never runs is a quarantined-fail, not a silent pass', async () => { + const f = fakeRun(() => suite(skip('q') + pass('a')), () => 0); + const r = await run(f); + expect(f.calls).toHaveLength(1); + expect(r.exitCode).toBe(1); + expect(r.outcomes).toMatchObject([{ status: 'quarantined-fail', attempts: ['skip'], reason: 'quarantined, and skipped on the final attempt instead of running' }]); + expect(r.ledger).toMatchObject([{ kind: 'quarantined-fail', id: 'a.test.ts::::q', attempts: ['skip'] }]); + expect(renderResult(r, '/l').at(-1)).toBe('FLAKY_RESULT: tests=2 failed=1 flaky=0 quarantined=1 reruns=0 command_exit=0 verdict=fail ledger=/l'); + }); + + test('a quarantined test skipped on the whole-command retry is not a clean pass', async () => { + const f = fakeRun(n => n === 1 ? suite(pass('q') + fail('a')) : suite(skip('q') + pass('a')), n => n === 1 ? 1 : 0); + const r = await run(f); + expect(f.calls).toHaveLength(2); + expect(r.exitCode).toBe(1); + expect(r.outcomes.find(o => o.test.id.endsWith('::q'))).toMatchObject({ status: 'quarantined-fail', attempts: ['pass', 'skip'] }); + expect(r.ledger.find(l => l.id.endsWith('::q'))).toMatchObject({ kind: 'quarantined-fail', attempts: ['pass', 'skip'] }); + expect(r.outcomes.find(o => o.test.id.endsWith('::a'))).toMatchObject({ status: 'flaky-pass', attempts: ['fail', 'pass'] }); + }); + + test('a quarantined test skipped first but passing on the whole-command retry counts as a pass', async () => { + const f = fakeRun(n => n === 1 ? suite(skip('q') + fail('a')) : suite(pass('q') + pass('a')), n => n === 1 ? 1 : 0); + const r = await run(f); + expect(f.calls).toHaveLength(2); + expect(r.exitCode).toBe(0); + expect(r.outcomes.find(o => o.test.id.endsWith('::q'))).toMatchObject({ status: 'quarantined-pass', attempts: ['skip', 'pass'] }); + }); + test('quarantined failures do not count against --max-reruns', async () => { const f = fakeRun(n => suite(pass('a') + (n === 1 ? fail('q') : pass('q'))), n => n === 1 ? 1 : 0); expect((await run(f, { maxReruns: 0 })).exitCode).toBe(0);