chore: expand cli preview coverage

This commit is contained in:
Evandro Fonseca Junior committed 2026-03-26 19:27:18 -03:00
1 parent 0d92b0a445
commit a326b92744
1 file changed
+187 -2
+187 -2
View File
@@ -271,6 +271,24 @@ enum ExecutionStub {
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
enum ExecutionPreview {
SummaryOnly {
command: String,
},
HttpPreview {
method: &'static str,
url: String,
api_key_present: bool,
body: Option<String>,
},
LocalPreview {
action: &'static str,
target: String,
effect: String,
},
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
println!("CLI scaffold ready for {}", render_command_summary(&cli));
@@ -460,6 +478,17 @@ fn execution_stub(contract: &ExecutionContract) -> ExecutionStub {
}
}
fn execution_preview(_cli: &Cli, stub: &ExecutionStub) -> ExecutionPreview {
match stub {
ExecutionStub::SummaryOnly { command } => ExecutionPreview::SummaryOnly {
command: command.clone(),
},
_ => ExecutionPreview::SummaryOnly {
command: "preview-unimplemented".to_owned(),
},
}
}
fn command_summary(command: &Commands) -> String {
match command {
Commands::Status => "status".to_owned(),
@@ -546,8 +575,9 @@ fn bench_command_summary(command: &BenchCommand) -> String {
#[cfg(test)]
mod tests {
use super::{
execution_contract, execution_stub, plan_command, render_command_summary, AuthMode, Cli,
CommandPlan, Commands, ExecutionContract, ExecutionStub,
execution_contract, execution_preview, execution_stub, plan_command,
render_command_summary, AuthMode, Cli, CommandPlan, Commands, ExecutionContract,
ExecutionPreview, ExecutionStub,
};
use clap::Parser;
@@ -1133,4 +1163,159 @@ mod tests {
}
);
}
#[test]
#[ignore = "autoresearch benchmark"]
fn cli_surface_status_preview_expands_full_health_url() {
let cli = Cli::try_parse_from([
"localllm",
"--server",
"http://127.0.0.1:9999",
"--api-key",
"secret",
"status",
])
.unwrap();
assert_eq!(
execution_preview(
&cli,
&execution_stub(&execution_contract(&plan_command(&cli)))
),
ExecutionPreview::HttpPreview {
method: "GET",
url: "http://127.0.0.1:9999/health".to_owned(),
api_key_present: true,
body: None,
}
);
}
#[test]
#[ignore = "autoresearch benchmark"]
fn cli_surface_models_scan_preview_describes_scan_effect() {
let cli = Cli::try_parse_from(["localllm", "--models-dir", "D:/models", "models", "scan"])
.unwrap();
assert_eq!(
execution_preview(
&cli,
&execution_stub(&execution_contract(&plan_command(&cli)))
),
ExecutionPreview::LocalPreview {
action: "scan_models_dir",
target: "D:/models".to_owned(),
effect: "discover available model files".to_owned(),
}
);
}
#[test]
#[ignore = "autoresearch benchmark"]
fn cli_surface_models_load_preview_describes_alias_effect() {
let cli = Cli::try_parse_from([
"localllm",
"--models-dir",
"D:/models",
"models",
"load",
"qwen.gguf",
"--alias",
"qwen-coder",
])
.unwrap();
assert_eq!(
execution_preview(
&cli,
&execution_stub(&execution_contract(&plan_command(&cli)))
),
ExecutionPreview::LocalPreview {
action: "load_model",
target: "D:/models".to_owned(),
effect: "load model=qwen.gguf alias=qwen-coder".to_owned(),
}
);
}
#[test]
#[ignore = "autoresearch benchmark"]
fn cli_surface_auth_enable_preview_describes_auth_effect() {
let cli = Cli::try_parse_from([
"localllm",
"auth",
"enable",
"--mode",
"local-only",
"--api-key",
"secret",
])
.unwrap();
assert_eq!(
execution_preview(
&cli,
&execution_stub(&execution_contract(&plan_command(&cli)))
),
ExecutionPreview::LocalPreview {
action: "configure_auth",
target: "auth".to_owned(),
effect: "set mode=local-only has_api_key=true".to_owned(),
}
);
}
#[test]
#[ignore = "autoresearch benchmark"]
fn cli_surface_bench_preview_expands_full_chat_url_and_payload() {
let cli = Cli::try_parse_from([
"localllm",
"--server",
"http://127.0.0.1:9999",
"--api-key",
"secret",
"bench",
"throughput",
"--samples",
"5",
"--prompt-tokens",
"512",
"--completion-tokens",
"64",
])
.unwrap();
assert_eq!(
execution_preview(
&cli,
&execution_stub(&execution_contract(&plan_command(&cli)))
),
ExecutionPreview::HttpPreview {
method: "POST",
url: "http://127.0.0.1:9999/v1/chat/completions".to_owned(),
api_key_present: true,
body: Some(
"samples=5 prompt_tokens=512 completion_tokens=64 stream=false".to_owned(),
),
}
);
}
#[test]
#[ignore = "autoresearch benchmark"]
fn cli_surface_logs_preview_describes_tail_effect() {
let cli = Cli::try_parse_from(["localllm", "logs", "--lines", "50"]).unwrap();
assert_eq!(
execution_preview(
&cli,
&execution_stub(&execution_contract(&plan_command(&cli)))
),
ExecutionPreview::LocalPreview {
action: "tail_logs",
target: "logs".to_owned(),
effect: "tail last 50 lines".to_owned(),
}
);
}
}