-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_model.lua
More file actions
131 lines (111 loc) · 3.47 KB
/
Copy pathtest_model.lua
File metadata and controls
131 lines (111 loc) · 3.47 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
local eq = MiniTest.expect.equality
local child_helper = require("tests.child_helper")
local child = child_helper.new_child_neovim("test_model")
local u = require("tests.utils")
local T = MiniTest.new_set({
hooks = {
pre_once = function() end,
pre_case = function()
child.run_pre_case(true)
end,
post_once = child.stop,
},
})
T["model()"] = MiniTest.new_set()
-- get_current_model tests
T["model()"]["get_current_model returns empty string by default"] = function()
child.configure_copilot()
local result = child.lua([[
local model = require("copilot.model")
return model.get_current_model()
]])
eq(result, "")
end
T["model()"]["get_current_model returns config value when set"] = function()
child.configure_copilot()
local result = child.lua([[
local config = require("copilot.config")
config.copilot_model = "gpt-4o"
local model = require("copilot.model")
return model.get_current_model()
]])
eq(result, "gpt-4o")
end
T["model()"]["get_current_model selected_model takes priority over config"] = function()
child.configure_copilot()
local result = child.lua([[
local config = require("copilot.config")
config.copilot_model = "gpt-4o"
local model = require("copilot.model")
model.selected_model = "gpt-4o-mini"
return model.get_current_model()
]])
eq(result, "gpt-4o-mini")
end
-- set tests
T["model()"]["set with valid model_id notifies"] = function()
child.configure_copilot()
child.lua([[
local model = require("copilot.model")
model.set({ args = "gpt-4o-mini" })
]])
local messages = child.lua([[
vim.wait(200, function() return false end, 10)
return vim.api.nvim_exec("messages", { output = true }) or ""
]])
u.expect_match(messages, "Copilot model set to: gpt%-4o%-mini")
end
T["model()"]["set with empty args shows Usage"] = function()
child.configure_copilot()
child.lua([[
local model = require("copilot.model")
model.set({})
]])
local messages = child.lua([[
vim.wait(200, function() return false end, 10)
return vim.api.nvim_exec("messages", { output = true }) or ""
]])
u.expect_match(messages, "Usage:")
end
-- get tests
T["model()"]["get shows server default message when no model configured"] = function()
child.configure_copilot()
child.lua([[
local model = require("copilot.model")
model.get()
]])
local messages = child.lua([[
vim.wait(200, function() return false end, 10)
return vim.api.nvim_exec("messages", { output = true }) or ""
]])
u.expect_match(messages, "No model configured %(using server default%)")
end
T["model()"]["get shows current model message when model set"] = function()
child.configure_copilot()
child.lua([[
local model = require("copilot.model")
model.selected_model = "gpt-4o"
model.get()
]])
local messages = child.lua([[
vim.wait(200, function() return false end, 10)
return vim.api.nvim_exec("messages", { output = true }) or ""
]])
u.expect_match(messages, "Current model: gpt%-4o")
end
-- list tests
T["model()"]["list shows completion model names"] = function()
child.configure_copilot()
child.lua([[
local model = require("copilot.model")
model.list()
]])
local messages = child.lua([[
vim.wait(500, function() return false end, 10)
return vim.api.nvim_exec("messages", { output = true }) or ""
]])
u.expect_match(messages, "Available completion models:")
u.expect_match(messages, "GPT 4o")
u.expect_match(messages, "GPT 4o Mini")
end
return T