Files
oh-my-pi/packages/coding-agent/test/memories/instructions.test.ts
T
oldschoola a2854ba768 fix: migrate coding-agent tests from fs.rm to removeWithRetries
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)
2026-06-23 15:28:05 -07:00

34 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { buildMemoryToolDeveloperInstructions, getMemoryRoot } from "@oh-my-pi/pi-coding-agent/memories";
import { removeWithRetries } from "@oh-my-pi/pi-utils";
async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "memory-instructions-"));
try {
return await fn(dir);
} finally {
await removeWithRetries(dir);
}
}
describe("buildMemoryToolDeveloperInstructions", () => {
it("uses memory:// URLs and does not expose raw memory root paths", async () => {
await withTempDir(async agentDir => {
const settings = Settings.isolated({ "memories.enabled": true });
const memoryRoot = getMemoryRoot(agentDir, settings.getCwd());
await fs.mkdir(memoryRoot, { recursive: true });
await Bun.write(path.join(memoryRoot, "memory_summary.md"), "Use structured retries for flaky network calls.");
const instructions = await buildMemoryToolDeveloperInstructions(agentDir, settings);
expect(instructions).toBeDefined();
expect(instructions).toContain("memory://root/memory_summary.md");
expect(instructions).toContain("memory://root/skills/<name>/SKILL.md");
expect(instructions).not.toContain(memoryRoot);
});
});
});