diff --git a/internal/dirent/watch.go b/internal/dirent/watch.go index 36be32fc5..8c76259f5 100644 --- a/internal/dirent/watch.go +++ b/internal/dirent/watch.go @@ -364,12 +364,21 @@ func current(dir string, l Listing) bool { if watched.dirty[dir] >= at.seq { return false } - // a change in a root's own folder is word of a change anywhere under - // it: Codex appends history.jsonl, closed each time, at each prompt, - // while the rollout it writes stays open and unheard + // a change in a folder above dir, up to its root's own, is word of a + // change in dir: a folder renamed in whole under dir's name is heard + // only in the folder that holds it, and Codex appends history.jsonl, + // in the root, at each prompt while the rollout it writes stays open + // and unheard for _, r := range watched.roots { - if (within(dir, r.given) || within(dir, r.real)) && (watched.dirty[r.given] >= at.seq || watched.dirty[r.real] >= at.seq) { - return false + for _, top := range [2]string{r.given, r.real} { + if !within(dir, top) { + continue + } + for p := dir; len(p) > len(top); p = filepath.Dir(p) { + if watched.dirty[filepath.Dir(p)] >= at.seq { + return false + } + } } } return true diff --git a/internal/dirent/watch_test.go b/internal/dirent/watch_test.go index deefff9aa..74766d71a 100644 --- a/internal/dirent/watch_test.go +++ b/internal/dirent/watch_test.go @@ -221,3 +221,37 @@ func TestRootReplacedWholeIsReadAgain(t *testing.T) { t.Fatal("the new root's folder was read on every Stats after it settled") } } + +// A folder under the root replaced whole, renamed in under its name, is +// heard only in the folder that holds it: the next read lists the new +// folder, not the old one's listing. +func TestFolderReplacedWholeIsReadAgain(t *testing.T) { + root, day, _ := dayFolder(t) + if !quiet(t, root, day) { + t.Fatal("an unchanged watched folder was read again") + } + other := filepath.Join(t.TempDir(), "12") + if err := os.Mkdir(other, 0o755); err != nil { + t.Fatal(err) + } + b := filepath.Join(other, "rollout-b.jsonl") + if err := os.WriteFile(b, []byte("{}\n"), 0o644); err != nil { + t.Fatal(err) + } + aged(t, b) + if err := os.Rename(day, day+".old"); err != nil { + t.Fatal(err) + } + if err := os.Rename(other, day); err != nil { + t.Fatal(err) + } + if _, ok := sizeOf(t, root, day, "rollout-b.jsonl"); !ok { + t.Fatal("the new folder's file wasn't seen") + } + if _, ok := sizeOf(t, root, day, "rollout-a.jsonl"); ok { + t.Fatal("the old folder's file was still listed") + } + if !quiet(t, root, day) { + t.Fatal("the new folder was read on every Stats after it settled") + } +}