Files
magpie/internal/gui/tests/omp-roles.test.cjs
T
yetone 744ffcde8b agent, gui: omp's commit, tiny and memory roles are picked on its row too, each with its own thinking level (#1397, KKKKKKKEM)
KKKKKKKEM (#1397, on v0.1.1164): plan, vision and advisor work on the
Mac, but the commit and tiny roles were still missing.

omp's own list of chat roles is CHAT_MODEL_ROLE_IDS in pi-tui's
overlays/model-browser.ts (read in the installed 18.6.1 and in 18.8.8 from
npm, the same list): default, smol, slow, vision, plan, commit, tiny,
memory, task, advisor. fc5dfa3c covered all but commit, tiny and memory;
this adds the three the same way (ompAt's role(), Quiet, a "<role>
thinking" field each, written under modelRoles in ~/.omp/agent/config.yml,
a value the user set off magpie stashed and put back on reset). omp's
other roles (KIND_ROLE_IDS: image, web, speech, dictation, judge) are for
kinds of model other than the chat models magpie writes for omp and are
left out.

In the GUI they join the roles square. Unset, each says what omp does
instead, from omp's source: commit and tiny take the smol role's model
(commit/model-selection.ts tries commit then smol; ROLE_CONFIGURED_FALLBACK
tiny → smol), memory the tiny role's, else smol's (memory → tiny). New
strings in zh, zh-TW, ja and de.

Tests:
- TestOmpEveryChatRole (Go): every chat role in omp's list is a field,
  set to a magpie model and to a level; the user's own tiny role comes
  back on reset. Red on the old omp.go (commit role: nil).
- omp-roles.test.cjs: the square lists commit, tiny and memory with their
  unset notes, and commit's picker leads with "the smol role's model";
  now in en, zh, ja and de, Chromium and WebKit, 1100px and 390px (16/16).
  Red on the old app.js.
- i18n-keys, gui-ja, gui-de, gui-zh-tw pass; gofmt -l, GOOS=linux and
  GOOS=windows go vet on internal/agent and internal/gui pass.
- go test -tags nogui ./... at load ~170: all packages pass except
  internal/agent, gateway, library (10m timeouts) and gui
  (TestOTelPreferencesAPI) and agent's TestCodexCustomProviderModelHasEfforts
  / TestPiAgentDir in one run each; rerun with -timeout 40m after the
  rebase, internal/agent, internal/gui, internal/gateway and
  internal/library all pass, and the two agent tests pass alone (-count=3).
2026-10-11 00:28:27 +08:00

227 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// omp's roles share one square after the model picker, as Claude Code's
// tiers do (#325, #1397): subagents, smol, slow, plan, vision, advisor,
// commit, tiny and memory (every chat role omp 18.8 has), each with the model it is on or what it takes unset, and a role on one
// model has its thinking level under it (KKKKKKKEM: the slow role at its
// own level). Picking a role opens the model picker for it, "Same as model"
// first for a role that follows the model; picking its level opens the
// level slider, which writes that role's level. OpenCode's small model,
// which doesn't follow the model, stays a picker; a named profile of omp
// (omp#work) has the same square. In the connected agent's
// opened row, in English, Chinese, Japanese and German, wide and at 390px.
// No backend: the API is faked here.
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 options = [
{ value: "magpie/deepseek/pro", label: "DeepSeek Pro", ref: "deepseek/pro" },
{ value: "magpie/deepseek/flash", label: "DeepSeek Flash", ref: "deepseek/flash" },
];
const LEVELS = ["auto", "off", "minimal", "low", "medium", "high", "xhigh", "max"].map((value) => ({ value }));
const field = (key, label, value) => ({ key, label, value, options });
// a role's level is offered while the role is on a model, as omp.go does
const level = (key, label, on) => ({ key: key + "_thinking", label: label + " thinking", value: "", options: on ? LEVELS : [] });
const fresh = () => ({
agents: [
{
id: "omp", name: "omp", path: "/test/config.yml", icon: "omp", wired: true,
fields: [
field("model", "model", "magpie/deepseek/pro"),
field("subagent", "subagents", ""), level("subagent", "subagents", false),
field("small", "smol", ""), level("small", "smol", false),
field("slow", "slow", "magpie/deepseek/flash"), level("slow", "slow", true),
field("plan", "plan", ""), level("plan", "plan", false),
field("vision", "vision", ""), level("vision", "vision", false),
field("advisor", "advisor", ""), level("advisor", "advisor", false),
field("commit", "commit", ""), level("commit", "commit", false),
field("tiny", "tiny", ""), level("tiny", "tiny", false),
field("memory", "memory", ""), level("memory", "memory", false),
{ key: "effort", label: "thinking", value: "", options: LEVELS.filter((l) => l.value !== "off") },
],
},
// a named profile of omp (#1233) has the same roles
{ id: "omp#work", name: "omp · work", path: "/test/profiles/work/config.yml", icon: "omp", wired: true,
fields: [field("model", "model", "magpie/deepseek/pro"), field("slow", "slow", "magpie/deepseek/flash"), level("slow", "slow", true), field("plan", "plan", ""), level("plan", "plan", false)] },
{ id: "opencode", name: "OpenCode", path: "/test/opencode.json", wired: true, fields: [field("model", "model", "magpie/deepseek/pro"), field("small", "small", "")] },
],
profiles: [],
});
function server(lang, sets) {
let cur = fresh();
return async (route) => {
const req = route.request(), url = new URL(req.url());
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 route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
if (url.pathname === "/api/set") {
const body = req.postDataJSON();
sets.push({ agent: body.agent, field: body.field, value: body.value });
cur = JSON.parse(JSON.stringify(cur));
const fields = cur.agents.find((a) => a.id === body.agent).fields;
fields.find((f) => f.key === body.field).value = body.value;
const lv = fields.find((f) => f.key === body.field + "_thinking");
if (lv) lv.options = body.value ? LEVELS : [];
return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
}
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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), contentType });
};
}
// the words as i18n.js has them
const W = {
en: {
roles: ["subagents", "smol", "slow", "slow thinking", "plan", "vision", "advisor", "commit", "tiny", "memory"],
follows: "same as model (DeepSeek Pro)", own: "omp's own pick", advisor: "the slow role's model, else omp's own pick",
smol: "the smol role's model", memory: "the tiny role's model, else the smol role's",
session: "the session's thinking level", same: "Same as model", summary: "roles: slow", high: "high", summarySet: "roles: slow (high)",
},
zh: {
roles: ["子代理", "小模型", "慢模型", "慢模型思考", "规划", "视觉", "顾问", "提交", "微模型", "记忆"],
follows: "同主模型(DeepSeek Pro)", own: "由 omp 自己挑选", advisor: "慢模型角色的模型,未设置时由 omp 自己挑选",
smol: "小模型角色的模型", memory: "微模型角色的模型,未设置时用小模型角色的",
session: "跟随会话的思考强度", same: "同主模型", summary: "角色:慢模型", high: "高", summarySet: "角色:慢模型 (高)",
},
ja: {
summary: "ロール:低速",
roles: ["サブエージェント", "小", "低速", "低速の思考", "プラン", "ビジョン", "アドバイザー", "コミット", "極小", "メモリー"],
own: "omp が自分で選ぶ", advisor: "slow ロールのモデル、未設定なら omp が自分で選ぶ",
smol: "smol ロールのモデル", memory: "tiny ロールのモデル、未設定なら smol ロールのモデル",
},
de: {
summary: "Rollen: langsam",
roles: ["Subagenten", "klein (smol)", "langsam", "Thinking langsam", "Planung", "Vision", "Berater", "Commit", "winzig (tiny)", "Gedächtnis"],
own: "wählt omp selbst", advisor: "das Modell der Rolle slow, sonst wählt omp selbst",
smol: "das Modell der Rolle smol", memory: "das Modell der Rolle tiny, sonst das der Rolle smol",
},
};
const omp = '.row.agent[data-id="omp"]';
const items = (page) => page.locator("#pop:not([hidden]) #list li").evaluateAll((es) => es.map((e) => [e.querySelector(".v")?.textContent, e.querySelector(".n")?.textContent || ""]));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const width of [1100, 390]) for (const lang of ["en", "zh", "ja", "de"]) {
test(`${engine} ${lang} ${width}px: omp's roles and their thinking levels are one square, OpenCode's small model is a picker`, async (t) => {
const w = W[lang];
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width, height: 760 } });
page.setDefaultTimeout(5000);
const errors = [], sets = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, sets));
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}-omp-roles.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/");
await page.locator(omp).waitFor();
await page.locator(`${omp} .ag-link`).click();
// one square for the roles; the model and the session's thinking are the pickers
const square = page.locator(`${omp} .extras-cell .field.extra[data-key="tiers"]`);
assert.equal(await square.count(), 1, "no roles square");
assert.equal(await page.locator(`${omp} .field.extra`).count(), 1, "a role kept a square of its own");
const pickers = await page.locator(`${omp} .field:not(.extra)`).evaluateAll((es) => es.map((e) => e.dataset.key));
assert.ok(pickers.includes("model") && pickers.every((k) => k === "model" || k === "effort"), String(pickers));
assert.ok((await square.getAttribute("aria-label")).startsWith(w.summary), await square.getAttribute("aria-label"));
assert.equal(await square.evaluate((e) => e.classList.contains("set")), true);
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "the row scrolls sideways");
const y = await page.evaluate(() => scrollY);
// each role, with its model or what it takes unset; slow's level under it
await square.click();
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
const rows = await items(page);
assert.deepEqual(rows.map((r) => r[0]), w.roles);
assert.deepEqual(rows.slice(4).map((r) => r[1]), [w.own, w.own, w.advisor, w.smol, w.smol, w.memory]);
// commit's picker: Default says what omp takes unset, the smol
// role's model, and no "Same as model"
const commitPicker = async () => {
if (!(await page.locator("#pop:not([hidden]) #list li").count())) await square.click();
const at = (await items(page)).findIndex((r) => r[0] === w.roles[7]);
await page.locator("#pop:not([hidden]) #list li").nth(at).click();
await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().waitFor();
const top = await page.locator("#pop:not([hidden]) #list li").first().innerText();
assert.ok(top.includes(w.smol), top);
await page.keyboard.press("Escape");
await page.waitForFunction(() => !document.querySelector("#pop:not([hidden])"));
};
// ja and de check the new roles' words; the rest of the walk is en's and zh's
if (!w.follows) {
await commitPicker();
assert.deepEqual(sets, []);
assert.deepEqual(errors, []);
return;
}
assert.deepEqual(rows.slice(0, 4).map((r) => r[1]), [w.follows, w.follows, "DeepSeek Flash", w.session]);
// slow's level: the slider, which writes slow_thinking
await page.locator("#pop:not([hidden]) #list li").nth(3).click();
const range = page.locator("#effortRange");
await range.waitFor({ state: "attached" });
await page.waitForFunction(() => document.querySelector("#effortRange")?.offsetParent);
const at = await page.evaluate(() => Number(document.querySelector("#effortRange").max));
const high = LEVELS.findIndex((l) => l.value === "high") + (at === LEVELS.length ? 1 : 0);
await range.evaluate((r, i) => { r.value = String(i); r.dispatchEvent(new Event("input", { bubbles: true })); r.dispatchEvent(new Event("change", { bubbles: true })); }, high);
await page.waitForFunction(() => document.querySelector("#status")?.textContent);
assert.deepEqual(sets, [{ agent: "omp", field: "slow_thinking", value: "high" }]);
await page.keyboard.press("Escape");
await page.waitForFunction((s) => document.querySelector('.row.agent[data-id="omp"] .field.extra[data-key="tiers"]')?.getAttribute("aria-label").startsWith(s), w.summarySet);
// smol: the model picker, following the model first
await square.click();
await page.locator("#pop:not([hidden]) #list li").nth(1).click();
await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().waitFor();
assert.match(await page.locator("#pop:not([hidden]) #list li").first().innerText(), new RegExp(`${w.same}[\\s\\S]*DeepSeek Pro`));
await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().click();
await page.waitForFunction(() => document.querySelectorAll("#status").length && !document.querySelector("#pop:not([hidden])"));
assert.deepEqual(sets[1], { agent: "omp", field: "small", value: "magpie/deepseek/flash" });
// plan: no "Same as model", omp picks unset
await square.click();
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
const planAt = (await items(page)).findIndex((r) => r[0] === w.roles[4]);
await page.locator("#pop:not([hidden]) #list li").nth(planAt).click();
await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().waitFor();
const first = await page.locator("#pop:not([hidden]) #list li").first().innerText();
assert.doesNotMatch(first, new RegExp(w.same));
assert.match(first, new RegExp(w.own));
await page.keyboard.press("Escape");
assert.equal(await page.evaluate(() => scrollY), y, "a click scrolled the page");
await commitPicker();
// omp's named profile: its roles share the square as well
const work = '.row.agent[data-id="omp#work"]';
await page.locator(`${work} .ag-link`).click();
const workSquare = page.locator(`${work} .extras-cell .field.extra[data-key="tiers"]`);
await workSquare.waitFor();
assert.ok((await workSquare.getAttribute("aria-label")).startsWith(w.summary), await workSquare.getAttribute("aria-label"));
assert.equal(await page.locator(`${work} .field[data-key="plan"]`).count(), 0, "a profile's role kept a picker of its own");
// OpenCode's small model doesn't follow the model: a picker, not a square
const oc = '.row.agent[data-id="opencode"]';
await page.locator(`${oc} .ag-link`).click();
await page.locator(`${oc} .ag-exp`).waitFor();
assert.equal(await page.locator(`${oc} .field.extra`).count(), 0);
assert.equal(await page.locator(`${oc} .field[data-key="small"]`).count(), 1);
assert.deepEqual(errors, []);
});
}
}