a2854ba768
Migrate 203 test files (356 call sites) from fs.rm/fs.rmSync to
removeWithRetries/removeSyncWithRetries to reduce EBUSY test failures
on Windows. removeWithRetries is now exported from @oh-my-pi/pi-utils.
The migration uses a regex-based approach that:
- Replaces fs.rm(path, { recursive, force }) → removeWithRetries(path)
- Replaces fs.rmSync(path, { recursive, force }) → removeSyncWithRetries(path)
- Replaces fs.rm(path) → removeWithRetries(path) (no options)
- Skips fs.rm/fs.rmSync inside template literals (bun --eval scripts)
- Adds imports to existing @oh-my-pi/pi-utils import or creates new one
- Removes unused fs imports where fs.rm was the only fs usage (4 files)
73 lines
2.3 KiB
TypeScript
73 lines
2.3 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 { getBundledModel } from "@oh-my-pi/pi-catalog/models";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
|
|
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
import { removeSyncWithRetries, Snowflake } from "@oh-my-pi/pi-utils";
|
|
|
|
function textContent(result: { content?: Array<{ type: string; text?: string }> }): string {
|
|
return (
|
|
result.content
|
|
?.filter(
|
|
(block): block is { type: "text"; text: string } => block.type === "text" && typeof block.text === "string",
|
|
)
|
|
.map(block => block.text)
|
|
.join("\n") ?? ""
|
|
);
|
|
}
|
|
|
|
describe("createAgentSession cwd after /move", () => {
|
|
const tempDirs: string[] = [];
|
|
|
|
afterEach(() => {
|
|
for (const tempDir of tempDirs.splice(0)) {
|
|
removeSyncWithRetries(tempDir);
|
|
}
|
|
});
|
|
|
|
it("runs tools from the moved session directory", async () => {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), `pi-sdk-move-cwd-${Snowflake.next()}-`));
|
|
tempDirs.push(tempDir);
|
|
const cwdA = path.join(tempDir, "cwd-a");
|
|
const cwdB = path.join(tempDir, "cwd-b");
|
|
fs.mkdirSync(cwdA, { recursive: true });
|
|
fs.mkdirSync(cwdB, { recursive: true });
|
|
|
|
const sessionManager = SessionManager.create(cwdA, path.join(tempDir, "sessions"));
|
|
const { session } = await createAgentSession({
|
|
cwd: cwdA,
|
|
agentDir: tempDir,
|
|
sessionManager,
|
|
settings: Settings.isolated({
|
|
"async.enabled": false,
|
|
"bash.autoBackground.enabled": false,
|
|
"bashInterceptor.enabled": false,
|
|
}),
|
|
model: getBundledModel("openai", "gpt-4o-mini"),
|
|
disableExtensionDiscovery: true,
|
|
skills: [],
|
|
contextFiles: [],
|
|
promptTemplates: [],
|
|
slashCommands: [],
|
|
enableMCP: false,
|
|
enableLsp: false,
|
|
toolNames: ["bash"],
|
|
});
|
|
|
|
try {
|
|
await sessionManager.moveTo(cwdB);
|
|
|
|
const bashTool = session.getToolByName("bash");
|
|
if (!bashTool) throw new Error("Expected bash tool");
|
|
const result = await bashTool.execute("pwd-after-move", { command: "pwd" });
|
|
|
|
expect(textContent(result)).toContain(cwdB);
|
|
} finally {
|
|
await session.dispose();
|
|
}
|
|
});
|
|
});
|