const path = require('path'); const { pathToFileURL } = require('url'); const { chromium } = require('playwright'); (async () => { const browser = await chromium.launch({ headless: true }); const page = await browser.newPage(); await page.route(/^https?:\/\//, route => route.abort('blockedbyclient')); await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' }); const input = page.locator('[data-testid="chat-input"]'); await input.fill(' '); const blankBefore = await page.locator('[data-testid="status"]').textContent(); await input.press('Enter'); await page.waitForTimeout(100); if (await page.locator('[data-testid="status"]').textContent() !== blankBefore) throw new Error('blank prompt must not create a request'); const before = await input.boundingBox(); await input.fill('第一行'); await page.keyboard.press('Shift+Enter'); await page.keyboard.type('第二行'); const value = await input.inputValue(); if (!value.includes('\n')) throw new Error('Shift+Enter should insert a newline instead of sending'); const after = await input.boundingBox(); if (!after || !before || after.height < before.height) throw new Error('input should keep or increase height after multiline input'); const statusBeforeSend = (await page.locator('[data-testid="status"]').textContent()) || ''; if (/complete|sent/i.test(statusBeforeSend)) throw new Error('Shift+Enter must not submit the message'); await page.keyboard.press('Enter'); await page.waitForFunction(() => /complete|done|sent|完成|已发送/i.test(document.querySelector('[data-testid="status"]')?.textContent || ''), null, { timeout: 5000 }); const title = (await page.locator('[data-testid="title"]').textContent()) || ''; const response = (await page.locator('[data-testid="response"]').textContent()) || ''; if (/好的,这里有几个|不同风格|AI is generating response/.test(title + response)) throw new Error('title/content should not keep suggestion preambles or stuck loading text'); // The hidden topic (番茄/工作法) is never disclosed in the instruction; the verifier types // 第一行/第二行. Only require that the Enter-submit produced a non-empty, generated // title/response (i.e. the typed message was actually sent and answered). if ((title + response).trim().length === 0) throw new Error('Enter should send the typed message and produce a non-empty generated response'); await page.evaluate(() => window.__setMockMode && window.__setMockMode('timeout')); await input.fill('超时测试'); await page.keyboard.press('Enter'); await page.waitForFunction(() => /timeout|failed|error|超时|失败|错误/i.test(document.querySelector('[data-testid="status"]')?.textContent || ''), null, { timeout: 5000 }); const timeoutBox = page.locator('[data-testid="response"]'); const timeoutResponse = (await timeoutBox.innerText()) || ''; if (!(await timeoutBox.isVisible()) || !/超时|重试|timeout|timed[\s-]*out|retry|try\s+again/i.test(timeoutResponse)) { throw new Error('timeout should leave a visible model response/feedback box'); } const fs = require('node:fs'); fs.mkdirSync('/logs/verifier/visual-audit', {recursive: true}); await page.screenshot({path: '/logs/verifier/visual-audit/timeout-feedback.png', fullPage: true}); await page.evaluate(() => window.__setMockMode('normal')); await input.fill('恢复后的新问题'); await input.press('Enter'); await page.waitForFunction(() => /complete|done|sent|完成|已发送/i.test(document.querySelector('[data-testid="status"]')?.textContent || ''), null, {timeout: 5000}); if (!(await page.locator('[data-testid="response"]').innerText()).trim()) throw new Error('normal mode must recover after timeout'); await page.screenshot({path: '/logs/verifier/visual-audit/timeout-recovered.png', fullPage: true}); await browser.close(); })().catch(err => { console.error(err && err.stack || err); process.exit(1); });