From cfa3686f9f05dcfbfb42f032724d20894bcfccd4 Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com> Date: Thu, 2 Jul 2026 22:45:37 -0300 Subject: [PATCH] =?UTF-8?q?test(cli):=20deflake=20setup-claude.test.ts=20?= =?UTF-8?q?=E2=80=94=20silence=20console=20to=20stop=20stdout/report=20int?= =?UTF-8?q?erleaving=20(#5959)=20(#6019)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Integrated into release/v3.8.44. Deflakes tests/unit/cli/setup-claude.test.ts (#5959) β€” verified in CI: setup-claude now passes in Unit Tests fast-path (2/2). Merged with --admin over two PRE-EXISTING base-reds proven independent of this test-only change (this PR only touches setup-claude.test.ts + CHANGELOG): - Fast Quality Gates β†’ check:test-discovery: tests/unit/executors/{firecrawl-fetch,xai-executor}.test.ts are orphaned on release/v3.8.44 (added by #5793/#5800); the shard glob 'tests/unit/{api,...,ui}/**' omits 'executors'. Both blobs exist on the pristine base. - Unit Tests fast-path (2/2): tests/unit/settings-i18n-keys.test.ts β†’ 'direct translation calls have English messages' fails on the pristine base too (unrelated i18n base-red). --- CHANGELOG.md | 2 ++ tests/unit/cli/setup-claude.test.ts | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9875a3d6cb..17506c549e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ _TBD_ ### πŸ“ Maintenance +- **test (deflake `setup-claude`):** `tests/unit/cli/setup-claude.test.ts` failed ~50% of runs with `Unable to deserialize cloned data due to invalid or unsupported version` at file teardown (all subtests passed), randomly reddening `Unit Tests fast-path (2/2)` / `Fast Quality Gates` across the PRβ†’release queue. Root cause: `node --test` streams each file's report to the parent as V8-serialized frames on fd 1 (stdout), and the CLI helper under test (`syncClaudeProfilesFromModels`) prints progress via `console.log` β€” that stdout output interleaved with the serialized frames and corrupted the stream. The test now silences the stdout-writing `console` methods for the file's duration (no assertion inspects stdout), making it deterministic (15/15 green locally). ([#5959](https://github.com/diegosouzapw/OmniRoute/issues/5959)) + - **API validation:** add a `validatedJsonBody(request, schema)` helper in `src/shared/validation/helpers.ts` that fuses JSON body parsing and Zod validation into a single call, returning either the type-narrowed data or a ready-to-return 400 `NextResponse` with the standard error envelope. Salvaged from the closed refactor PR #5075 (Tier 1 portable helper) with a focused 6-case regression test. Co-authored-by: KooshaPari --- diff --git a/tests/unit/cli/setup-claude.test.ts b/tests/unit/cli/setup-claude.test.ts index 5dec875335..d0fb28ed64 100644 --- a/tests/unit/cli/setup-claude.test.ts +++ b/tests/unit/cli/setup-claude.test.ts @@ -1,4 +1,4 @@ -import { test } from "node:test"; +import { test, before, after } from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs/promises"; import os from "node:os"; @@ -10,6 +10,27 @@ import { import { buildClaudeEnv, resolveLaunchTarget } from "../../../bin/cli/commands/launch.mjs"; import { categoriseModel } from "../../../bin/cli/commands/setup-codex.mjs"; +// #5959 β€” deflake: `node --test` runs each file in a child process that streams +// its report back to the parent as V8-serialized frames on fd 1 (stdout). The CLI +// helpers under test (`syncClaudeProfilesFromModels`) print progress via +// `console.log`, and that stdout output interleaves with the serialized frames, +// corrupting the stream β€” the parent then throws +// "Unable to deserialize cloned data due to invalid or unsupported version" at +// file teardown ~50% of runs (all subtests pass; only the file errors). No test +// here asserts on stdout, so silence the stdout-writing console methods for the +// duration of this file. Restored in `after` for good hygiene. +const _console = { log: console.log, info: console.info, warn: console.warn }; +before(() => { + console.log = () => {}; + console.info = () => {}; + console.warn = () => {}; +}); +after(() => { + console.log = _console.log; + console.info = _console.info; + console.warn = _console.warn; +}); + // ── setup-claude profile generation ────────────────────────────────────────── test("buildProfileSettings pins the model + base URL + gateway discovery", () => {