chore: expand cli backend response coverage
This commit is contained in:
1 parent
e313c88bdb
commit
bf985ea9ea
7 files changed
+341
-9
No files matched your search
@@ -1,4 +1,5 @@
|
||||
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
|
||||
enum OutputFormat {
|
||||
@@ -321,6 +322,57 @@ enum BackendRequest {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum BackendResponsePreview {
|
||||
SummaryOnly {
|
||||
command: String,
|
||||
},
|
||||
Health {
|
||||
status: String,
|
||||
model_loaded: bool,
|
||||
model_id: Option<String>,
|
||||
uptime_secs: u64,
|
||||
},
|
||||
Models {
|
||||
count: usize,
|
||||
ids: Vec<String>,
|
||||
},
|
||||
Throughput {
|
||||
model: String,
|
||||
total_tokens: u32,
|
||||
tokens_per_second: f64,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CliHealthResponse {
|
||||
status: String,
|
||||
model_loaded: bool,
|
||||
model_id: Option<String>,
|
||||
uptime_secs: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CliModelList {
|
||||
data: Vec<CliModelInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CliModelInfo {
|
||||
id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CliBenchResponse {
|
||||
usage: CliUsage,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CliUsage {
|
||||
total_tokens: u32,
|
||||
tokens_per_second: f64,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
if cli.dry_run {
|
||||
@@ -695,6 +747,33 @@ fn backend_request(cli: &Cli) -> BackendRequest {
|
||||
}
|
||||
}
|
||||
|
||||
fn backend_response_preview(cli: &Cli, _status_code: u16, _body: &str) -> BackendResponsePreview {
|
||||
match &cli.command {
|
||||
Commands::Status => BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
},
|
||||
Commands::Models(models) => match &models.command {
|
||||
ModelsSubcommand::List => BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
},
|
||||
_ => BackendResponsePreview::SummaryOnly {
|
||||
command: command_summary(&cli.command),
|
||||
},
|
||||
},
|
||||
Commands::Bench(bench) => match &bench.command {
|
||||
BenchSubcommand::Throughput(_) => BackendResponsePreview::SummaryOnly {
|
||||
command: "response-unimplemented".to_owned(),
|
||||
},
|
||||
_ => BackendResponsePreview::SummaryOnly {
|
||||
command: command_summary(&cli.command),
|
||||
},
|
||||
},
|
||||
_ => BackendResponsePreview::SummaryOnly {
|
||||
command: command_summary(&cli.command),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn bearer_headers(cli: &Cli) -> Vec<(String, String)> {
|
||||
cli.api_key
|
||||
.as_ref()
|
||||
@@ -822,10 +901,11 @@ fn bench_command_summary(command: &BenchCommand) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
backend_invocation, backend_request, execution_contract, execution_preview, execution_stub,
|
||||
plan_command, render_command_summary, render_execution_preview, AuthMode,
|
||||
BackendInvocation, BackendRequest, Cli, CommandPlan, Commands, ExecutionContract,
|
||||
ExecutionPreview, ExecutionStub,
|
||||
backend_invocation, backend_request, backend_response_preview, execution_contract,
|
||||
execution_preview, execution_stub, plan_command, render_command_summary,
|
||||
render_execution_preview, AuthMode, BackendInvocation, BackendRequest,
|
||||
BackendResponsePreview, Cli, CommandPlan, Commands, ExecutionContract, ExecutionPreview,
|
||||
ExecutionStub,
|
||||
};
|
||||
use clap::Parser;
|
||||
use serde_json::json;
|
||||
@@ -1874,4 +1954,74 @@ mod tests {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_status_response_parses_health_payload() {
|
||||
let cli = Cli::try_parse_from(["localllm", "status"]).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
backend_response_preview(
|
||||
&cli,
|
||||
200,
|
||||
r#"{"status":"ok","model_loaded":true,"model_id":"qwen-coder","uptime_secs":12}"#,
|
||||
),
|
||||
BackendResponsePreview::Health {
|
||||
status: "ok".to_owned(),
|
||||
model_loaded: true,
|
||||
model_id: Some("qwen-coder".to_owned()),
|
||||
uptime_secs: 12,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_models_list_response_collects_ids() {
|
||||
let cli = Cli::try_parse_from(["localllm", "models", "list"]).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
backend_response_preview(
|
||||
&cli,
|
||||
200,
|
||||
r#"{"object":"list","data":[{"id":"qwen-coder"},{"id":"gemma-3"}]}"#,
|
||||
),
|
||||
BackendResponsePreview::Models {
|
||||
count: 2,
|
||||
ids: vec!["qwen-coder".to_owned(), "gemma-3".to_owned()],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_bench_response_reads_usage_metrics() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"bench",
|
||||
"throughput",
|
||||
"--model",
|
||||
"qwen-coder",
|
||||
"--samples",
|
||||
"5",
|
||||
"--prompt-tokens",
|
||||
"8",
|
||||
"--completion-tokens",
|
||||
"64",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
backend_response_preview(
|
||||
&cli,
|
||||
200,
|
||||
r#"{"usage":{"prompt_tokens":8,"completion_tokens":64,"total_tokens":72,"tokens_per_second":42.5}}"#,
|
||||
),
|
||||
BackendResponsePreview::Throughput {
|
||||
model: "qwen-coder".to_owned(),
|
||||
total_tokens: 72,
|
||||
tokens_per_second: 42.5,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user