From 4d42185b0fea3a19326ba68ea6937051f7bc5cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= <35082514+alezmad@users.noreply.github.com> Date: Mon, 4 May 2026 13:06:40 +0100 Subject: [PATCH] test(cli): tolerate exit 2 in whoami --json golden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit whoami --json exits with EXIT.AUTH_FAILED (=2) when not signed in. The JSON output is the contract under test, valid regardless of exit code — execSync was throwing on exit 2 so the assertion never ran. Switch to spawnSync, accept {0,2}, parse stdout independently. Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/cli/tests/golden/whoami.test.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/cli/tests/golden/whoami.test.ts b/apps/cli/tests/golden/whoami.test.ts index ad96e10..c81fd65 100644 --- a/apps/cli/tests/golden/whoami.test.ts +++ b/apps/cli/tests/golden/whoami.test.ts @@ -1,14 +1,18 @@ import { describe, it, expect } from "vitest"; -import { execSync } from "node:child_process"; +import { spawnSync } from "node:child_process"; import { resolve } from "node:path"; const CLI = resolve(__dirname, "../../dist/entrypoints/cli.js"); describe("golden: whoami --json", () => { it("outputs schema_version 1.0 when not signed in", () => { + // `whoami --json` exits 2 (EXIT.AUTH_FAILED) when not signed in. + // The JSON is still valid output and the contract under test — + // capture stdout independently of exit code. const env = { ...process.env, CLAUDEMESH_CONFIG_DIR: "/tmp/claudemesh-golden-test-" + Date.now() }; - const output = execSync(`node ${CLI} whoami --json`, { encoding: "utf-8", env }).trim(); - const json = JSON.parse(output); + const result = spawnSync("node", [CLI, "whoami", "--json"], { encoding: "utf-8", env }); + expect([0, 2]).toContain(result.status); + const json = JSON.parse(result.stdout.trim()); expect(json.schema_version).toBe("1.0"); expect(json.signed_in).toBe(false); });