import fs from 'node:fs'; import { connectAudit, readAudit, sleep, auditCheck } from './lib/mobile-full-audit.mjs'; const a = await connectAudit(); async function tapText(id, text, scope = 'button') { const selector = await a.cdp.evaluate(({ text, scope }) => { document.querySelectorAll('[data-detail-resume-target]').forEach((e) => e.removeAttribute('data-detail-resume-target')); const matches = [...document.querySelectorAll(scope)].filter((e) => { const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && (e.textContent || '').replace(/\s+/g, ' ').trim().includes(text); }); if (matches.length !== 1) throw Error(`目标不唯一:${text}/${matches.length}`); const e = matches[0]; e.scrollIntoView({ block: 'center' }); const r = e.getBoundingClientRect(), hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2); if (hit !== e && !e.contains(hit)) throw Error(`目标被遮挡:${text}`); e.setAttribute('data-detail-resume-target', 'current'); return '[data-detail-resume-target="current"]'; }, { text, scope }); return a.tap(id, selector, text); } async function probe(id, path) { await a.cdp.waitFor((expected) => location.pathname === expected, path, 12000); await sleep(800); const shot = await a.snapshot(id); const data = await a.cdp.evaluate(() => ({ path: location.pathname, text: document.body.innerText.slice(0, 5000), cards: [...document.querySelectorAll('app-m-life-card')].map((e) => ({ name: e.querySelector('.m-name')?.textContent.trim(), buttons: [...e.querySelectorAll('button')].map((b) => b.textContent.trim()) })), controls: [...document.querySelectorAll('button,input')].filter((e) => { const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && r.x >= 0 && r.right <= innerWidth + 1 && r.y >= 0 && r.bottom <= innerHeight + 1; }).map((e) => ({ text: e.tagName === 'INPUT' ? '' : e.textContent.trim().replace(/\s+/g, ' ').slice(0, 100), placeholder: e.getAttribute('placeholder') })) })); fs.writeFileSync(`test-results/mobile-full-audit-20261130/${id}-probe.json`, JSON.stringify(data, null, 2) + '\n', { flag: 'w' }); auditCheck(`${path}页面状态已记录`, data.path === path, { screenshot: shot.id, cards: data.cards.length }); return data; } try { let path = await a.cdp.evaluate(() => location.pathname); if (path !== '/mobile/workbench') throw Error(`续接需要工作台页面,当前为 ${path}`); const openDialog = await a.cdp.evaluate(() => document.querySelector('.m-sheet-root[role="dialog"]')?.innerText ?? ''); if (openDialog) { await a.snapshot('detail-workbench-channel-1-dialog'); fs.writeFileSync('test-results/mobile-full-audit-20261130/detail-workbench-channel-1.txt', openDialog + '\n', { flag: 'w' }); auditCheck('第一个容器通道说明只读弹层', true, { chars: openDialog.length }); await a.tap('detail-workbench-channel-1-close', '.m-sheet-x', '关闭通道说明'); } const cards = await a.cdp.evaluate(() => [...document.querySelectorAll('app-m-life-card')].map((e) => e.querySelector('.m-name')?.textContent.trim()).filter(Boolean)); for (let index = 1; index < cards.length; index += 1) { const name = cards[index]; const selector = await a.cdp.evaluate((name) => { const card = [...document.querySelectorAll('app-m-life-card')].find((e) => e.querySelector('.m-name')?.textContent.trim() === name); const button = [...(card?.querySelectorAll('button') ?? [])].find((e) => e.textContent.trim() === '通道'); if (!button) throw Error(`找不到${name}的通道按钮`); button.setAttribute('data-detail-resume-target', 'current'); return '[data-detail-resume-target="current"]'; }, name); await a.tap(`detail-workbench-channel-${index + 1}`, selector, `${name}的通道说明`); await a.cdp.waitFor(() => !!document.querySelector('.m-sheet-root[role="dialog"]'), true, 5000); await sleep(200); await a.snapshot(`detail-workbench-channel-${index + 1}-dialog`); const text = await a.cdp.evaluate(() => document.querySelector('.m-sheet-root[role="dialog"]')?.innerText ?? ''); fs.writeFileSync(`test-results/mobile-full-audit-20261130/detail-workbench-channel-${index + 1}.txt`, text + '\n', { flag: 'w' }); auditCheck(`${name}通道说明只读弹层`, !!text, { chars: text.length }); await a.tap(`detail-workbench-channel-${index + 1}-close`, '.m-sheet-x', '关闭通道说明'); } await a.tap('detail-tab-contacts', '.m-tabbar button:nth-of-type(2)', '通讯录'); const contacts = await probe('detail-contacts-all', '/mobile/contacts'); await tapText('detail-contacts-ai-filter', '数字生命', '.m-segmented button'); await probe('detail-contacts-ai', '/mobile/contacts'); await tapText('detail-contacts-people-filter', '同事', '.m-segmented button'); await probe('detail-contacts-people', '/mobile/contacts'); await tapText('detail-contacts-all-filter', '全部', '.m-segmented button'); await a.fill('detail-contacts-search-no-match', 'app-m-search input', '__AUDIT_NO_MATCH_20261130__'); await probe('detail-contacts-no-match', '/mobile/contacts'); await a.tap('detail-contacts-search-clear', 'app-m-search .m-search-clear', '清除通讯录搜索'); await probe('detail-contacts-restored', '/mobile/contacts'); const colleague = await a.cdp.evaluate(() => { const section = [...document.querySelectorAll('.m-section')].find((e) => e.innerText.includes('同事 ·')); const button = section?.querySelector('button.m-row'); if (!button) return null; button.setAttribute('data-detail-resume-target', 'current'); return button.textContent.trim().replace(/\s+/g, ' '); }); if (colleague) { await a.tap('detail-contact-expand-colleague', '[data-detail-resume-target="current"]', '展开同事名下容器'); const expanded = await probe('detail-contacts-colleague-expanded', '/mobile/contacts'); auditCheck('同事行可展开容器列表', expanded.text.includes('数字生命') || expanded.text.includes('暂无可对话的数字生命'), { colleague }); } await a.checkpoint('已完成工作台所有真实容器的通道说明回读,并检查通讯录分类筛选/搜索/同事展开;未进入会话、未打开充值、未更改设置或服务端数据。证据与动作账本位于test-results/mobile-full-audit-20261130'); console.log(JSON.stringify({ stage: 'workbench_contacts_detail_complete', screenshots: readAudit().screenshots.length, actions: Object.keys(readAudit().actions).length, findings: readAudit().findings.length })); } catch (error) { console.error(error); process.exitCode = 1; } finally { a.close(); }