agent-device 0.14.0 → 0.14.2
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 +1 -1
- package/android-snapshot-helper/README.md +1 -1
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.14.0.apk → agent-device-android-snapshot-helper-0.14.2.apk} +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.14.2.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.14.0.manifest.json → agent-device-android-snapshot-helper-0.14.2.manifest.json} +6 -6
- package/dist/src/1231.js +1 -0
- package/dist/src/2007.js +33 -0
- package/dist/src/221.js +4 -4
- package/dist/src/8656.js +1 -1
- package/dist/src/android-snapshot-helper.d.ts +1 -0
- package/dist/src/batch.d.ts +138 -0
- package/dist/src/batch.js +1 -0
- package/dist/src/internal/bin.js +53 -44
- package/dist/src/internal/daemon.js +17 -17
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +26 -2
- package/package.json +7 -3
- package/skills/agent-device/SKILL.md +2 -2
- package/skills/dogfood/SKILL.md +2 -2
- package/skills/react-devtools/SKILL.md +1 -1
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.14.0.apk.sha256 +0 -1
- package/dist/src/3918.js +0 -33
package/dist/src/221.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"node:crypto";import t from"node:fs";import n from"node:fs/promises";import r from"node:os";import i from"node:path";import{AppError as a}from"./9152.js";let o="android-snapshot-helper",s="com.callstack.agentdevice.snapshothelper",l="com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",u="android-snapshot-helper-v1",d="uiautomator-xml",c=new Set(["-r","-t","-d","-g"]);async function h(e){let t=await w(e.apkPath);if(t!==e.manifest.sha256)throw new a("COMMAND_FAILED","Android snapshot helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function f(e){let t=e.fetch??fetch,o=await t(e.manifestUrl);if(!o.ok)throw new a("COMMAND_FAILED","Failed to download Android snapshot helper manifest",{manifestUrl:e.manifestUrl,status:o.status,statusText:o.statusText});let s=p(JSON.parse((await m(o,65536,"Android snapshot helper manifest")).toString("utf8")));if(!s.apkUrl)throw new a("COMMAND_FAILED","Android snapshot helper manifest does not include apkUrl",{manifestUrl:e.manifestUrl});let l=e.cacheDir??i.join(r.tmpdir(),`agent-device-android-snapshot-helper-${s.version}`),u=!e.cacheDir;await n.mkdir(l,{recursive:!0});let d=s.assetName??`agent-device-android-snapshot-helper-${s.version}.apk`,c=i.join(l,d),f=await t(s.apkUrl);if(!f.ok)throw new a("COMMAND_FAILED","Failed to download Android snapshot helper APK",{apkUrl:s.apkUrl,status:f.status,statusText:f.statusText});await n.writeFile(c,await m(f,0x1400000,"Android snapshot helper APK"));let A={apkPath:c,manifest:s};return await h(A),{...A,cleanup:async()=>{await n.rm(u?l:c,{recursive:u,force:!0})}}}function p(e){var t,n;if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS","Android snapshot helper manifest must be an object.");return{name:b(e.name,"name",o),version:g(e.version,"version"),releaseTag:N(e.releaseTag),assetName:N(e.assetName),apkUrl:(t=e.apkUrl,n="apkUrl",null===t?null:g(t,n)),sha256:function(e){let t=g(e,"sha256").trim().toLowerCase();if(64!==t.length||!function(e){for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,r=e>=97&&e<=102;if(!n&&!r)return!1}return!0}(t))throw new a("INVALID_ARGS","Android snapshot helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),checksumName:N(e.checksumName),packageName:g(e.packageName,"packageName"),versionCode:M(e.versionCode,"versionCode"),instrumentationRunner:g(e.instrumentationRunner,"instrumentationRunner"),minSdk:M(e.minSdk,"minSdk"),targetSdk:void 0===e.targetSdk?void 0:M(e.targetSdk,"targetSdk"),outputFormat:b(e.outputFormat,"outputFormat",d),statusProtocol:b(e.statusProtocol,"statusProtocol",u),installArgs:A(e.installArgs)}}async function m(e,t,n){let r=e.headers.get("content-length");if(null!==r){let e=Number(r);if(Number.isFinite(e)&&e>t)throw new a("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:e,maxBytes:t})}if(!e.body){let r=Buffer.from(await e.arrayBuffer());if(r.length>t)throw new a("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:r.length,maxBytes:t});return r}let i=e.body.getReader(),o=[],s=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if((s+=r.byteLength)>t)throw new a("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:s,maxBytes:t});o.push(Buffer.from(r))}}finally{i.releaseLock()}return Buffer.concat(o,s)}function A(e){let t=function(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be a string array.`);return e}(e,"installArgs");if("install"!==t[0])throw new a("INVALID_ARGS",'Android snapshot helper manifest installArgs must start with "install".');if(t.some(e=>e.includes("\0")))throw new a("INVALID_ARGS","Android snapshot helper manifest installArgs must not contain null bytes.");let n=t.slice(1).find(e=>{var t;return t=e,!c.has(t)});if(n)throw new a("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${n}".`);return t}async function w(n){return await new Promise((r,i)=>{let a=e.createHash("sha256"),o=t.createReadStream(n);o.on("error",i),o.on("data",e=>a.update(e)),o.on("end",()=>r(a.digest("hex")))})}function g(e,t){if("string"!=typeof e||0===e.trim().length)throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} is required.`);return e}function N(e){return"string"==typeof e&&e.trim().length>0?e:void 0}function M(e,t){if("number"!=typeof e||!Number.isInteger(e))throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be an integer.`);return e}function b(e,t,n){if(e!==n)throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be "${n}".`);return n}function x(e){let t=`${e??""}`.toLowerCase();return t.includes("scroll")||t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")||t.includes("collectionview")||"table"===t}function v(e){return!!x(e.type)||`${e.role??""} ${e.subrole??""}`.toLowerCase().includes("scroll")}function I(e,t,n){let{sourceNodes:r,...i}=D(_(e),t,n);return i}function D(e,t,n){let r={nodes:[],sourceNodes:[],maxNodes:t,maxDepth:n.depth??1/0,options:n,analysis:function(e){let t=0,n=0,r=[...e.children];for(;r.length>0;){let e=r.pop();t+=1,n=Math.max(n,e.depth),r.push(...e.children)}return{rawNodeCount:t,maxDepth:n}}(e),interactiveDescendantMemo:new Map,truncated:!1},i=n.scope?function(e,t){let n=t.toLowerCase(),r=[...e.children],i=0;for(;i<r.length;){let e=r[i++],t=e.label?.toLowerCase()??"",a=e.value?.toLowerCase()??"",o=e.identifier?.toLowerCase()??"";if(t.includes(n)||a.includes(n)||o.includes(n))return e;r.push(...e.children)}return null}(e,n.scope):null;for(let t of i?[i]:e.children)if(function e(t,n,r,i,a=!1,o=!1){if(t.nodes.length>=t.maxNodes){t.truncated=!0;return}if(r>t.maxDepth)return;let s=t.options.raw||function(e,t,n,r,i){var a,o,s;let l=function(e){let t=T(e.type),n=!!(e.label&&e.label.trim().length>0),r=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:n&&!O(e.label??""),hasMeaningfulId:r&&!O(e.identifier??""),isStructural:function(e){let t=e.split(".").pop()??e;return t.includes("layout")||"viewgroup"===t||"view"===t}(t),isVisual:"imageview"===t||"imagebutton"===t}}(e);return t.interactiveOnly?function(e,t,n,r,i){var a,o,s,l;return!!(e.hittable||x(t.type)&&r)||(a=t,o=n,s=r,l=i,(!!a.hasMeaningfulText||!!a.hasMeaningfulId)&&!a.isVisual&&(!a.isStructural||!!l)&&(o||s||l))}(e,l,n,r,i):t.compact?l.hasMeaningfulText||l.hasMeaningfulId||!!e.hittable:!l.isStructural&&!l.isVisual||(a=e,o=l,s=r,!!a.hittable||!!o.hasMeaningfulText||!!o.hasMeaningfulId&&!!s||s)}(n,t.options,a,function e(t,n){let r=t.interactiveDescendantMemo.get(n);if(void 0!==r)return r;for(let r of n.children)if(r.hittable||e(t,r))return t.interactiveDescendantMemo.set(n,!0),!0;return t.interactiveDescendantMemo.set(n,!1),!1}(t,n),o)?function(e,t,n,r){let i=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:i,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,rect:t.rect,enabled:t.enabled,hittable:t.hittable,depth:n,parentIndex:r,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),i}(t,n,r,i):i,l=a||!!n.hittable,u=o||function(e){if(!e)return!1;let t=T(e);return t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")}(n.type);for(let i of n.children)if(e(t,i,r+1,s,l,u),t.truncated)return}(r,t,0),r.truncated)break;let a={nodes:r.nodes,sourceNodes:r.sourceNodes,analysis:r.analysis};return r.truncated?{...a,truncated:!0}:a}function S(e){let t=function(e){let t=new Map,n=e.indexOf(" "),r=e.lastIndexOf(">");if(n<0||r<=n)return t;let i=n;for(;i<r&&!((i=C(e,i,r))>=r);){var a;let n=e[i];if("/"===n||">"===n)break;let o=i;for(;i<r&&!("="===(a=e[i]??"")||"/"===a||">"===a||k(a));)i+=1;let s=e.slice(o,i);if(i=C(e,i,r),!s||"="!==e[i])break;i=C(e,i+1,r);let l=e[i];if('"'!==l&&"'"!==l)break;let u=i+=1;for(;i<r&&e[i]!==l;)i+=1;if(i>=r)break;t.set(s,function(e){let t="",n=0;for(;n<e.length;){let r=e.indexOf("&",n);if(r<0){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(";",r+1);if(i<0){t+=e.slice(r);break}t+=function(e){switch(e){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:return function(e){if(!e.startsWith("#"))return;let t=e[1]?.toLowerCase()==="x"?16:10,n=16===t?e.slice(2):e.slice(1);if(!n||!function(e,t){for(let n of e){let e=n.charCodeAt(0),r=e>=48&&e<=57;if(10===t){if(!r)return!1;continue}let i=e>=65&&e<=70,a=e>=97&&e<=102;if(!r&&!i&&!a)return!1}return!0}(n,t))return;let r=Number.parseInt(n,t);if(Number.isFinite(r))try{return String.fromCodePoint(r)}catch{return}}(e)}}(e.slice(r+1,i))??e.slice(r,i+1),n=i+1}return t}(e.slice(u,i))),i+=1}return t}(e),n=e=>{let n=y(t,e);if(null!==n)return"true"===n};return{text:y(t,"text"),desc:y(t,"content-desc"),resourceId:y(t,"resource-id"),className:y(t,"class"),bounds:y(t,"bounds"),clickable:n("clickable"),enabled:n("enabled"),focusable:n("focusable"),focused:n("focused")}}function C(e,t,n){for(;t<n&&k(e[t]??"");)t+=1;return t}function k(e){return" "===e||"\n"===e||"\r"===e||" "===e}function y(e,t){return e.get(t)??null}function L(e){if(!e)return;let t=/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return{x:n,y:r,width:Math.max(0,Number(t[3])-n),height:Math.max(0,Number(t[4])-r)}}function _(e){let t={type:null,label:null,value:null,identifier:null,depth:-1,children:[]},n=[t],r=/<node\b[^>]*>|<\/node>/g,i=r.exec(e);for(;i;){let t=i[0];if(t.startsWith("</node")){n.length>1&&n.pop(),i=r.exec(e);continue}let a=S(t),o=L(a.bounds),s=n[n.length-1],l={type:a.className,label:a.text||a.desc,value:a.text,identifier:a.resourceId,rect:o,enabled:a.enabled,hittable:a.clickable??a.focusable,depth:s.depth+1,parentIndex:void 0,children:[]};s.children.push(l),t.endsWith("/>")||n.push(l),i=r.exec(e)}return t}function T(e){return e?e.toLowerCase():""}function O(e){let t=e.trim();return!!t&&/^[\w.]+:id\/[\w.-]+$/i.test(t)}async function E(e){let t,n=e.waitForIdleTimeoutMs??500,r=e.timeoutMs??8e3,i=e.commandTimeoutMs??r+5e3,o=e.maxDepth??128,l=e.maxNodes??5e3,u=e.packageName??s,d=e.instrumentationRunner??`${u}/.SnapshotInstrumentation`,c=["shell","am","instrument","-w","-e","waitForIdleTimeoutMs",String(n),"-e","timeoutMs",String(r),"-e","maxDepth",String(o),"-e","maxNodes",String(l),d],h=await e.adb(c,{allowFailure:!0,timeoutMs:i});try{t=F(`${h.stdout}
|
|
2
|
-
${h.stderr}`)}catch(e){throw new
|
|
3
|
-
${r.stderr}`,
|
|
4
|
-
${r.stderr}`.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")))return i;let
|
|
1
|
+
import e from"node:crypto";import t from"node:fs";import n from"node:fs/promises";import r from"node:os";import i from"node:path";import{AppError as o}from"./9152.js";let a="android-snapshot-helper",s="com.callstack.agentdevice.snapshothelper",l="com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",u="android-snapshot-helper-v1",d="uiautomator-xml",c=new Set(["-r","-t","-d","-g"]);async function h(e){let t=await w(e.apkPath);if(t!==e.manifest.sha256)throw new o("COMMAND_FAILED","Android snapshot helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function f(e){let t=e.fetch??fetch,a=await t(e.manifestUrl);if(!a.ok)throw new o("COMMAND_FAILED","Failed to download Android snapshot helper manifest",{manifestUrl:e.manifestUrl,status:a.status,statusText:a.statusText});let s=p(JSON.parse((await m(a,65536,"Android snapshot helper manifest")).toString("utf8")));if(!s.apkUrl)throw new o("COMMAND_FAILED","Android snapshot helper manifest does not include apkUrl",{manifestUrl:e.manifestUrl});let l=e.cacheDir??i.join(r.tmpdir(),`agent-device-android-snapshot-helper-${s.version}`),u=!e.cacheDir;await n.mkdir(l,{recursive:!0});let d=s.assetName??`agent-device-android-snapshot-helper-${s.version}.apk`,c=i.join(l,d),f=await t(s.apkUrl);if(!f.ok)throw new o("COMMAND_FAILED","Failed to download Android snapshot helper APK",{apkUrl:s.apkUrl,status:f.status,statusText:f.statusText});await n.writeFile(c,await m(f,0x1400000,"Android snapshot helper APK"));let A={apkPath:c,manifest:s};return await h(A),{...A,cleanup:async()=>{await n.rm(u?l:c,{recursive:u,force:!0})}}}function p(e){var t,n;if(!e||"object"!=typeof e||Array.isArray(e))throw new o("INVALID_ARGS","Android snapshot helper manifest must be an object.");return{name:v(e.name,"name",a),version:g(e.version,"version"),releaseTag:N(e.releaseTag),assetName:N(e.assetName),apkUrl:(t=e.apkUrl,n="apkUrl",null===t?null:g(t,n)),sha256:function(e){let t=g(e,"sha256").trim().toLowerCase();if(64!==t.length||!function(e){for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,r=e>=97&&e<=102;if(!n&&!r)return!1}return!0}(t))throw new o("INVALID_ARGS","Android snapshot helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),checksumName:N(e.checksumName),packageName:g(e.packageName,"packageName"),versionCode:M(e.versionCode,"versionCode"),instrumentationRunner:g(e.instrumentationRunner,"instrumentationRunner"),minSdk:M(e.minSdk,"minSdk"),targetSdk:void 0===e.targetSdk?void 0:M(e.targetSdk,"targetSdk"),outputFormat:v(e.outputFormat,"outputFormat",d),statusProtocol:v(e.statusProtocol,"statusProtocol",u),installArgs:A(e.installArgs)}}async function m(e,t,n){let r=e.headers.get("content-length");if(null!==r){let e=Number(r);if(Number.isFinite(e)&&e>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:e,maxBytes:t})}if(!e.body){let r=Buffer.from(await e.arrayBuffer());if(r.length>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:r.length,maxBytes:t});return r}let i=e.body.getReader(),a=[],s=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if((s+=r.byteLength)>t)throw new o("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:s,maxBytes:t});a.push(Buffer.from(r))}}finally{i.releaseLock()}return Buffer.concat(a,s)}function A(e){let t=function(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be a string array.`);return e}(e,"installArgs");if("install"!==t[0])throw new o("INVALID_ARGS",'Android snapshot helper manifest installArgs must start with "install".');if(t.some(e=>e.includes("\0")))throw new o("INVALID_ARGS","Android snapshot helper manifest installArgs must not contain null bytes.");let n=t.slice(1).find(e=>{var t;return t=e,!c.has(t)});if(n)throw new o("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${n}".`);return t}async function w(n){return await new Promise((r,i)=>{let o=e.createHash("sha256"),a=t.createReadStream(n);a.on("error",i),a.on("data",e=>o.update(e)),a.on("end",()=>r(o.digest("hex")))})}function g(e,t){if("string"!=typeof e||0===e.trim().length)throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} is required.`);return e}function N(e){return"string"==typeof e&&e.trim().length>0?e:void 0}function M(e,t){if("number"!=typeof e||!Number.isInteger(e))throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be an integer.`);return e}function v(e,t,n){if(e!==n)throw new o("INVALID_ARGS",`Android snapshot helper manifest ${t} must be "${n}".`);return n}function x(e){let t=`${e??""}`.toLowerCase();return t.includes("scroll")||t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")||t.includes("collectionview")||"table"===t}function b(e){return!!x(e.type)||`${e.role??""} ${e.subrole??""}`.toLowerCase().includes("scroll")}function I(e,t,n){let{sourceNodes:r,...i}=D(_(e),t,n);return i}function D(e,t,n){let r={nodes:[],sourceNodes:[],maxNodes:t,maxDepth:n.depth??1/0,options:n,analysis:function(e){let t=0,n=0,r=[...e.children];for(;r.length>0;){let e=r.pop();t+=1,n=Math.max(n,e.depth),r.push(...e.children)}return{rawNodeCount:t,maxDepth:n}}(e),interactiveDescendantMemo:new Map,truncated:!1},i=n.scope?function(e,t){let n=t.toLowerCase(),r=[...e.children],i=0;for(;i<r.length;){let e=r[i++],t=e.label?.toLowerCase()??"",o=e.value?.toLowerCase()??"",a=e.identifier?.toLowerCase()??"";if(t.includes(n)||o.includes(n)||a.includes(n))return e;r.push(...e.children)}return null}(e,n.scope):null;for(let t of i?[i]:e.children)if(function e(t,n,r,i,o=!1,a=!1){if(t.nodes.length>=t.maxNodes){t.truncated=!0;return}if(r>t.maxDepth)return;let s=t.options.raw||function(e,t,n,r,i){var o,a,s;let l=function(e){let t=T(e.type),n=!!(e.label&&e.label.trim().length>0),r=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:n&&!O(e.label??""),hasMeaningfulId:r&&!O(e.identifier??""),isStructural:function(e){let t=e.split(".").pop()??e;return t.includes("layout")||"viewgroup"===t||"view"===t}(t),isVisual:"imageview"===t||"imagebutton"===t}}(e);return t.interactiveOnly?function(e,t,n,r,i){var o,a,s,l;return!!(e.hittable||x(t.type)&&r)||(o=t,a=n,s=r,l=i,(!!o.hasMeaningfulText||!!o.hasMeaningfulId)&&!o.isVisual&&(!o.isStructural||!!l)&&(a||s||l))}(e,l,n,r,i):t.compact?l.hasMeaningfulText||l.hasMeaningfulId||!!e.hittable:!l.isStructural&&!l.isVisual||(o=e,a=l,s=r,!!o.hittable||!!a.hasMeaningfulText||!!a.hasMeaningfulId&&!!s||s)}(n,t.options,o,function e(t,n){let r=t.interactiveDescendantMemo.get(n);if(void 0!==r)return r;for(let r of n.children)if(r.hittable||e(t,r))return t.interactiveDescendantMemo.set(n,!0),!0;return t.interactiveDescendantMemo.set(n,!1),!1}(t,n),a)?function(e,t,n,r){let i=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:i,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,rect:t.rect,enabled:t.enabled,hittable:t.hittable,depth:n,parentIndex:r,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),i}(t,n,r,i):i,l=o||!!n.hittable,u=a||function(e){if(!e)return!1;let t=T(e);return t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")}(n.type);for(let i of n.children)if(e(t,i,r+1,s,l,u),t.truncated)return}(r,t,0),r.truncated)break;let o={nodes:r.nodes,sourceNodes:r.sourceNodes,analysis:r.analysis};return r.truncated?{...o,truncated:!0}:o}function S(e){let t=function(e){let t=new Map,n=e.indexOf(" "),r=e.lastIndexOf(">");if(n<0||r<=n)return t;let i=n;for(;i<r&&!((i=C(e,i,r))>=r);){var o;let n=e[i];if("/"===n||">"===n)break;let a=i;for(;i<r&&!("="===(o=e[i]??"")||"/"===o||">"===o||k(o));)i+=1;let s=e.slice(a,i);if(i=C(e,i,r),!s||"="!==e[i])break;i=C(e,i+1,r);let l=e[i];if('"'!==l&&"'"!==l)break;let u=i+=1;for(;i<r&&e[i]!==l;)i+=1;if(i>=r)break;t.set(s,function(e){let t="",n=0;for(;n<e.length;){let r=e.indexOf("&",n);if(r<0){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(";",r+1);if(i<0){t+=e.slice(r);break}t+=function(e){switch(e){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:return function(e){if(!e.startsWith("#"))return;let t=e[1]?.toLowerCase()==="x"?16:10,n=16===t?e.slice(2):e.slice(1);if(!n||!function(e,t){for(let n of e){let e=n.charCodeAt(0),r=e>=48&&e<=57;if(10===t){if(!r)return!1;continue}let i=e>=65&&e<=70,o=e>=97&&e<=102;if(!r&&!i&&!o)return!1}return!0}(n,t))return;let r=Number.parseInt(n,t);if(Number.isFinite(r))try{return String.fromCodePoint(r)}catch{return}}(e)}}(e.slice(r+1,i))??e.slice(r,i+1),n=i+1}return t}(e.slice(u,i))),i+=1}return t}(e),n=e=>{let n=y(t,e);if(null!==n)return"true"===n};return{text:y(t,"text"),desc:y(t,"content-desc"),resourceId:y(t,"resource-id"),className:y(t,"class"),bounds:y(t,"bounds"),clickable:n("clickable"),enabled:n("enabled"),focusable:n("focusable"),focused:n("focused")}}function C(e,t,n){for(;t<n&&k(e[t]??"");)t+=1;return t}function k(e){return" "===e||"\n"===e||"\r"===e||" "===e}function y(e,t){return e.get(t)??null}function L(e){if(!e)return;let t=/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return{x:n,y:r,width:Math.max(0,Number(t[3])-n),height:Math.max(0,Number(t[4])-r)}}function _(e){let t={type:null,label:null,value:null,identifier:null,depth:-1,children:[]},n=[t],r=/<node\b[^>]*>|<\/node>/g,i=r.exec(e);for(;i;){let t=i[0];if(t.startsWith("</node")){n.length>1&&n.pop(),i=r.exec(e);continue}let o=S(t),a=L(o.bounds),s=n[n.length-1],l={type:o.className,label:o.text||o.desc,value:o.text,identifier:o.resourceId,rect:a,enabled:o.enabled,hittable:o.clickable??o.focusable,depth:s.depth+1,parentIndex:void 0,children:[]};s.children.push(l),t.endsWith("/>")||n.push(l),i=r.exec(e)}return t}function T(e){return e?e.toLowerCase():""}function O(e){let t=e.trim();return!!t&&/^[\w.]+:id\/[\w.-]+$/i.test(t)}async function E(e){let t,n=e.waitForIdleTimeoutMs??500,r=e.timeoutMs??8e3,i=e.commandTimeoutMs??r+5e3,a=e.maxDepth??128,l=e.maxNodes??5e3,u=e.packageName??s,d=e.instrumentationRunner??`${u}/.SnapshotInstrumentation`,c=["shell","am","instrument","-w","-e","waitForIdleTimeoutMs",String(n),"-e","timeoutMs",String(r),"-e","maxDepth",String(a),"-e","maxNodes",String(l),d],h=await e.adb(c,{allowFailure:!0,timeoutMs:i});try{t=F(`${h.stdout}
|
|
2
|
+
${h.stderr}`)}catch(e){throw new o("COMMAND_FAILED",0===h.exitCode?"Android snapshot helper output could not be parsed":"Android snapshot helper failed before returning parseable output",{stdout:h.stdout,stderr:h.stderr,exitCode:h.exitCode},e)}if(0!==h.exitCode)throw new o("COMMAND_FAILED","Android snapshot helper failed",{stdout:h.stdout,stderr:h.stderr,exitCode:h.exitCode,helper:t.metadata});return t}function F(e){var t,n;let r=function(e){var t;let n={status:[],results:[],currentStatus:null,currentResult:null};for(let t of e.split(/\r?\n/))!function(e,t){if(e.startsWith("INSTRUMENTATION_STATUS: ")){t.currentStatus??={},$(e.slice(24),t.currentStatus);return}if(e.startsWith("INSTRUMENTATION_STATUS_CODE: "))return P(t);if(e.startsWith("INSTRUMENTATION_RESULT: ")){t.currentResult??={},$(e.slice(24),t.currentResult);return}e.startsWith("INSTRUMENTATION_CODE: ")&&U(t)}(t,n);return P(t=n),U(t),{status:n.status,results:n.results}}(e),i=function(e){let t=e.find(e=>e.agentDeviceProtocol===u);if(!t)throw new o("COMMAND_FAILED","Android snapshot helper did not return a final result");if("true"!==t.ok){var n;throw new o("COMMAND_FAILED",(n=t).message&&"null"!==n.message?n.message:n.errorType||"Android snapshot helper returned an error",{errorType:t.errorType,helper:t})}return t}(r.results);return{xml:function(e,t){if(0===e.length)throw new o("COMMAND_FAILED","Android snapshot helper did not return XML chunks",{helper:t});let n=function(e){let t=e[0]?.count??e.length;if(t<1||e.length!==t||e.some(e=>e.count!==t))throw new o("COMMAND_FAILED","Android snapshot helper returned incomplete XML chunks",{expectedChunks:t,actualChunks:e.length});return t}(e),r=Buffer.concat(function(e,t){let n=[];for(let r=0;r<t;r+=1){let i=e.get(r);if(void 0===i)throw new o("COMMAND_FAILED","Android snapshot helper returned incomplete XML chunks",{missingChunkIndex:r,expectedChunks:t});n.push(Buffer.from(i,"base64"))}return n}(function(e,t){let n=new Map;for(let r of e){if(void 0===r.index||r.index<0||r.index>=t)throw new o("COMMAND_FAILED","Android snapshot helper returned invalid chunk index",{chunkIndex:r.index,expectedChunks:t});if(n.has(r.index))throw new o("COMMAND_FAILED","Android snapshot helper returned duplicate XML chunks",{chunkIndex:r.index});n.set(r.index,r.payloadBase64)}return n}(e,n),n)).toString("utf8");if(!r.includes("<hierarchy")||!r.includes("</hierarchy>"))throw new o("COMMAND_FAILED","Android snapshot helper output did not contain XML",{xml:r});return r}(r.status.filter(e=>e.agentDeviceProtocol===u&&e.outputFormat===d&&"string"==typeof e.payloadBase64).map(e=>({index:H(e.chunkIndex),count:H(e.chunkCount),payloadBase64:e.payloadBase64})),i),metadata:{helperApiVersion:(t=i).helperApiVersion,outputFormat:d,waitForIdleTimeoutMs:H(t.waitForIdleTimeoutMs),timeoutMs:H(t.timeoutMs),maxDepth:H(t.maxDepth),maxNodes:H(t.maxNodes),rootPresent:B(t.rootPresent),captureMode:"interactive-windows"===(n=t.captureMode)||"active-window"===n?n:void 0,windowCount:H(t.windowCount),nodeCount:H(t.nodeCount),truncated:B(t.truncated),elapsedMs:H(t.elapsedMs)}}}function R(e,t={outputFormat:d},n={},r=800){return{...I(e,r,n),metadata:t}}function P(e){e.currentStatus&&(e.status.push(e.currentStatus),e.currentStatus=null)}function U(e){e.currentResult&&(e.results.push(e.currentResult),e.currentResult=null)}function $(e,t){let n=e.indexOf("=");n<0||(t[e.slice(0,n)]=e.slice(n+1))}function H(e){if(void 0===e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function B(e){return"true"===e||"false"!==e&&void 0}let V=new Map;function G(e){K(W(e.deviceKey,e.packageName,e.versionCode))}function W(e,t,n){return e?`${e}\0${t}\0${n}`:void 0}function K(e){e&&V.delete(e)}async function X(e){var t,n,r;let{adb:i,artifact:a}=e,s=e.installPolicy??"missing-or-outdated",l=a.manifest.packageName,u=a.manifest.versionCode;if("never"===s)return{packageName:l,versionCode:u,installed:!1,reason:"skipped"};let d=W(e.deviceKey,l,u),c=d?V.get(d):void 0;if(d&&"always"!==s&&void 0!==c)return{packageName:l,versionCode:u,installedVersionCode:c,installed:!1,reason:"current"};let f=await j(i,l,e.timeoutMs),p=(t=s,n=f,r=u,"never"===t?"skipped":"always"===t?"forced":void 0===n?"missing":n<r?"outdated":"current");if("current"===p){if(void 0===f)throw Error("Expected installed versionCode for current Android snapshot helper");return d&&V.set(d,f),{packageName:l,versionCode:u,installedVersionCode:f,installed:!1,reason:p}}await h(a);let m=[...A(a.manifest.installArgs),a.apkPath],w=await z(i,m,{packageName:l,timeoutMs:e.timeoutMs});if(0!==w.exitCode)throw K(d),new o("COMMAND_FAILED","Failed to install Android snapshot helper",{packageName:l,versionCode:u,stdout:w.stdout,stderr:w.stderr,exitCode:w.exitCode});return d&&V.set(d,u),{packageName:l,versionCode:u,installedVersionCode:f,installed:!0,reason:p}}async function j(e,t,n){let r=await e(["shell","cmd","package","list","packages","--show-versioncode",t],{allowFailure:!0,timeoutMs:n});if(0===r.exitCode){var i=`${r.stdout}
|
|
3
|
+
${r.stderr}`,o=t;let e=`package:${o}`;for(let t of i.split(/\r?\n/)){if(!t.startsWith(e)||t.length>e.length&&!/\s/.test(t[e.length]??""))continue;let n=/(?:^|\s)versionCode:(\d+)(?:\s|$)/.exec(t);if(n)return Number(n[1])}return}}async function z(e,t,n){var r;let i=await e(t,{allowFailure:!0,timeoutMs:n.timeoutMs});if(0===i.exitCode||(r=i,!`${r.stdout}
|
|
4
|
+
${r.stderr}`.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")))return i;let o=await e(["uninstall",n.packageName],{allowFailure:!0,timeoutMs:n.timeoutMs}),a=await e(t,{allowFailure:!0,timeoutMs:n.timeoutMs});return 0===a.exitCode?a:{...a,stderr:[a.stderr,o.stderr?`Previous uninstall stderr after INSTALL_FAILED_UPDATE_INCOMPATIBLE: ${o.stderr}`:""].filter(Boolean).join("\n")}}export{a as ANDROID_SNAPSHOT_HELPER_NAME,d as ANDROID_SNAPSHOT_HELPER_OUTPUT_FORMAT,s as ANDROID_SNAPSHOT_HELPER_PACKAGE,u as ANDROID_SNAPSHOT_HELPER_PROTOCOL,l as ANDROID_SNAPSHOT_HELPER_RUNNER,D as buildUiHierarchySnapshot,E as captureAndroidSnapshotWithHelper,X as ensureAndroidSnapshotHelper,G as forgetAndroidSnapshotHelperInstall,b as isScrollableNodeLike,x as isScrollableType,p as parseAndroidSnapshotHelperManifest,F as parseAndroidSnapshotHelperOutput,R as parseAndroidSnapshotHelperXml,L as parseBounds,I as parseUiHierarchy,_ as parseUiHierarchyTree,f as prepareAndroidSnapshotHelperArtifactFromManifestUrl,S as readNodeAttributes,h as verifyAndroidSnapshotHelperArtifact};
|
package/dist/src/8656.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{URL as t}from"node:url";import{runCmdSync as r}from"./9818.js";import{sleep as e}from"./4829.js";import{AppError as n}from"./9152.js";let o=[/(^|[/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])dist\/src\/internal\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])src\/daemon\.ts($|[\s"'])/];function i(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(t){return"EPERM"===t.code}}function
|
|
1
|
+
import{URL as t}from"node:url";import{runCmdSync as r}from"./9818.js";import{sleep as e}from"./4829.js";import{AppError as n}from"./9152.js";let o=[/(^|[/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])dist\/src\/internal\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])src\/daemon\.ts($|[\s"'])/];function i(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(t){return"EPERM"===t.code}}function u(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(-t,0),!0}catch(t){return"EPERM"===t.code}}function s(t){if(!Number.isInteger(t)||t<=0)return null;try{let e=r("ps",["-p",String(t),"-o","lstart="],{allowFailure:!0,timeoutMs:1e3});if(0!==e.exitCode)return null;let n=e.stdout.trim();return n.length>0?n:null}catch{return null}}function l(t){if(!Number.isInteger(t)||t<=0)return null;try{let e=r("ps",["-p",String(t),"-o","command="],{allowFailure:!0,timeoutMs:1e3});if(0!==e.exitCode)return null;let n=e.stdout.trim();return n.length>0?n:null}catch{return null}}function c(t,r){let e;if(!i(t))return!1;if(r){let e=s(t);if(!e||e!==r)return!1}let n=l(t);return!!n&&!!(e=n.toLowerCase().replaceAll("\\","/")).includes("agent-device")&&o.some(t=>t.test(e))}function a(t,r){try{return process.kill(t,r),!0}catch(r){let t=r.code;if("ESRCH"===t||"EPERM"===t)return!1;throw r}}async function m(t,r){if(!i(t))return!0;let n=Date.now();for(;Date.now()-n<r;)if(await e(50),!i(t))return!0;return!i(t)}async function f(t,r){!c(t,r.expectedStartTime)||!a(t,"SIGTERM")||await m(t,r.termTimeoutMs)||a(t,"SIGKILL")&&await m(t,r.killTimeoutMs)}function p(r){if(!r)return;let e=d(r.metroHost),o=h(r.metroPort),i="http",u=d(r.bundleUrl);if(u){var s;let r;try{r=new t(u)}catch(t){throw new n("INVALID_ARGS",`Invalid runtime bundle URL: ${u}`,{},t)}("http:"===r.protocol||"https:"===r.protocol)&&(e??=d(r.hostname),o??=h(r.port.length>0?Number(r.port):"https:"===(s=r.protocol)?443:"http:"===s?80:void 0),i="https:"===r.protocol?"https":"http")}if(e&&o)return{host:e,port:o,scheme:i}}function d(t){let r=t?.trim();return r&&r.length>0?r:void 0}function h(t){if(Number.isInteger(t)&&!(t<=0)&&!(t>65535))return t}export{c as isAgentDeviceDaemonProcess,i as isProcessAlive,u as isProcessGroupAlive,l as readProcessCommand,s as readProcessStartTime,p as resolveRuntimeTransportHints,f as stopProcessForTakeover,d as trimRuntimeValue,m as waitForProcessExit};
|
|
@@ -122,6 +122,7 @@ export declare function captureAndroidSnapshotWithHelper(options: AndroidSnapsho
|
|
|
122
122
|
export declare function ensureAndroidSnapshotHelper(options: {
|
|
123
123
|
adb: AndroidAdbExecutor;
|
|
124
124
|
artifact: AndroidSnapshotHelperArtifact;
|
|
125
|
+
deviceKey?: string;
|
|
125
126
|
installPolicy?: AndroidSnapshotHelperInstallPolicy;
|
|
126
127
|
timeoutMs?: number;
|
|
127
128
|
}): Promise<AndroidSnapshotHelperInstallResult>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export declare const BATCH_BLOCKED_COMMANDS: ReadonlySet<string>;
|
|
2
|
+
|
|
3
|
+
export declare type BatchFlags = Record<string, unknown> & {
|
|
4
|
+
batchOnError?: 'stop';
|
|
5
|
+
batchMaxSteps?: number;
|
|
6
|
+
batchSteps?: BatchStep[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export declare type BatchInvoke = (req: BatchRequest) => Promise<DaemonResponse>;
|
|
10
|
+
|
|
11
|
+
export declare type BatchRequest = Omit<DaemonRequest, 'flags'> & {
|
|
12
|
+
flags?: BatchFlags | Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export declare type BatchStep = {
|
|
16
|
+
command: string;
|
|
17
|
+
positionals?: string[];
|
|
18
|
+
flags?: Record<string, unknown>;
|
|
19
|
+
runtime?: unknown;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export declare type BatchStepResult = {
|
|
23
|
+
step: number;
|
|
24
|
+
command: string;
|
|
25
|
+
ok: true;
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
durationMs: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export declare function buildBatchStepFlags(parentFlags: BatchFlags | Record<string, unknown> | undefined, stepFlags: BatchStep['flags'] | Record<string, unknown> | undefined): BatchFlags;
|
|
31
|
+
|
|
32
|
+
declare type DaemonArtifact = {
|
|
33
|
+
field: string;
|
|
34
|
+
artifactId?: string;
|
|
35
|
+
fileName?: string;
|
|
36
|
+
localPath?: string;
|
|
37
|
+
path?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare type DaemonError = {
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
hint?: string;
|
|
44
|
+
diagnosticId?: string;
|
|
45
|
+
logPath?: string;
|
|
46
|
+
details?: Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
declare type DaemonInstallSource = {
|
|
50
|
+
kind: 'url';
|
|
51
|
+
url: string;
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'path';
|
|
55
|
+
path: string;
|
|
56
|
+
} | ({
|
|
57
|
+
kind: 'github-actions-artifact';
|
|
58
|
+
owner: string;
|
|
59
|
+
repo: string;
|
|
60
|
+
} & ({
|
|
61
|
+
artifactId: number;
|
|
62
|
+
} | {
|
|
63
|
+
runId: number;
|
|
64
|
+
artifactName: string;
|
|
65
|
+
} | {
|
|
66
|
+
artifactName: string;
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
declare type DaemonLockPolicy = 'reject' | 'strip';
|
|
70
|
+
|
|
71
|
+
declare type DaemonRequest = {
|
|
72
|
+
token?: string;
|
|
73
|
+
session?: string;
|
|
74
|
+
command: string;
|
|
75
|
+
positionals: string[];
|
|
76
|
+
flags?: Record<string, unknown>;
|
|
77
|
+
runtime?: SessionRuntimeHints;
|
|
78
|
+
meta?: DaemonRequestMeta;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare type DaemonRequestMeta = {
|
|
82
|
+
requestId?: string;
|
|
83
|
+
debug?: boolean;
|
|
84
|
+
cwd?: string;
|
|
85
|
+
tenantId?: string;
|
|
86
|
+
runId?: string;
|
|
87
|
+
leaseId?: string;
|
|
88
|
+
leaseTtlMs?: number;
|
|
89
|
+
leaseBackend?: LeaseBackend;
|
|
90
|
+
sessionIsolation?: 'none' | 'tenant';
|
|
91
|
+
uploadedArtifactId?: string;
|
|
92
|
+
clientArtifactPaths?: Record<string, string>;
|
|
93
|
+
installSource?: DaemonInstallSource;
|
|
94
|
+
retainMaterializedPaths?: boolean;
|
|
95
|
+
materializedPathRetentionMs?: number;
|
|
96
|
+
materializationId?: string;
|
|
97
|
+
lockPolicy?: DaemonLockPolicy;
|
|
98
|
+
lockPlatform?: 'ios' | 'macos' | 'android' | 'linux' | 'apple';
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
declare type DaemonResponse = {
|
|
102
|
+
ok: true;
|
|
103
|
+
data?: DaemonResponseData;
|
|
104
|
+
} | {
|
|
105
|
+
ok: false;
|
|
106
|
+
error: DaemonError;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
declare type DaemonResponseData = Record<string, unknown> & {
|
|
110
|
+
artifacts?: DaemonArtifact[];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export declare const DEFAULT_BATCH_MAX_STEPS = 100;
|
|
114
|
+
|
|
115
|
+
export declare const INHERITED_PARENT_FLAG_KEYS: readonly ["platform", "target", "device", "udid", "serial", "verbose", "out"];
|
|
116
|
+
|
|
117
|
+
declare type LeaseBackend = 'ios-simulator' | 'ios-instance' | 'android-instance';
|
|
118
|
+
|
|
119
|
+
export declare type NormalizedBatchStep = {
|
|
120
|
+
command: string;
|
|
121
|
+
positionals: string[];
|
|
122
|
+
flags: Record<string, unknown>;
|
|
123
|
+
runtime?: unknown;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export declare function runBatch(req: BatchRequest, sessionName: string, invoke: BatchInvoke): Promise<DaemonResponse>;
|
|
127
|
+
|
|
128
|
+
declare type SessionRuntimeHints = {
|
|
129
|
+
platform?: 'ios' | 'android';
|
|
130
|
+
metroHost?: string;
|
|
131
|
+
metroPort?: number;
|
|
132
|
+
bundleUrl?: string;
|
|
133
|
+
launchUrl?: string;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export declare function validateAndNormalizeBatchSteps(steps: unknown, maxSteps: number): NormalizedBatchStep[];
|
|
137
|
+
|
|
138
|
+
export { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{BATCH_BLOCKED_COMMANDS,DEFAULT_BATCH_MAX_STEPS,INHERITED_PARENT_FLAG_KEYS,buildBatchStepFlags,runBatch,validateAndNormalizeBatchSteps}from"./1231.js";
|