fix: protect project path from session kill cleanup

This commit is contained in:
Harsh 2026-03-06 10:32:40 +05:30
parent cf2b165b46
commit 8776ca278f
2 changed files with 19 additions and 1 deletions

View File

@ -1358,6 +1358,24 @@ describe("kill", () => {
expect(mockWorkspace.destroy).not.toHaveBeenCalled();
});
it("does not destroy workspace when worktree resolves to project path", async () => {
const projectPath = config.projects["my-app"]?.path;
if (!projectPath) throw new Error("missing project path");
writeMetadata(sessionsDir, "app-1", {
worktree: `${projectPath}/`,
branch: "main",
status: "working",
project: "my-app",
runtimeHandle: JSON.stringify(makeHandle("rt-1")),
});
const sm = createSessionManager({ config, registry: mockRegistry });
await sm.kill("app-1");
expect(mockWorkspace.destroy).not.toHaveBeenCalled();
});
it("throws for nonexistent session", async () => {
const sm = createSessionManager({ config, registry: mockRegistry });
await expect(sm.kill("nonexistent")).rejects.toThrow("not found");

View File

@ -11,7 +11,7 @@
* Reference: scripts/claude-ao-session, scripts/send-to-session
*/
import { statSync, existsSync, readdirSync, writeFileSync, mkdirSync } from "node:fs";
import { statSync, existsSync, readdirSync, writeFileSync, mkdirSync, realpathSync } from "node:fs";
import { execFile } from "node:child_process";
import { basename, join, resolve } from "node:path";
import { homedir } from "node:os";