const { chromium } = require( process.env.PLAYWRIGHT_MODULE_PATH || 'playwright', ); const assert = require('node:assert/strict'); (async () => { const path = require('node:path'); const expected = path.resolve(__dirname, '../shots/reference/data'); const config = await ( await fetch('http://127.0.0.1:8247/api/settings') ).json(); assert.equal( path.resolve(config.data_dir), expected, 'Start the isolated reference server first.', ); const b = await chromium.launch({ executablePath: process.env.CHROMIUM_EXECUTABLE_PATH, args: ['--no-sandbox', '--disable-dev-shm-usage'], }); try { const c = await b.newContext({ permissions: ['clipboard-read', 'clipboard-write'], }); const p = await c.newPage(); p.setDefaultTimeout(15000); await p.goto('http://127.0.0.1:5173/agents'); await p.locator('.agent-row').filter({ hasText: '视觉设计' }).click(); const created = p.waitForResponse( (r) => r.url().endsWith('/api/agent/sessions') && r.request().method() === 'POST', ); await p.getByRole('button', { name: /新任务/ }).click(); await created; await p.waitForFunction(() => Array.from(document.querySelectorAll('.agent-toolbar button')).some( (b) => b.textContent.includes('新任务') && !b.disabled, ), ); await p .locator('.agent-composer textarea') .fill('需要一个温暖的绘本视觉方向'); await p.locator('.agent-send').click(); await p.getByRole('button', { name: /编辑内容并带回项目/ }).waitFor(); await p.getByRole('button', { name: /编辑内容并带回项目/ }).click(); await p.locator('.result-project-label select').selectOption('3'); const text = '剪贴板降级复制的实际内容。此处用于确认非安全上下文的操作不会误报成功。'; await p.locator('#agent-result-editor').fill(text); await p.evaluate(async () => { window.__testClipboard = navigator.clipboard; await window.__testClipboard.writeText('INITIAL'); Object.defineProperty(navigator, 'clipboard', { value: undefined, configurable: true, }); }); await p .getByRole('button', { name: '复制内容并打开项目', exact: true }) .click(); await p.waitForURL('**/workbench/3?stage=style'); const copied = await p.evaluate(() => window.__testClipboard.readText()); assert.equal(copied, text); console.log( 'PASS clipboard unavailable: actual content copied and correct stage opened', ); } finally { await b.close(); } })().catch((e) => { console.error(e); process.exitCode = 1; });