sootsim 0.1.36 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -5
- package/dist-cli/bin.js +15 -20
- package/dist-cli/chunks/{agent-YZB6D3DR.js → agent-CGQWOOOL.js} +2 -2
- package/dist-cli/chunks/{agent-wrapper-VHCVS22I.js → agent-wrapper-M6P53GJ2.js} +10 -10
- package/dist-cli/chunks/{assert-AIVCKKLG.js → assert-O7N2SYJZ.js} +2 -2
- package/dist-cli/chunks/auto-bootstrap-DF4KYGPS.js +2 -0
- package/dist-cli/chunks/beta-AK25X3AU.js +2 -0
- package/dist-cli/chunks/chunk-23YMXBQ2.js +1 -0
- package/dist-cli/chunks/chunk-2ABGQIW7.js +4 -0
- package/dist-cli/chunks/chunk-5HNZO5AI.js +7 -0
- package/dist-cli/chunks/chunk-5XI3AB4I.js +3 -0
- package/dist-cli/chunks/{chunk-IJMYFYDZ.js → chunk-67K3WAEZ.js} +2 -2
- package/dist-cli/chunks/chunk-6UJXRT7F.js +5 -0
- package/dist-cli/chunks/chunk-ARH3T5NK.js +66 -0
- package/dist-cli/chunks/{chunk-VFDRZNPN.js → chunk-B4VH67D3.js} +1 -1
- package/dist-cli/chunks/chunk-BEY2QVU5.js +3 -0
- package/dist-cli/chunks/chunk-CB4PUMI2.js +1 -0
- package/dist-cli/chunks/chunk-CHMHTTI7.js +11 -0
- package/dist-cli/chunks/chunk-E473YTRQ.js +2 -0
- package/dist-cli/chunks/chunk-FCOCFEBU.js +27 -0
- package/dist-cli/chunks/chunk-FRE5TY3C.js +1 -0
- package/dist-cli/chunks/chunk-FX3PPKSJ.js +2 -0
- package/dist-cli/chunks/{chunk-27P763IZ.js → chunk-FXY5FWVY.js} +2 -2
- package/dist-cli/chunks/{chunk-A5BRCXYE.js → chunk-G23GIRBM.js} +1 -1
- package/dist-cli/chunks/chunk-G62Q2MQI.js +1 -0
- package/dist-cli/chunks/chunk-GWQUPWVO.js +2 -0
- package/dist-cli/chunks/{chunk-EWSQSALM.js → chunk-H6CG42HE.js} +4 -4
- package/dist-cli/chunks/chunk-HNAGYNWN.js +16 -0
- package/dist-cli/chunks/{chunk-KAXZHEKM.js → chunk-IE2WYVJF.js} +1 -1
- package/dist-cli/chunks/chunk-IKVIHHWE.js +2 -0
- package/dist-cli/chunks/chunk-JJVZMGRM.js +2 -0
- package/dist-cli/chunks/{chunk-HWCKZXNJ.js → chunk-LNRBXCUI.js} +2 -2
- package/dist-cli/chunks/{chunk-CYCXOAVZ.js → chunk-MTPWS4JK.js} +4 -4
- package/dist-cli/chunks/{chunk-G7XQD4KC.js → chunk-NKYTISAN.js} +2 -2
- package/dist-cli/chunks/chunk-NSZBULGG.js +348 -0
- package/dist-cli/chunks/chunk-P32FCOS3.js +4 -0
- package/dist-cli/chunks/chunk-P722XCFT.js +3 -0
- package/dist-cli/chunks/chunk-PFRPXFSL.js +117 -0
- package/dist-cli/chunks/chunk-QD22CQLH.js +5 -0
- package/dist-cli/chunks/chunk-QI4VLQ3A.js +5 -0
- package/dist-cli/chunks/{chunk-OXN2PEB7.js → chunk-SKNHJDYO.js} +3 -3
- package/dist-cli/chunks/{chunk-YIO6S3R5.js → chunk-T442FYM5.js} +1 -1
- package/dist-cli/chunks/chunk-TR554AIH.js +17 -0
- package/dist-cli/chunks/chunk-UD5ILFN5.js +3 -0
- package/dist-cli/chunks/{chunk-LHDWH7VS.js → chunk-VIEK76DX.js} +1 -1
- package/dist-cli/chunks/chunk-VVUEWU2P.js +64 -0
- package/dist-cli/chunks/{chunk-RMW5BO3S.js → chunk-Z2PBRNJP.js} +2 -2
- package/dist-cli/chunks/chunk-ZEVZN3S4.js +2 -0
- package/dist-cli/chunks/{compat-Y2O2U7FL.js → compat-DNQWSPFQ.js} +2 -2
- package/dist-cli/chunks/{config-SRBOFUCI.js → config-ABR5BGUO.js} +2 -2
- package/dist-cli/chunks/control-DEHRU4XZ.js +2 -0
- package/dist-cli/chunks/cpu-profile-Y5YDH6X2.js +22 -0
- package/dist-cli/chunks/daemon-2Z4DAJT6.js +83 -0
- package/dist-cli/chunks/{debug-BIDMW2PE.js → debug-R36UPOJP.js} +4 -4
- package/dist-cli/chunks/demo-app-registry-DMMWYL7G.js +2 -0
- package/dist-cli/chunks/detox-FQJWEWLT.js +49 -0
- package/dist-cli/chunks/device-SXKLDZEC.js +16 -0
- package/dist-cli/chunks/diagnose-M7RKNI2H.js +41 -0
- package/dist-cli/chunks/drivers-NSCX5CRA.js +2 -0
- package/dist-cli/chunks/electron-YUAKGT4H.js +18 -0
- package/dist-cli/chunks/flow-UQSRNEZD.js +2 -0
- package/dist-cli/chunks/hints-SDD7L3VS.js +2 -0
- package/dist-cli/chunks/home-paths-QMCX2227.js +2 -0
- package/dist-cli/chunks/inspect-6FPPW7GS.js +1101 -0
- package/dist-cli/chunks/install-TTH3PM3B.js +2 -0
- package/dist-cli/chunks/{install-desktop-2MYEI4FM.js → install-desktop-EKMYRDQH.js} +3 -3
- package/dist-cli/chunks/{keys-7PNASIQR.js → keys-ODG3TDUP.js} +2 -2
- package/dist-cli/chunks/{launch-JNS47LAQ.js → launch-7HUL745I.js} +3 -3
- package/dist-cli/chunks/{login-YWZWUHBS.js → login-BJKQMJYT.js} +4 -4
- package/dist-cli/chunks/{logout-O6SXMSBP.js → logout-7NG3KGJD.js} +2 -2
- package/dist-cli/chunks/maestro-VFEUWV3Q.js +80 -0
- package/dist-cli/chunks/{preview-WGKJO5FS.js → preview-WZ6XNOBC.js} +2 -2
- package/dist-cli/chunks/profile-DXFEZOHB.js +22 -0
- package/dist-cli/chunks/react-QP7PL5CZ.js +30 -0
- package/dist-cli/chunks/{record-QPWLYH5R.js → record-AFE25EMH.js} +5 -5
- package/dist-cli/chunks/{runtime-KEMO2MSB.js → runtime-GFWS3QLZ.js} +3 -3
- package/dist-cli/chunks/screenshot-U6VFOVFW.js +28 -0
- package/dist-cli/chunks/screenshot-mode-HNGV3AFC.js +17 -0
- package/dist-cli/chunks/screenshots-GYMRDUJR.js +70 -0
- package/dist-cli/chunks/server-3Q22YYM6.js +35 -0
- package/dist-cli/chunks/setup-repo-NNDWIGZR.js +2 -0
- package/dist-cli/chunks/{skills-MO7BFNVM.js → skills-FT76ZVAV.js} +2 -2
- package/dist-cli/chunks/start-N573LFCF.js +23 -0
- package/dist-cli/chunks/store-6NTDGLPH.js +2 -0
- package/dist-cli/chunks/telemetry-SNZBIRGL.js +2 -0
- package/dist-cli/chunks/{test-XUI3KNNQ.js → test-AJPY2Q6W.js} +3 -3
- package/dist-cli/chunks/three-mode-JZZVOMTG.js +39 -0
- package/dist-cli/chunks/timeline-GTSCF5P6.js +22 -0
- package/dist-cli/chunks/upload-UHTVCGGR.js +2 -0
- package/dist-cli/chunks/what-happened-N3AQ6I7O.js +15 -0
- package/dist-cli/chunks/whoami-FOIMN6UC.js +2 -0
- package/dist-lib/agent-daemon-client.cjs +4 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +41 -39
- package/dist-lib/attached-projects.cjs +30 -28
- package/dist-lib/auth/shared-session.cjs +35 -27
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/config.cjs +6 -2
- package/dist-lib/dev-bundle-resolution.cjs +5 -50
- package/dist-lib/home-paths.cjs +94 -38
- package/dist-lib/host/bridge-host.cjs +2144 -1330
- package/dist-lib/host/fetch-proxy-handler.cjs +248 -0
- package/dist-lib/index.cjs +21 -21
- package/dist-lib/metro.cjs +21 -21
- package/dist-lib/profiles.cjs +246 -0
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/vite-base.cjs +3410 -1632
- package/dist-lib/vite.cjs +1 -1
- package/package.json +7 -1
- package/dist-cli/chunks/auto-bootstrap-MLNTX23H.js +0 -2
- package/dist-cli/chunks/chunk-3UIWOHC2.js +0 -62
- package/dist-cli/chunks/chunk-5KGFHWVR.js +0 -1
- package/dist-cli/chunks/chunk-5QIUJNT3.js +0 -5
- package/dist-cli/chunks/chunk-6GGMKFWJ.js +0 -4
- package/dist-cli/chunks/chunk-6Z275LCY.js +0 -2
- package/dist-cli/chunks/chunk-75LBYBKW.js +0 -11
- package/dist-cli/chunks/chunk-DFN3GGH7.js +0 -5
- package/dist-cli/chunks/chunk-EBEHZJRG.js +0 -117
- package/dist-cli/chunks/chunk-EJLNUMMP.js +0 -3
- package/dist-cli/chunks/chunk-FE7UI3MT.js +0 -4
- package/dist-cli/chunks/chunk-G663654J.js +0 -1
- package/dist-cli/chunks/chunk-GW7XY5KC.js +0 -2
- package/dist-cli/chunks/chunk-H2QO4TDV.js +0 -22
- package/dist-cli/chunks/chunk-HWFHBMAQ.js +0 -27
- package/dist-cli/chunks/chunk-J7CTD37P.js +0 -1
- package/dist-cli/chunks/chunk-N32NCVL2.js +0 -3
- package/dist-cli/chunks/chunk-NIZBR7EK.js +0 -2
- package/dist-cli/chunks/chunk-NYY36OKU.js +0 -308
- package/dist-cli/chunks/chunk-PJL25JQV.js +0 -5
- package/dist-cli/chunks/chunk-SHO54NET.js +0 -2
- package/dist-cli/chunks/chunk-SMVJOWSV.js +0 -16
- package/dist-cli/chunks/chunk-TC6V7YFC.js +0 -3
- package/dist-cli/chunks/chunk-YLIIVTTQ.js +0 -3
- package/dist-cli/chunks/chunk-YR7BGGYE.js +0 -2
- package/dist-cli/chunks/chunk-ZEW3RF5Q.js +0 -1
- package/dist-cli/chunks/control-PL2V2O6S.js +0 -2
- package/dist-cli/chunks/daemon-IZC32PZW.js +0 -50
- package/dist-cli/chunks/demo-app-registry-5JFOUU3D.js +0 -2
- package/dist-cli/chunks/detox-B3FDOIS3.js +0 -49
- package/dist-cli/chunks/device-ZZSI363W.js +0 -16
- package/dist-cli/chunks/drivers-S4NGK4DB.js +0 -2
- package/dist-cli/chunks/electron-5YFHXEOI.js +0 -15
- package/dist-cli/chunks/flow-JJBO6TFY.js +0 -2
- package/dist-cli/chunks/hints-G5HBBV2O.js +0 -2
- package/dist-cli/chunks/home-paths-VWC3FWA3.js +0 -2
- package/dist-cli/chunks/inspect-POOPWUQI.js +0 -1034
- package/dist-cli/chunks/install-MP6FHXNZ.js +0 -2
- package/dist-cli/chunks/install-dev-desktop-SKH3KEHY.js +0 -100
- package/dist-cli/chunks/maestro-CW6XVUKV.js +0 -75
- package/dist-cli/chunks/profile-SUOBRPIC.js +0 -22
- package/dist-cli/chunks/screenshot-JTY46V7G.js +0 -26
- package/dist-cli/chunks/screenshot-mode-7OYBBX6D.js +0 -17
- package/dist-cli/chunks/screenshots-QISKC4GD.js +0 -70
- package/dist-cli/chunks/server-YSFJAKAV.js +0 -34
- package/dist-cli/chunks/setup-repo-LFB3HBEO.js +0 -2
- package/dist-cli/chunks/store-6MFL53I4.js +0 -2
- package/dist-cli/chunks/telemetry-CN42GMVC.js +0 -2
- package/dist-cli/chunks/upload-6FUT7AX5.js +0 -2
- package/dist-cli/chunks/whoami-TQFHY42N.js +0 -2
|
@@ -0,0 +1,1101 @@
|
|
|
1
|
+
/*! sootsim v0.1.38 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import{a as G}from"./chunk-P722XCFT.js";import{a as Re,b as Ee}from"./chunk-T442FYM5.js";import{a as X,b as D,c as B,d as K,e as ce,f as oe,g as ne,h as Ce,i as De,j as he}from"./chunk-MTPWS4JK.js";import{a as Ae,e as le}from"./chunk-LNRBXCUI.js";import{b as Be,h as Le}from"./chunk-CHMHTTI7.js";import"./chunk-E473YTRQ.js";import{a as Oe}from"./chunk-SKNHJDYO.js";import"./chunk-JJVZMGRM.js";import"./chunk-QI4VLQ3A.js";import"./chunk-5XI3AB4I.js";import"./chunk-FRE5TY3C.js";import{a as ge,c as ye,d as Me}from"./chunk-PFRPXFSL.js";import{a as Te}from"./chunk-FX3PPKSJ.js";import"./chunk-G23GIRBM.js";import{c as Ne,e as _e,f as Fe,g as Pe,h as be}from"./chunk-TR554AIH.js";import{b as Ie}from"./chunk-2ABGQIW7.js";import"./chunk-23YMXBQ2.js";import"./chunk-6UJXRT7F.js";import"./chunk-VIEK76DX.js";import{existsSync as vt,mkdirSync as kt,readFileSync as Tt,rmSync as je,writeFileSync as Mt}from"fs";import{tmpdir as It}from"os";import{dirname as Nt,join as _t,resolve as Ft}from"path";var re=1,Pt="SOOTSIM_INSPECT_NOTICE_PATH",At=300*1e3,Ot=15e3;function Je(){return Ft(process.env[Pt]||_t(It(),"sootsim-inspect-notice-state.json"))}function Rt(t,l){return Object.fromEntries(Object.entries(t).filter(([,a])=>typeof a?.signature=="string"&&Number.isFinite(a?.updatedAt)&&l-a.updatedAt<=At))}function Et(t){let l=Je();if(!vt(l))return{version:re,entries:{}};try{let a=JSON.parse(Tt(l,"utf8"));return a.version!==re||!a.entries||typeof a.entries!="object"?(je(l,{force:!0}),{version:re,entries:{}}):{version:re,entries:Rt(a.entries,t)}}catch{return je(l,{force:!0}),{version:re,entries:{}}}}function Ct(t){let l=Je();kt(Nt(l),{recursive:!0}),Mt(l,JSON.stringify(t,null,2)+`
|
|
3
|
+
`)}function Dt(t,l){let a=l.trim()||"default";return`${t}:${a}`}function we(t,l,a,d={}){let u=d.nowMs??Date.now(),i=d.cooldownMs??Ot,b=Et(u),k=Dt(t,l),$=b.entries[k];return $&&$.signature===a&&u-$.updatedAt<i?!1:(b.entries[k]={signature:a,updatedAt:u},Ct(b),!0)}async function He(t,l={args:[]}){let a=await t.send({type:"evaluate",code:"(async () => await window.__sootsimTest.getNodeCount())()"}),d=typeof a=="number"?a:0;if(D(l.args)){B({nodes:d});return}console.log(` nodes: ${d}`)}function xe(t,l){let a=t.indexOf(l);return a>=0&&a+1<t.length?t[a+1]:null}async function qe(t){let{bridge:l,args:a,positional:d}=t,u=a.includes("--verbose")||a.includes("-v"),i=D(a),b=u&&!i,k=a.includes("--watch")||a.includes("-w"),$=1e3,N=a.includes("--compact"),h=a.includes("--no-xy"),S=xe(a,"--testid-like"),F=xe(a,"--only"),I=xe(a,"--subtree"),C=d[1],c=C?/[*?]/.test(C):!1,J=!c&&!F?C:void 0,L=F??(c?C:void 0),O=async()=>{await ce(l,{verbose:b});let Z=`(async () => {
|
|
4
|
+
const t = window.__sootsimTest
|
|
5
|
+
const mainShell = window.SootSim?.bridges?.mainShell
|
|
6
|
+
const kb = window.__sootsimKeyboard
|
|
7
|
+
if (!t) return { error: 'no test bridge' }
|
|
8
|
+
|
|
9
|
+
let shell = null
|
|
10
|
+
try {
|
|
11
|
+
shell = typeof mainShell?.getState === 'function' ? await mainShell.getState() : null
|
|
12
|
+
} catch {}
|
|
13
|
+
|
|
14
|
+
const tree = await t.dumpTree(12, ${JSON.stringify({describe:!0,verbose:u,filter:J||"",testIdLike:S||void 0,onlyGlob:L||void 0,subtreeRoot:I||void 0,compact:N,hideXy:h})})
|
|
15
|
+
const nodeCount = (await t.getNodeCount?.()) || 0
|
|
16
|
+
const keyboard = kb && typeof kb.getLayout === 'function' ? kb.getLayout() : null
|
|
17
|
+
return { tree, shell, nodeCount, keyboard }
|
|
18
|
+
})()`,Y=await l.send({type:"evaluate",code:Z}),w=Y?.tree,_=Y?.shell,W=Y?.keyboard;if(i){B({shell:_,tree:w??"",keyboard:W});return}if(_&&typeof _=="object"){let E=[_.state?`state=${_.state}`:null,_.activeApp?`app=${_.activeApp}`:null,_.showSwitcher?"switcher":null,_.switcherPhase&&_.switcherPhase!=="idle"?`phase=${_.switcherPhase}`:null].filter(Boolean);E.length>0&&console.log(` shell: ${E.join(" ")}`)}if(typeof w=="string"&&w.startsWith("__SUBTREE_NOT_FOUND__:")){let E=w.slice(22);console.log(` subtree root not found: ${E}`),G("subtree-root-not-found",E);return}if(!w){let E=Y?.nodeCount??0;console.log(" no matching nodes found"),!(J||S||L||I)&&E<10&&G("app-still-loading",E);return}if(console.log(w),!(J||S||L||I)&&!k&&w.split(`
|
|
19
|
+
`).length>=80&&G("describe-use-filters"),W&&W.visible){let E=W.spec,V=[E?.keyboardType?`type=${E.keyboardType}`:null,E?.returnKeyType&&E.returnKeyType!=="default"?`return=${E.returnKeyType}`:null,W.mode!=="letters"?`mode=${W.mode}`:null,W.shifted?"shift":null,W.capsLock?"caps":null,E?.autoCapitalize&&E.autoCapitalize!=="sentences"?`autoCap=${E.autoCapitalize}`:null,W.accessoryBarId?`accessory=${W.accessoryBarId}`:null].filter(Boolean);console.log(`
|
|
20
|
+
keyboard: ${V.join(" ")||"visible"}`)}};if(k)for(console.log(` watching... (Ctrl+C to stop)
|
|
21
|
+
`);;)console.clear(),await O(),await X($);else await O()}var Bt=["SOOTSIM_AGENT","CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE_SESSION_ID","CODEX_THREAD_ID","CURSOR_TRACE_ID","AIDER_MODEL"];function We(){if(process.env.SOOTSIM_AGENT==="0")return!1;for(let t of Bt){let l=process.env[t];if(l&&l.trim()&&l!=="0")return!0}return!1}async function Ge(t){let{bridge:l,args:a,effectiveArgs:d,positional:u,inspectUsage:i}=t,b=w=>{let _=d.indexOf(w);return _>=0&&_+1<d.length?d[_+1]:null},k=w=>d.includes(w),$=b("--testid")||b("--test-id"),N=b("--role"),h=b("--type"),S=b("--text"),F=k("--pressable"),I=k("--visible"),C=k("--interactive-targets")||k("--actions"),c=!$&&!N&&!h&&!S&&!F&&!I&&!C?u[1]:null,J=S??c,L,O;$?(O="testid",L=`(async () => {
|
|
22
|
+
const t = window.__sootsimTest
|
|
23
|
+
return (await t.findByTestId(${JSON.stringify($)})) || (await t.findById(${JSON.stringify($)}))
|
|
24
|
+
})()`):N?(O="role",L=`(async () => await window.__sootsimTest.queryAll({ hasRole: ${JSON.stringify(N)}, pruneHidden: true }))()`):h?(O="type",L=`(async () => await window.__sootsimTest.queryAll({ type: ${JSON.stringify(h)}, pruneHidden: true }))()`):F?(O="pressable",L=`(async () => {
|
|
25
|
+
const t = window.__sootsimTest
|
|
26
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
27
|
+
return all.filter(n => n.pressable)
|
|
28
|
+
})()`):C?(O="interactive-targets",L=`(async () => {
|
|
29
|
+
const t = window.__sootsimTest
|
|
30
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
31
|
+
return all.filter(n => n.pressable && n.layout && n.layout.width > 0 && n.layout.height > 0)
|
|
32
|
+
})()`):I?(O="visible",L=`(async () => {
|
|
33
|
+
const all = await window.__sootsimTest.queryAll({ pruneHidden: true })
|
|
34
|
+
return all.filter(n => n.layout && n.layout.width > 0 && n.layout.height > 0)
|
|
35
|
+
})()`):J?(O="text",L=`(async () => await window.__sootsimTest.findByText(${JSON.stringify(J)}))()`):(console.error(i("find","<text> | --text <t> | --testid <id> | --role <r> | --type <t> | --pressable | --visible | --interactive-targets")),process.exit(1));let H=await l.send({type:"evaluate",code:L}),Z=D(a),Y=a.includes("--verbose")||a.includes("--dump");if(Z)O==="interactive-targets"&&Array.isArray(H)?B(Ke(H).map(w=>({...w,tap:Ue(w)}))):B(H??null);else if(Array.isArray(H))if(H.length===0){console.log(` no ${O} nodes found`);let w=await l.send({type:"evaluate",code:"(async () => (await window.__sootsimTest?.getNodeCount?.()) || 0)()"});typeof w=="number"&&w<10&&G("app-still-loading",w)}else if(O==="interactive-targets"){let w=Ke(H);console.log(` found ${w.length} interactive target${w.length===1?"":"s"} (sorted by score):`);for(let _ of w.slice(0,20)){let W=_.absolutePosition?`@(${Math.round(_.absolutePosition.x)},${Math.round(_.absolutePosition.y)})`:"",ee=_.layout?`${Math.round(_.layout.width)}x${Math.round(_.layout.height)}`:"?x?",E=_.text?` "${_.text.slice(0,30)}"`:"",V=_.testID?` #${_.testID}`:"",e=_.accessibilityLabel?` \u24D8"${String(_.accessibilityLabel).slice(0,24)}"`:"",o=_.accessibilityRole?`[${_.accessibilityRole}]`:_.type,s=Ue(_);console.log(` ${o}${E}${e}${V} ${ee} ${W}`),console.log(` \u2192 ${s}`),Y&&console.log($e(JSON.stringify(_,null,2)," "))}w.length>20&&console.log(` ... and ${w.length-20} more`)}else{console.log(` found ${H.length} node${H.length===1?"":"s"} (${O}):`);for(let w of H.slice(0,20)){let _=w.absolutePosition?`@(${Math.round(w.absolutePosition.x)},${Math.round(w.absolutePosition.y)})`:"",W=w.layout?`${Math.round(w.layout.width)}x${Math.round(w.layout.height)}`:"?x?",ee=w.text?` "${w.text.slice(0,30)}"`:"",E=w.testID?` #${w.testID}`:"",V=w.pressable?" (tap)":"",e=w.accessibilityRole?`[${w.accessibilityRole}]`:w.type;console.log(` ${e}${ee}${E} ${W} ${_}${V}`),Y&&console.log($e(JSON.stringify(w,null,2)," "))}H.length>20&&console.log(` ... and ${H.length-20} more`)}else if(H==null)console.log(` not found: ${J||$||N||h||""||O}`),$&&G("wait-selector-for-missing-testid",$);else{let w=H;if(w.type&&w.absolutePosition){let _=`@(${Math.round(w.absolutePosition.x)},${Math.round(w.absolutePosition.y)})`,W=w.layout?`${Math.round(w.layout.width)}x${Math.round(w.layout.height)}`:"?x?",ee=w.text?` "${w.text.slice(0,40)}"`:"",E=w.testID?` #${w.testID}`:"",V=w.pressable?" (tap)":"",e=w.accessibilityRole?`[${w.accessibilityRole}]`:w.type;console.log(` ${e}${ee}${E} ${W} ${_}${V}`),Y&&console.log($e(JSON.stringify(w,null,2)," "))}else console.log(JSON.stringify(H,null,2))}}function $e(t,l){return t.split(`
|
|
36
|
+
`).map(a=>l+a).join(`
|
|
37
|
+
`)}function Ke(t){return[...t].sort((l,a)=>ze(a)-ze(l))}function ze(t){let l=0;t.testID&&(l+=100),typeof t.text=="string"&&t.text.trim().length>0&&(l+=60),typeof t.accessibilityLabel=="string"&&t.accessibilityLabel.trim().length>0&&(l+=30),t.accessibilityRole&&(l+=15);let a=t.layout?.width??0,d=t.layout?.height??0,u=a*d;return u>=400&&u<=6e4?l+=25:u>6e4&&(l-=20),(t.absolutePosition?.y??0)<0&&(l-=30),l}function Ue(t){if(t.testID)return`sootsim do tap-id ${Ye(t.testID)}`;let l=typeof t.text=="string"?t.text.trim():"";if(l.length>0&&l.length<=80)return`sootsim do tap-text ${Ye(l)}`;let a=Math.round(((t.absolutePosition?.x??0)+(t.layout?.width??0)/2)*10)/10,d=Math.round(((t.absolutePosition?.y??0)+(t.layout?.height??0)/2)*10)/10;return`sootsim do tap ${a} ${d}`}function Ye(t){return/^[A-Za-z0-9_./@:-]+$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}async function Xe(t,l={}){let a=await t.send({type:"evaluate",code:`(() => {
|
|
38
|
+
const kb = window.__sootsimKeyboard
|
|
39
|
+
if (!kb || typeof kb.getLayout !== 'function') {
|
|
40
|
+
return { error: 'keyboard bridge getLayout() not available' }
|
|
41
|
+
}
|
|
42
|
+
return kb.getLayout()
|
|
43
|
+
})()`});if("error"in a&&(console.error(a.error),process.exit(1)),l.json){console.log(JSON.stringify(a,null,2));return}let{visible:d,spec:u,mode:i,shifted:b,capsLock:k,accessoryBarId:$}=a,N=[];N.push(`keyboard: ${d?"visible":"hidden"}`),u?(N.push(` type: ${u.keyboardType}`),N.push(` returnKey: ${u.returnKeyType}`),N.push(` autoCap: ${u.autoCapitalize}`),N.push(` autoCorrect: ${u.autoCorrect?"on":"off"}`),N.push(` appearance: ${u.keyboardAppearance}`),u.secureTextEntry&&N.push(" secureTextEntry: true"),u.enablesReturnKeyAutomatically&&N.push(` return: ${u.currentTextIsEmpty?"disabled (empty)":"enabled"}`)):N.push(" spec: <none> (shown via dev-tools with no TextInput)"),N.push(` mode: ${i}${b?" (shifted)":""}${k?" (caps)":""}`),$&&N.push(` accessoryBar: ${$}`),console.log(N.join(`
|
|
44
|
+
`))}async function Ve(t){let l=await t.bridge.listSims();if(D(t.args)){B(l.map(a=>({...a,active:a.id===t.simId})));return}Le(l,t.simId)}function te(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}function de(t,l){return l<=0?"?":`${(t/l*100).toFixed(0)}%`}async function Qe(t,l={args:[]}){let d=await t.send({type:"evaluate",code:`(async () => {
|
|
45
|
+
const host = window.__sootsimRenderHost
|
|
46
|
+
const stats = host?.queryStats ? await host.queryStats() : null
|
|
47
|
+
const hostMem = performance.memory
|
|
48
|
+
? {
|
|
49
|
+
usedJSHeapSize: performance.memory.usedJSHeapSize,
|
|
50
|
+
totalJSHeapSize: performance.memory.totalJSHeapSize,
|
|
51
|
+
jsHeapSizeLimit: performance.memory.jsHeapSizeLimit,
|
|
52
|
+
}
|
|
53
|
+
: null
|
|
54
|
+
return {
|
|
55
|
+
imageLoader: stats?.memory?.imageLoader ?? null,
|
|
56
|
+
workerHeap: stats?.memory?.workerHeap ?? null,
|
|
57
|
+
hostHeap: hostMem,
|
|
58
|
+
}
|
|
59
|
+
})()`})??{};if(D(l.args)){B(d);return}if(console.log(" memory:"),d.imageLoader){let u=d.imageLoader;console.log(" image-loader cache"),console.log(` entries: ${u.cacheEntries} / ${u.cacheMaxEntries} (${de(u.cacheEntries,u.cacheMaxEntries)})`),console.log(` pixel bytes: ${te(u.cachePixelBytes)} / ${te(u.cachePixelBudget)} (${de(u.cachePixelBytes,u.cachePixelBudget)})`),console.log(` pending: ${u.pendingFetches} fetches, ${u.pendingBytes} bytes`),console.log(` failed uris: ${u.failedUris}`),console.log(` snapshots: ${u.snapshots}`),console.log(` camera frames: ${u.cameraFrames}`)}else console.log(" image-loader cache: not available (engine pre-rebuild?)");if(d.workerHeap){let u=d.workerHeap;console.log(" worker heap (chrome only)"),console.log(` used: ${te(u.usedJSHeapSize)} / ${te(u.jsHeapSizeLimit)} (${de(u.usedJSHeapSize,u.jsHeapSizeLimit)})`),console.log(` total: ${te(u.totalJSHeapSize)}`)}if(d.hostHeap){let u=d.hostHeap;console.log(" host heap (chrome only)"),console.log(` used: ${te(u.usedJSHeapSize)} / ${te(u.jsHeapSizeLimit)} (${de(u.usedJSHeapSize,u.jsHeapSizeLimit)})`),console.log(` total: ${te(u.totalJSHeapSize)}`)}}function ie(t){let l=t.indexOf("--testid");if(l>=0&&t[l+1])return{mode:"testid",value:t[l+1]};let a=t.indexOf("--test-id");if(a>=0&&t[a+1])return{mode:"testid",value:t[a+1]};let d=t.indexOf("--text");return d>=0&&t[d+1]?{mode:"text",value:t[d+1]}:null}async function ue(t,l){let a=JSON.stringify(l.value),d=l.mode==="testid"?`(await t.findByTestId(${a})) || (await t.findById(${a}))`:`await t.findByText(${a})`;return await t.send({type:"evaluate",code:`(async () => {
|
|
60
|
+
const t = window.__sootsimTest
|
|
61
|
+
if (!t) return null
|
|
62
|
+
const n = ${d}
|
|
63
|
+
if (!n || !n.absolutePosition || !n.layout) return null
|
|
64
|
+
const resolved =
|
|
65
|
+
typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
|
|
66
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
67
|
+
: null
|
|
68
|
+
const cx =
|
|
69
|
+
typeof resolved?.cx === 'number'
|
|
70
|
+
? resolved.cx
|
|
71
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
72
|
+
const cy =
|
|
73
|
+
typeof resolved?.cy === 'number'
|
|
74
|
+
? resolved.cy
|
|
75
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
76
|
+
return { x: cx, y: cy, testID: n.testID, text: n.text }
|
|
77
|
+
})()`})??null}async function Ze(t,l={}){let a=await t.send({type:"evaluate",code:`(async () => {
|
|
78
|
+
const test = window.__sootsimTest
|
|
79
|
+
const kb = window.__sootsimKeyboard
|
|
80
|
+
// host-side __sootsimTest is a Proxy that forwards every call to the
|
|
81
|
+
// tenant worker \u2014 every method returns a Promise, so we must await.
|
|
82
|
+
const navSnap =
|
|
83
|
+
test && typeof test.getNavigationSnapshot === 'function'
|
|
84
|
+
? await test.getNavigationSnapshot()
|
|
85
|
+
: null
|
|
86
|
+
const keyboard =
|
|
87
|
+
kb && typeof kb.getLayout === 'function'
|
|
88
|
+
? (() => {
|
|
89
|
+
const layout = kb.getLayout()
|
|
90
|
+
return layout ? {
|
|
91
|
+
visible: layout.visible,
|
|
92
|
+
mode: layout.mode,
|
|
93
|
+
spec: layout.spec
|
|
94
|
+
? {
|
|
95
|
+
keyboardType: layout.spec.keyboardType,
|
|
96
|
+
returnKeyType: layout.spec.returnKeyType,
|
|
97
|
+
}
|
|
98
|
+
: null,
|
|
99
|
+
} : null
|
|
100
|
+
})()
|
|
101
|
+
: null
|
|
102
|
+
return { nav: navSnap, keyboard }
|
|
103
|
+
})()`}),d=a?.nav??null,u=a?.keyboard??null,i=await oe(t,500).catch(()=>null);if(l.json){console.log(JSON.stringify({shell:i??null,nav:d,keyboard:u},null,2));return}let b=[];if(i){let k=i.activeApp??i.state??"<none>",$=i.showSwitcher?" (app switcher open)":"",N=typeof i.launchProgress=="number"&&i.launchProgress<.98?` launching (${Math.round(i.launchProgress*100)}%)`:"";b.push(`shell: ${k}${$}${N}`)}else b.push("shell: <unavailable>");if(d){let k=d.transitionPhase!=="idle"?` (${d.transitionPhase}, ${d.activeTransitionCount} active)`:"";if(b.push(`nav: phase=${d.transitionPhase}${k}`),d.screens.length===0)b.push(" <no registered screens \u2014 app may not use react-native-screens>");else for(let $ of d.screens){let N=$.isActive?"\u25B6":" ",h=$.routeName?` ${$.routeName}`:"",S=$.headerHeight>0?` header=${$.headerHeight}`:"",F=$.largeTitleState&&$.largeTitleState!=="expanded"?` large-title=${$.largeTitleState}`:"";b.push(` ${N} #${$.id}${h}${S}${F}`)}}else b.push("nav: <runtime not available>");if(u&&u.visible){let k=u.spec?.keyboardType??"default",$=u.spec?.returnKeyType??"default";b.push(`keyboard: visible (${k}, return=${$}, mode=${u.mode??"?"})`)}else b.push("keyboard: hidden");console.log(b.join(`
|
|
104
|
+
`))}async function se({bridge:t,maxMs:l,pollMs:a=50,stablePolls:d=3,strict:u=!1}){let i=await t.send({type:"evaluate",code:`(async () => {
|
|
105
|
+
const start = Date.now()
|
|
106
|
+
const deadline = start + ${Math.max(0,Math.round(l))}
|
|
107
|
+
const pollMs = ${Math.max(1,Math.round(a))}
|
|
108
|
+
const requiredStablePolls = ${Math.max(1,Math.round(d))}
|
|
109
|
+
const strict = ${u?"true":"false"}
|
|
110
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
111
|
+
const readSnapshot = async () => {
|
|
112
|
+
let animating = false
|
|
113
|
+
try {
|
|
114
|
+
const stats = await window.__sootsimRenderHost?.queryStats?.()
|
|
115
|
+
if (stats) {
|
|
116
|
+
animating =
|
|
117
|
+
stats.hasActiveAnims === true ||
|
|
118
|
+
stats.hasActiveNativeAnimations === true ||
|
|
119
|
+
stats.hasPendingAnimationFrames === true
|
|
120
|
+
}
|
|
121
|
+
} catch {}
|
|
122
|
+
const root = window.__sootsimRoot
|
|
123
|
+
const nodes = []
|
|
124
|
+
if (root) {
|
|
125
|
+
const walk = (n) => {
|
|
126
|
+
if (n.layout && n.layout.width > 0) {
|
|
127
|
+
nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
|
|
128
|
+
}
|
|
129
|
+
for (const c of n.children || []) walk(c)
|
|
130
|
+
}
|
|
131
|
+
walk(root)
|
|
132
|
+
}
|
|
133
|
+
return { layout: nodes.join(';'), animating }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let lastLayout = ''
|
|
137
|
+
let stable = 0
|
|
138
|
+
while (Date.now() < deadline) {
|
|
139
|
+
const snapshot = await readSnapshot()
|
|
140
|
+
const strictOk = !strict || !snapshot.animating
|
|
141
|
+
if (strictOk && snapshot.layout === lastLayout) {
|
|
142
|
+
stable++
|
|
143
|
+
if (stable >= requiredStablePolls) {
|
|
144
|
+
return { settled: true, elapsed: Date.now() - start }
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
stable = 0
|
|
148
|
+
}
|
|
149
|
+
lastLayout = snapshot.layout
|
|
150
|
+
await sleep(pollMs)
|
|
151
|
+
}
|
|
152
|
+
return { settled: false, elapsed: Date.now() - start }
|
|
153
|
+
})()`}),{elapsed:b,settled:k}=i??{};return{elapsed:typeof b=="number"?b:l,settled:k===!0}}async function et(t){let{bridge:l,args:a,positional:d}=t,u=d[1]?Number(d[1])*1e3:3e3,i=a.includes("--strict"),{elapsed:b,settled:k}=await se({bridge:l,maxMs:u,strict:i});console.log(k?` settled in ${b}ms`:` timed out after ${b}ms (may still be animating)`)}async function tt(t){let l=t.positional[1]?Number(t.positional[1]):.5;(!Number.isFinite(l)||l<0)&&(console.error(t.inspectUsage("sleep","[seconds]")),process.exit(1)),await X(l*1e3),console.log(` slept ${l}s`)}async function ot(t){let{bridge:l,args:a,positional:d}=t,u=d[1]?Number(d[1]):5,i=await l.send({type:"evaluate",code:`(async () => await window.__sootsimTest.dumpTree(${u}))()`});if(D(a)){B({depth:u,tree:i??null});return}console.log(typeof i=="string"?i:JSON.stringify(i,null,2))}async function st(t,l={args:[]}){let a=await t.send({type:"evaluate",code:"window.location.href"}),d=typeof a=="string"?a:"";if(D(l.args)){B({url:d});return}console.log(d)}async function nt(t){let{wsPort:l,commandTimeoutMs:a,simId:d,positional:u}=t,i=u[1]?Number(u[1]):30,b=Math.max(1e3,(Number.isFinite(i)?i:30)*1e3),k=Math.max(1,Math.ceil(b/500));console.log(" waiting for sim reconnect...");let $=await Ce(l,a,d,{attempts:k});$||(console.error(" timed out waiting for sim reconnect"),process.exit(1)),$.bridge.close(),le({source:"inspect wait",step:{wait:b},summary:`wait ${Math.round(b/1e3)}s`}),console.log(` ready: ${$.count} nodes`)}var rt=new Set(["app-launch","toast","keyboard","screen","route","alert","actionsheet","picker","notification","fetch","console","shell","scroll","gesture","text-input","react-commit","animation","reanimated"]);function me(t,l){let a=t.indexOf(l);if(a>=0&&a+1<t.length)return t[a+1]}function Lt(t,l){if(!l.filter&&!l.equals)return!0;let a=t.data,d=[];if(a&&typeof a=="object")for(let i of["url","displayUrl","message","name","activeName","path","pathname","title","phase","event","type","kind"]){let b=a[i];typeof b=="string"&&b.length>0&&d.push(b)}let u=d.join(" ");return l.equals?d.some(i=>i===l.equals):l.filter?u.toLowerCase().includes(l.filter.toLowerCase()):!0}async function it(t){let{bridge:l,args:a,positional:d,inspectUsage:u}=t,i=d[1];i||(console.error(u("wait event","<kind> [--max-ms 5000] [--filter <substring>] [--equals <exact>] [--since now|cursor]")),process.exit(1)),rt.has(i)||console.error(` warning: '${i}' is not a known timeline kind \u2014 waiting anyway. known: ${[...rt].sort().join(", ")}`);let b=me(a,"--max-ms"),k=b&&Number.isFinite(Number(b))?Math.max(100,Number(b)):5e3,$=me(a,"--filter"),N=me(a,"--equals"),h=me(a,"--since")??"now",S=a.includes("--json"),F=Date.now(),I=F+k,C=200,c=F;for(;Date.now()<I;){let L={kinds:[i],since:h==="cursor"?void 0:c,limit:50},O=await l.send({type:"evaluate",code:`(async () => {
|
|
154
|
+
const t = window.SootSim?.bridges?.timeline
|
|
155
|
+
if (!t) return { ok: false, error: 'timeline bridge missing' }
|
|
156
|
+
return { ok: true, result: await t.recent(${JSON.stringify(L)}) }
|
|
157
|
+
})()`});(!O||!O.ok)&&(console.error(` could not query timeline: ${O&&"error"in O?O.error:"unknown"}`),process.exit(1));let H=O.result.events??[];for(let Z of H)if(Lt(Z,{filter:$,equals:N})){let Y=Date.now()-F;console.log(S?JSON.stringify({found:!0,elapsedMs:Y,event:Z}):` ${i} event after ${Y}ms${$?` (filter: ${$})`:""}${N?` (equals: ${N})`:""}`);return}O.result.watermark&&O.result.watermark>c&&(c=O.result.watermark),await new Promise(Z=>setTimeout(Z,C))}let J=Date.now()-F;S?console.log(JSON.stringify({found:!1,elapsedMs:J,kind:i,filter:$,equals:N})):console.error(` \u26A0 wait event ${i} timed out after ${J}ms${$?` (filter: ${$})`:""}${N?` (equals: ${N})`:""}`),process.exit(1)}async function at(t){let{bridge:l,args:a}=t,d=a.includes("--strict"),u=a.indexOf("--max-ms"),i=u>=0&&a[u+1]?Math.max(100,Number(a[u+1])):3e3,{elapsed:b,settled:k}=await se({bridge:l,maxMs:i,strict:d});k?console.log(` idle in ${b}ms`):(console.error(` \u26A0 wait idle timed out after ${b}ms (may still be animating)`),process.exit(1))}async function lt(t){let{bridge:l,args:a}=t,d=2e4,u=a.indexOf("--max-ms");u>=0&&a[u+1]&&(d=Math.max(100,Number(a[u+1])));let i=Date.now(),b=i+d,k=`(async () => {
|
|
158
|
+
const t = window.__sootsimTest
|
|
159
|
+
let nodes = 0
|
|
160
|
+
try { nodes = (await t?.getNodeCount?.()) || 0 } catch {}
|
|
161
|
+
return {
|
|
162
|
+
flag: (window).__sootsimExternalAppReady,
|
|
163
|
+
at: (window).__sootsimExternalAppReadyAt || 0,
|
|
164
|
+
nodes,
|
|
165
|
+
}
|
|
166
|
+
})()`,$={flag:void 0,at:0,nodes:0};for(;Date.now()<b;){try{$=await l.send({type:"evaluate",code:k})??$}catch{}if($.flag===!0){console.log(` ready in ${Date.now()-i}ms: ${$.nodes} nodes (flag)`);return}await new Promise(N=>setTimeout(N,150))}console.error(` \u26A0 wait ready timed out after ${Date.now()-i}ms \u2014 guest app did not emit sootsim:externalAppReady (nodes: ${$.nodes})`),process.exit(1)}async function ct(t){let{bridge:l,args:a,positional:d,inspectUsage:u}=t,i=d[1];i||(console.error(u("wait selector","<testid> [--max-ms 5000]")),process.exit(1));let b=a.indexOf("--max-ms"),k=b>=0&&a[b+1]?Math.max(100,Number(a[b+1])):5e3,$=await l.send({type:"evaluate",code:`(async () => {
|
|
167
|
+
const start = Date.now()
|
|
168
|
+
const deadline = start + ${k}
|
|
169
|
+
const t = window.__sootsimTest
|
|
170
|
+
const find = async () => {
|
|
171
|
+
try {
|
|
172
|
+
return (await t?.findByTestId?.(${JSON.stringify(i)})) ||
|
|
173
|
+
(await t?.findById?.(${JSON.stringify(i)})) || null
|
|
174
|
+
} catch {}
|
|
175
|
+
return null
|
|
176
|
+
}
|
|
177
|
+
while (Date.now() < deadline) {
|
|
178
|
+
const node = await find()
|
|
179
|
+
if (node && node.layout && node.layout.width > 0 && node.layout.height > 0) {
|
|
180
|
+
return { found: true, node, elapsed: Date.now() - start }
|
|
181
|
+
}
|
|
182
|
+
await new Promise((r) => setTimeout(r, 80))
|
|
183
|
+
}
|
|
184
|
+
return { found: false, elapsed: Date.now() - start }
|
|
185
|
+
})()`}),{found:N,node:h,elapsed:S}=$??{};if(N&&h){let F=h.absolutePosition?`@(${Math.round(h.absolutePosition.x)},${Math.round(h.absolutePosition.y)})`:"",I=h.layout?`${Math.round(h.layout.width)}x${Math.round(h.layout.height)}`:"?x?";console.log(` found #${i} in ${S}ms ${I} ${F}`)}else console.error(` \u26A0 wait selector #${i} timed out after ${S??k}ms`),process.exit(1)}function gt(t){return t==null?"\u2014":t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}K`:`${(t/1024/1024).toFixed(1)}M`}function yt(t){return t==null?" \u2026":t<1e3?`${t}ms`.padStart(5):`${(t/1e3).toFixed(2)}s`.padStart(5)}function Jt(t){return t.error?"err":t.status==null?" \u2026 ":String(t.status)}function dt(t){let l=new Date(t.startTs).toLocaleTimeString(),a=Jt(t).padEnd(3),d=t.method.padEnd(5),u=gt(t.size).padStart(6),i=yt(t.durationMs);console.log(` [${l}] ${a} ${d} ${u} ${i} ${t.displayUrl}`),t.error&&console.log(` error: ${t.error}`)}function Ht(t){let l=[["id",t.id],["source",t.source],["kind",t.kind],["method",t.method],["status",t.error?`error: ${t.error}`:`${t.status??"\u2014"} ${t.statusText??""}`.trim()],["url",t.url],["started",new Date(t.startTs).toLocaleTimeString()],["duration",yt(t.durationMs).trim()],["size",gt(t.size)],["content-type",t.type??"\u2014"]];for(let[a,d]of l)console.log(` ${a.padEnd(13)} ${d}`)}var qt={error:"\x1B[31m",warn:"\x1B[33m",info:"\x1B[36m",debug:"\x1B[35m",log:"\x1B[37m"},ut="\x1B[0m",Wt="\x1B[2m";function mt(t,l){let a=new Date(t.ts).toLocaleTimeString(),d=t.level.toUpperCase().padEnd(5),u=t.args.join(" ");if(l){let i=qt[t.level];console.log(` ${Wt}[${a}]${ut} ${i}${d}${ut} ${u}`)}else console.log(` [${a}] ${d} ${u}`);if(t.stack&&t.level==="error"){let i=t.stack.split(`
|
|
186
|
+
`).slice(0,5);for(let b of i)console.log(` ${b.trim()}`)}}var Q="__sootsimCliPerf",Kt=120;async function pt(t,l){let a=t.find((F,I)=>t[I-1]==="--id"),d=t.find((F,I)=>t[I-1]==="--text");if(a||d){let F=await l.send({type:"evaluate",code:Re({id:a,text:d})});if(!F)throw new Error(a?`no node with id "${a}"`:`no node matching text "${d}"`);let{x:I,y:C,w:c,h:J}=F;return{x:I,y:C,w:c,h:J}}let u=t.find((F,I)=>t[I-1]==="--area");if(u){let F=u.split(",").map(L=>Number(L.trim()));if(F.length!==4||F.some(L=>!Number.isFinite(L)))throw new Error(`--area expects x,y,w,h (got "${u}")`);let[I,C,c,J]=F;return{x:I,y:C,w:c,h:J}}let i=F=>{let I=t.find((c,J)=>t[J-1]===F);if(I==null)return null;let C=Number(I);return Number.isFinite(C)?C:null},b=i("--x"),k=i("--y"),$=i("--w"),N=i("--h");if(b!=null||k!=null||$!=null||N!=null)return{x:b??0,y:k??0,w:$??1,h:N??1};let S=t.filter((F,I)=>I>0&&!F.startsWith("-")&&t[I-1]!=="--output"&&t[I-1]!=="--area"&&t[I-1]!=="--id"&&t[I-1]!=="--text"&&t[I-1]!=="--x"&&t[I-1]!=="--y"&&t[I-1]!=="--w"&&t[I-1]!=="--h").map(Number).filter(F=>Number.isFinite(F));if(S.length>=2){let[F,I,C=1,c=1]=S;return{x:F,y:I,w:C,h:c}}return null}function Se(t){let l={"<8":0,"8-12":0,"12-16":0,"16-20":0,"20-33":0,">33":0};for(let a of t)a<8?l["<8"]++:a<12?l["8-12"]++:a<16?l["12-16"]++:a<20?l["16-20"]++:a<33?l["20-33"]++:l[">33"]++;console.log(" histogram:");for(let[a,d]of Object.entries(l)){let u="\u2588".repeat(Math.ceil(d/t.length*40));console.log(` ${a.padEnd(6)} ${u} ${d}`)}}async function pe(t,l,a){let d=Date.now()+l,u=await oe(t,l);for(;;){if(a(u))return{settled:!0,state:u};if(Date.now()>=d)return{settled:!1,state:u};await X(16),u=await oe(t)}}async function ke(t){return t.send({type:"evaluate",code:`(async () => {
|
|
187
|
+
const kb = window.__sootsimKeyboard
|
|
188
|
+
const test = window.__sootsimTest
|
|
189
|
+
if (!kb) return { error: 'keyboard bridge not available' }
|
|
190
|
+
const visible = kb.isVisible()
|
|
191
|
+
const mode = kb.getMode()
|
|
192
|
+
let focused = null
|
|
193
|
+
if (test && typeof test.getFocusedNode === 'function') {
|
|
194
|
+
try {
|
|
195
|
+
focused = await test.getFocusedNode()
|
|
196
|
+
} catch {}
|
|
197
|
+
}
|
|
198
|
+
let runtimeSnapshot = null
|
|
199
|
+
if (test && typeof test.getFocusKeyboardSnapshot === 'function') {
|
|
200
|
+
try {
|
|
201
|
+
runtimeSnapshot = await test.getFocusKeyboardSnapshot()
|
|
202
|
+
} catch {}
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
visible,
|
|
206
|
+
mode,
|
|
207
|
+
focusedInput: focused ? {
|
|
208
|
+
nodeId: focused.nodeId ?? null,
|
|
209
|
+
testID: focused.testID || null,
|
|
210
|
+
id: focused.id || null,
|
|
211
|
+
placeholder: focused.placeholder || null,
|
|
212
|
+
text: focused.text || null,
|
|
213
|
+
} : null,
|
|
214
|
+
phase: runtimeSnapshot?.keyboard?.phase ?? null,
|
|
215
|
+
frame: runtimeSnapshot?.keyboard?.frame ?? null,
|
|
216
|
+
focusedRect: runtimeSnapshot?.focused?.rect ?? null,
|
|
217
|
+
}
|
|
218
|
+
})()`})}async function zt(t,l=600){let a=Date.now()+l;for(;Date.now()<=a;){let d=await ke(t);if(d.visible)return d;await X(30)}return ke(t)}async function fe(t,l){let a=await ke(t);if(a.visible)return a;console.error(` ${l} requires the iOS keyboard to be visible. focus an input first with sootsim do tap-id/tap-text or sootsim do type-into.`),process.exit(1)}async function ft(t,l,a){return l==="appearance"?t.send({type:"evaluate",code:`(async () => {
|
|
219
|
+
const requested = ${JSON.stringify(a??"toggle")}
|
|
220
|
+
const rootBg = (document.documentElement?.style?.background || '').toLowerCase()
|
|
221
|
+
const inferredCurrent = rootBg.includes('33') ? 'dark' : 'light'
|
|
222
|
+
let next = requested
|
|
223
|
+
if (requested === 'toggle') {
|
|
224
|
+
next = inferredCurrent === 'dark' ? 'light' : 'dark'
|
|
225
|
+
}
|
|
226
|
+
// engine accepts 'auto' since the schema picker landed; pass through.
|
|
227
|
+
window.postMessage({ type: 'soot-action', action: 'set-appearance', value: next }, '*')
|
|
228
|
+
const applied = next === 'auto'
|
|
229
|
+
? (window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? 'dark' : 'light')
|
|
230
|
+
: next
|
|
231
|
+
return { ok: true, requested, value: next, applied }
|
|
232
|
+
})()`}):t.send({type:"evaluate",code:`(async () => {
|
|
233
|
+
window.dispatchEvent(new CustomEvent(${JSON.stringify(l==="lock"?"sootsim:toggleLock":"sootsim:shake")}))
|
|
234
|
+
return { ok: true, action: ${JSON.stringify(l)} }
|
|
235
|
+
})()`})}function Ut(t){let l={Enter:"return",NumpadEnter:"return",Backspace:"delete",Delete:"delete",Space:"space",ShiftLeft:"shift",ShiftRight:"shift"};if(l[t])return l[t];let a=t.match(/^Digit([0-9])$/);if(a)return a[1];let d=t.match(/^Key([A-Z])$/);return d?d[1].toLowerCase():null}function Yt(t){if(typeof t!="string")return null;let l=t.replace(/\s+/g," ").trim();return l?l.slice(0,80):null}function bt(...t){for(let l of t){if(typeof l!="string")continue;let a=l.trim();if(a)return a}return null}async function j(t,l,a){le({source:t,step:l,summary:a})}function Gt(t,l,a){if(!a||a.hit===!1)return null;let d=bt(a.responderTestID,a.testID);if(d)return{step:{tapOn:{id:d}},summary:`tap #${d}`};let u=Yt(a.text);return u?{step:{tapOn:u},summary:`tap "${u}"`}:{step:{tapAtCoords:{x:t,y:l}},summary:`tap @${Math.round(t)},${Math.round(l)}`}}function ve(t,l,a){let d=bt(l?.testID,l?.id);return d?{step:{tapOn:{id:d}},summary:`tap #${d}`}:a==="id"?{step:{tapOn:{id:t}},summary:`tap #${t}`}:{step:{tapOn:t},summary:`tap "${t}"`}}async function xs(t,l){let a=t[0]==="get"||t[0]==="do"||t[0]==="debug"||t[0]==="wait"?t[0]:null,d=a?t.slice(1):t,u=Ne(d,{port:l.port,commandTimeoutMs:l.timeoutMs,stripBooleanFlags:["--verbose","-v","--help","-h","--clear-state","--json","--all","--watch","-w","--strict","--no-wait","--dump","--failed","--slow","--tail","-f","--interactive-targets","--actions","--internal"],stripValueFlags:["--output","--nth","--index","--testid","--test-id","--text","--max-ms","--filter","--limit","--level","--threshold","--equals","--since"]}),i=u.positional,b=i[0],k=a==="get"||a==="do"||a==="debug"||a==="wait"?a:"inspect",$=typeof d[0]=="string"&&Me.has(d[0]),N=$?d[0]:null,h=e=>$&&e===d[0]?`sootsim ${e}`:`sootsim ${k} ${e}`,S=(e,o)=>` usage: ${h(e)}${o?` ${o}`:""}`;if(!b||t.includes("--help")||t.includes("-h")){let e={bridgePort:7668,defaultShellUrl:Te};if(k==="do"||k==="get"||k==="debug"||k==="wait"){let r=ge(k,e);r&&(console.log(`${r}
|
|
236
|
+
`),process.exit(0))}if(N==="shell"){let r=ye("shell",e);r&&(console.log(`${r}
|
|
237
|
+
`),process.exit(0))}let o=ye("inspect",e),s=["do","get","debug","wait"].map(r=>ge(r,e)).filter(r=>r!=null).join(`
|
|
238
|
+
|
|
239
|
+
`);console.log(`${o??""}
|
|
240
|
+
|
|
241
|
+
${s}
|
|
242
|
+
`),process.exit(0)}let F=u.wsPort,I=u.simId,C=u.commandTimeoutMs;if(b==="list"&&d.some(e=>e==="--drivers"||e==="-D")){let{buildDriverListRows:e}=await import("./drivers-NSCX5CRA.js"),o=e();console.log(` available drivers (${o.length}):
|
|
243
|
+
`);let s=Math.max(...o.map(n=>n.id.length),6),r=Math.max(...o.map(n=>n.kind.length),4);for(let n of o){let m=n.available?"\u2713":"\u2717",p=n.id.padEnd(s),y=n.kind.padEnd(r);console.log(` ${m} ${p} ${y} ${n.description}`),n.available&&n.detail?console.log(` ${n.detail}`):!n.available&&n.reason&&console.log(` unavailable: ${n.reason}`)}return}let c=_e(u),J=I||"default",L=new Set(["errors","warnings","requests","js","eval","reload","globals","perf","list","wait","sleep"]);function O(e){let o=e.displayUrl||e.url;return e.status!=null?`${e.method} ${o} -> ${e.status}${e.statusText?` ${e.statusText}`:""}`:e.error?`${e.method} ${o} -> ${e.error}`:`${e.method} ${o}`}async function H(e){let o=We()?1200:350;try{let{settled:s,elapsed:r}=await se({bridge:e,maxMs:o,pollMs:32,stablePolls:2});s||process.stderr.write(` \u26A0 auto-wait timed out after ${r??o}ms \u2014 next command may see mid-animation state. use \`sootsim do settle\` for a longer wait.
|
|
244
|
+
`)}catch{}}async function Z(){try{return await c.send({type:"evaluate",code:`(() => ({
|
|
245
|
+
console: window.__sootsimConsole?.count?.() || null,
|
|
246
|
+
requests: window.__sootsimTest?.getRequestCounts?.() || null,
|
|
247
|
+
}))()`})||{console:null,requests:null}}catch{return{console:null,requests:null}}}async function Y(e={}){let o=e.counts!==void 0?e.counts:await K(c,"getRequestCounts");if(!o||typeof o!="object")return;let s=Math.max(0,Number(o.failed)||0);if(s===0||!e.includeTail&&!we("requests",J,String(s))||(console.log(`
|
|
248
|
+
network: ${s} failed request${s===1?"":"s"}`),console.log(` inspect: ${h("requests")} 5`),!e.includeTail))return;let r=await K(c,"getFailedRequests",5);if(!(!Array.isArray(r)||r.length===0)){console.log(`
|
|
249
|
+
recent failed requests:
|
|
250
|
+
`);for(let n of r){let m=new Date(n.timestamp).toLocaleTimeString();console.log(` [${m}] ${O(n)}`),n.responseBody?console.log(` ${n.responseBody}`):n.error&&console.log(` ${n.error}`)}}}async function w(e={}){let o=e.counts!==void 0?e.counts:await c.send({type:"evaluate",code:"window.__sootsimConsole?.count?.() || { errors: 0, warnings: 0, total: 0 }"});if(!o||typeof o!="object")return;let s=o,r=Math.max(0,Number(s.errors)||0),n=Math.max(0,Number(s.warnings)||0);if(r===0&&n===0||!e.includeTail&&!we("console",J,`${r}:${n}`))return;let m=[];if(r>0&&m.push(`${r} console error${r===1?"":"s"}`),n>0&&m.push(`${n} console warning${n===1?"":"s"}`),console.log(`
|
|
251
|
+
console: ${m.join(", ")}`),console.log(` inspect: ${h("errors")} 5`),n>0&&console.log(` inspect: ${h("warnings")} 5`),!e.includeTail||r===0)return;let p=await c.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors?.(5) || []"});if(!(!Array.isArray(p)||p.length===0)){console.log(`
|
|
252
|
+
recent console errors:
|
|
253
|
+
`);for(let y of p){let g=new Date(y.timestamp).toLocaleTimeString(),x=Array.isArray(y.args)?y.args.map(R=>typeof R=="object"?JSON.stringify(R):String(R)).join(" "):String(y);console.log(` [${g}] ${x}`)}}}let _=["console","fetch","toast","alert","notification","screen","app-launch","keyboard","route","actionsheet","picker","shell","scroll","gesture","text-input","animation","reanimated"];async function W(e){let o=Ie(),s=null;try{s=await Pe(e,`(() => {
|
|
254
|
+
const tl = window.SootSim && window.SootSim.bridges && window.SootSim.bridges.timeline
|
|
255
|
+
if (!tl || typeof tl.summary !== 'function') return null
|
|
256
|
+
const cursorKey = ${JSON.stringify(o)}
|
|
257
|
+
const summary = tl.summary({ sinceCursor: cursorKey })
|
|
258
|
+
let consoleSplit = null
|
|
259
|
+
if (summary && summary.byKind && summary.byKind.console) {
|
|
260
|
+
const events = tl.recent({ sinceCursor: cursorKey, kinds: 'console', limit: 100000 }).events
|
|
261
|
+
consoleSplit = { error: 0, warn: 0 }
|
|
262
|
+
for (const ev of events) {
|
|
263
|
+
const lvl = ev && ev.data && ev.data.level
|
|
264
|
+
if (lvl === 'error') consoleSplit.error++
|
|
265
|
+
else if (lvl === 'warn') consoleSplit.warn++
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return summary ? { summary, consoleSplit } : null
|
|
269
|
+
})()`)}catch{return}if(!s||!s.summary||!s.summary.total)return;let r=s.summary.byKind??{},n=[],m=new Set;for(let p of _){let y=r[p];if(y)if(m.add(p),p==="console"&&s.consoleSplit){let{error:g,warn:x}=s.consoleSplit;g>0&&n.push(`${g} error${g===1?"":"s"}`),x>0&&n.push(`${x} warning${x===1?"":"s"}`)}else n.push(`${y} ${p}${y===1?"":"s"}`)}for(let[p,y]of Object.entries(r))!m.has(p)&&y&&n.push(`${y} ${p}${y===1?"":"s"}`);if(n.length!==0&&(console.log(`
|
|
270
|
+
since last: ${n.join(" \xB7 ")} \u2014 sootsim what-happened`),s.summary.lastAt))try{await be(e,"SootSim.bridges.timeline.cursorAdvance",o,s.summary.lastAt)}catch{}}let ee=new Set(["tap","double-tap","tap-text","tap-id","type","type-into","key","key-sequence","keycode","drag","swipe","long-press","touch","gesture","pinch","scroll","shell"]),E=new Set(["a11y","capture","count","double-tap","drag","find","gesture","layout","long-press","node","pinch","sample-color","scroll","screenshot","swipe","tap","tap-id","tap-text","touch","tree","type-into"]),V=(t.includes("--verbose")||t.includes("-v"))&&!t.includes("--json");k==="do"&&b==="shell"&&(console.error(" `sootsim do shell` was removed. use `sootsim shell ...` instead."),process.exit(1)),ee.has(b)&&await Fe(c),E.has(b)&&await ce(c,{verbose:V});try{switch(b){case"list":{await Ve({bridge:c,simId:I,args:d});break}case"tree":{await ot({bridge:c,args:d,positional:i});break}case"a11y":{let e=i[1]?Number(i[1]):5,o=await c.send({type:"evaluate",code:`(async () => {
|
|
271
|
+
const t = window.__sootsimTest
|
|
272
|
+
if (!t) return []
|
|
273
|
+
const all = await t.queryAll({ pruneHidden: true })
|
|
274
|
+
return all.filter(n => {
|
|
275
|
+
// skip zero-size nodes
|
|
276
|
+
if (!n.layout || n.layout.width <= 0 || n.layout.height <= 0) return false
|
|
277
|
+
// keep nodes with explicit accessibility roles or labels
|
|
278
|
+
if (n.accessibilityRole) return true
|
|
279
|
+
if (n.accessibilityHint) return true
|
|
280
|
+
if (n.isTextInput) return true
|
|
281
|
+
if (n.pressable) return true
|
|
282
|
+
// keep text leaf nodes
|
|
283
|
+
if (n.type === 'text' && n.text) return true
|
|
284
|
+
// keep views with intentional labels (not auto-derived)
|
|
285
|
+
if (n.accessibilityLabel && n.accessibilityLabel.length <= 30
|
|
286
|
+
&& n.accessibilityLabel !== n.text) return true
|
|
287
|
+
// skip container views without role (just concatenated child text)
|
|
288
|
+
return false
|
|
289
|
+
}).map(n => ({
|
|
290
|
+
role: n.accessibilityRole || (n.pressable ? 'button' : n.isTextInput ? 'textfield' : n.type === 'text' ? 'statictext' : 'none'),
|
|
291
|
+
label: n.accessibilityLabel || n.text || null,
|
|
292
|
+
hint: n.accessibilityHint || null,
|
|
293
|
+
state: n.accessibilityState || null,
|
|
294
|
+
testID: n.testID || null,
|
|
295
|
+
position: n.absolutePosition ? { x: Math.round(n.absolutePosition.x), y: Math.round(n.absolutePosition.y) } : null,
|
|
296
|
+
size: n.layout ? { w: Math.round(n.layout.width), h: Math.round(n.layout.height) } : null,
|
|
297
|
+
}))
|
|
298
|
+
})()`});if(!Array.isArray(o)||o.length===0){console.log(" no accessible nodes found");break}if(t.includes("--json"))console.log(JSON.stringify(o,null,2));else{console.log(` accessibility tree (${o.length} nodes):
|
|
299
|
+
`);for(let s of o){let r=[];if(r.push(`[${s.role}]`),s.label){let n=s.label.length>50?s.label.slice(0,47)+"...":s.label;r.push(`"${n}"`)}if(s.hint&&r.push(`(hint: "${s.hint}")`),s.testID&&r.push(`#${s.testID}`),s.state){let n=[];s.state.disabled&&n.push("disabled"),s.state.selected&&n.push("selected"),s.state.checked===!0&&n.push("checked"),s.state.checked==="mixed"&&n.push("mixed"),s.state.busy&&n.push("busy"),s.state.expanded===!0&&n.push("expanded"),s.state.expanded===!1&&n.push("collapsed"),n.length&&r.push(`{${n.join(", ")}}`)}s.position&&r.push(`@(${s.position.x},${s.position.y})`),s.size&&r.push(`${s.size.w}x${s.size.h}`),console.log(" "+r.join(" "))}}break}case"find":{await Ge({bridge:c,args:t,effectiveArgs:d,positional:i,inspectUsage:S});break}case"count":{await He(c,{args:d});break}case"keyboard":{await Xe(c,{json:t.includes("--json")});break}case"screens":{await Ze(c,{json:t.includes("--json")});break}case"memory":{await Qe(c,{args:d});break}case"wait":{await nt({wsPort:F,commandTimeoutMs:C,simId:I,positional:i});break}case"sleep":{await tt({positional:i,inspectUsage:S});break}case"settle":{await et({bridge:c,args:t,positional:i});break}case"ready":{await lt({bridge:c,args:t});break}case"idle":{await at({bridge:c,args:t,positional:i});break}case"selector":{await ct({bridge:c,args:t,positional:i,inspectUsage:S});break}case"event":{await it({bridge:c,args:t,positional:i,inspectUsage:S});break}case"layout":{let e=i[1];e||(console.error(S("layout","<id>")),process.exit(1));let o=await c.send({type:"evaluate",code:`(async () => await window.__sootsimTest.getLayout(${JSON.stringify(e)}))()`});console.log(JSON.stringify(o,null,2));break}case"capture":case"screenshot":{let o=t.find((y,g)=>t[g-1]==="--output")||"/tmp/sootsim-inspect.png",s=await pt(t,c),r={type:"screenshot"};s&&(r.crop=s);let m=(await c.send(r)).replace(/^data:image\/png;base64,/,"");s&&console.log(` area: x=${s.x} y=${s.y} w=${s.w} h=${s.h}`),(await import("fs")).writeFileSync(o,Buffer.from(m,"base64")),console.log(` saved: ${o}`);break}case"sample-color":{let e=await pt(t,c);e||(console.error(S("sample-color","<x> <y> [w] [h] | --id <testID> | --text <text>")),console.error(" samples an averaged color from the canvas. coords are logical sootsim units."),process.exit(1));let o=await c.send({type:"evaluate",code:Ee(e)});if(t.includes("--json"))console.log(JSON.stringify(o,null,2));else{let{r:s,g:r,b:n,a:m,hex:p,samples:y}=o,g=e.w===1&&e.h===1?`@(${e.x},${e.y})`:`@(${e.x},${e.y}) ${e.w}x${e.h}`;console.log(` ${p} rgba(${s}, ${r}, ${n}, ${m}) ${g} ${y} samples`)}break}case"node":{let e=i[1];e||(console.error(S("node","<matcher>")),console.error(" resolves testID, id, then text \u2014 dumps full node info as JSON"),process.exit(1));let o=await c.send({type:"evaluate",code:`(async () => {
|
|
300
|
+
const t = window.__sootsimTest
|
|
301
|
+
const q = ${JSON.stringify(e)}
|
|
302
|
+
let node = null
|
|
303
|
+
let via = null
|
|
304
|
+
if (t.findByTestId) { node = await t.findByTestId(q); if (node) via = 'testID' }
|
|
305
|
+
if (!node && t.findById) { node = await t.findById(q); if (node) via = 'id' }
|
|
306
|
+
if (!node && t.findByText) { node = await t.findByText(q); if (node) via = 'text' }
|
|
307
|
+
if (!node) return { matcher: q, found: false }
|
|
308
|
+
|
|
309
|
+
// read the resolved transform (if any) off the style \u2014 useful
|
|
310
|
+
// because canvas nodes often animate via transform and describe
|
|
311
|
+
// output strips that.
|
|
312
|
+
const transform =
|
|
313
|
+
node.style && Array.isArray(node.style.transform)
|
|
314
|
+
? node.style.transform
|
|
315
|
+
: node.style && node.style.transform
|
|
316
|
+
? node.style.transform
|
|
317
|
+
: null
|
|
318
|
+
|
|
319
|
+
// parent chain \u2014 walk up from the node so the JSON dump is
|
|
320
|
+
// self-describing.
|
|
321
|
+
const parentChain = []
|
|
322
|
+
const root = window.__sootsimRoot
|
|
323
|
+
if (root && node.id != null) {
|
|
324
|
+
const findPath = (n, targetId, path) => {
|
|
325
|
+
if (!n) return null
|
|
326
|
+
if (n.id === targetId) return path
|
|
327
|
+
if (n.children) {
|
|
328
|
+
for (const child of n.children) {
|
|
329
|
+
const nextPath = [
|
|
330
|
+
...path,
|
|
331
|
+
{
|
|
332
|
+
type: n.type || 'view',
|
|
333
|
+
testID: n.props?.testID || null,
|
|
334
|
+
text: n.text || null,
|
|
335
|
+
},
|
|
336
|
+
]
|
|
337
|
+
const found = findPath(child, targetId, nextPath)
|
|
338
|
+
if (found) return found
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return null
|
|
342
|
+
}
|
|
343
|
+
const chain = findPath(root, node.id, [])
|
|
344
|
+
if (chain) parentChain.push(...chain)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
matcher: q,
|
|
349
|
+
found: true,
|
|
350
|
+
resolvedVia: via,
|
|
351
|
+
node,
|
|
352
|
+
transform,
|
|
353
|
+
parentChain,
|
|
354
|
+
}
|
|
355
|
+
})()`});console.log(JSON.stringify(o,null,2));break}case"tap":{let e=Number(i[1]),o=Number(i[2]),s=ie(t);if(s){let m=await ue(c,s);m||(console.error(` not found: ${s.value}`),s.mode==="testid"&&G("wait-selector-for-missing-testid",s.value),process.exit(1)),e=m.x,o=m.y}(!Number.isFinite(e)||!Number.isFinite(o))&&(console.error(S("tap","<x> <y> | --testid <id> | --text <t>")),process.exit(1));let r=await c.send({type:"tap",x:e,y:o}),n=Gt(e,o,r);n&&await j("inspect tap",n.step,n.summary),console.log(JSON.stringify(r,null,2));break}case"drag":case"swipe":{let e=Number(i[1]),o=Number(i[2]),s=Number(i[3]),r=Number(i[4]),n=b==="swipe"?10:12,m=b==="swipe"?8:16,p=i[5]?Number(i[5]):n,y=i[6]?Number(i[6]):m;(!Number.isFinite(e)||!Number.isFinite(o)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(p)||!Number.isFinite(y))&&(console.error(S(b,"<x1> <y1> <x2> <y2> [steps] [stepMs]")),process.exit(1));let g=await c.send({type:"evaluate",code:`(async () => {
|
|
356
|
+
const interact = window.__sootsimInteract
|
|
357
|
+
if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
|
|
358
|
+
const value = await interact.drag(${e}, ${o}, ${s}, ${r}, ${Math.max(1,Math.round(p))}, ${Math.max(0,Math.round(y))})
|
|
359
|
+
return { ok: !!value, value }
|
|
360
|
+
})()`});if(g?.ok){let x=Math.max(1,Math.round(Math.max(1,p)*Math.max(0,y)));await j(`inspect ${b}`,{swipe:{start:`${e}, ${o}`,end:`${s}, ${r}`,duration:x}},`${b} ${e},${o} -> ${s},${r}`)}console.log(JSON.stringify(g,null,2));break}case"pinch":{let e=Number(i[1]),o=Number(i[2]),s=Number(i[3]),r=Number(i[4]),n=Number(i[5]),m=Number(i[6]),p=Number(i[7]),y=Number(i[8]),g=i[9]?Number(i[9]):12,x=i[10]?Number(i[10]):16;(!Number.isFinite(e)||!Number.isFinite(o)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g)||!Number.isFinite(x))&&(console.error(S("pinch","<x1> <y1> <x2> <y2> <x1'> <y1'> <x2'> <y2'> [steps] [stepMs]")),process.exit(1));let R=await c.send({type:"evaluate",code:`(async () => {
|
|
361
|
+
const interact = window.__sootsimInteract
|
|
362
|
+
if (!interact?.pinch) return { ok: false, reason: 'no interact.pinch' }
|
|
363
|
+
const value = await interact.pinch(${e}, ${o}, ${s}, ${r}, ${n}, ${m}, ${p}, ${y}, ${Math.max(1,Math.round(g))}, ${Math.max(0,Math.round(x))})
|
|
364
|
+
return { ok: !!value, value }
|
|
365
|
+
})()`});R?.ok&&await j("inspect pinch",{pinch:{from:[e,o,s,r],to:[n,m,p,y],steps:Math.max(1,Math.round(g)),stepMs:Math.max(0,Math.round(x))}},`pinch (${e},${o}) (${s},${r}) -> (${n},${m}) (${p},${y})`),console.log(JSON.stringify(R,null,2));break}case"tap-text":{let e=i[1];e||(console.error(S("tap-text","<text>")),process.exit(1));let o=P=>{let A=t.indexOf(P);return A>=0&&A+1<t.length?t[A+1]:null},s=P=>t.includes(P),r=o("--nth")??o("--index"),n=r!==null?Number(r):null;n!==null&&!Number.isFinite(n)&&(console.error(` --nth/--index requires an integer, got: ${r}`),process.exit(1));let m=o("--within"),p=o("--role"),y=s("--exact"),g=s("--first"),x=o("--min-y"),R=o("--max-y"),q=o("--min-x"),z=o("--max-x");for(let[P,A]of[["--min-y",x],["--max-y",R],["--min-x",q],["--max-x",z]])A!==null&&!Number.isFinite(Number(A))&&(console.error(` ${P} requires a number, got: ${A}`),process.exit(1));let U=t.indexOf("--near"),M=null;if(U>=0){let P=Number(t[U+1]),A=Number(t[U+2]);(!Number.isFinite(P)||!Number.isFinite(A))&&(console.error(" --near requires two numbers: --near <x> <y>"),process.exit(1)),M={x:P,y:A}}let v=JSON.stringify({query:e,exact:y,role:p,within:m,minX:q!==null?Number(q):null,maxX:z!==null?Number(z):null,minY:x!==null?Number(x):null,maxY:R!==null?Number(R):null,near:M,nth:n,first:g}),f=await c.send({type:"evaluate",code:`(async () => {
|
|
366
|
+
const t = window.__sootsimTest
|
|
367
|
+
if (!t) return { error: 'bridge-not-ready' }
|
|
368
|
+
const F = ${v}
|
|
369
|
+
|
|
370
|
+
const res = await t.queryTextCandidates({
|
|
371
|
+
query: F.query,
|
|
372
|
+
exact: !!F.exact,
|
|
373
|
+
...(F.role ? { role: F.role } : {}),
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
let candidates = res.candidates || []
|
|
377
|
+
|
|
378
|
+
candidates = candidates.filter((c) => {
|
|
379
|
+
const ax = c.info.absolutePosition && c.info.absolutePosition.x
|
|
380
|
+
const ay = c.info.absolutePosition && c.info.absolutePosition.y
|
|
381
|
+
if (F.minX !== null && !(ax >= F.minX)) return false
|
|
382
|
+
if (F.maxX !== null && !(ax <= F.maxX)) return false
|
|
383
|
+
if (F.minY !== null && !(ay >= F.minY)) return false
|
|
384
|
+
if (F.maxY !== null && !(ay <= F.maxY)) return false
|
|
385
|
+
if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
|
|
386
|
+
return true
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
if (F.near) {
|
|
390
|
+
candidates.sort((a, b) => {
|
|
391
|
+
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
392
|
+
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
393
|
+
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
394
|
+
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
395
|
+
return (
|
|
396
|
+
Math.hypot(ax - F.near.x, ay - F.near.y) -
|
|
397
|
+
Math.hypot(bx - F.near.x, by - F.near.y)
|
|
398
|
+
)
|
|
399
|
+
})
|
|
400
|
+
} else {
|
|
401
|
+
candidates.sort((a, b) => {
|
|
402
|
+
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
403
|
+
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
404
|
+
if (Math.abs(ay - by) > 2) return ay - by
|
|
405
|
+
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
406
|
+
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
407
|
+
return ax - bx
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const total = candidates.length
|
|
412
|
+
if (total === 0) return { matched: 0, total: 0 }
|
|
413
|
+
|
|
414
|
+
let idx = 0
|
|
415
|
+
if (F.nth !== null) {
|
|
416
|
+
idx = F.nth < 0 ? total + F.nth : F.nth
|
|
417
|
+
if (idx < 0 || idx >= total) {
|
|
418
|
+
return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
|
|
419
|
+
}
|
|
420
|
+
} else if (total > 1 && !F.first && !F.near) {
|
|
421
|
+
return {
|
|
422
|
+
ambiguous: true,
|
|
423
|
+
total,
|
|
424
|
+
candidates: candidates.slice(0, 10).map((c, i) => ({
|
|
425
|
+
idx: i,
|
|
426
|
+
nodeId: c.info.nodeId,
|
|
427
|
+
type: c.info.type,
|
|
428
|
+
testID: c.info.testID,
|
|
429
|
+
text: (c.info.text || '').slice(0, 60),
|
|
430
|
+
abs: c.info.absolutePosition,
|
|
431
|
+
layout: c.info.layout
|
|
432
|
+
? {
|
|
433
|
+
width: Math.round(c.info.layout.width || 0),
|
|
434
|
+
height: Math.round(c.info.layout.height || 0),
|
|
435
|
+
}
|
|
436
|
+
: null,
|
|
437
|
+
ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
|
|
438
|
+
})),
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const picked = candidates[idx]
|
|
443
|
+
const n = picked.info
|
|
444
|
+
if (!n.absolutePosition || !n.layout) return { matched: 0, total }
|
|
445
|
+
|
|
446
|
+
const resolved =
|
|
447
|
+
typeof n.nodeId === 'number' &&
|
|
448
|
+
typeof t.resolveTapTarget === 'function'
|
|
449
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
450
|
+
: null
|
|
451
|
+
const target = (resolved && resolved.target) || n
|
|
452
|
+
const cx =
|
|
453
|
+
resolved && typeof resolved.cx === 'number'
|
|
454
|
+
? resolved.cx
|
|
455
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
456
|
+
const cy =
|
|
457
|
+
resolved && typeof resolved.cy === 'number'
|
|
458
|
+
? resolved.cy
|
|
459
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
460
|
+
return {
|
|
461
|
+
cx,
|
|
462
|
+
cy,
|
|
463
|
+
match: {
|
|
464
|
+
nodeId: n.nodeId ?? null,
|
|
465
|
+
id: n.id,
|
|
466
|
+
testID: n.testID,
|
|
467
|
+
type: n.type,
|
|
468
|
+
},
|
|
469
|
+
target: {
|
|
470
|
+
nodeId: target.nodeId ?? null,
|
|
471
|
+
id: target.id,
|
|
472
|
+
testID: target.testID,
|
|
473
|
+
type: target.type,
|
|
474
|
+
},
|
|
475
|
+
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
476
|
+
total,
|
|
477
|
+
idx,
|
|
478
|
+
}
|
|
479
|
+
})()`});if(f?.error==="bridge-not-ready"&&(console.error(" sootsim test bridge not ready"),process.exit(1)),f?.ambiguous){let P=f.candidates;console.error(` ambiguous: ${f.total} matches for "${e}"`);for(let A of P){let ae=A.abs?`@(${Math.round(A.abs.x)},${Math.round(A.abs.y)})`:"",ht=A.layout?` ${A.layout.width}x${A.layout.height}`:"",wt=A.testID?` #${A.testID}`:"",xt=A.text?` "${A.text}"`:"",$t=A.ancestorTestIDs.length>0?` within ${A.ancestorTestIDs.slice(0,3).map(St=>`#${St}`).join(" > ")}`:"";console.error(` [${A.idx}] <${A.type}>${xt}${wt} ${ae}${ht}${$t}`)}f.total>P.length&&console.error(` ... and ${f.total-P.length} more`),console.error(" pick one:"),console.error(" --nth <index> pick the nth match (top-to-bottom, left-to-right; negatives from end)"),console.error(" --within <testID> narrow to descendants of a node"),console.error(" --min-y / --max-y geometric filter (pixels, absolute)"),console.error(" --min-x / --max-x geometric filter (pixels, absolute)"),console.error(" --near <x> <y> pick the closest match to a point"),console.error(" --exact exact text match (default is substring)"),console.error(" --role <role> narrow to accessibilityRole"),console.error(" --first keep the old pick-first-silently behavior"),process.exit(2)}f?.nthOutOfRange&&(console.error(` not found: nth ${f.nth} of ${f.total} match${f.total===1?"":"es"} for "${e}"`),process.exit(1)),(!f||typeof f.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1));let T=await c.send({type:"tap",x:f.cx,y:f.cy});if(T?.hit!==!1&&T?.ok!==!1){let P=ve(e,{id:f.target?.id??null,testID:f.target?.testID??null,type:f.target?.type??null,cx:f.cx,cy:f.cy},"text");await j("inspect tap-text",P.step,P.summary)}console.log(JSON.stringify({matched:f.match,tapped:{nodeId:f.target?.nodeId??null,id:f.target?.id??null,testID:f.target?.testID??null,type:f.target?.type??null,cx:f.cx,cy:f.cy},...f.strategy&&f.strategy!=="matched-node"?{strategy:f.strategy}:{},...f.total>1||n!==null?{nth:{index:f.idx,total:f.total}}:{},result:T},null,2));break}case"tap-best":{let e=i[1];e||(console.error(S("tap-best","<query>")),process.exit(1));let o=JSON.stringify(e),s=await c.send({type:"evaluate",code:`(async () => {
|
|
480
|
+
const t = window.__sootsimTest
|
|
481
|
+
if (!t) return { error: 'bridge-not-ready' }
|
|
482
|
+
// try testID first \u2014 strongest signal of "this is the
|
|
483
|
+
// intended tap target".
|
|
484
|
+
const byTestId =
|
|
485
|
+
(await t.findByTestId(${o})) || (await t.findById(${o}))
|
|
486
|
+
if (byTestId && byTestId.absolutePosition && byTestId.layout) {
|
|
487
|
+
return {
|
|
488
|
+
strategy: 'testid',
|
|
489
|
+
node: {
|
|
490
|
+
nodeId: byTestId.nodeId ?? null,
|
|
491
|
+
id: byTestId.id,
|
|
492
|
+
testID: byTestId.testID,
|
|
493
|
+
type: byTestId.type,
|
|
494
|
+
text: byTestId.text,
|
|
495
|
+
absolutePosition: byTestId.absolutePosition,
|
|
496
|
+
layout: byTestId.layout,
|
|
497
|
+
},
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// text fallback. findByText returns null when there are
|
|
501
|
+
// 0 or 2+ matches \u2014 to disambiguate we'd send the user
|
|
502
|
+
// back to tap-text with --nth, which is the right
|
|
503
|
+
// failure mode.
|
|
504
|
+
const byText = await t.findByText(${o})
|
|
505
|
+
if (byText && byText.absolutePosition && byText.layout) {
|
|
506
|
+
return {
|
|
507
|
+
strategy: 'text',
|
|
508
|
+
node: {
|
|
509
|
+
nodeId: byText.nodeId ?? null,
|
|
510
|
+
id: byText.id,
|
|
511
|
+
testID: byText.testID,
|
|
512
|
+
type: byText.type,
|
|
513
|
+
text: byText.text,
|
|
514
|
+
absolutePosition: byText.absolutePosition,
|
|
515
|
+
layout: byText.layout,
|
|
516
|
+
},
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return { strategy: 'none' }
|
|
520
|
+
})()`});"error"in s&&(console.error(` ${s.error}`),process.exit(1)),s.strategy==="none"&&(console.error(` tap-best: no testID or visible text matched "${e}". try \`sootsim find --interactive-targets\` to list candidates.`),process.exit(1));let r=s.node,n=r.absolutePosition.x+r.layout.width/2,m=r.absolutePosition.y+r.layout.height/2,p=await c.send({type:"tap",x:n,y:m});if(p?.hit!==!1&&p?.ok!==!1){let y=ve(e,{id:r.id,testID:r.testID,type:r.type,cx:n,cy:m},s.strategy==="testid"?"id":"text");await j("inspect tap-best",y.step,y.summary)}console.log(JSON.stringify({matched:{strategy:s.strategy,nodeId:r.nodeId,id:r.id,testID:r.testID,type:r.type,text:r.text},tapped:{cx:n,cy:m},result:p},null,2));break}case"tap-id":{let e=i[1];e||(console.error(S("tap-id","<id>")),process.exit(1));let o=JSON.stringify(e),s=await c.send({type:"evaluate",code:`(async () => {
|
|
521
|
+
const t = window.__sootsimTest
|
|
522
|
+
if (!t) return null
|
|
523
|
+
const n = (await t.findByTestId(${o})) || (await t.findById(${o}))
|
|
524
|
+
if (!n || !n.absolutePosition || !n.layout) return { cx: null }
|
|
525
|
+
const resolved =
|
|
526
|
+
typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
|
|
527
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
528
|
+
: null
|
|
529
|
+
const target = (resolved && resolved.target) || n
|
|
530
|
+
const cx =
|
|
531
|
+
resolved && typeof resolved.cx === 'number'
|
|
532
|
+
? resolved.cx
|
|
533
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
534
|
+
const cy =
|
|
535
|
+
resolved && typeof resolved.cy === 'number'
|
|
536
|
+
? resolved.cy
|
|
537
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
538
|
+
return {
|
|
539
|
+
cx,
|
|
540
|
+
cy,
|
|
541
|
+
match: {
|
|
542
|
+
nodeId: n.nodeId ?? null,
|
|
543
|
+
id: n.id,
|
|
544
|
+
testID: n.testID,
|
|
545
|
+
type: n.type,
|
|
546
|
+
},
|
|
547
|
+
target: {
|
|
548
|
+
nodeId: target.nodeId ?? null,
|
|
549
|
+
id: target.id,
|
|
550
|
+
testID: target.testID,
|
|
551
|
+
type: target.type,
|
|
552
|
+
},
|
|
553
|
+
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
554
|
+
}
|
|
555
|
+
})()`});(!s||typeof s.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1));let r=await c.send({type:"tap",x:s.cx,y:s.cy});if(r?.hit!==!1&&r?.ok!==!1){let n=ve(e,{id:s.target?.id??null,testID:s.target?.testID??null,type:s.target?.type??null,cx:s.cx,cy:s.cy},"id");await j("inspect tap-id",n.step,n.summary)}console.log(JSON.stringify({matched:s.match,tapped:{nodeId:s.target?.nodeId??null,id:s.target?.id??null,testID:s.target?.testID??null,type:s.target?.type??null,cx:s.cx,cy:s.cy},...s.strategy&&s.strategy!=="matched-node"?{strategy:s.strategy}:{},result:r},null,2));break}case"type-into":{let e=i[1],o=i.slice(2).join(" ");(!e||!o)&&(console.error(S("type-into","<id> <text>")),process.exit(1));let s=JSON.stringify(e),r=await c.send({type:"evaluate",code:`(async () => {
|
|
556
|
+
const t = window.__sootsimTest
|
|
557
|
+
if (!t) return null
|
|
558
|
+
const n = await (t.findByTestId(${s}) || t.findById(${s}))
|
|
559
|
+
if (!n || !n.absolutePosition || !n.layout) return null
|
|
560
|
+
return {
|
|
561
|
+
cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
|
|
562
|
+
cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
|
|
563
|
+
testID: n.testID,
|
|
564
|
+
isTextInput: !!n.isTextInput,
|
|
565
|
+
placeholder: n.placeholder || null,
|
|
566
|
+
}
|
|
567
|
+
})()`});(!r||typeof r.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1)),r.isTextInput||console.error(` warning: ${e} is not a text input (isTextInput: false)`);let n=await c.send({type:"tap",x:r.cx,y:r.cy}),m=await zt(c);m.visible||(console.error(` keyboard did not open after tapping ${e}`),process.exit(1));let p=m.focusedInput;p&&(p.testID===e||p.id===e||(console.error(` focus routing mismatch after tap: requested ${JSON.stringify(e)} but focus is on ${JSON.stringify(p.testID??p.id??null)}. did the tap land on an outer Pressable wrapper?`),process.exit(1))),await c.send({type:"keyboard",action:"type",text:o}),await j("inspect type-into",{tapOn:{id:e},inputText:o},`type-into #${e} ${JSON.stringify(o)}`),console.log(JSON.stringify({target:e,isTextInput:r.isTextInput,keyboardOpened:m.visible??n?.keyboardOpened??!1,focusedInput:m.focusedInput??null,typed:o},null,2));break}case"type":{let e=i.slice(1).join(" ");e||(console.error(S("type","<text>")),process.exit(1)),await fe(c,"type"),await c.send({type:"keyboard",action:"type",text:e}),await j("inspect type",{inputText:e},`type ${JSON.stringify(e)}`),console.log(` typed: ${JSON.stringify(e)}`);break}case"key":{let e=i[1];e||(console.error(S("key","<name>")),process.exit(1)),await fe(c,"key"),await c.send({type:"keyboard",action:"press",text:e}),await j("inspect key",{pressKey:e},`key ${e}`),console.log(` pressed: ${e}`);break}case"key-sequence":{let e=i.slice(1);e.length===0&&(console.error(S("key-sequence","<key> [<key> ...]")),process.exit(1)),await fe(c,"key-sequence");for(let o of e)await c.send({type:"keyboard",action:"press",text:o});await j("inspect key-sequence",{pressKey:e.join(" ")},`key-sequence ${e.join(" ")}`),console.log(` pressed: ${e.join(", ")}`);break}case"keycode":{let e=i.slice(1);e.length===0&&(console.error(S("keycode","<code> [<code> ...]")),process.exit(1));let o=e.map(r=>({code:r,key:Ut(r)})),s=o.filter(r=>!r.key);s.length>0&&(console.error(` unsupported keycode(s): ${s.map(r=>r.code).join(", ")}`),process.exit(1)),await fe(c,"keycode");for(let r of o)await c.send({type:"keyboard",action:"press",text:r.key});await j("inspect keycode",{pressKey:o.map(r=>r.key).join(" ")},`keycode ${e.join(" ")}`),console.log(` pressed: ${e.join(", ")}`);break}case"dispatch":{let e=i[1];e||(console.error(S("dispatch","<char>")),process.exit(1)),await c.send({type:"keyboard",action:"dispatchKey",text:e}),await j("inspect dispatch",{dispatchKey:e},`dispatch ${JSON.stringify(e)}`),console.log(` dispatched: ${e}`);break}case"dismiss":{await c.send({type:"keyboard",action:"dismiss"}),await j("inspect dismiss",{hideKeyboard:!0},"dismiss keyboard"),console.log(" keyboard dismissed");break}case"double-tap":{let e=Number(i[1]),o=Number(i[2]),s=ie(t);if(s){let p=await ue(c,s);p||(console.error(` not found: ${s.value}`),s.mode==="testid"&&G("wait-selector-for-missing-testid",s.value),process.exit(1)),e=p.x,o=p.y}let r=i[3]?Number(i[3]):80;(!Number.isFinite(e)||!Number.isFinite(o)||!Number.isFinite(r))&&(console.error(S("double-tap","<x> <y> [gapMs] | --testid <id>")),process.exit(1));let n=Math.max(0,Math.round(r)),m=await c.send({type:"evaluate",code:`(async () => {
|
|
568
|
+
const interact = window.__sootsimInteract
|
|
569
|
+
if (interact?.doubleTap) {
|
|
570
|
+
return {
|
|
571
|
+
ok: !!(await interact.doubleTap(${e}, ${o}, ${n})),
|
|
572
|
+
gapMs: ${n},
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (!interact?.tap) {
|
|
576
|
+
return { ok: false, reason: 'no interact.tap', gapMs: ${n} }
|
|
577
|
+
}
|
|
578
|
+
const first = await interact.tap(${e}, ${o})
|
|
579
|
+
if (!first || first.hit === false) {
|
|
580
|
+
return { ok: false, reason: 'first tap missed', gapMs: ${n}, first }
|
|
581
|
+
}
|
|
582
|
+
await new Promise((resolve) => setTimeout(resolve, ${n}))
|
|
583
|
+
const second = await interact.tap(${e}, ${o})
|
|
584
|
+
return {
|
|
585
|
+
ok: !!second && second.hit !== false,
|
|
586
|
+
gapMs: ${n},
|
|
587
|
+
first,
|
|
588
|
+
second,
|
|
589
|
+
}
|
|
590
|
+
})()`});m?.ok&&await j("inspect double-tap",{doubleTapAtCoords:{x:e,y:o,gapMs:n}},`double-tap @${e},${o}`),console.log(JSON.stringify(m,null,2));break}case"long-press":{let e=Number(i[1]),o=Number(i[2]),s=ie(t);if(s){let m=await ue(c,s);m||(console.error(` not found: ${s.value}`),s.mode==="testid"&&G("wait-selector-for-missing-testid",s.value),process.exit(1)),e=m.x,o=m.y}let r=i[3]?Number(i[3]):600;(!Number.isFinite(e)||!Number.isFinite(o)||!Number.isFinite(r))&&(console.error(S("long-press","<x> <y> [durationMs] | --testid <id>")),process.exit(1));let n=await c.send({type:"evaluate",code:`(async () => {
|
|
591
|
+
const interact = window.__sootsimInteract
|
|
592
|
+
if (!interact?.longPress) return { ok: false, reason: 'no interact.longPress' }
|
|
593
|
+
const value = await interact.longPress(${e}, ${o}, ${Math.max(0,Math.round(r))})
|
|
594
|
+
return { ok: !!value, value }
|
|
595
|
+
})()`});n?.ok&&await j("inspect long-press",{tapAtCoords:{x:e,y:o}},`long-press @${e},${o}`),console.log(JSON.stringify(n,null,2));break}case"touch":{let e=i[1],o=Number(i[2]),s=Number(i[3]),r=i[4]?Number(i[4]):999,n=e==="down"?"touchDown":e==="move"?"touchMove":e==="up"?"touchUp":e==="cancel"?"touchCancel":null;n||(console.error(S("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1)),e!=="cancel"&&(!Number.isFinite(o)||!Number.isFinite(s))&&(console.error(S("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1));let m=e==="down"?"tap":e==="move"?"move":null,p=m&&Number.isFinite(o)&&Number.isFinite(s)?`window.dispatchEvent(new CustomEvent('sootsim:agentAction', { detail: { type: '${m}', x: ${o}, y: ${s} } }));`:"",y=await c.send({type:"evaluate",code:`(async () => {
|
|
596
|
+
${p}
|
|
597
|
+
const interact = window.__sootsimInteract
|
|
598
|
+
if (!interact?.${n}) return { ok: false, reason: 'no interact.${n}' }
|
|
599
|
+
const value = ${e==="cancel"?`await interact.${n}(${Math.max(1,Math.round(r))})`:`await interact.${n}(${o}, ${s}, ${Math.max(1,Math.round(r))})`}
|
|
600
|
+
return { ok: !!value, value }
|
|
601
|
+
})()`});y?.ok&&e!=="cancel"&&await j("inspect touch",{tapAtCoords:{x:o,y:s}},`touch ${e} @${o},${s}`),console.log(JSON.stringify(y,null,2));break}case"gesture":{let e=i[1],o=i[2]?Number(i[2]):220;(!e||!Number.isFinite(o))&&(console.error(S("gesture","<preset> [durationMs]")),process.exit(1));let s=await c.send({type:"evaluate",code:`(async () => {
|
|
602
|
+
const spec = globalThis.__sootsimDeviceSpec || {}
|
|
603
|
+
return {
|
|
604
|
+
width: spec.width || window.innerWidth || 393,
|
|
605
|
+
height: spec.height || window.innerHeight || 852,
|
|
606
|
+
statusBarHeight: spec.statusBarHeight || 0,
|
|
607
|
+
homeIndicatorHeight: spec.homeIndicatorHeight || 0,
|
|
608
|
+
}
|
|
609
|
+
})()`}),r=Number(s?.width)||393,n=Number(s?.height)||852,m=Number(s?.statusBarHeight)||0,p=Number(s?.homeIndicatorHeight)||0,y=Math.round(r/2),g=Math.round(n/2),x=Math.max(24,m+18),R=Math.max(24,p+18),q=18,z=Math.min(220,Math.round(n*.24)),U=Math.min(180,Math.round(r*.32)),M=y,v=g,f=y,T=g;switch(e){case"scroll-up":v=g+Math.round(z/2),T=g-Math.round(z/2);break;case"scroll-down":v=g-Math.round(z/2),T=g+Math.round(z/2);break;case"scroll-left":M=y+Math.round(U/2),f=y-Math.round(U/2);break;case"scroll-right":M=y-Math.round(U/2),f=y+Math.round(U/2);break;case"swipe-from-left-edge":M=q,v=g,f=Math.min(r-q,q+U);break;case"swipe-from-right-edge":M=r-q,v=g,f=Math.max(q,r-q-U);break;case"swipe-from-top-edge":M=y,v=x,T=Math.min(n-R,x+z);break;case"swipe-from-bottom-edge":M=y,v=n-R,T=Math.max(x,n-R-z);break;default:console.error(` unknown gesture preset: ${e}`),process.exit(1)}let P=Math.max(8,Math.round(o/16)),A=Math.max(1,Math.round(o/P)),ae=await c.send({type:"evaluate",code:`(async () => {
|
|
610
|
+
const interact = window.__sootsimInteract
|
|
611
|
+
if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
|
|
612
|
+
const value = await interact.drag(${M}, ${v}, ${f}, ${T}, ${P}, ${A})
|
|
613
|
+
return { ok: !!value, value }
|
|
614
|
+
})()`});ae?.ok&&await j("inspect gesture",{swipe:{start:`${M}, ${v}`,end:`${f}, ${T}`,duration:Math.max(1,Math.round(o))}},`gesture ${e}`),console.log(JSON.stringify({preset:e,from:{x:M,y:v},to:{x:f,y:T},result:ae},null,2));break}case"scroll":{let e=ie(t),o=e?.mode==="testid"?e.value:i[1],s=Number(i[e?1:2]),r=Number(i[e?2:3]);(!o||!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(S("scroll","<id> <dx> <dy> | --testid <id> <dx> <dy>")),process.exit(1));let n=await c.send({type:"evaluate",code:`(async () => {
|
|
615
|
+
const t = window.__sootsimTest
|
|
616
|
+
if (!t) return null
|
|
617
|
+
const n = await t.findByTestId(${JSON.stringify(o)})
|
|
618
|
+
|| await t.findById(${JSON.stringify(o)})
|
|
619
|
+
if (!n || !n.absolutePosition || !n.layout) return null
|
|
620
|
+
return {
|
|
621
|
+
cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
|
|
622
|
+
cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
|
|
623
|
+
}
|
|
624
|
+
})()`}),m=await K(c,"scrollTo",o,s,r,!1);m?.ok&&await j("inspect scroll",{scrollTo:{id:o,x:s,y:r}},`scroll ${o} -> ${s},${r}`),console.log(JSON.stringify({...m,...n?{at:{x:n.cx,y:n.cy}}:{}},null,2));break}case"state":{let e=i[1];if(a==="get"&&!e){let s=await K(c,"getRuntimeState"),r=await c.send({type:"evaluate",code:`({
|
|
625
|
+
errors: window.__sootsimConsole?.getErrors?.()?.length ?? 0,
|
|
626
|
+
warnings: window.__sootsimConsole?.getWarnings?.()?.length ?? 0,
|
|
627
|
+
})`});s&&typeof s=="object"&&s.diagnostics&&(s.diagnostics.errors=r?.errors??0,s.diagnostics.warnings=r?.warnings??0),console.log(JSON.stringify(s,null,2));break}if(!e||e==="--help"||e==="-h"){console.log(`
|
|
628
|
+
${h("state")} \u2014 dump raw runtime state
|
|
629
|
+
|
|
630
|
+
subcommands:
|
|
631
|
+
shell dump shell transition/layout state
|
|
632
|
+
worker dump render-worker host/animation state
|
|
633
|
+
keyboard dump keyboard visibility, mode, and focused input
|
|
634
|
+
ownership dump surface ownership + pointerOnSurface delivery stats
|
|
635
|
+
node <id> dump raw node info by id or testID
|
|
636
|
+
scroll <id> dump scroll metrics and runtime state
|
|
637
|
+
scroll-hit <x> <y> dump the nearest scroll ancestor at coordinates
|
|
638
|
+
hit <x> <y> dump the hit-test ancestry at coordinates
|
|
639
|
+
gesture <x> <y> dump gesture routing/debug info at coordinates
|
|
640
|
+
|
|
641
|
+
examples:
|
|
642
|
+
${h("state")} shell
|
|
643
|
+
${h("state")} worker
|
|
644
|
+
${h("state")} keyboard
|
|
645
|
+
${h("state")} ownership
|
|
646
|
+
${h("state")} node photos
|
|
647
|
+
${h("state")} scroll feed
|
|
648
|
+
${h("state")} scroll-hit 360 420
|
|
649
|
+
${h("state")} hit 200 720
|
|
650
|
+
`);break}let o;switch(e){case"shell":o=await oe(c,500);break;case"worker":o=await be(c,"__sootsimRenderHost.queryStats");break;case"ownership":o=await c.send({type:"evaluate",code:`(() => {
|
|
651
|
+
const h = window.__sootsimRenderHost
|
|
652
|
+
if (!h || typeof h.getOwnershipSnapshot !== 'function') {
|
|
653
|
+
return { error: 'getOwnershipSnapshot not available' }
|
|
654
|
+
}
|
|
655
|
+
return h.getOwnershipSnapshot()
|
|
656
|
+
})()`});break;case"keyboard":o=await c.send({type:"evaluate",code:`(async () => {
|
|
657
|
+
const kb = window.__sootsimKeyboard
|
|
658
|
+
const test = window.__sootsimTest
|
|
659
|
+
if (!kb) return { error: 'keyboard bridge not available' }
|
|
660
|
+
const layout = typeof kb.getLayout === 'function' ? kb.getLayout() : null
|
|
661
|
+
const visible = kb.isVisible()
|
|
662
|
+
const mode = kb.getMode()
|
|
663
|
+
let focused = null
|
|
664
|
+
if (test && typeof test.getFocusedNode === 'function') {
|
|
665
|
+
try {
|
|
666
|
+
focused = await test.getFocusedNode()
|
|
667
|
+
} catch {}
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
visible,
|
|
671
|
+
mode,
|
|
672
|
+
layout,
|
|
673
|
+
focusedInput: focused ? {
|
|
674
|
+
nodeId: focused.nodeId ?? null,
|
|
675
|
+
testID: focused.testID || null,
|
|
676
|
+
id: focused.id || null,
|
|
677
|
+
placeholder: focused.placeholder || null,
|
|
678
|
+
text: focused.text || null,
|
|
679
|
+
} : null,
|
|
680
|
+
}
|
|
681
|
+
})()`});break;case"node":{let s=i[2];s||(console.error(` usage: ${h("state")} node <id>`),process.exit(1)),o=await K(c,"findByTestId",s)||await K(c,"findById",s);break}case"scroll":{let s=i[2];s||(console.error(` usage: ${h("state")} scroll <id>`),process.exit(1)),o=await K(c,"getScrollState",s);break}case"scroll-hit":{let s=Number(i[2]),r=Number(i[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${h("state")} scroll-hit <x> <y>`),process.exit(1)),o=await K(c,"getScrollStateAt",s,r);break}case"hit":{let s=Number(i[2]),r=Number(i[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${h("state")} hit <x> <y>`),process.exit(1)),o=await K(c,"debugHitAt",s,r);break}case"gesture":{let s=Number(i[2]),r=Number(i[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${h("state")} gesture <x> <y>`),process.exit(1)),o=await K(c,"debugGestureAt",s,r);break}default:console.error(` unknown state subcommand: ${e}`),process.exit(1)}console.log(JSON.stringify(o,null,2));break}case"shell":{let e=i[1];if(!e||e==="--help"||e==="-h"){console.log(`
|
|
682
|
+
${h("shell")} \u2014 run built-in shell commands
|
|
683
|
+
|
|
684
|
+
subcommands:
|
|
685
|
+
launch <appId> [waitMs] [--clear-state]
|
|
686
|
+
launch app and wait for settled shell state
|
|
687
|
+
home [waitMs] go home and wait for settled shell state
|
|
688
|
+
switcher [waitMs] open switcher and wait for settled shell state
|
|
689
|
+
open-card <appId> [waitMs]
|
|
690
|
+
open a specific switcher card and wait for app settle
|
|
691
|
+
appearance <light|dark|auto|toggle>
|
|
692
|
+
update simulator appearance
|
|
693
|
+
lock toggle device lock state
|
|
694
|
+
shake trigger the simulator shake gesture
|
|
695
|
+
|
|
696
|
+
examples:
|
|
697
|
+
${h("shell")} launch photos
|
|
698
|
+
${h("shell")} launch rn --clear-state
|
|
699
|
+
${h("shell")} launch photos 1500
|
|
700
|
+
${h("shell")} home 500
|
|
701
|
+
${h("shell")} switcher 800
|
|
702
|
+
${h("shell")} open-card clock 800
|
|
703
|
+
${h("shell")} appearance dark
|
|
704
|
+
${h("shell")} lock
|
|
705
|
+
`);break}let o=e==="launch"||e==="open-card"||e==="home"||e==="switcher",s=e==="launch"||e==="open-card"?i[3]:i[2],r=s?Number(s):350;o&&(!Number.isFinite(r)||r<0)&&(console.error(S("shell",e==="launch"||e==="open-card"?"<launch|open-card> <appId> [settleMs]":"<home|switcher> [settleMs]")),process.exit(1));let n=!1,m=!1,p=null,y=t.includes("--clear-state");if(e==="launch"){let g=i[2];g||(console.error(S("shell","launch <appId> [settleMs] [--clear-state]")),process.exit(1)),y&&await c.send({type:"evaluate",code:Ae}),n=!!await ne(c,"launchApp",r,g),{settled:m,state:p}=await pe(c,Math.round(r),x=>!!x&&x.state==="app"&&x.activeApp===g&&x.showSwitcher===!1&&x.switcherPhase==="idle"&&typeof x.launchProgress=="number"&&x.launchProgress>=.98),n&&await j("inspect shell launch",y?{launchApp:{clearState:!0}}:{launchApp:{}},y?"launch app (clear state)":"launch app")}else if(e==="home")n=!!await ne(c,"goHome",r),{settled:m,state:p}=await pe(c,Math.round(r),g=>!!g&&g.state==="home"&&g.activeApp==null&&g.showSwitcher===!1&&g.switcherPhase==="idle"&&typeof g.launchProgress=="number"&&g.launchProgress>=.98);else if(e==="switcher")n=!!await ne(c,"openSwitcher",r),{settled:m,state:p}=await pe(c,Math.round(r),g=>!!g&&g.state==="app"&&g.showSwitcher===!0&&g.switcherPhase==="idle"&&typeof g.zoomLevel=="number"&&Math.abs(g.zoomLevel)<=.02&&typeof g.horizontalZoom=="number"&&Math.abs(g.horizontalZoom)<=.02),m&&(await X(Kt),p=await oe(c));else if(e==="open-card"){let g=i[2];g||(console.error(S("shell","open-card <appId> [settleMs]")),process.exit(1)),n=!!await ne(c,"openSwitcherCard",r,g),{settled:m,state:p}=await pe(c,Math.round(r),x=>!!x&&x.state==="app"&&x.activeApp===g&&x.showSwitcher===!1&&x.switcherPhase==="idle"&&typeof x.zoomLevel=="number"&&x.zoomLevel>=.98&&typeof x.horizontalZoom=="number"&&x.horizontalZoom>=.98),n&&await j("inspect shell open-card",{openSwitcherCard:{appId:g}},`open switcher card ${g}`)}else if(e==="appearance"){let g=i[2];(!g||!["light","dark","auto","toggle"].includes(g))&&(console.error(S("shell","appearance <light|dark|auto|toggle>")),process.exit(1));let x=await ft(c,"appearance",g);n=!!x?.ok,p={appearance:x}}else if(e==="lock"||e==="shake"){let g=await ft(c,e);n=!!g?.ok,p={[e]:g}}else console.error(` unknown shell subcommand: ${e}`),process.exit(1);console.log(JSON.stringify({ok:n,settled:m,state:p},null,2));break}case"url":{await st(c,{args:d});break}case"reload":{let s=!1,r=!1;try{await c.send({type:"evaluate",code:"window.__sootsimConsole?.clear()"});let p=await c.send({type:"evaluate",code:`;(() => {
|
|
706
|
+
const reloadExternalApp = window.SootSim?.bridges?.hotRemount?.reloadExternalApp
|
|
707
|
+
if (typeof reloadExternalApp === 'function') {
|
|
708
|
+
reloadExternalApp()
|
|
709
|
+
return { kind: 'external-app' }
|
|
710
|
+
}
|
|
711
|
+
window.location.reload()
|
|
712
|
+
return { kind: 'page' }
|
|
713
|
+
})()`});r=!!p&&p.kind==="external-app",s=!0}catch{}console.log(" reloading...");let n=c,m=null;if(r)m=await he(c,{timeoutMs:1e4,errorGraceMs:3e3});else{s&&await X(300);let p=await De(F,C,I,{timeoutMs:1e4});p?(n=p,m=await he(p,{timeoutMs:1e4,errorGraceMs:3e3})):(console.log(" \u26A0 reload: bridge never reconnected within 10000ms"),n=null)}if(m)if(m.ready){let p=m.source==="nodes-fallback"?" (no ready signal, node-count fallback)":"";console.log(` ready in ${m.elapsedMs}ms: ${m.nodes} nodes${p}`)}else m.source==="error-bail"?console.log(` \u26A0 reload bailed after ${m.elapsedMs}ms: ${m.errors} console error(s), ready signal never fired`):console.log(` \u26A0 reload timed out after ${m.elapsedMs}ms (${m.nodes} nodes, ${m.errors} errors)`);if(n)try{let p=await n.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors(10) || []"});if(n!==c&&n.close(),Array.isArray(p)&&p.length>0){console.log(`
|
|
714
|
+
\u26A0 ${p.length} error(s) during mount:
|
|
715
|
+
`);for(let y of p){let g=y.args.map(x=>typeof x=="object"?JSON.stringify(x):x).join(" ");if(console.log(` ${g}`),y.stack){let x=y.stack.split(`
|
|
716
|
+
`).slice(0,2);for(let R of x)console.log(` ${R.trim()}`)}}}}catch{}m&&!m.ready&&(process.exitCode=1);break}case"eval":case"js":{let e=i.slice(1).join(" ");e||(console.error(S("js","<javascript>")),console.error(""),console.error(" runs the snippet in the engine realm. SootSim is the"),console.error(" canonical state surface \u2014 reach into it directly."),console.error(""),console.error(" examples:"),console.error(` ${h("js")} SootSim.bridges.test.findByText("Sign in")`),console.error(` ${h("js")} SootSim.bridges.debug.snapshot("before")`),console.error(` ${h("js")} SootSim.bridges.keyboard.type("hello")`),console.error(` ${h("js")} SootSim.state.root.children.length`),process.exit(1));let o=e;o.startsWith("(async")||(o=`(async () => ${o})()`);let s=await c.send({type:"evaluate",code:o});console.log(JSON.stringify(s,null,2));let r=e.toLowerCase(),n=[];(r.includes("sootsim:gohome")||r.includes("gohome"))&&n.push("sootsim shell home"),(r.includes("sootsim:appswitcher")||r.includes("appswitcher"))&&n.push("sootsim shell switcher"),(r.includes("keyboard.isvisible")||r.includes("keyboard.getmode"))&&n.push("sootsim debug state keyboard"),r.includes("interact.tap")&&n.push("sootsim do tap <x> <y>"),r.includes("keyboard.type")&&n.push("sootsim do type <text>"),(r.includes("keyboard.press")||r.includes("keyboard.dispatchkey"))&&n.push("sootsim do key <name>"),r.includes("keyboard.dismiss")&&n.push("sootsim do dismiss"),r.includes("dumptree")&&n.push("sootsim get tree"),r.includes("dumpaccessibilitytree")&&n.push("sootsim get a11y"),r.includes("getnodecount")&&n.push("sootsim get count"),r.includes("findbytext")&&n.push("sootsim find <text>"),(r.includes("findbytestid")||r.includes("findbyid"))&&n.push("sootsim find --testid <id>"),r.includes("document.hidden")&&n.push("sootsim debug state keyboard (includes tab health)"),n.length>0&&G("prefer-cli-over-eval",n);break}case"globals":{let e=await c.send({type:"evaluate",code:`(async () => {
|
|
717
|
+
const globals = {}
|
|
718
|
+
|
|
719
|
+
// test bridge (proxy in worker mode)
|
|
720
|
+
const testMethods = [
|
|
721
|
+
'findById', 'findByTestId', 'findByText', 'findByLabel', 'findByRole',
|
|
722
|
+
'findAllByRole', 'findByA11yState', 'findAllByA11yState', 'findByHint',
|
|
723
|
+
'findPressable', 'getStyle', 'getLayout', 'getAbsolutePosition', 'isVisible',
|
|
724
|
+
'queryAll', 'dumpTree', 'dumpAccessibilityTree', 'getNodeCount', 'getShellState',
|
|
725
|
+
'getScrollState', 'getScrollStateAt', 'scrollTo', 'waitForTree',
|
|
726
|
+
'waitForScreenTransitions', 'debugByText', 'debugByTestId', 'debugHitAt',
|
|
727
|
+
'debugGestureAt'
|
|
728
|
+
]
|
|
729
|
+
globals['test (\u2192 __sootsimTest)'] = testMethods
|
|
730
|
+
|
|
731
|
+
// debug
|
|
732
|
+
if (window.__sootsimDebug) {
|
|
733
|
+
globals['debug (\u2192 __sootsimDebug)'] = Object.keys(window.__sootsimDebug)
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// interact
|
|
737
|
+
if (window.__sootsimInteract) {
|
|
738
|
+
globals['interact (\u2192 __sootsimInteract)'] = Object.keys(window.__sootsimInteract)
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// keyboard
|
|
742
|
+
if (window.__sootsimKeyboard) {
|
|
743
|
+
globals['keyboard (\u2192 __sootsimKeyboard)'] = Object.keys(window.__sootsimKeyboard)
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// other globals
|
|
747
|
+
globals['other'] = [
|
|
748
|
+
'root (\u2192 __sootsimRoot) - live node tree',
|
|
749
|
+
'render() (\u2192 __sootsimForceRender) - force re-render'
|
|
750
|
+
]
|
|
751
|
+
|
|
752
|
+
return globals
|
|
753
|
+
})()`});console.log(` sootsim JS API:
|
|
754
|
+
`);for(let[o,s]of Object.entries(e)){console.log(` ${o}:`);for(let r of s)console.log(` .${r}`);console.log("")}console.log(` use: ${h("js")} <expression>`),console.log(` example: ${h("js")} test.findByText("Sign in")`);break}case"describe":{await qe({bridge:c,args:t,positional:i});break}case"perf":{let e=i[1];if(!e||e==="--help"||e==="-h"){console.log(`
|
|
755
|
+
${h("perf")} \u2014 performance profiling
|
|
756
|
+
|
|
757
|
+
subcommands:
|
|
758
|
+
stats one-shot stats (zero overhead query)
|
|
759
|
+
start begin recording frame times
|
|
760
|
+
stop stop recording and report results
|
|
761
|
+
frames [n] get last N frame times (default: 50)
|
|
762
|
+
transition <e> profile a shell transition (goHome, appSwitcher, lockScreen)
|
|
763
|
+
|
|
764
|
+
examples:
|
|
765
|
+
${h("perf")} stats
|
|
766
|
+
${h("perf")} start
|
|
767
|
+
# ... interact with the app ...
|
|
768
|
+
${h("perf")} stop
|
|
769
|
+
${h("perf")} transition goHome
|
|
770
|
+
`);break}switch(e){case"stats":{let o=await c.send({type:"evaluate",code:`(async () => {
|
|
771
|
+
// worker mode (host exposes these)
|
|
772
|
+
if (window.__sootsimPerfStats) {
|
|
773
|
+
return await window.__sootsimPerfStats()
|
|
774
|
+
}
|
|
775
|
+
// main-thread mode
|
|
776
|
+
const perf = window.__sootsimPerf
|
|
777
|
+
const a11y = window.__sootsimA11y
|
|
778
|
+
if (!perf && !a11y) return { error: 'no perf globals available' }
|
|
779
|
+
|
|
780
|
+
const frameStats = perf?.getFrameStats?.() || {}
|
|
781
|
+
const profile = a11y?.profile?.() || {}
|
|
782
|
+
const nodeCount = await window.__sootsimTest?.getNodeCount?.() || 0
|
|
783
|
+
|
|
784
|
+
return {
|
|
785
|
+
frames: frameStats.frames || profile.syncCount || 0,
|
|
786
|
+
avgMs: frameStats.totalMs && frameStats.frames
|
|
787
|
+
? (frameStats.totalMs / frameStats.frames).toFixed(2)
|
|
788
|
+
: profile.avgSyncMs?.toFixed(2) || '?',
|
|
789
|
+
maxMs: frameStats.maxMs?.toFixed(2) || profile.maxSyncMs?.toFixed(2) || '?',
|
|
790
|
+
layoutMs: frameStats.layoutTotalMs?.toFixed(2) || '?',
|
|
791
|
+
nodeCount,
|
|
792
|
+
jankFrames: frameStats.recentFrames?.filter(f => f > 16.67).length || 0,
|
|
793
|
+
recentCount: frameStats.recentFrames?.length || 0,
|
|
794
|
+
}
|
|
795
|
+
})()`});o.error&&(console.error(` error: ${o.error}`),process.exit(1));let s=o.avgMs!=="?"?(1e3/parseFloat(o.avgMs)).toFixed(1):"?";console.log(" perf stats:"),console.log(` frames: ${o.frames}`),console.log(` avg: ${o.avgMs}ms (${s} fps)`),console.log(` max: ${o.maxMs}ms`),console.log(` layout: ${o.layoutMs}ms total`),console.log(` nodes: ${o.nodeCount}`),o.recentCount>0&&console.log(` jank: ${o.jankFrames}/${o.recentCount} frames >16.67ms`);break}case"start":{await c.send({type:"evaluate",code:`(async () => {
|
|
796
|
+
// worker mode
|
|
797
|
+
if (window.__sootsimPerfStart && window.__sootsimRenderHost) {
|
|
798
|
+
const result = window.__sootsimPerfStart()
|
|
799
|
+
window.${Q} = {
|
|
800
|
+
active: true,
|
|
801
|
+
mode: 'render-worker',
|
|
802
|
+
lastSamples: [],
|
|
803
|
+
startedAt: performance.now(),
|
|
804
|
+
}
|
|
805
|
+
return result
|
|
806
|
+
}
|
|
807
|
+
// main-thread mode
|
|
808
|
+
window.__sootsimPerf?.enableFrameStats?.(true)
|
|
809
|
+
window.__sootsimA11y?.resetProfile?.()
|
|
810
|
+
window.${Q} = {
|
|
811
|
+
active: true,
|
|
812
|
+
mode: 'main-thread',
|
|
813
|
+
lastSamples: [],
|
|
814
|
+
startedAt: performance.now(),
|
|
815
|
+
}
|
|
816
|
+
return { started: true }
|
|
817
|
+
})()`}),console.log(` profiling started \u2014 interact with the app, then run '${h("perf")} stop'`);break}case"stop":{let o=await c.send({type:"evaluate",code:`(async () => {
|
|
818
|
+
// worker mode
|
|
819
|
+
if (window.__sootsimRenderHost) {
|
|
820
|
+
const session = window.${Q} || {}
|
|
821
|
+
const priorSamples = session.active && Array.isArray(session.lastSamples)
|
|
822
|
+
? session.lastSamples
|
|
823
|
+
: []
|
|
824
|
+
const flushedSamples = await window.__sootsimRenderHost.flushSamples()
|
|
825
|
+
const samples = priorSamples.concat(flushedSamples)
|
|
826
|
+
window.${Q} = {
|
|
827
|
+
...session,
|
|
828
|
+
active: false,
|
|
829
|
+
mode: 'render-worker',
|
|
830
|
+
lastSamples: samples,
|
|
831
|
+
stoppedAt: performance.now(),
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
const frameTimes = samples.map(sample => sample[1])
|
|
835
|
+
const layoutTimes = samples.map(sample => sample[2])
|
|
836
|
+
const renderTimes = samples.map(sample => sample[3])
|
|
837
|
+
const copyTimes = samples.map(sample => sample[4])
|
|
838
|
+
const auxTimes = samples.map(sample => sample[5] || 0)
|
|
839
|
+
const otherTimes = samples.map(sample => sample[6] || 0)
|
|
840
|
+
const sorted = [...frameTimes].sort((a, b) => a - b)
|
|
841
|
+
const total = frameTimes.reduce((a, b) => a + b, 0)
|
|
842
|
+
const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
|
|
843
|
+
const max = Math.max(...frameTimes, 0)
|
|
844
|
+
const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
|
|
845
|
+
const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
|
|
846
|
+
const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
|
|
847
|
+
const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
|
|
848
|
+
const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
|
|
849
|
+
|
|
850
|
+
return {
|
|
851
|
+
mode: 'render-worker',
|
|
852
|
+
frames: frameTimes.length,
|
|
853
|
+
totalMs: total,
|
|
854
|
+
avgMs: avg,
|
|
855
|
+
maxMs: max,
|
|
856
|
+
layoutTotalMs: layoutTotal,
|
|
857
|
+
renderTotalMs: renderTotal,
|
|
858
|
+
copyTotalMs: copyTotal,
|
|
859
|
+
auxTotalMs: auxTotal,
|
|
860
|
+
otherTotalMs: otherTotal,
|
|
861
|
+
layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
|
|
862
|
+
renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
|
|
863
|
+
copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
|
|
864
|
+
auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
|
|
865
|
+
otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
|
|
866
|
+
p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
|
|
867
|
+
p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
|
|
868
|
+
p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
|
|
869
|
+
jankFrames: frameTimes.filter((f) => f > 16.67).length,
|
|
870
|
+
sampleCount: frameTimes.length,
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
// main-thread mode
|
|
874
|
+
const perf = window.__sootsimPerf
|
|
875
|
+
const a11y = window.__sootsimA11y
|
|
876
|
+
if (!perf && !a11y) return { error: 'no perf globals' }
|
|
877
|
+
|
|
878
|
+
const frameStats = perf?.getFrameStats?.() || {}
|
|
879
|
+
const profile = a11y?.profile?.() || {}
|
|
880
|
+
|
|
881
|
+
// calculate distribution
|
|
882
|
+
const recent = frameStats.recentFrames || []
|
|
883
|
+
const sorted = [...recent].sort((a, b) => a - b)
|
|
884
|
+
const p50 = sorted[Math.floor(sorted.length * 0.5)] || 0
|
|
885
|
+
const p95 = sorted[Math.floor(sorted.length * 0.95)] || 0
|
|
886
|
+
const p99 = sorted[Math.floor(sorted.length * 0.99)] || 0
|
|
887
|
+
|
|
888
|
+
// disable collection
|
|
889
|
+
perf?.disableFrameStats?.()
|
|
890
|
+
window.${Q} = {
|
|
891
|
+
...(window.${Q} || {}),
|
|
892
|
+
active: false,
|
|
893
|
+
mode: 'main-thread',
|
|
894
|
+
lastSamples: recent.map((ms, index) => [index, ms, 0, 0, 0, 0, 0]),
|
|
895
|
+
stoppedAt: performance.now(),
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
return {
|
|
899
|
+
mode: 'main-thread',
|
|
900
|
+
frames: frameStats.frames || profile.syncCount || 0,
|
|
901
|
+
totalMs: frameStats.totalMs || 0,
|
|
902
|
+
avgMs: frameStats.totalMs && frameStats.frames
|
|
903
|
+
? frameStats.totalMs / frameStats.frames
|
|
904
|
+
: profile.avgSyncMs || 0,
|
|
905
|
+
maxMs: frameStats.maxMs || profile.maxSyncMs || 0,
|
|
906
|
+
layoutTotalMs: frameStats.layoutTotalMs || 0,
|
|
907
|
+
p50, p95, p99,
|
|
908
|
+
jankFrames: recent.filter(f => f > 16.67).length,
|
|
909
|
+
sampleCount: recent.length,
|
|
910
|
+
}
|
|
911
|
+
})()`});o.error&&(console.error(` error: ${o.error}`),process.exit(1));let s=o.avgMs>0?(1e3/o.avgMs).toFixed(1):"?",r=o.sampleCount>0?(o.jankFrames/o.sampleCount*100).toFixed(1):"0";console.log(` profiling stopped:
|
|
912
|
+
`),console.log(` frames: ${o.frames}`),console.log(` total: ${o.totalMs.toFixed(1)}ms`),console.log(` avg: ${o.avgMs.toFixed(2)}ms (${s} fps)`),console.log(` max: ${o.maxMs.toFixed(2)}ms`),console.log(""),o.layoutAvgMs!==void 0&&(console.log(" breakdown (avg per frame):"),console.log(` layout: ${o.layoutAvgMs.toFixed(2)}ms`),console.log(` render: ${o.renderAvgMs.toFixed(2)}ms`),console.log(` copy: ${o.copyAvgMs.toFixed(2)}ms`),o.auxAvgMs!==void 0&&console.log(` aux: ${o.auxAvgMs.toFixed(2)}ms`),o.otherAvgMs!==void 0&&console.log(` other: ${o.otherAvgMs.toFixed(2)}ms`),console.log("")),console.log(` distribution (${o.sampleCount} samples):`),console.log(` p50: ${o.p50.toFixed(2)}ms`),console.log(` p95: ${o.p95.toFixed(2)}ms`),console.log(` p99: ${o.p99.toFixed(2)}ms`),console.log(` jank: ${o.jankFrames} frames (${r}%) >16.67ms`);break}case"frames":{let o=i[2]?Number(i[2]):50;(!Number.isFinite(o)||o<=0)&&(console.error(` error: expected a positive frame count, got "${i[2]}"`),process.exit(1));let s=await c.send({type:"evaluate",code:`(async () => {
|
|
913
|
+
if (window.__sootsimRenderHost) {
|
|
914
|
+
const session = window.${Q} || {}
|
|
915
|
+
if (session.active) {
|
|
916
|
+
const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
|
|
917
|
+
const flushedSamples = await window.__sootsimRenderHost.flushSamples()
|
|
918
|
+
const samples = priorSamples.concat(flushedSamples)
|
|
919
|
+
window.__sootsimRenderHost.startSampling()
|
|
920
|
+
window.${Q} = {
|
|
921
|
+
...session,
|
|
922
|
+
active: true,
|
|
923
|
+
mode: 'render-worker',
|
|
924
|
+
lastSamples: samples,
|
|
925
|
+
lastFlushAt: performance.now(),
|
|
926
|
+
}
|
|
927
|
+
return {
|
|
928
|
+
mode: 'render-worker',
|
|
929
|
+
live: true,
|
|
930
|
+
samples: samples.slice(-${o}),
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return {
|
|
934
|
+
mode: 'render-worker',
|
|
935
|
+
live: false,
|
|
936
|
+
samples: (session.lastSamples || []).slice(-${o}),
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
// main-thread mode
|
|
940
|
+
const perf = window.__sootsimPerf
|
|
941
|
+
if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
|
|
942
|
+
const stats = perf.getFrameStats?.() || {}
|
|
943
|
+
return {
|
|
944
|
+
mode: 'main-thread',
|
|
945
|
+
frames: (stats.recentFrames || []).slice(-${o}),
|
|
946
|
+
}
|
|
947
|
+
})()`});if(s.error&&(console.error(` error: ${s.error}`),process.exit(1)),s.mode==="render-worker"){let n=Array.isArray(s.samples)?s.samples:[];if(n.length===0){console.log(` no frame data \u2014 run '${h("perf")} start' first`);break}console.log(` last ${n.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[m,p,y,g,x,R,q]of n)console.log(` ${p.toFixed(2).padStart(7)} ${y.toFixed(2).padStart(7)} ${g.toFixed(2).padStart(7)} ${x.toFixed(2).padStart(7)} ${R.toFixed(2).padStart(6)} ${q.toFixed(2).padStart(7)} ${String(m).padStart(5)}`);console.log(""),Se(n.map(m=>m[1])),s.live&&console.log(" sampling continues");break}let r=Array.isArray(s.frames)?s.frames:Array.isArray(s)?s:[];if(r.length===0){console.log(` no frame data \u2014 run '${h("perf")} start' first`);break}console.log(` last ${r.length} frame times (ms):`),console.log(` ${r.map(n=>n.toFixed(2)).join(", ")}`),Se(r);break}case"worst":{let o=i[2]?Number(i[2]):20;(!Number.isFinite(o)||o<=0)&&(console.error(` error: expected a positive frame count, got "${i[2]}"`),process.exit(1));let s=await c.send({type:"evaluate",code:`(async () => {
|
|
948
|
+
if (window.__sootsimRenderHost) {
|
|
949
|
+
const session = window.${Q} || {}
|
|
950
|
+
if (session.active) {
|
|
951
|
+
const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
|
|
952
|
+
const flushedSamples = await window.__sootsimRenderHost.flushSamples()
|
|
953
|
+
const samples = priorSamples.concat(flushedSamples)
|
|
954
|
+
window.__sootsimRenderHost.startSampling()
|
|
955
|
+
window.${Q} = {
|
|
956
|
+
...session,
|
|
957
|
+
active: true,
|
|
958
|
+
mode: 'render-worker',
|
|
959
|
+
lastSamples: samples,
|
|
960
|
+
lastFlushAt: performance.now(),
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
mode: 'render-worker',
|
|
964
|
+
live: true,
|
|
965
|
+
samples: samples
|
|
966
|
+
.slice()
|
|
967
|
+
.sort((a, b) => b[1] - a[1])
|
|
968
|
+
.slice(0, ${o}),
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
const samples = Array.isArray(session.lastSamples) ? session.lastSamples : []
|
|
972
|
+
return {
|
|
973
|
+
mode: 'render-worker',
|
|
974
|
+
live: false,
|
|
975
|
+
samples: samples
|
|
976
|
+
.slice()
|
|
977
|
+
.sort((a, b) => b[1] - a[1])
|
|
978
|
+
.slice(0, ${o}),
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
const perf = window.__sootsimPerf
|
|
982
|
+
if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
|
|
983
|
+
const stats = perf.getFrameStats?.() || {}
|
|
984
|
+
const recent = Array.isArray(stats.recentFrames) ? stats.recentFrames : []
|
|
985
|
+
return {
|
|
986
|
+
mode: 'main-thread',
|
|
987
|
+
frames: recent.slice().sort((a, b) => b - a).slice(0, ${o}),
|
|
988
|
+
}
|
|
989
|
+
})()`});if(s.error&&(console.error(` error: ${s.error}`),process.exit(1)),s.mode==="render-worker"){let n=Array.isArray(s.samples)?s.samples:[];if(n.length===0){console.log(` no frame data \u2014 run '${h("perf")} start' first`);break}console.log(` worst ${n.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[m,p,y,g,x,R,q]of n)console.log(` ${p.toFixed(2).padStart(7)} ${y.toFixed(2).padStart(7)} ${g.toFixed(2).padStart(7)} ${x.toFixed(2).padStart(7)} ${R.toFixed(2).padStart(6)} ${q.toFixed(2).padStart(7)} ${String(m).padStart(5)}`);s.live&&(console.log(""),console.log(" sampling continues"));break}let r=Array.isArray(s.frames)?s.frames:Array.isArray(s)?s:[];if(r.length===0){console.log(` no frame data \u2014 run '${h("perf")} start' first`);break}console.log(` worst ${r.length} frame times (ms):`),console.log(` ${r.map(n=>n.toFixed(2)).join(", ")}`);break}case"transition":{let o=i[2];if(!o||!["goHome","appSwitcher","lockScreen"].includes(o)){console.log(`
|
|
990
|
+
${h("perf")} transition <event> \u2014 profile a shell transition
|
|
991
|
+
|
|
992
|
+
events:
|
|
993
|
+
goHome swipe-to-home animation
|
|
994
|
+
appSwitcher app switcher card animation
|
|
995
|
+
lockScreen lock screen transition
|
|
996
|
+
|
|
997
|
+
note: uses 600ms capture window \u2014 may need --timeout 10000 flag
|
|
998
|
+
|
|
999
|
+
examples:
|
|
1000
|
+
${h("perf")} transition goHome --timeout 10000
|
|
1001
|
+
${h("perf")} transition appSwitcher
|
|
1002
|
+
`);break}let r=`sootsim:${o}`;console.log(` profiling ${o} transition...`),console.log(" (use --timeout 10000 if this times out)");let n=await c.send({type:"evaluate",code:`(async () => {
|
|
1003
|
+
// only supported in render-worker mode
|
|
1004
|
+
if (!window.__sootsimRenderHost) {
|
|
1005
|
+
return { error: 'transition profiling requires render-worker mode' }
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// start sampling
|
|
1009
|
+
window.__sootsimRenderHost.startSampling()
|
|
1010
|
+
|
|
1011
|
+
// give a frame for sampling to start
|
|
1012
|
+
await new Promise(r => requestAnimationFrame(() => r(undefined)))
|
|
1013
|
+
|
|
1014
|
+
// dispatch the shell event
|
|
1015
|
+
window.dispatchEvent(new Event('${r}'))
|
|
1016
|
+
|
|
1017
|
+
// wait 600ms for transition to complete (shell animations are ~300-500ms)
|
|
1018
|
+
// using fixed timing avoids complex animation-end detection
|
|
1019
|
+
await new Promise(r => setTimeout(r, 600))
|
|
1020
|
+
|
|
1021
|
+
// flush samples and compute stats
|
|
1022
|
+
const samples = await window.__sootsimRenderHost.flushSamples()
|
|
1023
|
+
const frameTimes = samples.map(s => s[1])
|
|
1024
|
+
const layoutTimes = samples.map(s => s[2])
|
|
1025
|
+
const renderTimes = samples.map(s => s[3])
|
|
1026
|
+
const copyTimes = samples.map(s => s[4])
|
|
1027
|
+
const auxTimes = samples.map(s => s[5] || 0)
|
|
1028
|
+
const otherTimes = samples.map(s => s[6] || 0)
|
|
1029
|
+
const sorted = [...frameTimes].sort((a, b) => a - b)
|
|
1030
|
+
const total = frameTimes.reduce((a, b) => a + b, 0)
|
|
1031
|
+
const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
|
|
1032
|
+
const max = Math.max(...frameTimes, 0)
|
|
1033
|
+
const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
|
|
1034
|
+
const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
|
|
1035
|
+
const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
|
|
1036
|
+
const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
|
|
1037
|
+
const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
|
|
1038
|
+
|
|
1039
|
+
return {
|
|
1040
|
+
event: '${o}',
|
|
1041
|
+
frames: frameTimes.length,
|
|
1042
|
+
totalMs: total,
|
|
1043
|
+
avgMs: avg,
|
|
1044
|
+
maxMs: max,
|
|
1045
|
+
layoutTotalMs: layoutTotal,
|
|
1046
|
+
renderTotalMs: renderTotal,
|
|
1047
|
+
copyTotalMs: copyTotal,
|
|
1048
|
+
auxTotalMs: auxTotal,
|
|
1049
|
+
otherTotalMs: otherTotal,
|
|
1050
|
+
layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
|
|
1051
|
+
renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
|
|
1052
|
+
copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
|
|
1053
|
+
auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
|
|
1054
|
+
otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
|
|
1055
|
+
p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
|
|
1056
|
+
p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
|
|
1057
|
+
p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
|
|
1058
|
+
jankFrames: frameTimes.filter(f => f > 16.67).length,
|
|
1059
|
+
samples,
|
|
1060
|
+
}
|
|
1061
|
+
})()`});if(n.error&&(console.error(` error: ${n.error}`),process.exit(1)),n.warning&&console.log(` warning: ${n.warning}`),n.frames===0){console.log(" no frames captured");break}let m=n.avgMs>0?(1e3/n.avgMs).toFixed(1):"?",p=n.frames>0?(n.jankFrames/n.frames*100).toFixed(1):"0";console.log(` ${o} transition profiled:
|
|
1062
|
+
|
|
1063
|
+
frames: ${n.frames}
|
|
1064
|
+
total: ${n.totalMs.toFixed(1)}ms
|
|
1065
|
+
avg: ${n.avgMs.toFixed(2)}ms (${m} fps)
|
|
1066
|
+
max: ${n.maxMs.toFixed(2)}ms
|
|
1067
|
+
|
|
1068
|
+
breakdown (avg per frame):
|
|
1069
|
+
layout: ${n.layoutAvgMs?.toFixed(2)||"?"}ms
|
|
1070
|
+
render: ${n.renderAvgMs?.toFixed(2)||"?"}ms
|
|
1071
|
+
copy: ${n.copyAvgMs?.toFixed(2)||"?"}ms
|
|
1072
|
+
aux: ${n.auxAvgMs?.toFixed(2)||"?"}ms
|
|
1073
|
+
other: ${n.otherAvgMs?.toFixed(2)||"?"}ms
|
|
1074
|
+
|
|
1075
|
+
distribution (${n.frames} samples):
|
|
1076
|
+
p50: ${n.p50.toFixed(2)}ms
|
|
1077
|
+
p95: ${n.p95.toFixed(2)}ms
|
|
1078
|
+
p99: ${n.p99.toFixed(2)}ms
|
|
1079
|
+
jank: ${n.jankFrames} frames (${p}%) >16.67ms`),Array.isArray(n.samples)&&n.samples.length>0&&(console.log(""),Se(n.samples.map(y=>y[1])));break}default:console.error(` unknown perf subcommand: ${e}`),process.exit(1)}break}case"errors":{let e=i[1];if(e==="clear"){await c.send({type:"evaluate",code:'window.__sootsimConsole?.clear(); "cleared"'}),D(d)?B({cleared:!0}):console.log(" error buffer cleared");break}let o=e?Number(e):20,s=await c.send({type:"evaluate",code:`window.__sootsimConsole?.getErrors(${o}) || []`}),r=Array.isArray(s)?s:[];if(D(d)){B(r);break}if(r.length===0){console.log(" no errors captured");break}console.log(` ${r.length} error(s):
|
|
1080
|
+
`);for(let n of r){let m=new Date(n.timestamp).toLocaleTimeString(),p=n.args.map(y=>typeof y=="object"?JSON.stringify(y):y).join(" ");if(console.log(` [${m}] ${p}`),n.stack){let y=n.stack.split(`
|
|
1081
|
+
`).slice(0,3);for(let g of y)console.log(` ${g.trim()}`)}}break}case"warnings":{let e=i[1]?Number(i[1]):20,o=await c.send({type:"evaluate",code:`window.__sootsimConsole?.getWarnings(${e}) || []`}),s=Array.isArray(o)?o:[];if(D(d)){B(s);break}if(s.length===0){console.log(" no warnings captured");break}console.log(` ${s.length} warning(s):
|
|
1082
|
+
`);for(let r of s){let n=new Date(r.timestamp).toLocaleTimeString(),m=r.args.map(p=>typeof p=="object"?JSON.stringify(p):p).join(" ");console.log(` [${n}] ${m}`)}break}case"animations":{let e=await K(c,"listAnimations")??[];if(t.includes("--json")){console.log(JSON.stringify(e,null,2));break}if(e.length===0){console.log(" no active animations");break}console.log(` ${e.length} active animation(s):
|
|
1083
|
+
`);for(let o of e){let s=String(o.kind).padEnd(6),r=`${Number(o.from).toFixed(2)}\u2192${Number(o.to).toFixed(2)}`,n=Number(o.current??0).toFixed(2),m=`${Math.round((o.progress??0)*100)}%`,p=`${Math.round(o.elapsedMs??0)}ms`,y=o.loop?" loop":"",g=o.layoutBound?" layout":"";console.log(` #${o.id} ${s} ${r.padEnd(14)} cur=${n.padEnd(7)} ${m.padStart(4)} ${p}${y}${g}`)}break}case"animation":{let e=i[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${h("animation")} <id>`),process.exit(1));let o=Number(e);Number.isFinite(o)||(console.error(` invalid id: ${e}`),process.exit(1));let s=await K(c,"getAnimation",o);console.log(JSON.stringify(s,null,2));break}case"stop-animation":{let e=i[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${h("stop-animation")} <id|all>`),process.exit(1));let o=e==="all"?"all":Number(e);o!=="all"&&!Number.isFinite(o)&&(console.error(` invalid id: ${e}`),process.exit(1));let s=await K(c,"stopAnimation",o);console.log(` stopped ${s??0} animation(s)`);break}case"requests":{let e=i[1];if(e==="clear"){await K(c,"clearRequests"),D(d)?B({cleared:!0}):console.log(" request buffer cleared");break}let o=e==="all",s=o?i[2]:e,r=s?Number(s):20,n=o?await K(c,"getRequests",r):await K(c,"getFailedRequests",r),m=Array.isArray(n)?n:[];if(D(d)){B(m);break}if(m.length===0){console.log(o?" no requests captured":" no failed requests captured");break}console.log(` ${m.length} ${o?"request(s)":"failed request(s)"}:
|
|
1084
|
+
`);for(let p of m){let y=new Date(p.timestamp).toLocaleTimeString();console.log(` [${y}] ${O(p)}`),p.responseBody?console.log(` ${p.responseBody}`):p.error&&console.log(` ${p.error}`)}break}case"network":{let e=i[1],o=null,s=null,r=!1,n=!1,m=1e3,p=!1,y=!1;for(let M=0;M<d.length;M++){let v=d[M];if(v==="--filter")o=d[M+1]??null,M++;else if(v==="--limit"){let f=Number(d[M+1]);Number.isFinite(f)&&(s=f),M++}else if(v==="--threshold"){let f=Number(d[M+1]);Number.isFinite(f)&&f>0&&(m=f),M++}else v==="--failed"?r=!0:v==="--slow"?n=!0:v==="--tail"||v==="-f"?p=!0:v==="--json"&&(y=!0)}if(e==="clear"){await c.send({type:"evaluate",code:'window.__sootsimObservability?.network.clear(); "cleared"'}),console.log(" network buffer cleared");break}if(e==="get"){let M=i[2];M||(console.error(" usage: sootsim network get <id>"),process.exit(1));let v=await c.send({type:"evaluate",code:`(() => {
|
|
1085
|
+
const obs = window.__sootsimObservability;
|
|
1086
|
+
if (!obs) return null;
|
|
1087
|
+
return obs.network.getSnapshot().find(e => e.id === ${JSON.stringify(M)}) || null;
|
|
1088
|
+
})()`});v||(console.error(` no entry with id ${M}`),process.exit(1)),y?console.log(JSON.stringify(v,null,2)):Ht(v);break}let g=s??(p?200:e?Number(e):20);Number.isFinite(g)||(console.error(` invalid limit: ${e}`),process.exit(1));let x=async()=>{let M=await c.send({type:"evaluate",code:`(() => {
|
|
1089
|
+
const obs = window.__sootsimObservability;
|
|
1090
|
+
if (!obs) return { ok: false };
|
|
1091
|
+
return { ok: true, entries: obs.network.getSnapshot() };
|
|
1092
|
+
})()`});if(!M||!M.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return M.entries??[]},R=M=>{let v=M;if(r&&(v=v.filter(f=>!!f.error||f.status!=null&&f.status>=400)),n&&(v=v.filter(f=>f.durationMs!=null&&f.durationMs>=m)),o){let f=o.toLowerCase();v=v.filter(T=>(T.displayUrl||T.url).toLowerCase().includes(f))}return n&&!p&&(v=[...v].sort((f,T)=>(T.durationMs??0)-(f.durationMs??0))),v};if(!p){let M=await x(),v=R(M).slice(-g);if(y){console.log(JSON.stringify(v,null,2));break}if(v.length===0){M.length===0?console.log(" no network requests captured"):console.log(n?` no requests slower than ${m}ms (${M.length} total \u2014 try --threshold <ms>)`:" no matching requests");break}console.log(n?` ${v.length} request(s) slower than ${m}ms (sorted by duration desc):
|
|
1093
|
+
`:` ${v.length} request(s):
|
|
1094
|
+
`);for(let f of v)dt(f);break}console.log(` tailing network (ctrl-c to stop)...
|
|
1095
|
+
`);let q=new Set,z=!0,U=()=>{z=!1};process.on("SIGINT",U);try{for(;z;){let M=await x(),v=R(M);for(let f of v)f.durationMs!=null&&(q.has(f.id)||(q.add(f.id),y?console.log(JSON.stringify(f)):dt(f)));await X(250)}}finally{process.off("SIGINT",U)}break}case"logs":{let e=i[1],o=null,s=null,r=null,n=!1,m=!1,p=!1;for(let f=0;f<d.length;f++){let T=d[f];if(T==="--filter")o=d[f+1]??null,f++;else if(T==="--limit"){let P=Number(d[f+1]);Number.isFinite(P)&&(s=P),f++}else T==="--level"?(r=d[f+1]??null,f++):T==="--tail"||T==="-f"?n=!0:T==="--json"?m=!0:(T==="--internal"||T==="--all")&&(p=!0)}let y=r?new Set(r.split(",").map(f=>f.trim()).filter(f=>f==="log"||f==="info"||f==="warn"||f==="error"||f==="debug")):null;if(e==="clear"){await c.send({type:"evaluate",code:'window.__sootsimObservability?.logs.clear(); "cleared"'}),console.log(" log buffer cleared");break}let g=!m&&process.stdout.isTTY===!0,x=s??(n?500:e?Number(e):50);Number.isFinite(x)||(console.error(` invalid limit: ${e}`),process.exit(1));let R=async()=>{let f=await c.send({type:"evaluate",code:`(() => {
|
|
1096
|
+
const obs = window.__sootsimObservability;
|
|
1097
|
+
if (!obs) return { ok: false };
|
|
1098
|
+
return { ok: true, entries: obs.logs.getSnapshot() };
|
|
1099
|
+
})()`});if(!f||!f.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return f.entries??[]},q=f=>{let T=f.args[0];return typeof T!="string"?!1:T.startsWith("[sootsim]")},z=f=>{let T=f;if(p||(T=T.filter(P=>!q(P))),y&&(T=T.filter(P=>y.has(P.level))),o){let P=o.toLowerCase();T=T.filter(A=>A.args.join(" ").toLowerCase().includes(P))}return T};if(!n){let f=await R(),T=z(f).slice(-x);if(m){console.log(JSON.stringify(T,null,2));break}if(T.length===0){console.log(f.length===0?" no logs captured":" no matching logs");break}console.log(` ${T.length} log(s):
|
|
1100
|
+
`);for(let P of T)mt(P,g);break}console.log(` tailing logs (ctrl-c to stop)...
|
|
1101
|
+
`);let U=new Set,M=!0,v=()=>{M=!1};process.on("SIGINT",v);try{for(;M;){let f=await R(),T=z(f);for(let P of T)U.has(P.id)||(U.add(P.id),m?console.log(JSON.stringify(P)):mt(P,g));await X(250)}}finally{process.off("SIGINT",v)}break}default:console.error(` unknown subcommand: ${b}`),process.exit(1)}if(ee.has(b)&&!t.includes("--no-wait")&&process.env.SOOTSIM_NO_AUTO_WAIT!=="1"&&await H(c),!L.has(b)&&!D(d))try{await W(c)}catch{}}catch(e){let o=e instanceof Error?e.message:String(e);if(console.error(` ${b??"inspect"} failed: ${o}`),/^no sim connected( with id .+)?$/.test(o))Be(F);else{try{await Oe(c)}catch{}try{await w({includeTail:!0})}catch{}try{await Y({includeTail:!0})}catch{}}process.exit(1)}finally{c.close()}}export{xs as runInspect};
|