Skip to content

test(support): reject a stale oc-rsync binary instead of reporting it as a regression - #7385

Merged
oferchen merged 8 commits into
masterfrom
fix/stale-binary-freshness-guard
Aug 19, 2026
Merged

oferchen merged 8 commits into
masterfrom
fix/stale-binary-freshness-guard

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Problem

crates/test-support/src/bin_path.rs opens by stating the invariant it enforces:

Every integration test that shells out to oc-rsync must run the binary Cargo just built, never one left over from an earlier revision.

It checks the binary exists and is executable. It never checks it is current.

Cargo builds the oc-rsync [[bin]] from the workspace root package, so a per-crate run
(cargo nextest run -p cli) compiles that crate's test binaries and leaves oc-rsync
untouched. The tests then exercise whatever revision was built last, and the failure
presents as a behavioural regression: tests red, diff innocent.

That is not hypothetical. Three cli::dir_merge_x_modifier cells were failing with

left:  (0, [".rules", "FOO", "KEEP"])
right: (0, [".rules", "KEEP"])

against a four-day-old binary. The same fixture run against a freshly built binary matches
upstream 3.5.0 exactly, in all four cells (: .rules / :x .rules, flat and nested), on
both Linux and macOS. There was no filter defect - only a stale build.

Fix

workspace_bin now also asserts the binary is newer than every source Cargo compiled it
from, read from Cargo's own <binary>.d dependency file (--emit=dep-info) rather than a
heuristic scan of the tree. On a stale binary:

oc-rsync at target/debug/oc-rsync is older than crates/cli/src/lib.rs - it was built from an
earlier revision.
Run `cargo build --bin oc-rsync` for this profile before these tests; a stale binary fails
as though the code under test had regressed.

Two deliberate rules, both pinned by tests:

  • .git entries are ignored. Build scripts that embed revision metadata record
    .git/HEAD; it changes on every commit and fetch without altering a byte of program
    input, so honouring it would demand a relink after each commit.
  • A missing .d panics. Silently passing when the evidence is absent is the
    vacuous-skip pattern this module already refuses for a missing binary.

A dependency Cargo recorded but that has since been deleted is not treated as stale - that
rebuild is Cargo's business.

Verification

  • RED/GREEN on the production path, not just synthetic fixtures: backdating the real
    target/debug/oc-rsync turns the three dir_merge_x_modifier cells into the freshness
    panic quoting Cargo.toml; rebuilding returns 3 tests run: 3 passed.
  • The parser test found a real defect during review. The first implementation treated
    \ as a universal escape, which turns C:\src\lib.rs into C:srclib.rs - a path that
    never exists and therefore always looks fresh, disabling the guard on Windows. rustc
    escapes only spaces; corrected in the second commit, with the Windows drive-letter and
    escaped-space cases pinned.
  • Every assertion carries its non-vacuity companion: the stale-binary panic is paired with
    a fresh-binary acceptance, without which a guard that rejects everything would also pass.
  • cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings zero diagnostics; -p test-support 52/52 on Linux.

Notes

OcRsyncCliRunner::new resolves through locate_workspace_binary, whose documented
contract is to return Option so a test can self-skip. It therefore bypasses this guard.
Changing that contract is a separate question and is left alone here.

@github-actions github-actions Bot added the test label Aug 19, 2026
…writes

Cargo emits `<profile>/<name>.d` beside the uplifted binary only when that
binary is a primary target of the invocation, as it is under `cargo build`.
A `cargo test` / nextest build uplifts the binary but writes no `.d` there,
and that is how every CI cell and the documented local workflow build it -
so the freshness guard aborted with "cannot read Cargo's dependency file"
on a binary that was perfectly current.

Fall back to the per-unit dependency file in `deps/`, which every build
writes. `deps/` holds one unit per feature set under its own hash, and the
uplifted binary is a hard link of exactly one of them, so the unit is
selected by file identity rather than by a name whose hash encodes a
feature set this crate cannot see.

The real-binary test now resolves through the same helper, making it the
gate that proves a dependency file is findable where CI actually runs
instead of leaving that an assumption.
`MetadataExt::file_index` and `volume_serial_number` sit behind the unstable
`windows_by_handle` feature, so the inode-equivalent comparison did not
compile on Windows at all - every Windows cell failed with E0658.

Compare length and write time there instead. A hard link shares both by
construction, and so does the copy Cargo falls back to when linking is
unavailable, since it preserves the timestamp. Because that is a weaker
discriminator than an inode, the match must now be unique: two units that
look alike refuse rather than pick one, since the wrong unit's dependency
list can name a `cfg`-gated source this binary never compiled, which would
demand a rebuild Cargo has no reason to perform.

Unix keeps the exact `(dev, ino)` pair; the uniqueness rule is shared and
costs it nothing, because only one `deps/` entry can carry the inode.
…weaker one

The per-unit `deps/<crate>-<hash>.d` is not a substitute for the dependency
file Cargo writes beside the uplifted binary. Measured on this workspace:
the per-unit file names 3 sources - `src/bin/oc-rsync.rs` and the two files
it `include!`s - while the aggregated file names 1451, every path
dependency included.

Checking against the per-unit list would therefore pass while the binary was
stale with respect to engine, transfer, cli, filters and every other crate,
which is exactly the class this guard exists to catch: all three prior
misdiagnoses were edits in those crates. That is worse than no check - it
reads as coverage and cannot fail for the reason it was built.

So the check is now active only when the aggregated file is present, which
is what `cargo build` writes, and does nothing when it is absent. The cost
is stated in the module docs rather than hidden: a binary built solely by a
workspace test run and then reused by a per-crate run is unguarded until one
`cargo build --bin oc-rsync` arms it. CI does not need it, because there
Cargo builds the binary in the same invocation that runs the tests.

Found by the test added to prove the assumption rather than assert it: it
resolved a dependency file and parsed 10 deps where the aggregated one has
1451. The assertion stays, and now also pins that the file read is the
aggregated one.
Removing the deps/ fallback left the one test that reads a real dependency
file unable to run anywhere automatic: it needs the aggregated file, which
only `cargo build` writes, so it early-returns in CI and in any worktree
that has not built the binary. Nothing then pinned the parser against
Cargo's actual format.

Adds one line of real `cargo build` output as a fixture - abridged to a
representative entry per category, checkout root replaced, verbatim in
every respect the parser can observe: one line, one target, space-separated
absolute paths, no continuations (measured: the real file is a single line
of 1461 entries, unlike the per-unit file's two target lines plus phony
lines).

Asserts the properties that matter and would otherwise go unchecked: the
target is not parsed as one of its own sources, `.git` metadata is filtered,
and non-`.rs` entries survive - a manifest or an `include!`d README edit is
a real rebuild trigger, so dropping them would blind the guard to it.

RED proven by deleting the `.git` filter: this test and its synthetic
sibling both fail.
@oferchen
oferchen merged commit 966f6a6 into master Aug 19, 2026
70 checks passed
@oferchen
oferchen deleted the fix/stale-binary-freshness-guard branch August 19, 2026 12:03
oferchen added a commit that referenced this pull request Aug 24, 2026
… as a regression (#7385)

* test(support): reject a stale oc-rsync binary instead of reporting it as a regression

* fix(support): backslash escapes only a space in a Cargo dependency file

* chore: sync Cargo.lock

* fix(support): resolve the dependency file a test-mode build actually writes

Cargo emits `<profile>/<name>.d` beside the uplifted binary only when that
binary is a primary target of the invocation, as it is under `cargo build`.
A `cargo test` / nextest build uplifts the binary but writes no `.d` there,
and that is how every CI cell and the documented local workflow build it -
so the freshness guard aborted with "cannot read Cargo's dependency file"
on a binary that was perfectly current.

Fall back to the per-unit dependency file in `deps/`, which every build
writes. `deps/` holds one unit per feature set under its own hash, and the
uplifted binary is a hard link of exactly one of them, so the unit is
selected by file identity rather than by a name whose hash encodes a
feature set this crate cannot see.

The real-binary test now resolves through the same helper, making it the
gate that proves a dependency file is findable where CI actually runs
instead of leaving that an assumption.

* docs(support): name the two places Cargo writes a dependency file

* fix(support): select the deps unit with APIs that are stable on Windows

`MetadataExt::file_index` and `volume_serial_number` sit behind the unstable
`windows_by_handle` feature, so the inode-equivalent comparison did not
compile on Windows at all - every Windows cell failed with E0658.

Compare length and write time there instead. A hard link shares both by
construction, and so does the copy Cargo falls back to when linking is
unavailable, since it preserves the timestamp. Because that is a weaker
discriminator than an inode, the match must now be unique: two units that
look alike refuse rather than pick one, since the wrong unit's dependency
list can name a `cfg`-gated source this binary never compiled, which would
demand a rebuild Cargo has no reason to perform.

Unix keeps the exact `(dev, ino)` pair; the uniqueness rule is shared and
costs it nothing, because only one `deps/` entry can carry the inode.

* fix(support): drop the deps/ fallback - it was a false oracle, not a weaker one

The per-unit `deps/<crate>-<hash>.d` is not a substitute for the dependency
file Cargo writes beside the uplifted binary. Measured on this workspace:
the per-unit file names 3 sources - `src/bin/oc-rsync.rs` and the two files
it `include!`s - while the aggregated file names 1451, every path
dependency included.

Checking against the per-unit list would therefore pass while the binary was
stale with respect to engine, transfer, cli, filters and every other crate,
which is exactly the class this guard exists to catch: all three prior
misdiagnoses were edits in those crates. That is worse than no check - it
reads as coverage and cannot fail for the reason it was built.

So the check is now active only when the aggregated file is present, which
is what `cargo build` writes, and does nothing when it is absent. The cost
is stated in the module docs rather than hidden: a binary built solely by a
workspace test run and then reused by a per-crate run is unguarded until one
`cargo build --bin oc-rsync` arms it. CI does not need it, because there
Cargo builds the binary in the same invocation that runs the tests.

Found by the test added to prove the assumption rather than assert it: it
resolved a dependency file and parsed 10 deps where the aggregated one has
1451. The assertion stays, and now also pins that the file read is the
aggregated one.

* test(support): pin the parser against genuine cargo dep-info output

Removing the deps/ fallback left the one test that reads a real dependency
file unable to run anywhere automatic: it needs the aggregated file, which
only `cargo build` writes, so it early-returns in CI and in any worktree
that has not built the binary. Nothing then pinned the parser against
Cargo's actual format.

Adds one line of real `cargo build` output as a fixture - abridged to a
representative entry per category, checkout root replaced, verbatim in
every respect the parser can observe: one line, one target, space-separated
absolute paths, no continuations (measured: the real file is a single line
of 1461 entries, unlike the per-unit file's two target lines plus phony
lines).

Asserts the properties that matter and would otherwise go unchecked: the
target is not parsed as one of its own sources, `.git` metadata is filtered,
and non-`.rs` entries survive - a manifest or an `include!`d README edit is
a real rebuild trigger, so dropping them would blind the guard to it.

RED proven by deleting the `.git` filter: this test and its synthetic
sibling both fail.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant