verify-mobile-newsession-20261202.mjs 3.8 KB

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