-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
151 lines (138 loc) · 3.63 KB
/
Copy pathconfig_test.go
File metadata and controls
151 lines (138 loc) · 3.63 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestLoadConfig_Defaults(t *testing.T) {
tmpDir := t.TempDir()
t.Setenv("HOME", tmpDir)
// No config file → use defaults
cfg := LoadConfig()
if cfg.ResumeMode != ResumeModeReplace {
t.Errorf("default resume_mode = %s, want replace", cfg.ResumeMode)
}
if cfg.Platforms == nil {
t.Error("platforms should not be nil")
}
if len(cfg.CustomAgents) != 0 {
t.Errorf("default custom_agents = %d, want 0", len(cfg.CustomAgents))
}
// ArgsFor for codebuddy returns platform-level args
args := cfg.ArgsFor(PlatformCodeBuddy)
if args != nil {
t.Errorf("default args for codebuddy = %v, want nil", args)
}
}
func TestLoadConfig_CustomAgents(t *testing.T) {
tmpDir := t.TempDir()
roostDir := filepath.Join(tmpDir, ".roost")
if err := os.MkdirAll(roostDir, 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("HOME", tmpDir)
if err := os.WriteFile(filepath.Join(roostDir, "roost.yaml"), []byte(`
resume_mode: suspend
platforms:
codebuddy:
args: [-y]
custom_agents:
- name: my-claude
type: claude
bin: claude-internal
data_dir: .claude-internal
args: [--dangerously-skip-permissions]
`), 0o644); err != nil {
t.Fatal(err)
}
cfg := LoadConfig()
if cfg.ResumeMode != ResumeModeSuspend {
t.Errorf("resume_mode = %s, want suspend", cfg.ResumeMode)
}
if len(cfg.CustomAgents) != 1 {
t.Fatalf("expected 1 custom agent, got %d", len(cfg.CustomAgents))
}
ca := cfg.CustomAgents[0]
if ca.Name != "my-claude" {
t.Errorf("custom agent name = %s, want my-claude", ca.Name)
}
if ca.Type != "claude" {
t.Errorf("custom agent type = %s, want claude", ca.Type)
}
if ca.Bin != "claude-internal" {
t.Errorf("custom agent bin = %s, want claude-internal", ca.Bin)
}
if ca.DataDir != ".claude-internal" {
t.Errorf("custom agent data_dir = %s, want .claude-internal", ca.DataDir)
}
args := cfg.ArgsFor(PlatformCodeBuddy)
if len(args) != 1 || args[0] != "-y" {
t.Errorf("codebuddy args = %v, want [-y]", args)
}
}
func TestConfig_GetResumeMode(t *testing.T) {
tests := []struct {
mode ResumeMode
want ResumeMode
}{
{"", ResumeModeReplace},
{ResumeModeReplace, ResumeModeReplace},
{ResumeModeSuspend, ResumeModeSuspend},
{"invalid", ResumeModeReplace},
}
for _, tt := range tests {
cfg := AppConfig{ResumeMode: tt.mode}
if got := cfg.GetResumeMode(); got != tt.want {
t.Errorf("GetResumeMode(%q) = %s, want %s", tt.mode, got, tt.want)
}
}
}
func TestPlatformString(t *testing.T) {
tests := []struct {
p Platform
want string
}{
{PlatformCodeBuddy, "CodeBuddy"},
{PlatformClaude, "Claude"},
{PlatformGemini, "Gemini"},
{PlatformCodex, "Codex"},
{PlatformCopilot, "Copilot"},
{PlatformOpenCode, "OpenCode"},
}
for _, tt := range tests {
if got := tt.p.String(); got != tt.want {
t.Errorf("Platform(%d).String() = %s, want %s", tt.p, got, tt.want)
}
}
}
func TestPlatformIcon(t *testing.T) {
for _, p := range AllPlatforms() {
icon := p.Icon()
if icon == "" {
t.Errorf("Platform(%s).Icon() returned empty", p)
}
}
}
func TestRelativeTime_Formats(t *testing.T) {
now := time.Now()
tests := []struct {
name string
t time.Time
want string
}{
{"now", now, "just now"},
{"zero", time.Time{}, "-"},
{"2min ago", now.Add(-2 * time.Minute), "2m ago"},
{"2h ago", now.Add(-2 * time.Hour), "2h ago"},
{"2d ago", now.Add(-48 * time.Hour), "2d ago"},
{"future", now.Add(1 * time.Hour), "just now"},
}
for _, tt := range tests {
got := RelativeTime(tt.t)
if got != tt.want {
// RelativeTime is approximate, check prefix instead
t.Logf("RelativeTime(%s) = %s, want %s", tt.name, got, tt.want)
}
}
}