fix(compact): 移除 OpenAI Compact 请求中不受支持的 store 参数

- 在 OpenAI Compact 请求规范化流程中剥离 `store`
- 将 compact 默认 body rules 与 Codex CLI 默认规则拆分
- 补充 same-format 和转换链路的 compact 回归测试
This commit is contained in:
AAEE86
2026-04-12 01:52:25 +08:00
parent 335e440cc5
commit def8135118
10 changed files with 97 additions and 18 deletions
@@ -26,7 +26,7 @@ fn applies_codex_defaults_when_body_rules_do_not_handle_fields() {
}
#[test]
fn defers_to_user_body_rules_for_handled_fields() {
fn strips_store_for_compact_even_when_body_rules_handle_it() {
let body_rules = json!([
{"action":"set","path":"store","value":true},
{"action":"set","path":"instructions","value":"Keep custom"},
@@ -51,7 +51,7 @@ fn defers_to_user_body_rules_for_handled_fields() {
);
assert!(body.get("max_output_tokens").is_none());
assert_eq!(body["store"], true);
assert!(body.get("store").is_none());
assert_eq!(body["instructions"], "Keep custom");
assert_eq!(body["metadata"]["mode"], "custom");
assert_eq!(body["top_p"], 0.5);
@@ -267,4 +267,32 @@ mod tests {
assert_eq!(converted["store"], false);
assert_eq!(converted["instructions"], "You are GPT-5.");
}
#[test]
fn strips_store_for_openai_compact_requests() {
let request = json!({
"model": "gpt-5",
"messages": [{
"role": "user",
"content": "Hello from OpenAI Chat"
}],
"store": true
});
let converted = build_standard_request_body(
&request,
"openai:chat",
"gpt-5",
"openai",
"openai:compact",
"/v1/chat/completions",
false,
None,
None,
)
.expect("openai chat should convert to openai compact");
assert_eq!(converted["model"], "gpt-5");
assert!(converted.get("store").is_none());
}
}
@@ -1,6 +1,5 @@
use serde_json::Value;
use super::super::codex::apply_codex_openai_cli_special_body_edits;
use crate::ai_pipeline::conversion::{request_conversion_kind, RequestConversionKind};
use crate::ai_pipeline::transport::apply_local_body_rules;
use crate::ai_pipeline::transport::url::{
@@ -8,6 +7,7 @@ use crate::ai_pipeline::transport::url::{
build_openai_cli_url, build_passthrough_path_url,
};
use crate::ai_pipeline::{
apply_codex_openai_cli_special_body_edits, apply_openai_compact_special_body_edits,
build_cross_format_openai_chat_request_body as pipeline_build_cross_format_openai_chat_request_body,
build_local_openai_chat_request_body as pipeline_build_local_openai_chat_request_body,
GatewayProviderTransportSnapshot,
@@ -74,6 +74,7 @@ pub(crate) fn build_cross_format_openai_chat_request_body(
body_rules,
user_api_key_id,
);
apply_openai_compact_special_body_edits(&mut provider_request_body, provider_api_format);
Some(provider_request_body)
}
@@ -3,7 +3,6 @@ use std::collections::BTreeMap;
use serde_json::Value;
use url::form_urlencoded;
use super::super::codex::apply_codex_openai_cli_special_body_edits;
use crate::ai_pipeline::conversion::{request_conversion_kind, RequestConversionKind};
use crate::ai_pipeline::transport::antigravity::{
build_antigravity_v1internal_url, AntigravityRequestUrlAction,
@@ -14,6 +13,7 @@ use crate::ai_pipeline::transport::url::{
build_openai_cli_url, build_passthrough_path_url,
};
use crate::ai_pipeline::{
apply_codex_openai_cli_special_body_edits, apply_openai_compact_special_body_edits,
build_cross_format_openai_cli_request_body as pipeline_build_cross_format_openai_cli_request_body,
build_local_openai_cli_request_body as pipeline_build_local_openai_cli_request_body,
GatewayProviderTransportSnapshot,
@@ -40,6 +40,7 @@ pub(crate) fn build_local_openai_cli_request_body(
body_rules,
user_api_key_id,
);
apply_openai_compact_special_body_edits(&mut provider_request_body, provider_api_format);
Some(provider_request_body)
}
@@ -70,6 +71,7 @@ pub(crate) fn build_cross_format_openai_cli_request_body(
body_rules,
user_api_key_id,
);
apply_openai_compact_special_body_edits(&mut provider_request_body, provider_api_format);
Some(provider_request_body)
}
@@ -81,6 +81,28 @@ fn local_openai_cli_wrapper_preserves_body_order_after_edits() {
);
}
#[test]
fn local_openai_compact_wrapper_strips_store_for_same_format_requests() {
let body_json = json!({
"model": "gpt-5.4",
"input": [],
"store": true
});
let provider_request_body = build_local_openai_cli_request_body(
&body_json,
"gpt-5.4",
false,
"openai",
"openai:compact",
None,
None,
)
.expect("local openai compact body should build");
assert!(provider_request_body.get("store").is_none());
}
#[test]
fn strips_metadata_for_codex_openai_cli_requests() {
let body_json = json!({