2026-06-02 21:21:28 -07:00
|
|
|
-- 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.
|
2026-06-02 09:32:32 -07:00
|
|
|
|
|
|
|
|
local h = require("e2e.helpers")
|
|
|
|
|
|
2026-06-02 21:21:28 -07:00
|
|
|
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)
|
2026-06-02 09:32:32 -07:00
|
|
|
end)
|
2026-06-02 21:21:28 -07:00
|
|
|
|
|
|
|
|
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")
|
2026-06-02 09:32:32 -07:00
|
|
|
pcall(function()
|
|
|
|
|
require("heph.rpc").close()
|
|
|
|
|
end)
|
|
|
|
|
t.rm()
|
|
|
|
|
end)
|
|
|
|
|
|
2026-06-02 21:21:28 -07:00
|
|
|
it("reconnects after the daemon is restarted under it", function()
|
|
|
|
|
local ctx = h.start()
|
|
|
|
|
require("heph").setup({ socket = ctx.sock, keymaps = false })
|
2026-06-02 09:32:32 -07:00
|
|
|
require("heph.rpc").call("health", {})
|
|
|
|
|
|
2026-06-02 21:21:28 -07:00
|
|
|
-- 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")
|
2026-06-02 09:32:32 -07:00
|
|
|
vim.wait(2000, function()
|
2026-06-02 21:21:28 -07:00
|
|
|
return ctx.exited.done
|
2026-06-02 09:32:32 -07:00
|
|
|
end, 20)
|
2026-06-02 21:21:28 -07:00
|
|
|
pcall(function()
|
|
|
|
|
vim.uv.fs_unlink(ctx.sock)
|
|
|
|
|
end)
|
2026-06-02 09:32:32 -07:00
|
|
|
|
2026-06-02 21:21:28 -07:00
|
|
|
local ctx2 = h.start_on(ctx.dir, ctx.sock, ctx.db)
|
2026-06-02 10:29:58 -07:00
|
|
|
assert.is_truthy(require("heph.rpc").call("health", {}))
|
2026-06-02 21:21:28 -07:00
|
|
|
h.stop(ctx2)
|
2026-06-02 09:32:32 -07:00
|
|
|
end)
|
|
|
|
|
end)
|