| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #!/usr/bin/env node
- /**
- * 新会话实时进度复现(2026-12-02 用户实测反馈「新会话卡住无进度」):
- * 直开 /mobile/chat/<agentId>/new(与 App 内「+」同一路由)→ 发多步任务
- * → 全程采样等待提示 / app-live-activity 实时步骤。
- * 用法:先 npm run build && node scripts/serve-dist.mjs --login(127.0.0.1:4300),
- * 再 node scripts/verify-mobile-newsession-20261202.mjs
- */
- import { chromium, devices } from 'playwright';
- import { mkdir } from 'node:fs/promises';
- import { dirname, resolve } from 'node:path';
- import { fileURLToPath } from 'node:url';
- const here = dirname(fileURLToPath(import.meta.url));
- const root = resolve(here, '..');
- const outDir = resolve(root, 'test-results/newsession-20261202');
- const BASE = process.env.BASE_URL || 'http://127.0.0.1:4300';
- const AGENT = process.env.AGENT_ID || 'agent-node-app-9ffwfdi7k2';
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
- await mkdir(outDir, { recursive: true });
- const browser = await chromium.launch({ channel: 'chrome' });
- const ctx = await browser.newContext({ ...devices['Pixel 7'], viewport: { width: 390, height: 844 } });
- const page = await ctx.newPage();
- const errors = [];
- page.on('pageerror', (e) => errors.push(String(e)));
- await page.goto(`${BASE}/mobile/chat/${AGENT}/new`, { waitUntil: 'domcontentloaded' });
- await sleep(12000);
- console.log('进入新会话后 URL =', page.url());
- await page.screenshot({ path: resolve(outDir, 'n-00-blank.png') });
- const box = page.locator('textarea').first();
- if (!(await box.count())) {
- console.log('FAIL: 没有输入框(preparingRoom 卡住?)');
- await page.screenshot({ path: resolve(outDir, 'n-99-noinput.png') });
- await browser.close();
- process.exit(1);
- }
- await box.click();
- await box.fill('请用 terminal 依次执行 echo ns-step-1、sleep 20、echo ns-step-2、sleep 20、echo ns-step-3,每步之间都报告进度。');
- await page.evaluate(() => document.querySelector('.m-send')?.click());
- console.log('已发送多步任务(新会话首条消息)');
- let sawWait = false, sawLive = false, maxSteps = 0, doneShot = false;
- for (let i = 0; i < 75; i++) {
- const probe = await page.evaluate(() => {
- const turns = [...document.querySelectorAll('app-assistant-turn')];
- const last = turns[turns.length - 1];
- const live = document.querySelector('app-live-activity');
- return {
- url: location.href,
- wait: [...document.querySelectorAll('.card-wait')].map((e) => (e.textContent || '').trim().slice(0, 40)),
- live: live ? (live.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 80) : null,
- steps: document.querySelectorAll('app-live-activity .step, app-live-activity li, app-live-activity [class*=step]').length,
- lastTurn: last ? (last.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 80) : null,
- };
- });
- console.log(`[+${i * 2}s]`, JSON.stringify(probe));
- if (probe.wait.length && !sawWait) { sawWait = true; await page.screenshot({ path: resolve(outDir, 'n-01-wait.png') }); }
- if (probe.live && !sawLive) { sawLive = true; await page.screenshot({ path: resolve(outDir, 'n-02-live.png') }); }
- if (probe.steps > maxSteps) maxSteps = probe.steps;
- if (probe.lastTurn && (probe.lastTurn.includes('已完成') || probe.lastTurn.includes('ns-step-3')) && !doneShot) {
- doneShot = true;
- await page.screenshot({ path: resolve(outDir, 'n-03-done.png') });
- break;
- }
- await sleep(2000);
- }
- console.log('=== 新会话复现结论 ===');
- console.log('① 等待提示:', sawWait ? 'OK' : 'FAIL(全程无等待提示)');
- console.log('② 实时步骤区:', sawLive ? `OK(最多 ${maxSteps} 步)` : 'FAIL(全程无实时步骤)');
- console.log('③ 回合完成:', doneShot ? 'OK' : '未等到结束');
- console.log('页面错误:', errors.length ? errors : '无');
- await browser.close();
|