Files
magpie/internal/gui/tests/win-fonts.test.cjs
T
yetone 8da304767a gui: Library is a plugin's page, its script, style and words in plugins/library
P2 of docs/subsystems/plugin-runtime.md, the second page after Sessions.

- library.js and library.css move to assets/plugins/library/ (client.js,
  library.css). The script registers with the kernel
  (magpie.plugin("library")) and adds its page to the "page" slot. Its
  hooks: open and relang load, redraw, close (its modal), dirty, discard.
  What it set up at load (list scroll and resize, the modal's backdrop
  and Escape, beforeunload, the stuck header, a quiet reload on focus)
  runs in mount.
- app.js calls those through magpie.call instead of window.loadLibrary,
  redrawLibrary, closeLibraryModal, libraryDirty and discardLibrary. It
  no longer lists library in its title map, hide loop or OPEN_VIEWS; the
  kernel's pages are in them.
- index.html: <main id="view-library"> goes, the kernel makes it.
  library.css keeps its place in the cascade.
- The 560 strings only Library says move from i18n.js to
  plugins/library/i18n.js (4 languages). i18n.js: 18826 → 16584 lines.
- plugins/library/library.go lists the client files.
- Tests that read i18n.js for a Library string read strings.cjs (i18n.js
  and the plugins'): 8 library tests and mcp-editor-cancel,
  mcp-oauth-app, mcp-signin-health. font-cascade, win-fonts and
  assets_revalidate_test.go name the new paths.
- "Check again" stays in i18n.js: Library said it alone when the words
  were split, and a5d72a095 (Settings' search keys) says it too since.
  i18n-keys has a new test, "a plugin's words are its own": a key in a
  plugin's i18n.js that any file outside the plugin's folder says fails
  it, naming the file. It was red on this key, and search-keys.test.cjs
  said "Check again" had no zh translation.
- docs: library.md, gui-shell.md, plugin-runtime.md.

Run, at this tree:
- 101 GUI test files touching Library, skills, MCP, the plugins, the
  shell and every language (gui-de/ja/zh-tw, i18n-keys, page-width,
  view-no-sideways, mobile-web, text-size, …): Chromium and WebKit, 4 at
  a time, all green but one. text-size's "zh: 100% picked at the foot"
  failed once in Chromium under load ("scrolled from 160 to 109 (max
  115)"); it passed alone, 6 at once here and on origin/main 8f34bbcd1,
  and at 6× and 12× CPU throttling. It's the Settings page, already
  "fixed" by 50dd39104, so I filed it as #2058.
- After rebasing onto origin/main 75cbc7e1e: i18n-keys, search-keys,
  library-mcp-tools, library-all, gui-de, mono-icon-redraw,
  group-first-token, Chromium and WebKit, green.
- go test ./internal/gui/ ./internal/pluginrt/ ./plugins/...; gofmt;
  go vet on darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
2026-10-14 08:33:25 +08:00

40 lines
2.3 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// Code text on Windows (#690): every monospace text in the GUI takes --code,
// and on Windows (html.win) --code is Cascadia Mono / Consolas with YaHei UI
// for Chinese, never the generic monospace alone, which a Chinese Windows
// draws in SimSun (thin, unhinted at 11px). Elsewhere --code stays the Mac's.
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 sheets = ["app.css", "plugins/library/library.css", "routing.css", "plugins/sessions/sessions.css", "plugins.css"];
test("no stylesheet names a monospace stack of its own", async () => {
for (const f of sheets) {
const css = await fs.readFile(path.join(assets, f), "utf8");
const lines = css.replace(/\/\*[\s\S]*?\*\//g, "").split("\n").filter((l) => /monospace/.test(l) && !/--code:/.test(l));
assert.deepEqual(lines, [], `${f} has a monospace stack of its own`);
}
});
test("code text on Windows is Cascadia Mono / Consolas with YaHei UI", async () => {
const css = (await Promise.all(sheets.map((f) => fs.readFile(path.join(assets, f), "utf8")))).join("\n");
const browser = await (process.env.BROWSER === "webkit" ? webkit : chromium).launch();
try {
const page = await browser.newPage();
await page.setContent(`<style>${css}</style>
<span class="mk-badge">远程 · 需登录</span><span class="mk-id">atlassian</span>
<div class="rt-accts"><b><code class="mdl">gpt-6.1-sol</code></b></div>
<div class="signing"><div class="signlink"><code>https://x</code></div></div>`);
const fams = () => page.evaluate(() => [".mk-badge", ".mk-id", ".rt-accts code.mdl", ".signing .signlink code"].map((s) => getComputedStyle(document.querySelector(s)).fontFamily));
for (const f of await fams()) assert.match(f, /^ui-monospace, "?SF Mono"?, Menlo/, "the Mac's stack off Windows");
await page.evaluate(() => document.documentElement.classList.add("win"));
for (const f of await fams()) assert.match(f, /^"?Cascadia Mono"?, Consolas, "?Microsoft YaHei UI"?/, "Windows' stack");
} finally {
await browser.close();
}
});