Files
magpie/internal/gui/tests/font-cascade.test.cjs
T
yetone eb7199e120 gui: Routing is a plugin's page, its script, style and words in plugins/routing (P2)
P2 of docs/subsystems/plugin-runtime.md, the third page after Sessions
and Library.

- routing.js and routing.css move to assets/plugins/routing/ (client.js,
  routing.css). Its part's html is the page's head and boxes that were
  index.html's <main id="view-routing">; the rest is drawn by
  routingPage, run at mount since it builds on app.js. It keeps itself
  after that as it did (its own hidden, the language, focus), so its
  hooks are dirty and discard, a routing group being edited, which
  show() and the window's close ask through magpie.call:
  window.routingDirty and discardRouting are gone.
- plugins/routing: Essential, Requires window and gateway, in use while
  the user has a routing group (not Auto, not Hidden), since the page is
  where it is edited. The gateway routes the same with it off.
- With it off, what leads to the page goes too: the nav and panel tabs
  and the panel's section (data-feature="routing"), the guide's Open
  Routing, Providers' "Make a routing group of …", the Usage list's
  View routing and its time as a link, the context card's Latest
  request. A panel left on its Routing tab shows Agents.
- What other pages use of it stays on window: openRoute (context.js),
  kindName, swapWhy, routedWhy (Usage's Requests), newGroupWith
  (Providers), panelRoutingShown (the panel).
- The 505 strings only Routing says move from i18n.js to
  plugins/routing/i18n.js (4 languages); i18n.js 17048 → 15032 lines.
  The plugin's own name and line stay in i18n.js: the Plugins page
  says them with the plugin off (TestBuiltinsTranslated).
- Tests and comments that named routing.js name the new path (gateway's
  antigravity_rest and loop_guard, codeassist.go, usage.go,
  web_compress, group_member_info, assets_revalidate, font-cascade,
  win-fonts, three routing-*.test.cjs). builtins.test.cjs and
  builtins_test.go count seven built-ins and switch Routing off: its
  tabs go, the page shown stays.
- docs: plugin-runtime.md, gui-shell.md, gateway-routing.md.

Run, first on origin/main 3ec45e715, then after rebasing onto af27b70b4
(main's routing.js, css, app.js and i18n.js changes since were carried
into the moved files; its new Routing words, as the rules' conditions,
are in the plugin's i18n.js):
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- go test -count=1 ./internal/gui ./internal/gateway ./internal/usage
  ./internal/pluginrt ./plugins/...: ok (gateway 1800s under load,
  -timeout 45m; gui with -skip TestMainWindowCorners, #1936).
- All 193 GUI test files, 3 at a time at load ~250, Chromium and WebKit,
  at the Usage commit on 743fcc035: 185 and 186 green. Every red run
  alone here and on a just-fetched origin/main c524bc018:
  - the same on main: routing-model-rest (#2115), routing-wb-restricted
    (#1905), usage-agents-hide (11 of 16 in both, #2211), usage-fold
    (#2163: 12 of 14 here, 9 of 14 on main over 7 runs, the same 4px),
    quota-count-wrap and quota-name-translated in WebKit (#2228);
  - red only under load, green alone on both: routing-flood (#2215),
    routing-log-icons, usage-ledger (#2211), and three plugin-* files
    whose tree was rebased under them mid-run.
- days-fit, failed-open, side-calls and burst-speed, red on main after
  cf455ebd5, are fixed before this commit (#2134, d692b2548).
2026-10-15 01:32:12 +08:00

46 lines
2.9 KiB
JavaScript

// Defaults keep the authored cascade, including a code span under bold UI.
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 choice = (family, weight, style) => ({ family, name: "Chosen", weight, style, stretch: 100 });
for (const [name, engine] of [["chromium", chromium], ["webkit", webkit]]) {
test(`${name}: font reset restores the original cascade and explicit emphasis`, async () => {
const css = (await Promise.all(["app.css", "plugins/library/library.css", "plugins/routing/routing.css", "plugins/sessions/sessions.css", "plugins.css"].map(f => fs.readFile(path.join(assets, f), "utf8")))).join("\n");
const js = await fs.readFile(path.join(assets, "fonts.js"), "utf8");
const browser = await engine.launch();
try {
const page = await browser.newPage();
await page.setContent(`<style>${css}</style>
<div class="sess-line"><b><code id="code">model-id</code></b></div>
<b><span class="key none" id="ui">No key</span></b>
<div class="acc"><input id="emphasis" class="rename mono" value="Account"></div>
<span id="badge" class="mk-badge">Code badge</span>`);
await page.addScriptTag({ content: js });
const read = () => page.evaluate(() => ["code", "ui", "emphasis", "badge"].map(id => {
const s = getComputedStyle(document.getElementById(id));
return { weight: s.fontWeight, style: s.fontStyle, family: s.fontFamily };
}));
const defaults = await read();
assert.equal(defaults[0].weight, "400", "code's authored regular weight must not inherit its bold parent");
assert.equal(defaults[1].weight, "400", "a UI family override must not discard the key's authored weight");
assert.equal(defaults[2].weight, "450");
await page.evaluate(s => window.desktopFonts.apply(s), { uiFont: choice("Arial", 500, "normal"), codeFont: choice("Consolas", 700, "italic") });
const picked = await read();
assert.equal(picked[0].weight, "700");
assert.equal(picked[0].style, "italic");
assert.equal(picked[1].weight, "500");
assert.equal(picked[2].weight, "450", "component emphasis stays explicit");
await page.evaluate(() => window.desktopFonts.apply({}));
assert.deepEqual(await read(), defaults, "reset restores every original font trait");
await page.evaluate(s => window.desktopFonts.apply(s), { uiFont: choice("Arial", 600, "italic"), codeFont: choice("Consolas", 400, "normal") });
const independent = await read();
assert.equal(independent[3].weight, "400");
assert.equal(independent[3].style, "normal", "code badges don't inherit the chosen interface slope");
} finally { await browser.close(); }
});
}