diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 17a992949..a315b294c 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -406,6 +406,9 @@ function optionFor(field, value) { return field.options.find((o) => o.value === value); } +// a pick as "Name · Provider", as namedIn says it (nb5p); a routing group by name +const optNamed = (o, v) => o ? (o.label || o.value) + (o.group && o.group !== ROUTING_GROUPS ? " · " + o.group : "") : v; + // directSaid: a model the agent asks its own vendor for itself, magpie not // in the way (Claude Code on its own sign-in), so its config names no magpie // endpoint — which read as magpie having failed to set it up @@ -21514,13 +21517,8 @@ function renderCodexAutoReview(s) { $("#codexAutoReviewPick").replaceChildren(b); } -// renderCodexMemories: the model Codex writes its memories with (#985, -// Hu9956: the notebook square on Codex's card was all there was, beside the -// subagent squares, and wasn't found). It is the card's own field, picked -// in the same picker and written the same way, so the row and the square -// show one setting; renderAgents draws the row again after every pick. -// The row is in Codex's sheet now (openAgentPrefs), not Settings. -// No Codex with a memories field to pick: no row. +// renderCodexMemories: Codex's memories model (#985), its card's field, in +// Codex's sheet; drawn again after every pick. No such field: no row. function renderCodexMemories() { homeAgentPrefRows(); const row = $("#codexMemoriesRow"); @@ -21533,7 +21531,7 @@ function renderCodexMemories() { const b = el("button", "rt-cond on"); b.type = "button"; b.setAttribute("aria-label", t("Codex memories model")); - if (f.value) b.append(icon(opt?.icon || "generic"), el("span", "", opt?.label || f.value)); + if (f.value) b.append(icon(opt?.icon || "generic"), el("span", "", optNamed(opt, f.value))); else b.append(icon("generic"), el("span", "", t(SAME_SESSION))); b.onclick = (ev) => openPicker(a, f, b, ev); $("#codexMemoriesPick").replaceChildren(b); @@ -21557,7 +21555,7 @@ function renderCodexSubagentModel() { const b = el("button", "rt-cond on"); b.type = "button"; b.setAttribute("aria-label", t("Codex subagent model")); - b.append(icon((f.value ? optionFor(f, f.value)?.icon : main && optionFor(main, main.value)?.icon) || "generic"), el("span", "", said.name)); + b.append(icon((f.value ? optionFor(f, f.value)?.icon : main && optionFor(main, main.value)?.icon) || "generic"), el("span", "", f.value ? optNamed(optionFor(f, f.value), f.value) : said.name)); b.onclick = (ev) => openPicker(a, f, b, ev); $("#codexSubagentModelPick").replaceChildren(b); b.title = said.line; diff --git a/internal/gui/tests/codex-sheet-providers.test.cjs b/internal/gui/tests/codex-sheet-providers.test.cjs new file mode 100644 index 000000000..293e23826 --- /dev/null +++ b/internal/gui/tests/codex-sheet-providers.test.cjs @@ -0,0 +1,133 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Codex's sheet says each picked model with its provider, "Name · Provider", +// in every model row (nb5p on Discord): "Codex composer predictions" and +// "Codex auto-review model" did, from Settings' model list, while "Codex +// memories model" and "Codex subagent model", which are Codex's own fields +// and pick from its options, said the name alone ("GPT-6 Luna", no +// "· MyGateway"). A routing group is said by its name alone, and a value no +// option has as it is. Chromium and WebKit, every language, 440px and wide; +// 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 { watchSettingsReads, openAgentSettings } = require("./reader.cjs"); + +const assets = path.resolve(__dirname, "../assets"); +// Codex's field options as internal/agent builds them: a magpie model's +// group is its provider's name, a routing group's "Routing groups" +const opts = [ + { value: "gpt-5.5", label: "GPT-5.5", note: "OpenAI · via magpie", group: "OpenAI", ref: "openai/gpt-5.5", icon: "openai" }, + { value: "mygw/gpt-6-luna", label: "GPT-6 Luna", note: "MyGateway · via magpie", group: "MyGateway", ref: "mygw/gpt-6-luna", icon: "openai" }, + { value: "group/cheap", label: "cheap", note: "routing group · via magpie", group: "Routing groups", ref: "group/cheap" }, +]; +const agents = (memories, sub) => [{ + id: "codex", name: "Codex", path: "/test/config.toml", icon: "codex-color", wired: true, + fields: [ + { key: "model", label: "model", value: "gpt-5.5", options: opts }, + { key: "subagent_model", label: "subagent model", value: sub, options: opts }, + { key: "memories", label: "memories", value: memories, options: opts }, + ], +}]; +// Settings' list, as /api/settings has it +const titleModels = [{ id: "mygw/gpt-6-luna", name: "GPT-6 Luna", provider: "mygw", providerName: "MyGateway", icon: "openai" }]; +const settings = (lang) => ({ + theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", + dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [], + codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "", workbuddyCheckin: false, noStats: false, + trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "", + version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", + proxyNow: "none", proxySource: "none", login: false, + visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], titleModels, + codexPredictions: "mygw/gpt-6-luna", codexAutoReview: "mygw/gpt-6-luna", + fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, +}); + +function server(lang, memories, sub) { + 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: agents(memories, sub), profiles: [], settings: { lang, theme: "light" } }); + if (url.pathname === "/api/settings") return json(settings(lang)); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false }); + if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + 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: "" }); + } + }; +} + +// the rows' names as i18n.js has them +const W = { + en: { mem: "Codex memories model", pred: "Codex composer predictions" }, + zh: { mem: "Codex 记忆整理模型", pred: "Codex 输入框预测" }, + "zh-TW": { mem: "Codex 記憶整理模型", pred: null }, + ja: { mem: "Codex メモリ整理のモデル", pred: null }, + de: { mem: "Codex-Modell für Erinnerungen", pred: null }, +}; + +async function open(engine, width, lang, memories, sub, t) { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const context = await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, memories, sub)); + 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}-${width}-${lang}-codex-sheet-providers.png`) }); + } + await browser.close(); + }); + await watchSettingsReads(page); + await page.goto("http://magpie.test/?view=agents"); + await openAgentSettings(page); + await page.locator("#codexMemoriesPick button").waitFor(); + return { page, errors }; +} +const said = (page, id) => page.locator(`#${id} button`).evaluate((b) => b.textContent.trim()); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const width of [440, 1100]) { + for (const lang of Object.keys(W)) { + test(`${engine} ${width}px ${lang}: every model row in Codex's sheet names its provider`, async (t) => { + const { page, errors } = await open(engine, width, lang, "mygw/gpt-6-luna", "mygw/gpt-6-luna", t); + assert.equal((await page.locator("#codexMemoriesRow .name").textContent()).trim(), W[lang].mem); + if (W[lang].pred) assert.equal((await page.locator("#codexPredictionsRow .name").textContent()).trim(), W[lang].pred); + for (const id of ["codexPredictionsPick", "codexAutoReviewPick", "codexMemoriesPick", "codexSubagentModelPick"]) + assert.equal(await said(page, id), "GPT-6 Luna · MyGateway", id); + // each row's name and button fit it, the page no wider than the window + const fit = await page.evaluate(() => ["#codexMemoriesRow", "#codexSubagentModelRow"].every((s) => { + const r = document.querySelector(s), box = r.getBoundingClientRect(); + return [...r.querySelectorAll(".name, button")].every((e) => { + const b = e.getBoundingClientRect(); + return b.width > 0 && b.left >= box.left - 1 && b.right <= box.right + 1; + }); + }) && document.documentElement.scrollWidth <= innerWidth); + assert(fit, "a row overflows"); + assert.deepEqual(errors, []); + }); + } + } + + test(`${engine}: a routing group by its name alone, a value with no option as it is`, async (t) => { + const { page, errors } = await open(engine, 900, "en", "group/cheap", "gone/old-model", t); + assert.equal(await said(page, "codexMemoriesPick"), "cheap"); + assert.equal(await said(page, "codexSubagentModelPick"), "gone/old-model"); + assert.deepEqual(errors, []); + }); +}