build-space/tests/example_press_runs.rs
//! # The worked example is actually RUN — not just compiled
//!
//! `cargo test` compiles examples but never runs their `main()`, so the flagship
//! *"a consumer presses the build-thing button"* demo
//! (`build-space/examples/press_build_thing.rs`, task #36) could silently rot
//! while the suite stayed green. This test drives the example end-to-end via
//! `cargo run --example press_build_thing` and asserts it exits 0 and prints the
//! key describe→press→ledger→reload lines — so the demo can never drift dead.
use std::process::Command;
/// Run the canonical example as a subprocess and assert it succeeds + emits the
/// milestone lines a reader relies on. LAW: inject a real run, assert the real
/// observable output (exit code + stdout), never merely "it compiled".
#[test]
fn press_build_thing_example_runs_end_to_end() {
// Run from THIS crate's manifest dir so `--example` resolves against
// holger-build-space regardless of the workspace CWD.
let manifest = env!("CARGO_MANIFEST_DIR");
let out = Command::new(env!("CARGO"))
.args([
"run",
"--quiet",
"-p",
"holger-build-space",
"--example",
"press_build_thing",
])
.current_dir(manifest)
.output()
.expect("spawn cargo run --example press_build_thing");
let stdout = String::from_utf8_lossy(&out.stdout);
let stderr = String::from_utf8_lossy(&out.stderr);
// Exit 0: the example's own `assert!(digest_matches_record)` and the
// round-trip `assert_eq!(reloaded, rec)` both held.
assert!(
out.status.success(),
"example must exit 0.\n--- stdout ---\n{stdout}\n--- stderr ---\n{stderr}"
);
// DESCRIBE half: the products were reflected as a surface.
assert!(
stdout.contains("repo 'holger'"),
"names the repo:\n{stdout}"
);
for row in [
"holger-downstream",
"holger-cli",
"holger-ui",
"mvp-server-musl",
] {
assert!(
stdout.contains(row),
"surface lists the '{row}' row:\n{stdout}"
);
}
// PRESS half: the `holger` row was pressed into a content-addressed record,
// its digest printed, and it verified.
assert!(
stdout.contains("pressed 'holger'"),
"reports pressing the holger row:\n{stdout}"
);
assert!(
stdout.contains("digest :"),
"prints the digest line:\n{stdout}"
);
assert!(
stdout.contains("sha256:"),
"prints the artifact content hash:\n{stdout}"
);
// LEDGER half: the record persisted, reloaded, and round-tripped.
assert!(stdout.contains("reloaded"), "reports the reload:\n{stdout}");
assert!(
stdout.contains("record round-trips"),
"asserts round-trip:\n{stdout}"
);
assert!(stdout.contains("OK"), "ends with the OK summary:\n{stdout}");
}