repositories / smith
smith
There are many coding harnesses - but this one is fast
owned by admin
smith-cli/tests/e2e_help.rs
Raw//! Help text of the built `smith` binary, pinned as snapshots
//! (`SMH-SPEC-SPEC0001`, Interface modes).
//!
//! Selection variables are removed: clap prints their current values in
//! `[env: …]`, which would leak the caller's environment into the snapshot.
use assert_cmd::Command;
use smith_cli::{short_help, short_help_surface};
fn help(args: &[&str]) -> Vec<u8> {
let output = Command::cargo_bin("smith")
.unwrap()
.args(args)
.env_clear()
.output()
.unwrap();
assert!(output.status.success(), "{output:?}");
assert!(output.stderr.is_empty(), "{output:?}");
output.stdout
}
fn help_with_selection_environment(provider: &str, model: &str) -> Vec<u8> {
let output = Command::cargo_bin("smith")
.unwrap()
.args(["--help"])
.env_clear()
.env("SMITH_PROVIDER", provider)
.env("SMITH_MODEL", model)
.output()
.unwrap();
assert!(output.status.success(), "{output:?}");
assert!(output.stderr.is_empty(), "{output:?}");
output.stdout
}
#[test]
fn help_top_level() {
insta::assert_snapshot!(String::from_utf8(help(&["--help"])).unwrap());
}
#[test]
fn short_help_surface_matches_built_binary_bytes() {
let binary = help(&["--help"]);
assert_eq!(short_help().unwrap().as_bytes(), binary);
assert_eq!(
short_help_surface().unwrap().rendered_bytes,
binary.len() as u64
);
}
#[test]
fn selection_environment_does_not_change_root_help_or_surface() {
let baseline = help(&["--help"]);
assert_eq!(
help_with_selection_environment("openai", "fixture-a"),
baseline
);
assert_eq!(
help_with_selection_environment("google", "fixture-b"),
baseline
);
assert_eq!(short_help().unwrap().as_bytes(), baseline);
}
#[test]
fn help_eval() {
insta::assert_snapshot!(String::from_utf8(help(&["eval", "--help"])).unwrap());
}
#[test]
fn help_login() {
insta::assert_snapshot!(String::from_utf8(help(&["login", "--help"])).unwrap());
}
#[test]
fn help_logout() {
insta::assert_snapshot!(String::from_utf8(help(&["logout", "--help"])).unwrap());
}
#[test]
fn help_plugin_trust_discloses_process_authority() {
insta::assert_snapshot!(String::from_utf8(help(&["plugin", "trust", "--help"])).unwrap());
}