kill 6 non-equivalent survivors in openai_chat and router tests
This commit is contained in:
parent
d65fb21870
commit
4dc182facf
2 changed files with 114 additions and 7 deletions
|
|
@ -742,19 +742,54 @@ fn every_finish_reason_maps_and_required_without_tool_fails() {
|
|||
json!({"prompt_tokens": 3, "completion_tokens": 2}),
|
||||
),
|
||||
));
|
||||
// Auto tool choice with tools present and zero tool calls completes with TextDelta.
|
||||
responses.push((
|
||||
200,
|
||||
chat_ok(
|
||||
"fr-auto-text",
|
||||
json!({"role": "assistant", "content": "plain reply"}),
|
||||
"stop",
|
||||
json!({"prompt_tokens": 3, "completion_tokens": 2}),
|
||||
),
|
||||
));
|
||||
// Empty content string emits no TextDelta event.
|
||||
responses.push((
|
||||
200,
|
||||
chat_ok(
|
||||
"fr-empty-text",
|
||||
json!({"role": "assistant", "content": ""}),
|
||||
"stop",
|
||||
json!({"prompt_tokens": 3, "completion_tokens": 2}),
|
||||
),
|
||||
));
|
||||
|
||||
let (url, _) = mock(responses);
|
||||
let client = backend(url, Some(KEY));
|
||||
let row = deepseek_row();
|
||||
|
||||
for (reason, expected_stop, expected_fail) in cases {
|
||||
let (_, outcome) = client.run_model(&base_request(&row.upstream), &row);
|
||||
let (events, outcome) = client.run_model(&base_request(&row.upstream), &row);
|
||||
match (expected_stop, expected_fail) {
|
||||
(Some(stop), None) => assert!(
|
||||
matches!(outcome, TransportOutcome::Completed { stop_reason, .. } if stop_reason == stop),
|
||||
"{reason}: got {outcome:?}"
|
||||
),
|
||||
(None, Some(kind)) => assert_eq!(failure_of(&outcome).0, kind, "{reason}"),
|
||||
(Some(stop), None) => {
|
||||
assert!(
|
||||
matches!(outcome, TransportOutcome::Completed { stop_reason, .. } if stop_reason == stop),
|
||||
"{reason}: got {outcome:?}"
|
||||
);
|
||||
assert!(
|
||||
events.iter().any(|e| matches!(
|
||||
&e.payload,
|
||||
TransportEventPayload::TextDelta { text } if text == "text"
|
||||
)),
|
||||
"{reason}: missing TextDelta in {events:?}"
|
||||
);
|
||||
}
|
||||
(None, Some(kind)) => {
|
||||
let (got_kind, msg, _) = failure_of(&outcome);
|
||||
assert_eq!(got_kind, kind, "{reason}");
|
||||
if reason == "aborted" {
|
||||
assert!(msg.contains("aborted"), "{msg}");
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -767,6 +802,33 @@ fn every_finish_reason_maps_and_required_without_tool_fails() {
|
|||
req_tool.tool_choice = ToolChoice::Required;
|
||||
let (_, req_outcome) = client.run_model(&req_tool, &row);
|
||||
assert_eq!(failure_of(&req_outcome).0, FailureKind::Provider);
|
||||
|
||||
let mut auto_tool = base_request(&row.upstream);
|
||||
auto_tool.tools = vec![weather_tool()];
|
||||
auto_tool.tool_choice = ToolChoice::Auto;
|
||||
let (auto_events, auto_outcome) = client.run_model(&auto_tool, &row);
|
||||
assert!(matches!(
|
||||
auto_outcome,
|
||||
TransportOutcome::Completed {
|
||||
stop_reason: StopReason::EndTurn,
|
||||
..
|
||||
}
|
||||
));
|
||||
assert_eq!(auto_events.len(), 1);
|
||||
assert!(matches!(
|
||||
&auto_events[0].payload,
|
||||
TransportEventPayload::TextDelta { text } if text == "plain reply"
|
||||
));
|
||||
|
||||
let (empty_events, empty_outcome) = client.run_model(&base_request(&row.upstream), &row);
|
||||
assert!(matches!(
|
||||
empty_outcome,
|
||||
TransportOutcome::Completed {
|
||||
stop_reason: StopReason::EndTurn,
|
||||
..
|
||||
}
|
||||
));
|
||||
assert!(empty_events.is_empty(), "empty content must emit no events");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -796,7 +858,17 @@ fn transport_auth_redirect_proxy_canary_and_http_errors() {
|
|||
),
|
||||
(
|
||||
429,
|
||||
json!({"error": {"type": "insufficient_quota", "code": "insufficient_quota", "message": "You exceeded your current quota"}}),
|
||||
json!({"error": {"type": "insufficient_quota", "message": "Quota reached"}}),
|
||||
FailureKind::Authentication,
|
||||
),
|
||||
(
|
||||
429,
|
||||
json!({"error": {"code": "insufficient_quota", "message": "Quota reached"}}),
|
||||
FailureKind::Authentication,
|
||||
),
|
||||
(
|
||||
429,
|
||||
json!({"error": {"type": "rate_limit_error", "message": "You exceeded your current quota"}}),
|
||||
FailureKind::Authentication,
|
||||
),
|
||||
(
|
||||
|
|
|
|||
|
|
@ -720,6 +720,41 @@ mod tests {
|
|||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn from_backends_rejects_untrimmed_cli_provider_id() {
|
||||
let cli = ClaudeCodeBackend::new(
|
||||
crate::config::ClaudeCodeConfig {
|
||||
provider_id: " cli-space".to_string(),
|
||||
claude_binary: std::path::PathBuf::from("/usr/bin/false"),
|
||||
claude_binary_sha256: [0xaa; 32],
|
||||
work_dir: std::path::PathBuf::from("/tmp"),
|
||||
config_dir: std::path::PathBuf::from("/tmp"),
|
||||
prompt_dir: std::path::PathBuf::from("/tmp"),
|
||||
token_credential: "tok".to_string(),
|
||||
handle_secret_credential: "sec".to_string(),
|
||||
instance: "inst".to_string(),
|
||||
meter_model: None,
|
||||
limits: crate::config::ClaudeCodeLimits {
|
||||
deadline: Duration::from_secs(5),
|
||||
max_line_bytes: 1024,
|
||||
max_total_bytes: 4096,
|
||||
stderr_tail_bytes: 256,
|
||||
},
|
||||
},
|
||||
Box::new(NoSink),
|
||||
);
|
||||
assert!(matches!(
|
||||
RouterBackend::from_backends(
|
||||
[],
|
||||
[],
|
||||
Some(Arc::new(cli)),
|
||||
vec![row("m1", "cli-space", "u1")]
|
||||
),
|
||||
Err(ConfigError::Invalid("providers"))
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
struct NoSink;
|
||||
#[cfg(unix)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue