Skip to content

Commit 5033239

Browse files
GLDRogerclaudemaria-rcks
authored
fix(provider-muse): Muse turns no longer fail when the project path's case differs from the disk (#22346)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 5e222be commit 5033239

4 files changed

Lines changed: 94 additions & 8 deletions

File tree

‎packages/provider-muse/src/server/adapter.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// @effect-diagnostics-next-line nodeBuiltinImport:off -- Mock native realpath to exercise macOS case correction on every platform.
2+
import * as NodeFSP from "node:fs/promises";
3+
import { vi } from "vite-plus/test";
14
import { assert, describe, it } from "@effect/vitest";
25
import * as NodeServices from "@effect/platform-node/NodeServices";
36
import { MspError } from "@muse-code/sdk";
@@ -379,6 +382,8 @@ const approval = (turnId: string) => ({
379382
subject: { kind: "shell", command: "touch result.txt" },
380383
});
381384

385+
vi.mock("node:fs/promises", { spy: true });
386+
382387
describe("MuseAdapterV2", () => {
383388
it.effect("connects the thread's MCP credential on native start and resume", () =>
384389
Effect.gen(function* () {
@@ -569,6 +574,36 @@ describe("MuseAdapterV2", () => {
569574
),
570575
);
571576

577+
it.effect("pins sessions and turns to native canonical case", () =>
578+
Effect.gen(function* () {
579+
using _realpath = vi.spyOn(NodeFSP, "realpath").mockResolvedValue("/workspace/eevee");
580+
const fake = yield* makeFakeMuse();
581+
const policy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
582+
...runtimePolicy,
583+
cwd: "/workspace/EEVEE",
584+
});
585+
const harness = yield* makeHarness(
586+
fake,
587+
INSTANCE_ID,
588+
undefined,
589+
undefined,
590+
undefined,
591+
policy,
592+
);
593+
yield* startConversation(harness, fake);
594+
const sessionStart = fake.calls.find((call) => call.method === "session/start");
595+
const turnStart = fake.calls.find((call) => call.method === "turn/start");
596+
assert.strictEqual(sessionStart?.params.workspaceRoot, "/workspace/eevee");
597+
assert.deepStrictEqual(turnStart?.params.workspaceRoots, [
598+
sessionStart?.params.workspaceRoot,
599+
]);
600+
}).pipe(
601+
Effect.scoped,
602+
Effect.provide(testLayer),
603+
Effect.provideService(HostProcess.Platform, "darwin"),
604+
),
605+
);
606+
572607
it.effect("stops at a Meta usage limit until every exhausted window resets", () =>
573608
Effect.gen(function* () {
574609
const fake = yield* makeFakeMuse();

‎packages/provider-muse/src/server/adapter.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { isMuseUsageLimitFailure, museUsageLimitResetAt } from "./usageLimits.ts
6565
import {
6666
createMuseSdkHostEffect,
6767
museApprovalMode,
68+
museCanonicalPath,
6869
musePermissionProfile,
6970
museWorkspaceRoot,
7071
type createMuseSdkHost,
@@ -289,11 +290,9 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
289290
if (input.runtimePolicy.interactionMode === "plan")
290291
return yield* protocolError("Muse Code does not support dedicated Plan mode");
291292
const scope = yield* Effect.scope;
292-
// Muse requires canonical workspace roots and approval paths; resolve symlinks once.
293+
// Native realpath also corrects filesystem case, which Muse validates.
293294
const requestedCwd = input.runtimePolicy.cwd ?? providerHost.paths.cwd;
294-
const cwd = yield* fileSystem
295-
.realPath(requestedCwd)
296-
.pipe(Effect.orElseSucceed(() => requestedCwd));
295+
const cwd = yield* museCanonicalPath(requestedCwd);
297296
const workspaceRoot = yield* museWorkspaceRoot(cwd);
298297
const now = yield* DateTime.now;
299298
let session: OrchestrationV2ProviderSession = {

‎packages/provider-muse/src/server/sdk.test.ts‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @effect-diagnostics-next-line nodeBuiltinImport:off -- Mock native realpath to exercise macOS case correction on every platform.
2+
import * as NodeFSP from "node:fs/promises";
13
// @effect-diagnostics-next-line nodeBuiltinImport:off -- The Muse SDK spawns with Node's child_process, so the launch test quotes arguments the same way.
24
import * as NodeChildProcess from "node:child_process";
35
import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -21,6 +23,8 @@ import {
2123
type MuseSdkHost,
2224
} from "./sdk.ts";
2325

26+
vi.mock("node:fs/promises", { spy: true });
27+
2428
vi.mock("@muse-code/sdk", () => ({ spawnMspConnection: vi.fn() }));
2529

2630
function pending<A>() {
@@ -311,13 +315,54 @@ describe("Muse launch", () => {
311315
});
312316

313317
describe("Muse workspace root", () => {
318+
it.effect("uses native canonical case off Windows", () =>
319+
Effect.gen(function* () {
320+
using _realpath = vi.spyOn(NodeFSP, "realpath").mockResolvedValue("/workspace/eevee");
321+
expect(yield* museWorkspaceRoot("/workspace/EEVEE")).toBe("/workspace/eevee");
322+
}).pipe(Effect.provideService(HostProcess.Platform, "darwin")),
323+
);
324+
314325
it("writes Windows paths in their verbatim form", () => {
315326
expect(museVerbatimPath("C:\\Users\\Person\\repo")).toBe("\\\\?\\C:\\Users\\Person\\repo");
316327
expect(museVerbatimPath("\\\\server\\share\\repo")).toBe("\\\\?\\UNC\\server\\share\\repo");
317328
expect(museVerbatimPath("\\\\?\\C:\\repo")).toBe("\\\\?\\C:\\repo");
318329
});
319330

320-
// FileSystem.realPath keeps the case it is given; Muse rejects a root whose case differs from the disk's.
331+
it.effect("keeps a root it cannot resolve off Windows", () =>
332+
Effect.gen(function* () {
333+
expect(yield* museWorkspaceRoot("/workspace/repo")).toBe("/workspace/repo");
334+
}).pipe(Effect.provideService(HostProcess.Platform, "linux")),
335+
);
336+
337+
it.effect("keeps a Windows root it cannot resolve, in verbatim form", () =>
338+
Effect.gen(function* () {
339+
expect(yield* museWorkspaceRoot("C:\\definitely-missing\\repo")).toBe(
340+
"\\\\?\\C:\\definitely-missing\\repo",
341+
);
342+
expect(yield* museWorkspaceRoot("C:/definitely-missing/repo")).toBe(
343+
"\\\\?\\C:\\definitely-missing\\repo",
344+
);
345+
expect(yield* museWorkspaceRoot("//server/share/missing")).toBe(
346+
"\\\\?\\UNC\\server\\share\\missing",
347+
);
348+
}).pipe(Effect.provideService(HostProcess.Platform, "win32")),
349+
);
350+
351+
// FileSystem.realPath keeps the case it is given; Muse rejects a root whose case
352+
// differs from the disk's, and APFS is case-insensitive just like NTFS.
353+
it.effect("fixes the case of a macOS root natively", () =>
354+
Effect.gen(function* () {
355+
if ((yield* HostProcess.Platform) !== "darwin") return;
356+
const fs = yield* FileSystem.FileSystem;
357+
const path = yield* Path.Path;
358+
const created = yield* fs.makeTempDirectoryScoped({ prefix: "MuseRoot-" });
359+
// Only a case-insensitive volume resolves the miscased path; skip on a case-sensitive one.
360+
if (!(yield* fs.exists(created.toUpperCase()))) return;
361+
const root = yield* museWorkspaceRoot(created.toUpperCase());
362+
expect(path.basename(root)).toBe(path.basename(created));
363+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
364+
);
365+
321366
it.effect("fixes the case of a Windows root natively", () =>
322367
Effect.gen(function* () {
323368
if ((yield* HostProcess.Platform) !== "win32") return;

‎packages/provider-muse/src/server/sdk.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @effect-diagnostics globalTimers:off
22
// The SDK owns process shutdown; native deadlines cover initialize before an Effect resource exists.
3-
// @effect-diagnostics-next-line nodeBuiltinImport:off -- FileSystem.realPath is Node's JS realpath; museWorkspaceRoot needs the native one.
3+
// @effect-diagnostics-next-line nodeBuiltinImport:off -- FileSystem.realPath is Node's JS realpath; museCanonicalPath needs the native one.
44
import * as NodeFSP from "node:fs/promises";
55

66
import {
@@ -70,9 +70,16 @@ export function museVerbatimPath(path: string): string {
7070
return path.startsWith("\\\\") ? `\\\\?\\UNC\\${path.slice(2)}` : `\\\\?\\${path}`;
7171
}
7272

73-
/** Windows roots need native realpath for true case/long names, then verbatim form; launch cmd.exe in plain form. */
73+
// Native realpath corrects filesystem case as well as resolving symlinks.
74+
export const museCanonicalPath = Effect.fn("museCanonicalPath")(function* (path: string) {
75+
return yield* Effect.tryPromise(() => NodeFSP.realpath(path)).pipe(
76+
Effect.orElseSucceed(() => path),
77+
);
78+
});
79+
80+
// Windows turn roots need verbatim form; launch cmd.exe with the plain canonical path.
7481
export const museWorkspaceRoot = Effect.fn("museWorkspaceRoot")(function* (path: string) {
75-
if ((yield* HostProcess.Platform) !== "win32") return path;
82+
if ((yield* HostProcess.Platform) !== "win32") return yield* museCanonicalPath(path);
7683
const canonical = yield* Effect.tryPromise(() => NodeFSP.realpath(path)).pipe(
7784
// A verbatim path takes `/` literally, so an unresolved root needs Windows separators.
7885
Effect.orElseSucceed(() => path.replaceAll("/", "\\")),

0 commit comments

Comments
 (0)