116 lines
3.7 KiB
Go
116 lines
3.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCloneBackendCopiesDiagnosticMetadataAndProviderValues(t *testing.T) {
|
|
profile := "profile"
|
|
reachabilityEndpoint := "https://probe.example/health"
|
|
authKind := "openrouter_key"
|
|
authEndpoint := "https://probe.example/key"
|
|
backend := Backend{
|
|
ExtraParams: map[string]any{"nested": map[string]any{"value": "original"}},
|
|
SmokeTests: &BackendSmokeTestConfig{
|
|
DefaultProfile: &profile,
|
|
Reachability: &ReachabilityProbeConfig{Endpoint: &reachabilityEndpoint},
|
|
Authentication: &AuthenticationProbeConfig{
|
|
Kind: &authKind,
|
|
Endpoint: &authEndpoint,
|
|
},
|
|
},
|
|
}
|
|
|
|
cloned, err := CloneBackend(backend)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
*cloned.SmokeTests.DefaultProfile = "changed"
|
|
*cloned.SmokeTests.Reachability.Endpoint = "changed"
|
|
*cloned.SmokeTests.Authentication.Kind = "changed"
|
|
*cloned.SmokeTests.Authentication.Endpoint = "changed"
|
|
cloned.ExtraParams["nested"].(map[string]any)["value"] = "changed"
|
|
|
|
if profile != "profile" || reachabilityEndpoint != "https://probe.example/health" ||
|
|
authKind != "openrouter_key" || authEndpoint != "https://probe.example/key" {
|
|
t.Fatal("cloned diagnostic metadata shared source pointers")
|
|
}
|
|
if got := backend.ExtraParams["nested"].(map[string]any)["value"]; got != "original" {
|
|
t.Fatalf("source provider parameter changed through clone: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestCloneSmokeTestRequestOwnsOptionalSettings(t *testing.T) {
|
|
temperature := 0.25
|
|
retries := 2
|
|
reasoning := "low"
|
|
request := SmokeTestRequest{
|
|
APIKey: "secret",
|
|
TransientRetries: &retries,
|
|
Execution: &ExecutionTargetOverride{
|
|
Temperature: &temperature,
|
|
ReasoningEffort: &reasoning,
|
|
ExtraParams: map[string]any{"nested": map[string]any{"value": "original"}},
|
|
},
|
|
}
|
|
|
|
cloned, err := CloneSmokeTestRequest(request)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
*cloned.TransientRetries = 3
|
|
*cloned.Execution.Temperature = 0.5
|
|
*cloned.Execution.ReasoningEffort = "high"
|
|
cloned.Execution.ExtraParams["nested"].(map[string]any)["value"] = "changed"
|
|
|
|
if retries != 2 || temperature != 0.25 || reasoning != "low" {
|
|
t.Fatal("cloned request shared optional scalar pointers")
|
|
}
|
|
if got := request.Execution.ExtraParams["nested"].(map[string]any)["value"]; got != "original" {
|
|
t.Fatalf("source provider parameter changed through clone: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestCloneSmokeTestReportOwnsMutableValues(t *testing.T) {
|
|
applicable := true
|
|
reachable := true
|
|
status := 200
|
|
wait := 3 * time.Millisecond
|
|
promptVersion := "v1"
|
|
report := SmokeTestReport{
|
|
Applicable: &applicable,
|
|
Target: SmokeTestTarget{
|
|
PromptVersion: &promptVersion,
|
|
EffectiveSettings: ExecutionTarget{
|
|
ExtraParams: map[string]any{"nested": map[string]any{"value": "original"}},
|
|
},
|
|
},
|
|
Facts: SmokeTestFacts{EndpointReachable: &reachable},
|
|
Attempts: []SmokeTestAttempt{{
|
|
HTTPStatus: &status,
|
|
Facts: SmokeTestFacts{EndpointReachable: &reachable},
|
|
Timing: SmokeTestTiming{CapacityWait: &wait},
|
|
}},
|
|
}
|
|
|
|
cloned, err := CloneSmokeTestReport(report)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
*cloned.Applicable = false
|
|
*cloned.Facts.EndpointReachable = false
|
|
*cloned.Attempts[0].HTTPStatus = 503
|
|
*cloned.Attempts[0].Facts.EndpointReachable = false
|
|
*cloned.Attempts[0].Timing.CapacityWait = time.Second
|
|
*cloned.Target.PromptVersion = "changed"
|
|
cloned.Target.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] = "changed"
|
|
|
|
if !applicable || !reachable || status != 200 || wait != 3*time.Millisecond || promptVersion != "v1" {
|
|
t.Fatal("cloned report shared optional scalar pointers")
|
|
}
|
|
if got := report.Target.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"]; got != "original" {
|
|
t.Fatalf("source provider parameter changed through clone: %v", got)
|
|
}
|
|
}
|