From 3969f12f26a3b3f74a46e07674309416ad4f05ed Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Thu, 26 Mar 2026 19:39:51 -0300 Subject: [PATCH] chore: expand cli backend invocation coverage --- crates/localllm-cli/src/main.rs | 119 +++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 3 deletions(-) diff --git a/crates/localllm-cli/src/main.rs b/crates/localllm-cli/src/main.rs index a0e913b..b9ce4bc 100644 --- a/crates/localllm-cli/src/main.rs +++ b/crates/localllm-cli/src/main.rs @@ -159,6 +159,9 @@ enum BenchSubcommand { #[derive(Debug, Args)] struct BenchThroughputArgs { + #[arg(long, default_value = "default")] + model: String, + #[arg(long, default_value_t = 3)] samples: u32, @@ -292,6 +295,19 @@ enum ExecutionPreview { }, } +#[derive(Debug, Clone, PartialEq, Eq)] +enum BackendInvocation { + SummaryOnly { + command: String, + }, + HttpCall { + method: &'static str, + url: String, + api_key_present: bool, + body: Option, + }, +} + fn main() -> anyhow::Result<()> { let cli = Cli::parse(); if cli.dry_run { @@ -597,6 +613,20 @@ fn preview_effect(action: &str, detail: Option<&str>) -> String { } } +fn backend_invocation(cli: &Cli) -> BackendInvocation { + let preview = execution_preview( + cli, + &execution_stub(&execution_contract(&plan_command(cli))), + ); + + match preview { + ExecutionPreview::SummaryOnly { command } => BackendInvocation::SummaryOnly { command }, + _ => BackendInvocation::SummaryOnly { + command: "backend-unimplemented".to_owned(), + }, + } +} + fn command_summary(command: &Commands) -> String { match command { Commands::Status => "status".to_owned(), @@ -683,9 +713,9 @@ fn bench_command_summary(command: &BenchCommand) -> String { #[cfg(test)] mod tests { use super::{ - execution_contract, execution_preview, execution_stub, plan_command, - render_command_summary, render_execution_preview, AuthMode, Cli, CommandPlan, Commands, - ExecutionContract, ExecutionPreview, ExecutionStub, + backend_invocation, execution_contract, execution_preview, execution_stub, plan_command, + render_command_summary, render_execution_preview, AuthMode, BackendInvocation, Cli, + CommandPlan, Commands, ExecutionContract, ExecutionPreview, ExecutionStub, }; use clap::Parser; @@ -1551,4 +1581,87 @@ mod tests { "DRY RUN tail_logs target=logs effect=tail last 50 lines" ); } + + #[test] + #[ignore = "autoresearch benchmark"] + fn cli_surface_status_backend_call_targets_live_health_endpoint() { + let cli = Cli::try_parse_from([ + "localllm", + "--server", + "http://127.0.0.1:9999", + "--api-key", + "secret", + "status", + ]) + .unwrap(); + + assert_eq!( + backend_invocation(&cli), + BackendInvocation::HttpCall { + 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_list_backend_call_targets_live_models_endpoint() { + let cli = Cli::try_parse_from([ + "localllm", + "--server", + "http://127.0.0.1:9999", + "models", + "list", + ]) + .unwrap(); + + assert_eq!( + backend_invocation(&cli), + BackendInvocation::HttpCall { + method: "GET", + url: "http://127.0.0.1:9999/v1/models".to_owned(), + api_key_present: false, + body: None, + } + ); + } + + #[test] + #[ignore = "autoresearch benchmark"] + fn cli_surface_bench_backend_call_preserves_model_and_budget() { + let cli = Cli::try_parse_from([ + "localllm", + "--server", + "http://127.0.0.1:9999", + "--api-key", + "secret", + "bench", + "throughput", + "--model", + "qwen-coder", + "--samples", + "5", + "--prompt-tokens", + "512", + "--completion-tokens", + "64", + ]) + .unwrap(); + + assert_eq!( + backend_invocation(&cli), + BackendInvocation::HttpCall { + method: "POST", + url: "http://127.0.0.1:9999/v1/chat/completions".to_owned(), + api_key_present: true, + body: Some( + "model=qwen-coder samples=5 prompt_tokens=512 completion_tokens=64 stream=false" + .to_owned(), + ), + } + ); + } }