chore: expand cli backend invocation coverage
This commit is contained in:
1 parent
d9408fc09a
commit
3969f12f26
1 file changed
+116
-3
@@ -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<String>,
|
||||
},
|
||||
}
|
||||
|
||||
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(),
|
||||
),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user