gui tests: market-have waits for the market's answer, not 2s, before looking for a mark (#1631)

"a server added by hand is marked added" timed out under the full suite.
The mark comes after two reads in a row: the change's answer, then the
market asked again (take() -> fetchMarket). Holding those answers in the
test showed nothing is dropped: with the save, the library and the market
each held 0 to 1200ms the mark always came, at about the sum of the
holds. The 2s bound on the whole was the busy machine's to miss: with the
save and the market each held 1200ms the old test failed in both engines.

Each of the three steps now waits for the market's answer that follows
its change (10s, the page's 5s for each of the two reads), then for the
mark with the page's own timeout. What the test checks is that the mark
comes with no focus (still asserted), not how fast.

Run: the save, library and market each held 0, 1200 and 3000ms: 8/8
green in Chromium and WebKit each time. Broken by hand (take() no longer
asks the market again): all three steps red, 8 of 8. 20/20 green in
WebKit and 20/20 in Chromium.
This commit is contained in:
yetone
2026-10-12 01:55:05 +08:00
parent 0b34449999
commit 9424639744
+16 -3
View File
@@ -99,14 +99,23 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const card = (kind, id) => view.locator(`.mk[data-market="${kind}"] .mk-card[data-id="${id}"]`);
await card("mcp", "playwright").locator(".mk-have").waitFor();
await card("mcp", "fetch").locator(".mk-add").waitFor();
// A mark follows the change's answer and the market's answer after it,
// two reads one after the other: each step waits for the market's
// answer, given the page's timeout for each of the two reads, then for
// the mark. A 2s bound on the whole was a busy machine's to miss
// (#1631); what this checks is that the mark comes with no focus, not
// how fast.
const answered = (kind) => page.waitForResponse((r) => new URL(r.url()).pathname === "/api/library/market/" + kind, { timeout: 10000 });
await t.test("a server removed is no longer marked added", async () => {
const top = await view.evaluate((e) => e.scrollTop);
const before = calls.filter((c) => c === "market/servers").length;
await view.locator(".lib-row", { hasText: "playwright" }).click();
await page.getByRole("button", { name: words[lang].remove, exact: true }).click();
const market = answered("servers");
await page.locator("dialog.action-confirm[open] button").last().click();
await card("mcp", "playwright").locator(".mk-add").waitFor({ timeout: 2000 });
await market;
await card("mcp", "playwright").locator(".mk-add").waitFor();
assert.equal(await card("mcp", "playwright").locator(".mk-have").count(), 0);
assert.equal(await card("mcp", "playwright").evaluate((e) => e.classList.contains("have")), false);
assert(calls.filter((c) => c === "market/servers").length > before, "the market was not asked again");
@@ -119,16 +128,20 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const ed = page.locator(".lib-editor");
await ed.locator('input[placeholder="e.g. github"], input[placeholder="例如 github"]').fill("fetch");
await ed.locator('input[placeholder="npx -y @modelcontextprotocol/server-github"]').fill("uvx mcp-server-fetch");
const market = answered("servers");
await ed.getByRole("button", { name: words[lang].add, exact: true }).click();
await card("mcp", "fetch").locator(".mk-have").waitFor({ timeout: 2000 });
await market;
await card("mcp", "fetch").locator(".mk-have").waitFor();
});
await t.test("a skill removed is no longer marked added", async () => {
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible").nth(2).click();
await card("skills", "acme/skills/pdf").locator(".mk-have").waitFor();
await view.locator(".lib-row", { hasText: "pdf" }).locator(".lib-icon.danger").click();
const market = answered("skills");
await page.locator(".lib-editor").getByRole("button", { name: words[lang].removeSkill, exact: true }).click();
await card("skills", "acme/skills/pdf").locator(".mk-add").waitFor({ timeout: 2000 });
await market;
await card("skills", "acme/skills/pdf").locator(".mk-add").waitFor();
});
assert.equal(await page.evaluate(() => window.__focus), 0, "the window was focused again");