Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa3cef53e0
|
||
|
|
554310186f
|
||
|
|
50e430f4de | ||
|
|
e94c46f2ec
|
||
|
|
5b46986cd7
|
||
|
|
5a90d5c829
|
||
|
|
eb3f0bd09b
|
||
|
|
6a80423bd0
|
||
|
|
5e8e773f78
|
||
|
|
3f97d3d1e7
|
@@ -66,6 +66,26 @@ jobs:
|
||||
#
|
||||
# The scratch workspaces use path dependencies only, so nothing here
|
||||
# reaches crates.io.
|
||||
# Nightly first, stable second, so stable ends up the default and
|
||||
# nightly is only reachable through an explicit `+nightly`.
|
||||
#
|
||||
# `hardlink-clone-selftest.sh`'s last scenario needs a Cargo that
|
||||
# resolves freshness by CONTENT — the mode where the dep-info file
|
||||
# carries per-source checksums, which is the mutation that turns a
|
||||
# hardlink clone into silent stale-artifact reuse rather than a slow
|
||||
# build. This step is what supplies it, and as of 2026-08-26 it does:
|
||||
# the scenario ran and passed against 1.100.0-nightly.
|
||||
#
|
||||
# It briefly did not. Cargo PR #17382 (2026-08-22) demoted
|
||||
# `-Z checksum-freshness` to a gate and gave `build.fingerprint` the
|
||||
# choice, defaulting to `mtime`, so the suite — which set only the gate —
|
||||
# measured a genuine INACTIVE and skipped its strongest scenario. That
|
||||
# read as "upstream withdrew content freshness" and was written up here
|
||||
# as this step buying nothing. It was a moved switch, not a withdrawal;
|
||||
# the suite now exports both and the coverage is back. See
|
||||
# daniel/gitdan#62 for the investigation.
|
||||
- name: Install Rust nightly
|
||||
uses: dtolnay/rust-toolchain@nightly
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
|
||||
@@ -31,14 +31,23 @@ One thing neither project had, and the reason the clone is not a plain
|
||||
`cp -al`: **a build inside a hardlink clone does mutate the directory it was
|
||||
cloned from.** Cargo writes real artifacts by replacing them, but writes its
|
||||
metadata — and build scripts write their `OUT_DIR` — with a plain truncating
|
||||
write, straight through the shared inode. Under
|
||||
`CARGO_UNSTABLE_CHECKSUM_FRESHNESS` the file that gets corrupted is
|
||||
`.fingerprint/<unit>/dep-<target>`, which holds the per-source checksums that
|
||||
decide freshness, and the failure is silent stale-artifact reuse rather than a
|
||||
slow build. `scripts/hardlink-clone-selftest.sh` reproduces it as an explicit
|
||||
control and asserts the fix. The fix is to hardlink the artifacts (the GB) and
|
||||
real-copy the metadata (the MB) — about 3.7% of a Bevy-sized target directory,
|
||||
against 100% for a full copy.
|
||||
write, straight through the shared inode. When Cargo resolves freshness by
|
||||
content the file that gets corrupted is its dep-info fingerprint —
|
||||
`.fingerprint/<unit>/dep-<target>`, or
|
||||
`build/<pkg>/<hash>/fingerprint/dep-<target>` under Cargo's build-dir layout v2
|
||||
— which holds the per-source checksums that decide freshness, and the failure
|
||||
is silent stale-artifact reuse rather than a slow build.
|
||||
`scripts/hardlink-clone-selftest.sh` reproduces it as an explicit control and
|
||||
asserts the fix. The fix is to hardlink the artifacts (the GB) and real-copy
|
||||
the metadata (the MB) — about 3.7% of a Bevy-sized target directory, against
|
||||
100% for a full copy.
|
||||
|
||||
That ratio is a **layout-v1** figure and does not survive layout v2, which
|
||||
regroups artifacts under `build/` alongside the metadata and so drags nearly
|
||||
the whole tree into the real-copy set. Measured 2026-08-26 at 99.998% on a
|
||||
scratch crate. v2 is the nightly default and stabilises in cargo 1.100.0 on
|
||||
2026-11-12; the correctness guarantee above is unaffected, the saving is not.
|
||||
Tracked as [#14](https://gitdan.com/daniel/gitdan-actions/issues/14).
|
||||
|
||||
---
|
||||
|
||||
@@ -98,10 +107,14 @@ env:
|
||||
CARGO_INCREMENTAL: 0 # per-run bloat on a persistent volume
|
||||
CARGO_PROFILE_DEV_DEBUG: line-tables-only
|
||||
CARGO_PROFILE_TEST_DEBUG: line-tables-only
|
||||
# Nightly only. Content-addressed freshness instead of mtime-based — a
|
||||
# strictly stronger guarantee, complementary to the mtime restore (which
|
||||
# still covers directory-form `rerun-if-changed` build-script watches).
|
||||
# Nightly only, and BOTH are needed. Content-addressed freshness instead of
|
||||
# mtime-based — a strictly stronger guarantee, complementary to the mtime
|
||||
# restore (which still covers directory-form `rerun-if-changed` build-script
|
||||
# watches). Since cargo PR #17382 (2026-08-22) the `-Z` gate below only
|
||||
# unlocks the feature; `build.fingerprint` selects it and defaults to
|
||||
# `mtime`, so the gate on its own is accepted and does nothing.
|
||||
CARGO_UNSTABLE_CHECKSUM_FRESHNESS: "true"
|
||||
CARGO_BUILD_FINGERPRINT: "content"
|
||||
```
|
||||
|
||||
---
|
||||
@@ -544,9 +557,15 @@ bash scripts/selftest.sh --fast # fixture-only suites, no compiler
|
||||
|
||||
Both run in CI — `.gitea/workflows/ci.yaml`, one job, on pushes to `main` and
|
||||
on PRs that were non-draft when the run was created. It installs shellcheck
|
||||
and a stable Rust toolchain and references no credentials; the scratch
|
||||
workspaces the compiler-backed suites build use path dependencies only, so
|
||||
nothing reaches crates.io. It runs the full suite rather than `--fast`,
|
||||
and both a stable and a nightly Rust toolchain (nightly so
|
||||
`hardlink-clone-selftest.sh` can run its content-freshness scenario, which as
|
||||
of 2026-08-26 a nightly does enable — 1.100.0-nightly (787af2b8c 2026-08-25)
|
||||
resolves freshness by content given both `CARGO_UNSTABLE_CHECKSUM_FRESHNESS`
|
||||
and `CARGO_BUILD_FINGERPRINT: content`, per cargo PR #17382; the suite still
|
||||
settles that by experiment on every run and skips the scenario loudly when it
|
||||
cannot measure) and references no credentials; the scratch workspaces the
|
||||
compiler-backed suites build use path dependencies only, so nothing reaches
|
||||
crates.io. It runs the full suite rather than `--fast`,
|
||||
because the two compiler-backed suites are the ones that check this scheme
|
||||
against real Cargo instead of against a fixture. Draft (`WIP:`-titled) PRs
|
||||
skip it, and un-drafting does **not** un-skip them — the guard is evaluated
|
||||
@@ -559,7 +578,7 @@ change here reaches all of them at once. That is what the gate is for.
|
||||
| suite | covers |
|
||||
|---|---|
|
||||
| `cache-root-selftest.sh` | that a lineage nests one level and nothing else moves: no lineage resolves byte-for-byte to the cache root, two lineages on one cache key get disjoint target dirs, seed/publish/prune all stay inside their own lineage, a PR layers over its own lineage's base snapshot — **and one rejection per lineage name a reader elsewhere would stop seeing**, plus the publish-side mismatch guard |
|
||||
| `hardlink-clone-selftest.sh` | that a build in a clone cannot mutate its source — with a control proving a raw `cp -al` does. Needs a real compiler. |
|
||||
| `hardlink-clone-selftest.sh` | that a build in a clone cannot mutate its source — with a control proving a raw `cp -al` does. Needs a real compiler, **and a nightly that actually resolves freshness by content for its last scenario**: the source's-next-build check reasons about content rather than mtime, so under mtime freshness it would assert a bug. Whether the toolchain does is settled by experiment on a throwaway crate, not by asking it — accepting `-Z checksum-freshness` stopped implying it on 2026-08-22, when cargo PR #17382 demoted the flag to a gate and gave `build.fingerprint` (default `mtime`) the choice; the suite now exports both and 1.100.0-nightly measures ACTIVE again. The experiment reports **three** outcomes, not two: active, measured-inactive, and *not measured*. Its answer codes are `0` and `3`, deliberately clear of every status bash generates for its own errors — so nothing that goes wrong inside the probe, including an expansion failure no guard can catch, can be read as an answer. The scenario is skipped for the last two alike, but a failure to measure is never reported as a measurement. The control also reports which mutation families the running Cargo exhibits — a note, not an assertion, since that set moves upstream. |
|
||||
| `seed-target-dir-selftest.sh` | seed-source preference, lock-file stripping, two jobs racing on one cache key, **and one scenario per check a hardlink clone is validated against**: a source rotated wholesale, a subtree silently lost from the walk, a copy that reports failure over a tree both other checks read as whole, and a source identity that resolved at neither end — plus a staging tree that could not be privately owned being discarded rather than published, and the publisher's log showing it waited on the consumer's own reader-lock marker before reclaiming a rotated snapshot |
|
||||
| `publish-snapshot-selftest.sh` | the atomic swap, that a live consumer survives a republish, and the publisher's side of the rotation race: deferred reclamation under a live reader, and its sweep once the reader is gone |
|
||||
| `prune-cache-selftest.sh` | liveness, protection, locking, eviction order, self-clear, **and that a cache a job claims *inside* the check-to-unlink window survives it** — against a real scratch `origin` |
|
||||
|
||||
+65
-9
@@ -329,11 +329,18 @@ _unshare_files() {
|
||||
# the source) the following files in the SOURCE were mutated through the
|
||||
# shared inode:
|
||||
#
|
||||
# <profile>/.fingerprint/<unit>/dep-<target> (only under
|
||||
# CARGO_UNSTABLE_CHECKSUM_FRESHNESS,
|
||||
# where this file carries the
|
||||
# per-source blake3 checksums)
|
||||
# <profile>/build/<pkg>/output, root-output (Cargo build-script metadata)
|
||||
# <profile>/.fingerprint/<unit>/dep-<target> (build-dir layout v1) — or,
|
||||
# <profile>/build/<pkg>/<hash>/fingerprint/dep-<target>
|
||||
# (build-dir layout v2; see the
|
||||
# dated note below for which
|
||||
# Cargo writes which). Only
|
||||
# when Cargo resolves freshness
|
||||
# by CONTENT, where this file
|
||||
# carries the per-source blake3
|
||||
# checksums.
|
||||
# <profile>/build/<pkg>/output, root-output (Cargo build-script metadata;
|
||||
# `<pkg>/<hash>/run/root-output`
|
||||
# under layout v2)
|
||||
# <profile>/build/<pkg>/out/** (whatever the build script
|
||||
# writes into OUT_DIR — build
|
||||
# scripts overwhelmingly use a
|
||||
@@ -349,10 +356,59 @@ _unshare_files() {
|
||||
# sources, reports `Fresh`, and reuses a binary built from the PRE-merge code.
|
||||
# That is silent stale-artifact reuse — a wrong answer, not a slow one.
|
||||
#
|
||||
# So: hardlink the artifacts (the GB), real-copy the metadata (the MB).
|
||||
# Measured on a 6.9 GB Bevy workspace target dir, the unshared set is
|
||||
# .fingerprint 22 MB + build/ 237 MB + a handful of dep-info files — about
|
||||
# 3.7% of the tree, against 100% for a plain `cp -a`.
|
||||
# WHAT UPSTREAM CHANGED, AND WHAT IT DID NOT (measured 2026-08-26, daniel/gitdan#62).
|
||||
#
|
||||
# An earlier revision of this comment recorded that the dep-info write was
|
||||
# "NOT reproduced on 1.100.0-nightly (2026-08-25) — upstream appears to have
|
||||
# stopped writing it in place". That reading was wrong, and the way it was
|
||||
# wrong is the reason this paragraph is dated. Two unrelated upstream changes
|
||||
# landed within days of each other, and between them they moved both the
|
||||
# switch that turns the behaviour on and the path it writes to:
|
||||
#
|
||||
# 1. The ON-SWITCH MOVED. cargo PR #17382 `feat(config): Add build.fingerprint`
|
||||
# (merged 2026-08-22) demoted `-Z checksum-freshness` to a gate: it now
|
||||
# only UNLOCKS the feature, and `build.fingerprint` SELECTS it, defaulting
|
||||
# to `"mtime"`. So `CARGO_UNSTABLE_CHECKSUM_FRESHNESS=true` on its own is
|
||||
# accepted and does nothing, which is exactly the "flag accepted, mtime
|
||||
# anyway" result that was mistaken for a withdrawal. Content freshness
|
||||
# needs BOTH, and with both it is entirely intact:
|
||||
#
|
||||
# CARGO_UNSTABLE_CHECKSUM_FRESHNESS=true CARGO_BUILD_FINGERPRINT=content
|
||||
#
|
||||
# Measured on cargo 1.100.0-nightly (e8cb624d5 2026-08-22): with the gate
|
||||
# alone a `cp -al` clone mutates only the build/ and *.d families; add
|
||||
# `CARGO_BUILD_FINGERPRINT=content` and the source's dep-info file is
|
||||
# mutated through the shared inode again. Same toolchain, same clone, one
|
||||
# env var apart. The hazard was never removed — it was switched off.
|
||||
#
|
||||
# 2. THE PATH MOVED. Build-dir layout v2 (`-Z build-dir-new-layout`, cargo
|
||||
# 1.91) became the nightly default in cargo 1.99 (PR #17258) and was
|
||||
# stabilised by PR #17354, merged 2026-08-18, shipping in cargo 1.100.0
|
||||
# stable on 2026-11-12. Under v2 there is no `<profile>/.fingerprint` and
|
||||
# no `<profile>/deps` at all: everything is regrouped per build unit under
|
||||
# `<profile>/build/<pkg>/<hash>/{fingerprint,out,run}/`, artifacts
|
||||
# included. Bracketed locally: cargo 1.97.1 and 1.98.0-nightly write v1,
|
||||
# 1.100.0-nightly writes v2.
|
||||
#
|
||||
# The `-name .fingerprint` clause below therefore matches nothing under a v2
|
||||
# Cargo, and the dep-info file is covered only because the `-name build` clause
|
||||
# happens to swallow its new home. That is belt-and-braces by accident, not by
|
||||
# design — and the same accident makes this function real-copy essentially the
|
||||
# whole tree, because the artifacts moved under `build/` too. Measured on one
|
||||
# scratch crate (serde + serde_json + regex), same sources both ways:
|
||||
#
|
||||
# cargo 1.97.1 (layout v1) 27.0 MB unshared of 126.7 MB — 21.3%
|
||||
# 1.100.0-nightly (layout v2) 105.9 MB unshared of 105.9 MB — 99.998%
|
||||
#
|
||||
# So the guard still holds and the saving does not. Deliberately NOT fixed
|
||||
# here: adjusting the selection is a change to what gets hardlinked on every
|
||||
# consumer, which wants its own change and its own review, and the deadline is
|
||||
# cargo 1.100.0 stable on 2026-11-12. Tracked as gitdan-actions#14.
|
||||
#
|
||||
# The historical v1 figure this block used to quote stands as measured: on a
|
||||
# 6.9 GB Bevy workspace target dir the unshared set was .fingerprint 22 MB +
|
||||
# build/ 237 MB + a handful of dep-info files — about 3.7% of the tree, against
|
||||
# 100% for a plain `cp -a`. It describes layout v1 only.
|
||||
#
|
||||
# `incremental/` is deliberately left shared: rustc writes each incremental
|
||||
# session to a fresh `s-*-working` directory and finalises it with a rename,
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
#
|
||||
# That assumption is FALSE for a plain `cp -al`. Measured, and asserted below
|
||||
# as an explicit control: build in a raw `cp -al` clone and the source's
|
||||
# `.fingerprint/<unit>/dep-*` (under CARGO_UNSTABLE_CHECKSUM_FRESHNESS),
|
||||
# `build/<pkg>/output`, `build/<pkg>/out/**` and `deps/*.d` all change,
|
||||
# dep-info file (`.fingerprint/<unit>/dep-*` under Cargo's build-dir layout
|
||||
# v1, `build/<pkg>/<hash>/fingerprint/dep-*` under v2 — and under content
|
||||
# freshness only, see the probe below), `build/<pkg>/output`,
|
||||
# `build/<pkg>/out/**` and `deps/*.d` all change,
|
||||
# because Cargo and build scripts write those with a plain truncating write
|
||||
# rather than the write-then-rename Cargo uses for real artifacts.
|
||||
#
|
||||
@@ -73,22 +75,173 @@ mkcrate "$crate_dir"
|
||||
cd "$crate_dir"
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
|
||||
# Every assertion below reads cargo's own words out of a build log
|
||||
# (`Compiling libdep`, `Fresh probe`). A CI image that forces colour splices an
|
||||
# ANSI reset between the status word and the crate name, at which point every
|
||||
# one of those greps silently stops matching and the suite reports the
|
||||
# opposite of what happened — observed on gitdan-ci's runner image, where
|
||||
# scenario 2 failed while the log it printed plainly showed `Compiling libdep`.
|
||||
# Pin the format the assertions are written against.
|
||||
export CARGO_TERM_COLOR=never
|
||||
# Checksum freshness is where the worst failure lives (the dep-* file carries
|
||||
# per-source checksums and is rewritten in place). Only available on nightly;
|
||||
# without it the test still covers the build/ and *.d families.
|
||||
CHECKSUM_MODE="off"
|
||||
if cargo +nightly -V >/dev/null 2>&1; then
|
||||
export CARGO_UNSTABLE_CHECKSUM_FRESHNESS=true
|
||||
CARGO_BIN=(cargo +nightly)
|
||||
CHECKSUM_MODE="on"
|
||||
else
|
||||
CARGO_BIN=(cargo)
|
||||
fi
|
||||
echo "=== checksum-freshness mode: ${CHECKSUM_MODE} ==="
|
||||
|
||||
CONTENT_A='pub fn f() -> u32 { 1 }'
|
||||
CONTENT_B='pub fn f() -> u32 { 22222 } pub fn g() -> u32 { 7 }'
|
||||
|
||||
# Probe the BEHAVIOUR, not the channel and not the flag. Two weaker probes
|
||||
# were tried against gitdan-ci's runner and each let the suite assert a
|
||||
# property the toolchain did not have:
|
||||
#
|
||||
# `cargo +nightly -V` — answers "did a proxy called with
|
||||
# +nightly exit 0". `-V`
|
||||
# short-circuits before `-Z` is
|
||||
# even parsed.
|
||||
# `cargo +nightly -Z checksum-freshness — answers "is this flag still
|
||||
# locate-project` accepted", which since cargo PR
|
||||
# #17382 (2026-08-22) is a
|
||||
# different question from "is
|
||||
# content freshness on". That PR
|
||||
# demoted the flag to a gate and
|
||||
# gave `build.fingerprint` the
|
||||
# choice, defaulting to `mtime` —
|
||||
# so 1.100.0-nightly accepts the
|
||||
# flag and resolves freshness by
|
||||
# mtime unless
|
||||
# CARGO_BUILD_FINGERPRINT=content
|
||||
# is set too. Measured 2026-08-26;
|
||||
# see daniel/gitdan#62.
|
||||
#
|
||||
# The scenario at the end of this file depends on one thing and it is neither
|
||||
# of those: that changed content with an OLDER mtime rebuilds. Under mtime
|
||||
# freshness the correct answer is Fresh, so under mtime freshness that
|
||||
# scenario asserts a bug. So the probe simply performs that experiment, on its
|
||||
# own crate and its own target dir, with no clone anywhere near it — which is
|
||||
# also what makes it a control rather than a restatement of the scenario: the
|
||||
# probe establishes that the toolchain rebuilds on content, the scenario
|
||||
# establishes that a hardlink clone did not take that away.
|
||||
# THREE OUTCOMES, NOT TWO. An experiment that cannot tell a negative result
|
||||
# from a failed measurement is not settling the question, and the two are not
|
||||
# interchangeable here: "this toolchain resolves freshness by mtime" is a
|
||||
# statement about Cargo, while "a probe build failed" is a statement about this
|
||||
# machine. Collapsing them — which an earlier cut of this did, by returning
|
||||
# non-zero for both — makes a half-installed toolchain print a confident and
|
||||
# wrong explanation and quietly drop a scenario. The scenario still has to be
|
||||
# skipped in either case; what must not happen is the log claiming to know why.
|
||||
#
|
||||
# 0 content freshness measured ACTIVE — both builds ran, the backdated
|
||||
# rebuild recompiled
|
||||
# 3 measured INACTIVE — both builds ran, the backdated
|
||||
# rebuild reported Fresh
|
||||
# anything else NOT MEASURED — nothing was learned about the
|
||||
# toolchain
|
||||
#
|
||||
# THE ANSWER CODES ARE 0 AND 3, AND THE GAP IS THE MECHANISM. Bash produces 1
|
||||
# for an ordinary command failure, 2 for a usage error, 126/127 for a command
|
||||
# it could not run, 128+n for a signal, and — this is the one that matters —
|
||||
# 1 for an unbound-variable or other EXPANSION failure, which happens before
|
||||
# the command runs and is therefore invisible to a `||` guard and to an ERR
|
||||
# trap alike. It never produces 3. So "not an answer code" is decided by a
|
||||
# property of the shell rather than by an enumeration of the ways a step can
|
||||
# go wrong, and a step added later without a guard, or with a guard that
|
||||
# cannot fire, lands on NOT MEASURED by construction.
|
||||
#
|
||||
# That is the whole reason INACTIVE is not 1. It was, and three review rounds
|
||||
# on this function each found a narrower way for a shell-generated 1 to be read
|
||||
# as a measurement — an unguarded command, then a typo'd variable name on a
|
||||
# line that HAS its guard. Each was closed by narrowing the failure surface,
|
||||
# which is a game with no last move. Moving the answer off the codes bash can
|
||||
# generate ends it instead: there is no longer a mutation that turns an error
|
||||
# into an answer, only mutations that turn an error into a different error.
|
||||
#
|
||||
# The guards below stay, and so does the trap, but their job is now reporting
|
||||
# rather than correctness: they make a failed step land on 2 with its logs
|
||||
# printed instead of on some incidental status, which is nicer to debug and
|
||||
# lands in the same place either way.
|
||||
#
|
||||
# One piece of that reporting layer is load-bearing and not obvious. A command
|
||||
# on the left of `||` — or in an `if` condition — runs with errexit suppressed,
|
||||
# and that suppression propagates into a subshell and is NOT undone by a
|
||||
# `set -e` inside it (measured on bash 5.3: an unguarded `false` there falls
|
||||
# through to `exit 0`). Calling with errexit disarmed at the site is the only
|
||||
# form that lets the subshell re-arm it; hence the `set +e` bracket. The ERR
|
||||
# trap is then required on top, because a bare `set -e` abort exits with the
|
||||
# FAILING COMMAND's status, and `false` gives 1.
|
||||
#
|
||||
# WHY NOT-MEASURED SKIPS RATHER THAN FAILS. The scenario it gates is the only thing in
|
||||
# this suite that depends on freshness mode; everything else still runs and
|
||||
# still catches real regressions. Failing instead would turn a statement about
|
||||
# one machine's toolchain into a red gate reading "the hardlink scheme is
|
||||
# broken" across the three repos consuming this action — the same category
|
||||
# error the three-state split exists to prevent, one level up. What would
|
||||
# change the answer is not-measured becoming the everyday CI outcome; it is not
|
||||
# — gitdan-ci's outcome is a measurement either way. It reported a measured
|
||||
# INACTIVE until 2026-08-26, for the reason recorded at the `export` below, and
|
||||
# an ACTIVE once both switches were set.
|
||||
CHECKSUM_MODE="off"
|
||||
CHECKSUM_REASON="no nightly on PATH accepting -Z checksum-freshness"
|
||||
CARGO_BIN=(cargo)
|
||||
checksum_freshness_probe() {
|
||||
local d="$scratch/freshness-probe" t="$scratch/freshness-probe-target"
|
||||
mkcrate "$d" || return 2 # 2 is simply "not 0 and not 3"; see the header
|
||||
(
|
||||
set -e
|
||||
trap 'exit 2' ERR
|
||||
cd "$d" || exit 2
|
||||
printf '%s\n' "$CONTENT_A" > src/lib.rs || exit 2
|
||||
CARGO_TARGET_DIR="$t" cargo +nightly build -q > "$scratch/freshness-probe-warm.log" 2>&1 || exit 2
|
||||
printf '%s\n' "$CONTENT_B" > src/lib.rs || exit 2
|
||||
touch -d '@1000000000' src/lib.rs || exit 2
|
||||
CARGO_TARGET_DIR="$t" cargo +nightly build -v > "$scratch/freshness-probe.log" 2>&1 || exit 2
|
||||
# 3, not 1: see the header. This is the only statement in the subshell that
|
||||
# may report a measurement, and it is the only one that may exit 3.
|
||||
if grep -qE '^\s+Fresh probe' "$scratch/freshness-probe.log"; then exit 3; fi
|
||||
exit 0
|
||||
)
|
||||
}
|
||||
if cargo +nightly -Z checksum-freshness locate-project > /dev/null 2>&1; then
|
||||
export CARGO_UNSTABLE_CHECKSUM_FRESHNESS=true
|
||||
# BOTH, since cargo PR #17382 (2026-08-22): the -Z flag only unlocks the
|
||||
# feature and `build.fingerprint` selects it, defaulting to `mtime`. Setting
|
||||
# the gate alone is what made this suite report a measured INACTIVE on
|
||||
# 1.100.0-nightly and skip its strongest scenario (daniel/gitdan#62). Safe to
|
||||
# export unconditionally — a Cargo that does not know the key ignores it
|
||||
# silently, verified 2026-08-26 on 1.93.1 stable and 1.96.0-nightly, both of
|
||||
# which still measure ACTIVE from the gate alone.
|
||||
export CARGO_BUILD_FINGERPRINT=content
|
||||
# Errexit off across the call, so the subshell can arm its own — see the
|
||||
# header. `probe_rc` is read before it is restored.
|
||||
probe_rc=0
|
||||
set +e
|
||||
checksum_freshness_probe
|
||||
probe_rc=$?
|
||||
set -e
|
||||
case "$probe_rc" in
|
||||
0)
|
||||
CARGO_BIN=(cargo +nightly)
|
||||
CHECKSUM_MODE="on"
|
||||
CHECKSUM_REASON=""
|
||||
;;
|
||||
3)
|
||||
unset CARGO_UNSTABLE_CHECKSUM_FRESHNESS CARGO_BUILD_FINGERPRINT
|
||||
CHECKSUM_REASON="this nightly accepts -Z checksum-freshness and build.fingerprint=content but still resolves freshness by mtime"
|
||||
;;
|
||||
*)
|
||||
unset CARGO_UNSTABLE_CHECKSUM_FRESHNESS CARGO_BUILD_FINGERPRINT
|
||||
CHECKSUM_MODE="unmeasured"
|
||||
CHECKSUM_REASON="the probe exited ${probe_rc}, which is not one of its answer codes, so this was NOT MEASURED — this toolchain may or may not resolve freshness by content"
|
||||
# Loud, because the cost is silently lost coverage on a machine that
|
||||
# might have had it. The suite continues: everything else it asserts is
|
||||
# independent of freshness mode.
|
||||
echo "::warning::hardlink-clone-selftest: could not measure whether this toolchain resolves freshness by content — the probe exited ${probe_rc}. This is a failure to measure, not a finding about Cargo."
|
||||
tail -n 15 "$scratch/freshness-probe-warm.log" "$scratch/freshness-probe.log" 2>/dev/null | sed 's/^/ /' >&2 || true
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
cd "$crate_dir"
|
||||
echo "=== checksum-freshness mode: ${CHECKSUM_MODE}${CHECKSUM_REASON:+ — ${CHECKSUM_REASON}} ==="
|
||||
|
||||
build_base() {
|
||||
local dir="$1"
|
||||
printf '%s\n' "$CONTENT_A" > src/lib.rs
|
||||
@@ -112,11 +265,35 @@ fi
|
||||
ok "raw cp -al clone mutates the source ($(printf '%s\n' "$ctl_mutated" | wc -l) paths)"
|
||||
printf '%s\n' "$ctl_mutated" | sed 's/^/ /'
|
||||
|
||||
# Reported, not asserted, and the distinction is the point. The control's job
|
||||
# is to prove the hazard exists at all, which the non-empty set above already
|
||||
# does; this line records WHICH families a given Cargo exhibits.
|
||||
#
|
||||
# The dep-info file is the worst of them — it carries the per-source
|
||||
# checksums, so mutating it through a shared inode turns a hardlink clone into
|
||||
# silent stale-artifact reuse rather than a slow build. Failing on its absence
|
||||
# would mean this suite goes red whenever upstream stops doing something we
|
||||
# never wanted it to do — and it would go red in the CONTROL, where a failure
|
||||
# reads as "the hazard is gone" rather than "upstream changed". Nothing is lost
|
||||
# by reporting it: the fix scenario below asserts the source is byte-identical
|
||||
# after a full rebuild in the clone, which covers every family this Cargo has,
|
||||
# named or not.
|
||||
#
|
||||
# THE PATTERN MUST MATCH BOTH LAYOUTS, and that is not a detail. Cargo's
|
||||
# build-dir layout v2 moved the file from `<profile>/.fingerprint/<unit>/dep-*`
|
||||
# to `<profile>/build/<pkg>/<hash>/fingerprint/dep-*` (stabilised by cargo PR
|
||||
# #17354, cargo 1.100.0, stable 2026-11-12; nightly default since 1.99). An
|
||||
# earlier cut of this line looked for the v1 path only, so on 2026-08-26,
|
||||
# against 1.100.0-nightly with content freshness genuinely on, it printed
|
||||
# "does NOT rewrite ... in place" directly beneath a control listing that
|
||||
# showed the rewrite. A reporting line that can contradict the data three
|
||||
# lines above it is worse than no line at all. `fingerprint/.*dep-` matches
|
||||
# either layout and neither `.d` family.
|
||||
if [ "$CHECKSUM_MODE" = "on" ]; then
|
||||
if printf '%s' "$ctl_mutated" | grep -q '\.fingerprint/.*/dep-'; then
|
||||
ok "control confirms the checksum-freshness dep-info file is among the mutated set"
|
||||
if printf '%s' "$ctl_mutated" | grep -q 'fingerprint/.*dep-'; then
|
||||
echo " note: this cargo DOES rewrite its dep-info fingerprint file in place under content freshness"
|
||||
else
|
||||
fail "expected .fingerprint/*/dep-* in the control's mutated set under checksum freshness"
|
||||
echo " note: this cargo does NOT rewrite its dep-info fingerprint file in place; only the build/ and *.d families appear above"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -161,18 +338,32 @@ fi
|
||||
ok "no file in the source changed after a full rebuild in the clone"
|
||||
|
||||
echo
|
||||
echo "=== the whole point: the source's next build is still correct ==="
|
||||
# The source's cache holds artifacts built from CONTENT_A. Advance the source
|
||||
# to CONTENT_B (as a merge would) and rebuild in it. If the clone had
|
||||
# corrupted its dep-info, Cargo would report Fresh and keep the stale rlib.
|
||||
printf '%s\n' "$CONTENT_B" > src/lib.rs
|
||||
touch -d '@1000000000' src/lib.rs
|
||||
log="$scratch/rebuild.log"
|
||||
CARGO_TARGET_DIR="$base_fix" "${CARGO_BIN[@]}" build -v > "$log" 2>&1 || { cat "$log"; fail "rebuild in the source failed"; }
|
||||
if grep -qE '^\s+Fresh probe' "$log"; then
|
||||
fail "source declared its own crate Fresh against sources it has never built — stale-artifact reuse"
|
||||
if [ "$CHECKSUM_MODE" = "on" ]; then
|
||||
echo "=== the whole point: the source's next build is still correct ==="
|
||||
# The source's cache holds artifacts built from CONTENT_A. Advance the
|
||||
# source to CONTENT_B (as a merge would) and rebuild in it. If the clone had
|
||||
# corrupted its dep-info, Cargo would report Fresh and keep the stale rlib.
|
||||
#
|
||||
# CHECKSUM-FRESHNESS ONLY, and the backdated mtime is why. Under checksum
|
||||
# freshness the dep-info file's per-source checksums decide, so a 2001
|
||||
# timestamp on changed content must still rebuild — the assertion below.
|
||||
# Under Cargo's ordinary MTIME freshness the same timestamp means the source
|
||||
# is older than the artifact, and reporting Fresh is the correct answer;
|
||||
# asserting otherwise asserts a bug. This scenario was written against a
|
||||
# machine with a nightly installed and, run without one, failed on that
|
||||
# correct answer.
|
||||
printf '%s\n' "$CONTENT_B" > src/lib.rs
|
||||
touch -d '@1000000000' src/lib.rs
|
||||
log="$scratch/rebuild.log"
|
||||
CARGO_TARGET_DIR="$base_fix" "${CARGO_BIN[@]}" build -v > "$log" 2>&1 || { cat "$log"; fail "rebuild in the source failed"; }
|
||||
if grep -qE '^\s+Fresh probe' "$log"; then
|
||||
fail "source declared its own crate Fresh against sources it has never built — stale-artifact reuse"
|
||||
fi
|
||||
ok "source correctly rebuilt its crate after advancing to the clone's content"
|
||||
else
|
||||
echo "=== skipped: the source's-next-build scenario needs content-based freshness ==="
|
||||
echo " reason: ${CHECKSUM_REASON}"
|
||||
fi
|
||||
ok "source correctly rebuilt its crate after advancing to the clone's content"
|
||||
|
||||
echo
|
||||
echo "hardlink-clone-selftest: ${pass_count} assertions passed"
|
||||
|
||||
@@ -65,10 +65,10 @@ origin="$scratch/origin.git"; git init -q --bare "$origin"
|
||||
work="$scratch/work"; git init -q "$work"
|
||||
(
|
||||
cd "$work"
|
||||
git -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
|
||||
git -c user.email=t@t -c user.name=t -c commit.gpgsign=false commit -q --allow-empty -m init
|
||||
git branch -M main
|
||||
git checkout -q -b dev; git -c user.email=t@t -c user.name=t commit -q --allow-empty -m dev
|
||||
git checkout -q -b feat/live; git -c user.email=t@t -c user.name=t commit -q --allow-empty -m live
|
||||
git checkout -q -b dev; git -c user.email=t@t -c user.name=t -c commit.gpgsign=false commit -q --allow-empty -m dev
|
||||
git checkout -q -b feat/live; git -c user.email=t@t -c user.name=t -c commit.gpgsign=false commit -q --allow-empty -m live
|
||||
git remote add origin "$origin"
|
||||
git push -q origin main dev feat/live
|
||||
)
|
||||
|
||||
@@ -75,6 +75,15 @@
|
||||
# Asserts BOTH jobs correctly recompile the dependency and succeed.
|
||||
set -euo pipefail
|
||||
|
||||
# Every assertion below reads cargo's own words out of a build log
|
||||
# (`Compiling libdep`, `Fresh probe`). A CI image that forces colour splices an
|
||||
# ANSI reset between the status word and the crate name, at which point every
|
||||
# one of those greps silently stops matching and the suite reports the
|
||||
# opposite of what happened — observed on gitdan-ci's runner image, where
|
||||
# scenario 2 failed while the log it printed plainly showed `Compiling libdep`.
|
||||
# Pin the format the assertions are written against.
|
||||
export CARGO_TERM_COLOR=never
|
||||
|
||||
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
restore_mtimes="$script_dir/restore-mtimes.sh"
|
||||
|
||||
@@ -131,6 +140,11 @@ cd "$repo"
|
||||
git init -q
|
||||
git config user.email test@example.com
|
||||
git config user.name "restore-mtimes-selftest"
|
||||
# Local to this mktemp'd throwaway repo. Without it the eight commits below
|
||||
# inherit the developer's GLOBAL commit.gpgsign, which makes whether this gate
|
||||
# passes depend on their gpg agent — observed as a red run caused by a full
|
||||
# disk breaking gpg, in a suite that has nothing to say about either.
|
||||
git config commit.gpgsign false
|
||||
|
||||
cat > Cargo.toml <<'EOF'
|
||||
[workspace]
|
||||
|
||||
@@ -64,7 +64,8 @@
|
||||
# two refs' fingerprints ever share a directory and this script never has to
|
||||
# arbitrate freshness across refs — only within one ref's own history, which
|
||||
# is exactly what it is built to do soundly. On a nightly toolchain,
|
||||
# CARGO_UNSTABLE_CHECKSUM_FRESHNESS is a complementary, stronger guarantee
|
||||
# CARGO_UNSTABLE_CHECKSUM_FRESHNESS plus CARGO_BUILD_FINGERPRINT=content (both,
|
||||
# since cargo PR #17382 on 2026-08-22) is a complementary, stronger guarantee
|
||||
# (content-addressed rather than mtime-based freshness); this script is not
|
||||
# made redundant by it, because directory-form `rerun-if-changed` build-script
|
||||
# watches are not covered by it and stable historical mtimes stay cheap
|
||||
|
||||
Reference in New Issue
Block a user