Merge remote-tracking branch 'origin/pr/498'

This commit is contained in:
fawney19
2026-05-21 22:56:43 +08:00
89 changed files with 18396 additions and 382 deletions

View File

@@ -323,6 +323,10 @@ fn key_auth_channel_matches(row: &StoredMinimalCandidateSelectionRow, api_format
"openai:chat" | "openai:responses" | "claude:messages" | "openai:image"
)
}
"windsurf" => {
matches!(auth_type.as_str(), "oauth" | "api_key" | "bearer")
&& api_format == "openai:chat"
}
"vertex_ai" => {
(auth_type == "api_key"
&& matches!(
@@ -557,6 +561,34 @@ mod tests {
);
}
#[tokio::test]
async fn allows_windsurf_managed_keys_for_openai_chat_only() {
let mut oauth = sample_row("windsurf-oauth", "openai:chat", "gpt-5", 10);
oauth.provider_type = "windsurf".to_string();
oauth.key_auth_type = "oauth".to_string();
let mut api_key = sample_row("windsurf-api-key", "openai:chat", "gpt-5", 20);
api_key.provider_type = "windsurf".to_string();
api_key.key_auth_type = "api_key".to_string();
let mut responses = sample_row("windsurf-responses", "openai:responses", "gpt-5", 30);
responses.provider_type = "windsurf".to_string();
responses.key_auth_type = "oauth".to_string();
let repository =
InMemoryMinimalCandidateSelectionReadRepository::seed(vec![oauth, api_key, responses]);
let rows = repository
.list_for_exact_api_format_and_requested_model("openai:chat", "gpt-5")
.await
.expect("list should succeed");
assert_eq!(
rows.iter()
.map(|row| row.provider_id.as_str())
.collect::<Vec<_>>(),
vec!["windsurf-oauth", "windsurf-api-key"]
);
}
#[tokio::test]
async fn filters_by_exact_api_format_only() {
let repository = InMemoryMinimalCandidateSelectionReadRepository::seed(vec![

View File

@@ -452,6 +452,10 @@ fn key_auth_channel_matches(row: &CandidateSelectionRow, api_format: &str) -> bo
"openai:chat" | "openai:responses" | "claude:messages" | "openai:image"
)
}
"windsurf" => {
matches!(auth_type.as_str(), "oauth" | "api_key" | "bearer")
&& api_format == "openai:chat"
}
"vertex_ai" => {
(auth_type == "api_key"
&& matches!(

View File

@@ -113,6 +113,11 @@ WHERE p.is_active = TRUE
AND LOWER(BTRIM(pak.auth_type)) = 'oauth'
AND LOWER($3) = 'gemini:generate_content'
)
OR (
LOWER(BTRIM(p.provider_type)) = 'windsurf'
AND LOWER(BTRIM(pak.auth_type)) IN ('oauth', 'api_key', 'bearer')
AND LOWER($3) = 'openai:chat'
)
OR (
LOWER(BTRIM(p.provider_type)) = 'vertex_ai'
AND (
@@ -135,7 +140,8 @@ WHERE p.is_active = TRUE
'grok',
'vertex_ai',
'antigravity',
'kiro'
'kiro',
'windsurf'
)
AND LOWER(BTRIM(pak.auth_type)) <> 'oauth'
)
@@ -302,6 +308,11 @@ WHERE p.is_active = TRUE
AND LOWER(BTRIM(pak.auth_type)) = 'oauth'
AND LOWER($4) = 'gemini:generate_content'
)
OR (
LOWER(BTRIM(p.provider_type)) = 'windsurf'
AND LOWER(BTRIM(pak.auth_type)) IN ('oauth', 'api_key', 'bearer')
AND LOWER($4) = 'openai:chat'
)
OR (
LOWER(BTRIM(p.provider_type)) = 'vertex_ai'
AND (
@@ -324,7 +335,8 @@ WHERE p.is_active = TRUE
'grok',
'vertex_ai',
'antigravity',
'kiro'
'kiro',
'windsurf'
)
AND LOWER(BTRIM(pak.auth_type)) <> 'oauth'
)
@@ -490,6 +502,11 @@ WHERE p.is_active = TRUE
AND LOWER(BTRIM(pak.auth_type)) = 'oauth'
AND LOWER($6) = 'gemini:generate_content'
)
OR (
LOWER(BTRIM(p.provider_type)) = 'windsurf'
AND LOWER(BTRIM(pak.auth_type)) IN ('oauth', 'api_key', 'bearer')
AND LOWER($6) = 'openai:chat'
)
OR (
LOWER(BTRIM(p.provider_type)) = 'vertex_ai'
AND (
@@ -512,7 +529,8 @@ WHERE p.is_active = TRUE
'grok',
'vertex_ai',
'antigravity',
'kiro'
'kiro',
'windsurf'
)
AND LOWER(BTRIM(pak.auth_type)) <> 'oauth'
)
@@ -1322,6 +1340,26 @@ mod tests {
}
}
#[test]
fn candidate_selection_sql_allows_windsurf_openai_chat_managed_keys() {
let requested_model_sql = requested_model_selection_sql();
for sql in [
LIST_FOR_EXACT_API_FORMAT_SQL,
LIST_FOR_EXACT_API_FORMAT_AND_GLOBAL_MODEL_SQL,
LIST_POOL_KEYS_FOR_GROUP_SQL,
requested_model_sql.as_str(),
] {
assert!(sql.contains("LOWER(BTRIM(p.provider_type)) = 'windsurf'"));
assert!(
sql.contains("LOWER($3) = 'openai:chat'")
|| sql.contains("LOWER($4) = 'openai:chat'")
|| sql.contains("LOWER($6) = 'openai:chat'")
);
assert!(sql.contains("LOWER(BTRIM(pak.auth_type)) IN ('oauth', 'api_key', 'bearer')"));
assert!(sql.contains("'windsurf'"));
}
}
#[test]
fn candidate_selection_sql_allows_vertex_embedding_auth() {
let requested_model_sql = requested_model_selection_sql();

View File

@@ -831,6 +831,10 @@ fn key_auth_channel_matches(row: &CandidateSelectionRow, api_format: &str) -> bo
"openai:chat" | "openai:responses" | "claude:messages" | "openai:image"
)
}
"windsurf" => {
matches!(auth_type.as_str(), "oauth" | "api_key" | "bearer")
&& api_format == "openai:chat"
}
"vertex_ai" => {
(auth_type == "api_key"
&& matches!(