Files
magpie/internal/gui/tests/name-suffix-remote.test.cjs
T
yetone 7e1858515b remote magpie: name its models by the provider serving them there (lcc580 on X)
lcc580 asked for a pass-through on the Remote magpie provider: show the
upstream magpie's own provider beside each model, so an agent can tell the
same model from two of its providers apart. Before, the names followed
both magpies' Provider in model names: with either one Off, both relays'
DeepSeek Chat reached the agents as "DeepSeek Chat · Office" (or plain
"DeepSeek Chat").

- The list a magpie gives another magpie (X-Magpie-Drawers) now names,
  as magpie_by, the provider serving each model there (Entry.ServedBy):
  "routing group" for a group, and for a model of its own Remote magpie
  the provider at the start of that chain. The fetch keeps it as the
  model's By (catalog/live.go).
- A Remote magpie provider gets upstreamProviders: the editor's "Model
  names" tick ("With the provider serving it there"), or
  `magpie provider set <id> upstream-providers=on`. With it on, each of
  its models is labelled "DeepSeek Chat · Office › Relay A" in every
  agent's list, whatever either magpie's Provider in model names says,
  unless the user named the model themselves under Own
  (Entry.Label/upstream, LabelsFor). Model settings' "Agents' lists show"
  line follows the tick at once.
- Ids are unchanged, so a request still goes by office/relay-b/model.
  Off (the default) names everything as before. A remote older than
  magpie_by has nothing to add, so its names stay as before.
- The core's scripts stay in budget: four long comments in app.js were
  cut to pay for it, no raise.

Run:
- Tests that fail on the old code: TestRemoteMagpieUpstreamNames
  (gateway: an httptest remote with two relays' DeepSeek Chat and a
  group, every Provider in model names mode, on and off, the third
  magpie's magpie_by, ids kept), TestServedByAndUpstreamLabel (provider),
  and name-suffix-remote.test.cjs's new case (tick, hint, save body).
- Broken by hand: upstream() returning "" and the magpie_by line removed;
  both Go tests went red with the plain labels, then restored.
- Two real gateways, built -tags nogui on the Linux box (WSL) under
  sandbox HOMEs: B with Relay A and Relay B both serving deepseek-chat,
  A with B as Remote magpie "Office". A's /v1/models before:
  "DeepSeek Chat · Relay A · Office"; after
  `provider set office upstream-providers=on`:
  "DeepSeek Chat · Office › Relay A" / "› Relay B" / "› routing group".
  A request for office/relay-b/deepseek-chat reached relay-b on B.
- gofmt -l clean; go vet darwin, linux (nogui), windows on the touched
  packages; go test catalog, provider, gateway, cli, gui on mote
  (macOS) at the rebased head: ok (catalog 2.6s, provider 165s, gateway 948s, cli 56s, gui 149s).
- GUI on mote, chromium and webkit: name-suffix-remote, remote-magpie,
  remote-self, i18n-keys, i18n-en-no-cjk, gui-ja, gui-de, gui-zh-tw,
  provider-detect-draft, provider-unmasked, routing-remote-windows,
  usage-remote-cards: all green except reds that fail the same on origin/main 388ca9ad4 (run there on the Linux box): gui-ja "ja has every zh string" (#5943) and remote-magpie "asks for the other magpie's address" in both engines (#4398); name-suffix-remote's old "named alone under Off" once in chromium de (#5147, scrollends.js import under load). The new case first failed in webkit (route lost after the save, the page's host went to DNS); it now uses one route whose server is swapped, 20 of 20 on the Linux box (WSL), both engines.

Not tried: the full suite (starts after the tag); the real desktop app's
editor by hand; a chain of three real magpies (the third magpie's
magpie_by is covered by the gateway test only).
2026-11-10 22:20:17 +08:00

133 lines
8.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// ARNO on Discord (我在设置里关闭了"模型名称带供应商"但是接入的remote-magpie的
// 模型名字还是带上了…): a remote magpie's models are named in its list with
// its own provider after them ("DeepSeek Chat · Relay A"), by that magpie's
// setting, and Off here kept it. Model settings says what the agents' lists
// show under each choice, saved on Settings: On, that label with this
// provider after it; Off, the model's name there alone. 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");
function serve(lang, posts, plainNames, saves = []) {
let cur = { lang, theme: "light", plainNames, plainOwnNames: false };
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light", plainNames } };
const models = [
{ id: "relaya/deepseek-chat", name: "DeepSeek Chat · Relay A", plain: "DeepSeek Chat", by: "Relay A", on: true, efforts: [], images: false },
];
const provider = { id: "remote-magpie", name: "Remote magpie", preset: "remote-magpie", icon: "generic", chat: "http://192.168.1.20:3425/v1", responses: "http://192.168.1.20:3425/v1", anthropic: "http://192.168.1.20:3425",
models, agents: [], key: { set: true, masked: "sk-…1234" }, ready: true };
return async (r) => {
const req = r.request(), url = new URL(req.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/settings/plain-names") {
const body = req.postDataJSON();
posts.push(body);
cur = { ...cur, plainNames: body.mode === "off", plainOwnNames: body.mode === "own" };
return json(cur);
}
if (url.pathname === "/api/settings") return json(cur);
if (url.pathname === "/api/provider/save") { saves.push(req.postDataJSON()); return json({ id: provider.id }); }
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.get("wait")) return new Promise(() => {});
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({ models: [], pools: [], groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [provider], 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 });
};
}
async function says(loc, want) {
for (let i = 0; i < 100 && (await loc.textContent()) !== want; i++) await new Promise((r) => setTimeout(r, 20));
assert.equal(await loc.textContent(), want);
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
test(`${engine} ${lang}: a remote magpie's model is named alone under Off`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
// narrow, as the panel is
const page = await (await browser.newContext({ viewport: { width: 420, height: 900 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
// Provider in model names is Settings' (joe on Discord): the editor
// says what each saved choice shows, On and then Off
for (const [plain, label] of [[false, "DeepSeek Chat · Relay A · Remote magpie"], [true, "DeepSeek Chat"]]) {
await page.unrouteAll({ behavior: "wait" });
await page.route("**/*", serve(lang, posts, plain));
await page.goto("http://magpie.test/?view=providers");
const tr = (k, vars = {}) => page.evaluate(([k, vars]) => t(k, vars), [k, vars]);
await page.locator(".row.provider").click();
if (!(await page.locator(".mnames:not([hidden])").count())) await page.getByRole("button", { name: await tr("Model settings"), exact: true }).click();
const sfx = page.locator(".mnames:not([hidden]) .msuffix");
await sfx.waitFor();
await says(sfx.locator(".hint"), await tr("Agents’ lists show “{label}”", { label }));
}
assert.deepEqual(posts, []);
assert.deepEqual(errors, []);
});
}
}
// lcc580 on X: a Remote magpie's models named by the provider serving each
// there, so one model from two of its providers is told apart here. Its
// editor's switch says what the agents' lists show, under On and Off
// alike, and is saved with the provider.
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
test(`${engine} ${lang}: a remote magpie's model named by its provider there`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width: 420, height: 900 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
// one route, its server swapped: WebKit lost a route set again after
// the save, and the page's address went to DNS
let served;
await page.route("**/*", (r) => served(r));
for (const plain of [false, true]) {
const saves = [];
served = serve(lang, posts, plain, saves);
await page.goto("http://magpie.test/?view=providers");
const tr = (k, vars = {}) => page.evaluate(([k, vars]) => t(k, vars), [k, vars]);
await page.locator(".row.provider").click();
if (!(await page.locator(".mnames:not([hidden])").count())) await page.getByRole("button", { name: await tr("Model settings"), exact: true }).click();
const sfx = page.locator(".mnames:not([hidden]) .msuffix");
await sfx.waitFor();
const tick = page.locator("label.upstream-providers");
assert.equal((await tick.textContent()).trim(), await tr("With the provider serving it there"));
assert.equal(await tick.locator("input").isChecked(), false);
await tick.locator("input").check();
await says(sfx.locator(".hint"), await tr("Agents’ lists show “{label}”", { label: "DeepSeek Chat · Remote magpie › Relay A" }));
await tick.locator("input").uncheck();
await says(sfx.locator(".hint"), await tr("Agents’ lists show “{label}”", { label: plain ? "DeepSeek Chat" : "DeepSeek Chat · Relay A · Remote magpie" }));
await tick.locator("input").check();
const ed = page.locator(".editor").filter({ has: tick });
await Promise.all([page.waitForResponse((r) => r.url().endsWith("/api/provider/save")), ed.locator(".bar button.primary").first().click()]);
assert.equal(saves.length, 1);
assert.equal(saves[0].upstreamProviders, true);
}
assert.deepEqual(posts, []);
assert.deepEqual(errors, []);
});
}
}