Skip to content

Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy

Rust

cursor test helpers: share jwt and resourceExhaustedFrame

Raine Virta027a6af3188b
diff --git a/src/providers/cursor/auth/token-store.test.ts b/src/providers/cursor/auth/token-store.test.ts
index e710b27..83d763e 100644
--- a/src/providers/cursor/auth/token-store.test.ts
+++ b/src/providers/cursor/auth/token-store.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "bun:test";
import { loadCursorAuth } from "./token-store.ts";
import { parseJwtClaims, tokenExpiryMs } from "./jwt.ts";
+import { jwt } from "../cursor-test-helpers.ts";
describe("Cursor auth token discovery", () => {
it("loads CCP_CURSOR_AUTH_TOKEN without reading Cursor storage", async () => {
@@ -22,11 +23,3 @@ describe("Cursor auth token discovery", () => {
expect(tokenExpiryMs(token)).toBe(123_000);
});
});
-
-function jwt(payload: Record<string, unknown>): string {
- return [
- Buffer.from(JSON.stringify({ alg: "none", typ: "JWT" })).toString("base64url"),
- Buffer.from(JSON.stringify(payload)).toString("base64url"),
- "signature",
- ].join(".");
-}
diff --git a/src/providers/cursor/cursor-test-helpers.ts b/src/providers/cursor/cursor-test-helpers.ts
index b8c9681..81d1829 100644
--- a/src/providers/cursor/cursor-test-helpers.ts
+++ b/src/providers/cursor/cursor-test-helpers.ts
@@ -109,3 +109,34 @@ export async function collectCursorSse(
}
return events;
}
+
+export function jwt(payload: Record<string, unknown>): string {
+ return [
+ Buffer.from(JSON.stringify({ alg: "none", typ: "JWT" })).toString("base64url"),
+ Buffer.from(JSON.stringify(payload)).toString("base64url"),
+ "signature",
+ ].join(".");
+}
+
+export function resourceExhaustedFrame(): Uint8Array {
+ return encodeConnectFrame(
+ jsonBytes({
+ error: {
+ code: "resource_exhausted",
+ message: "Error",
+ details: [
+ {
+ debug: {
+ details: {
+ additionalInfo: {
+ chatMessage: "You've hit your free requests limit.",
+ },
+ },
+ },
+ },
+ ],
+ },
+ }),
+ 2,
+ );
+}
diff --git a/src/providers/cursor/index.test.ts b/src/providers/cursor/index.test.ts
index f148fe7..e2b7258 100644
--- a/src/providers/cursor/index.test.ts
+++ b/src/providers/cursor/index.test.ts
@@ -2,12 +2,14 @@ import { afterEach, describe, expect, it } from "bun:test";
import { cursorProvider, createCursorProvider } from "./index.ts";
import { encodeConnectFrame, runCursorAgent, type CursorRunOptions } from "./client.ts";
import {
- decodeFrameJson,
collectCursorSse,
+ decodeFrameJson,
fakeCursorCtx,
fakeProtoMerged as fakeProto,
frame,
jsonBytes,
+ jwt,
+ resourceExhaustedFrame,
streamFromChunks,
} from "./cursor-test-helpers.ts";
import { mkdir, mkdtemp, stat, writeFile } from "node:fs/promises";
@@ -182,26 +184,7 @@ describe("Cursor provider messages", () => {
it("preserves Cursor Connect end error status for non-streaming requests", async () => {
const provider = createCursorTestProvider(async () => {
return streamFromChunks([
- encodeConnectFrame(
- jsonBytes({
- error: {
- code: "resource_exhausted",
- message: "Error",
- details: [
- {
- debug: {
- details: {
- additionalInfo: {
- chatMessage: "You've hit your free requests limit.",
- },
- },
- },
- },
- ],
- },
- }),
- 2,
- ),
+ resourceExhaustedFrame(),
]);
});
@@ -652,11 +635,3 @@ async function exists(path: string): Promise<boolean> {
return false;
}
}
-
-function jwt(payload: Record<string, unknown>): string {
- return [
- Buffer.from(JSON.stringify({ alg: "none", typ: "JWT" })).toString("base64url"),
- Buffer.from(JSON.stringify(payload)).toString("base64url"),
- "signature",
- ].join(".");
-}