Simplify diagnostic report ownership
This commit is contained in:
@@ -154,105 +154,6 @@ func CloneBackendSmokeTestConfig(config *BackendSmokeTestConfig) *BackendSmokeTe
|
||||
return &cloned
|
||||
}
|
||||
|
||||
// CloneSmokeTestRequest returns a copy that owns its optional settings.
|
||||
func CloneSmokeTestRequest(request SmokeTestRequest) (SmokeTestRequest, error) {
|
||||
cloned := request
|
||||
cloned.TransientRetries = cloneInt(request.TransientRetries)
|
||||
if request.Execution == nil {
|
||||
return cloned, nil
|
||||
}
|
||||
execution := *request.Execution
|
||||
execution.Temperature = cloneFloat64(request.Execution.Temperature)
|
||||
execution.MaxTokens = cloneInt(request.Execution.MaxTokens)
|
||||
execution.TopP = cloneFloat64(request.Execution.TopP)
|
||||
execution.TimeoutSeconds = cloneInt(request.Execution.TimeoutSeconds)
|
||||
execution.ReasoningEffort = cloneString(request.Execution.ReasoningEffort)
|
||||
var err error
|
||||
execution.ExtraParams, err = jsonvalue.CopyMap(request.Execution.ExtraParams)
|
||||
if err != nil {
|
||||
return SmokeTestRequest{}, err
|
||||
}
|
||||
cloned.Execution = &execution
|
||||
return cloned, nil
|
||||
}
|
||||
|
||||
// CloneSmokeTestReport returns a copy with independent optional facts and maps.
|
||||
func CloneSmokeTestReport(report SmokeTestReport) (SmokeTestReport, error) {
|
||||
cloned := report
|
||||
cloned.Applicable = cloneBool(report.Applicable)
|
||||
cloned.Facts = cloneSmokeTestFacts(report.Facts)
|
||||
cloned.Timing = cloneSmokeTestTiming(report.Timing)
|
||||
var err error
|
||||
cloned.Target.EffectiveSettings.ExtraParams, err = jsonvalue.CopyMap(report.Target.EffectiveSettings.ExtraParams)
|
||||
if err != nil {
|
||||
return SmokeTestReport{}, err
|
||||
}
|
||||
if report.Attempts != nil {
|
||||
cloned.Attempts = make([]SmokeTestAttempt, len(report.Attempts))
|
||||
for index, attempt := range report.Attempts {
|
||||
cloned.Attempts[index] = attempt
|
||||
cloned.Attempts[index].HTTPStatus = cloneInt(attempt.HTTPStatus)
|
||||
cloned.Attempts[index].Facts = cloneSmokeTestFacts(attempt.Facts)
|
||||
cloned.Attempts[index].Timing = cloneSmokeTestTiming(attempt.Timing)
|
||||
}
|
||||
}
|
||||
return cloned, nil
|
||||
}
|
||||
|
||||
func cloneSmokeTestFacts(facts SmokeTestFacts) SmokeTestFacts {
|
||||
facts.CredentialsSupplied = cloneBool(facts.CredentialsSupplied)
|
||||
facts.EndpointReachable = cloneBool(facts.EndpointReachable)
|
||||
facts.CredentialsAccepted = cloneBool(facts.CredentialsAccepted)
|
||||
facts.ResponseReceived = cloneBool(facts.ResponseReceived)
|
||||
facts.GenerationCompleted = cloneBool(facts.GenerationCompleted)
|
||||
facts.TextReturned = cloneBool(facts.TextReturned)
|
||||
facts.ExpectedTextMatched = cloneBool(facts.ExpectedTextMatched)
|
||||
facts.StructuredOutputRequested = cloneBool(facts.StructuredOutputRequested)
|
||||
facts.ValidJSON = cloneBool(facts.ValidJSON)
|
||||
facts.SchemaMatched = cloneBool(facts.SchemaMatched)
|
||||
return facts
|
||||
}
|
||||
|
||||
func cloneSmokeTestTiming(timing SmokeTestTiming) SmokeTestTiming {
|
||||
timing.CapacityWait = cloneDuration(timing.CapacityWait)
|
||||
timing.RequestDuration = cloneDuration(timing.RequestDuration)
|
||||
timing.RetryDelay = cloneDuration(timing.RetryDelay)
|
||||
timing.EvaluationDuration = cloneDuration(timing.EvaluationDuration)
|
||||
return timing
|
||||
}
|
||||
|
||||
func cloneBool(value *bool) *bool {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := *value
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneDuration(value *time.Duration) *time.Duration {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := *value
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneFloat64(value *float64) *float64 {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := *value
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneInt(value *int) *int {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := *value
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneString(value *string) *string {
|
||||
if value == nil {
|
||||
return nil
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
func TestCloneBackendCopiesDiagnosticMetadataAndProviderValues(t *testing.T) {
|
||||
profile := "profile"
|
||||
@@ -40,73 +37,3 @@ func TestCloneBackendCopiesDiagnosticMetadataAndProviderValues(t *testing.T) {
|
||||
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