RIck (Discord #feedback): after pressing 测试模型, the error took too long
to show, and the test couldn't be cancelled.
Fail fast. Each probe now has 10s (connectWait) to get a connection,
traced through httptrace's GotConn. If it doesn't get one, the error says
"couldn't connect to <host> in 10s". In the past a refused, unresolved or
silent host waited out the whole 20s probe, or TLS's own timeout, once for
every model. TestModels keeps the hosts it couldn't reach for the run
(withUnreached). Once one model on a host fails to connect, the rest of
that host's models fail at once with the same error, so they don't each
wait 10s in turn, four at a time. The 20s per-probe bound and the GUI's
3m/25s bounds are unchanged. A stream that breaks off before the model
answers is now a failure ("the stream broke off before the model
answered"), not a long wait. Plugin and account transports don't get the
connect bound, since they dial for themselves.
Stop. While a provider has a test running, its Test models button (the
model editor), its endpoints' Test, and a chip's own right-click test all
read Stop (停止 / 停止 / 停止 / Stoppen). Pressing Stop aborts the fetch
and posts provider/teststop with the run's token. The handler keeps each
run's cancel in testRuns, so the vendor's request ends on the server too.
This matters on WebView2, where a fetch abort never reaches the request's
context. The status line then reads "Test stopped". Every entry point goes
through one helper (provTest, testButton), so they behave the same.
app.js fits its budget with no raise. The helpers are compact, and three
comments in the editor's Fetch models were cut down.
Tests:
- TestTestModelsUnreachedHostFailsOnce: a listener that accepts and never
speaks TLS, connectWait set to 200ms and 8 models. Every model's error
must be "couldn't connect", and the listener may get at most 4
connections.
- TestStreamAnswerBrokenOff.
- TestProviderTestStops (models and endpoints): a fake vendor holds the
request until its context ends. The test waits for the request to
arrive, posts teststop, and waits for the reply to say canceled and for
the vendor's request to end. It waits on that state, not on a duration.
- model-test-stop.test.cjs: all three buttons read Stop, teststop is
posted with the run, the labels come back, the status reads Test
stopped, there is no left-border accent, and nothing overflows at
560px. It runs in Chromium and WebKit, in en, zh, zh-TW, ja and de.
Broken by hand (each one went red, then the fix was restored):
- the GUI test against origin/main's app.js;
- teststop's post removed ("Stop posted no teststop");
- teststop not cancelling ("the test went on after Stop");
- dead.Store removed (8 connections);
- the connecting wrap removed (TLS handshake timeout after 10s).
Run:
- At the pushed head:
- mote: TestCoreScriptBudget, TestProviderTestStops, the i18n Go tests,
TestTestModelsUnreachedHostFailsOnce and TestStreamAnswerBrokenOff:
ok.
- wsl-run (load 179): model-test-stop 10/10 and i18n-keys 4/4.
- model-test-one: webkit zh was red, "model-c moved on its right-click",
445.37 vs 444.89. origin/main's app.js was red the same way 3 of 6
times, in en and zh. That file is on #4218.
- provider-typed: 4 red (locator.fill 5s); see #4461.
- On the change before its last rebase:
- gofmt clean. GOOS=windows go vet and GOOS=linux -tags nogui go vet:
ok.
- Full Go suite on mote (-timeout 45m, tee'd): 79 packages ok.
internal/gui failed only on the ten AppKit window tests #4125 names.
- Whole GUI suite on Linux WSL (both engines, every language): 15,767
tests, 502 red across about 125 files, at load 160 to 175. The 8
provider-editor files gave the same pass and fail set at fresh
origin/main ccbefe2a2. The reds are on the WSL issues; the 12 files
no issue named are filed as #4461.
Not tried:
- Stop in the real Windows app (WebView2).
- A real vendor, or a real unreachable host outside the tests.
- Plugin and account transports (no connect bound for them).
- The Fetch models step inside the endpoints' test.
- The CLI's test path and Detect, which get the connect bound through
probeOnce but weren't exercised.
- The macOS GUI suite, since mote's WebKit is broken (#4125).
134 lines
8.0 KiB
JavaScript
134 lines
8.0 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A test under way can be stopped (RIck on Discord: 测试模型 took long to
|
|
// fail and couldn't be cancelled). While provider/test hasn't answered, the
|
|
// editor's Test models and the endpoints' Test read Stop; Stop aborts the
|
|
// request and posts provider/teststop with the run the test was sent with,
|
|
// so the server ends the vendor's request too, then the buttons read as
|
|
// before and the footer says the test was stopped. A chip's own test is
|
|
// stopped from the same button. No left-border accent, at a narrow width,
|
|
// in every language, Chromium and WebKit.
|
|
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 IDS = ["gpt-5.1", "model-b"];
|
|
const relay = {
|
|
id: "relay", name: "Relay", preset: "relay", icon: "generic", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "",
|
|
models: IDS.map((id) => ({ id, name: id, on: true })), agents: [], fallback: [], headers: {},
|
|
key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
|
|
};
|
|
|
|
// provider/test never answers: the request waits until the page aborts it
|
|
function serve(lang, tests, stops) {
|
|
// a preset's provider, so its editor shows the endpoints and their Test
|
|
const providers = { providers: [relay], presets: [{ id: "relay", name: "Relay", icon: "generic", chat: relay.chat, added: true }], 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 === "/api/provider/test") { tests.push(route.request().postDataJSON()); return; }
|
|
if (url.pathname === "/api/provider/teststop") { stops.push(route.request().postDataJSON()); return route.fulfill({ status: 204, body: "" }); }
|
|
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 });
|
|
};
|
|
}
|
|
|
|
const words = {
|
|
en: { test: "Test", all: "Test models", item: "Test this model", stop: "Stop", stopped: "Test stopped" },
|
|
zh: { test: "测试", all: "测试模型", item: "测试此模型", stop: "停止", stopped: "已停止测试" },
|
|
"zh-TW": { test: "測試", all: "測試模型", item: "測試此模型", stop: "停止", stopped: "已停止測試" },
|
|
ja: { test: "テスト", all: "モデルをテスト", item: "このモデルをテスト", stop: "停止", stopped: "テストを停止しました" },
|
|
de: { test: "Testen", all: "Modelle testen", item: "Dieses Modell testen", stop: "Stoppen", stopped: "Test gestoppt" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of Object.keys(words)) {
|
|
const w = words[lang];
|
|
test(`${engine} ${lang}: a test under way is stopped from its button`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await (await browser.newContext({ viewport: { width: 560, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-model-test-stop.png`) });
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const tests = [], stops = [];
|
|
await page.route("**/*", serve(lang, tests, stops));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider", { hasText: "Relay" }).click();
|
|
await page.locator(".editor .mchips .mchip").first().waitFor();
|
|
const all = page.locator(".editor .mfoot button[data-tests]");
|
|
const ep = page.locator(".editor .eps button[data-tests]");
|
|
const until = async (cond, what) => { for (let i = 0; i < 100; i++) { if (await cond()) return; await page.waitForTimeout(50); } assert.fail(what); };
|
|
const reads = async (b, text) => until(async () => (await b.textContent()) === text, `the button never read ${text}`);
|
|
const footer = () => page.waitForFunction((want) => document.querySelector("#status")?.textContent === want, w.stopped);
|
|
|
|
// Test models, then Stop
|
|
assert.equal(await all.textContent(), w.all);
|
|
await all.click();
|
|
await until(async () => tests.length === 1, "Test models sent nothing");
|
|
assert.deepEqual(tests[0].test, IDS);
|
|
assert(tests[0].run, "the test is sent with a run to stop it by");
|
|
await reads(all, w.stop);
|
|
await reads(ep, w.stop);
|
|
const border = await page.evaluate(() => [...document.querySelectorAll(".editor button[data-tests]")].map((e) => getComputedStyle(e).borderLeftWidth).filter((b) => parseFloat(b) > 1));
|
|
assert.deepEqual(border, [], "no left-border accent");
|
|
const over = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth);
|
|
assert.equal(over, false, "nothing runs off the page");
|
|
await all.click();
|
|
await until(async () => stops.length === 1, "Stop posted no teststop");
|
|
assert.deepEqual(stops[0], { run: tests[0].run }, "teststop names the test's run");
|
|
await reads(all, w.all);
|
|
await reads(ep, w.test);
|
|
await footer();
|
|
|
|
// the endpoints' Test, stopped from itself
|
|
await page.evaluate(() => { document.querySelector("#status").textContent = ""; });
|
|
await ep.click();
|
|
await until(async () => tests.length === 2, "Test sent nothing");
|
|
assert.equal(tests[1].test, undefined, "the endpoint test names no models");
|
|
await reads(ep, w.stop);
|
|
await ep.click();
|
|
await until(async () => stops.length === 2, "Stop posted no teststop");
|
|
assert.equal(stops[1].run, tests[1].run);
|
|
assert.notEqual(tests[1].run, tests[0].run, "each test has its own run");
|
|
await reads(ep, w.test);
|
|
await footer();
|
|
|
|
// a chip's own test, stopped from Test models' place
|
|
await page.evaluate(() => { document.querySelector("#status").textContent = ""; });
|
|
await page.locator(".editor .mchips .mchip", { hasText: "model-b" }).click({ button: "right" });
|
|
await page.locator(".pop.row-menu").getByRole("menuitem", { name: w.item }).click();
|
|
await until(async () => tests.length === 3, "the chip's test sent nothing");
|
|
assert.deepEqual(tests[2].test, ["model-b"]);
|
|
await reads(all, w.stop);
|
|
await all.click();
|
|
await until(async () => stops.length === 3, "Stop posted no teststop");
|
|
assert.equal(stops[2].run, tests[2].run);
|
|
await reads(all, w.all);
|
|
await footer();
|
|
|
|
if (lang !== "en") {
|
|
const missing = await page.evaluate((l) => ["Stop", "Test stopped"].filter((k) => !I18N[l][k]), lang);
|
|
assert.deepEqual(missing, [], "every string has its translation");
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|