Skip to content

Commit 6066a4b

Browse files
beyondnetPeruclaude
andcommitted
fix(cli): stop tests from leaking jest's own exit code
With coverage finally over the line, the Unit Tests job stayed red — 1250 tests passing, branches 75.54% against a 75% threshold, and jest still exiting 1 with no failure printed anywhere. The difference was `--runInBand`, which is how CI runs and how nobody runs locally. Without workers every suite shares jest's process, so a command that sets `process.exitCode = 1` to carry its verdict (ADR-0073) leaves it set for the rest of the run. In worker mode the same test is harmless, which is exactly why this only ever appeared in CI. Worth stating plainly: the leak in `scaffold.command.spec.ts` PREDATES this session's coverage work — it reproduces on HEAD~1. So the Unit Tests job could not have gone green even at 100% coverage; the coverage gate was taking the blame for two failures while hiding one of them. The `update` spec picked up the same leak from the tests added yesterday. Fixed once, in `setupFilesAfterEnv`, rather than in the two specs that happen to leak today. A unit test setting the runner's exit code is always an artifact and never a signal — jest reports real failures on its own — so restoring it after every test makes the whole class impossible instead of waiting for the next command to reintroduce it. Refs GT-562 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7cffd73 commit 6066a4b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/sdk/cli/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
'^conf$': '<rootDir>/src/test/__mocks__/conf.ts',
4545
'^chokidar$': '<rootDir>/src/test/__mocks__/chokidar.ts',
4646
},
47-
setupFilesAfterEnv: [],
47+
setupFilesAfterEnv: ['<rootDir>/src/test/reset-exit-code.setup.ts'],
4848
testTimeout: 10000,
4949
verbose: true,
5050
// OPP-003: Suppress console noise during tests for cleaner output
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Impide que un test filtre el codigo de salida del propio jest.
3+
*
4+
* Los comandos del CLI señalan su veredicto con `process.exitCode = 1` (ADR-0073:
5+
* el exit code transporta el veredicto). Bajo `--runInBand` -- que es como corre
6+
* CI -- no hay workers: todas las suites comparten el proceso de jest, asi que
7+
* ese `1` sobrevive al test que lo puso y jest termina en 1 con 1250 pruebas en
8+
* verde y la cobertura por encima del umbral. En modo worker el mismo test pasa
9+
* inadvertido, y por eso el defecto solo aparecia en CI.
10+
*
11+
* El valor se restaura despues de CADA test. Que un test unitario fije el codigo
12+
* de salida del runner es siempre un artefacto, nunca una señal: los fallos
13+
* reales los reporta jest por su cuenta. Se resuelve aqui, y no en las dos specs
14+
* que hoy filtran, para que la clase entera de fuga deje de ser posible.
15+
*/
16+
const original = process.exitCode;
17+
18+
afterEach(() => {
19+
process.exitCode = original;
20+
});

0 commit comments

Comments
 (0)