Retain producer files after failed extraction
This commit is contained in:
@@ -11,7 +11,11 @@ them or change the agreed operator contract.
|
|||||||
|
|
||||||
**Priority:** P2
|
**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.
|
**Stages:** 11–12; failure-evidence and workspace requirements in 16 and 21–23.
|
||||||
|
|
||||||
|
|||||||
@@ -151,14 +151,8 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re
|
|||||||
ReportPath: reportPath, LogPath: logPath, Timeout: timeout, Cache: cache,
|
ReportPath: reportPath, LogPath: logPath, Timeout: timeout, Cache: cache,
|
||||||
Debug: notariusConfig.Debug, DebugDirectory: debugDirectory, References: referenceBindings,
|
Debug: notariusConfig.Debug, DebugDirectory: debugDirectory, References: referenceBindings,
|
||||||
}
|
}
|
||||||
accepted := false
|
// Producer files remain inspectable even when completion delivery fails.
|
||||||
defer func() {
|
// Only Narratio's temporary promotion copies are cleaned below.
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
adapterResult, err := env.Notarius.Run(ctx, request)
|
adapterResult, err := env.Notarius.Run(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("extract: run notarius: %w", err)
|
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,
|
"completion": completion,
|
||||||
}
|
}
|
||||||
result = &StageResult{Outputs: outputs, Logs: []string{reportPath, logPath}, Metadata: metadata}
|
result = &StageResult{Outputs: outputs, Logs: []string{reportPath, logPath}, Metadata: metadata}
|
||||||
accepted = true
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package stage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -46,6 +47,34 @@ func nativeRecordResult(m *manifest.Manifest, result *StageResult) {
|
|||||||
m.Stages["extract"].Metadata = result.Metadata
|
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) {
|
func TestNativeExtractionPromotesRequiredLanesAndReusesCanonicalProducts(t *testing.T) {
|
||||||
env, m, fake := nativeExtractFixture(t)
|
env, m, fake := nativeExtractFixture(t)
|
||||||
reporter := &extractionWarnings{}
|
reporter := &extractionWarnings{}
|
||||||
|
|||||||
Reference in New Issue
Block a user