Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions packages/provider-cursor/src/server/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import {
DEFAULT_SERVER_SETTINGS,
MessageId,
NodeId,
ProjectId,
Expand All @@ -21,6 +22,8 @@
import * as Stream from "effect/Stream";
import { vi } from "vite-plus/test";
import * as HttpClient from "effect/http/HttpClient";
import * as HttpClientResponse from "effect/http/HttpClientResponse";
import * as HostProcess from "@t3tools/shared/HostProcess";

import {
DEFAULT_HANDOFF_TOKEN_CAP,
Expand Down Expand Up @@ -102,12 +105,40 @@
instanceId: ProviderInstanceId.make("cursor-browser-persisted"),
displayName: "Personal Cursor",
enabled: true,
environment: [{ name: "CURSOR_API_KEY", value: "", sensitive: true }],
// Clear inherited Cursor settings so the fixture always takes the mocked Keychain path.
environment: [
{ name: "CURSOR_API_KEY", value: "", sensitive: true },
{ name: "CURSOR_AUTH_TOKEN", value: "", sensitive: true },
{ name: "CURSOR_API_ENDPOINT", value: "", sensitive: false },
{ name: "AGENT_CLI_CREDENTIAL_STORE", value: "default", sensitive: false },
],
config: CursorDriver.defaultConfig(),
};
const settingsControl = yield* TestProviderHost.TestProviderHostSettings;
yield* settingsControl.set({
...DEFAULT_SERVER_SETTINGS,
cursorKeychainUsageEnabled: true,
});
yield* Effect.addFinalizer(() => settingsControl.set(DEFAULT_SERVER_SETTINGS));
const openedKeys: Array<string | undefined> = [];
let closed = 0;
const instance = yield* CursorDriver.create(input).pipe(
Effect.provideService(HostProcess.Platform, "darwin"),
Effect.provideService(CursorKeychain.CursorKeychain, {
accessToken: Effect.succeed("keychain-account-token"),
}),
Effect.provideService(
HttpClient.HttpClient,
HttpClient.make((request) => {
expect(request.headers.authorization).toBe("Bearer keychain-account-token");
return Effect.succeed(
HttpClientResponse.fromWeb(
request,
Response.json({ planUsage: { totalPercentUsed: 42 } }),
),
);
}),
),
Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {
assertComplete: Effect.void,
open: (request) =>
Expand All @@ -132,6 +163,7 @@
Effect.map(Option.getOrThrow),
);
expect(me).toHaveBeenCalledWith({ apiKey: "instance-browser-key" });
expect((yield* instance.snapshot.refresh).usageLimits?.windows[0]?.usedPercent).toBe(42);

Check failure on line 166 in packages/provider-cursor/src/server/driver.test.ts

View workflow job for this annotation

GitHub Actions / Test

src/server/driver.test.ts > CursorDriver > persists browser credentials, uses them for chat, and closes the SDK session on logout

AssertionError: expected undefined to be 42 // Object.is equality - Expected: 42 + Received: undefined ❯ src/server/driver.test.ts:166:89 ❯ ~effect/Effect/successCont ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:1422:28 ❯ ~effect/Effect/evaluate ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/core.ts:585:30 ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:654:41 ❯ FiberImpl.evaluate ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:595:23 ❯ FiberImpl.evaluate ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:589:27 ❯ ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:1159:17 ❯ Array.<anonymous> ../../node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:1697:11
expect(yield* instance.snapshot.getSnapshot).toMatchObject({
status: "ready",
auth: {
Expand All @@ -158,8 +190,26 @@
yield* runtime.ensureThread({ threadId, modelSelection, runtimePolicy });
expect(openedKeys).toEqual(["instance-browser-key"]);
expect(closed).toBe(0);
const recreated = yield* CursorDriver.create(input);
expect((yield* recreated.snapshot.refresh).auth.status).toBe("authenticated");
const recreated = yield* CursorDriver.create(input).pipe(
Effect.provideService(HostProcess.Platform, "darwin"),
Effect.provideService(CursorKeychain.CursorKeychain, {
accessToken: Effect.succeed("keychain-account-token"),
}),
Effect.provideService(
HttpClient.HttpClient,
HttpClient.make((request) =>
Effect.succeed(
HttpClientResponse.fromWeb(
request,
Response.json({ planUsage: { totalPercentUsed: 42 } }),
),
),
),
),
);
const recreatedSnapshot = yield* recreated.snapshot.refresh;
expect(recreatedSnapshot.auth.status).toBe("authenticated");
expect(recreatedSnapshot.usageLimits?.windows[0]?.usedPercent).toBe(42);
yield* instance.auth!.logout(Effect.void);
expect(closed).toBe(1);
expect((yield* instance.snapshot.getSnapshot).auth.status).toBe("unauthenticated");
Expand Down
2 changes: 1 addition & 1 deletion packages/provider-cursor/src/server/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const CursorDriver: ProviderDriver<
Effect.flatMap((settings) =>
readCursorUsageLimits(
effectiveConfig,
{ ...processEnv, CURSOR_API_KEY: apiKey },
{ ...processEnv, CURSOR_API_KEY: auth.usesApiKey ? apiKey : undefined },
settings.cursorKeychainUsageEnabled,
),
),
Expand Down
Loading