chore: expand cli live execution coverage
This commit is contained in:
1 parent
1501d2388a
commit
4f94b98f4f
4 files changed
+186
-5
No files matched your search
@@ -344,6 +344,12 @@ enum BackendResponsePreview {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct LiveExecutionResponse {
|
||||
status_code: u16,
|
||||
body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CliHealthResponse {
|
||||
status: String,
|
||||
@@ -518,6 +524,21 @@ fn render_backend_response(cli: &Cli, status_code: u16, body: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_live_command_with<F>(cli: &Cli, mut transport: F) -> String
|
||||
where
|
||||
F: FnMut(&BackendRequest) -> LiveExecutionResponse,
|
||||
{
|
||||
let request = backend_request(cli);
|
||||
|
||||
match request {
|
||||
BackendRequest::SummaryOnly { command } => format!("LIVE {}", command),
|
||||
_ => {
|
||||
let _response = transport(&request);
|
||||
format!("LIVE EXEC {}", render_command_summary(cli))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_json_optional_string(value: Option<&str>) -> String {
|
||||
match value {
|
||||
Some(value) => format!(r#""{}""#, value),
|
||||
@@ -999,11 +1020,11 @@ fn bench_command_summary(command: &BenchCommand) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
backend_invocation, backend_request, backend_response_preview, execution_contract,
|
||||
execution_preview, execution_stub, plan_command, render_backend_response,
|
||||
render_command_summary, render_execution_preview, AuthMode, BackendInvocation,
|
||||
BackendRequest, BackendResponsePreview, Cli, CommandPlan, Commands, ExecutionContract,
|
||||
ExecutionPreview, ExecutionStub,
|
||||
backend_invocation, backend_request, backend_response_preview, execute_live_command_with,
|
||||
execution_contract, execution_preview, execution_stub, plan_command,
|
||||
render_backend_response, render_command_summary, render_execution_preview, AuthMode,
|
||||
BackendInvocation, BackendRequest, BackendResponsePreview, Cli, CommandPlan, Commands,
|
||||
ExecutionContract, ExecutionPreview, ExecutionStub, LiveExecutionResponse,
|
||||
};
|
||||
use clap::Parser;
|
||||
use serde_json::json;
|
||||
@@ -2240,4 +2261,139 @@ mod tests {
|
||||
r#"{"kind":"throughput","model":"qwen-coder","total_tokens":72,"tokens_per_second":42.5}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_status_execute_pipeline_uses_transport_and_renders_text() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--server",
|
||||
"http://127.0.0.1:9999",
|
||||
"--api-key",
|
||||
"secret",
|
||||
"status",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let rendered = execute_live_command_with(&cli, |request| {
|
||||
assert_eq!(
|
||||
request,
|
||||
&BackendRequest::HttpRequest {
|
||||
method: "GET",
|
||||
url: "http://127.0.0.1:9999/health".to_owned(),
|
||||
headers: vec![("authorization".to_owned(), "Bearer secret".to_owned())],
|
||||
body: None,
|
||||
}
|
||||
);
|
||||
|
||||
LiveExecutionResponse {
|
||||
status_code: 200,
|
||||
body: r#"{"status":"ok","model_loaded":true,"model_id":"qwen-coder","uptime_secs":12}"#.to_owned(),
|
||||
}
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
rendered,
|
||||
"STATUS status=ok model_loaded=true model_id=qwen-coder uptime_secs=12"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_models_execute_pipeline_uses_transport_and_renders_json() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"localllm",
|
||||
"--server",
|
||||
"http://127.0.0.1:9999",
|
||||
"--format",
|
||||
"json",
|
||||
"models",
|
||||
"list",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let rendered = execute_live_command_with(&cli, |request| {
|
||||
assert_eq!(
|
||||
request,
|
||||
&BackendRequest::HttpRequest {
|
||||
method: "GET",
|
||||
url: "http://127.0.0.1:9999/v1/models".to_owned(),
|
||||
headers: vec![],
|
||||
body: None,
|
||||
}
|
||||
);
|
||||
|
||||
LiveExecutionResponse {
|
||||
status_code: 200,
|
||||
body: r#"{"object":"list","data":[{"id":"qwen-coder"},{"id":"gemma-3"}]}"#
|
||||
.to_owned(),
|
||||
}
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
rendered,
|
||||
r#"{"kind":"models","count":2,"ids":["qwen-coder","gemma-3"]}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "autoresearch benchmark"]
|
||||
fn cli_surface_bench_execute_pipeline_uses_transport_and_renders_text() {
|
||||
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",
|
||||
"8",
|
||||
"--completion-tokens",
|
||||
"64",
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
let rendered = execute_live_command_with(&cli, |request| {
|
||||
assert_eq!(
|
||||
request,
|
||||
&BackendRequest::HttpRequest {
|
||||
method: "POST",
|
||||
url: "http://127.0.0.1:9999/v1/chat/completions".to_owned(),
|
||||
headers: vec![
|
||||
("authorization".to_owned(), "Bearer secret".to_owned()),
|
||||
("content-type".to_owned(), "application/json".to_owned()),
|
||||
],
|
||||
body: Some(
|
||||
json!({
|
||||
"model": "qwen-coder",
|
||||
"stream": false,
|
||||
"temperature": 0.0,
|
||||
"top_p": 1.0,
|
||||
"max_completion_tokens": 64,
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": "benchmark token benchmark token benchmark token benchmark token"
|
||||
}],
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
LiveExecutionResponse {
|
||||
status_code: 200,
|
||||
body: r#"{"usage":{"prompt_tokens":8,"completion_tokens":64,"total_tokens":72,"tokens_per_second":42.5}}"#.to_owned(),
|
||||
}
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
rendered,
|
||||
"THROUGHPUT model=qwen-coder total_tokens=72 tokens_per_second=42.5"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user