feat(cli): print the engine commit in --version

aura --version now prints 'aura 0.1.0 (<commit>)', the commit sourced
from the same AURA_COMMIT build provenance the run manifest stamps
(option_env! at build time, 'unknown' fallback, dirty suffix included)
— a pre-run freshness probe: a stale binary is now distinguishable from
an engine bug at the CLI surface, and research docs pinning
'Engine: aura @ <sha>' can verify the binary they invoke.

The version string is memoized as a OnceLock-leaked &'static str:
clap 4.6's builder Str accepts only &'static str (no From<String>), so
the owned-String alternative a quality pass suggested does not build —
verified, held with evidence in the loop report.

closes #266
This commit is contained in:
2026-07-13 22:26:47 +02:00
parent 5a1696891a
commit be9f1cef8c
+30 -4
View File
@@ -125,7 +125,7 @@ fn sim_optimal_manifest(
// Typed params pass straight through: the manifest carries self-describing // Typed params pass straight through: the manifest carries self-describing
// Scalars, so a length stays `i64` and a scale `f64` in the record. // Scalars, so a length stays `i64` and a scale `f64` in the record.
RunManifest { RunManifest {
commit: option_env!("AURA_COMMIT").unwrap_or("unknown").to_string(), commit: ENGINE_COMMIT.to_string(),
params, params,
defaults: Vec::new(), defaults: Vec::new(),
window, window,
@@ -2640,10 +2640,36 @@ fn parse_scalar_csv(csv: &str) -> Option<Vec<Scalar>> {
// the campaign path. Usage errors (clap parse + argv-applicability guards) exit 2; // the campaign path. Usage errors (clap parse + argv-applicability guards) exit 2;
// runtime failures exit 1. // runtime failures exit 1.
/// The `aura` root parser. `#[command(version)]` reads `CARGO_PKG_VERSION` /// The single build-time commit provenance (`option_env!("AURA_COMMIT")`,
/// (the workspace `0.1.0`), so `aura --version` prints `aura 0.1.0`. /// falling back to `"unknown"`): both `--version` (via `version_string`) and
/// `sim_optimal_manifest`'s `RunManifest.commit` read this one const, so a
/// stale binary is distinguishable from a fresh one at the CLI surface,
/// before any run, without a second commit-sourcing mechanism (#266).
const ENGINE_COMMIT: &str = match option_env!("AURA_COMMIT") {
Some(c) => c,
None => "unknown",
};
/// `aura 0.1.0 (<commit>)` as a process-lifetime `&'static str` — computed once
/// (clap's `version` builder method wants `Into<Str>`, and `clap::builder::Str`
/// (clap 4.6) only implements `From<&'static str>`, not `From<String>`, so the
/// one owned `String` this formats is leaked for the process's lifetime, same
/// as any other CLI one-shot startup string).
fn version_string() -> &'static str {
static VERSION: std::sync::OnceLock<String> = std::sync::OnceLock::new();
VERSION.get_or_init(|| format!("{} ({ENGINE_COMMIT})", env!("CARGO_PKG_VERSION")))
}
/// The `aura` root parser. `version` is built from `CARGO_PKG_VERSION` (the
/// workspace `0.1.0`) plus the parenthesized `ENGINE_COMMIT`, so
/// `aura --version` prints `aura 0.1.0 (<commit>)`.
#[derive(Parser)] #[derive(Parser)]
#[command(name = "aura", version, about = "Author, backtest, and validate trading strategies — research CLI", infer_long_args = true)] #[command(
name = "aura",
version = version_string(),
about = "Author, backtest, and validate trading strategies — research CLI",
infer_long_args = true
)]
struct Cli { struct Cli {
#[command(subcommand)] #[command(subcommand)]
command: Command, command: Command,