forked from sudo-tee/opencode.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_file_spec.lua
More file actions
95 lines (85 loc) · 3.05 KB
/
config_file_spec.lua
File metadata and controls
95 lines (85 loc) · 3.05 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
local config_file = require('opencode.config_file')
local Promise = require('opencode.promise')
local state = require('opencode.state')
describe('config_file.setup', function()
local original_schedule
local original_api_client
before_each(function()
original_schedule = vim.schedule
vim.schedule = function(fn)
fn()
end
original_api_client = state.api_client
config_file.config_promise = nil
config_file.project_promise = nil
end)
after_each(function()
vim.schedule = original_schedule
state.api_client = original_api_client
end)
it('lazily loads config when accessed', function()
local get_config_called, get_project_called = false, false
local cfg = { agent = { ['a1'] = { mode = 'primary' } } }
state.api_client = {
get_config = function()
get_config_called = true
return Promise.new():resolve(cfg)
end,
get_current_project = function()
get_project_called = true
return Promise.new():resolve({ id = 'p1', name = 'P', path = '/tmp' })
end,
}
-- Promises should not be set up during setup (lazy loading)
assert.falsy(config_file.config_promise)
assert.falsy(config_file.project_promise)
-- Accessing config should trigger lazy loading
local resolved_cfg = config_file.get_opencode_config()
assert.same(cfg, resolved_cfg)
assert.True(get_config_called)
-- Project should be loaded when accessed
local project = config_file.get_opencode_project()
assert.True(get_project_called)
end)
it('get_opencode_agents returns primary + defaults', function()
state.api_client = {
get_config = function()
return Promise.new():resolve({ agent = { ['custom'] = { mode = 'primary' } } })
end,
get_current_project = function()
return Promise.new():resolve({ id = 'p1' })
end,
}
local agents = config_file.get_opencode_agents()
assert.True(vim.tbl_contains(agents, 'custom'))
assert.True(vim.tbl_contains(agents, 'build'))
assert.True(vim.tbl_contains(agents, 'plan'))
end)
it('get_opencode_agents respects disabled defaults', function()
state.api_client = {
get_config = function()
return Promise.new():resolve({ agent = { ['custom'] = { mode = 'primary' }, ['build'] = { disable = true }, ['plan'] = { disable = false } } })
end,
get_current_project = function()
return Promise.new():resolve({ id = 'p1' })
end,
}
local agents = config_file.get_opencode_agents()
assert.True(vim.tbl_contains(agents, 'custom'))
assert.False(vim.tbl_contains(agents, 'build'))
assert.True(vim.tbl_contains(agents, 'plan'))
end)
it('get_opencode_project returns project', function()
local project = { id = 'p1', name = 'X' }
state.api_client = {
get_config = function()
return Promise.new():resolve({ agent = {} })
end,
get_current_project = function()
return Promise.new():resolve(project)
end,
}
local proj = config_file.get_opencode_project()
assert.same(project, proj)
end)
end)