mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-11 21:50:19 +08:00
Merge pull request #676 from MMEXA/codex/sync-capture-envelope-finalize-20260716
修复同步 finalize 的 Responses 流聚合与转换
This commit is contained in:
@@ -1790,6 +1790,93 @@ fn local_finalize_handles_openai_chat_cross_format_sync_response_from_openai_res
|
||||
assert_eq!(client_body["usage"]["total_tokens"], 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_finalize_aggregates_openai_responses_capture_envelope_before_chat_conversion() {
|
||||
let payload = GatewaySyncReportRequest {
|
||||
trace_id: "trace-openai-chat-capture-envelope-sync-123".to_string(),
|
||||
report_kind: "openai_chat_sync_finalize".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:chat",
|
||||
"provider_api_format": "openai:responses",
|
||||
"model": "gpt-5.6-luna",
|
||||
"mapped_model": "gpt-5.6-luna",
|
||||
"needs_conversion": true,
|
||||
"has_envelope": false,
|
||||
})),
|
||||
status_code: 200,
|
||||
headers: BTreeMap::from([("content-type".to_string(), "application/json".to_string())]),
|
||||
body_json: Some(json!({
|
||||
"chunks": [
|
||||
{
|
||||
"type": "response.output_text.delta",
|
||||
"response_id": "resp_capture_gateway_123",
|
||||
"output_index": 0,
|
||||
"content_index": 0,
|
||||
"delta": "Gateway "
|
||||
},
|
||||
{
|
||||
"type": "response.output_text.done",
|
||||
"response_id": "resp_capture_gateway_123",
|
||||
"output_index": 0,
|
||||
"content_index": 0,
|
||||
"text": "Gateway capture"
|
||||
},
|
||||
{
|
||||
"type": "response.completed",
|
||||
"response": {
|
||||
"id": "resp_capture_gateway_123",
|
||||
"object": "response",
|
||||
"status": "completed",
|
||||
"model": "gpt-5.6-luna",
|
||||
"output": [],
|
||||
"usage": {
|
||||
"input_tokens": 2,
|
||||
"output_tokens": 3,
|
||||
"total_tokens": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
})),
|
||||
client_body_json: None,
|
||||
body_base64: None,
|
||||
telemetry: None,
|
||||
};
|
||||
|
||||
let outcome = maybe_build_local_core_sync_finalize_response(
|
||||
"trace-openai-chat-capture-envelope-sync-123",
|
||||
&test_decision(),
|
||||
&payload,
|
||||
)
|
||||
.expect("capture envelope finalize should succeed")
|
||||
.expect("capture envelope finalize should match");
|
||||
|
||||
let report = outcome
|
||||
.background_report
|
||||
.expect("capture envelope conversion should produce a success report");
|
||||
assert_eq!(report.report_kind, "openai_chat_sync_success");
|
||||
let provider_body = report
|
||||
.body_json
|
||||
.expect("aggregated provider body should exist");
|
||||
assert_eq!(provider_body["id"], "resp_capture_gateway_123");
|
||||
assert_eq!(
|
||||
provider_body["output"][0]["content"][0]["text"],
|
||||
"Gateway capture"
|
||||
);
|
||||
assert!(provider_body.get("chunks").is_none());
|
||||
let client_body = report
|
||||
.client_body_json
|
||||
.expect("converted client body should exist");
|
||||
assert_eq!(
|
||||
client_body["choices"][0]["message"]["content"],
|
||||
"Gateway capture"
|
||||
);
|
||||
assert_eq!(client_body["usage"]["prompt_tokens"], 2);
|
||||
assert_eq!(client_body["usage"]["completion_tokens"], 3);
|
||||
assert_eq!(client_body["usage"]["total_tokens"], 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_finalize_handles_claude_chat_cross_format_sync_response_from_openai_chat() {
|
||||
let payload = GatewaySyncReportRequest {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user