30e5abb6aa
RunManifest.commit read option_env!("AURA_COMMIT").unwrap_or("unknown"),
so a normal build's manifest identity field was a bare placeholder --
C8's audit trail (this run = this commit) had nothing to point back at
once runs are archived (C18 registry).
Add crates/aura-cli/build.rs: at compile time it shells out to the `git`
already in PATH -- `rev-parse HEAD`, plus a `-dirty` suffix when
`status --porcelain` is non-empty -- and emits
`cargo:rustc-env=AURA_COMMIT=<sha>`. The existing option_env! read is
untouched and now picks it up. Chose shelling to git over a libgit crate
to keep the zero-external-dependency commitment (C14/C18); the firewall
crate is aura-ingest, and a build-time process call adds no runtime dep.
No-git case (packaged source tree, no .git): build.rs returns early and
swallows git errors, leaving AURA_COMMIT unset so "unknown" still holds.
Staleness guard: build.rs emits rerun-if-changed on .git/HEAD and
.git/logs/HEAD (logs/HEAD grows on every HEAD move incl. branch switch),
so the captured sha is rebuilt when HEAD moves rather than going stale.
Determinism (C1) is intact: AURA_COMMIT is fixed at compile time, so two
runs of one build still produce byte-identical manifests.
Two tests that pinned the old "unknown" placeholder are relaxed to the
new structural contract (not scope creep -- they were the old contract):
the cli_run.rs JSON-shape prefix no longer pins the commit value, and
the main.rs unit test asserts commit is non-empty and stable across runs
instead of equal to "unknown". The headline contract (manifest.commit
contains the real HEAD sha) is pinned by run_manifest_commit_carries_
real_git_head (4552d0c). Verified: cargo test -p aura-cli green (5),
clippy --all-targets -D warnings clean.
closes #15
119 lines
5.5 KiB
Rust
119 lines
5.5 KiB
Rust
//! Integration test: drive the built `aura` binary as a downstream user would,
|
|
//! asserting the `run` subcommand's stdout/exit contract and the bad-args path.
|
|
|
|
use std::process::Command;
|
|
|
|
/// Path to the freshly-built `aura` binary (Cargo sets this env var for the test
|
|
/// crate; the binary is named `aura` in `Cargo.toml`).
|
|
const BIN: &str = env!("CARGO_BIN_EXE_aura");
|
|
|
|
#[test]
|
|
fn run_prints_json_and_exits_zero() {
|
|
let out = Command::new(BIN).arg("run").output().expect("spawn aura run");
|
|
assert!(out.status.success(), "exit status: {:?}", out.status);
|
|
|
|
let stdout = String::from_utf8(out.stdout).expect("utf-8 stdout");
|
|
// exactly one line (the JSON object + a trailing newline from println!).
|
|
assert_eq!(stdout.lines().count(), 1, "stdout was: {stdout:?}");
|
|
let line = stdout.trim_end();
|
|
|
|
// canonical cycle-0009 JSON shape: nested manifest + metrics, stable keys.
|
|
// The manifest leads with a `commit` field; its value is the build's git
|
|
// identity (asserted by `run_manifest_commit_carries_real_git_head`), so
|
|
// this shape check pins only the surrounding structure, not the value.
|
|
assert!(line.starts_with("{\"manifest\":{\"commit\":\""), "got: {line}");
|
|
assert!(line.contains("\"broker\":\"sim-optimal(pip_size=0.0001)\""), "got: {line}");
|
|
assert!(line.contains("\"window\":[1,7]"), "got: {line}");
|
|
assert!(line.contains("\"metrics\":{\"total_pips\":"), "got: {line}");
|
|
// the integer sign-flip count is stable across float renderings.
|
|
assert!(line.ends_with("\"exposure_sign_flips\":1}}"), "got: {line}");
|
|
}
|
|
|
|
/// Property: the RunManifest is self-identifying — its `commit` carries the
|
|
/// real code identity that produced the run, not a placeholder. C8/C18 audit
|
|
/// trail (this run = this commit): once runs are archived, `manifest.commit`
|
|
/// must point back at the source. The build captures the current git HEAD at
|
|
/// compile time; the `"unknown"` literal survives only when there is no git.
|
|
///
|
|
/// Structural assertion (not exact-equality) on purpose: the working tree may
|
|
/// be dirty when this runs (e.g. this very test file uncommitted), so a build
|
|
/// that appends a `-dirty` suffix would not equal `rev-parse HEAD` verbatim.
|
|
/// The honest contract is: the field CONTAINS the current HEAD sha AND is not
|
|
/// the bare `"unknown"` placeholder — true regardless of dirtiness/suffix.
|
|
#[test]
|
|
fn run_manifest_commit_carries_real_git_head() {
|
|
// The current HEAD sha, obtained the same way the build is expected to.
|
|
let head = Command::new("git")
|
|
.args(["rev-parse", "HEAD"])
|
|
.output()
|
|
.expect("spawn git rev-parse HEAD");
|
|
assert!(head.status.success(), "git rev-parse HEAD failed");
|
|
let head_sha = String::from_utf8(head.stdout).expect("utf-8 sha");
|
|
let head_sha = head_sha.trim();
|
|
assert!(!head_sha.is_empty(), "empty HEAD sha");
|
|
|
|
// Drive the binary and pull `manifest.commit` out of the single JSON line.
|
|
let out = Command::new(BIN).arg("run").output().expect("spawn aura run");
|
|
assert!(out.status.success(), "exit status: {:?}", out.status);
|
|
let stdout = String::from_utf8(out.stdout).expect("utf-8 stdout");
|
|
let line = stdout.trim_end();
|
|
|
|
// Locate the `"commit":"<value>"` value without a JSON dependency (the
|
|
// sibling tests parse this output by substring too).
|
|
let key = "\"commit\":\"";
|
|
let start = line.find(key).expect("manifest has a commit field") + key.len();
|
|
let rest = &line[start..];
|
|
let end = rest.find('"').expect("commit field is a closed string");
|
|
let commit = &rest[..end];
|
|
|
|
assert_ne!(
|
|
commit, "unknown",
|
|
"manifest.commit is still the placeholder: {line}"
|
|
);
|
|
assert!(
|
|
commit.contains(head_sha),
|
|
"manifest.commit {commit:?} should contain the current HEAD sha {head_sha:?}; line: {line}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn no_args_prints_usage_and_exits_two() {
|
|
let out = Command::new(BIN).output().expect("spawn aura");
|
|
assert_eq!(out.status.code(), Some(2), "exit status: {:?}", out.status);
|
|
assert!(out.stdout.is_empty(), "stdout should be empty on the usage path");
|
|
let stderr = String::from_utf8(out.stderr).expect("utf-8 stderr");
|
|
assert!(stderr.contains("usage"), "stderr was: {stderr:?}");
|
|
}
|
|
|
|
/// Property: `--help`/`-h` is the success-path help affordance, not the error
|
|
/// path. A newcomer's reflex first command (C22 first-contact ergonomics, #20)
|
|
/// prints the usage to stdout and exits 0; the conventional `-h` alias behaves
|
|
/// identically. An *unknown* subcommand keeps the error path (exit 2) so the
|
|
/// help fix does not regress bad-args handling.
|
|
#[test]
|
|
fn help_flag_prints_usage_to_stdout_and_exits_zero() {
|
|
for flag in ["--help", "-h"] {
|
|
let out = Command::new(BIN).arg(flag).output().expect("spawn aura --help");
|
|
assert_eq!(out.status.code(), Some(0), "`aura {flag}` exit: {:?}", out.status);
|
|
let stdout = String::from_utf8(out.stdout).expect("utf-8 stdout");
|
|
assert!(
|
|
!stdout.trim().is_empty(),
|
|
"`aura {flag}` should print help to stdout, got: {stdout:?}"
|
|
);
|
|
// The usage names the only subcommand a newcomer can run.
|
|
assert!(
|
|
stdout.contains("run"),
|
|
"`aura {flag}` help should mention the `run` subcommand, got: {stdout:?}"
|
|
);
|
|
}
|
|
|
|
// Negative-preservation: an unknown subcommand is still the error path.
|
|
let out = Command::new(BIN).arg("frobnicate").output().expect("spawn aura frobnicate");
|
|
assert_eq!(
|
|
out.status.code(),
|
|
Some(2),
|
|
"unknown subcommand must stay exit 2: {:?}",
|
|
out.status
|
|
);
|
|
}
|