@@ -46,17 +46,39 @@ describe('opencode.opencode_server', function()
4646
4747 it (' shutdown resolves shutdown_promise and clears fields' , function ()
4848 local server = OpencodeServer .new ()
49- server .job = { pid = 2 , kill = function () end }
50- server .url = ' http://x'
51- server .handle = 2
49+ local exit_callback
50+
51+ -- Mock vim.system to capture the exit callback
52+ vim .system = function (cmd , opts , on_exit )
53+ exit_callback = on_exit
54+ return { pid = 2 , kill = function () end }
55+ end
56+
57+ -- Spawn the server so the exit callback is set up
58+ server :spawn ({
59+ cwd = ' .' ,
60+ on_ready = function () end ,
61+ on_error = function () end ,
62+ on_exit = function () end ,
63+ })
64+
5265 local resolved = false
5366 server :get_shutdown_promise ():and_then (function ()
5467 resolved = true
5568 end )
69+
70+ -- Call shutdown (sends SIGTERM)
5671 server :shutdown ()
57- vim .wait (50 , function ()
72+
73+ -- Simulate the process exiting by calling the exit callback
74+ vim .schedule (function ()
75+ exit_callback ({ code = 0 , signal = 0 })
76+ end )
77+
78+ vim .wait (100 , function ()
5879 return resolved
5980 end )
81+
6082 assert .is_true (resolved )
6183 assert .is_nil (server .job )
6284 assert .is_nil (server .url )
0 commit comments