From 2a7dae9a13f7e2ec87c43fcd0c9d55d30b4f1bb4 Mon Sep 17 00:00:00 2001 From: underwaterresearch Date: Sat, 4 Apr 2026 10:27:33 +0000 Subject: [PATCH] test: cover gateway url status policy --- backend-api/__tests__/agents.test.js | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/backend-api/__tests__/agents.test.js b/backend-api/__tests__/agents.test.js index 7e3241c..179f405 100644 --- a/backend-api/__tests__/agents.test.js +++ b/backend-api/__tests__/agents.test.js @@ -214,6 +214,26 @@ describe("GET /agents/:id/gateway-url", () => { delete process.env.GATEWAY_HOST; }); + it("allows gateway url lookups for warning agents so degraded control-plane recovery still works", async () => { + mockDb.query.mockResolvedValueOnce({ + rows: [{ + id: "a-warning-gateway", + container_id: "container-warning-gateway", + gateway_host_port: 19123, + user_id: "user-1", + status: "warning", + }], + }); + + const res = await auth(request(app).get("/agents/a-warning-gateway/gateway-url")); + + expect(res.status).toBe(200); + expect(res.body).toEqual({ + url: "http://localhost:19123", + port: 19123, + }); + }); + it("rejects gateway url lookups for stopped agents so stale ports are not exposed", async () => { mockDb.query.mockResolvedValueOnce({ rows: [{ @@ -230,6 +250,23 @@ describe("GET /agents/:id/gateway-url", () => { expect(res.status).toBe(409); expect(res.body.error).toMatch(/only available while running/i); }); + + it("rejects gateway url lookups for error agents so failed control-plane state stays closed", async () => { + mockDb.query.mockResolvedValueOnce({ + rows: [{ + id: "a-error-gateway", + container_id: "container-error-gateway", + gateway_host_port: 19123, + user_id: "user-1", + status: "error", + }], + }); + + const res = await auth(request(app).get("/agents/a-error-gateway/gateway-url")); + + expect(res.status).toBe(409); + expect(res.body.error).toMatch(/only available while running/i); + }); }); describe("POST /agents/deploy", () => {