gui: an agent's current model, lifted to the top of its picker, says whose it is when another provider lists a model by the same name

ADNANYURTSEVER3 on X (Mac, macOS 27.2.1): with WorkBuddy and WorkBuddy AI
both serving Hy4 and DeepSeek-V4.1-Flash (WorkBuddy AI spells it
Deepseek-V4.1-Flash), the Agents page's picker showed WorkBuddy AI's
section with Hy4 alone, while dsh listed and ticked "Deepseek-V4.1-Flash ·
WorkBuddy AI".

Cause: not case handling. buildVia and the catalog keep both spellings
apart (checked with a probe test in internal/agent, not kept). openPicker
lifts the agent's current model out of its section to the top of the list
(#1229). There its note named only the account. With WorkBuddy's
DeepSeek-V4.1-Flash, a model of the same name, under the same icon, the
row on top could not be told apart, and WorkBuddy AI's section read as if
magpie had dropped the model.

Fix: when another provider lists a model by the same name, in any case,
the lifted row's note now starts with its provider ("WorkBuddy AI ·
b@…"). The rail's own provider view leaves the name out, since its
section already says it. Pickers with no such clash are unchanged.

A first try listed the current model both at the top and in its section.
It broke the "each model once" and "current first" contracts of
claude-picker-fold, claude-picker-magpie-first and others, so it was
dropped.

Siblings:
- The tray panel uses the same openPicker.
- The Routing member picker and modelfind do not lift the current model.
- The TUI's withCurrent lists the current row by its full value
  (magpie/workbuddy-ai/…), which names the provider.
- dsh already names the provider on every row.

Run (on mica via mica-run):
- New internal/gui/tests/picker-current-in-section.test.cjs: chromium and
  webkit, en/zh/zh-TW/ja/de, 1000 and 440px.
  - Red on origin/main, 20 of 20 ("it says whose it is: b@example.com").
  - Green with the fix, 20 of 20.
- Picker files at the change: picker-rail-current, claude-picker-fold,
  claude-picker-magpie-first, agent-path-same, codex-accounts-via,
  searcher-pick, images-codex-one, video-gen-pick.
  - 150 of 156 pass.
  - The 6 reds (images-codex-one and video-gen-pick, "reading 'x'") fail
    the same on origin/main f9807c5e8 and are in #6709.
- codex-memories-settings, desktop-tiers, fast-pick, fast-ultra,
  menu-scroll, mobile-web, omp-roles and zero-priced-free: no test went
  red that was not red on origin/main f9807c5e8 too (#6709, #6201, #5262,
  #6432).
- At the pushed head (rebased on 9e627c507): go test ./internal/gui, plus
  picker-current-in-section, picker-rail-current, claude-picker-fold,
  claude-picker-magpie-first and i18n-keys: go ok (135s), GUI 76 of 76 pass

Not tried: the real app with the reporter's two WorkBuddy accounts, the
Linux WebKitGTK app, and a whole GUI suite.
This commit is contained in:
yetone
2026-11-16 01:42:40 +08:00
parent 9e627c5079
commit 8df7885d48
2 changed files with 120 additions and 1 deletions
+12 -1
View File
@@ -4797,7 +4797,17 @@ function openPicker(agent, field, anchor, ev, only) {
// high); its group stays as `home` for the rail (#1229)
const groups = [...new Set(options.map((o) => o.group).filter(Boolean))];
const i = options.findIndex((o) => o.value === cur);
if (!effortPicker && !field.menu && i > 0) { const [c] = options.splice(i, 1); options.unshift({ ...c, group: "", home: c.group }); }
// Lifted out of its section, a model another provider lists by the same
// name, in any case, says whose it is (renderList): WorkBuddy AI's
// Deepseek-V4.1-Flash on top read as WorkBuddy's DeepSeek-V4.1-Flash,
// and WorkBuddy AI's section, Hy4 alone, as if magpie had dropped it
// (ADNANYURTSEVER3 on X).
if (!effortPicker && !field.menu && i > 0) {
const [c] = options.splice(i, 1);
const name = (c.label || "").toLowerCase();
const whose = !!name && !!c.group && c.group !== ROUTING_GROUPS && options.some((o) => o.group && o.group !== c.group && (o.label || "").toLowerCase() === name);
options.unshift({ ...c, group: "", home: c.group, whose });
}
else if (i < 0 && cur && !only) options.unshift({ value: cur, note: t("current value") });
// the agent's own default: magpie's wiring comes out and the key is removed
if (FOLLOWS_MODEL.includes(field.label)) {
@@ -5438,6 +5448,7 @@ function renderList() {
const path = pathTag(o);
if (path) { words.append(path); note = note.replace(/(^| · )via magpie$/, ""); }
if (q && o.group && !note) note = o.group;
if (o.whose && pick.groupFilter !== o.home && !note.split(" · ").includes(o.home)) note = note ? o.home + " · " + note : o.home;
// a note cut off by its ellipsis reads whole on hover (#907)
if (note) { const n = el("span", "n", note); n.title = note; words.append(n); }
li.append(words);
@@ -0,0 +1,108 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// An agent's current model is listed first in its picker, out of its
// provider's section (#1229), and says whose it is there. Without it,
// WorkBuddy AI's Deepseek-V4.1-Flash on top read as WorkBuddy's
// DeepSeek-V4.1-Flash, and WorkBuddy AI's section, Hy4 alone, as if magpie
// had dropped it (ADNANYURTSEVER3 on X). The two spellings, which differ
// only in case, stay two rows. In the rail's provider and for a query the
// model is listed once, in its place. Chromium and WebKit, wide and narrow,
// in 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 row = (group, icon, id, label, note) => ({ value: "magpie/" + id, ref: id, label, group, icon, note });
const options = [
row("Routing groups", "workbuddy-color", "auto/DeepSeek-V4.1-Flash", "DeepSeek V4.1 Flash", "routing group · via magpie"),
row("Routing groups", "workbuddy-color", "auto/Hy4", "Hy4", "routing group · via magpie"),
row("DeepSeek", "deepseek-color", "deepseek/deepseek-v4-flash", "DeepSeek V4 Flash", "DeepSeek · via magpie"),
row("WorkBuddy", "workbuddy-color", "workbuddy/Hy4", "Hy4", "a@example.com · via magpie"),
row("WorkBuddy", "workbuddy-color", "workbuddy/DeepSeek-V4.1-Flash", "DeepSeek-V4.1-Flash", "a@example.com · via magpie"),
row("WorkBuddy AI", "workbuddy-color", "workbuddy-ai/Hy4", "Hy4", "b@example.com · via magpie"),
row("WorkBuddy AI", "workbuddy-color", "workbuddy-ai/Deepseek-V4.1-Flash", "Deepseek-V4.1-Flash", "b@example.com · via magpie"),
];
const CUR = "magpie/workbuddy-ai/Deepseek-V4.1-Flash";
const state = (lang) => ({
agents: [{ id: "opencode", name: "OpenCode", path: "/test/opencode.json", icon: "opencode", wired: true, fields: [{ key: "model", label: "model", value: CUR, options }] }],
profiles: [], settings: { lang, theme: "light", guideHidden: true },
});
function serve(st, lang) {
return async (route) => {
const url = new URL(route.request().url());
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(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: st });
if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
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 list's rows, each with the section header it is under
const rows = (page) => page.evaluate(() => {
let section = "";
const out = [];
for (const li of document.querySelectorAll("#list li")) {
if (li.classList.contains("group")) { section = li.textContent; continue; }
const v = li.querySelector(".v");
if (v) out.push({ section, name: v.textContent, cur: li.classList.contains("cur"), note: li.querySelector(".n")?.textContent || "" });
}
return out;
});
const named = (all, name) => all.filter((r) => r.name === name);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1000, 440]) {
test(`${engine} ${lang} ${width}px: the current model, listed first, says whose it is`, async () => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
try {
const page = await browser.newPage({ viewport: { width, height: 760 } });
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("http://magpie.test/**", serve(state(lang), lang));
await page.goto("http://magpie.test/");
await page.locator('#nav [data-view="agents"]').click();
await page.locator("#agents .ag-link").first().click();
await page.locator('#agents [data-key="model"]').first().click();
await page.locator("#pickerRail .rail-item").first().waitFor();
let all = await rows(page);
const cur = named(all, "Deepseek-V4.1-Flash");
assert.equal(cur.length, 1, `listed once: ${JSON.stringify(all)}`);
assert(cur[0].cur && cur[0].section === "", "first, out of the sections, ticked");
assert(all.indexOf(cur[0]) < all.findIndex((r) => r.section), "before every section");
assert.equal(cur[0].note.split(" · ")[0], "WorkBuddy AI", `it says whose it is: ${cur[0].note}`);
assert.deepEqual(all.filter((r) => r.section === "WorkBuddy").map((r) => [r.name, r.cur, r.note]), [["Hy4", false, "a@example.com"], ["DeepSeek-V4.1-Flash", false, "a@example.com"]], "WorkBuddy's own spelling stays its own row, not ticked, and says no provider");
assert.deepEqual(all.filter((r) => r.section === "WorkBuddy AI").map((r) => r.name), ["Hy4"]);
// in the provider picked in the rail: once, ticked
await page.locator('#pickerRail .rail-item[data-group="WorkBuddy AI"]').click();
await page.waitForTimeout(400);
all = await rows(page);
assert.deepEqual(all.map((r) => [r.name, r.cur]).filter(([n]) => /Hy4|Flash/.test(n)).sort(), [["Deepseek-V4.1-Flash", true], ["Hy4", false]], `under WorkBuddy AI, its two: ${JSON.stringify(all)}`);
assert.equal(named(all, "Deepseek-V4.1-Flash")[0].note.split(" · ")[0], "b@example.com", "the rail says whose it is already");
// found by a query: once, beside WorkBuddy's
await page.locator('#pickerRail .rail-item[data-group="all"]').click();
await page.waitForTimeout(400);
await page.locator("#q").fill("v4.1-flash");
all = await rows(page);
assert.equal(named(all, "Deepseek-V4.1-Flash").length, 1, `found once: ${JSON.stringify(all)}`);
assert.equal(named(all, "DeepSeek-V4.1-Flash").length, 1, "WorkBuddy's found too");
assert.deepEqual(errors, [], "page runtime errors");
} finally {
await browser.close();
}
});
}
}
}