package v071 import ( "errors" "os" "path/filepath" "testing" ) func TestContractEvidenceRejectsAncestorSymlinkBeforeWrite(t *testing.T) { root := t.TempDir() outside := t.TempDir() if err := os.Symlink(outside, filepath.Join(root, "effects")); err != nil { t.Fatal(err) } if err := persistImmutableJSON(filepath.Join(root, "effects", "job", "index", "id", "intent.json"), []byte(`{"intent":true}`)); err == nil { t.Fatal("ancestor symlink accepted") } entries, err := os.ReadDir(outside) if err != nil { t.Fatal(err) } if len(entries) != 0 { t.Fatal("refusal wrote through ancestor symlink") } } func TestContractEvidenceSyncsEveryAncestorAndPropagatesFailure(t *testing.T) { root := t.TempDir() leaf := filepath.Join(root, "effects", "plan", "index", "id") synced := map[string]bool{} if err := ensureEvidenceDirectory(leaf, func(path string) error { synced[path] = true; return syncEvidenceDirectory(path) }); err != nil { t.Fatal(err) } for path := filepath.Dir(leaf); ; path = filepath.Dir(path) { if !synced[path] { t.Fatalf("unsynced directory entry parent: %s", path) } if filepath.Dir(path) == path { break } } failure := errors.New("injected directory fsync error") if err := ensureEvidenceDirectory(leaf, func(string) error { return failure }); !errors.Is(err, failure) { t.Fatalf("fsync error not propagated: %v", err) } }