all: a usage read says what it means for the sign-in, and a renewal clears the mark whatever follows, as the built-ins did (要保证插件跟内置的所有逻辑都要一模一样) — auth.usage returns signIn on every path: expired where the built-in's quota read marked the account (Zed's /users/me 401, Factory's and MiMo's refused renewals, Qoder's refused job refresh), renewed after a renewal, which took the mark off, kept everywhere else, so magpie no longer guesses from the words 'sign in again' (Kiro's, Devin's and ZCode's usage errors marked accounts their built-ins never did) nor clears on a clean read. A request after a renewal says renewed on any status; one without says kept, as the built-ins cleared only on renewal. Kiro, Cursor, Devin, Command Code, WorkBuddy, Grok and ZCode, whose built-ins never marked an account, say kept on every answer. New tests fail against 85d7dd0's index.mjs.

This commit is contained in:
yetone
2026-10-01 04:53:29 +08:00
parent 85d7dd0d0a
commit 01aee5da28
31 changed files with 541 additions and 229 deletions
+8 -1
View File
@@ -74,5 +74,12 @@ test("an error line saying 401 keeps the account too", async () => {
test("the Provider API's 401 goes on as it came, the account kept", async () => {
expect(await signIn(() => Response.json({ error: { message: "Invalid API key" } }, { status: 401 }), "Pro", "/provider/v1/chat/completions"))
.toEqual({ status: 401, signIn: "kept" })
expect(await signIn(() => Response.json({}), "Pro", "/provider/v1/chat/completions")).toEqual({ status: 200, signIn: null })
})
// nor cleared one: an answer that went through leaves the mark as it is
test("an answer that goes through keeps the account's mark, Go's and the Provider API's", async () => {
expect(await signIn(() => Response.json({}), "Pro", "/provider/v1/chat/completions")).toEqual({ status: 200, signIn: "kept" })
expect(await signIn(() => Response.json({}, { status: 404 }), "Pro", "/provider/v1/chat/completions")).toEqual({ status: 404, signIn: "kept" })
const line = JSON.stringify({ type: "text-delta", text: "hi" }) + "\n" + JSON.stringify({ type: "finish", finishReason: "stop" }) + "\n"
expect(await signIn(() => new Response(line))).toEqual({ status: 200, signIn: "kept" })
})