import fs from 'node:fs'; import { connectAudit, readAudit, sleep, auditCheck } from './lib/mobile-full-audit.mjs'; const a = await connectAudit(); async function buttonByText(id, text, scope = 'button', occurrence = 0) { const selector = await a.cdp.evaluate(({ text, scope, occurrence }) => { 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[occurrence]) throw Error(`目标不唯一或不可见:${text} / ${matches.length}`); matches[occurrence].scrollIntoView({ block: 'center' }); const r = matches[occurrence].getBoundingClientRect(); const hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2); if (hit !== matches[occurrence] && !matches[occurrence].contains(hit)) throw Error(`目标被其他界面遮挡:${text}`); matches[occurrence].setAttribute('data-secondary-audit-target', 'current'); return '[data-secondary-audit-target="current"]'; }, { text, scope, occurrence }); return a.tap(id, selector, text); } async function settled(id, expectedPath, wait = 1000) { await a.cdp.waitFor((path) => location.pathname === path, expectedPath, 15000); await sleep(wait); const shot = await a.snapshot(id); const probe = await a.cdp.evaluate(() => ({ path: location.pathname, heading: document.querySelector('.m-title-main')?.textContent.trim() || document.querySelector('h1')?.textContent.trim() || '', text: document.body.innerText.slice(0, 5000), controls: [...document.querySelectorAll('button,a,input,textarea,[role="button"]')].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) => ({ tag: e.tagName, text: e.tagName === 'INPUT' ? '' : e.textContent.trim().replace(/\s+/g, ' ').slice(0, 120), label: e.getAttribute('aria-label'), href: e.getAttribute('href'), class: String(e.className).slice(0, 100), disabled: !!e.disabled })) })); fs.writeFileSync(`test-results/mobile-full-audit-20261130/${id}-probe.json`, JSON.stringify(probe, null, 2) + '\n', { flag: 'w' }); auditCheck(`${expectedPath}页面到达`, probe.path === expectedPath, { screenshot: shot.id, heading: probe.heading }); return probe; } try { const current = await a.cdp.evaluate(() => location.pathname); if (current !== '/mobile/my-containers') throw Error(`当前页面不是待续的我的容器:${current}`); const containers = readAudit().screenshots.find((x) => x.id === 'secondary-my-containers-settled'); if (!containers) await settled('secondary-my-containers-settled', '/mobile/my-containers', 1200); await buttonByText('secondary-container-access-open', '查看接入信息', 'button.container-btn', 0); await settled('secondary-plan-access-settled', '/mobile/plan-access', 1200); await a.back('secondary-plan-access-back'); await a.cdp.waitFor((path) => location.pathname === path, '/mobile/my-containers', 10000); await buttonByText('secondary-plans-open-from-containers', '查看套餐与开通', '.quota-btn'); await settled('secondary-plans-settled', '/mobile/plans', 1200); await a.back('secondary-plans-back'); await a.cdp.waitFor((path) => location.pathname === path, '/mobile/my-containers', 10000); await a.back('secondary-containers-back'); await a.cdp.waitFor((path) => location.pathname === path, '/mobile/mine', 10000); await buttonByText('secondary-about-open', '关于与版本', '.m-row'); await sleep(1800); await a.snapshot('secondary-about-after'); const about = await a.cdp.evaluate(() => ({ path: location.pathname, text: document.body.innerText.slice(0, 3000), dialogs: [...document.querySelectorAll('[role="dialog"]')].map((e) => e.innerText.slice(0, 1000)) })); fs.writeFileSync('test-results/mobile-full-audit-20261130/secondary-about-probe.json', JSON.stringify(about, null, 2) + '\n', { flag: 'w' }); auditCheck('关于与版本点击后仍在设置页或显示更新反馈', about.path === '/mobile/mine', { screenshot: 'secondary-about-after', hasVersion: about.text.includes('v2.0.0') || about.text.includes('关于与版本') }); 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(); }