-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscan_plans_test.go
More file actions
95 lines (75 loc) · 2.27 KB
/
Copy pathscan_plans_test.go
File metadata and controls
95 lines (75 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"os"
"path/filepath"
"testing"
)
func withCleanWhitelist(t *testing.T) {
t.Helper()
fileMutex.Lock()
orig := markdownFiles
markdownFiles = nil
fileMutex.Unlock()
t.Cleanup(func() {
fileMutex.Lock()
markdownFiles = orig
fileMutex.Unlock()
})
}
func TestScanUntrackedPlans_WhitelistsNewFiles(t *testing.T) {
plansDir := t.TempDir()
cacheDir := filepath.Join(t.TempDir(), "cache")
planPath := filepath.Join(plansDir, "test-plan.md")
if err := os.WriteFile(planPath, []byte("# Plan: Test Plan\n\nSome content"), 0644); err != nil {
t.Fatal(err)
}
tracked := map[string]*SessionMetadata{}
withCleanWhitelist(t)
scanUntrackedPlans(tracked, plansDir, cacheDir)
if !isWhitelistedFile(planPath) {
t.Error("plan file should be whitelisted after scan")
}
cachedPath := filepath.Join(cacheDir, "test-plan.md")
if _, err := os.Stat(cachedPath); err != nil {
t.Errorf("cached plan file should exist: %v", err)
}
}
func TestScanUntrackedPlans_SkipsTrackedFiles(t *testing.T) {
plansDir := t.TempDir()
planPath := filepath.Join(plansDir, "existing.md")
if err := os.WriteFile(planPath, []byte("# Plan: Existing"), 0644); err != nil {
t.Fatal(err)
}
tracked := map[string]*SessionMetadata{
planPath: {ToolName: "Write"},
}
withCleanWhitelist(t)
scanUntrackedPlans(tracked, plansDir, "")
if isWhitelistedFile(planPath) {
t.Error("tracked plan file should not be re-whitelisted")
}
}
func TestScanUntrackedPlans_SkipsNonMarkdown(t *testing.T) {
plansDir := t.TempDir()
if err := os.WriteFile(filepath.Join(plansDir, "notes.txt"), []byte("not markdown"), 0644); err != nil {
t.Fatal(err)
}
if err := os.Mkdir(filepath.Join(plansDir, "subdir.md"), 0755); err != nil {
t.Fatal(err)
}
tracked := map[string]*SessionMetadata{}
withCleanWhitelist(t)
scanUntrackedPlans(tracked, plansDir, "")
fileMutex.Lock()
count := len(markdownFiles)
fileMutex.Unlock()
if count != 0 {
t.Errorf("expected 0 whitelisted files, got %d", count)
}
}
func TestScanUntrackedPlans_EmptyDir(t *testing.T) {
// Verify no panic on empty, missing, or blank dir
scanUntrackedPlans(map[string]*SessionMetadata{}, t.TempDir(), "")
scanUntrackedPlans(map[string]*SessionMetadata{}, "", "")
scanUntrackedPlans(map[string]*SessionMetadata{}, "/nonexistent/path", "")
}