Skip to content

Commit aac9fac

Browse files
committed
fix(provider-muse): Muse turns no longer fail when the project path's case differs from the disk
1 parent 67c0fc0 commit aac9fac

4 files changed

Lines changed: 74 additions & 14 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
@@ -26,7 +26,9 @@ import * as Effect from "effect/Effect";
2626
import * as Option from "effect/Option";
2727
import type * as Exit from "effect/Exit";
2828
import * as Fiber from "effect/Fiber";
29+
import * as FileSystem from "effect/FileSystem";
2930
import * as Layer from "effect/Layer";
31+
import * as Path from "effect/Path";
3032
import * as Queue from "effect/Queue";
3133
import * as Schema from "effect/Schema";
3234
import * as Stream from "effect/Stream";
@@ -580,6 +582,39 @@ describe("MuseAdapterV2", () => {
580582
),
581583
);
582584

585+
it.effect("pins macOS turns to the root's on-disk case", () =>
586+
Effect.gen(function* () {
587+
if ((yield* HostProcess.Platform) !== "darwin") return;
588+
const fs = yield* FileSystem.FileSystem;
589+
const path = yield* Path.Path;
590+
const created = yield* fs.makeTempDirectoryScoped({ prefix: "MuseRoot-" });
591+
const fake = yield* makeFakeMuse();
592+
const policy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
593+
...runtimePolicy,
594+
cwd: created.toUpperCase(),
595+
});
596+
const harness = yield* makeHarness(
597+
fake,
598+
INSTANCE_ID,
599+
undefined,
600+
undefined,
601+
undefined,
602+
policy,
603+
);
604+
yield* startConversation(harness, fake);
605+
const sessionStart = fake.calls.find((call) => call.method === "session/start");
606+
const turnStart = fake.calls.find((call) => call.method === "turn/start");
607+
// Muse rejects a root whose case differs from the disk's: "expected a canonical path".
608+
assert.strictEqual(
609+
path.basename(String(sessionStart?.params.workspaceRoot)),
610+
path.basename(created),
611+
);
612+
assert.deepStrictEqual(turnStart?.params.workspaceRoots, [
613+
sessionStart?.params.workspaceRoot,
614+
]);
615+
}).pipe(Effect.scoped, Effect.provide(testLayer)),
616+
);
617+
583618
it.effect("skips an unreadable usage notification without ending the turn", () =>
584619
Effect.gen(function* () {
585620
const fake = yield* makeFakeMuse();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { isMuseUsageLimitFailure, museUsageLimitResetAt } from "./usageLimits.ts
6666
import {
6767
createMuseSdkHostEffect,
6868
museApprovalMode,
69+
museCanonicalPath,
6970
musePermissionProfile,
7071
museWorkspaceRoot,
7172
type createMuseSdkHost,
@@ -290,12 +291,11 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
290291
if (input.runtimePolicy.interactionMode === "plan")
291292
return yield* protocolError("Muse Code does not support dedicated Plan mode");
292293
const scope = yield* Effect.scope;
293-
// Muse rejects non-canonical workspace roots (for example macOS /tmp) and
294-
// reports canonical paths in approvals, so resolve symlinks once here.
294+
// Muse rejects non-canonical workspace roots (for example macOS /tmp, or a
295+
// root whose case differs from the disk's) and reports canonical paths in
296+
// approvals, so canonicalize natively once here.
295297
const requestedCwd = input.runtimePolicy.cwd ?? providerHost.paths.cwd;
296-
const cwd = yield* fileSystem
297-
.realPath(requestedCwd)
298-
.pipe(Effect.orElseSucceed(() => requestedCwd));
298+
const cwd = yield* museCanonicalPath(requestedCwd);
299299
const workspaceRoot = yield* museWorkspaceRoot(cwd);
300300
const now = yield* DateTime.now;
301301
let session: OrchestrationV2ProviderSession = {

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ describe("Muse workspace root", () => {
420420
expect(museVerbatimPath("\\\\?\\C:\\repo")).toBe("\\\\?\\C:\\repo");
421421
});
422422

423-
it.effect("leaves the root alone off Windows", () =>
423+
it.effect("keeps a root it cannot resolve off Windows", () =>
424424
Effect.gen(function* () {
425425
expect(yield* museWorkspaceRoot("/workspace/repo")).toBe("/workspace/repo");
426426
}).pipe(Effect.provideService(HostProcess.Platform, "linux")),
@@ -440,7 +440,19 @@ describe("Muse workspace root", () => {
440440
}).pipe(Effect.provideService(HostProcess.Platform, "win32")),
441441
);
442442

443-
// FileSystem.realPath keeps the case it is given; Muse rejects a root whose case differs from the disk's.
443+
// FileSystem.realPath keeps the case it is given; Muse rejects a root whose case
444+
// differs from the disk's, and APFS is case-insensitive just like NTFS.
445+
it.effect("fixes the case of a macOS root natively", () =>
446+
Effect.gen(function* () {
447+
if ((yield* HostProcess.Platform) !== "darwin") return;
448+
const fs = yield* FileSystem.FileSystem;
449+
const path = yield* Path.Path;
450+
const created = yield* fs.makeTempDirectoryScoped({ prefix: "MuseRoot-" });
451+
const root = yield* museWorkspaceRoot(created.toUpperCase());
452+
expect(path.basename(root)).toBe(path.basename(created));
453+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
454+
);
455+
444456
it.effect("fixes the case of a Windows root natively", () =>
445457
Effect.gen(function* () {
446458
if ((yield* HostProcess.Platform) !== "win32") return;

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

Lines changed: 20 additions & 7 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 {
@@ -69,14 +69,27 @@ export function museVerbatimPath(path: string): string {
6969
}
7070

7171
/**
72-
* On Windows Muse rejects anything but the verbatim canonical path, true case
73-
* and long names included, so resolve with the native realpath, which unlike
74-
* FileSystem.realPath fixes case and expands 8.3 names. Muse itself still
75-
* starts in the plain path: the `muse.cmd` launcher runs under cmd.exe, which
76-
* cannot use a verbatim directory.
72+
* A path in the canonical form Muse reports and requires: symlinks resolved
73+
* and, on case-insensitive filesystems, the case that is on disk. The
74+
* promises realpath is Node's native one, which fixes case (and expands
75+
* Windows 8.3 names); FileSystem.realPath is the JS one, which keeps the case
76+
* it is given, so `…/EEVEE` survives it when the directory is `eevee` and
77+
* Muse then rejects the root. An unresolvable path is returned unchanged.
78+
*/
79+
export const museCanonicalPath = Effect.fn("museCanonicalPath")(function* (path: string) {
80+
return yield* Effect.tryPromise(() => NodeFSP.realpath(path)).pipe(
81+
Effect.orElseSucceed(() => path),
82+
);
83+
});
84+
85+
/**
86+
* A workspace root in the form `turn/start` accepts: the canonical path, in
87+
* verbatim form on Windows, where Muse rejects anything else. Muse itself
88+
* still starts in the plain path: the `muse.cmd` launcher runs under cmd.exe,
89+
* which cannot use a verbatim directory.
7790
*/
7891
export const museWorkspaceRoot = Effect.fn("museWorkspaceRoot")(function* (path: string) {
79-
if ((yield* HostProcess.Platform) !== "win32") return path;
92+
if ((yield* HostProcess.Platform) !== "win32") return yield* museCanonicalPath(path);
8093
const canonical = yield* Effect.tryPromise(() => NodeFSP.realpath(path)).pipe(
8194
// A verbatim path takes `/` literally, so an unresolved root needs Windows separators.
8295
Effect.orElseSucceed(() => path.replaceAll("/", "\\")),

0 commit comments

Comments
 (0)