Repository navigation
Expand file tree
/
Copy pathdoctor_test.go
More file actions
51 lines (46 loc) · 1.45 KB
/
Copy pathdoctor_test.go
File metadata and controls
51 lines (46 loc) · 1.45 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
package contexting
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestRunDoctorHealthy(t *testing.T) {
tmpDir := t.TempDir()
index := &ContextIndex{
RootPath: tmpDir,
GeneratedAt: time.Now().UTC(),
Tree: &Node{
FullPath: tmpDir,
Type: "directory",
Children: map[string]*Node{},
},
}
if err := SaveContextIndex(filepath.Join(tmpDir, ".ctxt", "ctx_index.json"), index); err != nil {
t.Fatalf("save index: %v", err)
}
if err := SaveSynonymCache(filepath.Join(tmpDir, ".ctxt", "ctx_cache.json"), SynonymResponse{"src": {"code"}}); err != nil {
t.Fatalf("save cache: %v", err)
}
if err := writeStarterConfig(filepath.Join(tmpDir, "context.toml"), false); err != nil {
t.Fatalf("write config: %v", err)
}
if err := os.Setenv("OPENROUTER_API_KEY", "sk-test"); err != nil {
t.Fatalf("set env: %v", err)
}
defer os.Unsetenv("OPENROUTER_API_KEY")
report := RunDoctor(DoctorOptions{ConfigPath: filepath.Join(tmpDir, "context.toml"), RootPath: tmpDir, WriteCheck: true})
if !report.Healthy {
t.Fatalf("expected healthy report, got %+v", report)
}
if len(report.Checks) == 0 {
t.Fatalf("expected checks in report")
}
}
func TestRunDoctorFindsFailures(t *testing.T) {
tmpDir := t.TempDir()
report := RunDoctor(DoctorOptions{ConfigPath: filepath.Join(tmpDir, "missing.toml"), RootPath: filepath.Join(tmpDir, "missing-root"), WriteCheck: false})
if report.Healthy {
t.Fatalf("expected unhealthy report when root is missing")
}
}