Repository navigation
fix(pnpm): stop pnpm run from re-poisoning the lockfile - #73
Conversation
## The problem this fixes **Every Dependabot PR arrives broken.** Measured on the six open right now: | PR | host-pinned entries | |---|---| | #61 | 1724 | | #64 | 1720 | | #65 | 1718 | | #66 | 1720 | | #71 | 1723 | | #72 | 1719 | All six fail CI at `verify:workspace`: ``` pnpm-lock.yaml: 1723 pinned of 1723 entr(ies), 1723 rotating shard-host URL(s) Repair with: node scripts/strip-lockfile-hosts.mjs ``` Dependabot cannot run the repair, so the only remedy was a human checking out each branch, stripping, and pushing. That is the recurring tax — bigger than the local-poisoning one #73 fixes. And it is unavoidable: there is **no pnpm configuration that stops the URLs being written**. Tested — shard host as the registry with an isolated cache and store still records them; `lockfileIncludeTarballUrl` only drops *reconstructible* URLs; `registries`/`serverType` explicitly excludes divergent hosts; `trustLockfile` keeps the URLs *and* drops the anti-tamper binding. ## What changes CI **normalises** the lockfile before installing — the order [SOURCES.md](../blob/main/SOURCES.md#lockfile-integrity) already requires, since pnpm's check runs before lifecycle scripts. Both installing jobs do it. A dependency PR is now built and tested rather than rejected before it gets that far. That removes the only signal, so the signal **moves** rather than disappearing. The step after the install compares the repaired tree against what was committed: - **pull request** → warning annotation naming the fix, PR proceeds - **main** (`push` only ever runs there) → error Main is the one that matters: a host recorded there sits quietly until the shard it names rotates away, and then breaks the next install for everyone. ## The trade, stated plainly **A host-pinned lockfile can now reach main, and main goes red once when it does.** That is the cost of letting dependency PRs through. It is a red *assertion* rather than a broken build — CI still repairs the tree before using it — and the fix is one command. The alternative (auto-commit the repair back to the PR branch) needs `pull_request_target` or a PAT; not taken here. ## Verification Against a genuinely committed host-pinned lockfile, not a simulated one — my first attempt injected into the working tree and stripped it back, which proved nothing: | state | event | result | |---|---|---| | 1721 hosts committed | `pull_request` | `::warning::` exit 0 | | 1721 hosts committed | `push` | `::error::` exit 1 | | clean | either | exit 0 | Also confirmed `pnpm install --frozen-lockfile` accepts a just-stripped lockfile, and that the repair is **lossless** — the stripped file is byte-identical to the clean committed one. ## Still not automated Humans. There is no root pre-commit hook (`maximal-core` has `simple-git-hooks` + `lint-staged`; the root has neither), so a local `pnpm install` still needs the strip run by hand. Adding two devDependencies to the root felt like the wrong thing to bundle into a CI fix — happy to do it separately if wanted.
Closes #26. pnpm 11 defaults `verifyDepsBeforeRun` to `install`, so every `pnpm run`, `pnpm test` and `pnpm --filter ... run ...` silently performs a full install first. That install re-resolves, and re-resolution re-records the rotating `ms-feed-N` tarball hosts -- all 1721 of them -- that scripts/strip-lockfile-hosts.mjs exists to remove. The effect is that stripping the lockfile and then running literally any script put every host straight back, so the next --frozen-lockfile install rejected the lockfile: the Docker test image, and CI. Working on this repo meant re-stripping after almost every command, and forgetting once produced a failure that reads like a dependency break rather than like a stale lockfile. `warn` keeps the check the default exists for -- it still reports a node_modules that has drifted from the lockfile -- and does not write. Verified: with the setting in place, `pnpm run verify:workspace`, `pnpm --filter maximal-site run build`, `pnpm test` and a full container suite all leave the lockfile byte-identical, with zero recorded hosts. Without it, one `pnpm run` re-adds 1721. Rebased after #77 landed, which changes what this is for. `.pnpmfile.cjs` now drops the shard hosts as the lockfile is written, so an implicit install no longer poisons anything and the acute failure is gone. The setting is still worth having, for the smaller reason it was always also true: a `pnpm run` should not resolve and rewrite the tree behind the script it was asked to run. The prose in SOURCES.md and pnpm-workspace.yaml says that rather than the pre-#77 rationale, and the first of the two caveats below is now obsolete -- kept as the record of why the hook exists. Two things this does NOT fix, recorded so the next person does not go looking: The tarball URLs themselves. The proxy serves tarballs from ms-feed-N.pkgs.visualstudio.com while the registry is packagefeedproxy.microsoft.io, and pnpm records a tarball URL whenever it cannot rebuild it from registry + name + version -- which it never can when the hosts differ. `lockfileIncludeTarballUrl` does not help: it only drops URLs that ARE reconstructible. There is no setting to disable the check. pnpm/pnpm#13619 reproduces this against this exact proxy and these exact hosts. (Superseded by #77: the pnpmfile hook drops them at write time instead.) The need to strip after a deliberate `pnpm install`. That is unchanged, and SOURCES.md already documents it. What changes is that it is now needed after an install rather than after every command.
d960fae to
405c6a7
Compare
|
Rebased onto main now that #76, #77 and #75 have landed. The conflict was in Resolution, and one thing worth knowing before merging: #77 removed the acute reason for this change. The setting still earns its place, for the smaller reason that was always also true — a Re-verified on the rebased branch, with pnpm 11.25.0 from mise (as #75 now requires):
|
pnpm 11 defaults
verifyDepsBeforeRuntoinstall. Everypnpm run,pnpm testandpnpm --filter ... run ...silently performs a full installfirst. That install re-resolves, and re-resolution re-records the rotating
ms-feed-Ntarball hosts.So stripping the lockfile and then running any script put every host straight
back, and the next
--frozen-lockfileThe tarball URLs themselves. The proxy serves tarballs from
ms-feed-N.pkgs.visualstudio.comwhile the registry ispackagefeedproxy.microsoft.io. pnpm records a tarball URL whenever it cannotrebuild it from registry + name + version — which it never can when the hosts
differ.
lockfileIncludeTarballUrldoes not appear to help: it only drops URLs thatreconstructible. Ours are not, and pnpm keeps them deliberately, because a
frozen lockfile would otherwise be unable to re-fetch.
against this exact proxy and these exact
ms-feedhosts — it is a knownpnpm limitation, not a misconfiguration here. The
maintainer-less discussion
lands on stripping the lockfile as the accepted workaround, which is what this
repo already does.