diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 747537e..d843d28 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -11,7 +11,11 @@ them or change the agreed operator contract. **Priority:** P2 -**Status:** Pending +**Status:** Complete + +Producer output is retained on failure; temporary promotion copies still clean +up. Stage regressions cover failed delivery and missing/invalid lanes, without +promoting incidental files. Verified with `go test ./internal/stage`. **Stages:** 11–12; failure-evidence and workspace requirements in 16 and 21–23. diff --git a/internal/stage/extract.go b/internal/stage/extract.go index 8e854a9..bf63373 100644 --- a/internal/stage/extract.go +++ b/internal/stage/extract.go @@ -151,14 +151,8 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re ReportPath: reportPath, LogPath: logPath, Timeout: timeout, Cache: cache, Debug: notariusConfig.Debug, DebugDirectory: debugDirectory, References: referenceBindings, } - accepted := false - defer func() { - if !accepted { - if cleanupErr := fileops.RemoveAllUnderRoot(filepath.Dir(outputRoot), outputRoot); cleanupErr != nil { - resultErr = errors.Join(resultErr, fmt.Errorf("extract: remove failed Notarius output root: %w", cleanupErr)) - } - } - }() + // Producer files remain inspectable even when completion delivery fails. + // Only Narratio's temporary promotion copies are cleaned below. adapterResult, err := env.Notarius.Run(ctx, request) if err != nil { return nil, fmt.Errorf("extract: run notarius: %w", err) @@ -248,7 +242,6 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re "completion": completion, } result = &StageResult{Outputs: outputs, Logs: []string{reportPath, logPath}, Metadata: metadata} - accepted = true return result, nil } diff --git a/internal/stage/extract_native_test.go b/internal/stage/extract_native_test.go index 21f6f54..18b5732 100644 --- a/internal/stage/extract_native_test.go +++ b/internal/stage/extract_native_test.go @@ -3,6 +3,7 @@ package stage import ( "context" "encoding/json" + "errors" "os" "path/filepath" "strings" @@ -46,6 +47,34 @@ func nativeRecordResult(m *manifest.Manifest, result *StageResult) { m.Stages["extract"].Metadata = result.Metadata } +func TestNativeExtractionFailureRetainsProducerFiles(t *testing.T) { + for _, failure := range []string{"delivery", "missing", "invalid"} { + t.Run(failure, func(t *testing.T) { + env, m, fake := nativeExtractFixture(t) + if failure == "delivery" { + fake.Err = errors.New("completion delivery failed") + } else { + env.Config.Pipeline.Notarius.Outputs["other"] = config.NotariusOutputConfig{LaneID: "other"} + if failure == "invalid" { + writeFile(t, filepath.Join(fake.Result.BundleRoot, "lanes", "other.json"), "invalid JSON") + } + } + result, err := (extractStage{}).Run(context.Background(), env, m) + if err == nil || result != nil { + t.Fatalf("failed extraction returned %v, %v", result, err) + } + for _, name := range []string{"lanes/npc-registry.json", "chunk-map.json"} { + if _, err := os.Stat(filepath.Join(fake.Result.BundleRoot, name)); err != nil { + t.Fatalf("producer evidence %s lost: %v", name, err) + } + } + if _, err := os.Stat(filepath.Join(sessionPathsForEnv(env, m.SessionID).ArtifactsDir, "npc_registry.json")); !os.IsNotExist(err) { + t.Fatalf("failed extraction promoted a product: %v", err) + } + }) + } +} + func TestNativeExtractionPromotesRequiredLanesAndReusesCanonicalProducts(t *testing.T) { env, m, fake := nativeExtractFixture(t) reporter := &extractionWarnings{}