Files
oh-my-pi/packages/coding-agent/test/mcp/config-writer.test.ts
T
2026-07-27 16:43:53 +02:00

44 lines
1.6 KiB
TypeScript

import { afterEach, beforeEach, 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 { addMCPServer, readDisabledServers, readMCPConfigFile, setServerDisabled } from "../../src/mcp/config-writer";
describe("config-writer concurrent mutations", () => {
let dir: string;
let filePath: string;
beforeEach(async () => {
dir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-mcp-config-"));
filePath = path.join(dir, "mcp.json");
});
afterEach(async () => {
await fs.rm(dir, { recursive: true, force: true });
});
it("preserves both servers when two adds race the same file", async () => {
await Promise.all([
addMCPServer(filePath, "alpha", { type: "stdio", command: "a" }),
addMCPServer(filePath, "bravo", { type: "stdio", command: "b" }),
]);
const config = await readMCPConfigFile(filePath);
expect(Object.keys(config.mcpServers ?? {}).sort()).toEqual(["alpha", "bravo"]);
});
it("preserves both denylist edits when disable calls race", async () => {
await Promise.all([setServerDisabled(filePath, "alpha", true), setServerDisabled(filePath, "bravo", true)]);
expect((await readDisabledServers(filePath)).sort()).toEqual(["alpha", "bravo"]);
});
it("writes into a directory that does not exist yet", async () => {
const nestedPath = path.join(dir, "nested", "deep", "mcp.json");
await addMCPServer(nestedPath, "alpha", { type: "stdio", command: "a" });
const config = await readMCPConfigFile(nestedPath);
expect(Object.keys(config.mcpServers ?? {})).toEqual(["alpha"]);
});
});