Skip to content

Commit 0b40947

Browse files
committed
test: update tests for auth and debugger
1 parent 536fb08 commit 0b40947

File tree

7 files changed

+118
-8
lines changed

7 files changed

+118
-8
lines changed

tests/scripts/minimal_init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- Add current directory to 'runtimepath' to be able to use 'lua' files
22
vim.cmd([[let &rtp.=','.getcwd()]])
3+
vim.cmd("set rtp+=deps/osv")
34

45
-- Set up 'mini.test' only when calling headless Neovim (like with `make test`)
56
if #vim.api.nvim_list_uis() == 0 then

tests/test_auth.lua

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
local child = MiniTest.new_child_neovim()
2+
local u = require("tests.utils")
3+
local env = require("tests.env")
4+
5+
local config_path = require("copilot.auth").find_config_path()
6+
local config_path_renamed = config_path .. "_temp_renamed"
7+
8+
local T = MiniTest.new_set({
9+
hooks = {
10+
pre_once = function()
11+
if vim.fn.filereadable("./tests/logs/test_auth.log") == 1 then
12+
vim.fn.delete("./tests/logs/test_auth.log")
13+
end
14+
15+
if vim.fn.isdirectory(config_path) == 1 then
16+
vim.fn.rename(config_path, config_path_renamed)
17+
end
18+
end,
19+
pre_case = function()
20+
child.restart({ "-u", "tests/scripts/minimal_init.lua" })
21+
child.lua("M = require('copilot')")
22+
child.lua("c = require('copilot.client')")
23+
child.lua("s = require('copilot.status')")
24+
child.lua("cmd = require('copilot.command')")
25+
child.lua("a = require('copilot.api')")
26+
child.lua("logger = require('copilot.logger')")
27+
end,
28+
post_once = function()
29+
child.stop()
30+
31+
if vim.fn.isdirectory(config_path_renamed) == 1 then
32+
vim.fn.rename(config_path_renamed, config_path)
33+
end
34+
end,
35+
},
36+
})
37+
38+
T["auth()"] = MiniTest.new_set()
39+
40+
-- TODO: This test currently assumes you are not auth'd, so the token env var cannot be used
41+
T["auth()"]["auth before attaching, should not give error"] = function()
42+
child.lua([[M.setup({
43+
logger = {
44+
file_log_level = vim.log.levels.TRACE,
45+
file = "./tests/logs/test_auth.log",
46+
trace_lsp = "verbose",
47+
log_lsp_messages = true,
48+
trace_lsp_progress = true,
49+
},
50+
})]])
51+
52+
vim.loop.sleep(500)
53+
child.cmd("Copilot auth")
54+
vim.loop.sleep(500)
55+
local messages = child.cmd_capture("messages")
56+
u.expect_match(messages, ".*Online.*Enabled.*")
57+
end
58+
59+
T["auth()"]["auth issue replication"] = function()
60+
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
61+
child.lua([[M.setup({
62+
logger = {
63+
file_log_level = vim.log.levels.TRACE,
64+
file = "./tests/logs/test_auth.log",
65+
trace_lsp = "verbose",
66+
log_lsp_messages = true,
67+
trace_lsp_progress = true,
68+
},
69+
})]])
70+
71+
vim.loop.sleep(500)
72+
child.cmd("Copilot auth")
73+
vim.loop.sleep(500)
74+
child.cmd("Copilot status")
75+
local messages = child.cmd_capture("messages")
76+
u.expect_match(messages, ".*Online.*Authenticated.*")
77+
end
78+
79+
return T

tests/test_base_to_organize.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local eq = MiniTest.expect.equality
22
local child = MiniTest.new_child_neovim()
3-
-- local env = require("tests.env")
3+
local env = require("tests.env")
4+
local utils_debug = require("tests.utils_debug")
45

56
local T = MiniTest.new_set({
67
hooks = {
@@ -9,13 +10,18 @@ local T = MiniTest.new_set({
910
child.lua([[M = require('copilot')]])
1011
child.lua([[c = require('copilot.command')]])
1112
child.lua([[s = require('copilot.status')]])
12-
-- child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
13+
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
14+
utils_debug.launch_lua_debugee(child)
1315
end,
1416
post_once = child.stop,
1517
},
1618
})
1719

20+
-- TODO: find a way for autocmd or something
1821
local function run_setup()
22+
-- utils_debug.attach_to_debugee()
23+
vim.loop.sleep(10000)
24+
-- vim.wait(0)
1925
child.lua([[M.setup({
2026
logger = {
2127
file_log_level = vim.log.levels.TRACE,

tests/test_client.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local child = MiniTest.new_child_neovim()
22
local u = require("tests.utils")
3-
-- local env = require("tests.env")
3+
local env = require("tests.env")
44

55
local T = MiniTest.new_set({
66
hooks = {
@@ -18,7 +18,7 @@ local T = MiniTest.new_set({
1818
child.lua([[a = require('copilot.api')]])
1919
child.lua("logger = require('copilot.logger')")
2020
-- child.lua([[require("osv").launch({ port = 8086 })]])
21-
-- child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
21+
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
2222
end,
2323
post_once = child.stop,
2424
},

tests/test_panel.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local eq = MiniTest.expect.equality
22
local child = MiniTest.new_child_neovim()
3-
-- local env = require("tests.env")
3+
local env = require("tests.env")
44

55
local T = MiniTest.new_set({
66
hooks = {
@@ -16,7 +16,7 @@ local T = MiniTest.new_set({
1616
child.lua("cmd = require('copilot.command')")
1717
child.lua("p = require('copilot.panel')")
1818
-- child.lua([[require("osv").launch({ port = 8086 })]])
19-
-- child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
19+
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
2020
end,
2121
post_once = child.stop,
2222
},

tests/test_suggestion.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local reference_screenshot = MiniTest.expect.reference_screenshot
22
local child = MiniTest.new_child_neovim()
3-
-- local env = require("tests.env")
3+
local env = require("tests.env")
44

55
local T = MiniTest.new_set({
66
hooks = {
@@ -15,7 +15,7 @@ local T = MiniTest.new_set({
1515
child.lua("M = require('copilot')")
1616
child.lua("cmd = require('copilot.command')")
1717
-- child.lua([[require("osv").launch({ port = 8086 })]])
18-
-- child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
18+
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
1919
end,
2020
post_once = child.stop,
2121
},

tests/utils_debug.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local M = {}
2+
3+
function M.launch_lua_debugee(child)
4+
-- child.lua([[local dap = require("nvim-dap")
5+
-- dap.configurations.lua = {
6+
-- {
7+
-- type = 'nlua',
8+
-- request = 'attach',
9+
-- name = "Attach to running Neovim instance",
10+
-- }
11+
-- }
12+
--
13+
-- dap.adapters.nlua = function(callback, config)
14+
-- callback({ type = 'server', host = config.host or "127.0.0.1", port = config.port or 8086 })
15+
-- end
16+
-- ]])
17+
child.lua([[require("osv").launch({ port = 8086 })]])
18+
end
19+
20+
function M.attach_to_debugee()
21+
require("dap").continue()
22+
end
23+
24+
return M

0 commit comments

Comments
 (0)