Skip to content

Commit e39b6e2

Browse files
fix(api): correct HTTP endpoint URLs for live testing
- /api/run-tests → /api/live-testing/run - /api/test-policy → /api/live-testing/policy - /api/toggle-live-testing → /api/live-testing/toggle - Add test state recovery on SSE connect via /api/live-testing/status - Fix decode_event_data call (was referencing nonexistent sse_parser method) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dcd8718 commit e39b6e2

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

lua/sagefs/commands.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function M.register_commands(plugin, helpers)
148148
})
149149
transport.http_json({
150150
method = "POST",
151-
url = helpers.base_url() .. "/api/run-tests",
151+
url = helpers.base_url() .. "/api/live-testing/run",
152152
body = req,
153153
timeout = 10,
154154
callback = function(ok)
@@ -174,7 +174,7 @@ function M.register_commands(plugin, helpers)
174174
local policy = policy_choice:match("^(%S+)")
175175
transport.http_json({
176176
method = "POST",
177-
url = helpers.base_url() .. "/api/test-policy",
177+
url = helpers.base_url() .. "/api/live-testing/policy",
178178
body = { category = category, policy = policy },
179179
timeout = 5,
180180
callback = function(ok)
@@ -319,7 +319,7 @@ function M.register_commands(plugin, helpers)
319319
vim.api.nvim_create_user_command("SageFsToggleTesting", function()
320320
transport.http_json({
321321
method = "POST",
322-
url = helpers.base_url() .. "/api/toggle-live-testing",
322+
url = helpers.base_url() .. "/api/live-testing/toggle",
323323
timeout = 5,
324324
callback = function(ok)
325325
if ok then helpers.notify("Live testing toggled")

lua/sagefs/init.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,26 @@ local function start_sse()
264264
on_connect = function()
265265
M.state = model.set_status(M.state, "connected")
266266
fire_user_event("connected")
267-
-- Test state recovery on (re)connect
268-
-- Note: /api/live-test-status is not an HTTP endpoint — it's only available
269-
-- as an MCP tool (get_live_test_status). Recovery will be enabled once SageFs
270-
-- adds an HTTP endpoint for test status, or sends typed events over SSE.
271-
if M.testing_state.enabled then
272-
fire_user_event("test_recovery_needed")
273-
end
267+
-- Recover test state on (re)connect via HTTP
268+
transport.http_json({
269+
method = "GET",
270+
url = base_url() .. "/api/live-testing/status",
271+
timeout = 3,
272+
callback = function(ok, raw)
273+
if ok and raw and raw ~= "" then
274+
local decode_ok, decoded = pcall(vim.json.decode, raw)
275+
if decode_ok and decoded then
276+
if decoded.Enabled ~= nil then
277+
M.testing_state = testing.set_enabled(M.testing_state, decoded.Enabled)
278+
end
279+
if decoded.Summary then
280+
M.testing_state = testing.handle_test_summary(M.testing_state, decoded.Summary)
281+
end
282+
vim.schedule(function() fire_user_event("test_state") end)
283+
end
284+
end
285+
end,
286+
})
274287
end,
275288
on_disconnect = function()
276289
M.state = model.set_status(M.state, "disconnected")

0 commit comments

Comments
 (0)