Simplify smoke report ownership
This commit is contained in:
@@ -383,6 +383,12 @@ results also remain detached from metadata retained by the handle.
|
|||||||
|
|
||||||
## Stage 14: Simplify Smoke Target And Public Report Detachment
|
## 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`,
|
**Finding:** 5. **Files:** `internal/usecase/smoke_tester.go`,
|
||||||
`smoke_diagnostics.go`, smoke conversion/ownership tests.
|
`smoke_diagnostics.go`, smoke conversion/ownership tests.
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
"go.maximumdirect.net/promptkit/internal/generation"
|
"go.maximumdirect.net/promptkit/internal/generation"
|
||||||
"go.maximumdirect.net/promptkit/internal/jsonvalue"
|
|
||||||
"go.maximumdirect.net/promptkit/internal/llm"
|
"go.maximumdirect.net/promptkit/internal/llm"
|
||||||
"go.maximumdirect.net/promptkit/internal/observation"
|
"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) {
|
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 = ""
|
target.EffectiveSettings.APIKey = ""
|
||||||
|
var err error
|
||||||
target.Endpoint, err = endpointWithoutUserInfo(target.Endpoint)
|
target.Endpoint, err = endpointWithoutUserInfo(target.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.SmokeTestTarget{}, fmt.Errorf("%w: invalid resolved diagnostic endpoint", ErrInvalidRequest)
|
return domain.SmokeTestTarget{}, fmt.Errorf("%w: invalid resolved diagnostic endpoint", ErrInvalidRequest)
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ func (b cancelOnCloseSmokeBody) Close() error {
|
|||||||
return b.ReadCloser.Close()
|
return b.ReadCloser.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSmokeReportTargetOwnsProviderValuesAndRedactsCredentials(t *testing.T) {
|
func TestSmokeReportTargetRedactsCredentialsAndSanitizesEndpoints(t *testing.T) {
|
||||||
target := domain.SmokeTestTarget{
|
target := domain.SmokeTestTarget{
|
||||||
Endpoint: "https://user:password@example.invalid/key",
|
Endpoint: "https://user:password@example.invalid/key",
|
||||||
EffectiveSettings: domain.ExecutionTarget{
|
EffectiveSettings: domain.ExecutionTarget{
|
||||||
@@ -407,13 +407,8 @@ func TestSmokeReportTargetOwnsProviderValuesAndRedactsCredentials(t *testing.T)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
got.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] = "changed"
|
if got.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] != "original" ||
|
||||||
if target.EffectiveSettings.ExtraParams["nested"].(map[string]any)["value"] != "original" ||
|
|
||||||
got.EffectiveSettings.APIKey != "" || got.Endpoint != "https://example.invalid/key" || got.EffectiveSettings.Endpoint != "https://example.invalid/v1" {
|
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)
|
t.Fatalf("report target not redacted: %+v", got)
|
||||||
}
|
|
||||||
target.EffectiveSettings.ExtraParams = map[string]any{"invalid": func() {}}
|
|
||||||
if _, err := smokeReportTarget(target); err == nil {
|
|
||||||
t.Fatal("invalid provider values were accepted")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,14 +29,8 @@ func TestSmokeReportConversionOwnsMutableValues(t *testing.T) {
|
|||||||
Timing: domain.SmokeTestTiming{RequestDuration: &duration},
|
Timing: domain.SmokeTestTiming{RequestDuration: &duration},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
converted, err := fromDomainSmokeTestReport(source)
|
converted := fromDomainSmokeTestReport(source)
|
||||||
if err != nil {
|
other := fromDomainSmokeTestReport(source)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
other, err := fromDomainSmokeTestReport(source)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
encoded, err := json.Marshal(converted)
|
encoded, err := json.Marshal(converted)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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" {
|
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)
|
t.Fatalf("converted report changed source provider parameters: %v", got)
|
||||||
}
|
}
|
||||||
later, err := fromDomainSmokeTestReport(source)
|
later := fromDomainSmokeTestReport(source)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(other, later) {
|
if !reflect.DeepEqual(other, later) {
|
||||||
t.Fatal("converted report mutation affected another result")
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
"go.maximumdirect.net/promptkit/internal/jsonvalue"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SmokeTestKind identifies one built-in diagnostic operation.
|
// SmokeTestKind identifies one built-in diagnostic operation.
|
||||||
@@ -272,11 +271,7 @@ func (e *Engine) SmokeTest(ctx context.Context, req SmokeTestRequest) (*SmokeTes
|
|||||||
if domainReport == nil {
|
if domainReport == nil {
|
||||||
return nil, mapPublicError(err)
|
return nil, mapPublicError(err)
|
||||||
}
|
}
|
||||||
report, conversionErr := fromDomainSmokeTestReport(*domainReport)
|
return fromDomainSmokeTestReport(*domainReport), mapPublicError(err)
|
||||||
if conversionErr != nil {
|
|
||||||
return nil, fmt.Errorf("%w: failed to copy smoke-test report", ErrInvalidRequest)
|
|
||||||
}
|
|
||||||
return report, mapPublicError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toDomainSmokeTestRequest(request SmokeTestRequest) (domain.SmokeTestRequest, error) {
|
func toDomainSmokeTestRequest(request SmokeTestRequest) (domain.SmokeTestRequest, error) {
|
||||||
@@ -295,11 +290,7 @@ func toDomainSmokeTestRequest(request SmokeTestRequest) (domain.SmokeTestRequest
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromDomainSmokeTestReport(report domain.SmokeTestReport) (*SmokeTestReport, error) {
|
func fromDomainSmokeTestReport(report domain.SmokeTestReport) *SmokeTestReport {
|
||||||
extraParams, err := jsonvalue.CopyMap(report.Target.EffectiveSettings.ExtraParams)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &SmokeTestReport{
|
result := &SmokeTestReport{
|
||||||
Kind: SmokeTestKind(report.Kind),
|
Kind: SmokeTestKind(report.Kind),
|
||||||
Supported: report.Supported,
|
Supported: report.Supported,
|
||||||
@@ -313,7 +304,7 @@ func fromDomainSmokeTestReport(report domain.SmokeTestReport) (*SmokeTestReport,
|
|||||||
DefaultSourceBackendID: report.Target.DefaultSourceBackendID,
|
DefaultSourceBackendID: report.Target.DefaultSourceBackendID,
|
||||||
SelectionSource: report.Target.SelectionSource,
|
SelectionSource: report.Target.SelectionSource,
|
||||||
Endpoint: report.Target.Endpoint,
|
Endpoint: report.Target.Endpoint,
|
||||||
EffectiveSettings: fromDomainExecutionTargetWithOwnedParams(report.Target.EffectiveSettings, extraParams),
|
EffectiveSettings: fromDomainExecutionTarget(report.Target.EffectiveSettings),
|
||||||
SettingsPresence: fromDomainExecutionTargetPresence(report.Target.SettingsPresence),
|
SettingsPresence: fromDomainExecutionTargetPresence(report.Target.SettingsPresence),
|
||||||
},
|
},
|
||||||
Facts: fromDomainSmokeTestFacts(report.Facts),
|
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 {
|
func fromDomainSmokeTestFacts(facts domain.SmokeTestFacts) SmokeTestFacts {
|
||||||
|
|||||||
Reference in New Issue
Block a user