axelburks on Discord: a vendor routes one model by a header of its own. A key's provider (built-in or custom) can give each model headers (settings.ModelHeaders["pid/model"]). They go on that provider's requests for that model alone, after the provider's headers and after auth: a name both have is sent once, as the model's, so a user's value is never overridden by the provider's or magpie's key header. The gateway names the model (provider.WithModel) on every route that asks one: chat on each API, translated and streamed, count_tokens, System One's decision, embeddings, images, videos and the model test. A fallback provider serving the same model id gets its own headers only. Accounts and plugins carry their sign-in's headers and take none. The editor's "Name, price and reasoning level" panel is now "Model settings" (every language), with + Add header per model, staged and made with the Save; Restore default takes them away. The rows being typed are kept out of the draft's compare, so an untouched editor still closes without asking. Broken by hand: dropping WithModel from gateway.go turns TestModelHeadersReachTheirModelOnEveryRoute red; dropping the provider id check in modelOf turns TestModelHeadersStayWithTheirProvider red. Run, on this stack over origin/main0fc3455e2(mote's suite lock had hours of queue, so the suites ran on WSL magpie-desktop under flock): - go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx} on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean; go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok; TestCoreScriptBudget ok (paid by cutting comments, no raise). - GUI, both engines, every language, on WSL at the pushed head and at0fc3455e2: every touched test file plus the provider-editor files a first run found red. No red at head that isn't red at0fc3455e2. The shared reds have issues: i18n-keys #5332, model-chip-steady #4388, model-copy-id #4621, models-works-only #4391, plugin-move-unserved #4392, provider-fetch-again #5232, provider-levels-save #4394, provider-levels-scroll #4395, provider-models-rest #4396, provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398, zero-priced-free #5262, model-reasonless (webkit de) #4100, name-suffix-no-names #1937. - Rebased on origin/main4ab1191bc(gateway.go moved under it) and run again at the pushed head: gateway and provider ok on WSL, gofmt, vet (mac, linux nogui, windows) and the budget ok, i18n-keys, model-headers and routing-groups-back with only #5332's red. Not run at push: the whole GUI suite (1277 files). Not tried: a real vendor that routes by header (Ark); fake vendors only. Reported-by: axelburks (Discord)
86 lines
5.3 KiB
JavaScript
86 lines
5.3 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. 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) {
|
||
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", 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);
|
||
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, []);
|
||
});
|
||
}
|
||
}
|