diff --git a/packages/cursor/context.test.mjs b/packages/cursor/context.test.mjs index d063c75..f87d78d 100644 --- a/packages/cursor/context.test.mjs +++ b/packages/cursor/context.test.mjs @@ -82,7 +82,7 @@ test("a model once for each context size, named with it and with that window", a test("the provider's list, efforts as variants, no model of its own for fast or an effort", async () => { fakeAPI() const hooks = await CursorAuthPlugin() - const jwt = ["e30", Buffer.from(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 7200 + ++n })).toString("base64url"), "s"].join(".") + const jwt = ["e30", Buffer.from(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 7200 + ++n, sub: "context-" + Math.random() })).toString("base64url"), "s"].join(".") const list = await hooks.provider.models({ models: {} }, { auth: { type: "oauth", access: jwt, refresh: "", expires: 0 } }) expect(list["claude-opus-5-5@300k"].limit.context).toBe(300000) expect(Object.keys(list["claude-opus-5-5@300k"].variants)).toEqual(["low", "medium", "high", "xhigh", "max"]) @@ -95,7 +95,7 @@ test("fast is said on the models Cursor has a fast variant of, at that size, and const fastOf = async (usableIDs) => { fakeAPI(PICKER, usableIDs) const hooks = await CursorAuthPlugin() - const jwt = ["e30", Buffer.from(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 7200 + ++n })).toString("base64url"), "s"].join(".") + const jwt = ["e30", Buffer.from(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 7200 + ++n, sub: "context-" + Math.random() })).toString("base64url"), "s"].join(".") const list = await hooks.provider.models({ models: {} }, { auth: { type: "oauth", access: jwt, refresh: "", expires: 0 } }) return Object.keys(list).filter((id) => list[id].fast === true).sort() } diff --git a/packages/cursor/conversation.test.mjs b/packages/cursor/conversation.test.mjs index f2a7bb2..e0f1fda 100644 --- a/packages/cursor/conversation.test.mjs +++ b/packages/cursor/conversation.test.mjs @@ -20,7 +20,9 @@ http2.connect = (origin, ...rest) => { } afterAll(() => (http2.connect = connect)) -const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp })).toString("base64url"), "sig"].join(".") +// a token of this file's own: another file's {exp} alone can be the same +// token, and would find the endpoint and list kept for it +const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp, sub: "conversation-" + Math.random() })).toString("base64url"), "sig"].join(".") let n = 0 // a sign-in of its own, so no list or endpoint kept for another is used const fresh = () => ({ type: "oauth", access: jwt(Math.floor(Date.now() / 1000) + 7200 + ++n), refresh: "", expires: 0, accountId: "a@b.c" }) diff --git a/packages/cursor/listwait.test.mjs b/packages/cursor/listwait.test.mjs index e60cabd..f421956 100644 --- a/packages/cursor/listwait.test.mjs +++ b/packages/cursor/listwait.test.mjs @@ -6,7 +6,7 @@ // by a stand-in fetch, its agent API by an HTTP/2 server here. import "./nonet.mjs" // first: no request leaves this machine import { afterAll, afterEach, beforeAll, beforeEach, expect, test } from "bun:test" -import { createHash } from "node:crypto" +import { createHash, randomUUID } from "node:crypto" import http2 from "node:http2" import { CursorAuthPlugin, _internal } from "./index.mjs" import { NATIVE_LIMITS, nativeSessions } from "./native-session.mjs" @@ -70,9 +70,11 @@ function fakeAPI(picker) { } } +// a token of its own: another file's {exp} alone can be the same token, +// and would find this file's endpoint and list kept for it let n = 0 const signIn = () => { - const jwt = ["e30", Buffer.from(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 7200 + ++n })).toString("base64url"), "sig"].join(".") + const jwt = ["e30", Buffer.from(JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 7200 + ++n, sub: "listwait-" + randomUUID() })).toString("base64url"), "sig"].join(".") return { type: "oauth", access: jwt, refresh: "", expires: 0, accountId: "a@b.c" } } diff --git a/packages/cursor/maxmode.test.mjs b/packages/cursor/maxmode.test.mjs index 00d42ae..5af5956 100644 --- a/packages/cursor/maxmode.test.mjs +++ b/packages/cursor/maxmode.test.mjs @@ -14,7 +14,9 @@ const { fields, pb, frame, maxRequired } = _internal const real = globalThis.fetch afterEach(() => (globalThis.fetch = real)) -const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp })).toString("base64url"), "sig"].join(".") +// a token of this file's own: another file's {exp} alone can be the same +// token, and would find the endpoint and list kept for it +const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp, sub: "maxmode-" + Math.random() })).toString("base64url"), "sig"].join(".") let n = 0 // a sign-in of its own, so no list kept for another is used const fresh = () => ({ type: "oauth", access: jwt(Math.floor(Date.now() / 1000) + 7200 + 50_000 + ++n), refresh: "", expires: 0, accountId: "a@b.c" }) diff --git a/packages/cursor/usage.test.mjs b/packages/cursor/usage.test.mjs index e7c2308..af0f0c8 100644 --- a/packages/cursor/usage.test.mjs +++ b/packages/cursor/usage.test.mjs @@ -9,7 +9,9 @@ const real = globalThis.fetch afterEach(() => (globalThis.fetch = real)) // a token that runs out in an hour -const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp })).toString("base64url"), "sig"].join(".") +// a token of this file's own: another file's {exp} alone can be the same +// token, and would find the endpoint and list kept for it +const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp, sub: "usage-" + Math.random() })).toString("base64url"), "sig"].join(".") const tok = jwt(Math.floor(Date.now() / 1000) + 3600) const auth = { type: "oauth", access: tok, refresh: "", expires: 0, accountId: "a@b.c" } // a sign-in of its own, so no plan asked before is remembered for it