Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,20 @@ export const OpenCodeMemPlugin: Plugin = async (ctx: PluginInput) => {
}

const cleanupPlugin = async () => {
if (idleTimeout) {
clearTimeout(idleTimeout);
idleTimeout = null;
}
if (webServer) await webServer.stop();
if (memoryClient) memoryClient.close();
};

const shutdownHandler = async () => {
try {
await cleanupPlugin();
process.exit(0);
} catch (error) {
log("Shutdown error", { error: String(error) });
process.exit(1);
process.exitCode = 1;
}
};

Expand Down
17 changes: 17 additions & 0 deletions tests/plugin-shutdown.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from "bun:test";
import { readFileSync } from "node:fs";

describe("plugin shutdown", () => {
it("does not force host process exit from signal handlers", () => {
const source = readFileSync(new URL("../src/index.ts", import.meta.url), "utf-8");

expect(source).not.toContain("process.exit(");
});

it("clears pending idle auto-capture work during cleanup", () => {
const source = readFileSync(new URL("../src/index.ts", import.meta.url), "utf-8");

expect(source).toContain("clearTimeout(idleTimeout)");
expect(source).toContain("idleTimeout = null");
});
});