Files
worklane/tests/cmd_version.rs
T
Ansho ReiandClaude Opus 5 32a43b5201 (c28bc04) Report the version and the commit it was built from
worklane --version exited 2: the Cli derive set name and about but never
version, so clap generated no flag. Nothing could say what a given binary
was, which matters here because the opencode tools shell out to whatever
worklane is on PATH, so an agent can be driving a stale build with no way
to notice.

The crate version alone would not have answered it. Cargo.toml is pinned
at 0.1.0 and nobody bumps it per install, so a stale install and a fresh
build both claim the same thing. A build script stamps the short sha
alongside it, giving "worklane 0.1.0 (df97b06)", and falls back to
"unknown" where there is no git directory, as when installing from a
published crate.

propagate_version lets subcommands answer too. This overrides the ticket's
own plan step, which said to skip the sha if it needed a build script.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 14:48:37 +02:00

49 lines
1.6 KiB
Rust

use assert_cmd::Command;
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
fn version_output(arg: &str) -> String {
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let assert = cmd.arg(arg).assert().success();
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
}
#[test]
fn long_flag_reports_the_crate_version() {
let stdout = version_output("--version");
assert!(stdout.starts_with("worklane "), "was {stdout:?}");
assert!(stdout.contains(env!("CARGO_PKG_VERSION")), "was {stdout:?}");
}
#[test]
fn short_flag_matches_the_long_one() {
assert_eq!(version_output("-V"), version_output("--version"));
}
/// The crate version alone cannot tell two builds apart, so the build stamp is
/// the load-bearing half.
#[test]
fn the_output_identifies_the_build() {
let stdout = version_output("--version");
let stamp = stdout
.split_once('(')
.and_then(|(_, rest)| rest.split_once(')'))
.map(|(stamp, _)| stamp.to_string())
.unwrap_or_default();
assert!(!stamp.is_empty(), "no build stamp in {stdout:?}");
// "unknown" is the documented fallback when there is no git directory.
assert!(
stamp == "unknown" || stamp.chars().all(|c| c.is_ascii_hexdigit()),
"stamp was {stamp:?}"
);
}
#[test]
fn subcommands_accept_the_flag_too() {
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let assert = cmd.args(["mv", "--version"]).assert().success();
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
assert!(stdout.contains(env!("CARGO_PKG_VERSION")), "was {stdout:?}");
}