Skip to content

ci: repair the lockfile instead of failing on it - #76

Merged
stuffbucket merged 1 commit into
mainfrom
fix/ci-normalise-lockfile
Sep 7, 2026
Merged

stuffbucket merged 1 commit into
mainfrom
fix/ci-normalise-lockfile

Conversation

@stuffbucket

Copy link
Copy Markdown
Owner

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 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.

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
stuffbucket force-pushed the fix/ci-normalise-lockfile branch from cd30d31 to 4351f8c Compare September 7, 2026 06:53
@stuffbucket

Copy link
Copy Markdown
Owner Author

Retested after #77 (the afterAllResolved hook), because that changes what this step is for.

This is still load-bearing, not a backstop. The decisive case:

case result
frozen install, poisoned lockfile, hook present still fails — --frozen-lockfile skips resolution, so afterAllResolved never runs
@astrojs/[email protected] has a tarball URL (…ms-feed-2…) that does not
match the registry's published metadata (…ms-feed-25…)
…and 1701 more

So the division of labour is:

  • fix(pnpm): stop the lockfile carrying shard hosts, at write time #77's hook stops hosts being written — nothing resolved from this repo commits them again.
  • This PR repairs a lockfile that arrives already carrying them: resolved before the hook existed, or by a tool that did not load it.
  • The main-only assertion is what would tell us if the hook ever silently stopped applying.

Comments updated to say that rather than attributing it all to Dependabot.

@stuffbucket
stuffbucket merged commit 3a0b07f into main Sep 7, 2026
6 checks passed
@stuffbucket
stuffbucket deleted the fix/ci-normalise-lockfile branch September 7, 2026 07:38
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant