anewuser6937 (Discord, plugins#590) saw one model in WorkBuddy's editor
and took the plugin for broken. They had turned on "Free models only"
themselves, but its label and description read in English in the Chinese
window, and nothing by the models said the list was filtered.
A plugin option (auth.options, magpie's own field; OpenCode's AuthHook is
provider/loader/methods and never reads it) may now give `labels`,
`descriptions` and `confirms`, each keyed by the window's language
("zh", "zh-TW", "ja", "de"), beside the plain strings, as a page's
`titles` do. The host keeps only non-empty strings under language names
of 16 or less, 16 languages at most, each capped as the plain one is
(60/300/300). The editor shows the exact language, then its first part
(zh-TW reads zh), else the plain words, in the row, the hint, and the
confirm dialog and its title. `filtersModels: true` says the plugin's
model list leaves models out while the switch is on; while one is on, as
saved, the Models field says under the chips "Only some models are
listed: the plugin option “…” is on." (zh 只列出部分模型:插件选项「…」已开启。,
zh-TW, ja, de too). An older plugin shows what it showed before, and an
older magpie shows a new plugin's plain words with no note.
WorkBuddy 0.2.10 gives "Free models only" in all four languages with
filtersModels (magpie-community/plugins aec58ae, on npm: `npm view
@magpie-community/opencode-workbuddy-auth@0.2.10 --prefer-online` on mote
says 0.2.10, latest), and the mover's min is raised to it so every moved
user gets it. The CLI's `magpie plugin options` stays English, as the CLI is.
The core scripts would have gone 608 bytes over their budget; three of the
provider editor's comments in app.js are cut down instead, no raise
(1,532,865 of 1,533,105).
Run, on mote (mote-run), at this tree:
- node --test plugin-option-words.test.cjs (new): Chromium and WebKit,
1100 and 420 wide, en/zh/zh-TW/ja/de, switch on and off: each
language's label and description, zh-TW falling back to zh and ja/de to
the plain words for a zh-only option, the note exactly once under the
chips in a .hint inside the editor with no sideways scroll, none while
off, the confirm in the language. With app.js put back: 19 of 21 red
in Chromium (only "en off" passes, both widths).
- With plugin-options.test.cjs and i18n-keys.test.cjs, both engines:
68 pass, 0 fail.
- go test ./internal/plugin ./internal/provider ./internal/cli: ok.
TestPluginOptions with host.js put back: red (empty maps, FiltersModels
false). The real WorkBuddy 0.2.10 index.mjs loaded into this host
(a temporary test, not kept): plugin.Providers lists free_only for
workbuddy and workbuddy-ai with all four languages and filtersModels true.
- go test ./internal/gui: TestCoreScriptBudget ok after the cut. Red,
and red the same at origin/main ed5872d18 (run there too):
TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
/macOS_26_SDK on macOS 27 (#3949); TestColdTurnsTaken red once in the
package run and passed at origin/main (#4510, the same 0.00s red).
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./...: ok.
- plugins: HOME=$(mktemp -d) bun test packages/workbuddy 303 pass 0
fail; the new freeonly test red 2 of 2 with index.mjs put back.
Not run: the whole GUI suite. mote and the WSL box were each running
another session's full GUI suite (hours left on both), and one runs per
machine; it runs on mote once that one ends. Not tried: a real WorkBuddy
account in the real app window. go test ./... was not run.
120 lines
8.6 KiB
JavaScript
120 lines
8.6 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A plugin option in the reader's language, and a short model list said to
|
|
// be filtered (plugins#590, anewuser6937 on Discord): WorkBuddy's "Free
|
|
// models only" showed in English inside the Chinese window, and with it on
|
|
// the editor listed one model with nothing saying why, so the plugin read as
|
|
// broken. The option's labels, descriptions and confirms give its words by
|
|
// the window's language (zh-TW falls back to zh, any other to the plain
|
|
// one), and while a switch that says filtersModels is on, as saved, the
|
|
// Models field says so under the chips. Off, nothing is said. Both engines,
|
|
// 1100 and 420 wide, every language.
|
|
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 free = (on) => ({
|
|
key: "free_only", label: "Free models only", description: "Lists only the models WorkBuddy serves at no cost.",
|
|
labels: { zh: "仅免费模型", "zh-TW": "僅免費模型", ja: "無料モデルのみ", de: "Nur kostenlose Modelle" },
|
|
descriptions: { zh: "只列出 WorkBuddy 免费提供的模型。", "zh-TW": "只列出 WorkBuddy 免費提供的模型。", ja: "WorkBuddy が無料で提供するモデルだけを表示します。", de: "Listet nur die Modelle, die WorkBuddy kostenlos anbietet." },
|
|
filtersModels: true, on,
|
|
});
|
|
// only Simplified Chinese words: zh-TW reads them, the rest the plain ones
|
|
const beta = { key: "beta", label: "Beta models", confirm: "Beta models may be withdrawn.", labels: { zh: "测试版模型" }, confirms: { zh: "测试版模型可能会下线。" }, on: false };
|
|
|
|
function serve(lang, on) {
|
|
const plugin = { id: "workbuddy", pid: "workbuddy", name: "WorkBuddy", icon: "generic", spec: "@magpie-community/opencode-workbuddy-auth", signedIn: true, models: 1,
|
|
methods: [{ type: "api", label: "API key" }], options: [free(on), beta] };
|
|
const payload = { providers: [{ id: "workbuddy", name: "WorkBuddy", icon: "generic", chat: "plugin://workbuddy/v1", responses: "", anthropic: "", catalog: "",
|
|
models: [{ id: "hy3", name: "Hy3", on: true }], agents: [], fallback: [], headers: {}, keyList: [], key: {}, proxy: "", maxConcurrency: null,
|
|
account: { agent: "workbuddy", agentName: "WorkBuddy", agentIcon: "generic", user: "me@fake", logins: [{ user: "me@fake", active: true, on: true }] } }],
|
|
// moved onto its plugin, as every WorkBuddy user is since 10-17
|
|
presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [plugin], onPlugins: ["workbuddy"] };
|
|
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:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json(payload);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const W = {
|
|
en: { models: "Models", on: "On", label: "Free models only", about: "Lists only the models WorkBuddy serves at no cost.", beta: "Beta models", ask: "Beta models may be withdrawn.",
|
|
note: "Only some models are listed: the plugin option “Free models only” is on." },
|
|
zh: { models: "模型", on: "开启", label: "仅免费模型", about: "只列出 WorkBuddy 免费提供的模型。", beta: "测试版模型", ask: "测试版模型可能会下线。",
|
|
note: "只列出部分模型:插件选项「仅免费模型」已开启。" },
|
|
"zh-TW": { models: "模型", on: "開啟", label: "僅免費模型", about: "只列出 WorkBuddy 免費提供的模型。", beta: "测试版模型", ask: "测试版模型可能会下线。",
|
|
note: "只列出部分模型:外掛選項「僅免費模型」已開啟。" },
|
|
ja: { models: "モデル", on: "オン", label: "無料モデルのみ", about: "WorkBuddy が無料で提供するモデルだけを表示します。", beta: "Beta models", ask: "Beta models may be withdrawn.",
|
|
note: "一部のモデルのみ表示しています。プラグインのオプション「無料モデルのみ」がオンです。" },
|
|
de: { models: "Modelle", on: "An", label: "Nur kostenlose Modelle", about: "Listet nur die Modelle, die WorkBuddy kostenlos anbietet.", beta: "Beta models", ask: "Beta models may be withdrawn.",
|
|
note: "Nur einige Modelle werden angezeigt: Die Plugin-Option „Nur kostenlose Modelle“ ist an." },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a plugin option's own words and its filtered list", async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const width of [1100, 420]) for (const lang of Object.keys(W)) for (const on of [true, false]) {
|
|
await t.test(`${width} ${lang} ${on ? "on" : "off"}`, async () => {
|
|
const w = W[lang];
|
|
const ctx = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" });
|
|
const page = await ctx.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, on));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider", { hasText: "WorkBuddy" }).click();
|
|
const ed = page.locator("#modal .editor");
|
|
const box = ed.locator(".plugin-options");
|
|
await box.waitFor();
|
|
await page.waitForTimeout(300); // the editor drawn again as what it asked for comes in
|
|
const row = (k) => box.locator(`.plugin-option[data-key="${k}"]`);
|
|
assert.equal(await row("free_only").locator(".n").textContent(), w.label);
|
|
assert.equal(await row("free_only").locator(".hint").textContent(), w.about);
|
|
assert.equal(await row("beta").locator(".n").textContent(), w.beta);
|
|
|
|
// the Models field: its label, then the chips, the note under them
|
|
const models = ed.locator("label", { hasText: new RegExp("^" + w.models + "$") }).first();
|
|
await models.waitFor();
|
|
const field = models.locator("xpath=following-sibling::div[1]");
|
|
const notes = await field.locator(":scope > .hint").allTextContents();
|
|
if (on) {
|
|
assert.deepEqual(notes, [w.note]);
|
|
const where = await field.evaluate((f) => {
|
|
const hint = f.querySelector(":scope > .hint"), chips = f.firstElementChild, r = f.closest(".editor").getBoundingClientRect(), h = hint.getBoundingClientRect();
|
|
return { below: h.top >= chips.getBoundingClientRect().bottom - 1, spill: h.right - r.right, page: document.documentElement.scrollWidth - document.documentElement.clientWidth };
|
|
});
|
|
assert.ok(where.below, "the note is under the chips");
|
|
assert.ok(where.spill <= 0, "the note runs past the editor by " + where.spill);
|
|
assert.ok(where.page <= 0, "the page scrolls sideways by " + where.page);
|
|
if (process.env.ARTIFACT_DIR) await field.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `plugin-option-words-${engine}-${width}-${lang}.png`) });
|
|
} else {
|
|
assert.deepEqual(notes, [], "nothing said while the switch is off");
|
|
}
|
|
|
|
// its confirm in the reader's language too
|
|
await row("beta").locator(".opt", { hasText: w.on }).click();
|
|
const dialog = page.locator("dialog.action-confirm");
|
|
await dialog.waitFor();
|
|
assert.equal(await dialog.locator("p").textContent(), w.ask);
|
|
assert.ok((await dialog.locator("h2").textContent()).includes(w.beta));
|
|
assert.deepEqual(errors, []);
|
|
await ctx.close();
|
|
});
|
|
}
|
|
});
|
|
}
|