From fad2de118e68857a93bd9aa7fd374483c16f2190 Mon Sep 17 00:00:00 2001 From: wtz2333 Date: Thu, 19 Nov 2026 16:30:36 +0800 Subject: [PATCH] [fix] browser: retry a history command on a stale snapshot The workspace autosaves while the suite reads a snapshot to build expectedVersions, so a save that lands between the read and the command makes the server reject it as revision_conflict. That is the documented reload-and-retry contract, so the suite now waits for the save indicator, re-reads the revisions and retries up to three times instead of failing on a stale snapshot. --- tests/browser/created_node_focus.mjs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/browser/created_node_focus.mjs b/tests/browser/created_node_focus.mjs index d33af2ccd..3e128e5b8 100644 --- a/tests/browser/created_node_focus.mjs +++ b/tests/browser/created_node_focus.mjs @@ -90,12 +90,25 @@ try { // Restoring an existing identity must not be mistaken for remote creation, // including when it arrives through the event stream rather than UI undo. const read = () => call(`/api/creation/projects/${projectId}`); + // The workspace autosaves on its own, so a save can land between reading the + // revisions below and posting the command. That is the documented "the item + // changed since it was loaded, reload and try again" race, not a history bug: + // refresh the revisions and retry instead of failing on a stale snapshot. + const settle = async () => { + await page.getByText('Saved on this device', { exact: true }).first().waitFor({ timeout: 5000 }).catch(() => {}); + }; const send = async (type, payload) => { - const current = await read(); - return call(`/api/creation/projects/${projectId}/commands`, { - commandId: crypto.randomUUID(), projectId, type, payload, - expectedVersions: current.canvasItems.map((item) => ({ objectType: 'canvas_item', id: item.id, revision: item.revision })), - }); + for (let attempt = 1; ; attempt += 1) { + await settle(); + const current = await read(); + const receipt = await call(`/api/creation/projects/${projectId}/commands`, { + commandId: crypto.randomUUID(), projectId, type, payload, + expectedVersions: current.canvasItems.map((item) => ({ objectType: 'canvas_item', id: item.id, revision: item.revision })), + }); + const stale = receipt.status === 'rejected' && receipt.issues?.some((issue) => issue.code === 'revision_conflict'); + if (!stale || attempt === 3) return receipt; + await page.waitForTimeout(150); + } }; const shown = (id) => page.locator(`.react-flow__node[data-id="${id}"]`); const selection = () => page.locator('.react-flow__node.selected').evaluateAll((nodes) => nodes.map((node) => node.dataset.id).sort());