commit 02d40902d3017dc80c0f99369cd3b6667862ab1f
parent c8242dc0855c1b6158273ddaac2d2fffeeb65564
Author: Henry Unite <unitehenry@gmail.com>
Date: Sat, 14 Nov 2026 19:07:08 +0000
test(opencode): remove lima instance and pod on session delete
Add an e2e test that prompts to create a pod, deletes the session through the SDK, and asserts the lima instance and openpod directory are removed.
Diffstat:
2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -22,5 +22,5 @@
- [x] Opencode shell command runs in lima instance (using opencode shell api)
- [x] Opencode `clear-openpod` command is registered
- [x] Create session -> prompt -> verify pod -> delete lima instance -> re-prompt -> verify pod
-- [ ] Opencode delete session removes lima instance and openpod directory
+- [x] Opencode delete session removes lima instance and openpod directory
- [ ] Opencode `clear-openpod` removes directories, lima instances, and deletes openpod sessions
diff --git a/opencode.test.ts b/opencode.test.ts
@@ -286,6 +286,82 @@ describe("opencode", () => {
);
it(
+ "should remove lima instance and openpod directory when the session is deleted",
+ { timeout: 180_000 },
+ async () => {
+ // Create a temp git repo with a remote origin
+ const tempDir = await mkdtemp(
+ path.join(os.tmpdir(), "openpod-e2e-delete-"),
+ );
+ const bareDir = await mkdtemp(
+ path.join(os.tmpdir(), "openpod-bare-delete-"),
+ );
+ execSync("git init --bare", { cwd: bareDir, stdio: "ignore" });
+ execSync("git init", { cwd: tempDir, stdio: "ignore" });
+ execSync(`git remote add origin ${bareDir}`, {
+ cwd: tempDir,
+ stdio: "ignore",
+ });
+
+ function limaInstanceExists(name: string): boolean {
+ try {
+ execSync(`limactl list ${name}`, { stdio: "ignore" });
+ return true;
+ } catch {
+ return false;
+ }
+ }
+
+ const session = await opencode.sessions.create();
+ const sessionDir = path.join(openpodRoot, session.id);
+
+ await opencode.sessions.move({
+ sessionID: session.id,
+ directory: tempDir,
+ });
+
+ // Wait for the move to take effect
+ await new Promise((r) => setTimeout(r, 200));
+
+ // Prompt so the handler clones the project and creates the lima instance
+ await opencode.sessions.prompt({
+ sessionID: session.id,
+ text: "hello",
+ });
+
+ expect(fs.existsSync(sessionDir)).toBe(true);
+ expect(limaInstanceExists(session.id)).toBe(true);
+
+ // Wait for the prompt hook's async session.move() to land the session
+ // in the openpod directory before deleting it.
+ for (let i = 0; i < 50; i++) {
+ const current = await opencode.sessions.get({ sessionID: session.id });
+ if (current.location?.directory === sessionDir) break;
+ await new Promise((r) => setTimeout(r, 100));
+ }
+
+ // Delete the session. The plugin's session.deleted handler should clean
+ // up the lima instance and the openpod directory.
+ await opencode.sessions.remove({ sessionID: session.id });
+
+ let limaGone = false;
+ let dirGone = false;
+ for (let i = 0; i < 100; i++) {
+ limaGone = !limaInstanceExists(session.id);
+ dirGone = !fs.existsSync(sessionDir);
+ if (limaGone && dirGone) break;
+ await new Promise((r) => setTimeout(r, 100));
+ }
+
+ expect(limaGone).toBe(true);
+ expect(dirGone).toBe(true);
+
+ // Clean up
+ await cleanup(session.id, [sessionDir, tempDir, bareDir]);
+ },
+ );
+
+ it(
"runs shell commands within the session lima instance",
{ timeout: 120_000 },
async () => {