Simplify diagnostic report ownership

This commit is contained in:
2026-11-05 14:21:33 +00:00
parent f745b14b71
commit 68668cee56
6 changed files with 36 additions and 176 deletions

View File

@@ -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