openpod

An opencode plugin that spins up a dedicated virtual machine for each session to isolate agent work.
git clone https://unitehenry.com/git/openpod.git
Log | Files | Refs | README

commit 7e2dca2d31c5e4379957668dfe5f520787375040
parent 1bb8a42d5516d3e53aade23ccd4c39cccf470a66
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sun, 25 Oct 2026 01:58:46 +0000

test(context): capture limactl calls with vi.mock in cleanup.test.ts

- Use vi.mock on node:child_process to replace spawnSync with vi.fn()
- Assert exact command, args, and options passed to limactl stop/delete
- No changes to production code
- All tests pass

Diffstat:
Mcontext/cleanup.test.ts | 32+++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/context/cleanup.test.ts b/context/cleanup.test.ts @@ -1,14 +1,29 @@ -import { describe, it, expect, beforeEach, afterEach } from "vitest"; +import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; import * as fs from "node:fs"; import * as path from "node:path"; import * as os from "node:os"; +import { spawnSync } from "node:child_process"; import { initCleanup } from "./cleanup"; +vi.mock("node:child_process", async (importOriginal) => { + const actual = await importOriginal<typeof import("node:child_process")>(); + return { + ...actual, + spawnSync: vi.fn(), + }; +}); + describe("cleanup", () => { let tempRoot: string; beforeEach(() => { + vi.clearAllMocks(); + ( + spawnSync as unknown as { mockReturnValue: (val: unknown) => void } + ).mockReturnValue({ + status: 0, + }); tempRoot = path.join( os.tmpdir(), `openpod-test-${Date.now()}-${Math.random()}`, @@ -44,6 +59,21 @@ describe("cleanup", () => { const cleanup = initCleanup(tempRoot); const sessionID = "test-session"; await cleanup.execute(sessionID); + + expect(spawnSync).toHaveBeenCalledWith( + "limactl", + ["stop", sessionID, "--force"], + { + stdio: "ignore", + }, + ); + expect(spawnSync).toHaveBeenCalledWith( + "limactl", + ["delete", sessionID, "--force"], + { + stdio: "ignore", + }, + ); }); it("removes existing pod directory", async () => {