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 6b16976483af10da875c26a160eea3931da6dc4f
parent 5628df7f9d1deccf01e2a9448b25a6407584485d
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sun, 25 Oct 2026 01:41:26 +0000

test(command): override cleanup.execute to spy calls without limactl

- After real init(), override ctx.cleanup.execute with vi.fn() in beforeEach
- Assert .toHaveBeenCalledWith for session IDs (and .log due to side effects)
- Prevents any real limactl spawn/delete during unit tests
- Tests still pass and verify removal via final fs.rmSync in clear

Diffstat:
Mcommand/clear.test.ts | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/command/clear.test.ts b/command/clear.test.ts @@ -1,4 +1,12 @@ -import { describe, it, expect, beforeAll, beforeEach, afterEach } from "vitest"; +import { + describe, + it, + expect, + beforeAll, + beforeEach, + afterEach, + vi, +} from "vitest"; import * as fs from "node:fs"; import * as path from "node:path"; @@ -8,6 +16,7 @@ import { clear } from "./clear"; describe("clear", () => { let ctx: OpenpodContext; + let cleanupExecute: ReturnType<typeof vi.fn>; beforeAll(async () => { ctx = await init(); @@ -17,6 +26,8 @@ describe("clear", () => { if (fs.existsSync(ctx.openpodRoot)) { fs.rmSync(ctx.openpodRoot, { recursive: true, force: true }); } + cleanupExecute = vi.fn(); + ctx.cleanup = { execute: cleanupExecute }; }); afterEach(() => { @@ -30,6 +41,7 @@ describe("clear", () => { expect(fs.existsSync(ctx.openpodRoot)).toBe(true); const entries = fs.readdirSync(ctx.openpodRoot); expect(entries).toContain(".log"); + expect(cleanupExecute).toHaveBeenCalledWith(".log"); }); it("removes session directories and leaves only .log after cleanup", async () => { @@ -46,6 +58,9 @@ describe("clear", () => { expect(fs.existsSync(ctx.openpodRoot)).toBe(true); const entries = fs.readdirSync(ctx.openpodRoot); expect(entries).toEqual([".log"]); + expect(cleanupExecute).toHaveBeenCalledWith("session-abc"); + expect(cleanupExecute).toHaveBeenCalledWith("session-xyz"); + expect(cleanupExecute).toHaveBeenCalledWith(".log"); }); it("ignores non-directory entries and cleans sessions", async () => { @@ -60,6 +75,8 @@ describe("clear", () => { expect(fs.existsSync(ctx.openpodRoot)).toBe(true); const entries = fs.readdirSync(ctx.openpodRoot); expect(entries).toEqual([".log"]); + expect(cleanupExecute).toHaveBeenCalledWith("real-session"); + expect(cleanupExecute).toHaveBeenCalledWith(".log"); }); it("handles errors gracefully without throwing", async () => {