chore: expand cli dry-run output coverage
This commit is contained in:
1 parent
633b39eb53
commit
14e406b3ba
1 file changed
+139
-3
@@ -19,6 +19,9 @@ struct Cli {
|
||||
#[arg(long, global = true, default_value = "http://127.0.0.1:8080")]
|
||||
server: String,
|
||||
|
||||
#[arg(long, global = true, default_value_t = false)]
|
||||
dry_run: bool,
|
||||
|
||||
#[arg(long, global = true)]
|
||||
api_key: Option<String>,
|
||||
|
||||
@@ -291,10 +294,18 @@ enum ExecutionPreview {
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
println!("CLI scaffold ready for {}", render_command_summary(&cli));
|
||||
if cli.dry_run {
|
||||
println!("{}", render_execution_preview(&cli));
|
||||
} else {
|
||||
println!("CLI scaffold ready for {}", render_command_summary(&cli));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_execution_preview(cli: &Cli) -> String {
|
||||
format!("DRY RUN {}", render_command_summary(cli))
|
||||
}
|
||||
|
||||
fn render_command_summary(cli: &Cli) -> String {
|
||||
format!(
|
||||
"command={} server={} format={} models_dir={}",
|
||||
@@ -608,8 +619,8 @@ fn bench_command_summary(command: &BenchCommand) -> String {
|
||||
mod tests {
|
||||
use super::{
|
||||
execution_contract, execution_preview, execution_stub, plan_command,
|
||||
render_command_summary, AuthMode, Cli, CommandPlan, Commands, ExecutionContract,
|
||||
ExecutionPreview, ExecutionStub,
|
||||
render_command_summary, render_execution_preview, AuthMode, Cli, CommandPlan, Commands,
|
||||
ExecutionContract, ExecutionPreview, ExecutionStub,
|
||||
};
|
||||
use clap::Parser;
|
||||
|
||||
@@ -1350,4 +1361,129 @@ mod tests {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_status_dry_run_text_renders_full_health_request() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--dry-run",
|
||||
"--server",
|
||||
"http://127.0.0.1:9999",
|
||||
"--api-key",
|
||||
"secret",
|
||||
"status",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
render_execution_preview(&cli),
|
||||
"DRY RUN GET http://127.0.0.1:9999/health api_key_present=true"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_status_dry_run_json_renders_method_url() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--dry-run",
|
||||
"--format",
|
||||
"json",
|
||||
"--server",
|
||||
"http://127.0.0.1:9999",
|
||||
"--api-key",
|
||||
"secret",
|
||||
"status",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
render_execution_preview(&cli),
|
||||
r#"{"kind":"http","method":"GET","url":"http://127.0.0.1:9999/health","api_key_present":true,"body":null}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_models_load_dry_run_text_mentions_alias_effect() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--dry-run",
|
||||
"--models-dir",
|
||||
"D:/models",
|
||||
"models",
|
||||
"load",
|
||||
"qwen.gguf",
|
||||
"--alias",
|
||||
"qwen-coder",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
render_execution_preview(&cli),
|
||||
"DRY RUN load_model target=D:/models effect=load model=qwen.gguf alias=qwen-coder"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_auth_enable_dry_run_text_mentions_mode() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--dry-run",
|
||||
"auth",
|
||||
"enable",
|
||||
"--mode",
|
||||
"local-only",
|
||||
"--api-key",
|
||||
"secret",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
render_execution_preview(&cli),
|
||||
"DRY RUN configure_auth target=auth effect=set mode=local-only has_api_key=true"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_bench_dry_run_json_preserves_payload() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--dry-run",
|
||||
"--format",
|
||||
"json",
|
||||
"--server",
|
||||
"http://127.0.0.1:9999",
|
||||
"--api-key",
|
||||
"secret",
|
||||
"bench",
|
||||
"throughput",
|
||||
"--samples",
|
||||
"5",
|
||||
"--prompt-tokens",
|
||||
"512",
|
||||
"--completion-tokens",
|
||||
"64",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
render_execution_preview(&cli),
|
||||
r#"{"kind":"http","method":"POST","url":"http://127.0.0.1:9999/v1/chat/completions","api_key_present":true,"body":"samples=5 prompt_tokens=512 completion_tokens=64 stream=false"}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_logs_dry_run_text_mentions_tail_effect() {
|
||||
let cli = Cli::try_parse_from(["localllm", "--dry-run", "logs", "--lines", "50"]).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
render_execution_preview(&cli),
|
||||
"DRY RUN tail_logs target=logs effect=tail last 50 lines"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user