diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index ae38e9b47..84645864e 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -8174,17 +8174,19 @@ function routingPage(part) { // the image models after them, said as such (jzw690 on X): a group // of them is picked in Settings › Models › Images, or named at the images API const drawRef = (x) => ({ ...ref(x), note: noted(`${x.providerName} · ${t("Image model")}`, x.id) }); - const options = [...subs, ...(decides ? [] : groups.models.map(ref)), ...(decides ? [] : (groups.drawers || []).map(drawRef)), ...(chats ? [] : (groups.deciders || []).map(ref))]; - // the member a model is in the group as: itself, or with its - // reasoning fixed (deepseek/x:max), which is ticked as it and taken - // out by it rather than added twice (#907) - const holding = (id) => d.members.includes(id) ? id : d.members.find((m) => splitMember(m)[0] === id); - openPicker({ id: "", name: "", fields: [] }, { key: "member", label: "model", value: "", options, multi: true, picked: (id) => !!holding(id), onPick: (id) => { + // a model in the group with its reasoning fixed (deepseek/x:max) or + // on one account is a row of its own, ticked, its level or account + // in its note, and a click takes that member out (#907); the model's + // own row under it adds it again, to be fixed at another level + // (visamzh on X: gpt-6.2-sol at high and at xhigh, #189) + const withHeld = (mk) => (x) => [...d.members.filter((m) => m !== x.id && !subOf(m) && splitMember(m)[0] === x.id) + .map((m) => { const o = mk(x); return { ...o, value: m, note: [fixedOf(m) && fixedWords(fixedOf(m)), memberAccount(m)?.name, o.note].filter(Boolean).join(" · ") }; }), mk(x)]; + const options = [...subs, ...(decides ? [] : groups.models.flatMap(withHeld(ref))), ...(decides ? [] : (groups.drawers || []).flatMap(withHeld(drawRef))), ...(chats ? [] : (groups.deciders || []).flatMap(withHeld(ref)))]; + openPicker({ id: "", name: "", fields: [] }, { key: "member", label: "model", value: "", options, multi: true, picked: (id) => d.members.includes(id), onPick: (id) => { if (!id) return; - const m = holding(id); - if (!m) d.members.splice(d.members.findLastIndex((x) => !d.matched.includes(x)) + 1, 0, id); // after the last named - else if (d.matched.includes(m)) return status(t("In the group by a pattern: switch it off to send it nothing"), "warn"); - else { d.members.splice(d.members.indexOf(m), 1); rematch(); } + if (!d.members.includes(id)) d.members.splice(d.members.findLastIndex((x) => !d.matched.includes(x)) + 1, 0, id); // after the last named + else if (d.matched.includes(id)) return status(t("In the group by a pattern: switch it off to send it nothing"), "warn"); + else { d.members.splice(d.members.indexOf(id), 1); rematch(); } draw(); drawRules(); } }, addBtn, ev); }; diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index e2ac6f3d4..e0843326a 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -1128,14 +1128,23 @@ and 1000x700, in Chromium and WebKit, English and Chinese. `group-pick-filter.test.cjs` covers a group's Add a model picker and the filter over the routing groups (#907; PAMI on Discord). A model in the group -with its reasoning fixed (a/two:max) is ticked, and a click takes that member -out instead of adding it a second time. A model that is in other groups names +with its reasoning fixed (a/two:max) is a ticked row of its own, and a click +takes that member out; the model's own row under it is not ticked. A model +that is in other groups names them, and the whole note shows on hover. The filter keeps the groups whose name, id or models match every word typed, and the keyboard stays in it. When nothing matches it says so, and Escape clears it. The page never moves, and there is no select or left border. In Chromium and WebKit, English and Chinese. +`group-member-again.test.cjs` covers adding a model to a group a second +time at another reasoning (visamzh on X: gpt-6.2-sol at high and at xhigh). +With sol in the group at xhigh, the picker lists that member ticked and sol +itself not; a click on sol adds it again, its reasoning is fixed at high, and +the save sends both members. A group read with sol at two levels keeps both +rows and sends both back. It fails on the picker that took the model as its +member at a level. In Chromium and WebKit, English and Chinese. + `old-webkit.test.cjs` holds the page to Safari 15.0, the WebKit macOS 12 can have (#220: a regex lookbehind in app.js, a syntax error before Safari 16.4, left the panel with its headings and nothing working). Every script in diff --git a/internal/gui/tests/group-member-again.test.cjs b/internal/gui/tests/group-member-again.test.cjs new file mode 100644 index 000000000..c433b60b6 --- /dev/null +++ b/internal/gui/tests/group-member-again.test.cjs @@ -0,0 +1,133 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// visamzh on X: a routing group held gpt-6.2-sol at high and at xhigh, two +// members of one model (#189), but the Add a model picker took a model in +// the group at a fixed level as that member (#907): clicking it took the +// member out, so the model could not be added a second time. +// - The picker lists the member at its level as a ticked row of its own +// and the model's own row under it, not ticked; a click there adds the +// model again, whose reasoning is then fixed at another level, and a +// save sends both members. +// - A group read with the same model at two levels keeps both, in the +// editor and in what it saves. +// In English and Chinese, Chromium and WebKit. +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 efforts = ["low", "medium", "high", "xhigh"]; +const models = [ + { id: "cx/sol", name: "sol", providerName: "Codex", icon: "generic", efforts }, + { id: "cx/terra", name: "terra", providerName: "Codex", icon: "generic", efforts }, +]; + +const words = { + en: { edit: "Edit", save: "Save", add: "Add another model", xhigh: "xhigh reasoning", high: "high reasoning" }, + zh: { edit: "编辑", save: "保存", add: "再添加一个模型", xhigh: "xhigh 推理强度", high: "high 推理强度" }, +}; + +function serve(lang, posts) { + const info = (ids) => ids.map((id) => ({ id, ready: true })); + const groups = () => ({ + models, pools: [], + groups: [ + { id: "g", name: "G", members: ["cx/sol:xhigh", "cx/terra:high"], off: [], routing: "order", ready: true, memberInfo: info(["cx/sol:xhigh", "cx/terra:high"]) }, + { id: "pair", name: "Pair", members: ["cx/sol:xhigh", "cx/sol:high"], off: [], routing: "order", ready: true, memberInfo: info(["cx/sol:xhigh", "cx/sol:high"]) }, + ], + }); + const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } }; + return async (r) => { + const url = new URL(r.request().url()); + const json = (data) => r.fulfill({ json: data }); + if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes + return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] }); + } + if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); + if (url.pathname === "/api/groups") return json(groups()); + if (url.pathname.startsWith("/api/groups/")) { + posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") }); + return json(groups()); + } + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } }); + 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)]; + await r.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + const w = words[lang]; + test(`${engine} ${lang}: a model in a group at one reasoning is added again at another`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await (await browser.newContext({ viewport: { width: 1100, height: 1400 }, reducedMotion: "reduce" })).newPage(); + t.after(() => browser.close()); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], posts = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, posts)); + await page.goto("http://magpie.test/?view=groups"); + const card = (id) => page.locator(`.rt-group[data-id="${id}"]`); + await card("g").waitFor(); + const pop = page.locator("#pop"); + const save = async (ed) => { + const b = ed.locator("button.primary", { hasText: w.save }); + await page.mouse.move(550, 600); + for (let i = 0; i < 10 && (await b.boundingBox()).y > 1400 - 160; i++) { + await page.mouse.wheel(0, 300); + await page.waitForTimeout(150); + } + const bb = await b.boundingBox(); + await page.mouse.click(bb.x + bb.width / 2, bb.y + bb.height / 2); + await page.waitForFunction(() => !document.querySelector(".rt-gedit")); + return posts.filter((p) => p.path === "/api/groups/save").at(-1).body; + }; + + // G holds sol at xhigh: the picker adds sol again + await card("g").locator("button", { hasText: w.edit }).click(); + let ed = page.locator(".rt-gedit"); + const rows = () => ed.locator(".fbl").first().locator(".fbrow"); + assert.equal(await rows().count(), 2); + await ed.locator("button.rt-gadd", { hasText: w.add }).click(); + const sols = pop.locator("li", { has: page.locator(".v", { hasText: /^sol$/ }) }); + await sols.first().waitFor(); + assert.equal(await sols.count(), 2, "sol at xhigh and sol itself are not two rows"); + const cur = (li) => li.evaluate((x) => x.classList.contains("cur")); + assert.equal(await cur(sols.nth(0)), true, "sol at xhigh is not ticked"); + assert((await sols.nth(0).locator(".n").textContent()).includes(w.xhigh), "the held row doesn't say its level"); + assert.equal(await cur(sols.nth(1)), false, "sol itself is ticked while it is in at xhigh only"); + await sols.nth(1).click(); + assert.equal(await rows().count(), 3, "sol was not added again"); + assert.equal(await cur(sols.nth(0)), true, "adding sol again took sol at xhigh out"); + assert.equal(await cur(sols.nth(1)), true); + await page.keyboard.press("Escape"); + await pop.waitFor({ state: "hidden" }); + + // the new row fixed at high + await rows().nth(2).locator("button.rt-fixed:not(.rt-fast)").click(); + await pop.locator("li", { has: page.locator(".v", { hasText: new RegExp(`^${w.high}$`) }) }).first().click(); + await pop.waitFor({ state: "hidden" }); + assert.equal((await rows().nth(2).locator("button.rt-fixed:not(.rt-fast)").textContent()).trim(), w.high); + assert.equal((await rows().nth(0).locator("button.rt-fixed:not(.rt-fast)").textContent()).trim(), w.xhigh); + let sent = await save(ed); + assert.deepEqual(sent.members, ["cx/sol:xhigh", "cx/terra:high", "cx/sol:high"], "both of sol's members are not sent"); + + // Pair, read with sol at two levels, keeps both + await card("pair").locator("button", { hasText: w.edit }).click(); + ed = page.locator(".rt-gedit"); + assert.equal(await rows().count(), 2, "a member of the same model was dropped on read"); + sent = await save(ed); + assert.deepEqual(sent.members, ["cx/sol:xhigh", "cx/sol:high"]); + assert.deepEqual(errors, []); + }); + } +} diff --git a/internal/gui/tests/group-pick-filter.test.cjs b/internal/gui/tests/group-pick-filter.test.cjs index f0a617cb6..d8912d52c 100644 --- a/internal/gui/tests/group-pick-filter.test.cjs +++ b/internal/gui/tests/group-pick-filter.test.cjs @@ -3,9 +3,11 @@ // with its reasoning fixed (a/two:max) was neither ticked nor taken out by // a click: it was added a second time. PAMI on Discord: with many groups, // one was hard to find. -// - The picker ticks a model in the group as itself or with an effort, and -// a click takes that member out (its effort with it), not adds it twice; -// a model in other groups says them, the whole note on hover. +// - The picker ticks a model in the group as itself or with an effort (a +// row of its own, saying its level), and a click takes that member out +// (its effort with it); the model's own row under it is not ticked and +// adds it again (visamzh on X, group-member-again.test.cjs). A model in +// other groups says them, the whole note on hover. // - Over the groups, a filter keeps those whose name, id or models match // every word typed; the keyboard stays in it as the list is drawn, none // matching says so, Escape clears it. Not one