diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 08807f86f..14cb4fd37 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -11473,7 +11473,9 @@ const typedIds = (v) => (v || "").split(/[,\n]/).map((id) => id.trim()).filter(B // a Save takes as if Enter had been pressed on them function chosenIds() { const typed = typedIds(draft.typed); - return [...draft.chosen, ...typed.filter((id) => !draft.chosen.includes(id))].filter((id, i, all) => all.indexOf(id) === i); + // ids typed join what the list serves, drawn dashed (none while some + // are picked), as a click on a chip it doesn't serve does + return [...typed[0] && draft.dashed || [], ...draft.chosen, ...typed].filter((id, i, all) => all.indexOf(id) === i); } // noneChosen: Select none kept, nothing picked or served (#1818) @@ -11484,7 +11486,7 @@ const pickingNone = () => !!draft.picking && !chosenIds().length; const bestChosen = () => !!draft.best && !draft.none && !chosenIds().length; // servedIds: the picks; none after Select none; else the vendor's list's -const servedIds = (p) => draft.chosen.length ? draft.chosen : draft.none || draft.picking ? [] : p.models.filter((m) => draft.best ? m.best : m.on).map((m) => m.id); +const servedIds = (p) => draft.chosen[0] ? draft.chosen : draft.none || draft.picking ? [] : p.models.filter((m) => draft.best ? m.best : m.on).map((m) => m.id); // modelsOpen: models let out to full height (#833). MCHIPS_MAX: .mchips' max-height let modelsOpen = false; @@ -11641,15 +11643,17 @@ function renderModels(p) { }; const draw = () => { if (agentMenu && chips.contains(agentMenu.anchor)) closeAgentMenu(); - if (draft.chosen.length) draft.picking = false; + if (draft.chosen[0]) draft.picking = false; chips.replaceChildren(); const f = (q?.value || "").trim().toLowerCase(); let shown = 0, hidden = 0, unpicked = 0; // Picked only, unfiltered: the picks alone (unpickedShown) - const picksOnly = draft.chosen.length && !f && unpickedShown !== p.id && !decideOnly(p); + const picksOnly = draft.chosen[0] && !f && unpickedShown !== p.id && !decideOnly(p); // none picked: what the vendor's list serves is drawn as served (#614, // #1818), none after Select none - const served = draft.chosen.length || draft.picking || decideOnly(p) || draft.none ? new Set() : new Set(dashed()); + const served = draft.chosen[0] || draft.picking || decideOnly(p) || draft.none ? new Set() : new Set(dashed()); + // an id added by hand joins them too (chosenIds) + draft.dashed = [...served]; // models that would read alike say what tells them apart (modelTells) const tells = modelTells(p.models); // a filter is a search: what it doesn't match is left out @@ -11697,9 +11701,13 @@ function renderModels(p) { if (kb.length) c.title = (c.title || m.id) + "\n" + t("Kept out of agents' lists by {groups}, a routing group listed alone", { groups: kb.join(", ") }); tested(c, m.id); menu(c, m.id); - // a click picks it (#681); the last unpicked leaves none (#1831) + // a click picks it (#681); the last unpicked leaves none (#1831). + // With none picked, a served (dashed) one is picked alone (#681), and + // one the list doesn't serve joins those it does: a relay's 25th + // model clicked left the 24 served out (onkashiko on X), where the + // TUI's toggle adds it to them c.onclick = () => { - draft.chosen = on ? draft.chosen.filter((x) => x !== m.id) : [...draft.chosen, m.id]; + draft.chosen = on ? draft.chosen.filter((x) => x !== m.id) : [...served.has(m.id) ? [] : served, ...draft.chosen, m.id]; draft.none = true; unpickedShown = p.id; draw(); @@ -11718,7 +11726,7 @@ function renderModels(p) { chips.append(c); } if (hidden || unpicked) chips.append(showRest(hidden || unpicked, () => { if (unpicked) unpickedShown = p.id; else showAll = true; draw(); })); - if (!p.models.length && !draft.chosen.length) chips.append(el("span", "hint", t(emptyModelsHint(p)))); + if (!p.models.length && !draft.chosen[0]) chips.append(el("span", "hint", t(emptyModelsHint(p)))); // the list is of models agents chat with: image, embedding and speech // models are left out of it, and an image model is set in Settings else if (f && !chips.children.length) chips.append(el("span", "hint", t("No model here matches “{q}”. Image, embedding and speech models aren't listed, as agents can't chat with them: pick an image model in Settings › Models › Images.", { q: q.value.trim() }))); @@ -11727,11 +11735,11 @@ function renderModels(p) { drawWorkOn(); drawServes(); why.textContent = decideOnly(p) ? t("Agents never see them: a routing group picks one as its classifier.") - : !draft.chosen.length && draft.picking ? t("Pick a model first.") - : !draft.chosen.length && draft.none ? t("None selected: no agent or routing group uses its models. Its balance and usage still show. Click a model to pick it.") + : !draft.chosen[0] && draft.picking ? t("Pick a model first.") + : !draft.chosen[0] && draft.none ? t("None selected: no agent or routing group uses its models. Its balance and usage still show. Click a model to pick it.") : bestChosen() && !draft.unlisted ? t("Best in family: agents see the newest model of each family it lists (dashed), up to {n}. A newer one it lists later takes the old one's place.", { n: 24 }) - : draft.unlisted ? t(draft.chosen.length ? "Agents don't see them: only the routing groups they are in use them." : "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a model to pick just it.", { n: 24 }) - : t(draft.chosen.length ? "Agents see the models picked." : "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a model to pick just it.", { n: 24 }); + : draft.unlisted ? t(draft.chosen[0] ? "Agents don't see them: only the routing groups they are in use them." : "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a dashed one to pick just it.", { n: 24 }) + : t(draft.chosen[0] ? "Agents see the models picked." : "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a dashed one to pick just it.", { n: 24 }); drawLost(); drawHiders(); }; @@ -12165,12 +12173,12 @@ function renderModels(p) { b.dataset.serves = v; b.title = t(tip, { n: 24 }); b.onclick = () => { - if (v !== "picked" && draft.chosen.length) picksLeft = { id: p.id, picks: [...draft.chosen] }; + if (v !== "picked" && draft.chosen[0]) picksLeft = { id: p.id, picks: [...draft.chosen] }; if (v !== "picked") { draft.chosen = []; draft.typed = ""; draft.none = v === "none"; draft.best = v === "best"; draft.picking = false; } else { - if (!draft.chosen.length && picksLeft?.id === p.id) { draft.chosen = picksLeft.picks; draft.none = true; } + if (!draft.chosen[0] && picksLeft?.id === p.id) { draft.chosen = picksLeft.picks; draft.none = true; } // none picked: it picks none, not the first 24 (yuancjun) - draft.picking = !draft.chosen.length; + draft.picking = !draft.chosen[0]; unpickedShown = null; draft.best = false; } draw(); @@ -12178,7 +12186,7 @@ function renderModels(p) { serves.append(b); return b; }); - const servesMode = () => draft.chosen.length || draft.picking ? "picked" : draft.none ? "none" : draft.best ? "best" : "list"; + const servesMode = () => draft.chosen[0] || draft.picking ? "picked" : draft.none ? "none" : draft.best ? "best" : "list"; const drawServes = () => { const now = servesMode(); for (const b of servesOpts) { b.classList.toggle("on", b.dataset.serves === now); b.setAttribute("aria-pressed", b.dataset.serves === now); } diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index c3e6b5aa1..44a8ad18c 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4901,8 +4901,8 @@ const I18N = { "Best in family: agents see the newest model of each family it lists (dashed), up to {n}. A newer one it lists later takes the old one's place.": "每系最新:Agent 看到它列表里每个系列最新的模型(虚线框),最多 {n} 个。之后上了更新的,会自动替换旧的。", "Route nothing to it: no agent or routing group uses its models, and those it lists later aren't added. Its balance and usage still show.": "不往它路由:Agent 和路由分组都不使用它的模型,之后新上的模型也不会加进来。余额和用量照常显示。", "usage only": "仅看用量", - "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a model to pick just it.": "供应商列表:Agent 看不到,模型所在的路由分组最多使用其中 {n} 个(虚线框)。点击模型可单选。", - "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a model to pick just it.": "供应商列表:Agent 看到最多 {n} 个模型(虚线框),之后新上的也会看到。点击模型可单选。", + "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a dashed one to pick just it.": "供应商列表:Agent 看不到,模型所在的路由分组最多使用其中 {n} 个(虚线框)。点击虚线框的模型可单选,点击其他模型会把它加进来。", + "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a dashed one to pick just it.": "供应商列表:Agent 看到最多 {n} 个模型(虚线框),之后新上的也会看到。点击虚线框的模型可单选,点击其他模型会把它加进来。", "Free only": "只选免费", "Pick only the free models (those the filter shows), unpicking the others": "只选中免费模型(有筛选时只选筛出来的),其余取消选中", "Working only": "只选可用", @@ -10386,8 +10386,8 @@ const I18N = { "Best in family: agents see the newest model of each family it lists (dashed), up to {n}. A newer one it lists later takes the old one's place.": "每系最新:Agent 看到它列表裡每個系列最新的模型(虛線框),最多 {n} 個。之後上了更新的,會自動取代舊的。", "Route nothing to it: no agent or routing group uses its models, and those it lists later aren't added. Its balance and usage still show.": "不往它路由:Agent 和路由分組都不使用它的模型,之後新上的模型也不會加進來。餘額和用量照常顯示。", "usage only": "僅看用量", - "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a model to pick just it.": "供應商列表:Agent 看不到,模型所在的路由分組最多使用其中 {n} 個(虛線框)。點選模型可單選。", - "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a model to pick just it.": "供應商列表:Agent 看到最多 {n} 個模型(虛線框),之後新上的也會看到。點選模型可單選。", + "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a dashed one to pick just it.": "供應商列表:Agent 看不到,模型所在的路由分組最多使用其中 {n} 個(虛線框)。點選虛線框的模型可單選,點選其他模型會把它加進來。", + "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a dashed one to pick just it.": "供應商列表:Agent 看到最多 {n} 個模型(虛線框),之後新上的也會看到。點選虛線框的模型可單選,點選其他模型會把它加進來。", "Free only": "只選免費", "Pick only the free models (those the filter shows), unpicking the others": "只選中免費模型(有篩選時只選篩出來的),其餘取消選中", "Working only": "只選可用", @@ -15889,8 +15889,8 @@ const I18N = { "Best in family: agents see the newest model of each family it lists (dashed), up to {n}. A newer one it lists later takes the old one's place.": "系列の最新のみ:エージェントには一覧の各系列の最新モデルが見えます(破線、最大 {n} 個)。後で新しいモデルが載ると、古いものと自動で入れ替わります。", "Route nothing to it: no agent or routing group uses its models, and those it lists later aren't added. Its balance and usage still show.": "何もルーティングしません。エージェントもルーティンググループもモデルを使わず、後から追加されたモデルも加わりません。残高と使用量は引き続き表示されます。", "usage only": "使用量のみ", - "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a model to pick just it.": "ベンダーのリスト:エージェントには表示されず、モデルが属するルーティンググループが最大 {n} 件(破線)を使います。モデルをクリックするとそれだけを選択します。", - "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a model to pick just it.": "ベンダーのリスト:エージェントにはモデルが最大 {n} 件(破線)表示され、後から追加されたものも表示されます。モデルをクリックするとそれだけを選択します。", + "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a dashed one to pick just it.": "ベンダーのリスト:エージェントには表示されず、モデルが属するルーティンググループが最大 {n} 件(破線)を使います。破線のモデルをクリックするとそれだけを選択し、ほかのモデルをクリックするとそれらに追加します。", + "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a dashed one to pick just it.": "ベンダーのリスト:エージェントにはモデルが最大 {n} 件(破線)表示され、後から追加されたものも表示されます。破線のモデルをクリックするとそれだけを選択し、ほかのモデルをクリックするとそれらに追加します。", "Free only": "無料のみ", "Pick only the free models (those the filter shows), unpicking the others": "無料モデル(フィルタで表示されているもの)だけを選択し、他は選択を解除します", "Working only": "使えるもののみ", @@ -21416,8 +21416,8 @@ const I18N = { "Best in family: agents see the newest model of each family it lists (dashed), up to {n}. A newer one it lists later takes the old one's place.": "Neuestes je Familie: Agents sehen das neueste Modell jeder Familie aus der Liste (gestrichelt), bis zu {n}. Ein neueres, das er später listet, ersetzt das alte.", "Route nothing to it: no agent or routing group uses its models, and those it lists later aren't added. Its balance and usage still show.": "Nichts dorthin leiten: Weder Agenten noch Weiterleitungsgruppen nutzen seine Modelle, auch später gelistete nicht. Guthaben und Nutzung werden weiter angezeigt.", "usage only": "nur Nutzung", - "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a model to pick just it.": "Liste des Anbieters: Agenten sehen sie nicht, die Weiterleitungsgruppen seiner Modelle nutzen bis zu {n} davon (gestrichelt). Klicken Sie auf ein Modell, um nur dieses zu wählen.", - "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a model to pick just it.": "Liste des Anbieters: Agenten sehen bis zu {n} seiner Modelle (gestrichelt), auch später hinzukommende. Klicken Sie auf ein Modell, um nur dieses zu wählen.", + "Vendor's list: agents don't see it, the routing groups its models are in use up to {n} of it (dashed). Click a dashed one to pick just it.": "Liste des Anbieters: Agenten sehen sie nicht, die Weiterleitungsgruppen seiner Modelle nutzen bis zu {n} davon (gestrichelt). Klicken Sie auf ein gestricheltes Modell, um nur dieses zu wählen, auf ein anderes, um es hinzuzufügen.", + "Vendor's list: agents see up to {n} of its models (dashed), and those it lists later. Click a dashed one to pick just it.": "Liste des Anbieters: Agenten sehen bis zu {n} seiner Modelle (gestrichelt), auch später hinzukommende. Klicken Sie auf ein gestricheltes Modell, um nur dieses zu wählen, auf ein anderes, um es hinzuzufügen.", "Free only": "Nur kostenlose", "Pick only the free models (those the filter shows), unpicking the others": "Nur die kostenlosen Modelle wählen (die der Filter zeigt), die übrigen abwählen", "Working only": "Nur funktionierende", diff --git a/internal/gui/tests/model-first-pick.test.cjs b/internal/gui/tests/model-first-pick.test.cjs index 0f89aafcf..c73154fdc 100644 --- a/internal/gui/tests/model-first-pick.test.cjs +++ b/internal/gui/tests/model-first-pick.test.cjs @@ -65,8 +65,8 @@ function serve(lang, saves) { } const words = { - en: { hint: "Click a model to pick just it", tip: "Click to pick just this model", save: "Save", picked: "Agents see the models picked." }, - zh: { hint: "点击模型可单选", tip: "点击只选这个模型", save: "保存", picked: "Agent 看到的是已勾选的模型。" }, + en: { hint: "Click a dashed one to pick just it", tip: "Click to pick just this model", save: "Save", picked: "Agents see the models picked." }, + zh: { hint: "点击虚线框的模型可单选", tip: "点击只选这个模型", save: "保存", picked: "Agent 看到的是已勾选的模型。" }, }; for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { diff --git a/internal/gui/tests/provider-pick-adds.test.cjs b/internal/gui/tests/provider-pick-adds.test.cjs new file mode 100644 index 000000000..b9f362346 --- /dev/null +++ b/internal/gui/tests/provider-pick-adds.test.cjs @@ -0,0 +1,161 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A relay's model picked past the ones its list serves joins them (onkashiko +// on X: 点开一个供应商新选模型的时候,之前已经选中的模型就会失效,对于有大量 +// 模型的中转供应商来说很不方便,新选的模型难道不应该是新增进模型列表吗). A relay +// listing 60 models serves the first 24 (dashed) with none picked; a click +// on the 30th picked it alone, so Save wrote that one and agents lost the +// 24 they had. Now the 24 stay and it joins them, as the TUI's toggle does, +// and so does an id added by hand, by Add model or left in the box at Save. +// A dashed one clicked is still picked alone (#681), and Best in family's +// newest ones are kept the same way. In every language, Chromium and +// WebKit, at 1000 and 420. +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 fetched = new Date(Date.now() - 3600e3).toISOString(); +// a relay's list, as such lists run: many vendors' models side by side +const families = ["gpt-5.5", "claude-opus-5-5", "gemini-3.5-pro", "deepseek-v4", "glm-5.3", "qwen4-max", "kimi-k3", "grok-5", "doubao-seed-2.5", "minimax-m3"]; +const ids = Array.from({ length: 60 }, (_, i) => families[i % 10] + (i < 10 ? "" : "-" + String.fromCharCode(97 + Math.floor(i / 10) - 1))); +const first24 = ids.slice(0, 24); +// Best in family: one of each family +const best = ids.slice(0, 10); + +function relay(chosen, bestOn) { + const on = new Set(chosen.length ? chosen : bestOn ? best : first24); + return { + id: "relay", name: "Relay", icon: "generic", host: "relay.example.com", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "", + models: ids.map((id) => ({ id, name: id, on: on.has(id), best: best.includes(id) })), chosen, bestInFamily: !!bestOn, fetched, agents: [], fallback: [], headers: {}, + key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", ready: true, + }; +} + +function serve(lang, saves, at) { + return async (route) => { + const req = route.request(), url = new URL(req.url()); + const json = (data) => route.fulfill({ json: data }); + const providers = () => ({ providers: [relay(at.chosen, at.best)], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] }); + 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 json({ agents: [], profiles: [], settings: { lang, theme: "light" } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/providers") return json(providers()); + if (url.pathname === "/api/provider/save") { + const body = req.postDataJSON(); + saves.push(body.models); + at.chosen = body.models; + at.best = body.bestInFamily; + return json(providers()); + } + if (url.pathname === "/api/groups") return json({ groups: [], pools: [] }); + if (url.pathname === "/api/gateway/trace") return json({ routes: [] }); + 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: "" }); } + }; +} + +const words = { + en: { save: "Save", add: "Add model", hint: "Click a dashed one to pick just it." }, + zh: { save: "保存", add: "添加模型", hint: "点击虚线框的模型可单选,点击其他模型会把它加进来。" }, + "zh-TW": { save: "儲存", add: "新增模型", hint: "點選虛線框的模型可單選,點選其他模型會把它加進來。" }, + ja: { save: "保存", add: "モデルを追加", hint: "破線のモデルをクリックするとそれだけを選択し、ほかのモデルをクリックするとそれらに追加します。" }, + de: { save: "Speichern", add: "Modell hinzufügen", hint: "Klicken Sie auf ein gestricheltes Modell, um nur dieses zu wählen, auf ein anderes, um es hinzuzufügen." }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(words)) { + const w = words[lang]; + for (const width of [1000, 420]) { + test(`${engine} ${lang} ${width}: a model past the served ones joins them`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], saves = [], at = { chosen: [], best: false }; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, saves, at)); + await page.goto("http://magpie.test/?view=providers"); + const editor = page.locator("#modal:not([hidden]) .editor"); + const open = async () => { + await page.locator(".row.provider", { hasText: "Relay" }).first().click(); + await editor.locator(".mchips .mchip").first().waitFor(); + }; + const chip = (id) => editor.locator(".mchips .mchip", { has: page.locator(`span:text-is("${id}")`) }); + const picked = () => editor.locator(".mchips .mchip.on").evaluateAll((cs) => cs.map((c) => c.firstChild.textContent)); + const save = async () => { + await editor.getByRole("button", { name: w.save, exact: true }).click(); + await editor.waitFor({ state: "detached" }); + }; + const seg = (v) => editor.locator(`.mserves .opt[data-serves=${v}]`); + // the saved provider set afresh, and the page loaded again to read it + const again = async (chosen, best) => { + Object.assign(at, { chosen, best }); + await page.reload(); + await open(); + }; + + // the reporter's case: the 30th clicked joins the 24 served + await open(); + assert.equal(await editor.locator(".mchips .mchip.auto").count(), 24); + await editor.getByText(w.hint).waitFor(); + await chip(ids[29]).click(); + assert.equal(await seg("picked").getAttribute("aria-pressed"), "true"); + assert.deepEqual((await picked()).sort(), [...first24, ids[29]].sort()); + // every model stays in sight to go on picking + assert.equal(await editor.locator(".mchips .mchip").count(), 60); + await chip(ids[40]).click(); + await save(); + assert.deepEqual(saves.at(-1), [...first24, ids[29], ids[40]]); + + // saved picks: one more joins them + await open(); + assert.equal(await seg("picked").getAttribute("aria-pressed"), "true"); + await editor.locator(".mchips .mchips-rest").click(); + await chip(ids[50]).click(); + await save(); + assert.deepEqual(saves.at(-1), [...first24, ids[29], ids[40], ids[50]]); + + // a dashed one, with none picked, is still picked alone (#681) + await again([], false); + await chip(ids[3]).click(); + assert.deepEqual(await picked(), [ids[3]]); + await save(); + assert.deepEqual(saves.at(-1), [ids[3]]); + + // an id added by hand joins the 24, by Add model and by Save + for (const how of ["add", "save"]) { + await again([], false); + const box = editor.locator(".mfoot input"); + await box.fill("my-own-model"); + if (how === "add") { + await editor.getByRole("button", { name: w.add, exact: true }).click(); + assert.equal(await picked().then((l) => l.length), 25); + } + await save(); + assert.deepEqual(saves.at(-1), [...first24, "my-own-model"], how); + } + + // Best in family: the newest of each kept, the one clicked beside them + await again([], true); + assert.equal(await seg("best").getAttribute("aria-pressed"), "true"); + assert.equal(await editor.locator(".mchips .mchip.auto").count(), 10); + await chip(ids[33]).click(); + await save(); + assert.deepEqual(saves.at(-1), [...best, ids[33]]); + + // Usage only: nothing served, so a click picks just it + await again([], false); + await seg("none").click(); + await chip(ids[33]).click(); + assert.deepEqual(await picked(), [ids[33]]); + assert.deepEqual(errors, []); + }); + } + } +}