Add protocol selection to Claude and Codex provider forms referencing CCSwitch
This commit is contained in:
1 parent
bae24cc439
commit
16957decb2
14 files changed
+274
-25
No files matched your search
@@ -337,3 +337,48 @@ func TestSetGatewayValidation(t *testing.T) {
|
||||
t.Error("unknown language accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderProtocol(t *testing.T) {
|
||||
t.Setenv("CROSSRELAY_HOME", t.TempDir())
|
||||
store, err := Load()
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
|
||||
// 1. Default protocol when omitted should be openai_chat.
|
||||
p1, err := store.AddProvider("Claude-Default", "", "https://api.example.com/v1", "sk-1", Models{}, TargetClaude)
|
||||
if err != nil {
|
||||
t.Fatalf("AddProvider: %v", err)
|
||||
}
|
||||
if p1.Protocol != ProtocolOpenAIChat || p1.APIFormat != ProtocolOpenAIChat {
|
||||
t.Errorf("expected default protocol %q, got protocol=%q, api_format=%q", ProtocolOpenAIChat, p1.Protocol, p1.APIFormat)
|
||||
}
|
||||
|
||||
// 2. Explicit protocol should be saved.
|
||||
p2, err := store.AddProvider("Claude-Anthropic", "", "https://api.anthropic.com/v1", "sk-2", Models{}, TargetClaude, ProtocolAnthropic)
|
||||
if err != nil {
|
||||
t.Fatalf("AddProvider with protocol: %v", err)
|
||||
}
|
||||
if p2.Protocol != ProtocolAnthropic {
|
||||
t.Errorf("expected protocol %q, got %q", ProtocolAnthropic, p2.Protocol)
|
||||
}
|
||||
|
||||
// 3. Update protocol.
|
||||
updated, err := store.UpdateProvider(p2.ID, "Claude-Anthropic-Updated", "", "https://api.anthropic.com/v1", "sk-2", Models{}, TargetClaude, ProtocolOpenAIResponses)
|
||||
if err != nil {
|
||||
t.Fatalf("UpdateProvider with protocol: %v", err)
|
||||
}
|
||||
if updated.Protocol != ProtocolOpenAIResponses {
|
||||
t.Errorf("expected updated protocol %q, got %q", ProtocolOpenAIResponses, updated.Protocol)
|
||||
}
|
||||
|
||||
// 4. Persistence round-trip.
|
||||
reloaded, err := Load()
|
||||
if err != nil {
|
||||
t.Fatalf("Load reloaded: %v", err)
|
||||
}
|
||||
found := reloaded.FindProvider(p2.ID)
|
||||
if found == nil || found.Protocol != ProtocolOpenAIResponses {
|
||||
t.Errorf("expected persisted protocol %q, got %+v", ProtocolOpenAIResponses, found)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user