Skip to content

Commit 22ee8a4

Browse files
riccardopllclaudemaria-rcks
authored
fix(cursor): ignore a stale Keychain login when Cursor is not installed (#27143)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 17c837c commit 22ee8a4

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎apps/server/src/usage/UsageService.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,37 @@ describe("UsageService", () => {
14621462
}).pipe(Effect.scoped),
14631463
);
14641464

1465+
it.effect("ignores a stale macOS Keychain login when Cursor is not installed", () =>
1466+
Effect.gen(function* () {
1467+
const { settings, home } = yield* setup;
1468+
const cursor = makeFakeCursor();
1469+
cursor.state.error = "Sign in to Cursor again to read account usage.";
1470+
const readCursorSource = Effect.gen(function* () {
1471+
const service = yield* makeWithCursor(cursor.read);
1472+
const summary = yield* service.readSummary({ ...WINDOW, awaitRefresh: true });
1473+
return cursorSource(summary);
1474+
}).pipe(
1475+
Effect.provide(
1476+
layerService({
1477+
prefix: "usage-service-cursor-keychain-uninstalled",
1478+
home,
1479+
settings: { ...settings, cursorKeychainUsageEnabled: true },
1480+
platform: "darwin",
1481+
environment: {},
1482+
}),
1483+
),
1484+
);
1485+
1486+
assert.isUndefined(yield* readCursorSource);
1487+
assert.lengthOf(cursor.state.calls, 0);
1488+
1489+
yield* Effect.promise(() => NodeFSP.mkdir(NodePath.join(home, ".cursor")));
1490+
const installed = yield* readCursorSource;
1491+
assert.strictEqual(installed?.message, "Sign in to Cursor again to read account usage.");
1492+
assert.lengthOf(cursor.state.calls, 1);
1493+
}).pipe(Effect.scoped),
1494+
);
1495+
14651496
it.live("ignores stale Cursor file logins when the active credential store differs", () =>
14661497
Effect.gen(function* () {
14671498
const { settings, home } = yield* setup;

‎packages/provider-cursor/src/server/CursorUsageAccounts.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,9 @@ const make = Effect.gen(function* () {
186186
retentionStartMs: number,
187187
awaitRefresh: boolean,
188188
) {
189-
if (
190-
typeof credential === "string" &&
191-
!(yield* fileSystem.exists(credential).pipe(Effect.orElseSucceed(() => true)))
192-
) {
189+
// A Keychain login outlives an uninstalled Cursor, so it also needs Cursor's local directory.
190+
const localLogin = typeof credential === "string" ? credential : path.dirname(authPath);
191+
if (!(yield* fileSystem.exists(localLogin).pipe(Effect.orElseSucceed(() => true)))) {
193192
return null;
194193
}
195194
yield* ensureLoaded;

0 commit comments

Comments
 (0)