Files
magpie/internal/gui/tests/routing-rest-error.test.cjs
T
yetone 82b45888ac routing: a plain failure's rest says its status and the vendor's words (GanHei37443 on X)
GanHei37443 on X ("workbuddy 全都连接失败是怎么回事啊") showed Routing with
three WorkBuddy Free accounts each "失败 · 16 秒后恢复" on
deepseek-v4.1-flash, and a fourth (WorkBuddy AI) "额度用尽 · 19:07 恢复".
The fourth is the free plan's 24-hour token window, as it says. The three
rested at once for the same request, so the vendor refused that request
the same way on each, with an error the plugin doesn't name (no 11128,
11140, 14018 or content_filter): magpie's "failed". Nothing on the page
said what WorkBuddy answered: the rest carried no status shown and none
of the vendor's words, only the request's details did.

Cause on WorkBuddy's side not found. The owner's WorkBuddy AI account
answers deepseek-v4.1-flash with 200, plain and with DeepSeek Harness's
real main-turn and title bodies, through plugin 0.2.6 (current
5.9.3 headers). The owner's China (copilot.tencent.com) sign-in is
refused 401 since 10-29 and its refresh token too, so the China site,
the reporter's, couldn't be asked. No plugin change.

Fix: a Rest carries Error, the vendor's words (provider.APIError, cut to
300 runes), set where restAfterMarked makes every real rest, kept in the
rest note and sent with each try's and order's rest. The Routing page's
stage row, Accounts table and per-model rest line say the status for a
failure of no named kind ("500 · failed · back in 16s") and show the
vendor's words as the tooltip. Kinds that name themselves read as before.
No new strings.

Run (mote):
- go test ./internal/gateway -run 'TestRestCarriesTheVendorsWords|TestCarried|TestOneRequestDoesNotClimb': ok
- broken by hand: without Error set, TestRestCarriesTheVendorsWords is red
  ("the rest says \"\", not the vendor's words")
- gofmt -l; go vet ./internal/gateway for darwin, linux, windows: clean
- GUI, new routing-rest-error.test.cjs (5 languages, 1100 and 420px):
  chromium 10/10 on mote; webkit on Linux (wsl magpie-desktop) with
  routing-model-rest, rest-probed, routing-rest-off: 50/50. WebKit
  doesn't launch on mote at the moment (browserType.launch timeout at
  180s, untouched routing-model-rest the same), so it ran there.
- chromium on Linux: routing-rest-error, routing-model-rest, rest-probed,
  routing-rest-off, provider-limit-rest, rest-try-now, key-rest-date,
  routing-lifted-elsewhere, routing-day-tallies: 126/126
- broken by hand: origin/main's client.js with the new GUI test is red
  ("a@x.test: the stage row says failed · back in 16 s")
- rebased on 03f609e3f: the Go test and routing-rest-error again ok;
  i18n-keys red on "Unmarked" in internal/usage/search_calls_test.go,
  which this change doesn't touch: #4524

Not tried: the China WorkBuddy site (no signed-in account), so the
reporter's actual error text is unknown; the Windows desktop app itself;
the full Go and GUI suites (owner's rule: not held behind them).
2026-10-31 14:30:15 +08:00

112 lines
6.7 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// An account resting after a failure that names no kind says the status
// it answered, and the vendor's words are over the row, on the stage and
// in the Accounts table (GanHei37443 on X: three WorkBuddy accounts each
// "failed · back in 16s", and nothing on the page said why). A rest that
// names its kind (quota used up) reads as before. In every language, at a
// wide and a narrow window, in both engines.
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 soon = new Date(now.getTime() + 16e3).toISOString();
const later = new Date(now.getTime() + 10 * 3600e3).toISOString();
const said = "WorkBuddy: model deepseek-v4.1-flash is not available right now";
const seat = (user, rest) => ({
id: "workbuddy@" + user, provider: "workbuddy", name: "WorkBuddy", kind: "account", icon: "workbuddy",
who: user, plan: "Free", model: "deepseek-v4.1-flash", rest,
});
const failed = (user) => ({ why: "other", status: 500, until: soon, by: "cooldown", key: "workbuddy@" + user, error: said });
const spent = { why: "quota", status: 429, until: later, by: "window", key: "workbuddy@d@x.test" };
function routes() {
const order = [], tries = [];
for (const user of ["a@x.test", "b@x.test", "c@x.test"]) {
const rest = failed(user), s = seat(user, rest);
order.push(s);
tries.push({ id: s.id, model: s.model, start, done: true, status: 500, ms: 300, fail: "other", rest, error: said });
}
const d = seat("d@x.test", spent);
order.push(d);
tries.push({ id: d.id, model: d.model, start, done: true, status: 429, ms: 300, fail: "quota", rest: spent, error: "quota" });
return [{ id: 1, seq: 1, time: start, agent: "codex", model: "group/g", provider: "workbuddy", order, tries, done: true, status: 500, ms: 2000, error: said }];
}
function serve(lang) {
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: 1 }, routes: routes() });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
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 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 ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}px: a plain failure's rest says its status and the vendor's words`, 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);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
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}-rest-error.png`), fullPage: true });
}
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-act").first().waitFor();
const stage = (user) => page.locator("li", { has: page.locator("code.mdl") }).filter({ has: page.locator(".who", { hasText: user }) });
for (const user of ["a@x.test", "b@x.test", "c@x.test"]) {
const li = stage(user);
await li.first().waitFor({ state: "attached" });
await li.first().evaluate((e) => new Promise((done) => { const ok = () => e.classList.contains("rest") ? done() : requestAnimationFrame(ok); setTimeout(done, 5000); ok(); }));
assert.equal(await li.count(), 1, `${user}: one stage row`);
const em = li.locator("em");
const text = (await em.textContent()).trim();
assert(text.startsWith("500 · "), `${user}: the stage row says ${text}`);
assert.equal(await em.getAttribute("title"), said, `${user}: the stage row's words`);
const act = page.locator(".rt-act", { hasText: user });
assert.equal(await act.count(), 1);
const st = act.locator(".st.rest");
assert((await st.textContent()).startsWith("500 · "), `${user}: the Accounts table says ${await st.textContent()}`);
assert.equal(await st.getAttribute("title"), said, `${user}: the Accounts table's words`);
}
const d = stage("d@x.test").locator("em");
assert(!(await d.textContent()).trim().startsWith("429"), `a quota rest says its status: ${await d.textContent()}`);
assert.equal(await d.getAttribute("title"), null, "a rest without words has a tooltip");
assert(!(await sideways(page)), "the page scrolls sideways");
assert.deepEqual(errors, []);
});
}
}
}