Files
magpie/internal/gui/tests/provider-test-v1.test.cjs
T
yetone 2fbead7983 provider: a relay URL typed without its /v1 (CRS's …/openai) is tested, detected and listed under it (Cyrus_4433 on X)
Cyrus_4433 added a claude-relay-service provider as OpenAI compatible at
http://<ip>:55088/openai. The list couldn't be fetched and Test models
said "gpt-6.1-sol: 404 · Not Found". From CRS's src/app.js and routes:
/openai mounts unifiedRoutes (POST /v1/chat/completions) and
openaiRoutes (/responses, /v1/responses); /api mounts GET /v1/models.
There is no /openai/chat/completions or /openai/models, and anything
unrouted is 404 {"error":"Not Found",...}. magpie asked base +
/chat/completions, i.e. /openai/chat/completions.

- probe: a Chat/Responses 404 at an unversioned base equal to the
  provider's URL is asked once more at base/v1/... (missingV1; not
  accounts, Azure, Bedrock, Vertex). Answered OK there, the saved URL
  takes /v1 (setV1) and the result carries it (Result.V1); Detect uses
  it as the base; the editor's URL field follows (draft.onV1) so Save
  doesn't undo it. A 404 at both stays the first 404.
- catalog: an unversioned …/openai base is also listed at
  <origin>/api/v1/models (RelayOpenAIList), and fixV1 adds /v1 when the
  list answered there.

Run (WSL magpie-desktop via wsl-run; mote's sshd reset every
connection this session):
- at 630b0de98 (this change on 987eac0aa): go vet -tags nogui (linux),
  CGO_ENABLED=0 GOOS=windows and GOOS=darwin go vet of the touched
  packages ok; go test -tags nogui ./internal/catalog ./internal/provider
  ./internal/gui ok; GUI chromium + webkit: provider-test-v1 (new: en/zh,
  900/420px, Test models and a chip's Test this model, then Save posts
  .../v1), model-test-one, model-test-why, model-test-stop,
  provider-detect-models, provider-base-api: 54 pass, 0 fail.
- rebased again on 6b92824ff, the core went 366 bytes over its budget;
  five provider-test comments cut in app.js pay for it, no raise
  (core 1,533,689 <= 1,533,802). At this head: internal/gui's budget
  tests, internal/catalog and internal/provider, and the
  provider-test-v1 and model-test-one GUI files: all ok, 20 pass 0 fail.
- models-works-only is red, also red on untouched origin/main
  7c41060c2: #4391 (commented there). gofmt -l clean.

Broken by hand: missingV1 returning false and RelayOpenAIList returning
"" -> TestCRSOpenAIBaseTestsUnderV1/ListsAtAPI/DetectsV1 red with
"gpt-6.1-sol: 404 Not Found"; restored.

Not tried: a real CRS instance (the fake follows its routes and 404
body); the gateway itself doesn't retry /v1 for a provider never
tested, listed or detected since this release (the user presses Test
models or types .../openai/v1); the full suite runs after the tag; no
Windows or macOS run.
2026-11-10 18:07:27 +08:00

92 lines
5.5 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// A relay typed without the /v1 it serves OpenAI's API under (Cyrus_4433 on
// X: claude-relay-service at http://host:port/openai, every model 404 Not
// Found): Test models is answered under …/openai/v1 and says so (v1), and the
// editor's Base URL takes it, so Save keeps …/openai/v1 instead of putting
// the URL back as typed. Right-click's one-model test does the same. In
// English and Chinese, Chromium and WebKit, at 900px and 420px.
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 BASE = "http://216.36.117.18:55088/openai";
const IDS = ["gpt-6.1-sol", "gpt-6-sol"];
const relay = {
id: "my-relay", name: "My Relay", icon: "generic", chat: BASE, responses: "", anthropic: "", catalog: "",
models: IDS.map((id) => ({ id, name: id, on: true })), chosen: IDS, agents: [], fallback: [], headers: {},
key: { set: true, masked: "cr_1…4209" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", listOff: true,
};
function serve(lang, posts) {
const providers = { providers: [relay], presets: [], excluded: [], gateway: { running: true, window: true } };
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
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(state);
if (url.pathname === "/api/providers") return json(providers);
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname.startsWith("/api/provider/")) {
const body = route.request().postDataJSON();
posts.push({ path: url.pathname, body });
if (url.pathname === "/api/provider/test") return json({ results: body.test.map((id) => ({ ok: true, ms: 321, model: id, protocol: "chat", status: 200, v1: BASE + "/v1" })) });
return json({});
}
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 route.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"]) {
for (const width of [900, 420]) {
for (const how of ["all", "one"]) {
test(`${engine} ${lang} ${width}px ${how}: a test answered under /v1 sets the Base URL`, async (t) => {
const zh = lang === "zh";
const L = { all: zh ? "测试模型" : "Test models", item: zh ? "测试此模型" : "Test this model", save: zh ? "保存" : "Save" };
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
t.after(() => browser.close());
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const posts = [];
await page.route("**/*", serve(lang, posts));
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: "My Relay" }).click();
const ed = page.locator(".editor");
await ed.locator(".base-url").waitFor();
assert.equal(await ed.locator(".base-url").inputValue(), BASE);
const tested = () => posts.filter((p) => p.path === "/api/provider/test").length;
if (how === "all") {
await ed.locator(".mfoot").getByRole("button", { name: L.all, exact: true }).click();
} else {
const chip = ed.locator(".mchips .mchip", { hasText: IDS[0] });
await chip.scrollIntoViewIfNeeded();
await page.waitForTimeout(150); // the editor's scroll settles (model-test-one)
await chip.click({ button: "right" });
await page.locator(".pop.row-menu").getByRole("menuitem", { name: L.item }).click();
}
for (let i = 0; i < 60 && !tested(); i++) await page.waitForTimeout(50);
assert.equal(tested(), 1);
await page.waitForFunction((want) => document.querySelector(".editor .base-url")?.value === want, BASE + "/v1");
await ed.locator(":scope > .bar").getByRole("button", { name: L.save, exact: true }).click();
for (let i = 0; i < 60 && !posts.some((p) => p.path === "/api/provider/save"); i++) await page.waitForTimeout(50);
const save = posts.find((p) => p.path === "/api/provider/save");
assert(save, "saved");
assert.equal(save.body.chat, BASE + "/v1", "Save keeps the /v1 the test found");
assert.deepEqual(errors, []);
});
}
}
}
}