Files
oh-my-pi/packages/coding-agent/test/sdk-session-isolation.test.ts
T
can1357 9148ec01ec feat(session-manager): added optional sessionDir with multi-root migration support
- Made sessionDir parameter optional in SessionManager.create(), forkFrom(), continueRecent(), and list() methods with automatic default computation.
- Updated SessionManager.getDefaultSessionDir() to accept optional agentDir parameter for custom sessions root configuration.
- Changed SessionManager.list() signature to require cwd parameter as first argument with sessionDir now optional.
- Implemented multi-root session migration support by replacing global migration state with per-root tracking and extracting session directory encoding logic.
- Added resolveManagedSessionRoot() function to determine if session directory is managed and extract its root.
2026-03-16 16:06:04 +01:00

51 lines
1.5 KiB
TypeScript

import { afterEach, describe, expect, it } from "bun:test";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
import { getSessionsDir, Snowflake } from "@oh-my-pi/pi-utils";
describe("createAgentSession session storage isolation", () => {
const tempDirs: string[] = [];
afterEach(async () => {
for (const tempDir of tempDirs.splice(0)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
});
it("uses the provided agentDir for the default persistent session root", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), `pi-sdk-session-isolation-${Snowflake.next()}-`));
tempDirs.push(tempDir);
const cwd = path.join(tempDir, `project-${Snowflake.next()}`);
const agentDir = path.join(tempDir, "agent");
fs.mkdirSync(cwd, { recursive: true });
const { session } = await createAgentSession({
cwd,
agentDir,
settings: Settings.isolated(),
disableExtensionDiscovery: true,
skills: [],
contextFiles: [],
promptTemplates: [],
slashCommands: [],
enableMCP: false,
enableLsp: false,
});
try {
const sessionFile = session.sessionFile;
if (!sessionFile) {
throw new Error("Expected session file path");
}
expect(sessionFile.startsWith(path.join(agentDir, "sessions"))).toBe(true);
expect(sessionFile.startsWith(getSessionsDir())).toBe(false);
} finally {
await session.dispose();
}
});
});