From 8ee17efc347241ef3e2e16052ef8958225b3dcb6 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Sun, 21 Jun 2026 13:20:44 +0000 Subject: [PATCH] test(cli): assert the force-exit forwards process.exitCode, not a hardcoded 1 (#2264) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing cases asserted process.exit(1), but since the error catch always sets exitCode=1 they couldn't distinguish forwarding (process.exit(process.exitCode ?? 1)) from a hardcoded 1. Add a case on the alreadyUpToDate path — which returns without setting exitCode or calling process.exit — with a pre-set exitCode=2 and isLbugReady forced true, asserting the wrapper force-exits with 2. Proves the exitCode-forwarding branch. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01JBJomjoTdBV2eveDVq4JMm --- .../analyze-finalize-failure-exits.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gitnexus/test/unit/analyze-finalize-failure-exits.test.ts b/gitnexus/test/unit/analyze-finalize-failure-exits.test.ts index f3aabdcba..013aa30a4 100644 --- a/gitnexus/test/unit/analyze-finalize-failure-exits.test.ts +++ b/gitnexus/test/unit/analyze-finalize-failure-exits.test.ts @@ -155,4 +155,25 @@ describe('analyzeCommand — finalize-failure must terminate, not hang (#2264 P1 expect(exitSpy).not.toHaveBeenCalled(); expect(process.exitCode).toBe(1); }); + + it('forwards a pre-set process.exitCode rather than the hardcoded fallback', async () => { + // The alreadyUpToDate path returns WITHOUT setting process.exitCode or calling + // process.exit (unlike the error catch, which always sets exitCode=1), so the + // wrapper's force-exit must forward whatever exitCode is already set — proving + // `process.exit(process.exitCode ?? 1)` reads exitCode and doesn't hardcode 1. + // isLbugReady is forced true to drive the wrapper's force-exit on this path. + isLbugReadyMock.mockReturnValue(true); + runFullAnalysisMock.mockResolvedValue({ + repoName: 'repo', + repoPath: '/repo', + stats: {}, + alreadyUpToDate: true, + ftsRepairedOnly: false, + pipelineResult: { communityResult: undefined }, + }); + assertAnalysisFinalizedMock.mockResolvedValue(undefined); + process.exitCode = 2; + await analyzeCommand(undefined, {}); + expect(exitSpy).toHaveBeenCalledWith(2); + }); });