A remote magpie's list names each model by its label there (magpie_label),
which carries that magpie's provider, or "· routing group", by that
magpie's own setting. Here it was taken as the model's name, so turning
Provider in model names Off on this computer still left "DeepSeek Chat ·
Relay A" and "Fast · routing group" in every agent's list.
The list's display_name, the name there alone, is now kept beside it
(catalog.Model.Plain, Entry.Plain). provider.Labels names an entry by it
under Off, and under own for a name the user gave; two that would read the
same keep their labels as before. On is unchanged ("DeepSeek Chat · Relay A
· Remote magpie"). /v1/models' display_name is that name alone too, as it
is for every other model, so a magpie chained after this one gets it. The
provider editor's Names & levels line says the same ("plain" in the
provider's model JSON).
Reproduced in a sandbox: fake vendor on :3571, magpie A on :3572 with it
and a group, magpie B on :3573 with remote-magpie → A and `model suffix
off`: B's /v1/models said "DeepSeek Chat · Relay A", "Fast · routing
group". With the fix: "DeepSeek Chat", "Fast"; on: "DeepSeek Chat · Relay
A · Remote magpie".
Run:
- TestRemoteMagpieSuffixOff (internal/gateway, A's list bytes as served)
fails on the old code (off: "DeepSeek Chat · Relay A", "Fast · routing
group"), passes with the fix.
- name-suffix-remote.test.cjs, Chromium and WebKit, en/zh/zh-TW/ja/de at
420px: 10/10; on the old app.js it fails ("… · Relay A"). Sibling
name-suffix-*.test.cjs and names-fold: 86/86.
- go test -tags nogui ./internal/{catalog,provider,gui,agent,gateway}
under a temp HOME with pinned caches: ok. gofmt -l clean; go vet
darwin/linux/windows on the touched packages: ok. Full suite before push.
84 lines
5.4 KiB
JavaScript
84 lines
5.4 KiB
JavaScript
// 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. Names & levels says what the agents' lists
|
||
// show under each choice: 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) {
|
||
let cur = { lang, theme: "light", plainNames: false, plainOwnNames: false };
|
||
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
||
const models = [
|
||
{ id: "relaya/deepseek-chat", name: "DeepSeek Chat · Relay A", plain: "DeepSeek Chat", 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/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);
|
||
const errors = [], posts = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", serve(lang, posts));
|
||
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("Names & levels"), exact: true }).click();
|
||
const sfx = page.locator(".mnames:not([hidden]) .msuffix");
|
||
await sfx.waitFor();
|
||
assert.equal((await sfx.locator(".opt.on").textContent()).trim(), await tr("On"));
|
||
assert.equal(await sfx.locator(".hint").textContent(), await tr("Agents’ lists show “{label}”", { label: "DeepSeek Chat · Relay A · Remote magpie" }));
|
||
await sfx.locator(".opt", { hasText: await tr("Off") }).click();
|
||
await page.locator(".mnames:not([hidden]) .msuffix .opt.on", { hasText: await tr("Off") }).waitFor();
|
||
await says(sfx.locator(".hint"), await tr("Agents’ lists show “{label}”", { label: "DeepSeek Chat" }));
|
||
assert.deepEqual(posts, [{ mode: "off" }]);
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
}
|