Limit cleanup checks to owned diagnostic views
This commit is contained in:
@@ -57,7 +57,12 @@ before promotion, as the existing staging test already requires.
|
||||
|
||||
**Priority:** P2
|
||||
|
||||
**Status:** Pending
|
||||
**Status:** Complete
|
||||
|
||||
Cleanup inspects only canonical stage and restore views. Unrelated files,
|
||||
directories, and links remain untouched; conflicts at owned views still fail.
|
||||
Verified cleanup/resume/rotation and file-operation tests with
|
||||
`go test ./internal/fileops ./internal/stage`.
|
||||
|
||||
**Stages:** 15 and 20; requirement-strengthening review in 21–23.
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ func existingManagedView(parent *os.Root, name, category string) (*string, error
|
||||
|
||||
// ManagedAttemptTargets returns run-relative diagnostic directories selected by
|
||||
// the session's managed navigation links. It never follows link targets.
|
||||
func ManagedAttemptTargets(sessionRoot, runID string) ([]string, error) {
|
||||
func ManagedAttemptTargets(sessionRoot, runID string, names []string) ([]string, error) {
|
||||
if err := pathsafe.ValidateOpaqueSegment(runID); err != nil {
|
||||
return nil, fmt.Errorf("run identity: %w", err)
|
||||
}
|
||||
@@ -165,19 +165,7 @@ func ManagedAttemptTargets(sessionRoot, runID string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dir, err := parent.Open(".")
|
||||
if err != nil {
|
||||
_ = parent.Close()
|
||||
return nil, err
|
||||
}
|
||||
entries, err := dir.ReadDir(-1)
|
||||
_ = dir.Close()
|
||||
if err != nil {
|
||||
_ = parent.Close()
|
||||
return nil, err
|
||||
}
|
||||
for _, entry := range entries {
|
||||
name := entry.Name()
|
||||
for _, name := range names {
|
||||
if err := pathsafe.ValidateOpaqueSegment(name); err != nil {
|
||||
_ = parent.Close()
|
||||
return nil, fmt.Errorf("invalid managed %s view %q: %w", category, name, err)
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestManagedAttemptTargetsRejectForeignLinks(t *testing.T) {
|
||||
if err := os.Symlink("../../outside", filepath.Join(root, "logs", "polish")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ManagedAttemptTargets(root, "run-one"); err == nil {
|
||||
if _, err := ManagedAttemptTargets(root, "run-one", []string{"polish"}); err == nil {
|
||||
t.Fatal("accepted foreign diagnostic target")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,11 @@ func cleanRunWithRetainedBundle(workspaceRoot, runRoot string, remove bool) (boo
|
||||
return false, fmt.Errorf("invalid run cleanup directory %q", runRoot)
|
||||
}
|
||||
sessionRoot := filepath.Dir(runsDir)
|
||||
targets, err := fileops.ManagedAttemptTargets(sessionRoot, filepath.Base(runRoot))
|
||||
names := []string{"restore"}
|
||||
for _, stage := range All() {
|
||||
names = append(names, stage.Name())
|
||||
}
|
||||
targets, err := fileops.ManagedAttemptTargets(sessionRoot, filepath.Base(runRoot), names)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("resolve managed diagnostic targets: %w", err)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,13 @@ func TestCleanupPreservesLatestViewsAcrossRunsAndRemovesOldDiagnostics(t *testin
|
||||
writeStageTestFile(t, kept, "current")
|
||||
writeStageTestFile(t, old, "old")
|
||||
writeStageTestFile(t, filepath.Join(root, "polish", "outputs", "work.json"), "work")
|
||||
for _, category := range []string{"logs", "debug"} {
|
||||
writeStageTestFile(t, filepath.Join(session.Root, category, "README.txt"), "operator notes")
|
||||
writeStageTestFile(t, filepath.Join(session.Root, category, "notes", "keep.txt"), "keep")
|
||||
if err := os.Symlink("../../outside", filepath.Join(session.Root, category, "operator-link")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := (cleanupStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -78,6 +85,13 @@ func TestCleanupPreservesLatestViewsAcrossRunsAndRemovesOldDiagnostics(t *testin
|
||||
if _, err := os.Stat(filepath.Join(session.Root, "logs", "merge")); err != nil {
|
||||
t.Fatalf("newer merge view: %v", err)
|
||||
}
|
||||
for _, category := range []string{"logs", "debug"} {
|
||||
for _, name := range []string{"README.txt", "notes/keep.txt", "operator-link"} {
|
||||
if _, err := os.Lstat(filepath.Join(session.Root, category, name)); err != nil {
|
||||
t.Fatalf("unrelated content removed: %s/%s: %v", category, name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanupStageRemovesOnlySelectedPublishedRunTarget(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user