Skip to content

Commit 02ff5df

Browse files
committed
ci: initial release for automated tests
1 parent ccb1336 commit 02ff5df

File tree

10 files changed

+137
-35
lines changed

10 files changed

+137
-35
lines changed

.github/workflows/ci.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
unit_tests:
7+
name: unit tests
8+
if: github.repository == 'AntoineGS/copilot.lua'
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-latest, windows-2025]
14+
rev: [nightly, v0.10.4, v0.11.0]
15+
include:
16+
- os: ubuntu-24.04
17+
install-rg: sudo apt-get update && sudo apt-get install -y nodejs curl
18+
- os: ubuntu-24.04-arm
19+
install-rg: sudo apt-get update && sudo apt-get install -y nodejs curl
20+
- os: macos-latest
21+
install-rg: brew update && brew install node curl
22+
- os: windows-2025
23+
install-rg: choco install nodejs-lts curl
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- uses: rhysd/action-setup-vim@v1
29+
with:
30+
neovim: true
31+
version: ${{ matrix.rev }}
32+
33+
- name: Prepare
34+
run: |
35+
${{ matrix.install-rg }}
36+
mkdir deps
37+
mkdir ./tests/logs
38+
git clone --filter=blob:none https://github.com/echasnovski/mini.nvim deps/mini.nvim
39+
mv ./tests/env.lua.ci ./tests/env.lua
40+
41+
- name: Run tests
42+
env:
43+
GH_COPILOT_TOKEN: ${{ secrets.GH_COPILOT_TOKEN }}
44+
run: |
45+
nvim --version
46+
make test

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Run all test files
22
# test: deps/mini.nvim
33
test:
4-
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run()"
4+
nvim --headless --noplugin -u ./tests/scripts/minimal_init.lua -c "lua MiniTest.run()"
55

66
# Run test from file at `$FILE` environment variable
77
test_file: deps/mini.nvim
8-
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run_file('$(FILE)')"
8+
nvim --headless --noplugin -u ./tests/scripts/minimal_init.lua -c "lua MiniTest.run_file('$(FILE)')"
99

1010
# Download 'mini.nvim' to use its 'mini.test' testing module
1111
# deps/mini.nvim:

lua/copilot/auth/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ function M.find_config_path()
145145
config = vim.fn.expand("~/.config")
146146
if vim.fn.isdirectory(config) > 0 then
147147
return config
148-
else
149-
logger.error("could not find config path")
150148
end
151149
end
150+
151+
logger.error("could not find config path")
152152
end
153153

154154
M.get_creds = function()

tests/child_helper.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ function M.new_child_neovim(test_name)
6060
function child.run_pre_case()
6161
child.reset_config()
6262
child.restart({ "-u", "tests/scripts/minimal_init.lua" })
63-
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
63+
if env.COPILOT_TOKEN and env.COPILOT_TOKEN ~= "" then
64+
child.fn.setenv("GITHUB_COPILOT_TOKEN", env.COPILOT_TOKEN)
65+
end
6466
child.setup_and_wait_for_debugger()
67+
child.lua("M = require('copilot')")
6568
end
6669

6770
function child.configure_copilot()

tests/env.lua.ci

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local M = {
2+
COPILOT_TOKEN = '',
3+
}
4+
5+
return M

tests/test_auth.lua

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ local child_helper = require("tests.child_helper")
22
local child = child_helper.new_child_neovim("test_auth")
33
local u = require("tests.utils")
44

5-
local config_path = require("copilot.auth").find_config_path()
5+
local config_path = require("copilot.auth").find_config_path() .. "/github-copilot"
66
local config_path_renamed = config_path .. "_temp_renamed"
77

8+
--TODO: find a way to not mess with folders
89
local T = MiniTest.new_set({
910
hooks = {
1011
pre_once = function()
@@ -14,13 +15,6 @@ local T = MiniTest.new_set({
1415
end,
1516
pre_case = function()
1617
child.run_pre_case()
17-
child.lua("M = require('copilot')")
18-
child.lua("c = require('copilot.client')")
19-
child.lua("s = require('copilot.status')")
20-
child.lua("cmd = require('copilot.command')")
21-
child.lua("a = require('copilot.api')")
22-
child.lua("logger = require('copilot.logger')")
23-
child.fn.setenv("GITHUB_COPILOT_TOKEN", vim.NIL)
2418
end,
2519
post_once = function()
2620
child.stop()
@@ -34,22 +28,59 @@ local T = MiniTest.new_set({
3428

3529
T["auth()"] = MiniTest.new_set()
3630

37-
-- TODO: callback for this too
3831
T["auth()"]["auth before attaching, should not give error"] = function()
3932
child.configure_copilot()
4033
child.cmd("Copilot auth")
41-
vim.loop.sleep(3000)
42-
local messages = child.cmd_capture("messages")
34+
35+
local messages = child.lua([[
36+
local messages = ""
37+
local function has_passed()
38+
messages = vim.api.nvim_exec("messages", { output = true }) or ""
39+
return string.find(messages, ".*Authenticated as GitHub user.*") ~= nil
40+
end
41+
42+
vim.wait(30000, function()
43+
return has_passed()
44+
end, 50)
45+
46+
return messages
47+
]])
48+
4349
u.expect_match(messages, ".*Authenticated as GitHub user.*")
4450
end
4551

4652
T["auth()"]["auth issue replication"] = function()
4753
child.configure_copilot()
4854
child.cmd("Copilot auth")
49-
vim.loop.sleep(2000)
55+
56+
child.lua([[
57+
local messages = ""
58+
local function has_passed()
59+
messages = vim.api.nvim_exec("messages", { output = true }) or ""
60+
return string.find(messages, ".*Authenticated as GitHub user.*") ~= nil
61+
end
62+
63+
vim.wait(30000, function()
64+
return has_passed()
65+
end, 50)
66+
]])
67+
5068
child.cmd("Copilot status")
51-
vim.loop.sleep(500)
52-
local messages = child.cmd_capture("messages")
69+
70+
local messages = child.lua([[
71+
local messages = ""
72+
local function has_passed()
73+
messages = vim.api.nvim_exec("messages", { output = true }) or ""
74+
return string.find(messages, ".*Online.*Enabled.*") ~= nil
75+
end
76+
77+
vim.wait(30000, function()
78+
return has_passed()
79+
end, 50)
80+
81+
return messages
82+
]])
83+
5384
u.expect_match(messages, ".*Online.*Enabled.*")
5485
end
5586

tests/test_base_to_organize.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local T = MiniTest.new_set({
66
hooks = {
77
pre_case = function()
88
child.run_pre_case()
9-
child.lua([[M = require('copilot')]])
109
child.lua([[s = require('copilot.status')]])
1110
child.lua([[a = require('copilot.api')]])
1211
end,

tests/test_client.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ local T = MiniTest.new_set({
77
pre_once = function() end,
88
pre_case = function()
99
child.run_pre_case()
10-
child.lua("M = require('copilot')")
1110
child.lua("s = require('copilot.status')")
1211
child.lua("c = require('copilot.client')")
1312
end,
@@ -30,8 +29,23 @@ T["client()"] = MiniTest.new_set()
3029
T["client()"]["status info"] = function()
3130
child.configure_copilot()
3231
child.cmd("Copilot status")
33-
vim.loop.sleep(500)
34-
local messages = child.cmd_capture("messages")
32+
33+
local messages = child.lua([[
34+
local messages = ""
35+
local function has_passed()
36+
messages = vim.api.nvim_exec("messages", { output = true }) or ""
37+
if messages:find(".*Online.*Enabled.*") then
38+
return true
39+
end
40+
end
41+
42+
vim.wait(30000, function()
43+
return has_passed()
44+
end, 50)
45+
46+
return messages
47+
]])
48+
3549
u.expect_match(messages, ".*Online.*Enabled.*")
3650
end
3751

tests/test_panel.lua

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ local T = MiniTest.new_set({
88
pre_case = function()
99
child.run_pre_case()
1010
child.bo.readonly = false
11-
child.lua("M = require('copilot')")
1211
child.lua("p = require('copilot.panel')")
1312
end,
1413
post_once = child.stop,
@@ -17,7 +16,6 @@ local T = MiniTest.new_set({
1716

1817
T["panel()"] = MiniTest.new_set()
1918

20-
-- This test can fail if the LSP is taking more time than usual and re-running it passes
2119
T["panel()"]["panel suggestions works"] = function()
2220
child.o.lines, child.o.columns = 30, 100
2321
child.config.panel = child.config.panel .. "auto_refresh = true,"
@@ -26,16 +24,23 @@ T["panel()"]["panel suggestions works"] = function()
2624
child.type_keys("i123", "<Esc>", "o456", "<Esc>", "o7")
2725
child.lua("p.toggle()")
2826

29-
local i = 0
30-
local lines = ""
31-
while i < 50 do
32-
vim.loop.sleep(200)
33-
child.lua("vim.wait(0)")
34-
lines = child.api.nvim_buf_get_lines(2, 4, 5, false)
35-
if lines[1] == "789" then
36-
break
27+
local lines = child.lua([[
28+
local messages = ""
29+
local function suggestion_is_visible()
30+
lines = vim.api.nvim_buf_get_lines(2, 4, 5, false)
31+
return lines[1] == "789" or lines[1] == "789\r"
3732
end
38-
i = i + 1
33+
34+
vim.wait(30000, function()
35+
return suggestion_is_visible()
36+
end, 50)
37+
38+
return lines
39+
]])
40+
41+
-- For Windows, on some shells not all
42+
if lines[1] == "789\r" then
43+
lines[1] = "789"
3944
end
4045

4146
eq(lines[1], "789")

tests/test_suggestion.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ local T = MiniTest.new_set({
88
pre_case = function()
99
child.run_pre_case()
1010
child.bo.readonly = false
11-
child.lua("M = require('copilot')")
1211
end,
1312
post_once = child.stop,
1413
},

0 commit comments

Comments
 (0)