1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Declared resolution of the `apr` binary for the falsifiers that drive the
//! real CLI (`falsify_mcp_dogfood_001`, `falsify_mcp_stdio_protocol`).
//!
//! # Why this module exists
//!
//! `aprender-mcp` is a **lib-only** package: it declares no `[[bin]]`, so cargo
//! never sets `CARGO_BIN_EXE_apr` for these test targets. Both files used to
//! call `assert_cmd::cargo::cargo_bin("apr")`, which on assert_cmd 2.2 reads
//! `CARGO_BIN_EXE_apr` and, finding it unset, falls back to guessing
//! `<dir of current_exe>/../apr` — the target directory of *whoever happened to
//! build last*. Neither half is a declared dependency:
//!
//! * The env-var half can never fire here. Only the package that *builds* a
//! binary gets `CARGO_BIN_EXE_<name>`, and this package builds none.
//! * The guess half depends on another package having already built `apr` into
//! that exact directory. When it has, the test silently runs whatever commit's
//! binary is lying there; when it has not, `cargo_bin` **panics** with
//! "`CARGO_BIN_EXE_apr` is unset". Measured on a fresh worktree: all six
//! falsifiers in these two files failed that way, before a single assertion ran.
//!
//! The panic also made `falsify_mcp_dogfood_001`'s
//! `if candidate.is_file() { .. } else { build_apr_binary() }` unreachable —
//! `cargo_bin` returns a path only when the file already exists, so the
//! build-on-demand arm was dead code that could never repair the missing binary.
//!
//! # What replaces it
//!
//! Ask cargo to build the binary we name, then take the path **cargo reports**
//! for it. Same doctrine as `scripts/apr_bin.sh` ("Ask cargo; never guess"),
//! for the same reason: every strategy that *searches* for an `apr` eventually
//! finds the wrong one. `--message-format=json` emits a `compiler-artifact`
//! record whose `executable` field is the authoritative path, so this is
//! immune to `CARGO_TARGET_DIR`, to `.cargo/config.toml` target-dir redirects
//! (gitignored here, so main and a worktree build to different places), and to
//! cargo's `build-dir` split — the three things the directory guess gets wrong.
//!
//! `cargo build` is a cheap no-op when the binary is already current, so the
//! build is unconditional: short-circuiting on "a file exists there" is exactly
//! the stale-artifact hole documented above.
//!
//! # No `$APR_BIN` escape hatch, deliberately
//!
//! `aprender_mcp::apr_bin` honours `$APR_BIN` at *runtime*, and the spawned
//! `apr mcp` child inherits this process's environment. Reading `$APR_BIN` here
//! would therefore also redirect the server's own subprocess resolution, past
//! the mock shim the dogfood falsifier installs on `PATH` — the override would
//! silently change what is under test rather than just where it lives.
use PathBuf;
use ;
/// The workspace package that owns the `apr` binary (root `Cargo.toml`,
/// `[[bin]] name = "apr"`). Pinned by version because crates.io ships older
/// `aprender` releases that can land in the dependency graph and make a bare
/// `-p aprender` spec ambiguous. `aprender-mcp` and the root package both take
/// `version.workspace = true`, so `CARGO_PKG_VERSION` here is the right one.
/// Build `apr` and return the path cargo reports for it.
///
/// Panics with the cargo failure surfaced on stderr if the build fails — a
/// broken `apr` is a real failure these falsifiers must report, not skip.