diff --git a/docs/METHODOLOGY.md b/docs/METHODOLOGY.md index 7476f61c65..96a289ce92 100644 --- a/docs/METHODOLOGY.md +++ b/docs/METHODOLOGY.md @@ -159,8 +159,11 @@ wrapper, failed lookups and the interpreter, and `ci` counted most tools against npm's lockfile. Until issue #214, the lockfile, `node_modules` and cache variations counted each tool from what earlier tools left, not its own lockfile, `node_modules` or cache, and upm, which refuses more than one -lockfile, had no count in the lockfile variations. Don't compare them with -later counts. +lockfile, had no count in the lockfile variations. Until November 2026, +cleaning `node_modules` left the workspaces' `node_modules` behind on +`babylon`, so in the lockfile and cache variations every tool but the first +started from what earlier tools had put there, and npm's `lockfile` count was +missing. Don't compare them with later counts. ## Variations diff --git a/suite/scripts/clean-helpers.sh b/suite/scripts/clean-helpers.sh index 978676e19c..5e27938a19 100644 --- a/suite/scripts/clean-helpers.sh +++ b/suite/scripts/clean-helpers.sh @@ -211,10 +211,17 @@ clean_package_manager_field() { fi } -# Function to clean node_modules directory +# Function to clean the node_modules directories: the project's and every +# workspace's. On a monorepo (babylon), vlt, pnpm, bun and the yarns also +# write packages/*/node_modules; vlt fills them with symlinks into the root +# node_modules/.vlt store. Removing only the root left those behind, dangling, +# for the next tool: npm's lockfile install then fails with +# "Invalid Version: ". Hidden directories (.aube, .upm-store, ...) are the +# tools' own stores, which clean_package_manager_files removes whole. clean_node_modules() { - echo "Cleaning node_modules directory..." - safe_remove "node_modules" + echo "Cleaning node_modules directories..." + find . -mindepth 1 \( -name '.*' -prune \) -o \ + -type d -name node_modules -prune -exec rm -rf {} + || true } # Function to clean transient package manager artifacts. diff --git a/suite/scripts/clean-helpers.test.js b/suite/scripts/clean-helpers.test.js index 1d8fc9dfbb..04d8036469 100644 --- a/suite/scripts/clean-helpers.test.js +++ b/suite/scripts/clean-helpers.test.js @@ -87,6 +87,48 @@ safe_remove() { printf '%s\\n' "$1" >> "$REMOVE_LOG"; } }); } +test("clean_node_modules removes the workspaces' node_modules too, not the tools' stores", (t) => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "clean-node-modules-test-")); + t.after(() => fs.rmSync(dir, { recursive: true, force: true })); + const files = [ + "node_modules/.vlt/a/node_modules/a/package.json", + "packages/dev/core/node_modules/.bin/a", + "packages/dev/core/src/index.ts", + "packages/public/@scope/gui/node_modules/@scope/core/package.json", + "packages/public/@scope/gui/package.json", + ".aube/store/node_modules/b/package.json", + ".upm-store/b/node_modules/b/package.json", + ]; + for (const file of files) { + fs.mkdirSync(path.dirname(path.join(dir, file)), { recursive: true }); + fs.writeFileSync(path.join(dir, file), ""); + } + // what vlt leaves once the root node_modules is gone: a dangling symlink + fs.symlinkSync( + "../../../../node_modules/.vlt/a/node_modules/a", + path.join(dir, "packages/dev/core/node_modules/a"), + ); + + const result = spawnSync( + "bash", + ["-c", `source "$HELPERS" >/dev/null; clean_node_modules`], + { + cwd: dir, + encoding: "utf8", + env: { ...process.env, HELPERS: path.join(__dirname, "clean-helpers.sh") }, + }, + ); + assert.equal(result.status, 0, result.stderr); + const exists = (file) => fs.existsSync(path.join(dir, file)); + assert.equal(exists("node_modules"), false); + assert.equal(exists("packages/dev/core/node_modules"), false); + assert.equal(exists("packages/public/@scope/gui/node_modules"), false); + assert.equal(exists("packages/dev/core/src/index.ts"), true); + assert.equal(exists("packages/public/@scope/gui/package.json"), true); + assert.equal(exists(".aube/store/node_modules/b/package.json"), true); + assert.equal(exists(".upm-store/b/node_modules/b/package.json"), true); +}); + // A stand-in for one of vlt's detached children: `sleep` copied to a file // with the given name, so pgrep sees that process name (truncated to 15 // characters, as Linux does), or a node script at a vlt-style path when diff --git a/suite/scripts/process-count.sh b/suite/scripts/process-count.sh index f6cefa8b52..7259f9230e 100644 --- a/suite/scripts/process-count.sh +++ b/suite/scripts/process-count.sh @@ -40,6 +40,8 @@ INSTALL_CMD="$3" PREPARE_CMD="${4:-}" STRACE_LOG="$OUTPUT_FOLDER/${PM_NAME}-strace.log" +# The counted install's own output, kept so a failure explains itself. +INSTALL_LOG="$OUTPUT_FOLDER/${PM_NAME}-process-count-output.log" PROCESS_COUNT_FILE="$OUTPUT_FOLDER/${PM_NAME}-process-count.txt" # Ensure strace is available @@ -75,12 +77,15 @@ echo "[process-count] Running strace'd install for $PM_NAME..." EXIT_CODE=0 timeout -k 10 "${BENCH_TIMEOUT:-300}" \ strace -f -e trace=execve,execveat -o "$STRACE_LOG" \ - bash -c "$INSTALL_CMD" > /dev/null 2>&1 || EXIT_CODE=$? + bash -c "$INSTALL_CMD" > "$INSTALL_LOG" 2>&1 || EXIT_CODE=$? if [ "$EXIT_CODE" -ne 0 ]; then # strace passes the command's exit status through, but exits non-zero on its # own if it can't trace (e.g. no ptrace permission), so name both. echo "Warning: strace'd install exited with $EXIT_CODE for $PM_NAME, skipping process count" + echo "--- $INSTALL_LOG ---" + cat "$INSTALL_LOG" + echo "---" elif [ ! -f "$STRACE_LOG" ]; then echo "Warning: strace log not found for $PM_NAME" elif ! COUNT=$(node "$(dirname "$0")/count-processes.js" "$STRACE_LOG"); then