From 7d2535398102d11b9cd9fefaf985d6265800de5d Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 18 Nov 2026 09:13:29 +0000 Subject: [PATCH 1/2] suite: tidy-ups from the 2026-11-18 audit - registry-package-count.sh counted node_modules with a name pattern that skipped package names containing a dot (335 instead of 362 on next), so registry per-package times used a smaller count than the package-manager ones. Count by walking the graph with package-count.js, like package-count.sh; the per-registry -count.txt output is unchanged. - clean_berry_cache: drop the `corepack yarn@latest cache clean` line. Corepack is not on PATH since it got its own prefix (#211), so it never ran, and the safe_remove of berry's global folder covers cache and metadata both. - common.sh: the comment said npm, yarn classic and bun run install scripts by default; npm 12 blocks dependency scripts by default and bun skipped esbuild's postinstall without the flag too. Correct it, keep the flags. - clean_fixture_config (in clean_all): turbo's build on next appends `.turbo` to .gitignore, and the berry, zpm and vp prepares write a .yarnrc.yml that stays behind in fixtures that don't commit one (run). Restore tracked .gitignore/.yarnrc.yml from git, remove an untracked .yarnrc.yml. - registry/common.sh: give CLOUDSMITH_REGISTRY, GH_REGISTRY and JFROG_REGISTRY an empty default, so `--registries=npm` no longer aborts with "CLOUDSMITH_REGISTRY: unbound variable"; the selected registries are still checked for their variables. - clean_bun_cache: also remove $XDG_CACHE_HOME/.bun/install, where bun keeps its cache when XDG_CACHE_HOME is set; the hard-coded ~/.bun/install is the CI path only. The removes no longer depend on bun being on PATH. Tests for the registry count, the bun XDG path and clean_fixture_config. Co-Authored-By: Claude Opus 5.5 --- suite/scripts/clean-helpers.sh | 53 ++++++++--- suite/scripts/clean-helpers.test.js | 113 +++++++++++++++++++++++- suite/scripts/registry-package-count.sh | 10 +-- suite/scripts/registry/common.sh | 8 ++ suite/scripts/variations/common.sh | 9 +- 5 files changed, 170 insertions(+), 23 deletions(-) diff --git a/suite/scripts/clean-helpers.sh b/suite/scripts/clean-helpers.sh index f572589c90..89783224f0 100644 --- a/suite/scripts/clean-helpers.sh +++ b/suite/scripts/clean-helpers.sh @@ -29,13 +29,12 @@ clean_yarn_cache() { safe_remove "${XDG_CACHE_HOME:-$HOME/.cache}/yarn" } +# berry's cache and its metadata cache (packuments) both live in its global +# folder: ~/.yarn/berry, or under $XDG_DATA_HOME when that is set. Removing +# the folder covers both. `yarn cache clean --all` would leave the metadata +# behind (so cold runs skipped every packument download), and Corepack is not +# on PATH anyway since it got its own prefix (BENCH_COREPACK_BIN). clean_berry_cache() { - if command -v corepack &> /dev/null; then - corepack yarn@latest cache clean --all >/dev/null || true - fi - # `cache clean --all` leaves berry's metadata cache (packuments) in its - # global folder, so cold runs skipped every packument download. The global - # folder is ~/.yarn/berry, or under $XDG_DATA_HOME when that is set. safe_remove "$HOME/.yarn/berry" safe_remove "${XDG_DATA_HOME:-$HOME/.local/share}/yarn/berry" } @@ -114,12 +113,16 @@ clean_bun_cache() { if command -v bun &> /dev/null; then bun pm cache rm -g || true bun pm cache rm || true - # Remove the entire install directory (includes cache/ and metadata files) - safe_remove "$HOME/.bun/install" - # Also remove BUN_INSTALL_CACHE_DIR if set to a custom location - if [ -n "${BUN_INSTALL_CACHE_DIR:-}" ]; then - safe_remove "$BUN_INSTALL_CACHE_DIR" - fi + fi + # Remove the entire install directory (includes cache/ and metadata files): + # ~/.bun/install, or $XDG_CACHE_HOME/.bun/install when that is set. + safe_remove "$HOME/.bun/install" + if [ -n "${XDG_CACHE_HOME:-}" ]; then + safe_remove "$XDG_CACHE_HOME/.bun/install" + fi + # Also remove BUN_INSTALL_CACHE_DIR if set to a custom location + if [ -n "${BUN_INSTALL_CACHE_DIR:-}" ]; then + safe_remove "$BUN_INSTALL_CACHE_DIR" fi } @@ -312,11 +315,32 @@ clean_workspace_protocol() { fi } +# Tools also touch the fixture's config files: turbo's build on `next` appends +# `.turbo` to .gitignore (the `run` fixture already ignores it), and the berry, +# zpm and vp prepares write a .yarnrc.yml. Restore a tracked file to what is +# committed and remove an untracked one (next and babylon commit a .yarnrc.yml; +# the other fixtures don't), so the next tool starts from the fixture as +# committed. +clean_fixture_config() { + echo "Restoring fixture config files (.gitignore, .yarnrc.yml)..." + if command -v git &> /dev/null && git rev-parse --git-dir > /dev/null 2>&1; then + local file + for file in .gitignore .yarnrc.yml; do + if git ls-files --error-unmatch "$file" > /dev/null 2>&1; then + git checkout -- "$file" 2>/dev/null || true + elif [ -e "$file" ]; then + rm -f "$file" + fi + done + fi +} + clean_all() { clean_node_modules clean_lockfiles clean_package_manager_files clean_workspace_protocol + clean_fixture_config clean_all_cache # Strip packageManager / devEngines.packageManager AFTER the cache cleans, # so nothing they write survives: this must run last to guarantee a @@ -350,6 +374,8 @@ show_help() { echo " clean_all_cache" echo " clean_build_files" echo " clean_build_output" + echo " clean_workspace_protocol" + echo " clean_fixture_config" echo " clean_git" echo " clean_all" echo " wait_for_vlt_background" @@ -427,6 +453,9 @@ else clean_workspace_protocol) clean_workspace_protocol ;; + clean_fixture_config) + clean_fixture_config + ;; clean_git) clean_git ;; diff --git a/suite/scripts/clean-helpers.test.js b/suite/scripts/clean-helpers.test.js index 300533a914..6ef007f884 100644 --- a/suite/scripts/clean-helpers.test.js +++ b/suite/scripts/clean-helpers.test.js @@ -339,11 +339,15 @@ for (const [label, opts] of [ } // Record what a cleaner removes, without touching anything real. -const removedBy = (command, env = {}) => { +const removedBy = (command, env = {}, bins = {}) => { const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "cleaner-test-")); try { const removeLog = path.join(tempDir, "removed.txt"); fs.writeFileSync(removeLog, ""); + fs.mkdirSync(path.join(tempDir, "bin")); + for (const [name, script] of Object.entries(bins)) { + fs.writeFileSync(path.join(tempDir, "bin", name), script, { mode: 0o755 }); + } const result = spawnSync( "bash", ["-c", `source "$HELPERS" >/dev/null; safe_remove() { printf '%s\\n' "$1" >> "$REMOVE_LOG"; }; ${command}`], @@ -381,16 +385,119 @@ test("clean_zpm_cache removes ~/.yarn/zpm", () => { }); test("clean_berry_cache removes berry's global folder, with and without XDG_DATA_HOME", () => { - assert.deepEqual(removedBy("clean_berry_cache", { XDG_DATA_HOME: "" }).slice(-2), [ + assert.deepEqual(removedBy("clean_berry_cache", { XDG_DATA_HOME: "" }), [ "/home/runner/.yarn/berry", "/home/runner/.local/share/yarn/berry", ]); - assert.deepEqual(removedBy("clean_berry_cache", { XDG_DATA_HOME: "/xdg/data" }).slice(-2), [ + assert.deepEqual(removedBy("clean_berry_cache", { XDG_DATA_HOME: "/xdg/data" }), [ "/home/runner/.yarn/berry", "/xdg/data/yarn/berry", ]); }); +test("clean_bun_cache removes bun's install folder, under $HOME and under XDG_CACHE_HOME", () => { + // a `bun` that does nothing, so the test never touches a real bun cache + const bins = { bun: "#!/bin/sh\nexit 0\n" }; + assert.deepEqual(removedBy("clean_bun_cache", { XDG_CACHE_HOME: "" }, bins), [ + "/home/runner/.bun/install", + ]); + assert.deepEqual(removedBy("clean_bun_cache", { XDG_CACHE_HOME: "/xdg/cache" }, bins), [ + "/home/runner/.bun/install", + "/xdg/cache/.bun/install", + ]); + assert.deepEqual( + removedBy("clean_bun_cache", { XDG_CACHE_HOME: "", BUN_INSTALL_CACHE_DIR: "/custom" }, bins), + ["/home/runner/.bun/install", "/custom"], + ); +}); + +// A git repository with the given files committed: what a fixture looks like. +const committedRepo = (dir, files) => { + fs.mkdirSync(dir, { recursive: true }); + for (const [name, content] of Object.entries(files)) fs.writeFileSync(path.join(dir, name), content); + const git = (...args) => + execFileSync("git", args, { + cwd: dir, + env: { + ...process.env, + GIT_AUTHOR_NAME: "t", + GIT_AUTHOR_EMAIL: "t@t", + GIT_COMMITTER_NAME: "t", + GIT_COMMITTER_EMAIL: "t@t", + }, + }); + git("init", "-q"); + git("add", "."); + git("commit", "-q", "-m", "fixture"); +}; + +test("clean_fixture_config restores a tracked .gitignore and .yarnrc.yml, removes an untracked .yarnrc.yml", (t) => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "fixture-config-test-")); + t.after(() => fs.rmSync(tempDir, { recursive: true, force: true })); + const run = (cwd) => { + const result = spawnSync("bash", ["-c", 'source "$HELPERS" >/dev/null; clean_fixture_config'], { + cwd, + encoding: "utf8", + env: { ...process.env, HELPERS: path.join(__dirname, "clean-helpers.sh") }, + }); + assert.equal(result.status, 0, result.stderr); + }; + + // like next: both files committed; turbo's build appends to .gitignore + const next = path.join(tempDir, "next"); + committedRepo(next, { ".gitignore": "/node_modules\n", ".yarnrc.yml": "nodeLinker: node-modules\n" }); + fs.appendFileSync(path.join(next, ".gitignore"), "\n# Turborepo\n.turbo\n"); + fs.writeFileSync(path.join(next, ".yarnrc.yml"), "enableMirror: false\n"); + run(next); + assert.equal(fs.readFileSync(path.join(next, ".gitignore"), "utf8"), "/node_modules\n"); + assert.equal(fs.readFileSync(path.join(next, ".yarnrc.yml"), "utf8"), "nodeLinker: node-modules\n"); + + // like run: no .yarnrc.yml committed; berry's prepare writes one + const run_ = path.join(tempDir, "run"); + committedRepo(run_, { ".gitignore": "/node_modules\n", "package.json": "{}" }); + fs.writeFileSync(path.join(run_, ".yarnrc.yml"), "enableMirror: false\n"); + run(run_); + assert.equal(fs.existsSync(path.join(run_, ".yarnrc.yml")), false); + assert.equal(fs.readFileSync(path.join(run_, ".gitignore"), "utf8"), "/node_modules\n"); + + // outside a repository nothing is touched + const plain = path.join(tempDir, "plain"); + fs.mkdirSync(plain); + fs.writeFileSync(path.join(plain, ".yarnrc.yml"), "x\n"); + run(plain); + assert.equal(fs.existsSync(path.join(plain, ".yarnrc.yml")), true); +}); + +test("registry-package-count.sh counts by walking the graph, dotted names included", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "registry-count-test-")); + try { + const project = path.join(tempDir, "project"); + const out = path.join(tempDir, "out"); + for (const [name, manifest] of [ + ["a", { name: "a", dependencies: { "lodash.merge": "1" } }], + ["lodash.merge", { name: "lodash.merge" }], + ["@scope.x/b", { name: "@scope.x/b" }], + [".store/unreachable", { name: "unreachable" }], + ]) { + fs.mkdirSync(path.join(project, "node_modules", name), { recursive: true }); + fs.writeFileSync(path.join(project, "node_modules", name, "package.json"), JSON.stringify(manifest)); + } + fs.writeFileSync( + path.join(project, "package.json"), + JSON.stringify({ name: "x", dependencies: { a: "1", "@scope.x/b": "1" } }), + ); + const script = path.join(__dirname, "registry-package-count.sh"); + for (const registry of ["npm", "aws"]) { + const result = spawnSync("bash", [script, out, registry], { cwd: project, encoding: "utf8" }); + assert.equal(result.status, 0, result.stderr); + } + assert.deepEqual(fs.readdirSync(out).sort(), ["aws-count.txt", "npm-count.txt"]); + assert.equal(fs.readFileSync(path.join(out, "npm-count.txt"), "utf8"), "3\n"); + } finally { + fs.rmSync(tempDir, { recursive: true, force: true }); + } +}); + test("clean_nx_cache does nothing outside an Nx workspace", () => { const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nx-clean-test-")); try { diff --git a/suite/scripts/registry-package-count.sh b/suite/scripts/registry-package-count.sh index 34124e276b..f6b3e81111 100644 --- a/suite/scripts/registry-package-count.sh +++ b/suite/scripts/registry-package-count.sh @@ -17,12 +17,12 @@ fi # If the node_modules directory exists, count the number of packages if [ -d "node_modules" ]; then + # Walk the dependency graph, as package-count.sh does. Scanning node_modules + # with a name pattern skipped package names containing a dot (335 instead of + # 362 on next), so registry per-package times were computed from a smaller + # count than the package-manager ones. BENCH_PACKAGE_COUNT=$( - find node_modules -name package.json -type f \ - | grep -E 'node_modules/([a-zA-Z0-9_-]+)/package\.json$|node_modules/@[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+/package\.json$' \ - | sort -u \ - | wc -l \ - | xargs + node "$(dirname "${BASH_SOURCE[0]}")/package-count.js" . ) || true else echo "Warning: node_modules directory does not exist" diff --git a/suite/scripts/registry/common.sh b/suite/scripts/registry/common.sh index ee088473b4..69c47f0d04 100644 --- a/suite/scripts/registry/common.sh +++ b/suite/scripts/registry/common.sh @@ -67,6 +67,14 @@ fi # relying on any cached metadata, so we measure actual registry performance. BENCH_NPM_INSTALL="npm install --prefer-online --no-audit --no-fund --no-update-notifier --ignore-scripts --loglevel=$BENCH_LOGLEVEL $FORCE_FLAG" +# Only the selected registries need their variables (checked below). With +# `set -u`, the `${VAR#//}` expansions below abort on an unset one, so give the +# optional registry URLs an empty default first: `--registries=npm` must run +# without CLOUDSMITH_REGISTRY, GH_REGISTRY and JFROG_REGISTRY. +CLOUDSMITH_REGISTRY="${CLOUDSMITH_REGISTRY:-}" +GH_REGISTRY="${GH_REGISTRY:-}" +JFROG_REGISTRY="${JFROG_REGISTRY:-}" + # Registry definitions BENCH_REGISTRY_NPM_URL="https://registry.npmjs.org/" BENCH_REGISTRY_VLT_URL="https://registry.vlt.io/vlt-benchmarks/npm/" diff --git a/suite/scripts/variations/common.sh b/suite/scripts/variations/common.sh index ca13a0a07c..526288e2e0 100644 --- a/suite/scripts/variations/common.sh +++ b/suite/scripts/variations/common.sh @@ -110,9 +110,12 @@ BENCH_SETUP_VP="touch yarn.lock" BENCH_SETUP_NODE="" # Bare install commands (no log redirection) — used by strace process counting. -# Install scripts are disabled where the PM runs them by default, so benchmarks -# measure dependency resolution + linking only (not arbitrary postinstall work). -# npm, yarn classic, bun: run scripts by default → --ignore-scripts +# Install scripts are disabled so benchmarks measure dependency resolution + +# linking only (not arbitrary postinstall work), whatever a tool's default. +# yarn classic: runs scripts by default → --ignore-scripts +# npm 12, bun: already block dependency scripts by default (npm 12 allows +# only explicitly listed ones; bun skipped esbuild's postinstall without +# the flag too), so --ignore-scripts is explicit, not load-bearing # pnpm v11+: errors on ignored build scripts (ERR_PNPM_IGNORED_BUILDS) → --ignore-scripts # aube: runs scripts for its default trusted dependencies → --ignore-scripts # berry, zpm, vlt: don't run scripts by default → no flag needed From 054b752cd2821153b4cdf0608fc4f3fef9325850 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 18 Nov 2026 09:38:20 +0000 Subject: [PATCH 2/2] fix(vp): write vp's own .yarnrc.yml instead of relying on berry's vp installs through Yarn 4 and needs nodeLinker: node-modules. It only had it because berry's prepare left a .yarnrc.yml behind in fixtures that don't commit one; clean_fixture_config now removes that between tools, which made vp's prepare fail in the run variation (CI run 44273957630). Co-Authored-By: Claude Opus 5.5 --- suite/scripts/variations/common.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/suite/scripts/variations/common.sh b/suite/scripts/variations/common.sh index 145ae19819..c19994a101 100644 --- a/suite/scripts/variations/common.sh +++ b/suite/scripts/variations/common.sh @@ -110,8 +110,11 @@ BENCH_SETUP_UPM="" BENCH_NX_VERSION="$(node -p "require('$(npm root -g)/nx/package.json').version" 2>/dev/null || echo latest)" BENCH_SETUP_NX="npm install --no-save --no-audit --no-fund --ignore-scripts --silent nx@$BENCH_NX_VERSION && npm pkg set nx='{}' --json" BENCH_SETUP_TURBO="" -# vp install delegates to Yarn 4, so it needs the same yarn.lock as berry above. -BENCH_SETUP_VP="touch yarn.lock" +# vp install delegates to Yarn 4, so it needs the same yarn.lock and +# .yarnrc.yml (nodeLinker: node-modules) as berry above. It used to get the +# .yarnrc.yml only because berry's prepare left one behind in fixtures that +# don't commit one; clean_fixture_config now removes that between tools. +BENCH_SETUP_VP="touch yarn.lock; echo \"$BENCH_COMMAND_YARN_MODERN_CONFIG\" > .yarnrc.yml" BENCH_SETUP_NODE="" # Bare install commands (no log redirection) — used by strace process counting.