From 041d745ff34dc86f91e236ca47a103f04bc29713 Mon Sep 17 00:00:00 2001 From: wangtiance Date: Mon, 30 Nov 2026 12:29:37 +0800 Subject: [PATCH] [test] Wait for real saves and decoded subject images in Nightly --- docs/development/lessons.md | 1 + tests/browser/node_versions.mjs | 14 +++++++++++--- tests/browser/subject_node_media.mjs | 12 +++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/development/lessons.md b/docs/development/lessons.md index 20e3ea60f..daa78424b 100644 --- a/docs/development/lessons.md +++ b/docs/development/lessons.md @@ -68,6 +68,7 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u - Browser checks that inspect a canvas image or video after reopening a project or placing a result should bring the target node into view first. - The subject-library and video-review checks in Nightly run 45572808123 reached their persisted-state assertions before the lazy previews were ready. After fitting the canvas, wait for the target image to load or the video to load metadata, then verify the dimensions or duration. [Nightly run 45572808123](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/45572808123/job/139063347523) +- [Nightly run 46322961844](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/46322961844/job/141535114491) reached a subject image fingerprint check after the element mounted but before its source was ready. Wait for a nonempty source and decode before reading bytes. The same run's history dialog test intercepted a save on a clean canvas. Make a real edit before testing the pending or failed save states, since the save queue skips unchanged content. ## Browser clock pauses must precede short-lived observations diff --git a/tests/browser/node_versions.mjs b/tests/browser/node_versions.mjs index 3644bc794..b5871575f 100644 --- a/tests/browser/node_versions.mjs +++ b/tests/browser/node_versions.mjs @@ -166,6 +166,13 @@ try { await page.getByText("已保存到本机", { exact: true }).waitFor(); const source = page.locator(`.react-flow__node[data-id="${fixture.source}"]`); const target = page.locator(`.react-flow__node[data-id="${fixture.target}"]`); + const renameTarget = async (name) => { + await target.locator(".cw-node-title").dblclick(); + const title = target.locator(".cw-node-title-input"); + await title.fill(name); + await title.press("Enter"); + await target.getByText(name, { exact: true }).waitFor(); + }; await source.getByRole("button", { name: "历史版本,共 2 个" }).waitFor(); await page.evaluate(async (id) => { const client = ( @@ -190,8 +197,7 @@ try { projection.save = save; }, }; - // Opening history flushes through projection.save. A clean canvas never - // reaches batch, so hold the flush the dialog actually awaits. + // Hold the dirty document save that history preparation must await. projection.save = async (...args) => { await gate; try { @@ -209,6 +215,7 @@ try { return view(...args); }; }, fixture.id); + await renameTarget("历史图片(待保存)"); await target.getByRole("button", { name: "历史版本,共 2 个" }).click(); const dialog = page.getByRole("dialog", { name: "节点历史版本" }); await dialog.waitFor({ timeout: 1500 }); @@ -807,11 +814,12 @@ try { window.restoreHistoryBatch = () => { projection.save = save; }; - // A clean canvas does not call batch. The dialog awaits this flush. + // The dialog must surface a failure while saving a real edit. projection.save = async () => { throw new Error("模拟草稿保存失败"); }; }, fixture.id); + await renameTarget("历史图片(重试保存)"); await target.getByRole("button", { name: "历史版本,共 3 个" }).click(); await dialog .getByRole("alert") diff --git a/tests/browser/subject_node_media.mjs b/tests/browser/subject_node_media.mjs index 2baca60f6..0356a866e 100644 --- a/tests/browser/subject_node_media.mjs +++ b/tests/browser/subject_node_media.mjs @@ -261,12 +261,14 @@ try { }); } const target = node(fixture.images[0]); - const mainBefore = await target - .locator(".cw-subject-main img") - .getAttribute("src"); + const mainImage = target.locator('.cw-subject-main img[src]:not([src=""])'); + const mainBefore = await mainImage.getAttribute("src"); const mainFingerprint = () => - target.locator(".cw-subject-main img").evaluate(async (element) => { - const bytes = await (await fetch(element.src)).arrayBuffer(); + mainImage.evaluate(async (element) => { + await element.decode(); + const response = await fetch(element.currentSrc); + if (!response.ok) throw new Error(`Main subject image read failed: ${response.status}`); + const bytes = await response.arrayBuffer(); return Array.from( new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)), ).join(",");