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.
This commit is contained in:
yetone
2026-10-28 14:49:59 +08:00
parent d9c858c3c0
commit 944610f8c8
5 changed files with 15 additions and 7 deletions
+2 -2
View File
@@ -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()
}
+3 -1
View File
@@ -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" })
+4 -2
View File
@@ -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" }
}
+3 -1
View File
@@ -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" })
+3 -1
View File
@@ -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