Skip to content

Commit 6d8e63d

Browse files
fix(server): keep a discovered Muse home after its CLI disappears
Read the settled discovery before checking the executable, and pin that a cached failure is not reported as pending.
1 parent 5b39e2d commit 6d8e63d

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ const make = Effect.gen(function* () {
5050
);
5151
const resolve: MuseUsageHome["Service"]["resolve"] = Effect.fn("MuseUsageHome.resolve")(
5252
function* ({ binaryPath, environment, awaitRefresh }) {
53-
// Spawn failures surface asynchronously; without this a missing CLI would report as pending.
54-
const resolveExecutable = yield* SpawnExecutableResolution;
55-
if (resolveExecutable(binaryPath, yield* HostProcess.Platform, environment) === undefined) {
56-
return Option.some(undefined);
57-
}
5853
// Cache keys compare structurally. Omitted and undefined variables both
5954
// disappear from the child process environment and must share an entry.
6055
const key = {
@@ -63,9 +58,14 @@ const make = Effect.gen(function* () {
6358
Object.entries(environment).filter(([, value]) => value !== undefined),
6459
),
6560
};
66-
if (awaitRefresh) return Option.some(yield* Cache.get(cache, key));
6761
const settled = yield* Cache.getSuccess(cache, key);
6862
if (Option.isSome(settled)) return settled;
63+
// Spawn failures surface asynchronously; without this a missing CLI would report as pending.
64+
const resolveExecutable = yield* SpawnExecutableResolution;
65+
if (resolveExecutable(binaryPath, yield* HostProcess.Platform, environment) === undefined) {
66+
return Option.some(undefined);
67+
}
68+
if (awaitRefresh) return Option.some(yield* Cache.get(cache, key));
6969
// Awaited in the layer scope so a departing caller cannot cancel discovery.
7070
yield* Effect.forkIn(Cache.get(cache, key), scope, { startImmediately: true });
7171
// A lookup that settled synchronously needs no refresh.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ describe("Muse history discovery", () => {
425425
expect(first).toEqual(second);
426426
expect(first).toHaveLength(1);
427427
expect(yield* museUsageReader.directories(instance, { awaitRefresh: false })).toEqual(first);
428+
const uninstalled = Effect.provideService(SpawnExecutableResolution, () => undefined);
429+
expect(
430+
yield* museUsageReader.directories(instance, { awaitRefresh: false }).pipe(uninstalled),
431+
).toEqual(first);
432+
expect(yield* museUsageReader.directories(instance, AWAIT_REFRESH).pipe(uninstalled)).toEqual(
433+
first,
434+
);
428435
expect(create).toHaveBeenCalledOnce();
429436
expect(close).toHaveBeenCalledOnce();
430437
}).pipe(Effect.provide([NodeServices.layer, MuseUsageHome.layer]), onPath),
@@ -453,7 +460,7 @@ describe("Muse history discovery", () => {
453460
environment: {},
454461
};
455462
expect(yield* museUsageReader.directories(instance, AWAIT_REFRESH)).toEqual([]);
456-
expect(yield* museUsageReader.directories(instance, AWAIT_REFRESH)).toEqual([]);
463+
expect(yield* museUsageReader.directories(instance, { awaitRefresh: false })).toEqual([]);
457464
expect(create).toHaveBeenCalledOnce();
458465
yield* TestClock.adjust("30 seconds");
459466
expect(yield* museUsageReader.directories(instance, AWAIT_REFRESH)).toHaveLength(1);

0 commit comments

Comments
 (0)