test(router-eval): give spawned CLI children an explicit DATA_DIR

The router-eval CLI test spawns the CLI with spawnSync and asserts stderr stays empty. NODE_TEST_CONTEXT is inherited by those children, so since #10432 (guard #10428) resolveWritableDataDir() detects a test context with no DATA_DIR and warns on stderr before falling back to a throwaway dir - 194 chars that broke three cases. Pass an isolated DATA_DIR in the child env (the resolution the guard message itself prescribes) instead of loosening the assertions.
This commit is contained in:
diegosouzapw
2026-08-25 08:05:31 +00:00
parent 93c798c694
commit 7de2643243

View File

@@ -8,7 +8,7 @@
// limitation, not a defect in the code under test: the OmniRoute runtime itself
// cascades to node:sqlite/sql.js when better-sqlite3 is unavailable. See
// tests/unit/_helpers/betterSqlite3Availability.ts for a guard helper.
import test from "node:test";
import test, { after } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, readFileSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
@@ -18,9 +18,19 @@ import Database from "better-sqlite3";
const scriptPath = "scripts/router-eval/index.ts";
// #10432 (guard #10428) made every process that detects a test context but has no
// explicit DATA_DIR warn on stderr before falling back to a throwaway dir.
// `NODE_TEST_CONTEXT` is inherited by the children spawned below, so the CLI printed
// that warning and broke the "stderr stays empty" assertions. Give every child its own
// DATA_DIR — the exact resolution the guard message prescribes — instead of loosening
// the assertions.
const cliDataDir = mkdtempSync(join(tmpdir(), "router-eval-cli-datadir-"));
after(() => rmSync(cliDataDir, { recursive: true, force: true }));
function runCli(args: string[]) {
return spawnSync(process.execPath, ["--import", "tsx", scriptPath, ...args], {
encoding: "utf8",
env: { ...process.env, DATA_DIR: cliDataDir },
});
}