hephaestus/heph.nvim/tests/e2e/managed_daemon_spec.lua

47 lines
1.8 KiB
Lua
Raw Normal View History

-- The plugin is connect-only (tech-spec §8, [[design]] §4): it never spawns a
-- daemon — it connects to one run as an OS service (`heph daemon start`). These
-- specs cover connecting to a running daemon, a clean failure when none is
-- running, and reconnecting after the daemon is restarted.
local h = require("e2e.helpers")
describe("connect-only daemon", function()
it("connects to a running daemon and works", function()
local ctx = h.start() -- harness starts a real daemon; binds the plugin to it
require("heph").setup({ socket = ctx.sock, keymaps = false })
assert.is_truthy(require("heph.rpc").call("health", {}))
h.stop(ctx)
end)
it("fails cleanly when no daemon is running (never spawns one)", function()
local t = h.tmp() -- temp socket path with nothing serving it
require("heph.rpc").setup(t.sock)
-- A call must fail loudly (connection error), not hang or spawn a daemon.
local ok = pcall(require("heph.rpc").call, "health", {})
assert.is_false(ok, "expected a connection failure with no daemon running")
pcall(function()
require("heph.rpc").close()
end)
t.rm()
end)
it("reconnects after the daemon is restarted under it", function()
local ctx = h.start()
require("heph").setup({ socket = ctx.sock, keymaps = false })
require("heph.rpc").call("health", {})
-- Kill the daemon, then start a fresh one on the SAME socket (as
-- `heph daemon restart` would). The next call should reconnect.
ctx.daemon.handle:kill("sigterm")
vim.wait(2000, function()
return ctx.exited.done
end, 20)
pcall(function()
vim.uv.fs_unlink(ctx.sock)
end)
local ctx2 = h.start_on(ctx.dir, ctx.sock, ctx.db)
assert.is_truthy(require("heph.rpc").call("health", {}))
h.stop(ctx2)
end)
end)