refactor: separate request auth channel from route kind

Extract request_auth_channel as a distinct routing dimension to distinguish
between api_key and bearer_like authentication methods. This improves routing
clarity by decoupling authentication mechanism from route classification.
This commit is contained in:
fawney19
2026-05-02 21:23:33 +08:00
parent 47ee8b9c13
commit 3a770306cc
16 changed files with 337 additions and 58 deletions

View File

@@ -269,7 +269,8 @@ async fn gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_cand
"action": "proxy_public",
"route_class": "ai_public",
"route_family": "claude",
"route_kind": "cli",
"route_kind": "messages",
"request_auth_channel": "bearer_like",
"auth_endpoint_signature": "claude:messages",
"execution_runtime_candidate": true,
"auth_context": {

View File

@@ -288,7 +288,8 @@ async fn gateway_executes_kiro_claude_cli_sync_via_local_provider_catalog_candid
"action": "proxy_public",
"route_class": "ai_public",
"route_family": "claude",
"route_kind": "cli",
"route_kind": "messages",
"request_auth_channel": "bearer_like",
"auth_endpoint_signature": "claude:messages",
"execution_runtime_candidate": true,
"auth_context": {
@@ -872,7 +873,8 @@ async fn gateway_executes_kiro_claude_cli_sync_via_local_provider_catalog_candid
"action": "proxy_public",
"route_class": "ai_public",
"route_family": "claude",
"route_kind": "cli",
"route_kind": "messages",
"request_auth_channel": "bearer_like",
"auth_endpoint_signature": "claude:messages",
"execution_runtime_candidate": true,
"auth_context": {

View File

@@ -27,6 +27,7 @@ fn sample_decision() -> crate::control::GatewayControlDecision {
route_class: Some("ai_public".to_string()),
route_family: Some("openai".to_string()),
route_kind: Some("chat".to_string()),
request_auth_channel: None,
auth_endpoint_signature: None,
execution_runtime_candidate: true,
auth_context: None,

View File

@@ -50,6 +50,28 @@ async fn gateway_handles_internal_gateway_resolve_without_proxying_upstream() {
assert_eq!(payload["route_kind"], "chat");
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
let response = reqwest::Client::new()
.post(format!("{gateway_url}/api/internal/gateway/resolve"))
.json(&json!({
"method": "POST",
"path": "/v1/messages",
"headers": {
"authorization": "Bearer local-token",
},
}))
.send()
.await
.expect("request should succeed");
assert_eq!(response.status(), StatusCode::OK);
let payload: serde_json::Value = response.json().await.expect("json body should parse");
assert_eq!(payload["route_class"], "ai_public");
assert_eq!(payload["route_family"], "claude");
assert_eq!(payload["route_kind"], "messages");
assert_eq!(payload["request_auth_channel"], "bearer_like");
assert_eq!(payload["auth_endpoint_signature"], "claude:messages");
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
gateway_handle.abort();
upstream_handle.abort();
}

View File

@@ -1645,7 +1645,7 @@ async fn gateway_records_failed_usage_when_all_local_claude_cli_candidates_are_s
assert_eq!(stored_usage.routing_key_name(), None);
assert_eq!(stored_usage.routing_planner_kind(), Some("claude_cli_sync"));
assert_eq!(stored_usage.routing_route_family(), Some("claude"));
assert_eq!(stored_usage.routing_route_kind(), Some("cli"));
assert_eq!(stored_usage.routing_route_kind(), Some("messages"));
assert_eq!(
stored_usage.routing_execution_path(),
Some("local_execution_runtime_miss")