-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathconfig_spec.lua
More file actions
148 lines (124 loc) · 3.89 KB
/
config_spec.lua
File metadata and controls
148 lines (124 loc) · 3.89 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
-- luacheck: globals expect
require("tests.busted_setup")
describe("Configuration", function()
local config
local function setup()
package.loaded["claudecode.config"] = nil
config = require("claudecode.config")
end
local function teardown()
-- Nothing to clean up for now
end
setup()
it("should have default configuration", function()
expect(config.defaults).to_be_table()
expect(config.defaults).to_have_key("port_range")
expect(config.defaults).to_have_key("auto_start")
expect(config.defaults).to_have_key("log_level")
expect(config.defaults).to_have_key("track_selection")
expect(config.defaults).to_have_key("models")
end)
it("should validate valid configuration", function()
local valid_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
terminal_cmd = "toggleterm",
log_level = "debug",
track_selection = false,
visual_demotion_delay_ms = 50,
connection_wait_delay = 200,
connection_timeout = 10000,
queue_timeout = 5000,
diff_opts = {
auto_close_on_accept = true,
show_diff_stats = true,
vertical_split = true,
open_in_current_tab = true,
},
models = {
{ name = "Test Model", value = "test-model" },
},
}
local success = config.validate(valid_config)
expect(success).to_be_true()
end)
it("should reject invalid port range", function()
local invalid_config = {
port_range = { min = -1, max = 65536 },
auto_start = true,
log_level = "debug",
track_selection = false,
}
local success, _ = pcall(function() -- Use _ for unused error variable
config.validate(invalid_config)
end)
expect(success).to_be_false()
end)
it("should reject invalid log level", function()
local invalid_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
log_level = "invalid_level",
track_selection = false,
}
local success, _ = pcall(function() -- Use _ for unused error variable
config.validate(invalid_config)
end)
expect(success).to_be_false()
end)
it("should reject invalid models configuration", function()
local invalid_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
log_level = "debug",
track_selection = false,
visual_demotion_delay_ms = 50,
diff_opts = {
auto_close_on_accept = true,
show_diff_stats = true,
vertical_split = true,
open_in_current_tab = true,
},
models = {}, -- Empty models array should be rejected
}
local success, _ = pcall(function()
config.validate(invalid_config)
end)
expect(success).to_be_false()
end)
it("should reject models with invalid structure", function()
local invalid_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
log_level = "debug",
track_selection = false,
visual_demotion_delay_ms = 50,
diff_opts = {
auto_close_on_accept = true,
show_diff_stats = true,
vertical_split = true,
open_in_current_tab = true,
},
models = {
{ name = "Test Model" }, -- Missing value field
},
}
local success, _ = pcall(function()
config.validate(invalid_config)
end)
expect(success).to_be_false()
end)
it("should merge user config with defaults", function()
local user_config = {
auto_start = true,
log_level = "debug",
}
local merged_config = config.apply(user_config)
expect(merged_config.auto_start).to_be_true()
expect(merged_config.log_level).to_be("debug")
expect(merged_config.port_range.min).to_be(config.defaults.port_range.min)
expect(merged_config.track_selection).to_be(config.defaults.track_selection)
expect(merged_config.models).to_be_table()
end)
teardown()
end)