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)
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { afterEach, beforeEach, 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 { MCPManager } from "@oh-my-pi/pi-coding-agent/mcp/manager";
|
|
import type { McpConnectionStatusEvent } from "@oh-my-pi/pi-coding-agent/mcp/startup-events";
|
|
import type { MCPServerConfig } from "@oh-my-pi/pi-coding-agent/mcp/types";
|
|
import { removeSyncWithRetries } from "@oh-my-pi/pi-utils";
|
|
|
|
const FIXTURE_PATH = path.join(import.meta.dir, "fixtures", "many-tools-mcp.ts");
|
|
const BUN_EXEC = process.execPath;
|
|
|
|
describe("MCPManager connection status events", () => {
|
|
let workDir: string;
|
|
|
|
beforeEach(() => {
|
|
workDir = fs.mkdtempSync(path.join(os.tmpdir(), "omp-mcp-status-"));
|
|
});
|
|
|
|
afterEach(() => {
|
|
removeSyncWithRetries(workDir);
|
|
});
|
|
|
|
it("emits connecting, connected, and failed updates for startup status", async () => {
|
|
const manager = new MCPManager(workDir);
|
|
const events: McpConnectionStatusEvent[] = [];
|
|
const success: MCPServerConfig = {
|
|
type: "stdio",
|
|
command: BUN_EXEC,
|
|
args: [FIXTURE_PATH],
|
|
};
|
|
const invalid: MCPServerConfig = { type: "stdio", command: "" };
|
|
|
|
try {
|
|
const result = await manager.connectServers({ alpha: success, broken: invalid }, {}, event =>
|
|
events.push(event),
|
|
);
|
|
|
|
expect(result.connectedServers).toContain("alpha");
|
|
expect(result.errors.get("broken")).toBe('Server "broken": stdio server requires "command" field');
|
|
expect(events).toEqual([
|
|
{ type: "connecting", serverNames: ["alpha", "broken"] },
|
|
{ type: "failed", serverName: "broken", error: 'Server "broken": stdio server requires "command" field' },
|
|
{ type: "connected", serverName: "alpha" },
|
|
]);
|
|
} finally {
|
|
await manager.disconnectAll();
|
|
}
|
|
});
|
|
});
|