From 944610f8c8fdd3397ce59a0b75fe01399b557fcc Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 14:49:59 +0800 Subject: [PATCH] cursor: each test file mints sign-in tokens of its own The publish run for d9c858c (cursor 0.2.28) went red in conversation.test.mjs: its first Run went to 127.0.0.1:42583, a closed agent server of listwait.test.mjs, got ECONNRESET and fell back to HTTP/1.1, which its fake API doesn't answer. listwait's tokens were {exp: now+7200+n} with a counter from 0, byte for byte the tokens conversation.test.mjs mints, so within one second the plugin's agent endpoint and model list kept for listwait's token were found by conversation's. conversation, maxmode and usage had the same latent collision with each other. Each of those files, and context's tokens, now carry a sub of their own (as http1, latency and the native tests already did). Run: on Linux (wsl-run), listwait then conversation was red 6 of 6 before and 0 of 6 after; listwait, conversation, maxmode and usage in one run 0 of 4 red; bun test packages/cursor 314 pass. On mote, the whole repo's bun test (2997 pass, 0 fail) and bun scripts/check.mjs (ok). Broken by hand: the failing order was found by replaying CI's file order and logging open()'s HTTP/2 failure (ECONNRESET to listwait's port). Not tried: CI's exact random order beyond the replay. --- packages/cursor/context.test.mjs | 4 ++-- packages/cursor/conversation.test.mjs | 4 +++- packages/cursor/listwait.test.mjs | 6 ++++-- packages/cursor/maxmode.test.mjs | 4 +++- packages/cursor/usage.test.mjs | 4 +++- 5 files changed, 15 insertions(+), 7 deletions(-) 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