diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 0f7846fa8..99dacb5a9 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -448,7 +448,7 @@ jobs: if: always() run: | mkdir -p nightly-perf/profiles - for profile in /tmp/opendirector-drag-nightly-*.cpuprofile; do + for profile in /tmp/opendirector-drag-*/opendirector-drag-nightly-*.cpuprofile; do if [ -f "$profile" ]; then cp "$profile" nightly-perf/profiles/; fi done - name: Upload perf and output report diff --git a/docs/development/assets/nightly-canvas/README.md b/docs/development/assets/nightly-canvas/README.md new file mode 100644 index 000000000..254f27098 --- /dev/null +++ b/docs/development/assets/nightly-canvas/README.md @@ -0,0 +1,15 @@ +# Nightly canvas interaction evidence / 画布交互验证 + +Recorded from the fix tree based on `9f24de145389dab2186944d6fcc79acee5492dad`, using the isolated creation API, temporary projects and fixture model configurations. No real provider calls. The PR description identifies the committed candidate containing this source and these artifacts. + +- `text-escape.png` and `text-escape.webm`: follow the text case of `canvas_selection_history.mjs`: create/select text, exercise copy/delete/undo, enter inline editing, type ABC and delete C, then press Escape while chat has staged references. The editor closes and AB remains visible. The previous run timed out waiting for that textarea to detach. +- `reference-escape.png` and `reference-escape.webm`: follow the first reference-drag case of `node_connections.mjs`: keep keyboard focus in chat, drag the image reference port, then press Escape. The pending connection preview disappears. The previous run retained one preview after cancellation. +- Previous failures: https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47181192889/job/144520613998 + +Local validation passed: all seven previously failing scripts, `context_menu_dismissal.mjs`, all nine node-connection combinations, three production-preview journeys (`first_last_frame_connections`, `composer_expansion`, `canvas_selection_history`), 19 related Node tests, production build, browser manifest/locale checks and i18n check. Performance sampling asserts real pan/node movement; no speed improvement is claimed. + +Local environment: Windows, Node 26.13.0, Python 3.14.7, Chrome 158, Playwright Core 1.65.1. Full Linux Release checks and Nightly remain for CI. Recordings show focused portions of the regression journeys; the complete script results above were checked separately. + +## 中文 + +录屏和截图来自本分支的实际隔离测试:文本编辑按 Escape 后保留 AB 并退出编辑;键盘焦点仍在聊天区时,参考连线拖动可被 Escape 取消。原始 Nightly 分别卡在编辑框未移除和连线预览未消失。全部原失败脚本及相关检查已在本机通过,完整 Linux CI 尚待运行。使用临时工程和模型替身,没有真实模型调用,也不宣称性能提升。 diff --git a/docs/development/assets/nightly-canvas/reference-escape.png b/docs/development/assets/nightly-canvas/reference-escape.png new file mode 100644 index 000000000..a97bcb79e Binary files /dev/null and b/docs/development/assets/nightly-canvas/reference-escape.png differ diff --git a/docs/development/assets/nightly-canvas/reference-escape.webm b/docs/development/assets/nightly-canvas/reference-escape.webm new file mode 100644 index 000000000..d7007aca0 Binary files /dev/null and b/docs/development/assets/nightly-canvas/reference-escape.webm differ diff --git a/docs/development/assets/nightly-canvas/text-escape.png b/docs/development/assets/nightly-canvas/text-escape.png new file mode 100644 index 000000000..8f38a16cb Binary files /dev/null and b/docs/development/assets/nightly-canvas/text-escape.png differ diff --git a/docs/development/assets/nightly-canvas/text-escape.webm b/docs/development/assets/nightly-canvas/text-escape.webm new file mode 100644 index 000000000..48e42a4c3 Binary files /dev/null and b/docs/development/assets/nightly-canvas/text-escape.webm differ diff --git a/docs/development/lessons.md b/docs/development/lessons.md index c25a1fbc3..d9aa22b8b 100644 --- a/docs/development/lessons.md +++ b/docs/development/lessons.md @@ -47,6 +47,12 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u - **Check:** Hold the assistant read until the project picker or name editor is active, then release it and verify that both the control and its focus remain. Preserve focus requested by explicitly opening chat or changing conversations, while respecting a later user focus change. Distinguish a controlled reproduction from proof of the original CI event order. - In a narrow chat, dismissing the pending canvas references on pointer-down moved a result button before pointer-up. The click landed on the card and never reached the button. Exercise a real pointer click after returning from a selected canvas node and verify that the node becomes visible again. / 窄屏聊天曾在按下鼠标时收起待引用面板,使结果按钮在松开鼠标前移位。回归应从已有选区的画布返回对话,实际点击结果按钮,并检查对应节点是否重新进入视口。 +## Pointer capture does not transfer keyboard focus + +- **Trigger:** Starting a canvas gesture while chat or another editor still owns keyboard focus, or pressing Escape in an inline editor while chat has staged references. +- **Evidence:** [Nightly run 47181192889](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/47181192889) failed inline-text dismissal and reference-drag cancellation. Local reproduction identified staged-reference capture swallowing the editor's Escape, and the focused chat consuming Escape before the reference gesture's bubbling listener. +- **Check:** Give an active pointer gesture first access to cancellation without cancelling IME composition. Let inline editors own their Escape, and preserve staged-reference dismissal from chat. Exercise these paths with chat open and keyboard focus left in the previously focused control. Canvas-only geometry tests must establish their chat layout or hit-test points inside the actual canvas region; a browser viewport coordinate can hit docked chat instead. + ## Baseline failures still need tracking - **Trigger:** A relevant test fails and comparison shows that it also fails on the baseline. diff --git a/src/canvas/useCanvasReferences.ts b/src/canvas/useCanvasReferences.ts index 96582f391..f8ca4a2a3 100644 --- a/src/canvas/useCanvasReferences.ts +++ b/src/canvas/useCanvasReferences.ts @@ -302,19 +302,22 @@ export function useCanvasReferences(options: { create(d.sources, d.side, client, point, d.anchor); }; const key = (event: KeyboardEvent) => { - if (event.key === "Escape") cancel(); + if (event.key !== "Escape" || event.isComposing || !drag.current) return; + event.preventDefault(); + event.stopPropagation(); + cancel(); }; window.addEventListener("pointermove", move); window.addEventListener("pointerup", up); window.addEventListener("pointercancel", cancel); window.addEventListener("blur", cancel); - window.addEventListener("keydown", key); + window.addEventListener("keydown", key, true); return () => { window.removeEventListener("pointermove", move); window.removeEventListener("pointerup", up); window.removeEventListener("pointercancel", cancel); window.removeEventListener("blur", cancel); - window.removeEventListener("keydown", key); + window.removeEventListener("keydown", key, true); }; }, []); useEffect(() => { diff --git a/src/canvas/usePendingCanvasReferences.ts b/src/canvas/usePendingCanvasReferences.ts index c7d9f5e64..62a1fcab3 100644 --- a/src/canvas/usePendingCanvasReferences.ts +++ b/src/canvas/usePendingCanvasReferences.ts @@ -96,7 +96,7 @@ export function usePendingCanvasReferences( // Menus and open editors own their dismissal, including ARIA-based modals. if ( event.target instanceof Element && - event.target.closest('[role="menu"],dialog:modal,[aria-modal="true"]') + event.target.closest('[role="menu"],dialog:modal,[aria-modal="true"],.cw-text-editor,.cw-composer-dock,.cw-text-window-backdrop') ) return; event.preventDefault(); diff --git a/tests/browser/canvas_creation.mjs b/tests/browser/canvas_creation.mjs index 2bcd22f2d..5612ecca5 100644 --- a/tests/browser/canvas_creation.mjs +++ b/tests/browser/canvas_creation.mjs @@ -7,3 +7,8 @@ export function canvasNodeButton(page, label) { export async function addCanvasNode(page, label) { await canvasNodeButton(page, label).click(); } + +export async function collapseCanvasAssistant(page) { + await page.getByRole("button", { name: /^(收起 AI 对话|Collapse AI chat)$/ }).click(); + await page.locator("#canvas-assistant").waitFor({ state: "hidden" }); +} diff --git a/tests/browser/canvas_selection_history.mjs b/tests/browser/canvas_selection_history.mjs index e6ec98b79..b563c10c1 100644 --- a/tests/browser/canvas_selection_history.mjs +++ b/tests/browser/canvas_selection_history.mjs @@ -154,6 +154,7 @@ try { await editor.press("Backspace"); assert.equal(await editor.inputValue(), "AB"); assert.equal(await page.locator(".react-flow__node").count(), 3); + await page.locator("[data-pending-references]").waitFor(); await editor.press("Escape"); await editor.waitFor({ state: "detached" }); assert.equal( diff --git a/tests/browser/composer_expansion.mjs b/tests/browser/composer_expansion.mjs index bbc29da4d..d35aff38d 100644 --- a/tests/browser/composer_expansion.mjs +++ b/tests/browser/composer_expansion.mjs @@ -1,5 +1,5 @@ /** Isolated fixture only: compact spacing and an expanded editor keep one draft. */ -import { addCanvasNode } from "./canvas_creation.mjs"; +import { addCanvasNode, collapseCanvasAssistant } from "./canvas_creation.mjs"; import assert from "node:assert/strict"; import { join } from "node:path"; import { chooseGenerationModel } from "./model_picker.mjs"; @@ -54,6 +54,7 @@ try { waitUntil: "domcontentloaded", }); await page.getByText("已保存到本机", { exact: true }).waitFor(); + await collapseCanvasAssistant(page); const checked = []; for (const kind of ["视频", "图片"]) { await addCanvasNode(page, kind); diff --git a/tests/browser/first_last_frame_connections.mjs b/tests/browser/first_last_frame_connections.mjs index 7cf2f7195..307df06f7 100644 --- a/tests/browser/first_last_frame_connections.mjs +++ b/tests/browser/first_last_frame_connections.mjs @@ -2,7 +2,7 @@ * both frame slots when the model declares a last frame (#83). * Uses the isolated creation_server.py; no remote generation. */ -import { addCanvasNode } from "./canvas_creation.mjs"; +import { addCanvasNode, collapseCanvasAssistant } from "./canvas_creation.mjs"; import assert from "node:assert/strict"; import { launchBrowser } from "./engine.mjs"; import { chooseGenerationModel } from "./model_picker.mjs"; @@ -68,6 +68,7 @@ try { await page .getByText("已保存到本机", { exact: true }) .waitFor({ state: "attached" }); + await collapseCanvasAssistant(page); // Two distinct real images, each uploaded as its own canvas node. for (const [index, color] of ["#d33", "#36c"].entries()) { diff --git a/tests/browser/multi_selection_references.mjs b/tests/browser/multi_selection_references.mjs index 4586b2279..82488de6e 100644 --- a/tests/browser/multi_selection_references.mjs +++ b/tests/browser/multi_selection_references.mjs @@ -1,5 +1,6 @@ /** Isolated fixture + Vite: selection geometry and real batch reference writes. */ import assert from "node:assert/strict"; +import { collapseCanvasAssistant } from "./canvas_creation.mjs"; const { chromium } = await import( process.env.PLAYWRIGHT_MODULE ?? "playwright-core" ); @@ -94,6 +95,7 @@ try { await page.unroute(bootstrap); await page.goto(`${base}/ai-tool/ai-canvas/${f.id}`); await page.getByText("已保存到本机", { exact: true }).waitFor(); + await collapseCanvasAssistant(page); const node = (id) => page.locator(`.react-flow__node[data-id="${id}"]`); const plus = page.getByRole("button", { name: "批量连接所选节点", diff --git a/tests/browser/node_connections.mjs b/tests/browser/node_connections.mjs index 34ffef5e3..745d7b767 100644 --- a/tests/browser/node_connections.mjs +++ b/tests/browser/node_connections.mjs @@ -321,6 +321,7 @@ try { path: `.opendirector/node-ports-${theme}-active.png`, }); const bounds = await port.boundingBox(); + await page.locator("#canvas-assistant [contenteditable=true]").focus(); await page.mouse.move( bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, @@ -413,13 +414,25 @@ try { assert.equal(await page.locator(".react-flow__edge").count(), 1); } if (!accepted) await page.locator(".cw-toast").waitFor(); - await page.waitForTimeout(900); - const response = await page.request.get( - base + "/api/" + ("creation/projects/" + f.id), - { headers: { "X-OpenDirector-Request": "1" } }, - ); - assert.equal(response.status(), 200); - const saved = await response.json(); + let saved; + const deadline = Date.now() + 15000; + do { + const response = await page.request.get( + base + "/api/" + ("creation/projects/" + f.id), + { headers: { "X-OpenDirector-Request": "1" } }, + ); + assert.equal(response.status(), 200); + saved = await response.json(); + const targetItem = saved.canvasItems.find((item) => item.id === f.target); + const editor = saved.editorDocuments.find( + (item) => item.id === targetItem.binding.objectRef?.id, + ); + const persisted = ["subject", "timeline"].includes(targetKind) + ? editor?.inputConnections.length === count + : saved.references.length === count; + if (!accepted || persisted) break; + await page.waitForTimeout(80); + } while (Date.now() < deadline); { const doc = saved.editorDocuments.find( (d) => @@ -466,9 +479,12 @@ try { ); await page.reload(); await page.getByText("已保存到本机", { exact: true }).waitFor(); - await source.locator(".cw-node-placeholder").waitFor(); + await source.getByText("素材加载失败", { exact: true }).waitFor(); await source.hover(); - await page.waitForTimeout(100); + await page.waitForFunction((sourceId) => + document.querySelectorAll( + `.cw-node-reference-port[data-reference-source="${sourceId}"]`, + ).length === 0, f.source); assert.equal( await page .locator( diff --git a/tests/browser/node_versions.mjs b/tests/browser/node_versions.mjs index 2cbc762a5..77ae7d265 100644 --- a/tests/browser/node_versions.mjs +++ b/tests/browser/node_versions.mjs @@ -221,7 +221,7 @@ try { return batch(...args); }; client.view = async (...args) => { - window.historyReadCheck.views++; + if (args[0]) window.historyReadCheck.views++; return view(...args); }; }, fixture.id); diff --git a/tests/browser/reference_drag_performance.mjs b/tests/browser/reference_drag_performance.mjs index 67f8cc544..41f8e97e0 100644 --- a/tests/browser/reference_drag_performance.mjs +++ b/tests/browser/reference_drag_performance.mjs @@ -4,6 +4,8 @@ */ import assert from "node:assert/strict"; import fs from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; const { chromium } = await import( process.env.PLAYWRIGHT_MODULE ?? "playwright-core" ); @@ -12,6 +14,7 @@ const label = (process.env.PROFILE_LABEL ?? "current").replace( /[^a-z0-9_-]/gi, "", ); +const profileDirectory = await fs.mkdtemp(join(tmpdir(), "opendirector-drag-")); const browser = await chromium.launch({ headless: true, ...(process.env.CHROMIUM_PATH @@ -111,7 +114,7 @@ try { const cdp = await page.context().newCDPSession(page); await cdp.send("Profiler.enable"); await cdp.send("Profiler.setSamplingInterval", { interval: 1000 }); - const results = { fixture, scenarios: [], errors }; + const results = { fixture, profileDirectory, scenarios: [], errors }; for (const kind of ["pan", "node"]) { const close = page.getByRole("button", { name: "关闭生成面板", @@ -133,7 +136,16 @@ try { if (kind === "node") { const box = await card(fixture.target).boundingBox(); origin = { x: box.x + box.width / 2, y: box.y + box.height / 2 }; - } else origin = { x: 1580, y: 780 }; + } else { + origin = await page.locator(".react-flow__pane").evaluate((pane) => { + const box = pane.getBoundingClientRect(); + for (const [dx, dy] of [[180, 220], [180, 350], [250, 220]]) { + const point = { x: box.right - dx, y: box.bottom - dy }; + if (document.elementFromPoint(point.x, point.y) === pane) return point; + } + throw new Error("No empty canvas point for the pan sample"); + }); + } await page.evaluate(() => { window.__perfFrames = []; window.__perfLong = []; @@ -201,7 +213,7 @@ try { top, }); await fs.writeFile( - `/tmp/opendirector-drag-${label}-${kind}.cpuprofile`, + join(profileDirectory, `opendirector-drag-${label}-${kind}.cpuprofile`), JSON.stringify(profile), ); }