refactor(rules): 规则引擎容错优化,无效规则条目跳过而非中止整个规则集

- header/body rules 的 _are_locally_supported 简化为仅检查是否为数组
- apply 逻辑中遇到格式错误/不支持的规则条目改为 continue 跳过,而非 return false
- 允许非字符串 header value,自动序列化为 JSON 字符串
- 宽松处理无效 regex flag,不再拒绝整条规则

fix(gateway): Claude CLI 路由仅检查 bearer 头,不排斥同时携带 x-api-key 的请求

feat(observability): 监控链路候选展示解密 auth_config 的账号标签和 OAuth 计划类型
This commit is contained in:
fawney19
2026-04-25 19:46:52 +08:00
parent 00744c0ce5
commit 912a92cd1a
7 changed files with 438 additions and 184 deletions

View File

@@ -236,6 +236,21 @@ mod tests {
}
}
fn codex_default_body_rules() -> Value {
json!([
{"action":"drop","path":"max_output_tokens"},
{"action":"drop","path":"temperature"},
{"action":"drop","path":"top_p"},
{"action":"set","path":"store","value":false},
{
"action":"set",
"path":"instructions",
"value":"You are GPT-5.",
"condition":{"path":"instructions","op":"not_exists"}
}
])
}
#[test]
fn builds_request_body_for_all_standard_surface_pairs_in_sync_and_stream_modes() {
for client_api_format in STANDARD_SURFACES {
@@ -269,6 +284,45 @@ mod tests {
}
}
#[test]
fn applies_codex_body_rules_for_all_standard_sources_to_openai_cli() {
let body_rules = codex_default_body_rules();
for client_api_format in STANDARD_SURFACES {
let (mut request, request_path) = sample_request_for(client_api_format);
if let Some(object) = request.as_object_mut() {
object.insert("temperature".to_string(), json!(0.7));
object.insert("top_p".to_string(), json!(0.8));
}
let converted = build_standard_request_body(
&request,
client_api_format,
"gpt-5.5",
"codex",
"openai:cli",
request_path,
true,
Some(&body_rules),
Some("key-1"),
)
.unwrap_or_else(|| {
panic!("{client_api_format} -> openai:cli should build with codex body rules")
});
assert_eq!(converted["model"], "gpt-5.5");
assert_eq!(converted["stream"], true);
assert_eq!(converted["store"], false);
assert!(converted.get("max_output_tokens").is_none());
assert!(converted.get("temperature").is_none());
assert!(converted.get("top_p").is_none());
assert!(
converted.get("instructions").is_some(),
"{client_api_format} -> openai:cli should keep or inject instructions"
);
}
}
#[test]
fn builds_openai_chat_request_from_claude_chat_source() {
let request = json!({