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) { const selector = await a.cdp.evaluate(({ text, scope }) => { document.querySelectorAll('[data-secondary-audit-target]').forEach((e) => e.removeAttribute('data-secondary-audit-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-secondary-audit-target', 'current'); return '[data-secondary-audit-target="current"]'; }, { text, scope }); return a.tap(id, selector, text); } async function expect(path, shotId, probeId) { await a.cdp.waitFor((target) => location.pathname === target, path, 10000); await sleep(1000); const shot = await a.snapshot(shotId); const probe = await a.cdp.evaluate(() => ({ path: location.pathname, text: document.body.innerText.slice(0, 5000), dialogs: [...document.querySelectorAll('[role="dialog"]')].map((e) => e.innerText.slice(0, 1000)), controls: [...document.querySelectorAll('button,a,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), label: e.getAttribute('aria-label'), cls: String(e.className).slice(0, 80) })) })); fs.writeFileSync(`test-results/mobile-full-audit-20261130/${probeId}.json`, JSON.stringify(probe, null, 2) + '\n', { flag: 'w' }); auditCheck(`${path}只读页面到达`, probe.path === path, { screenshot: shot.id, dialogs: probe.dialogs.length }); return probe; } try { let path = await a.cdp.evaluate(() => location.pathname); if (path === '/plans') { await expect('/plans', 'secondary-plans-settled', 'secondary-plans-probe'); await a.back('secondary-plans-back'); path = await a.cdp.evaluate(() => location.pathname); } if (path === '/mobile/my-containers') { await a.back('secondary-containers-back'); path = await a.cdp.evaluate(() => location.pathname); } if (path !== '/mobile/mine') throw Error(`期望返回我的页面,当前为 ${path}`); await a.snapshot('secondary-mine-returned'); await tapText('secondary-about-open', '关于与版本', '.m-row'); await sleep(1600); const about = await expect('/mobile/mine', 'secondary-about-after', 'secondary-about-probe'); auditCheck('关于与版本入口显示当前版本或更新结果', about.text.includes('关于与版本') && /v\d|版本|检查/.test(about.text), { dialogCount: about.dialogs.length }); await a.checkpoint('已真机只读审计我的容器列表、首个容器接入信息、顶层套餐页及关于与版本入口;未申请、未续费、未充值、未退出或创建。路由探针修正记录保留。证据与动作账本位于test-results/mobile-full-audit-20261130'); console.log(JSON.stringify({ stage: 'secondary_account_pages_complete', screenshots: readAudit().screenshots.length, actions: Object.keys(readAudit().actions).length })); } catch (error) { console.error(error); process.exitCode = 1; } finally { a.close(); }