Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162package config
import ( "encoding/json" "testing")
func TestSettingsValidatePreservesBedrockAPI(t *testing.T) { for _, api := range []string{"", "messages", "converse"} { t.Run(api, func(t *testing.T) { settings := Settings{Extension: "bedrock", API: api, Model: " amazon.nova-pro-v1:0 ", Protocol: "chat_completions", AccountIDs: []string{"first", "second"}} validated, err := settings.Validate() if err != nil { t.Fatal(err) } if len(validated.AccountIDs) != 2 || validated.AccountIDs[0] != "first" || validated.AccountIDs[1] != "second" || validated.AccountID != nil || validated.API != api || validated.Extension != "bedrock" || validated.Model != "amazon.nova-pro-v1:0" || validated.Protocol != "chat_completions" { t.Fatalf("validation changed provider API or replay protocol: %+v", validated) } data, err := json.Marshal(validated) if err != nil { t.Fatal(err) } var fields map[string]any if err := json.Unmarshal(data, &fields); err != nil { t.Fatal(err) } if api == "" { if _, present := fields["api"]; present { t.Fatalf("default API must stay omitted: %s", data) } } else if fields["api"] != api { t.Fatalf("API lost from JSON: %s", data) } var decoded Settings if err := json.Unmarshal(data, &decoded); err != nil { t.Fatal(err) } if decoded.API != api || len(decoded.AccountIDs) != 2 || decoded.AccountIDs[0] != "first" || decoded.AccountIDs[1] != "second" { t.Fatalf("JSON changed API: %+v", decoded) } }) }}
func TestSettingsValidateRejectsUnknownBedrockAPI(t *testing.T) { for _, api := range []string{"converse_stream", "Converse", " converse", "converse ", "responses", "invoke_model", "messages\n"} { t.Run(api, func(t *testing.T) { _, err := (Settings{Extension: "bedrock", API: api, Model: "fixture", Protocol: "chat_completions"}).Validate() if err == nil { t.Fatalf("accepted unknown Bedrock API %q", api) } }) }}
func TestSettingsValidatePreservesOtherExtensionAPI(t *testing.T) { got, err := (Settings{Extension: "fixture-extension", API: "extension-owned", Model: "fixture", Protocol: "responses"}).Validate() if err != nil || got.API != "extension-owned" { t.Fatalf("lost unrelated extension API: %+v, %v", got, err) }}