Skip to content

fix(project): pick newer cargo target binary by mtime#51

Merged
brettdavies merged 2 commits into
devfrom
fix/dogfood-binary-discovery
May 7, 2026
Merged

fix(project): pick newer cargo target binary by mtime#51
brettdavies merged 2 commits into
devfrom
fix/dogfood-binary-discovery

Conversation

@brettdavies
Copy link
Copy Markdown
Owner

Summary

Replaces discover_rust_binaries()'s always-prefer-release heuristic with mtime-newest-wins so dev workflows where cargo run/cargo test only refresh debug stop probing stale target/release/<bin> binaries. The v0.4.0 spec sync surfaced the trap on p2-must-schema-print against anc itself.

Changelog

Changed

  • Binary discovery in src/project.rs::discover_rust_binaries now picks the newer of target/release/<bin> and target/debug/<bin> by mtime when both exist. Ties and metadata failures fall back to debug (matches cargo's dev-flow default). CI scenarios where only one profile is built are unchanged.

Documentation

  • Add Dogfooding Safety rule 3 to CLAUDE.md describing the mtime-based selection, with a NEVER directive against reverting to the always-prefer-release shape.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • refactor: Code refactoring (no functional changes)
  • perf: Performance improvement
  • docs: Documentation update
  • test: Adding or updating tests
  • chore: Maintenance tasks (dependencies, config, etc.)
  • ci: CI/CD configuration changes
  • style: Code style/formatting changes
  • build: Build system changes
  • BREAKING CHANGE: Breaking API change (requires major version bump)

Related Issues/Stories

  • Story: stale target/release/anc masking p2-must-schema-print regressions during v0.4.0 spec sync
  • Issue: n/a
  • Architecture: docs/solutions/test-failures/stale-release-binary-dogfood-fail-2026-05-07.md
  • Related PRs: feat(spec): sync v0.4.0 — add 11 requirement IDs across P1/P2/P4/P6/P8 #50 (v0.4.0 spec sync, where the trap was surfaced and a temporary PENDING_FAILS allowlist for p2-schema-print was added in tests/dogfood.rs)

Files Modified

Modified:

  • src/project.rs: discover_rust_binaries switches from existence-only release-over-debug preference to mtime-based selection via a new pick_newer_artifact helper. Adds two unix-gated tests (test_discover_picks_newer_artifact_by_mtime, test_discover_picks_release_when_newer).
  • CLAUDE.md: Dogfooding Safety section gains rule 3 describing the new behavior; the Rules for new behavioral checks subsection gains a NEVER directive locking the new shape in.

Created:

  • None.

Renamed:

  • None.

Deleted:

  • None.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing completed (dogfood anc check . against this branch; p2-schema-print no longer needs a manual cargo build --release to flip from Fail to Pass)
  • All tests passing

Test Summary:

cargo test reports 588 passed, 2 ignored across 7 suites. The two new unit tests use tempfile-style temp dirs and File::set_modified (stable since 1.75) to construct binaries with controlled mtimes; gated to #[cfg(unix)] because mtime semantics under Windows file-attribute caching are not the semantics this regression asserts against. Pre-push gate (fmt, clippy -Dwarnings, test, cargo-deny, Windows compat) passed before the push.

…inary

The discover_rust_binaries() preference for target/release over
target/debug masks behavioral check failures when target/release lingers
stale from past builds. Surfaced during v0.4.0 spec sync work — the new
p2-must-schema-print check kept reporting Fail despite the schema
subcommand being visible in target/debug/anc --help; the runner was
probing a stale target/release/anc that predated the subcommand.

Adds rule 3 to the Dogfooding Safety section (current behavior +
workaround: cargo build --release before dogfooding, or trash
target/release). Adds a corresponding rule under 'Rules for new
behavioral checks' so future checks that exercise help-surface get
the right pre-flight.

Cites docs/solutions/test-failures/stale-release-binary-dogfood-fail-2026-05-07.md
for the full investigation, root cause, and fix-candidate analysis.

Pairs with the next commit on this branch which lands the mtime-based
binary-discovery fix and updates this rule to reflect the new behavior.
discover_rust_binaries() previously preferred target/release/<bin>
unconditionally when both directories existed. In dev workflows where
cargo run / cargo test only refresh debug, target/release lingers stale
from past builds and behavioral checks probed yesterday's --help. The
v0.4.0 spec sync surfaced this when the new p2-must-schema-print check
kept reporting Fail despite the schema subcommand being visible in
target/debug/anc --help — captured help was 1071 bytes vs 1145 from a
direct invocation, exactly one subcommand line shorter (the line that
lived only in debug).

The fix replaces existence-only selection with mtime comparison: when
both binaries exist, return the one with the more recent modified time.
Ties and metadata-failures fall back to debug (cargo's dev-flow default).
CI scenarios where only one profile is built are unchanged — fall
through cleanly to the existence check.

Adds two unix-gated tests:

- test_discover_picks_newer_artifact_by_mtime: stamps target/release/myapp
  one hour in the past while target/debug/myapp stays at 'now'; asserts
  Project::discover returns the debug path. Regression for the original
  bug.
- test_discover_picks_release_when_newer: symmetric — stamps debug old
  and asserts release wins. Locks in that the function still does the
  right thing after a fresh cargo build --release.

Updates the CLAUDE.md Dogfooding Safety rule (added in the previous
commit on this branch) to describe the new mtime-based behavior. The
'Rules for new behavioral checks' subsection gains a NEVER directive
against reverting to the always-prefer-release shape.

Backstory: docs/solutions/test-failures/stale-release-binary-dogfood-fail-2026-05-07.md
@brettdavies brettdavies merged commit ef7609f into dev May 7, 2026
7 checks passed
@brettdavies brettdavies deleted the fix/dogfood-binary-discovery branch May 7, 2026 21:27
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