Files
magpie/internal/gui/tests/panel-effort.test.cjs
T
yetone df27f0882a agent: the 接入 switch and a model picked in the row, both (owner: 对于那种想在 magpie 中一键设置 Agent 模型的用户能否也兼容一下,鱼和熊掌都要兼得); a row opens in place and slides as on iOS (owner: 展开的时候,上/下 padding 变了,导致抖动;展开和折叠都没有 iOS 那种丝滑优雅精致的动画)
Every agent row keeps its 接入 switch and now has its model picker beside it. Picking a magpie model on an agent that isn't connected connects it first (agent.Pick, used by /api/set), so one pick sets the agent up; disconnecting still puts back what the agent had. The intro line says both ways.

An opened row shook: the connected row centred its lines in its 56px min-height, and the 3px row-gap couldn't be folded away, so opening moved the name and the switch and changed the space under them. The first line now has its own height and isn't centred, the row-gap is 0 with the spacing in margins, and the opened part starts where the shut row ended (56/56 at 980px, 90/90 at 560px; the name at 8px and the switch at 19px open and shut). Opening and closing animate the part's height, padding, margin and border on iOS's sheet curve cubic-bezier(.32,.72,0,1), 460 ms open and 340 ms shut, and what's in it fades in from 6px above; a row already open slides shut before another opens. With reduced motion it opens at once.

Gemini CLI's .env made by magpie for its key was left holding a newline after a disconnect (main too): DelEnvFile now removes a dotenv file once the deleted keys were all it held.

TestPickConnectsFirst, the only.env case in TestEnvFile, agent-start-pick and agent-expand-steady (name and switch unmoved, the opened part's top at the shut row's end, at least 3 heights between on the way open and shut, growing/shrinking only, chromium and webkit at 980 and 560px) fail on the old code and pass. Tests that open rows wait for the slide. In a sandbox HOME with real accounts: Claude Code and Gemini CLI picked while not connected answer PONG and disconnect back to what they had; Goose's pick → disconnect round trip is byte-identical (goose itself stops at a Linear MCP OAuth, so no request). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui for edit, agent and gui under a temp HOME pass; GUI tests that fail here fail the same on 82340f41 (account-arrange, cli-update, mobile-web, provider-levels-scroll, provider-proxy, redact-rule-row, routing-compact, provider-detect-models, plugin-move).
2026-10-04 02:05:10 +08:00

171 lines
9.3 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// The tray panel's effort slider shows an agent's effort as it is when that
// isn't one of the levels offered — omp at auto before magpie listed it, an
// agent with none set — rather than as the lowest level, which a touch on
// the slider then wrote over it. A touch where it stands posts nothing; the
// next stop is the lowest level. A level beyond those offered (max, the
// model's going to high) stands in its place, after high, and lights the
// bars in the list and the effort icon full; one between two offered lights
// them as far as its stop. auto, none and the default light no bar, where
// minimal lights one, and none counts for no level: Hermes at low, second
// of five, lights one of three; the window's icon is read in a connected
// agent's opened row. In English and Chinese. No backend: the API
// is faked here. ARTIFACT_DIR gets the slider and the panel's list.
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 levels = ["minimal", "low", "medium", "high", "xhigh", "max"].map((value) => ({ value }));
const agent = (id, name, effort, options = levels) => ({
id, name, path: "/test/" + id, wired: true,
fields: [{ key: "model", label: "model", value: "anthropic/claude-opus-5-5:max", options: [{ value: "anthropic/claude-opus-5-5:max", ref: "anthropic/claude-opus-5-5:max" }] },
{ key: "effort", label: "thinking", value: effort, options }],
});
const some = (...vs) => vs.map((value) => ({ value }));
const state = { agents: [agent("omp", "omp", "auto"), agent("pi", "Pi", ""),
agent("codex", "Codex", "max", some("low", "medium", "high")),
// omp as magpie lists it now, auto first, and one at minimal beside it
agent("omp-listed", "omp", "auto", [{ value: "auto" }, ...levels]),
agent("pi-minimal", "Pi", "minimal"),
agent("kimi", "Kimi", "medium", some("low", "high")),
agent("grok", "Grok", "none", some("none", "minimal", "low", "medium", "high", "xhigh", "max")),
agent("hermes", "Hermes", "low", some("none", "minimal", "low", "medium", "high", "xhigh"))], profiles: [] };
function server(lang, sets) {
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: { ...state, settings: { lang, theme: "light" } } });
if (url.pathname === "/api/set") { sets.push(req.postDataJSON()); return route.fulfill({ json: { ...state, 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/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 });
};
}
const row = (id) => `.row.agent[data-id="${id}"]`;
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the panel's effort as it is", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const errors = [];
t.after(async () => {
if (errors.length) console.log(errors);
await browser.close();
});
// the page, a row opened in the panel with its slider and a click on the
// slider's first or last stop
const load = async (lang, sets, url, viewport = { width: 440, height: 560 }) => {
const page = await (await browser.newContext({ viewport })).newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, sets));
await page.goto(url);
return page;
};
const open = async (lang, sets, id) => {
const page = await load(lang, sets, "http://magpie.test/?mode=panel");
await page.locator(`${row(id)} .ag-sum`).click();
await page.waitForTimeout(700);
const box = page.locator(`${row(id)} .ag-open .effort-control`);
const slider = box.locator(".eslide");
const click = async (end) => {
const r = await box.locator(".rail").evaluate((e) => e.getBoundingClientRect().toJSON());
await page.mouse.click(end ? r.right - 1 : r.left + 1, r.top + r.height / 2);
await page.waitForTimeout(300);
};
const shot = async (name) => {
if (!process.env.ARTIFACT_DIR) return;
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await box.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${name}-panel-effort.png`) });
};
return { page, box, slider, first: () => click(false), end: () => click(true), shot };
};
const ends = (box) => box.locator(".effort-ends span").allTextContents();
await t.test("omp at auto", async () => {
const sets = [];
const { box, slider, first } = await open("en", sets, "omp");
assert.equal(await box.locator(".effort-head b").textContent(), "auto");
assert.equal(await slider.getAttribute("aria-valuetext"), "auto");
assert.equal(await box.locator(".effort-ends span").first().textContent(), "auto");
await first();
assert.deepEqual(sets, [], "a touch where it stands wrote a level over auto");
await slider.press("ArrowRight");
await slider.page().waitForTimeout(300);
assert.deepEqual(sets, [{ agent: "omp", field: "effort", value: "minimal" }]);
});
await t.test("none set", async () => {
const sets = [];
const { box, first } = await open("en", sets, "pi");
assert.equal(await box.locator(".effort-head b").textContent(), "default");
await first();
assert.deepEqual(sets, []);
});
await t.test("max, the levels going to high", async () => {
const sets = [];
const { box, slider, end, shot } = await open("en", sets, "codex");
assert.deepEqual(await ends(box), ["low", "max"], "max stood before low");
assert.equal(await slider.getAttribute("aria-valuenow"), "3");
await shot("en");
await end();
assert.deepEqual(sets, [], "a touch where it stands wrote a level over max");
await slider.press("ArrowLeft");
await slider.page().waitForTimeout(300);
assert.deepEqual(sets, [{ agent: "codex", field: "effort", value: "high" }]);
});
await t.test("as bars", async () => {
const lit = (page, id) => page.locator(`${row(id)} .field[data-key="effort"] .effort-ic rect[opacity="1"]`).count();
const ids = ["omp-listed", "pi-minimal", "codex", "kimi", "grok", "hermes"];
const page = await load("en", [], "http://magpie.test/", { width: 980, height: 900 });
await page.locator(row("hermes")).waitFor();
const icons = [];
for (const id of ids) {
// Hermes picks no model once started: its pickers stay in the row
const more = page.locator(`${row(id)} .ag-link`);
// the one open slides shut before this one opens
if (await more.count()) { await more.click(); await page.locator(`${row(id)} .ag-exp`).waitFor(); }
icons.push(await lit(page, id));
}
const panel = await load("en", [], "http://magpie.test/?mode=panel");
await panel.locator(row("hermes")).waitFor();
const bars = [];
for (const id of ids) bars.push(Number(await panel.locator(`${row(id)} .ag-sum .eff`).getAttribute("data-l")));
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await panel.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-en-panel-effort-list.png`) });
}
// auto, minimal, max past high, medium between low and high, none, and
// low second of five (none not counted): of four in the icon, of three
// in the list
assert.deepEqual({ icons, bars }, { icons: [0, 1, 4, 3, 0, 2], bars: [0, 1, 3, 2, 0, 1] });
});
await t.test("in Chinese", async () => {
const sets = [];
const { box, first } = await open("zh", sets, "omp");
assert.equal(await box.locator(".effort-head b").textContent(), "自动");
await first();
assert.deepEqual(sets, []);
const codex = await open("zh", sets, "codex");
assert.deepEqual(await ends(codex.box), ["低", "最高"]);
await codex.shot("zh");
});
assert.deepEqual(errors, []);
});
}