chore: expand cli execution stub coverage
This commit is contained in:
1 parent
812b486855
commit
1454e64066
4 files changed
+174
-2
No files matched your search
@@ -253,6 +253,24 @@ enum ExecutionContract {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
enum ExecutionStub {
|
||||
SummaryOnly {
|
||||
command: String,
|
||||
},
|
||||
HttpRequest {
|
||||
method: &'static str,
|
||||
path: String,
|
||||
api_key_present: bool,
|
||||
body: Option<String>,
|
||||
},
|
||||
LocalAction {
|
||||
action: &'static str,
|
||||
target: String,
|
||||
detail: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
println!("CLI scaffold ready for {}", render_command_summary(&cli));
|
||||
@@ -374,6 +392,17 @@ fn execution_contract(plan: &CommandPlan) -> ExecutionContract {
|
||||
}
|
||||
}
|
||||
|
||||
fn execution_stub(contract: &ExecutionContract) -> ExecutionStub {
|
||||
match contract {
|
||||
ExecutionContract::SummaryOnly { command } => ExecutionStub::SummaryOnly {
|
||||
command: command.clone(),
|
||||
},
|
||||
_ => ExecutionStub::SummaryOnly {
|
||||
command: "unimplemented".to_owned(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn command_summary(command: &Commands) -> String {
|
||||
match command {
|
||||
Commands::Status => "status".to_owned(),
|
||||
@@ -460,8 +489,8 @@ fn bench_command_summary(command: &BenchCommand) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
execution_contract, plan_command, render_command_summary, AuthMode, Cli, CommandPlan,
|
||||
Commands, ExecutionContract,
|
||||
execution_contract, execution_stub, plan_command, render_command_summary, AuthMode, Cli,
|
||||
CommandPlan, Commands, ExecutionContract, ExecutionStub,
|
||||
};
|
||||
use clap::Parser;
|
||||
|
||||
@@ -920,4 +949,131 @@ mod tests {
|
||||
ExecutionContract::LocalLogRead { lines: 50 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_status_stub_targets_http_get_health() {
|
||||
let cli = Cli::try_parse_from(["localllm", "--api-key", "secret", "status"]).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
execution_stub(&execution_contract(&plan_command(&cli))),
|
||||
ExecutionStub::HttpRequest {
|
||||
method: "GET",
|
||||
path: "/health".to_owned(),
|
||||
api_key_present: true,
|
||||
body: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_models_scan_stub_names_local_scan_action() {
|
||||
let cli = Cli::try_parse_from(["localllm", "--models-dir", "D:/models", "models", "scan"])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
execution_stub(&execution_contract(&plan_command(&cli))),
|
||||
ExecutionStub::LocalAction {
|
||||
action: "scan_models_dir",
|
||||
target: "D:/models".to_owned(),
|
||||
detail: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_models_load_stub_names_local_load_action() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--models-dir",
|
||||
"D:/models",
|
||||
"models",
|
||||
"load",
|
||||
"qwen.gguf",
|
||||
"--alias",
|
||||
"qwen-coder",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
execution_stub(&execution_contract(&plan_command(&cli))),
|
||||
ExecutionStub::LocalAction {
|
||||
action: "load_model",
|
||||
target: "D:/models".to_owned(),
|
||||
detail: Some("model=qwen.gguf alias=qwen-coder".to_owned()),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_auth_enable_stub_names_local_auth_action() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"auth",
|
||||
"enable",
|
||||
"--mode",
|
||||
"local-only",
|
||||
"--api-key",
|
||||
"secret",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
execution_stub(&execution_contract(&plan_command(&cli))),
|
||||
ExecutionStub::LocalAction {
|
||||
action: "configure_auth",
|
||||
target: "auth".to_owned(),
|
||||
detail: Some("mode=local-only has_api_key=true".to_owned()),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_bench_stub_targets_chat_completion_post() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--api-key",
|
||||
"secret",
|
||||
"bench",
|
||||
"throughput",
|
||||
"--samples",
|
||||
"5",
|
||||
"--prompt-tokens",
|
||||
"512",
|
||||
"--completion-tokens",
|
||||
"64",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
execution_stub(&execution_contract(&plan_command(&cli))),
|
||||
ExecutionStub::HttpRequest {
|
||||
method: "POST",
|
||||
path: "/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_stub_names_local_tail_action() {
|
||||
let cli = Cli::try_parse_from(["localllm", "logs", "--lines", "50"]).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
execution_stub(&execution_contract(&plan_command(&cli))),
|
||||
ExecutionStub::LocalAction {
|
||||
action: "tail_logs",
|
||||
target: "logs".to_owned(),
|
||||
detail: Some("lines=50".to_owned()),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user