Repository navigation
build(provenance): stamp -dirty-<digest> of the worktree diff into the version banner (rubash#827) - #939
Conversation
…e version banner (rubash#827) #488 blind spot proven in the v1.4.0 incident: the installed niu.exe printed an honest HEAD hash while the tree it compiled carried uncommitted edits — "hash honest, content ahead". A bare `git rev-parse --short HEAD` never guarantees content, so two different dirty trees could print the same banner. Mirror the niubash-side fix (its build.rs already stamps `-dirty-<8 hex>` for the sibling rubash checkout) on rubash's own stamp: - A tracked tree differing from HEAD (`git status --porcelain --untracked-files=no`, same rule as `git describe --dirty` / `diff-index --quiet HEAD`) appends `-dirty-<8 hex>` where the digest is SHA-256(`git diff HEAD --binary`)[..4]: staged and unstaged edits both count, untracked files never do. - The explicit `RUBASH_BUILD_HASH` release pin wins the hash half but can no longer launder a dirty tree — the dirty half is still appended when a repo is present. - Deliberately keep zero `rerun-if-changed`: cargo's default whole-package scan is the freshness contract that recomputes the dirty half on every uncommitted edit; emitting any rerun-if-changed would opt out of that scan and could serve a stale clean stamp into a dirty build. Verified: this worktree (dirty) builds `build: d4fc195-dirty-225d2d9f (debug)`; new tests/build_rs_dirty.rs exercises the stamp against throwaway fixture repos (clean -> bare HEAD, dirty -> stable content digest, staged counts, untracked ignored, restore returns bare HEAD). Refs #827 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Verdict: blocking flaw in the invalidation contract — the exact #827/#488 incident shape (dirty build, bare banner) still reproduces on this branch. Leaving unmerged until the rerun wiring is fixed. Independent review on a detached worktree at What verified clean
Where it breaksThe PR's load-bearing claim —
— is false on this toolchain, because Empirical matrix (detached worktree @
|
| step | tree | rebuild | banner | verdict |
|---|---|---|---|---|
| 1 | clean, first build | build.rs runs | 2d29290b |
correct |
| 2 | append 1 line to src/build_info.rs |
lib recompiles | 2d29290b |
stale bare — under-claim: the "hash honest, content ahead" incident shape survives the fix |
| 3 | same dirty tree, touch build.rs |
build.rs reruns | 2d29290b-dirty-421b9bb6 |
correct |
| 4 | restore file → clean tree | lib recompiles | 2d29290b-dirty-421b9bb6 |
stale dirty — over-claim on a clean tree |
| 5 | different single-file edit | lib recompiles | 2d29290b-dirty-421b9bb6 |
stale digest naming a different dirty state |
Both PR verifications structurally could not catch this: the live dirty check was a first build in a fresh worktree (build.rs always runs there), and tests/build_rs_dirty.rs invokes revision_label_for_checkout in-process, bypassing cargo invalidation entirely. The design note's "can only over-claim dirtiness, never under-claim it" is also inverted by step 2 — under-claiming is precisely the #827 blind spot.
Why this blocks
#827's rubash-half acceptance is that a binary can no longer print a clean commit while compiling HEAD+edits. Step 2 shows that shape remains one incremental rebuild away on this branch. Mechanism and tests are good; the invalidation wiring is the defect.
Suggested direction
Emit no directive at all (restores the default whole-package rescan) and take the explicit pin out of build.rs: emit the git-derived stamp under a separate cargo:rustc-env variable (e.g. RUBASH_GIT_STAMP), and let build_info.rs keep preferring option_env!("RUBASH_BUILD_HASH") for the pinned half (the pin's own staleness semantics are pre-existing; release pipelines set it before a fresh build). cargo invalidation is not reachable from tests/, but the 5-step matrix above is a cheap manual check worth recording in the PR description or a test comment.
… (rubash#827) PR #939 review (comment 6296907080) falsified the load-bearing claim that only `rerun-if-changed` opts out of cargo's whole-package rescan: the `cargo:rerun-if-env-changed=RUBASH_BUILD_HASH` line at build.rs:29 opted out on its own, so the dirty half of the stamp was not recomputed on incremental rebuilds — a dirty tree still printed a bare HEAD (the exact #827 "hash honest, content ahead" incident shape), and restoring the tree left a stale `-dirty-<digest>` naming a state that no longer existed. Rework per the review's direction: - build.rs emits NO `cargo:rerun-if-*` directive of any kind, restoring cargo's default whole-package rescan: every uncommitted tracked edit re-runs the script and re-computes the stamp. - The explicit `RUBASH_BUILD_HASH` pin moves out of build.rs entirely and is read crate-side via `option_env!` in build_info.rs; rustc dep-info already tracks `option_env!` reads, so pin changes recompile the crate without any build-script env hook. - The git-derived stamp is emitted under its own name (`RUBASH_GIT_STAMP`, plus `RUBASH_GIT_DIRTY_SUFFIX` for the dirty half) so it can never be mistaken for — or overwrite — a pipeline pin. - Pin-still-can't-launder-dirty is preserved: the suffix is appended to a pinned hash too (pin + `-dirty[-<digest>]`). Tests: build_rs_dirty gains a stamp == revision + suffix decomposition case and a source-level guard asserting no `rerun-if` emission ever reappears (cargo invalidation is not reachable in-process; the 5-step rebuild matrix is verified manually in the PR). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Reworked per the blocking review above (comment 6296907080). Commit What changed
Verification (detached worktree @
|
| step | tree | banner | verdict |
|---|---|---|---|
| 1 | clean, first build | fa903da2 |
correct |
| 2 | append 1 line to src/usage.rs |
fa903da2-dirty-0650e270 |
fixed — was the stale-bare-HEAD blocker |
| 3 | restore → clean | fa903da2 |
fixed — no stale -dirty |
| 4 | different single-file edit | fa903da2-dirty-63965379 |
correct — digest tracks the changed dirty state |
Pin path (new code, also verified end-to-end):
| tree | RUBASH_BUILD_HASH |
banner |
|---|---|---|
| dirty (same edit as step 4) | testpin |
testpin-dirty-63965379 — same suffix as the unpinned stamp, pin does not launder dirty |
| clean | testpin |
testpin |
| clean | unset | fa903da2 — dep-info env tracking recompiles on unset too |
Tests: cargo test --test build_rs_dirty 7/7 — the original 5 fixtures unchanged, plus two new ones: the_dirty_suffix_is_exactly_the_stamps_dirty_half (decomposition invariant the pin path depends on) and build_rs_emits_no_rerun_if_directives (source-level guard; cargo invalidation itself is not reachable in-process, hence the manual matrix above). cargo test --lib is red at src/builtins/cd.rs:486/491 — pre-existing on origin/master (VarTable vs HashMap, from 4aaedfb), unrelated to this PR; build_info's own test module verified standalone via rustc --test (4/4).
Ticket repro still PAIR-OK on this build: HOME=$PWD/newhome + -c 'mkdir ~/x && cd ~/x && pwd' → /d/repo/rubash-wt-827-rw/newhome/x, rc=0.
已合并(回执:上轮评审 #issuecomment-6296907080)Squash merge: 上轮 BLOCKER 复核:全部翻转复核在上轮同一失效语义命题上重跑矩阵(Windows,cargo 1.99.0,自建 detached worktree @ fa903da):
机理确认:build.rs 全文零 钉值路径(返工新契约)
票面复现保持
夹带检查diff 仅 6 个文件: 备注:master 上 |
|
返工复审通过,已合并(完整矩阵见合并说明:#issuecomment-6298212882)。 上轮 BLOCKER( Squash:master |
Summary
Closes the rubash-side half of the provenance blind spot behind #827 / #488: a bare
git rev-parse --short HEADinbuild:never guaranteed content. The v1.4.0 incident shipped a binary whose banner named a commit while compiling that commit plus uncommitted edits — two different dirty trees could print the same banner.This PR mirrors on rubash's own stamp what niubash's build.rs already does for the sibling rubash checkout (niubash PR #424,
b3ef4fb):git status --porcelain --untracked-files=no, same rule asgit describe --dirty/diff-index --quiet HEAD) now stamps<rev>-dirty-<8 hex>; the digest isSHA-256(git diff HEAD --binary)[..4]— staged and unstaged edits both count, untracked files never do. Same edits → same digest; any change → different banner.RUBASH_BUILD_HASHoverride still wins the hash half (release pipelines pin the packaged commit), but when a repo is present the-dirty[-<digest>]half is appended regardless — a pin names the claim, the digest marks the truth.rerun-if-changed— cargo's default whole-package scan is what recomputes the dirty half on every uncommitted edit. Emitting anyrerun-if-changedwould opt OUT of that scan and could bake a stale clean stamp into a dirty build. (Trade-off, now documented: a HEAD move with a byte-identical worktree — e.g. committing exactly what was built — keeps the previous stamp until the next file change. This can only over-claim dirtiness, never under-claim it; the incident shape was under-claiming.)Status of #827 acceptance items
scripts/release/rubash-pin.json+ pinned-clone + drift check, niubash PR [bug] unmatched extglob redirect target >?(zz)out creates a literal file (GNU: syntax error near unexpected token) #424).niu --version(Niubash 1.4.0names only the Cargo version — the v1.4.0 tag was repushed ~6×), the v1.4.1 recut/warning decision, tag-repush discipline, and the path model: cd ~ uses the startup HOME; mkdir succeeds where cd then fails at ~260 chars; pwd and realpath disagree on spelling #754 acceptance-baseline re-anchor.Test plan
cargo test --test build_rs_dirty— 5/5 fixture tests (clean → bare HEAD; dirty → stable content digest that tracks edits; staged-but-uncommitted counts; untracked ignored; restore returns bare HEAD)build: d4fc195c-dirty-225d2d9f (debug)cargo build --locked— lockfile consistent;cargo fmt --checkcleancargo test --lib build_infopredicate verified against the live stamp (note:cargo test --libcurrently fails to compile on Windows due to a pre-existing master regression —src/builtins/cd.rs:486,491#[cfg(windows)]test still passes&mut HashMapafter the perf(env): write-behind marker strings, read from structured flags #918VarTablerefactor; unrelated to this change, left for its own fix)Refs #827
Generated with Devin