From f2935ca3ec3b830f191872598536129cae08e3ce Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 13 May 2026 00:41:53 +0100 Subject: [PATCH] test: dedupe sandbox manage mock reads --- src/agents/sandbox/manage.test.ts | 49 +++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/agents/sandbox/manage.test.ts b/src/agents/sandbox/manage.test.ts index d15ca5b13293..3acbee867df8 100644 --- a/src/agents/sandbox/manage.test.ts +++ b/src/agents/sandbox/manage.test.ts @@ -50,6 +50,40 @@ beforeAll(async () => { ({ listSandboxBrowsers, removeSandboxBrowserContainer } = await import("./manage.js")); }); +function firstDescribeRuntimeInput(): { agentId?: string; entry?: { configLabelKind?: string } } { + const input = backendMocks.describeRuntime.mock.calls[0]?.[0] as + | { agentId?: string; entry?: { configLabelKind?: string } } + | undefined; + if (!input) { + throw new Error("expected describe runtime input"); + } + return input; +} + +function firstRemoveRuntimeInput(): { + entry?: { + containerName?: string; + configLabelKind?: string; + runtimeLabel?: string; + backendId?: string; + }; +} { + const input = backendMocks.removeRuntime.mock.calls[0]?.[0] as + | { + entry?: { + containerName?: string; + configLabelKind?: string; + runtimeLabel?: string; + backendId?: string; + }; + } + | undefined; + if (!input) { + throw new Error("expected remove runtime input"); + } + return input; +} + describe("listSandboxBrowsers", () => { beforeEach(async () => { configMocks.getRuntimeConfig.mockReset(); @@ -101,9 +135,7 @@ describe("listSandboxBrowsers", () => { it("compares browser runtimes against sandbox.browser.image", async () => { const results = await listSandboxBrowsers(); - const describeInput = backendMocks.describeRuntime.mock.calls.at(0)?.[0] as - | { agentId?: string; entry?: { configLabelKind?: string } } - | undefined; + const describeInput = firstDescribeRuntimeInput(); expect(describeInput?.agentId).toBe("coder"); expect(describeInput?.entry?.configLabelKind).toBe("BrowserImage"); expect(results).toHaveLength(1); @@ -115,16 +147,7 @@ describe("listSandboxBrowsers", () => { it("removes browser runtimes with BrowserImage config label kind", async () => { await removeSandboxBrowserContainer("browser-1"); - const removeInput = backendMocks.removeRuntime.mock.calls.at(0)?.[0] as - | { - entry?: { - containerName?: string; - configLabelKind?: string; - runtimeLabel?: string; - backendId?: string; - }; - } - | undefined; + const removeInput = firstRemoveRuntimeInput(); expect(removeInput?.entry?.containerName).toBe("browser-1"); expect(removeInput?.entry?.configLabelKind).toBe("BrowserImage"); expect(removeInput?.entry?.runtimeLabel).toBe("browser-1");