Claude Code's WebSearch and Codex's web_search never name a count, so magpie answered every such search with searchHits, 6 pages (#5545, mdwsk88: more pages for research-heavy work, fewer to save context). settings.SearchCount holds the count. 0 means the default, 6 (SearchCountDefault), and the most is 20 (SearchCountMost), the most Brave and Tavily return. Save refuses a value out of range, so nothing is written. Settings.SearchPages reads it. The gateway's searchCount falls back to it when a search names no count. The web_search MCP tool still answers a named count with that count, and its schema's default says the count set. It reaches every search API (Brave, Tavily, Exa, You, the plugins' searchers), as a named count already did. - Settings › Models › Web search: "Results per search", segments 3, 6, 10, 15 and 20, plus a count set by hand in settings.json. POST /api/settings/search-count sets it alone. settingsapi.Apply keeps it as it keeps search-all, so a save of the Settings form doesn't put it back. - CLI: magpie search count says the count; magpie search count <n> sets it; magpie search count default puts 6 back. A bad value is refused and nothing is written. - docs/subsystems/gateway-routing.md says it. - New strings are in zh, zh-TW, ja and de. Run at this tree (mote-run, macOS): - go test -count=1: internal/settings, settingsapi, cli, gateway (TestSearchMCPCount, TestSearchCountReachesEveryAPI, TestSearchCountSetting), and gui (TestSettingsSearchCountSetOnItsOwn, and TestSettingsSaveKeepsWhatItDoesNotSend with SearchCount set): ok. internal/gateway whole: ok with -timeout 45m (847s). internal/gui whole: ok but TestMainWindowCorners/macOS_26_SDK (#3949, mote is on macOS 27). The first cli run was red on TestEveryRouteHasACommandOrIsNamed: the new route had no CLI entry. cliForRoute maps it to search count now. - Broken by hand: searchCount returning searchHits again makes TestSearchCountSetting fail ("set 11: a search naming no count asks for 6, want 11"). Restored, it passes. - GUI: node --test --test-concurrency=4 over routing-*, usage-*, ledger-*, panel-*, call-*, search-*, searcher-*, settings-*, i18n-* and gui-* (Chromium and WebKit; the files cover en, zh, zh-TW, ja and de), with #2398 and #5545 in one tree: 4961 of 5016 ok. The 55 reds are in 12 files. i18n-keys' "a plugin's words are its own" names other files' strings (#5327, #5426, #5482). The other 11 files were run alone at dc49feca9 (this tree without either change) and at this tree: 52 and 51 reds, the same tests. The one apart is usage-focus-steady, which flakes (#3501). Each is filed: #5392, #3414, #5048, #3799, #3415, #3954, #4627, #4628, #5223, #1529. routing-canceled-row.test.cjs: 10 of 10. With the .rt-req.gone rule taken out, its dot is the answered green rgb(24, 154, 88) and it fails. Restored, it passes. - Not tried: a real Claude Code WebSearch through this tree with a live search API key. The tests use fake search APIs. Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com> Reported-by: mdwsk88 (dawei on Discord)
124 lines
6.6 KiB
JavaScript
124 lines
6.6 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||
// Settings › Models › Web search (#5545, mdwsk88): "Results per search" is
|
||
// how many results a search that names no count (Claude Code's WebSearch,
|
||
// Codex's web_search) is answered with. It shows 6 when none is set, and
|
||
// a count set by hand in settings.json among the choices; a click sets it
|
||
// on its own (POST /api/settings/search-count), not with a save of the
|
||
// page, and moves nothing. In every language, wide and narrow.
|
||
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 { watchSettingsReads, settingsDrawn, reach } = require("./reader.cjs");
|
||
|
||
const assets = path.resolve(__dirname, "../assets");
|
||
const words = {
|
||
en: "Results per search",
|
||
zh: "每次搜索的结果条数",
|
||
"zh-TW": "每次搜尋的結果數",
|
||
ja: "1 回の検索の結果数",
|
||
de: "Ergebnisse pro Suche",
|
||
};
|
||
|
||
function serve(lang, saved, counts, searchCount) {
|
||
const settings = { lang, theme: "light", redact: true, searcher: "ds", searchCount,
|
||
searchProvider: "DeepSeek · deepseek-flash",
|
||
searchVendors: [{ id: "tavily", name: "Tavily", keysURL: "https://app.tavily.com/home" }],
|
||
searchAPIs: [{ vendor: "tavily", name: "Tavily", key: "tvly…abcd", ready: true }],
|
||
searchChoices: [{ id: "ds", name: "DeepSeek", icon: "deepseek", small: "deepseek-flash", models: [] }] };
|
||
const state = { agents: [], profiles: [], settings };
|
||
return async (r) => {
|
||
const url = new URL(r.request().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/search-count") {
|
||
counts.push(JSON.parse(r.request().postData()));
|
||
settings.searchCount = counts.at(-1).n;
|
||
return json(settings);
|
||
}
|
||
if (url.pathname === "/api/settings") {
|
||
if (r.request().method() === "POST") {
|
||
saved.push(JSON.parse(r.request().postData()));
|
||
Object.assign(settings, saved.at(-1));
|
||
}
|
||
return json(settings);
|
||
}
|
||
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
|
||
if (url.pathname === "/api/providers") return json({ providers: [], 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)];
|
||
try { await r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404 }); }
|
||
};
|
||
}
|
||
|
||
async function open(engine, t, lang, saved, counts, searchCount, width) {
|
||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||
t.after(() => browser.close());
|
||
const page = await (await browser.newContext({ viewport: { width, height: 900 } })).newPage();
|
||
page.setDefaultTimeout(5000);
|
||
page.setDefaultNavigationTimeout(60000);
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", serve(lang, saved, counts, searchCount));
|
||
await watchSettingsReads(page);
|
||
await page.goto(`http://magpie.test/?view=settings&tab=models&lang=${lang}`);
|
||
await settingsDrawn(page);
|
||
return { page, errors };
|
||
}
|
||
|
||
async function press(page, locator) {
|
||
await reach(page, locator);
|
||
const b = await locator.boundingBox();
|
||
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
|
||
}
|
||
|
||
const choices = (row) => row.locator(".segs button").evaluateAll((bs) => bs.map((b) => b.textContent.trim()));
|
||
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
for (const [lang, name] of Object.entries(words)) {
|
||
for (const width of [1100, 560]) {
|
||
test(`${engine} ${lang} ${width}px: how many results a search is answered with is set on its own`, async (t) => {
|
||
const saved = [], counts = [];
|
||
const { page, errors } = await open(engine, t, lang, saved, counts, undefined, width);
|
||
const row = page.locator("#searchList #searchCountRow");
|
||
await reach(page, row);
|
||
assert.equal(await row.locator(".name").textContent(), name);
|
||
assert.notEqual(await row.locator(".sub").innerText(), "", "the cost is said");
|
||
assert.deepEqual(await choices(row), ["3", "6", "10", "15", "20"]);
|
||
assert.equal(await row.locator(".segs button.on").textContent(), "6", "6 when none is set");
|
||
assert(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), "the page scrolls sideways");
|
||
const rb = await row.boundingBox();
|
||
for (const b of await row.locator(".segs button").all()) {
|
||
const bb = await b.boundingBox();
|
||
assert(bb.x >= rb.x - 1 && bb.x + bb.width <= rb.x + rb.width + 1, `${await b.textContent()} sticks out of its row`);
|
||
}
|
||
|
||
const ten = row.locator(".segs button", { hasText: /^10$/ });
|
||
await reach(page, ten);
|
||
const before = await page.evaluate(() => [scrollX, scrollY, document.scrollingElement.scrollTop]);
|
||
await press(page, ten);
|
||
for (let i = 0; i < 50 && !counts.length; i++) await page.waitForTimeout(50);
|
||
assert.deepEqual(counts, [{ n: 10 }], "set once, on its own");
|
||
assert.equal(saved.length, 0, "the rest of the settings not written");
|
||
await page.waitForFunction(() => prefsBusy === 0);
|
||
await page.locator("#searchCountRow .segs button.on", { hasText: /^10$/ }).waitFor();
|
||
assert.deepEqual(await page.evaluate(() => [scrollX, scrollY, document.scrollingElement.scrollTop]), before, "the click moved nothing");
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
|
||
test(`${engine} ${lang}: a count set by hand is one of the choices, and on`, async (t) => {
|
||
const { page, errors } = await open(engine, t, lang, [], [], 12, 560);
|
||
const row = page.locator("#searchList #searchCountRow");
|
||
await reach(page, row);
|
||
assert.deepEqual(await choices(row), ["3", "6", "10", "12", "15", "20"]);
|
||
assert.equal(await row.locator(".segs button.on").textContent(), "12");
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
}
|