|
|
|
|
@@ -106,10 +106,9 @@ func TestNativeExtractionPromotesRequiredLanesAndReusesCanonicalProducts(t *test
|
|
|
|
|
t.Fatalf("output = %#v", output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
marker := result.Metadata["retention_path"].(string)
|
|
|
|
|
content, err := os.ReadFile(marker)
|
|
|
|
|
if err != nil || !strings.Contains(string(content), "session_durable") {
|
|
|
|
|
t.Fatalf("retention = %s, %v", content, err)
|
|
|
|
|
marker := filepath.Join(artifacts.SessionRunRootForCampaign(env.Config.Pipeline.Workspace.Root, m.Campaign, m.SessionID, m.RunID), "extract", "notarius-retention.json")
|
|
|
|
|
if _, err := os.Lstat(marker); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("unexpected retention marker: %v", err)
|
|
|
|
|
}
|
|
|
|
|
nativeRecordResult(m, result)
|
|
|
|
|
encoded, err := json.Marshal(m)
|
|
|
|
|
@@ -122,7 +121,7 @@ func TestNativeExtractionPromotesRequiredLanesAndReusesCanonicalProducts(t *test
|
|
|
|
|
}
|
|
|
|
|
*m = restored
|
|
|
|
|
// Reuse is based on canonical files even after the original bundle disappears.
|
|
|
|
|
if err := os.RemoveAll(fake.Result.BundleRoot); err != nil {
|
|
|
|
|
if err := os.RemoveAll(artifacts.SessionRunRootForCampaign(env.Config.Pipeline.Workspace.Root, m.Campaign, m.SessionID, m.RunID)); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
validation, err := (extractStage{}).ValidateResume(context.Background(), env, m)
|
|
|
|
|
@@ -155,12 +154,37 @@ func TestNativeExtractionPromotesRequiredLanesAndReusesCanonicalProducts(t *test
|
|
|
|
|
if err != nil || len(published) != 1 || published[0].LocalPath != entry.Path {
|
|
|
|
|
t.Fatalf("publication source = %#v, %v", published, err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(entry.Path, []byte(`{"tampered":true}`), 0o644); err != nil {
|
|
|
|
|
original, err := os.ReadFile(entry.Path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
validation, err = (extractStage{}).ValidateResume(context.Background(), env, m)
|
|
|
|
|
if err != nil || validation.Resumable {
|
|
|
|
|
t.Fatalf("tampered resume = %#v, %v", validation, err)
|
|
|
|
|
for _, change := range []string{"altered", "missing"} {
|
|
|
|
|
t.Run(change, func(t *testing.T) {
|
|
|
|
|
if change == "altered" {
|
|
|
|
|
err = os.WriteFile(entry.Path, []byte(`{"tampered":true}`), 0o644)
|
|
|
|
|
} else {
|
|
|
|
|
err = os.Remove(entry.Path)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
validation, err := (extractStage{}).ValidateResume(context.Background(), env, m)
|
|
|
|
|
if err != nil || validation.Resumable {
|
|
|
|
|
t.Fatalf("invalid product resume = %#v, %v", validation, err)
|
|
|
|
|
}
|
|
|
|
|
invalidCatalog := artifacts.NewArtifactCatalog()
|
|
|
|
|
if err := invalidCatalog.RegisterExtractionArtifacts(definitions); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
invalidCatalog.HydrateExtractionArtifacts(paths, m, definitions)
|
|
|
|
|
invalidEntry, ok := invalidCatalog.Lookup(artifacts.ExtractionArtifactSourceID("spells"))
|
|
|
|
|
if !ok || invalidEntry.Available {
|
|
|
|
|
t.Fatalf("invalid catalog entry = %#v", invalidEntry)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(entry.Path, original, 0o644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -281,37 +305,6 @@ func TestNativeExtractionRejectsMappedLaneCollisions(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNativeExtractionRetentionSurvivesRunCleanup(t *testing.T) {
|
|
|
|
|
env, m, fake := nativeExtractFixture(t)
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
runRoot := artifacts.SessionRunRootForCampaign(env.Config.Pipeline.Workspace.Root, m.Campaign, m.SessionID, m.RunID)
|
|
|
|
|
if err := os.Mkdir(filepath.Join(runRoot, "other"), 0o755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(filepath.Join(runRoot, "other", "temporary"), []byte("x"), 0o644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := cleanRunWithRetainedBundle(env.Config.Pipeline.Workspace.Root, runRoot, true); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(filepath.Join(fake.Result.BundleRoot, "chunk-map.json")); err != nil {
|
|
|
|
|
t.Fatalf("retained auxiliary: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(result.Metadata["retention_path"].(string)); err != nil {
|
|
|
|
|
t.Fatalf("retention marker: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(filepath.Join(runRoot, "other")); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("ordinary run data remains: %v", err)
|
|
|
|
|
}
|
|
|
|
|
pending, err := cleanRunWithRetainedBundle(env.Config.Pipeline.Workspace.Root, runRoot, false)
|
|
|
|
|
if err != nil || pending {
|
|
|
|
|
t.Fatalf("cleanup resume = %v, %v", pending, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNativeExtractionReportsPartialPromotionFailure(t *testing.T) {
|
|
|
|
|
env, m, fake := nativeExtractFixture(t)
|
|
|
|
|
env.Config.Pipeline.Notarius.Outputs = map[string]config.NotariusOutputConfig{"alpha": {LaneID: "alpha"}, "zeta": {LaneID: "zeta"}}
|
|
|
|
|
@@ -360,29 +353,3 @@ func TestNativeExtractionThroughSubprocess(t *testing.T) {
|
|
|
|
|
t.Fatalf("resume = %#v, %v", validation, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRetainedBundleCleanupRejectsUnsafeMarker(t *testing.T) {
|
|
|
|
|
env, m, _ := nativeExtractFixture(t)
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
marker := result.Metadata["retention_path"].(string)
|
|
|
|
|
if err := os.Remove(marker); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
outside := filepath.Join(t.TempDir(), "outside")
|
|
|
|
|
if err := os.WriteFile(outside, []byte(`{"role":"session_durable"}`), 0o644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.Symlink(outside, marker); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
runRoot := artifacts.SessionRunRootForCampaign(env.Config.Pipeline.Workspace.Root, m.Campaign, m.SessionID, m.RunID)
|
|
|
|
|
if _, err := cleanRunWithRetainedBundle(env.Config.Pipeline.Workspace.Root, runRoot, true); err == nil {
|
|
|
|
|
t.Fatal("unsafe retention marker accepted")
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(result.Metadata["bundle_root"].(string)); err != nil {
|
|
|
|
|
t.Fatalf("bundle removed after unsafe marker: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|