Repository navigation
ci: check that Cargo.lock is what cargo writes, so a misplaced entry fails CI and not the next checkout - #288
Merged
Merged
Conversation
…fails CI and not the next checkout `cargo metadata --locked`, which every other step runs, accepts a lockfile whose packages are in the wrong order, and a cargo command without `--locked` then rewrites the file. #279 added `thrust-preview-provisioner` one place late and #284 moved it; nothing had failed in between, and a clean checkout of `main` was dirty after its first cargo run. Nothing in CI could have said so. `scripts/check-cargo-lock.sh` runs `cargo metadata` without `--locked` and fails (exit 1, with the diff) when the lockfile is not what cargo wrote back, which also catches a lockfile that has not heard of a change to a manifest. It exits 2 when it cannot vouch (no Cargo.toml, no lockfile, cargo failing). It puts the lockfile back as it found it whatever the result, so it never leaves a checkout dirty. `--self-test` builds small workspaces with no dependencies and checks the accept and refuse cases against cargo's own output (no network). - `.github/workflows/lint.yml`: two steps of the `deps` job, the self-test and the check. - `.github/scripts/plan-ci.py`: the script is a guard of the `deps` job (`deps` and `ci-scripts`), and not "a script this planner does not know", which runs everything. `Cargo.lock` itself already runs everything. - `docs/src/testing/running.md`: the two commands and the `deps` row. Controls (AGENTS.md rule 8): the guard on the lockfile as it was before #284 (`git show 15bcfb0:Cargo.lock`) exits 1 and prints the 14-line move, and leaves that file as it found it; on the real lockfile it exits 0 (491 packages) and the tree stays clean. Four broken copies of the script each fail the self-test on the cases that guard the broken line: cargo run with `--locked` (the disorder is accepted, 2 cases fail), no restore after a rewrite (2), a cargo failure counted as success (1), a check that accepts any change (4). The self-test is 10 of 10 on macOS and under dash on Linux. Refs: #284 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
A guard for what #284 fixed:
Cargo.lockmust be what cargo itself writes, so that a misplaced entry fails CI instead of surfacing as a dirty checkout. Part of the follow-up to #279 and #284; this PR closes nothing.The gap
cargo metadata --locked, which every other step runs, accepts a lockfile whose packages are in the wrong order (measured onmainat15bcfb0: exit 0, nothing changed). A cargo command without--lockedthen rewrites the file by 14 lines. #279 addedthrust-preview-provisionerone place late, nothing failed, and a clean checkout ofmainwas dirty after its first cargo run until #284. Nothing in CI could have said so.What it does
scripts/check-cargo-lock.shrunscargo metadatawithout--locked, the way a person does, and compares the lockfile with what it was:Cargo.toml, no lockfile, cargo failing, which is not an answer about the order).--self-testbuilds small workspaces with no dependencies (no network) and checks the accept and refuse cases against cargo's own output: the lockfile cargo wrote, two packages swapped, a member the lockfile has not heard of, no lockfile, no manifest, and a cargo that fails; each refusal also checks that the file was put back. POSIX sh, as CI runs its scripts under dash.Wiring: two steps of the
depsjob inlint.yml(the self-test and the check);plan-ci.pylists the script with the other guards of thedepsjob (so a change to it runsdepsandci-scripts, and not everything, which is what "a script this planner does not know" does);docs/src/testing/running.mdhas the commands and thedepsrow.Cargo.lockitself already runs everything.Controls (AGENTS.md rule 8)
git show 15bcfb0:Cargo.lock, which differs from today's only by that move, 14 lines) exits 1 and prints the move (thrust-preview-provisionerahead ofthrust-profiling), and leaves the file byte-identical to what it was given. On today's lockfile it exits 0 ("what cargo writes (491 packages)") and the tree stays clean.--locked(what the rest of CI does)rust:1,/bin/shisdash,CHECK_CARGO=cargo).Verification
test_plan_ci.py: 7008 passed, none bad (it holds one sample per planner rule; the rule is extended, not added). The planner puts the new script with the otherdepsguards, an unknown script andCargo.lockstill run everything.depsjob, the 22 it had and the two new ones, which also lint the edited workflow (lint-all-workflows.sh, actionlint). My local list of the steps was compared withlint.ymlmechanically.shellcheckon the new script.Not checked
docsjob's book build (mdbook-mermaidis not installed here); the docs edit is two lines in a table and a code block.cargo metadata, which thedepsjob'scheck-deps.shhas just run with the same cache, so the crates are already downloaded. I have not seen it on a runner.Refs: #284
🤖 Generated with Claude Code