Retain producer files after failed extraction
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user