From 7fb88739e539ad0eec5e4a0240382ce208609cf5 Mon Sep 17 00:00:00 2001 From: JSONbored <49853598+JSONbored@users.noreply.github.com> Date: Sat, 25 Jul 2026 02:32:34 -0700 Subject: [PATCH] fix(rees): run REES coverage's test child from review-enrichment/ spawnSync ran c8 and the node:test child it wraps with the same cwd (the monorepo root), needed so c8's lcov SF: paths remap to review-enrichment/src/** for Codecov. But that left the actual test process running from the wrong directory, so tests that read fixtures via bare relative paths (e.g. analyzer-metadata.test.ts reading "analyzer-metadata.json") failed with ENOENT even though the fixture exists at review-enrichment/analyzer-metadata.json. Preload a small --require script into only the spawned test child to chdir it into review-enrichment/ before node:test loads any files, leaving c8's own process cwd (and therefore its SF: path remapping) untouched. Test file arguments switch from root-relative to absolute paths since they're now resolved from a different cwd. --- scripts/rees-coverage-chdir.cjs | 8 ++++++++ scripts/rees-coverage.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 scripts/rees-coverage-chdir.cjs diff --git a/scripts/rees-coverage-chdir.cjs b/scripts/rees-coverage-chdir.cjs new file mode 100644 index 0000000000..e19c9dc8c4 --- /dev/null +++ b/scripts/rees-coverage-chdir.cjs @@ -0,0 +1,8 @@ +// Preloaded via --require before node:test loads review-enrichment's test files. +// c8 (the parent process) must keep its own cwd at the monorepo root so lcov SF: paths +// remap to `review-enrichment/src/**` for Codecov (#6250); this only chdir's the spawned +// test child, so tests that read fixtures with bare relative paths (e.g. "analyzer-metadata.json") +// resolve them against review-enrichment/, matching `npm run test:node`. +const { join } = require("node:path"); + +process.chdir(join(__dirname, "..", "review-enrichment")); diff --git a/scripts/rees-coverage.ts b/scripts/rees-coverage.ts index 5752f065ce..1fc9e084f0 100644 --- a/scripts/rees-coverage.ts +++ b/scripts/rees-coverage.ts @@ -3,7 +3,7 @@ // (not bare `src/**`), and expands the test list in-process so Windows/npm quoting cannot drop the suite. import { spawnSync } from "node:child_process"; import { readFileSync, readdirSync, writeFileSync } from "node:fs"; -import { join, relative } from "node:path"; +import { join } from "node:path"; import { fileURLToPath, URL } from "node:url"; /** Normalize c8's SF: paths to forward slashes for Codecov. Swallows only a missing report @@ -39,8 +39,10 @@ function main() { const c8Bin = join(root, "review-enrichment", "node_modules", "c8", "bin", "c8.js"); const reportDir = join(root, "review-enrichment", "coverage"); const testRoot = join(root, "review-enrichment", "test"); + const chdirPreload = join(root, "scripts", "rees-coverage-chdir.cjs"); - const tests = collectTests(testRoot).map((path) => relative(root, path).split("\\").join("/")); + // Absolute paths: the test child's cwd is review-enrichment/ (see chdirPreload), not root. + const tests = collectTests(testRoot).map((path) => path.split("\\").join("/")); if (tests.length === 0) { console.error("rees-coverage: no review-enrichment/test/**/*.test.ts files found"); process.exit(1); @@ -57,6 +59,8 @@ function main() { "--exclude=**/*.d.ts", "--all", process.execPath, + "--require", + chdirPreload, "--test", "--experimental-strip-types", ...tests,