From 7ac20a0b59b69f06c57a4f2abb6d0b68c24828b4 Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 8 Oct 2026 12:07:45 +0200 Subject: [PATCH] test(client): pin the exit codes of the ratchet commands Every ratchet command hands its check to runCli, which sets the exit code from the check's result and turns a failure of the check itself (a missing or broken baseline, a directory that is not there) into a printed FAIL and exit 1. The test runs runCli in a separate node process, as CI does, and also pins that an unexpected exception still ends the run with a non-zero code. --- client/tests/unit/scripts/ratchet.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/tests/unit/scripts/ratchet.test.ts b/client/tests/unit/scripts/ratchet.test.ts index 0dc3ce67e..ccaecb4b6 100644 --- a/client/tests/unit/scripts/ratchet.test.ts +++ b/client/tests/unit/scripts/ratchet.test.ts @@ -1,3 +1,6 @@ +import { spawnSync } from 'node:child_process'; +import { resolve } from 'node:path'; +import { pathToFileURL } from 'node:url'; import { afterEach, describe, expect, it } from 'vitest'; import { countMap, @@ -79,4 +82,20 @@ describe('scripts/lib/ratchet', () => { it('RATCHET-008: a file list only loses the files that stopped offending', () => { expect(lowerList(['a', 'b', 'c'], ['c', 'a', 'new'])).toEqual(['a', 'c']); }); + + it('RATCHET-009: a command exits with what its check returns, and 1 when the check itself fails', () => { + const lib = pathToFileURL(resolve('scripts/lib/ratchet.mjs')).href; + const command = (body: string) => + spawnSync( + process.execPath, + ['--input-type=module', '-e', `import { runCli, RatchetError } from '${lib}'; await runCli('lint:x', ${body})`], + { encoding: 'utf8' } + ); + expect(command('() => 0').status).toBe(0); + expect(command('async () => 1').status).toBe(1); + const broken = command("() => { throw new RatchetError('baseline gone') }"); + expect(broken.status).toBe(1); + expect(broken.stderr).toContain('FAIL lint:x: baseline gone'); + expect(command("() => { throw new Error('bug') }").status).not.toBe(0); + }); });