Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(httpapi): split temp-dir scan and mtime filter out of recentDeckPathsIn (#477)

fx-kurumidc84d68b9ca3
diff --git a/internal/httpapi/assistant_workbench.go b/internal/httpapi/assistant_workbench.go
index 791548f3..1971a10c 100644
--- a/internal/httpapi/assistant_workbench.go
+++ b/internal/httpapi/assistant_workbench.go
@@ -674,10 +674,22 @@ func recentDeckPathsIn(root string, since, until time.Time) []string {
var out []string
out = append(out, deckFilesUnder(filepath.Join(root, "ws"), 0)...)
out = append(out, deckFilesUnder(filepath.Join(root, "home", "tmp"), 0)...)
- entries, err := os.ReadDir(os.TempDir())
+ tmp, err := tempDirDeckFiles()
if err != nil {
return uniquePaths(out)
}
+ out = append(out, tmp...)
+ return filterRecentRegularFiles(uniquePaths(out), since, until)
+}
+
+// tempDirDeckFiles collects pptx files directly under the system temp dir and
+// inside temp subdirectories whose names look deck-related.
+func tempDirDeckFiles() ([]string, error) {
+ entries, err := os.ReadDir(os.TempDir())
+ if err != nil {
+ return nil, err
+ }
+ var out []string
for _, entry := range entries {
name := entry.Name()
path := filepath.Join(os.TempDir(), name)
@@ -693,8 +705,14 @@ func recentDeckPathsIn(root string, since, until time.Time) []string {
}
out = append(out, deckFilesUnder(path, 0)...)
}
+ return out, nil
+}
+
+// filterRecentRegularFiles keeps regular files modified within
+// [since-30s, until]; a zero since/until leaves that side unbounded.
+func filterRecentRegularFiles(paths []string, since, until time.Time) []string {
var fresh []string
- for _, path := range uniquePaths(out) {
+ for _, path := range paths {
info, err := os.Lstat(path)
if err != nil || !info.Mode().IsRegular() {
continue
diff --git a/internal/httpapi/assistant_workbench_deck_paths_test.go b/internal/httpapi/assistant_workbench_deck_paths_test.go
new file mode 100644
index 00000000..c81f4ec0
--- /dev/null
+++ b/internal/httpapi/assistant_workbench_deck_paths_test.go
@@ -0,0 +1,84 @@
+package httpapi
+
+import (
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestFilterRecentRegularFiles(t *testing.T) {
+ dir := t.TempDir()
+ base := time.Date(2026, 11, 13, 12, 0, 0, 0, time.UTC)
+ write := func(name string, mod time.Time) string {
+ path := filepath.Join(dir, name)
+ if err := os.WriteFile(path, []byte("x"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chtimes(path, mod, mod); err != nil {
+ t.Fatal(err)
+ }
+ return path
+ }
+ old := write("old.pptx", base.Add(-time.Minute))
+ grace := write("grace.pptx", base.Add(-20*time.Second))
+ inside := write("inside.pptx", base.Add(time.Minute))
+ future := write("future.pptx", base.Add(time.Hour))
+ subdir := filepath.Join(dir, "dir.pptx")
+ if err := os.Mkdir(subdir, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ link := filepath.Join(dir, "link.pptx")
+ if err := os.Symlink(inside, link); err != nil {
+ t.Fatal(err)
+ }
+ missing := filepath.Join(dir, "missing.pptx")
+ all := []string{old, grace, inside, future, subdir, link, missing}
+
+ got := filterRecentRegularFiles(all, base, base.Add(2*time.Minute))
+ if want := []string{grace, inside}; !slices.Equal(got, want) {
+ t.Fatalf("windowed=%v want %v", got, want)
+ }
+ got = filterRecentRegularFiles(all, time.Time{}, time.Time{})
+ if want := []string{old, grace, inside, future}; !slices.Equal(got, want) {
+ t.Fatalf("unbounded=%v want %v", got, want)
+ }
+}
+
+func TestTempDirDeckFiles(t *testing.T) {
+ root := t.TempDir()
+ t.Setenv("TMPDIR", root)
+ mk := func(rel string) string {
+ path := filepath.Join(root, rel)
+ if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path, []byte("x"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ return path
+ }
+ top := mk("top.PPTX")
+ mk("notes.txt")
+ inPPT := mk("my-ppt-job/deck.pptx")
+ inSlide := mk("Slides/a/b.pptx")
+ inLF := mk("loopforge-x/c.pptx")
+ mk("unrelated/d.pptx")
+
+ got, err := tempDirDeckFiles()
+ if err != nil {
+ t.Fatal(err)
+ }
+ slices.Sort(got)
+ want := []string{inSlide, inLF, inPPT, top}
+ slices.Sort(want)
+ if !slices.Equal(got, want) {
+ t.Fatalf("temp decks=%v want %v", got, want)
+ }
+
+ t.Setenv("TMPDIR", filepath.Join(root, "does-not-exist"))
+ if _, err := tempDirDeckFiles(); err == nil {
+ t.Fatal("expected error for missing temp dir")
+ }
+}