Files
magpie/internal/gui/tests/routing-classifier-above.test.cjs
T
yetone 22f69ae443 gateway, routing: a group in a group says the group above picked its reasoning (#4358)
30c55ff5e skips a nested group's effort classifier once the group above
picked, and traced it as Classified{Error: "the group above already
picked this turn's reasoning"}. The Routing page reads an Error with no
intents as "{by} was to rate how hard turn {turn} is, but couldn't —
{err} — so it reasons as the agent asked", which is wrong: the turn
reasons at the group above's pick.

Classified gets Above, the pick of the group above, in place of that
Error (also on a classifier still asked for intents), and classWhy says
"{by} wasn't asked how hard turn {turn} is: the group above picked
{level} reasoning for it.", in zh, zh-TW, ja and de too.
TestNestedGroupClassifierNotAskedWhenTheParentPicked checks the nested trace carries
Above "high" and no Error; routing-classifier-above.test.cjs checks the
line in every language at 1100px and 390px, with no sideways scroll
and without the old "reasons as the agent asked".

Run on mote: go test -tags nogui ./internal/gateway/ -run
'Nested|Classif|Intent|Effort|Rule' ok; node --test (chromium and
webkit) routing-classifier-above, routing-classifier-said,
routing-intent-fallback, routing-smart-intent and i18n-keys: 124 of 124
pass. Broken by hand: classWhy without the Above branch, the new GUI
file 0 of 10 in chromium.
Not tried: a real nested effort=auto group.

The whole batch (101e6201c..this, gua2100's five patches and three
follow-ups) at this tree, on mote: gofmt -l clean; go vet -tags nogui
for GOOS darwin, linux, windows, and go vet (GUI) darwin, all ok;
go test -tags nogui -count=1 -timeout 45m ./...: 85 packages ok and 2
reds, neither from this batch. internal/cli
TestEveryRouteHasACommandOrIsNamed is red at origin/main ad53a23dc too
(POST /api/usage/checkin-account, from e87140242; #4826). internal/gateway
TestCodexPoolSaysTheClientsVersion passes alone 3 of 3 at the base and at
this head (#4807).
2026-11-02 07:40:21 +08:00

110 lines
6.4 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// A group in a group, effort=auto of its own, isn't asked how hard the
// turn is once the group above picked its reasoning (#4358): the Routing
// page says it wasn't asked and what the group above picked, not that it
// "couldn't" and the turn "reasons as the agent asked", which the turn
// doesn't. In every language, and at a phone's width.
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 models = [
{ id: "a/fast", name: "fast", providerName: "A", icon: "generic", context: 256000, ready: true },
];
const groups = () => ({
models,
groups: [
{ id: "quality", name: "Quality", members: ["a/fast"], routing: "order", ready: true, classifier: "cc/cls", effort: "auto",
memberInfo: [{ id: "a/fast", ready: true, context: 256000 }] },
{ id: "main", name: "Main", members: ["group/quality"], routing: "order", ready: true, classifier: "cp/cls", effort: "auto",
memberInfo: [{ id: "group/quality", ready: true, context: 256000 }] },
],
pools: [],
});
const now = Date.now();
const routeOf = () => ({
id: 7, seq: 7, time: new Date(now - 2000).toISOString(), agent: "claude", model: "main", provider: "a", done: true, status: 200, ms: 900, tokens: 9000,
effort: "medium",
group: { id: "main", name: "Main", members: ["group/quality"] },
order: [{ id: "a", provider: "a", name: "A", kind: "key", model: "fast", known: true, via: ["quality"] }],
tries: [{ id: "a", model: "fast", start: new Date(now - 2000).toISOString(), done: true, ms: 800, status: 200, effort: "high" }],
rule: { turn: 2, tokens: 9000, pick: "high", classified: { by: "cp/cls", intents: null, effort: "high", score: 2.2, ms: 300 } },
nested: [{ group: "quality", name: "Quality", rule: { turn: 2, tokens: 9000, classified: { by: "cc/cls", intents: null, above: "high" } } }],
});
// what the group in it says, in each language
const words = {
en: "cc/cls wasn't asked how hard turn 2 is: the group above picked high reasoning for it.",
zh: "cc/cls 未被要求评估第 2 轮的难度:上一层分组已为这一轮选了 high 推理强度。",
"zh-TW": "cc/cls 未被要求評估第 2 輪的難度:上一層群組已為這一輪選了 high 推理強度。",
ja: "cc/cls にはターン 2 の難しさを尋ねていません。上位のグループがこのターンの推論に high を選んだためです。",
de: "cc/cls wurde nicht gefragt, wie schwer Runde 2 ist: Die Gruppe darüber hat für sie high als Reasoning gewählt.",
};
// what it said before: that it couldn't, and the turn reasons as asked
const before = {
en: "reasons as the agent asked", zh: "按 agent 要求的推理强度", "zh-TW": "按 agent 要求的推理強度",
ja: "エージェントの指定どおりに推論します", de: "vom Agenten verlangte Reasoning",
};
function serve(lang, route) {
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
let first = true;
return async (r) => {
const url = new URL(r.request().url());
const json = (data) => r.fulfill({ json: data });
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
const routes = first ? [route] : [];
first = false;
return json({ mine: true, now: new Date().toISOString(), seq: 7, totals: { requests: 1, rerouted: 0, errors: 0 }, 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, url: "http://127.0.0.1:3999" } });
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 r.fulfill({ body: await fs.readFile(file), contentType });
};
}
async function open(t, engine, lang, width) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 1400 } })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, routeOf()));
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-group").first().waitFor();
return { page, errors };
}
const text = (page) => page.evaluate(() => document.documentElement.innerText);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(words)) {
for (const width of [1100, 390]) {
test(`${engine} ${lang} ${width}px: a group in a group says the group above picked its turn's reasoning`, async (t) => {
const { page, errors } = await open(t, engine, lang, width);
await page.waitForFunction((s) => document.documentElement.innerText.includes(s), words[lang]).catch(() => {});
const said = await text(page);
assert(said.includes(words[lang]), `told: ${said.slice(0, 3000)}`);
assert(!said.includes(before[lang]), "not told it reasons as the agent asked");
assert(!/\{(by|turn|level)\}/.test(said), "no placeholder left");
const wide = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
assert(wide <= 0, `no sideways scroll: ${wide}px`);
assert.deepEqual(errors, []);
});
}
}
}