fix(web): de-race directory browsing in the files panel and workspace picker (#222)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yaowei ZhengandClaude Fable 5 authored and GitHub committed 2026-08-06 20:08:27 +08:00
1 parent 8fc26cc44f
commit c98749fbff
8 files changed
+182 -55

No files matched your search

+29 -2
View File
@@ -201,12 +201,39 @@ test("draft: pick model/approval -> reload restores them -> send creates the ses
await expect(page.getByRole("textbox", { name: "Workspace" })).toHaveValue(
new RegExp(`${wsLabel}$`),
);
await page.getByRole("button", { name: "上级目录" }).click();
// Regression (workspace picker race): while a /dirs request is in flight the picker's rows
// are disabled, so a rapid double-click on "parent dir" must issue exactly ONE request and
// ascend exactly one level — previously both clicks fired an un-sequenced load and could
// relocate the browsing position. The response is gated on an explicit release (not a
// timeout) so the second click deterministically lands inside the loading window.
let releaseDirs;
const dirsGate = new Promise((resolve) => {
releaseDirs = resolve;
});
let dirsRequests = 0;
const dirsRoute = (url) => url.pathname.endsWith("/dirs");
const gateDirs = async (route) => {
dirsRequests += 1;
await dirsGate;
await route.continue();
};
await page.route(dirsRoute, gateDirs);
const upRow = page.getByRole("button", { name: "上级目录" });
await upRow.click();
// force: the row is disabled while loading, and a plain click would stall on Playwright's
// actionability wait instead of exercising the double-click; the disabled button swallows it.
await upRow.click({ force: true });
releaseDirs();
const parentLabel = basename(dirname(namedWs));
await expect(page.getByRole("textbox", { name: "Workspace" })).toHaveValue(
new RegExp(`${parentLabel}$`),
);
await expect(page.getByRole("textbox", { name: "Workspace" })).not.toHaveValue(
new RegExp(`${wsLabel}$`),
);
expect(dirsRequests, "double-click while loading fires a single /dirs request").toBe(1);
await page.unroute(dirsRoute, gateDirs);
await page.getByRole("button", { name: "使用此目录" }).click();
const parentLabel = basename(dirname(namedWs));
await expect(page.getByLabel("Workspace")).toContainText(parentLabel);
await page.reload();
await expect(page.getByLabel("Workspace")).toContainText(parentLabel);