From 4e72aa0481a2f962d271938991b7cba2e3669bd1 Mon Sep 17 00:00:00 2001 From: mesalogo Date: Sun, 4 Oct 2026 23:38:32 +0800 Subject: [PATCH] test: wait for workspace import controls to become ready --- docs/development/release-preparation-0.15.11.md | 7 +++++++ tests/support/workspace-import-main.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/development/release-preparation-0.15.11.md b/docs/development/release-preparation-0.15.11.md index e8cc2b08..f7eabf9b 100644 --- a/docs/development/release-preparation-0.15.11.md +++ b/docs/development/release-preparation-0.15.11.md @@ -79,3 +79,10 @@ App 旧测试仍假定回顾表单默认展开,改为点击“新回顾”后 覆盖层堆栈通过仅编译测试 driver(不运行应用或生产构建)定位到窄转宽后的 侧栏按钮,先前 Escape 等待已通过;补齐宽高与 CSS 过渡结束后再原生点击。 保留 hit-test、侧栏 inert 和后续归档/弹层操作断言,等待下一轮 CI 验证。 + +`29af4090` 的 CI `37212673749`:上轮两项通过,6039 通过、56 跳过, +仅工作区导入 Electron 探针失败(Renderer 脚本执行异常)。 +探针取消选择后按旧名称查询按钮并直接读 disabled,导入中的临时名称会使 +查询为空;改为等待匹配按钮存在且可用,点击也使用同一就绪条件,并在脚本 +异常中保留执行表达式和原始 cause。字节核对、同名保护、取消和旧图片保留 +断言均保留;此为探针时序修正,不宣称修复产品导入故障。 diff --git a/tests/support/workspace-import-main.ts b/tests/support/workspace-import-main.ts index 86191c89..803471d2 100644 --- a/tests/support/workspace-import-main.ts +++ b/tests/support/workspace-import-main.ts @@ -37,13 +37,17 @@ app.whenReady().then(async () => { let picks = 0 // Only the native chooser is deterministic; App, preload, IPC and filesystem are production. dialog.showOpenDialog = (async () => { picks++; return { canceled: picks === 3, filePaths: picks === 3 ? [] : [join(source, 'import.bin')] } }) as typeof dialog.showOpenDialog - const run = (code: string): Promise => win.webContents.executeJavaScript(code, true) + const run = async (code: string): Promise => { + try { return await win.webContents.executeJavaScript(code, true) } + catch (error) { throw new Error(`Workspace import probe failed: ${code}`, { cause: error }) } + } const wait = async (code: string): Promise => { for (let i = 0; i < 300; i++) { if (await run(code)) return; await new Promise(resolve => setTimeout(resolve, 50)) } throw new Error(`Timed out: ${code}`) } const button = (label: string): string => `[...document.querySelectorAll('button')].find(e=>(e.getAttribute('aria-label')||e.textContent.trim())===${JSON.stringify(label)}&&e.getClientRects().length)` - const click = async (label: string): Promise => { await wait(`Boolean(${button(label)})`); await run(`${button(label)}.click()`) } + const ready = (label: string): string => `(() => { const target = ${button(label)}; return Boolean(target && !target.disabled) })()` + const click = async (label: string): Promise => { await wait(ready(label)); await run(`${button(label)}.click()`) } try { await win.loadURL(process.env.GB_IMPORT_URL!) await wait('Boolean(document.querySelector(".message-generated-image img"))') @@ -64,7 +68,7 @@ app.whenReady().then(async () => { await wait('document.body.innerText.includes("EEXIST")') assert.deepEqual(await readFile(join(project.rootPath, 'selected/import.bin')), bytes) await click('Import files') - await wait(`!${button('Import files')}.disabled`) + await wait(ready('Import files')) await win.reload() await wait('Boolean(document.querySelector(".message-generated-image img")) && document.querySelector(".message-generated-image img").naturalWidth===1') await writeFile(join(directory, 'result.json'), JSON.stringify({ passed: true, picks, bytes: bytes.length, imageAfterReload: true, artifactCount: database.listArtifacts().length, modelCalls: 0 }))