import { copyFile, mkdir, readdir, readFile, stat, symlink, writeFile } from "node:fs/promises"; import path from "node:path"; import { PR_BASE_REF_VARIABLE } from "./pr-gate-selection.ts"; /** * Links the repository's installed dependencies into a throwaway fixture root. * * The obvious form — one directory symlink at `/node_modules` — is * destructive. A fixture runs `pnpm` inside itself, pnpm does not recognise the * modules directory it finds there, and its purge follows the symlink and * deletes the *repository's* real dependencies mid-run. With `CI=true` that * happens without a prompt, so a test suite silently uninstalls the workspace * it is running in. * * `node_modules` is therefore a real directory here, and every entry inside it * is an individual symlink. Package resolution is unchanged, but a recursive * delete unlinks the fixture's own symlinks instead of walking through one link * into the shared tree. * * Top-level files are pnpm's install state (`.modules.yaml`, * `.pnpm-workspace-state-v1.json`, ...). pnpm rewrites them in place when it * runs inside the fixture, so they are copied: a link would carry the fixture's * path into the repository's own state and make its next pnpm command * re-verify the install. * * The copied workspace state still names the repository as its validated * project, so pnpm in the fixture would re-verify and start an install through * the linked directories. It is rewritten to name the fixture root instead: * the packages are the repository's own, already validated. */ /** * F-4. The environment for every `pnpm` a linked fixture runs. pnpm verifies * the install before a script and, when the fixture's copied state disagrees * with its own settings (for example `CI=true` against an install made * without it), installs. `.pnpm` and `.bin` are links into the repository's * node_modules, so that install rewrote the shared `.pnpm/lock.yaml` and bin * shims. A fixture started through `pnpm