Skip to content

Commit 914c2c4

Browse files
committed
test(cursor): remove unused CLI credential test setup
1 parent ae91097 commit 914c2c4

1 file changed

Lines changed: 52 additions & 76 deletions

File tree

‎packages/provider-cursor/src/server/usageLimits.test.ts‎

Lines changed: 52 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { describe, expect, it } from "@effect/vitest";
2-
import * as HostProcess from "@t3tools/shared/HostProcess";
32
import * as Effect from "effect/Effect";
4-
import * as FileSystem from "effect/FileSystem";
53
import * as HttpClient from "effect/http/HttpClient";
64
import * as HttpClientResponse from "effect/http/HttpClientResponse";
75
import { cursorUsageResponseToLimits, readCursorUsageLimits } from "./usageLimits.ts";
@@ -56,41 +54,29 @@ describe("Cursor usage limits", () => {
5654
).toEqual([{ id: "totalPercentUsed", kind: "monthly", label: "Overall", usedPercent: 100 }]);
5755
});
5856

59-
it.effect("ignores CLI logins and accepts an explicit auth token", () =>
57+
it.effect("requires explicit credentials and accepts an auth token", () =>
6058
Effect.gen(function* () {
61-
for (const platform of ["linux", "darwin"] as const) {
62-
for (const token of [undefined, "explicit-token"]) {
63-
const limits = yield* readCursorUsageLimits(
64-
{ apiEndpoint: "" },
65-
{
66-
AGENT_CLI_CREDENTIAL_STORE: platform === "linux" ? "memory" : "default",
67-
...(token ? { CURSOR_AUTH_TOKEN: token } : {}),
68-
},
69-
).pipe(
70-
Effect.provideService(HostProcess.Platform, platform),
71-
Effect.provideService(
72-
FileSystem.FileSystem,
73-
FileSystem.makeNoop({
74-
readFileString: () => Effect.die("must not read an unrelated credential file"),
75-
}),
76-
),
77-
Effect.provideService(
78-
HttpClient.HttpClient,
79-
HttpClient.make((request) => {
80-
expect(token).toBe("explicit-token");
81-
expect(request.headers.authorization).toBe("Bearer explicit-token");
82-
return Effect.succeed(
83-
HttpClientResponse.fromWeb(
84-
request,
85-
Response.json({ planUsage: { totalPercentUsed: 10 } }),
86-
),
87-
);
88-
}),
89-
),
90-
);
91-
if (token) expect(limits.windows[0]?.usedPercent).toBe(10);
92-
else expect(limits.unavailable?.reason).toBe("unsupported");
93-
}
59+
for (const token of [undefined, "explicit-token"]) {
60+
const limits = yield* readCursorUsageLimits(
61+
{ apiEndpoint: "" },
62+
token ? { CURSOR_AUTH_TOKEN: token } : {},
63+
).pipe(
64+
Effect.provideService(
65+
HttpClient.HttpClient,
66+
HttpClient.make((request) => {
67+
expect(token).toBe("explicit-token");
68+
expect(request.headers.authorization).toBe("Bearer explicit-token");
69+
return Effect.succeed(
70+
HttpClientResponse.fromWeb(
71+
request,
72+
Response.json({ planUsage: { totalPercentUsed: 10 } }),
73+
),
74+
);
75+
}),
76+
),
77+
);
78+
if (token) expect(limits.windows[0]?.usedPercent).toBe(10);
79+
else expect(limits.unavailable?.reason).toBe("unsupported");
9480
}
9581
}),
9682
);
@@ -120,47 +106,38 @@ describe("Cursor usage limits", () => {
120106
}),
121107
);
122108

123-
it.effect("reads an API key's own account instead of a stored login", () =>
109+
it.effect("exchanges an API key to read its account limits", () =>
124110
Effect.gen(function* () {
125-
for (const platform of ["linux", "darwin"] as const) {
126-
const requests: Array<readonly [string, string | undefined]> = [];
127-
const limits = yield* readCursorUsageLimits(
128-
{ apiEndpoint: "" },
129-
{ CURSOR_API_KEY: "api-key" },
130-
).pipe(
131-
Effect.provideService(HostProcess.Platform, platform),
132-
Effect.provideService(
133-
FileSystem.FileSystem,
134-
FileSystem.makeNoop({
135-
readFileString: () => Effect.die("must not read a stored login"),
136-
}),
137-
),
138-
Effect.provideService(
139-
HttpClient.HttpClient,
140-
HttpClient.make((request) => {
141-
requests.push([request.url, request.headers.authorization]);
142-
return Effect.succeed(
143-
HttpClientResponse.fromWeb(
144-
request,
145-
Response.json(
146-
request.url.endsWith("/auth/exchange_user_api_key")
147-
? { accessToken: "api-key-access-token" }
148-
: { planUsage: { totalPercentUsed: 37 } },
149-
),
111+
const requests: Array<readonly [string, string | undefined]> = [];
112+
const limits = yield* readCursorUsageLimits(
113+
{ apiEndpoint: "" },
114+
{ CURSOR_API_KEY: "api-key" },
115+
).pipe(
116+
Effect.provideService(
117+
HttpClient.HttpClient,
118+
HttpClient.make((request) => {
119+
requests.push([request.url, request.headers.authorization]);
120+
return Effect.succeed(
121+
HttpClientResponse.fromWeb(
122+
request,
123+
Response.json(
124+
request.url.endsWith("/auth/exchange_user_api_key")
125+
? { accessToken: "api-key-access-token" }
126+
: { planUsage: { totalPercentUsed: 37 } },
150127
),
151-
);
152-
}),
153-
),
154-
);
155-
expect(requests).toEqual([
156-
["https://api2.cursor.sh/auth/exchange_user_api_key", "Bearer api-key"],
157-
[
158-
"https://api2.cursor.sh/aiserver.v1.DashboardService/GetCurrentPeriodUsage",
159-
"Bearer api-key-access-token",
160-
],
161-
]);
162-
expect(limits.windows[0]?.usedPercent).toBe(37);
163-
}
128+
),
129+
);
130+
}),
131+
),
132+
);
133+
expect(requests).toEqual([
134+
["https://api2.cursor.sh/auth/exchange_user_api_key", "Bearer api-key"],
135+
[
136+
"https://api2.cursor.sh/aiserver.v1.DashboardService/GetCurrentPeriodUsage",
137+
"Bearer api-key-access-token",
138+
],
139+
]);
140+
expect(limits.windows[0]?.usedPercent).toBe(37);
164141
}),
165142
);
166143

@@ -173,7 +150,6 @@ describe("Cursor usage limits", () => {
173150
["https://cursor-proxy.example", { CURSOR_API_KEY: "api-key" }],
174151
] as const) {
175152
const limits = yield* readCursorUsageLimits({ apiEndpoint }, environment).pipe(
176-
Effect.provideService(HostProcess.Platform, "darwin"),
177153
Effect.provideService(
178154
HttpClient.HttpClient,
179155
HttpClient.make(() => Effect.die("must not send an API key to a proxy")),

0 commit comments

Comments
 (0)