commit 1bb8a42d5516d3e53aade23ccd4c39cccf470a66
parent f311003c4831f7dfd2b2a2c9517ed740c26432c1
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 25 Oct 2026 01:51:52 +0000
test(context): refactor cleanup.test.ts to not create logger
- Remove Logger import, mock logger, and logSpy
- Call initCleanup(tempRoot) without logger (now optional)
- Remove all logSpy assertions
- Simplify/rename tests that were only testing logs
- 5 tests remain, focused on behavior
Diffstat:
1 file changed, 8 insertions(+), 48 deletions(-)
diff --git a/context/cleanup.test.ts b/context/cleanup.test.ts
@@ -1,15 +1,12 @@
-import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
+import { describe, it, expect, beforeEach, afterEach } from "vitest";
import * as fs from "node:fs";
import * as path from "node:path";
import * as os from "node:os";
-import type { Logger } from "./logger";
import { initCleanup } from "./cleanup";
describe("cleanup", () => {
let tempRoot: string;
- let logger: Logger;
- let logSpy: ReturnType<typeof vi.fn>;
beforeEach(() => {
tempRoot = path.join(
@@ -20,9 +17,6 @@ describe("cleanup", () => {
fs.rmSync(tempRoot, { recursive: true, force: true });
}
fs.mkdirSync(tempRoot, { recursive: true });
-
- logSpy = vi.fn();
- logger = { log: logSpy };
});
afterEach(() => {
@@ -32,36 +26,24 @@ describe("cleanup", () => {
});
it("returns a cleanup with execute function", () => {
- const cleanup = initCleanup(tempRoot, logger);
+ const cleanup = initCleanup(tempRoot);
expect(cleanup).toHaveProperty("execute");
expect(typeof cleanup.execute).toBe("function");
});
it("returns early for invalid sessionID", async () => {
- const cleanup = initCleanup(tempRoot, logger);
+ const cleanup = initCleanup(tempRoot);
await cleanup.execute("");
// @ts-expect-error testing runtime guard
await cleanup.execute(null);
// @ts-expect-error testing runtime guard
await cleanup.execute(undefined);
-
- expect(logSpy).not.toHaveBeenCalled();
});
- it("logs starting and attempts lima stop/delete", async () => {
- const cleanup = initCleanup(tempRoot, logger);
+ it("attempts lima stop/delete", async () => {
+ const cleanup = initCleanup(tempRoot);
const sessionID = "test-session";
await cleanup.execute(sessionID);
-
- expect(logSpy).toHaveBeenCalledWith(`[cleanup] starting for ${sessionID}`);
- expect(logSpy).toHaveBeenCalledWith(
- `[cleanup] stopped ${sessionID} (if running)`,
- );
- expect(logSpy).toHaveBeenCalledWith(
- expect.stringContaining(
- `[cleanup] limactl delete ${sessionID} exited with`,
- ),
- );
});
it("removes existing pod directory", async () => {
@@ -70,41 +52,19 @@ describe("cleanup", () => {
fs.mkdirSync(podDir, { recursive: true });
fs.writeFileSync(path.join(podDir, "file.txt"), "data");
- const cleanup = initCleanup(tempRoot, logger);
+ const cleanup = initCleanup(tempRoot);
await cleanup.execute(sessionID);
expect(fs.existsSync(podDir)).toBe(false);
- expect(logSpy).toHaveBeenCalledWith(
- `[cleanup] removed directory ${podDir}`,
- );
});
- it("logs when pod directory does not exist", async () => {
+ it("handles pod directory that does not exist", async () => {
const sessionID = "no-dir";
const podDir = path.join(tempRoot, sessionID);
- const cleanup = initCleanup(tempRoot, logger);
+ const cleanup = initCleanup(tempRoot);
await cleanup.execute(sessionID);
expect(fs.existsSync(podDir)).toBe(false);
- expect(logSpy).toHaveBeenCalledWith(
- `[cleanup] directory did not exist: ${podDir}`,
- );
- });
-
- it("logs error on rm failure (simulated)", async () => {
- const sessionID = "fail-rm";
- const podDir = path.join(tempRoot, sessionID);
- fs.mkdirSync(podDir, { recursive: true });
-
- // make it unremovable? hard in test, but we can still call and check it logs attempt
- // instead, just verify it tries
- const cleanup = initCleanup(tempRoot, logger);
- await cleanup.execute(sessionID);
-
- // after remove it should be gone, but to test error path we rely on catch in impl
- expect(logSpy).toHaveBeenCalledWith(
- expect.stringContaining("removed directory"),
- );
});
});