gateway, gui: one model out of its pool rests on that model's rows only, not on the account's other models (#1960, WardLu)

An Antigravity account out of its Claude & GPT pool (claude-opus-5.5
refused until Sunday) rests that model alone: the gateway keys the rest
by restID and still sends gemini-3.8-flash, in its own pool, to the
account. Routing's page didn't know a rest could be one model's: it
kept rests by key or account, so the stage marked the account's
gemini-3.8-flash row "quota used up · back at Sun 17:53", and the row
under Accounts and keys said the whole account was out.

- gateway: Rest.Model names the model a rest is for when it rests by
  restID (a pool, a model not served, a paid model beside free ones);
  "" for an account- or key-wide rest.
- routing.js: restModel reads it (or, for a kept request from before,
  the model on the end of Rest.Key). The stage keeps a model's own rest
  by key and model, so only that model's row rests; an answered try
  ends the account's rest and its own model's. Accounts and keys keeps
  an account's model rests apart from its own: the account isn't shown
  as out, a line names the models resting with why and when, and Try
  now lifts those rests. An account resting as a whole is as before.
- docs/subsystems/gateway-routing.md says so.

Run: routing-model-rest.test.cjs (new), Chromium and WebKit, 1100 and
420, en/zh/zh-TW/ja/de, 20/20; with the old routing.js it fails
("old@x.test: gemini-3.8-flash rests with Opus"). All 74 routing/rest
GUI test files in both engines (456 each, 0 fail).
TestPoolRefusalRestsTheModelOnly checks Rest.Model, set and read back.
go test ./internal/gateway ./internal/gui, gofmt -l, go vet
darwin/linux/windows (-tags nogui).
Not tried: the reporter's real Antigravity account in the app.
This commit is contained in:
yetone
2026-10-13 17:40:47 +08:00
parent 4795f56469
commit 42216ea609
5 changed files with 237 additions and 14 deletions
+1
View File
@@ -106,6 +106,7 @@ recorded as a prediction failure (`noPrediction`).
- A 429 that names in words when the account is back (WorkBuddy's "将在 2026-10-11 20:16:02 UTC+8重置" and "your usage will reset at 2026-10-11 12:37:53 UTC+8, …", #1669) is out of quota in either language (`resetsWhen`), and rests until that time (`resetsWritten`, read in the offset written). Only the reset phrasing right beside a whole date and time with its UTC/GMT offset, followed by 重置 or punctuation, is read, so a refusal cut short isn't read as UTC and another vendor's date in passing is no reset; a time past, not a real date, or more than `longestWritten` (7 days) off isn't read. One that points to the account's other models (`otherModels`: "切换其他模型", "switch to the other models") rests that model alone (`restID`). Out of credit or quota on a model that costs credits, where the subscription serves other models free (`catalog.Model.Free`: WorkBuddy's x0.00, Qoder's is_free, Cline's free models; `Provider.PaidBesideFree`), rests that model alone too: the free ones draw on no credits (Creat.wu on Discord, `TestOutOfCreditLeavesFreeModels`). A free model the vendor refuses all the same (WorkBuddy refuses even 0-rate models to an account with no package) rests the account on its own refusal. WorkBuddy's 429 14018 "Credits exhausted" is out of credit (`brokeWords`), not a rate limit, on the built-in's raw body and the plugin's `insufficient_quota` alike (`TestCreditsExhaustedIsOutOfCredit`). On the rate-limit branch, a reset time the refusal names (`resetsAt`, or `resetsHeader` as `keepRetry` noted it) is believed up to `longestQuota`, as out of quota believes it, and the Routing page says it rests until then (`resets`); a `Retry-After` or a rate-limit reset header is still held to `longestWait` (an hour) (`rateRest`). The same rest runs for a plugin's requests: the WorkBuddy plugin passes these 429s on as they come (`TestPluginWrittenResetRests`). A JSON error body that escapes what isn't ASCII as `\uXXXX` (Python's json.dumps does by default) has its strings decoded before any word list (`creditWords`, `rateWords`, `plannedWords`, `usedUpWords`, `resetsWhen`, …) is matched (`wordsOf`), so an escaped 余额不足 or 用量 reads as an unescaped one does.
- An account resting out of its window (a Claude account by the time Claude Code's refusal named, `resets`, or any by `window`) is back once magpie's reading of its windows (`provider.Allowances`) finds it full till sooner: the window used below `SpentShareOf`, or its reset passed, with no other window over the same models still full. The reading tells `provider.OnRenewed` as the account's `UsageAgent` and user, and `renewed` lifts that account's rests out of quota or by `window`; its rests for a rate limit, its credit, a verification or a failure stay, as a key's do, and so does every rest of other accounts still out of their windows. Planning reads every account candidate's allowance, ordered groups included, so this needs no step of its own in `restingOf`.
- Only an account is held at a usage cap (`capHeld`) or rested out of one model's pool (`pooled`); a key's windows order it and rest it, nothing more.
- A rest of one model alone (keyed by `restID`: a pool, a model not served, a paid model beside free ones) names that model in the trace (`Rest.Model`). The Routing page shows it on that model's rows only: the account's other models' rows on the stage, and the account's row under Accounts and keys, don't read as resting. The account's row names the models resting on a line of their own under what it has left, and its Try now lifts their rests. A kept request from before `Rest.Model` has the model on the end of `Rest.Key`, which the page reads the same (`restModel` in `routing.js`, #1960, `routing-model-rest.test.cjs`).
- Codex offers its image tool (the `image_gen` namespace, #870) to every magpie provider. When a provider other than a ChatGPT sign-in or openai.com answers a bare 400, `attempt` asks it once more without the tool (`image_tool.go`). This happens both passed through and translated. If that works, the provider is marked unfit for the tool (`tool:image_gen`) and isn't offered it again. If it doesn't, the tool is restored and the 400 stands (#949).
- A turn the agent stopped with its tool call still out is replayed by the client with the call and no result, and Google's APIs turn a history whose call turn goes unanswered away with 400, every later turn of the conversation with it. The Gemini build (`buildCodeAssistSent`, which serves a Google sign-in, Vertex AI and a custom provider's Gemini API alike) answers such a call with the synthetic result the chat build pairs an interrupted turn's call with (`pairToolMessages`, #1275), right after the calls (`pairFunctionTurns`, #1560): beside the answers the client sent there, or in a user turn of its own before what the user said, since a turn mixing a `functionResponse` with text is turned away too (#1533); a Claude model on Antigravity gets it in the one tool_result turn. A call with no id counts as answered by a response of its name.
- A request built for a Messages upstream (`buildAnthropic`: a Chat, Responses or Gemini client translated, and Zed's bridge) has its tool exchanges mended after its messages are built (`pairToolBlocks`, #1558, ggbdpq), since Anthropic answers 400 for a `tool_use` the next message doesn't answer and for a `tool_result` naming no call of the message before it. A call left unanswered gets the synthetic interrupted result, `is_error` set, first in the user message after it or in one of its own; a result that answers no call goes as a text block with what it said (its images as they came); a second answer to one call is dropped. A well-formed exchange goes as it was built. An Anthropic client relayed to a Messages upstream isn't mended. [`anthropic_tool_pairing_test.go`](../../internal/gateway/anthropic_tool_pairing_test.go).
+9 -2
View File
@@ -39,6 +39,13 @@ func TestPoolRefusalRestsTheModelOnly(t *testing.T) {
if r.Why != failQuota || r.Key != opus.restID() || r.By != "window" {
t.Fatalf("Opus out of its week rests %+v", r)
}
// the app shows it on Opus's rows only (#1960)
if r.Model != opus.model {
t.Fatalf("Opus's own rest says model %q", r.Model)
}
if kept, _ := restOf(opus.restID()); kept.Model != opus.model {
t.Fatalf("Opus's rest, read back, says model %q", kept.Model)
}
if _, ok := restOf(sonnet.restKey()); ok {
t.Fatal("Opus out of its own week rests the account")
}
@@ -50,8 +57,8 @@ func TestPoolRefusalRestsTheModelOnly(t *testing.T) {
}
whole := acct("out@x.com", "claude-sonnet-4-6")
if r := s.restAfter(whole, 429, http.Header{}, refused); r.Key != whole.restKey() {
t.Fatalf("the account's week used up rests %s, not the account", r.Key)
if r := s.restAfter(whole, 429, http.Header{}, refused); r.Key != whole.restKey() || r.Model != "" {
t.Fatalf("the account's week used up rests %s (model %q), not the account", r.Key, r.Model)
}
if _, ok := restOf(acct("out@x.com", "claude-opus-4-7").restKey()); !ok {
t.Fatal("the account's week used up leaves its other models in")
+9
View File
@@ -377,6 +377,12 @@ type Rest struct {
Failures int `json:"failures,omitempty"` // in a row, for a backoff
// Key is what it rests by, for the app to lift the rest (Unrest)
Key string `json:"key,omitempty"`
// Model: the one model resting, when the account or key still
// answers its others (a pooled allowance, a model it doesn't serve);
// "" for the account or key as a whole. The app shows the rest on
// that model's rows only (#1960: Antigravity's Claude & GPT pool used
// up showed gemini-3.8-flash, in a pool of its own, as out too).
Model string `json:"model,omitempty"`
// Link: where the vendor said to verify the account, for failVerify
Link string `json:"link,omitempty"`
@@ -666,6 +672,9 @@ func (s *Server) restAfterMarked(c candidate, status int, header http.Header, bo
id = c.restID()
}
r.Key = id
if id == c.restID() {
r.Model = c.model
}
restingUntil.Lock()
restingUntil.m[id] = r.Until
restingUntil.note[id] = r
+52 -12
View File
@@ -443,6 +443,13 @@
return { c: 0, k: -1 };
}
// restModel is the one model a rest is for, "" when it is the account's
// or key's as a whole (#1960): an account out of a pool that counts some
// models only (Antigravity's Claude & GPT) still answers its others
// (gemini-3.8-flash, in a pool of its own). The gateway names it; a kept
// request from before it did has it on the end of the key it rests by,
// after the model of the seat that carried it.
const restModel = (rest, m) => rest.model || (m && rest.key?.endsWith("/" + m) ? m : "");
// how long a rest is from a moment: now for a row, the moment it was
// decided for the story of a request
function restWhen(rest, from = now()) {
@@ -1500,15 +1507,21 @@
for (const f of flying.values()) { onWire.add(f.id); busy.add(f.agent); }
for (const [id, row] of rows) {
// each row as the latest staged request that weighed it found it
// rests by key or account, and by key or account and model for a
// rest of one model only: the account's other models' rows don't
// rest with it (#1960)
const r = src().get(row.rid) || pinned || cur, answered = new Set(), rests = new Map(), gave = new Map();
for (const w of r.order) if (w.rest) rests.set(w.id, w.rest);
const restAt = (id, m, rest) => { const rm = restModel(rest, m); rests.set(rm ? id + "\u0000" + rm : id, rest); };
const modelOf = (tr) => tried(r, tr)?.model || tr.model || "";
for (const w of r.order) if (w.rest) restAt(w.id, w.model, w.rest);
for (const tr of r.tries) {
if (tr.done && tryOk(tr)) answered.add(tryseat(r, tr));
else if (tr.done && !tr.rest && !tr.again) gave.set(tryseat(r, tr), tr); // the error the agent got
if (tr.rest) rests.set(tr.id, tr.rest);
if (tr.rest) restAt(tr.id, modelOf(tr), tr.rest);
}
for (const tr of r.tries) if (tr.done && tryOk(tr)) rests.delete(tr.id); // it answered: whatever rest it began in is over
const w = row.w, rest = rests.get(w.id), resting = rest && at(rest.until) > n;
// it answered: whatever rest it began in is over
for (const tr of r.tries) if (tr.done && tryOk(tr)) { rests.delete(tr.id); rests.delete(tr.id + "\u0000" + modelOf(tr)); }
const w = row.w, rest = rests.get(w.id) || rests.get(w.id + "\u0000" + (w.model || "")), resting = rest && at(rest.until) > n;
let s;
if (w.unlisted) s = unlistedWord(w);
else if (resting) s = `${failWord(rest.why)} · ${restWhen(rest)}`;
@@ -2385,6 +2398,11 @@
// when each rest was lifted by hand, by the key it rests by (#1869)
const liftedAt = new Map();
// modelRest keeps the latest word of one of an account's models resting
// alone (#1960)
function modelRest(a, m, rest, when) {
if ((a.mrests.get(m)?.at || 0) <= when) a.mrests.set(m, { rest, at: when });
}
// each account or key the kept requests weighed: how often it was
// tried, answered and failed in them, and how the latest found it
function renderActs(rs) {
@@ -2398,10 +2416,15 @@
const candidates = new Map();
r.order.forEach((w, i) => {
const key = keyOf(w);
const a = by.get(key) || { w, tried: 0, ok: 0, fails: {}, last: 0, rest: null, restAt: 0, seen: 0, pos: 0, models: new Set() };
const a = by.get(key) || { w, tried: 0, ok: 0, fails: {}, last: 0, rest: null, restAt: 0, seen: 0, pos: 0, models: new Set(), mrests: new Map() };
a.w = w; a.seen++; a.pos = i; a.at = r.time;
// a later request found it resting, or not
if (at(r.time) >= a.restAt) { a.rest = w.rest || null; a.restAt = at(r.time); }
// a later request found it resting, or not: the account as a
// whole, or one of its models alone (#1960), which leaves the
// account and its other models as they are
const rm = w.rest ? restModel(w.rest, w.model) : "", T = at(r.time);
if (rm) modelRest(a, rm, w.rest, T);
else if (T >= a.restAt) { a.rest = w.rest || null; a.restAt = T; }
if (!w.rest && w.model && (a.mrests.get(w.model)?.at || 0) <= T) a.mrests.delete(w.model);
by.set(key, a);
candidates.set(w.id, a);
});
@@ -2412,12 +2435,17 @@
const end = at(tr.start) + (tr.ms || 0);
if (tryOk(tr)) { a.ok++; a.last = Math.max(a.last, end); const m = tr.model || r.order.find((x) => x.id === tr.id)?.model; if (m) a.models.add(m); }
else a.fails[tr.fail || "other"] = (a.fails[tr.fail || "other"] || 0) + 1;
if (tr.rest && end >= a.restAt) { a.rest = tr.rest; a.restAt = end; }
const rm = tr.rest ? restModel(tr.rest, tr.model || r.order.find((x) => x.id === tr.id)?.model) : "";
if (rm) modelRest(a, rm, tr.rest, end);
else if (tr.rest && end >= a.restAt) { a.rest = tr.rest; a.restAt = end; }
}
}
// a rest lifted by hand since the request that found it (#1869): the
// kept requests still say it, until the next one asks it again
for (const a of by.values()) if (a.rest?.key && (liftedAt.get(a.rest.key) || 0) >= a.restAt) a.rest = null;
for (const a of by.values()) {
if (a.rest?.key && (liftedAt.get(a.rest.key) || 0) >= a.restAt) a.rest = null;
for (const [m, x] of a.mrests) if (x.rest.key && (liftedAt.get(x.rest.key) || 0) >= x.at) a.mrests.delete(m);
}
const list = [...by.values()].sort((x, y) => (x.w.name || "").localeCompare(y.w.name || "") || x.w.provider.localeCompare(y.w.provider) || rankOf(x.w) - rankOf(y.w) || x.pos - y.pos);
setText(actLabel, t("Accounts and keys"));
setText(actNote, t("over those requests"));
@@ -2465,6 +2493,10 @@
else name.append(el("b", "", who(w)), el("span", "", w.plan || (w.kind === "key" ? t("API key") : "")));
let st, cls = "";
const resting = a.rest && at(a.rest.until) > n;
// its models resting alone, while the account answers its others:
// a line of their own, naming them, under what the account has left
const parts = resting ? [] : [...a.mrests].filter(([, x]) => at(x.rest.until) > n)
.sort(([m, x], [l, y]) => at(x.rest.until) - at(y.rest.until) || m.localeCompare(l));
if (resting) { st = `${failWord(a.rest.why)} · ${restWhen(a.rest)}`; cls = "rest"; }
else if (w.unlisted) { st = unlistedWord(w); cls = "left"; }
else if (w.noURL) st = noURLWord(w);
@@ -2482,6 +2514,10 @@
...(fails.length ? [el("span", "bad", fails.join(", "))] : []),
...(a.last ? [el("span", "", t("last answered {time}", { time: clock(a.last) }))] : []));
row.append(name, el("div", "st " + cls, st));
if (parts.length) {
const r0 = parts[0][1].rest;
row.append(el("div", "st rest part", `${parts.map(([m]) => m).join(", ")} · ${failWord(r0.why)} · ${restWhen(r0)}`));
}
// a subscription account's windows each, with when they reset, as
// the Usage page read them (#1833): the figure above is the one
// window routing went by. Live only: a kept day's requests were
@@ -2501,20 +2537,24 @@
ms.append(...mdls.map((m) => el("code", "mdl", m)));
row.append(ms);
}
if (resting && a.rest.key) {
const lifts = resting ? (a.rest.key ? [a.rest] : []) : parts.map(([, x]) => x.rest).filter((x) => x.key);
if (lifts.length) {
// any rest can be lifted by hand (#1869): a quota, a backoff, a
// Retry-After, a network blip read as down. It only ends the rest;
// the vendor refusing again rests it again as before. The vendor
// wants the account verified (#152), or restricted it until an
// appeal lifts it (#1849): where, and the way to stop its rest
// once it is
const fix = el("div", "fix"), rest = a.rest;
const fix = el("div", "fix"), rest = lifts[0];
if (rest.link) { const b = el("button", "link", t("Verify the account ↗")); b.onclick = () => api("open", { url: rest.link }).catch(() => {}); fix.append(b); }
const go = el("button", "link", t(rest.why === "restricted" ? "The restriction is lifted — try it again"
: rest.why === "verify" ? "It's verified — try it again" : "Try now"));
if (rest.why !== "restricted" && rest.why !== "verify") go.title = t("Ends the rest: the next request asks it again. Refused again, it rests again.");
go.onclick = async () => {
try { await api("gateway/unrest", { key: rest.key }); liftedAt.set(rest.key, Date.now()); render(); } catch (e) { go.textContent = e.message; }
try {
for (const x of lifts) { await api("gateway/unrest", { key: x.key }); liftedAt.set(x.key, Date.now()); }
render();
} catch (e) { go.textContent = e.message; }
};
fix.append(go);
row.append(fix);
@@ -0,0 +1,166 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// One model resting alone rests on its own rows only (#1960, WardLu): an
// Antigravity account out of its Claude & GPT pool (claude-opus-5.5 refused
// until Sunday) still answers gemini-3.8-flash from its Gemini pool. Before,
// Routing's stage marked the account's gemini-3.8-flash row "quota used up ·
// back at Sun 17:53", and its row under Accounts and keys said the account
// was out. Now the stage marks the Opus row alone, and the account's row
// says what it has left with a line of its own naming the model that rests,
// whose Try now lifts that model's rest. An account resting as a whole
// still rests on every row. In every language, at a wide and a narrow
// window, in Chromium and WebKit.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const now = new Date();
const start = new Date(now.getTime() - 60e3).toISOString();
const sunday = new Date(now.getTime() + 5 * 24 * 3600e3).toISOString();
const renews = new Date(now.getTime() + 3 * 3600e3).toISOString();
const seat = (user, model, used, extra = {}) => ({
id: "antigravity@" + user, provider: "antigravity", name: "Antigravity", kind: "account", icon: "antigravity",
who: user, plan: "Google AI Pro", model, known: true, used, renews: [renews], ...extra,
});
// the issue's: the Claude & GPT pool used up rests claude-opus-5.5 alone,
// as the gateway names it (Rest.Model) — and one from a kept day before it
// did, the model on the end of the key only
const opusRest = { why: "quota", status: 429, until: sunday, by: "window", key: "antigravity@me@x.test/claude-opus-5.5", model: "claude-opus-5.5" };
const oldRest = { why: "quota", status: 429, until: sunday, by: "window", key: "antigravity@old@x.test/claude-opus-5.5" };
// an account out as a whole
const allRest = { why: "quota", status: 429, until: sunday, by: "window", key: "antigravity@out@x.test" };
// one request weighing the three accounts' seats, as the gateway does:
// each seat with its own rest, the account's on every seat of it. The
// stage shows the latest request's seats.
function routes() {
const time = start, order = [], tries = [];
for (const [user, rest] of [["me@x.test", opusRest], ["old@x.test", oldRest], ["out@x.test", allRest]]) {
const opus = seat(user, "claude-opus-5.5", 100, { rest });
const flash = seat(user, "gemini-3.8-flash", 46, rest === allRest ? { rest } : {});
order.push(opus, flash);
tries.push({ id: opus.id, model: opus.model, start: time, done: true, status: 429, ms: 300, fail: "quota", rest, error: "quota exhausted" });
}
tries.push({ id: order[1].id, model: order[1].model, start: time, done: true, status: 200, ms: 900 });
return [{ id: 1, seq: 1, time, agent: "codex", model: "group/g", provider: "antigravity", order, tries, done: true, status: 200, ms: 2000 }];
}
function serve(lang, lifted) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [{ id: "codex", name: "Codex", path: "/test/config.toml", fields: [] }], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.has("wait")) return;
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 1, rerouted: 1, errors: 0 }, routes: routes() });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/gateway/unrest") {
lifted.push(JSON.parse(route.request().postData() || "{}"));
return json({ lifted: true });
}
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
};
}
const go = { en: "Try now", zh: "立即重试", "zh-TW": "立即重試", ja: "今すぐ試す", de: "Jetzt versuchen" };
const posted = async (lifted) => {
for (let i = 0; i < 60 && !lifted.length; i++) await new Promise((r) => setTimeout(r, 50));
return lifted;
};
// a reader wheels down to it, over what scrolls it, and it is the
// button under the pointer
async function reach(page, btn) {
const at = await btn.evaluate((e) => {
let p = e.parentElement;
while (p && !(p.scrollHeight > p.clientHeight + 1 && /auto|scroll/.test(getComputedStyle(p).overflowY))) p = p.parentElement;
const l = (p || document.documentElement).getBoundingClientRect();
const top = Math.max(l.top, 0), bottom = Math.min(l.bottom, innerHeight);
return { x: l.left + Math.min(l.width / 2, 100), y: (top + bottom) / 2 };
});
await page.mouse.move(at.x, at.y);
for (let i = 0; i < 30 && !(await btn.evaluate((e) => e.getBoundingClientRect().bottom < innerHeight - 80)); i++) await page.mouse.wheel(0, 200);
await page.waitForTimeout(200);
assert(await btn.evaluate((e) => { const r = e.getBoundingClientRect(); return e.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2)); }), "the button can't be reached");
}
const sideways = (page) => page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(go)) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}px: one model resting leaves the account's other models and the account in`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
const errors = [], lifted = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, lifted));
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-model-rest.png`), fullPage: true });
}
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-act").first().waitFor();
// the stage: a row per account and model
const stage = (user, model) => page.locator("li", { has: page.locator("code.mdl", { hasText: new RegExp(`^${model.replace(/\./g, "\\.")}$`) }) })
.filter({ has: page.locator(".who", { hasText: user }) });
// old@x.test's gemini-3.8-flash wasn't asked, as the reporter's
// wasn't; me@x.test's answered after its Opus was refused
for (const user of ["old@x.test", "me@x.test"]) {
const opus = stage(user, "claude-opus-5.5"), flash = stage(user, "gemini-3.8-flash");
await opus.first().waitFor({ state: "attached" });
assert.equal(await opus.count(), 1, `${user}: one Opus row`);
assert.equal(await flash.count(), 1, `${user}: one gemini-3.8-flash row`);
assert(!(await flash.evaluate((e) => e.classList.contains("rest"))), `${user}: gemini-3.8-flash rests with Opus`);
assert(await opus.evaluate((e) => e.classList.contains("rest")), `${user}: the Opus row doesn't rest`);
const said = (await opus.locator("em").textContent()).trim();
assert(said, `${user}: the Opus row says nothing`);
assert.notEqual((await flash.locator("em").textContent()).trim(), said, `${user}: gemini-3.8-flash says Opus's rest`);
}
for (const model of ["claude-opus-5.5", "gemini-3.8-flash"]) {
assert(await stage("out@x.test", model).evaluate((e) => e.classList.contains("rest")), `the account out as a whole: ${model} doesn't rest`);
}
// Accounts and keys: the account isn't out; the model resting is named
for (const user of ["me@x.test", "old@x.test"]) {
const row = page.locator(".rt-act", { hasText: user });
assert.equal(await row.count(), 1);
assert.equal(await row.locator(".st.rest:not(.part)").count(), 0, `${user}: the account reads as out`);
const part = row.locator(".st.rest.part");
assert.equal(await part.count(), 1, `${user}: no line names the model resting`);
const text = await part.textContent();
assert(text.startsWith("claude-opus-5.5 · "), `${user}: the line says ${text}`);
assert(!text.includes("gemini"), `${user}: the line names gemini-3.8-flash`);
}
const out = page.locator(".rt-act", { hasText: "out@x.test" });
assert.equal(await out.locator(".st.rest:not(.part)").count(), 1, "the account out as a whole doesn't read as out");
assert.equal(await out.locator(".st.part").count(), 0);
assert(!(await sideways(page)), "the page scrolls sideways");
// Try now lifts the model's own rest
const row = page.locator(".rt-act", { hasText: "me@x.test" });
const btn = row.locator(".fix button", { hasText: go[lang] });
await reach(page, btn);
await btn.click();
assert.deepEqual(await posted(lifted), [{ key: opusRest.key }]);
await row.locator(".st.part").waitFor({ state: "detached" });
assert.deepEqual(errors, []);
});
}
}
}