Files
magpie/internal/gui/tests/omp-roles.test.cjs
T
yetone fc5dfa3c63 agent, gui: omp's plan, vision and advisor roles are picked on its row, and each role but the default one has its own thinking level (#1397, KKKKKKKEM)
KKKKKKKEM (#1397): omp 18.x runs plan mode, images and the advisor on
roles of their own that don't follow the default model, and magpie
offered no way to set them; then, setting slow, they asked to set its
thinking level too (slow at high while sessions start at medium).

omp reads a role's thinking level off the end of its model, "model:level"
(splitThinkingSuffix / parseModelPattern in model-resolver.ts, with
:auto and :max allowed for role values). magpie now has:
- plan, vision and advisor beside subagents, smol and slow (all written
  under modelRoles in ~/.omp/agent/config.yml as before);
- a "<role> thinking" field for each of them: the level rewrites the
  role's value through the role's own Set, so magpie's provider prefix
  and the stash are kept. Offered while the role is one model (auto,
  off, minimal…max); a role left unset or set to a list says to pick its
  model first, and an unknown level is refused. Unset, the role runs at
  the session's level.
In the GUI the roles move into the tiers square ("roles") with each
role's level in its menu; unset roles say what omp does instead (the
advisor: the slow role's model, else omp's own pick). The same holds
for a named profile (omp#<name>) and omp in a WSL distro: ompAgent now
matches those ids, so their rows don't list the roles as loose fields.
New strings in zh, zh-TW, ja and de.

Tests:
- TestOmpRoleThinking (Go): level read and written for each role,
  provider prefix kept, unset and list roles refused, unknown level
  refused, clearing the level leaves the model.
- omp-roles.test.cjs: the roles square, a role's level picked and
  written, and an omp#work profile row drawn the same way. Broken by
  hand (ompAgent on the bare id), the profile case goes red.
2026-10-10 20:04:49 +08:00

188 lines
12 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 and advisor,
// 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 and Chinese, 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),
{ 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"],
follows: "same as model (DeepSeek Pro)", own: "omp's own pick", advisor: "the slow role's model, else omp's own pick",
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 自己挑选",
session: "跟随会话的思考强度", same: "同主模型", summary: "角色:慢模型", high: "高", summarySet: "角色:慢模型 (高)",
},
};
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"]) {
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.map((r) => r[1]), [w.follows, w.follows, "DeepSeek Flash", w.session, w.own, w.own, w.advisor]);
// 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");
// 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, []);
});
}
}