test(cli): deflake setup-claude.test.ts — silence console to stop stdout/report interleaving (#5959) (#6019)

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).
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-07-02 22:45:37 -03:00
committed by GitHub
parent 6756fa8e54
commit cfa3686f9f
2 changed files with 24 additions and 1 deletions

View File

@@ -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 <KooshaPari@users.noreply.github.com>
---

View File

@@ -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", () => {