Repository navigation
ci: repair the lockfile instead of failing on it - #76
Merged
Merged
Conversation
A lockfile can arrive carrying rotating shard hosts -- resolved before `.pnpmfile.cjs` existed, or by a tool that did not load it -- and --frozen-lockfile cannot repair it: resolution is skipped, so the hook never runs and pnpm rejects the record against the registry's current metadata. Every such pull request failed at verify:workspace, and the only remedy was a human checking out the branch, running the strip script and pushing. Six were open at once. CI now normalises before installing, which is the order SOURCES.md already requires -- pnpm's check runs before lifecycle scripts, so nothing later can repair it. Both installing jobs do it. Such a pull request 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. On a pull request that is a warning annotation naming the fix; on main -- where `push` only ever runs -- it is an error, because a host recorded there sits until the shard it names rotates away and then breaks the next install for everyone. The trade this accepts, deliberately: a host-pinned lockfile can reach main, and main goes red once when it does. It is a red assertion rather than a broken build -- CI still repairs the tree before using it -- and the fix is one command. Verified against a committed host-pinned lockfile, not a simulated one: the pull-request path warns and exits 0, the main path errors and exits 1, a clean lockfile exits 0 in both. `pnpm install --frozen-lockfile` accepts a just-stripped lockfile, and the repair is lossless -- the stripped file is byte-identical to the committed clean one.
stuffbucket
force-pushed
the
fix/ci-normalise-lockfile
branch
from
September 7, 2026 06:53
cd30d31 to
4351f8c
Compare
Owner
Author
|
Retested after #77 (the This is still load-bearing, not a backstop. The decisive case:
So the division of labour is:
Comments updated to say that rather than attributing it all to Dependabot. |
stuffbucket
added a commit
that referenced
this pull request
Sep 7, 2026
Answers "can we just run strip on install?" — yes, and better than that: **at write time, so the hosts are never in the lockfile at all.** `.pnpmfile.cjs` drops the rotating `ms-feed-N.pkgs.visualstudio.com` tarball URLs in `afterAllResolved`, which runs on the in-memory lockfile *before* pnpm serializes it. ## Why this beats the strip script `scripts/strip-lockfile-hosts.mjs` can only repair a lockfile someone remembered to run it against. **Dependabot cannot be asked to run anything** — every dependency PR arrived with ~1720 host-pinned entries and failed CI; six were open at once. A hook travels with the repository, so it applies to whoever resolves. It also cannot be a `postinstall` hook, which is the obvious thing to reach for: pnpm's check rejects a recorded host *before* lifecycle scripts run, so the install is already dead by the time a hook would fire. `afterAllResolved` is earlier than that — it is part of resolution, not a lifecycle script. Scoped to the shard hosts deliberately. A tarball URL that is genuinely not reconstructible — a git dependency, a GitHub release — is pinned there on purpose, and blanking it would break resolution rather than harden it. Same rule the script follows. ## Verification - `pnpm install --force` over the whole workspace: **drops 1740 URLs, lockfile byte-identical, zero hosts.** - A subsequent `pnpm run` and a second forced install: unchanged. - `verify:workspace` passes; container suite **15/15**, which exercises `--frozen-lockfile` with the hook present. The single lockfile change is `pnpmfileChecksum` — pnpm hashing the hook so the lockfile re-resolves if it is edited. ## What I could not verify from here **That Dependabot's updater honours the pnpmfile.** pnpm loads `.pnpmfile.cjs` from the workspace root without configuration, so it should, but the proof is the next dependency PR arriving clean. Until that is observed, #76 (CI-side normalisation) is worth keeping as a backstop — and its main-only assertion is what would tell us if this hook ever stops applying. If the next Dependabot PR comes through clean, #76 becomes belt-and-braces rather than load-bearing. ## On `strip` vs the settings pnpm offers Since it came up — they are not equivalent, and neither pnpm setting does what this hook does: | | this hook / strip | `trustLockfile` | `lockfileIncludeTarballUrl` | |---|---|---|---| | URLs in lockfile | none | present, rewritten every install | unchanged — only drops *reconstructible* URLs, and ours are not | | Diff noise per install | none | ~1700 lines | ~1700 lines | | Install fetches from | derived registry URL | the **recorded shard** | the recorded shard | | If that shard rotates away | fine | breaks | breaks | | Anti-tamper binding (pnpm/pnpm#12134) | nothing to tamper with | **disabled** | intact | `trustLockfile` only silences the mismatch error; it leaves the churn and gives up the binding. Only four shards answer anonymously, so a recorded one going away is a live failure mode, not a theoretical one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem this fixes
Every Dependabot PR arrives broken. Measured on the six open right now:
All six fail CI at
verify:workspace: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;
lockfileIncludeTarballUrlonly drops reconstructibleURLs;
registries/serverTypeexplicitly excludes divergent hosts;trustLockfilekeeps the URLs and drops the anti-tamper binding.What changes
CI normalises the lockfile before installing — the order
SOURCES.md 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:
pushonly ever runs there) → errorMain 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_targetor 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:
pull_request::warning::exit 0push::error::exit 1Also confirmed
pnpm install --frozen-lockfileaccepts 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-corehassimple-git-hooks+lint-staged; the root has neither), so a localpnpm installstill needs thestrip 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.