From c36f234da2eecad3e527ebefdd55d0404d70db00 Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Thu, 25 Jun 2026 22:30:57 -0700 Subject: [PATCH] Address PR review feedback (#1785) - P2 (greptile): anchor the changed-test existence check at the git repo root (repoRootForExistence via `git rev-parse --show-toplevel`) instead of rootDir, so a script run from a package subdir without FUSION_PROJECT_DIR no longer forms a doubled path and silently drops live tests into the delegate path. +1 regression test (default root resolves to repo root). - coderabbit: fix stale "1-worker lane" wording in the delegation log (now "heavy memory-envelope lane") and the "single-worker envelope" test title, both stale after the 1->4 worker change. test-changed 118/118, eslint clean. Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/__tests__/test-changed.test.mjs | 10 +++++++++- scripts/test-changed.mjs | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/__tests__/test-changed.test.mjs b/scripts/__tests__/test-changed.test.mjs index b0da039c2d..062ddada37 100644 --- a/scripts/__tests__/test-changed.test.mjs +++ b/scripts/__tests__/test-changed.test.mjs @@ -370,7 +370,7 @@ test("@fusion/core is a wide-fan-out memory-envelope package but is NOT gate-cov ); }); -test("core scoped-affected env applies the bounded heap and single-worker envelope", () => { +test("core scoped-affected env applies the bounded heap and worker envelope", () => { const env = createScopedAffectedMemoryEnvelopeEnv(CORE_SCOPED_AFFECTED_PACKAGE, { NODE_OPTIONS: "--trace-warnings", HOME: "/tmp/fusion-home", @@ -1976,6 +1976,14 @@ test("existingChangedTestFilesInPackage: excludes non-test and out-of-package pa } }); +// FNXC:TestInfrastructure 2026-06-26-13:40: regression for the doubled-path subdir +// bug — with NO projectRoot passed, the existence root must resolve to the git repo +// root (not cwd), so a real repo-relative test path is found from any cwd. +test("existingChangedTestFilesInPackage: default existence root anchors at the git repo root", () => { + const selfRel = "scripts/__tests__/test-changed.test.mjs"; // this very file — guaranteed on disk + assert.deepEqual(existingChangedTestFilesInPackage([selfRel], "scripts"), [selfRel]); +}); + // FNXC:TestInfrastructure 2026-06-26-09:15: the merge gate re-covers a delegated // engine lane (curated engine-core subset) but runs NO dashboard tests. Lock that // asymmetry so the delegation messaging never overclaims dashboard gate coverage. diff --git a/scripts/test-changed.mjs b/scripts/test-changed.mjs index b7df291da1..f8c6a326ba 100644 --- a/scripts/test-changed.mjs +++ b/scripts/test-changed.mjs @@ -1469,7 +1469,26 @@ handing Vitest an empty/garbage positional set. * @param {{ projectRoot?: string }} [opts] * @returns {string[]} */ -export function existingChangedTestFilesInPackage(changedFiles, pkgDir, { projectRoot = rootDir } = {}) { +/* +FNXC:TestInfrastructure 2026-06-26-13:40: +Existence checks for changed test files must anchor at the GIT REPO ROOT, not +`rootDir` (which falls back to `process.cwd()`). `git diff --name-only` returns +repo-root-relative paths regardless of the cwd it runs from, so joining them +against a `rootDir` that is a package SUBDIR (script run from a package without +FUSION_PROJECT_DIR) would form a doubled path (packages/x/packages/x/...), make +`existsSync` false, and silently DROP live changed tests into the delegate path. +Resolve the toplevel once via git so the check is correct from any cwd inside the +repo; fall back to rootDir if git can't report a toplevel. +*/ +let _repoToplevelCache; +function repoRootForExistence() { + if (_repoToplevelCache !== undefined) return _repoToplevelCache; + const top = gitOutput(["rev-parse", "--show-toplevel"]); + _repoToplevelCache = top && top.trim() ? top.trim() : rootDir; + return _repoToplevelCache; +} + +export function existingChangedTestFilesInPackage(changedFiles, pkgDir, { projectRoot = repoRootForExistence() } = {}) { return (changedFiles ?? []).filter( (file) => isTestFilePath(file) && @@ -1794,7 +1813,7 @@ export async function main(argv = process.argv.slice(2)) { const log = gateCovered ? console.log : console.warn; log( `[test-changed] ${pkg}: a changed non-test source file (${wideSourceDesc}) ` + - "would fan `vitest --changed` out to ~the full suite at this heavy 1-worker lane; " + + "would fan `vitest --changed` out to ~the full suite at this heavy memory-envelope lane; " + `no directly-changed ${pkg} test file to run, so ${delegationNote}`, ); continue;