commit 38bdceb5bd07e6a61ad439451c2044822f702edb
parent efedd331c3016f2c5161496cfa03785c59b9c0a0
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 25 Oct 2026 02:19:23 +0000
fix(test): isolate openpodRoot with per-test temps while using real init()
- Call actual init() in beforeAll (baseCtx) for both handle and clear tests
- In beforeEach, create unique temp dir (like context/*.test.ts), set ctx = {...baseCtx, openpodRoot: tempRoot}
- Override only ctx.cleanup.execute = vi.fn() (handle) or reassign (clear) per prior requests
- Update clear.test expectations: root no longer exists after clear() (matches impl)
- Prevents ENOTEMPTY races and missed calls when vitest runs files in parallel against shared ~/.local/share/openpod
- All tests pass, format/lint clean
Diffstat:
2 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/command/clear.test.ts b/command/clear.test.ts
@@ -9,6 +9,7 @@ import {
} from "vitest";
import * as fs from "node:fs";
import * as path from "node:path";
+import * as os from "node:os";
import type { OpenpodContext } from "../context";
import { init } from "../context";
@@ -17,15 +18,26 @@ import { clear } from "./clear";
describe("clear", () => {
let ctx: OpenpodContext;
let cleanupExecute: ReturnType<typeof vi.fn>;
+ let baseCtx: OpenpodContext;
beforeAll(async () => {
- ctx = await init();
+ baseCtx = await init();
});
beforeEach(() => {
- if (fs.existsSync(ctx.openpodRoot)) {
- fs.rmSync(ctx.openpodRoot, { recursive: true, force: true });
+ const tempRoot = path.join(
+ os.tmpdir(),
+ `openpod-test-${Date.now()}-${Math.random()}`,
+ );
+ if (fs.existsSync(tempRoot)) {
+ fs.rmSync(tempRoot, { recursive: true, force: true });
}
+ fs.mkdirSync(tempRoot, { recursive: true });
+
+ ctx = {
+ ...baseCtx,
+ openpodRoot: tempRoot,
+ };
cleanupExecute = vi.fn();
ctx.cleanup = { execute: cleanupExecute };
});
@@ -46,7 +58,7 @@ describe("clear", () => {
await clear(ctx);
- expect(fs.existsSync(ctx.openpodRoot)).toBe(true);
+ expect(fs.existsSync(ctx.openpodRoot)).toBe(false);
expect(fs.existsSync(path.join(ctx.openpodRoot, "session-abc"))).toBe(
false,
);
@@ -66,7 +78,7 @@ describe("clear", () => {
await clear(ctx);
- expect(fs.existsSync(ctx.openpodRoot)).toBe(true);
+ expect(fs.existsSync(ctx.openpodRoot)).toBe(false);
expect(fs.existsSync(path.join(ctx.openpodRoot, "real-session"))).toBe(
false,
);
diff --git a/prompt/handle.test.ts b/prompt/handle.test.ts
@@ -9,6 +9,7 @@ import {
} 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 type { OpenpodContext } from "../context";
@@ -26,9 +27,10 @@ vi.mock("node:child_process", async (importOriginal) => {
describe("handle", () => {
let mockMove: ReturnType<typeof vi.fn>;
let ctx: OpenpodContext;
+ let baseCtx: OpenpodContext;
beforeAll(async () => {
- ctx = await init();
+ baseCtx = await init();
});
beforeEach(() => {
@@ -38,10 +40,20 @@ describe("handle", () => {
).mockReturnValue({
status: 0,
});
- if (fs.existsSync(ctx.openpodRoot)) {
- fs.rmSync(ctx.openpodRoot, { recursive: true, force: true });
+
+ const tempRoot = path.join(
+ os.tmpdir(),
+ `openpod-test-${Date.now()}-${Math.random()}`,
+ );
+ if (fs.existsSync(tempRoot)) {
+ fs.rmSync(tempRoot, { recursive: true, force: true });
}
+ fs.mkdirSync(tempRoot, { recursive: true });
+ ctx = {
+ ...baseCtx,
+ openpodRoot: tempRoot,
+ };
ctx.cleanup.execute = vi.fn();
mockMove = vi.fn();
});