audit-mobile-navigation.mjs 5.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import fs from 'node:fs';
  2. import {connectAudit,readAudit,updateAudit,auditCheck,auditFinding,auditDirectory,sleep} from './lib/mobile-full-audit.mjs';
  3. const a=await connectAudit();
  4. const resume=process.argv.find(x=>x.startsWith('--resume='))?.slice(9);
  5. if(resume&&resume!=='tabs')throw Error('不支持的恢复位置');
  6. try{
  7. const id=await a.cdp.evaluate(()=>{try{return JSON.parse(localStorage.getItem('fmode_me')||'null')?.id}catch{return null}});
  8. if(id!==readAudit().identity?.me?.id)throw Error('当前账号变化,停止业务页面操作');
  9. const permission=()=>a.adb(['shell','dumpsys','package',a.session.packageId]).split(/\r?\n/).filter(x=>/android.permission.POST_NOTIFICATIONS:/.test(x)).map(x=>x.trim());
  10. const before=permission();
  11. if(!resume){
  12. if(await a.cdp.evaluate(()=>!!document.querySelector('.pg-root'))){
  13. const shot=await a.snapshot('notification-guide-initial');
  14. const dom=JSON.parse(fs.readFileSync(shot.dom,'utf8'));
  15. const close=dom.controls.find(x=>x.label==='关闭'&&x.classes.includes('pg-close'));
  16. if(close&&(close.rect.width<44||close.rect.height<44))auditFinding({id:'TOUCH-001',priority:'P2',area:'通知引导',title:'关闭按钮触控范围偏小',actual:`${close.rect.width}×${close.rect.height} CSS像素`,expected:'至少44×44 CSS像素',screenshots:[shot.id],recommendation:'后续统一扩大点击热区,保留当前视觉图标尺寸'});
  17. await a.tap('notification-guide-close-x','.pg-root .pg-close','关闭消息提醒说明,不改变系统权限');
  18. }
  19. auditCheck('关闭引导保持系统通知权限不变',JSON.stringify(before)===JSON.stringify(permission()),{before,after:permission()});
  20. await a.snapshot('messages-main');
  21. await a.tapText('messages-project-filter','项目','.m-seg-row');
  22. await a.tapText('messages-project-form-open','新建项目','.m-msgws-actions');
  23. auditCheck('空项目名创建禁用',await a.cdp.evaluate(()=>document.querySelector('.m-msgws-ok')?.disabled));
  24. await a.tapText('messages-project-form-cancel','取消','.m-msgws-form');
  25. await a.tapText('messages-all-filter','全部','.m-seg-row');
  26. await a.tap('messages-search-focus','app-m-search input','搜索会话');
  27. await a.fill('messages-search-no-match','app-m-search input','__AUDIT_NO_MATCH_20261130__');
  28. await a.tap('messages-search-clear','app-m-search .m-search-clear','清除搜索');
  29. if(/mInputShown=true|isInputViewShown=true/.test(a.adb(['shell','dumpsys','input_method'])))await a.back('messages-search-keyboard-back');
  30. await a.snapshot('messages-search-restored');
  31. await a.tap('navigation-drawer-open','[aria-label="打开导航"]','打开导航');
  32. await a.snapshot('navigation-drawer-full');
  33. const menus=await a.cdp.evaluate(()=>[...document.querySelectorAll('.m-drawer.show 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=>({text:e.textContent.trim().replace(/\s+/g,' '),label:e.getAttribute('aria-label'),class:e.className})));
  34. fs.writeFileSync(auditDirectory+'/drawer-controls.json',JSON.stringify(menus,null,2)+'\n',{flag:'wx'});
  35. await a.tap('navigation-drawer-mask-close','app-m-drawer .m-mask.show','关闭导航遮罩');
  36. }else{
  37. if(!await a.cdp.evaluate(()=>!!document.querySelector('.m-drawer.show')))throw Error('当前不在待恢复抽屉状态');
  38. updateAudit(s=>{const old=s.actions['navigation-drawer-mask-close'];if(old?.status!=='uncertain')throw Error('旧动作状态不匹配');old.statusHistory=[{status:'uncertain',reason:'遮罩中心在抽屉下方;测试在命中检查时停止,未派发触摸'}];old.status='not_executed_precondition';old.reconciledAt=new Date().toISOString()});
  39. await a.tap('navigation-drawer-mask-edge-close','app-m-drawer .m-mask.show','点击抽屉外露遮罩关闭');
  40. }
  41. for(const [route,index] of [['contacts',2],['workbench',3],['mine',4],['messages',1]]){
  42. await a.tap('tab-'+route,'.m-tabbar button:nth-of-type('+index+')','底栏进入'+route);
  43. await a.cdp.waitFor(r=>location.pathname==='/mobile/'+r,route,15000);
  44. await sleep(1200);await a.snapshot(route+'-settled');
  45. const probe=await a.cdp.evaluate(()=>({path:location.pathname,heading:document.querySelector('.m-title-main')?.textContent.trim(),text:document.body.innerText.slice(0,2600),buttons:[...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}).map(e=>({tag:e.tagName,text:e.tagName==='INPUT'?'':e.textContent.trim().replace(/\s+/g,' ').slice(0,80),label:e.getAttribute('aria-label'),class:String(e.className).slice(0,100),placeholder:e.getAttribute('placeholder'),href:e.getAttribute('href')}))}));
  46. probe.text=probe.text.replace(/r:[A-Za-z0-9_+%/=.-]{8,}/g,'[凭证已遮盖]');
  47. fs.writeFileSync(auditDirectory+'/'+route+'-probe.json',JSON.stringify(probe,null,2)+'\n',{flag:'wx'});
  48. auditCheck('底栏'+route+'路由到达',probe.path==='/mobile/'+route,{heading:probe.heading});
  49. }
  50. updateAudit(s=>{s.stage='navigation_basics_complete';s.notificationPermissionBaseline=before});
  51. await a.checkpoint('登录后通知引导关闭/权限保持、会话筛选与搜索、项目空表单取消、导航抽屉和四个底栏页面均已真机点击并截图;未创建项目或发送消息。接下来继续页面二级入口、容器与设置细项');
  52. console.log(JSON.stringify({stage:'navigation_basics_complete',screenshots:readAudit().screenshots.length,findings:readAudit().findings.length}));
  53. }catch(error){updateAudit(s=>{s.failures.push({stage:'navigation_audit',message:error.message,at:new Date().toISOString()});s.stage='navigation_audit_needs_readback'});console.error(error);process.exitCode=1}finally{a.close()}