Skip to content

Commit bdf8faf

Browse files
committed
test(mcp): address CodeRabbit review on user-scope.test.ts
Add afterAll mock cleanup and replace node:fs/promises readFile/writeFile with Bun.file().json(), Bun.file().text(), and Bun.write() per project standards.
1 parent 6d21677 commit bdf8faf

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/cli-core/src/commands/mcp/clients/user-scope.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2-
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
1+
import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2+
import { mkdir, mkdtemp, rm } from "node:fs/promises";
33
import { join } from "node:path";
44
import * as realOs from "node:os";
55
import { useCaptureLog } from "../../../test/lib/stubs.ts";
@@ -10,6 +10,7 @@ import { useCaptureLog } from "../../../test/lib/stubs.ts";
1010
// module mock instead — registered at file top, before the clients are imported.
1111
let mockHome = realOs.tmpdir();
1212
mock.module("node:os", () => ({ ...realOs, homedir: () => mockHome }));
13+
afterAll(() => mock.restore());
1314

1415
const mockIsAgent = mock();
1516
mock.module("../../../mode.ts", () => ({
@@ -42,7 +43,7 @@ describe("user-scope MCP clients (homedir redirected to a tmpdir)", () => {
4243
describe("gemini", () => {
4344
test("encodes the mcp-remote stdio-bridge shape", async () => {
4445
await geminiClient.upsert({ name: "clerk", url: URL }, "/ignored", false);
45-
const parsed = JSON.parse(await readFile(geminiClient.configPath("/ignored"), "utf8")) as {
46+
const parsed = (await Bun.file(geminiClient.configPath("/ignored")).json()) as {
4647
mcpServers: { clerk: { command: string; args: string[] } };
4748
};
4849
expect(parsed.mcpServers.clerk).toEqual({ command: "npx", args: ["-y", "mcp-remote", URL] });
@@ -61,7 +62,7 @@ describe("user-scope MCP clients (homedir redirected to a tmpdir)", () => {
6162
// unrelated npx tool must not round-trip as a Clerk MCP entry.
6263
const dir = join(mockHome, ".gemini");
6364
await mkdir(dir, { recursive: true });
64-
await writeFile(
65+
await Bun.write(
6566
join(dir, "settings.json"),
6667
JSON.stringify({
6768
mcpServers: {
@@ -78,7 +79,7 @@ describe("user-scope MCP clients (homedir redirected to a tmpdir)", () => {
7879
describe("windsurf", () => {
7980
test("encodes the serverUrl shape and round-trips it on list", async () => {
8081
await windsurfClient.upsert({ name: "clerk", url: URL }, "/ignored", false);
81-
const parsed = JSON.parse(await readFile(windsurfClient.configPath("/ignored"), "utf8")) as {
82+
const parsed = (await Bun.file(windsurfClient.configPath("/ignored")).json()) as {
8283
mcpServers: { clerk: { serverUrl: string } };
8384
};
8485
expect(parsed.mcpServers.clerk).toEqual({ serverUrl: URL });

0 commit comments

Comments
 (0)