Simplify smoke report ownership

This commit is contained in:
2026-11-05 20:12:40 +00:00
parent f5c900cb0a
commit 5dd1418953
5 changed files with 17 additions and 50 deletions

View File

@@ -383,6 +383,12 @@ results also remain detached from metadata retained by the handle.
## Stage 14: Simplify Smoke Target And Public Report Detachment
**Completed:** Smoke targets remain private through orchestration and public
reports use the trusted outward projection; endpoint sanitization and credential
redaction remain. Go 1.27.3 `go test ./internal/usecase . -run
'Smoke|Diagnostic'` passed, including report isolation, cancellation, and
diagnostic selection coverage.
**Finding:** 5. **Files:** `internal/usecase/smoke_tester.go`,
`smoke_diagnostics.go`, smoke conversion/ownership tests.

View File

@@ -8,7 +8,6 @@ import (
"go.maximumdirect.net/promptkit/internal/domain"
"go.maximumdirect.net/promptkit/internal/generation"
"go.maximumdirect.net/promptkit/internal/jsonvalue"
"go.maximumdirect.net/promptkit/internal/llm"
"go.maximumdirect.net/promptkit/internal/observation"
)
@@ -439,12 +438,8 @@ func httpExecutionFacts(evidence llm.HTTPExecutionEvidence) domain.SmokeTestFact
}
func smokeReportTarget(target domain.SmokeTestTarget) (domain.SmokeTestTarget, error) {
params, err := jsonvalue.CopyMap(target.EffectiveSettings.ExtraParams)
if err != nil {
return domain.SmokeTestTarget{}, fmt.Errorf("clone smoke-test target settings: %w", err)
}
target.EffectiveSettings.ExtraParams = params
target.EffectiveSettings.APIKey = ""
var err error
target.Endpoint, err = endpointWithoutUserInfo(target.Endpoint)
if err != nil {
return domain.SmokeTestTarget{}, fmt.Errorf("%w: invalid resolved diagnostic endpoint", ErrInvalidRequest)

View File

@@ -394,7 +394,7 @@ func (b cancelOnCloseSmokeBody) Close() error {
return b.ReadCloser.Close()
}
func TestSmokeReportTargetOwnsProviderValuesAndRedactsCredentials(t *testing.T) {
func TestSmokeReportTargetRedactsCredentialsAndSanitizesEndpoints(t *testing.T) {
target := domain.SmokeTestTarget{
Endpoint: "https://user:password@example.invalid/key",
EffectiveSettings: domain.ExecutionTarget{
@@ -407,13 +407,8 @@ func TestSmokeReportTargetOwnsProviderValuesAndRedactsCredentials(t *testing.T)
if err != nil {
t.Fatal(err)
}
got.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] = "changed"
if target.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] != "original" ||
if got.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] != "original" ||
got.EffectiveSettings.APIKey != "" || got.Endpoint != "https://example.invalid/key" || got.EffectiveSettings.Endpoint != "https://example.invalid/v1" {
t.Fatalf("report target not detached or redacted: %+v", got)
}
target.EffectiveSettings.ExtraParams = map[string]any{"invalid": func() {}}
if _, err := smokeReportTarget(target); err == nil {
t.Fatal("invalid provider values were accepted")
t.Fatalf("report target not redacted: %+v", got)
}
}

View File

@@ -29,14 +29,8 @@ func TestSmokeReportConversionOwnsMutableValues(t *testing.T) {
Timing: domain.SmokeTestTiming{RequestDuration: &duration},
}},
}
converted, err := fromDomainSmokeTestReport(source)
if err != nil {
t.Fatal(err)
}
other, err := fromDomainSmokeTestReport(source)
if err != nil {
t.Fatal(err)
}
converted := fromDomainSmokeTestReport(source)
other := fromDomainSmokeTestReport(source)
encoded, err := json.Marshal(converted)
if err != nil {
t.Fatal(err)
@@ -63,22 +57,8 @@ func TestSmokeReportConversionOwnsMutableValues(t *testing.T) {
if got := source.Target.EffectiveSettings.ExtraParams["nested"].([]any)[0].(map[string]any)["value"]; got != "original" {
t.Fatalf("converted report changed source provider parameters: %v", got)
}
later, err := fromDomainSmokeTestReport(source)
if err != nil {
t.Fatal(err)
}
later := fromDomainSmokeTestReport(source)
if !reflect.DeepEqual(other, later) {
t.Fatal("converted report mutation affected another result")
}
}
func TestSmokeReportConversionPreservesProviderMapCopyError(t *testing.T) {
report, err := fromDomainSmokeTestReport(domain.SmokeTestReport{
Target: domain.SmokeTestTarget{EffectiveSettings: domain.ExecutionTarget{
ExtraParams: map[string]any{"unsupported": func() {}},
}},
})
if err == nil || report != nil {
t.Fatalf("invalid provider data produced report=%+v, error=%v", report, err)
}
}

View File

@@ -6,7 +6,6 @@ import (
"time"
"go.maximumdirect.net/promptkit/internal/domain"
"go.maximumdirect.net/promptkit/internal/jsonvalue"
)
// SmokeTestKind identifies one built-in diagnostic operation.
@@ -272,11 +271,7 @@ func (e *Engine) SmokeTest(ctx context.Context, req SmokeTestRequest) (*SmokeTes
if domainReport == nil {
return nil, mapPublicError(err)
}
report, conversionErr := fromDomainSmokeTestReport(*domainReport)
if conversionErr != nil {
return nil, fmt.Errorf("%w: failed to copy smoke-test report", ErrInvalidRequest)
}
return report, mapPublicError(err)
return fromDomainSmokeTestReport(*domainReport), mapPublicError(err)
}
func toDomainSmokeTestRequest(request SmokeTestRequest) (domain.SmokeTestRequest, error) {
@@ -295,11 +290,7 @@ func toDomainSmokeTestRequest(request SmokeTestRequest) (domain.SmokeTestRequest
}, nil
}
func fromDomainSmokeTestReport(report domain.SmokeTestReport) (*SmokeTestReport, error) {
extraParams, err := jsonvalue.CopyMap(report.Target.EffectiveSettings.ExtraParams)
if err != nil {
return nil, err
}
func fromDomainSmokeTestReport(report domain.SmokeTestReport) *SmokeTestReport {
result := &SmokeTestReport{
Kind: SmokeTestKind(report.Kind),
Supported: report.Supported,
@@ -313,7 +304,7 @@ func fromDomainSmokeTestReport(report domain.SmokeTestReport) (*SmokeTestReport,
DefaultSourceBackendID: report.Target.DefaultSourceBackendID,
SelectionSource: report.Target.SelectionSource,
Endpoint: report.Target.Endpoint,
EffectiveSettings: fromDomainExecutionTargetWithOwnedParams(report.Target.EffectiveSettings, extraParams),
EffectiveSettings: fromDomainExecutionTarget(report.Target.EffectiveSettings),
SettingsPresence: fromDomainExecutionTargetPresence(report.Target.SettingsPresence),
},
Facts: fromDomainSmokeTestFacts(report.Facts),
@@ -336,7 +327,7 @@ func fromDomainSmokeTestReport(report domain.SmokeTestReport) (*SmokeTestReport,
}
}
}
return result, nil
return result
}
func fromDomainSmokeTestFacts(facts domain.SmokeTestFacts) SmokeTestFacts {