Add smoke diagnostic domain values
This commit is contained in:
110
internal/domain/smoke_diagnostics_test.go
Normal file
110
internal/domain/smoke_diagnostics_test.go
Normal file
@@ -0,0 +1,110 @@
|
||||
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
|
||||
report := SmokeTestReport{
|
||||
Applicable: &applicable,
|
||||
Target: SmokeTestTarget{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.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] = "changed"
|
||||
|
||||
if !applicable || !reachable || status != 200 || wait != 3*time.Millisecond {
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user