agent-device 0.20.2 → 0.20.4
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/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.2.apk → agent-device-android-ime-helper-0.20.4.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.4.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.2.manifest.json → agent-device-android-ime-helper-0.20.4.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.4.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.4.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.2.manifest.json → agent-device-android-snapshot-helper-0.20.4.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +57 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +45 -185
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +257 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +1 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +3 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +8 -2
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/android-adb.d.ts +4 -27
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-helpers.js +1 -0
- package/dist/src/app-inventory.d.ts +4 -0
- package/dist/src/app-lifecycle.js +7 -7
- package/dist/src/app-resolution.js +1 -1
- package/dist/src/apps.js +5 -5
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +27 -19
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +15 -14
- package/dist/src/client-metro.js +1 -1
- package/dist/src/{tv-remote.d.ts → cloud-artifacts.d.ts} +109 -126
- package/dist/src/command-metadata.js +1 -1
- package/dist/src/command-schema.js +1 -1
- package/dist/src/command-surface.js +1 -1
- package/dist/src/context.js +1 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/debug-symbols.js +4 -4
- package/dist/src/device-input-state.d.ts +26 -0
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/device.js +1 -9
- package/dist/src/devices2.js +1 -1
- package/dist/src/entities.js +1 -0
- package/dist/src/find.js +1 -1
- package/dist/src/finders.d.ts +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/ime-lifecycle.js +9 -0
- package/dist/src/index.d.ts +593 -556
- package/dist/src/input-actions.js +4 -4
- package/dist/src/install-artifact.js +4 -4
- package/dist/src/install-artifact2.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.d.ts +7 -4
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +14 -14
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun.d.ts +171 -190
- package/dist/src/limrun.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/logcat.js +1 -1
- package/dist/src/manifest.js +1 -1
- package/dist/src/metro.d.ts +1 -1
- package/dist/src/parser.js +2 -0
- package/dist/src/path-resolution.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/plist-xml.js +1 -0
- package/dist/src/plist.js +1 -1
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/process-lock.js +1 -1
- package/dist/src/provider-limrun-runtime.js +1 -0
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/register-builtins.js +1 -1
- package/dist/src/registry.js +22 -22
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/reporting.js +7 -7
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runner-provider.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime-transport.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/screenshot-geometry.js +1 -0
- package/dist/src/screenshot-result.js +6 -0
- package/dist/src/sdk-android-adb.d.ts +5 -6
- package/dist/src/sdk-android-adb.js +3 -3
- package/dist/src/sdk-batch-runner.d.ts +2 -2
- package/dist/src/sdk-batch-runner.js +3 -3
- package/dist/src/sdk-contracts.d.ts +21 -25
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.js +1 -1
- package/dist/src/sdk-remote-config.d.ts +19 -4
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selector-vocabulary.js +1 -1
- package/dist/src/selectors.d.ts +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +2 -2
- package/dist/src/session-target-evidence.js +1 -1
- package/dist/src/session.js +8 -8
- package/dist/src/setting-state.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/src.js +1 -0
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/viewport-dimension.js +14 -0
- package/package.json +28 -19
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.2.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.2.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.2.apk.sha256 +0 -1
- package/dist/src/android-input-method-overlays.js +0 -1
- package/dist/src/android-input-ownership.js +0 -1
- package/dist/src/apple-multitouch-support.js +0 -1
- package/dist/src/click-button.d.ts +0 -5
- package/dist/src/compatibility-policy.js +0 -1
- package/dist/src/gesture-plan-types.js +0 -1
- package/dist/src/gesture-plan.js +0 -1
- package/dist/src/launch-console.js +0 -1
- package/dist/src/recording-export-quality.js +0 -15
- package/dist/src/rolldown-runtime.js +0 -1
- package/dist/src/runtime2.js +0 -1
- package/dist/src/sdk-app-inventory.d.ts +0 -4
- package/dist/src/sdk-app-inventory.js +0 -1
- package/dist/src/snapshot-diagnostics.js +0 -6
- package/dist/src/xml.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{C as t,j as n,p as r}from"./sdk-android-adb.js";import{n as i,t as a}from"./version.js";import{c as o,g as s,o as c,s as ee}from"./sdk-device.js";import{c as te,o as ne,s as re}from"./boot-diagnostics.js";import{a as l,s as ie}from"./tool-provider.js";import u from"node:crypto";import d,{promises as f}from"node:fs";import p from"node:os";import m from"node:path";function h(e,t={}){let n=ne(t.simulatorSetPath);return n?[`simctl`,`--set`,n,...e]:[`simctl`,...e]}function g(e,t){return!ee(e)||e.kind!==`simulator`?[`simctl`,...t]:h(t,{simulatorSetPath:e.simulatorSetPath})}function ae(e,t,n){return l(g(e,t),n)}const _={iOS:{sdkName:{simulator:`iphonesimulator`,device:`iphoneos`},derivedBaseName:{simulator:`ios-simulator`,device:`ios-device`},xctestrunHints:{simulator:{preferred:[`iphonesimulator`],disallowed:[`iphoneos`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`iphoneos`],disallowed:[`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}},tvOS:{sdkName:{simulator:`appletvsimulator`,device:`appletvos`},derivedBaseName:{simulator:`tvos-simulator`,device:`tvos-device`},xctestrunHints:{simulator:{preferred:[`appletvsimulator`],disallowed:[`appletvos`,`iphoneos`,`iphonesimulator`,`macos`]},device:{preferred:[`appletvos`],disallowed:[`appletvsimulator`,`iphoneos`,`iphonesimulator`,`macos`]}}},macOS:{sdkName:{simulator:`macosx`,device:`macosx`},derivedBaseName:{simulator:`macos`,device:`macos`},xctestrunHints:{simulator:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]},device:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]}}},visionOS:{sdkName:{simulator:`xrsimulator`,device:`xros`},derivedBaseName:{simulator:`visionos-simulator`,device:`visionos-device`},xctestrunHints:{simulator:{preferred:[`xrsimulator`],disallowed:[`xros`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`xros`],disallowed:[`xrsimulator`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}}};function v(t){if(!c(t.platform))throw new e(`UNSUPPORTED_PLATFORM`,`Unsupported platform for Apple runner: ${t.platform}`);return o(t)?`macOS`:s(t.target,t.appleOs)}function oe(e,t){return _[e].sdkName[y(t)]}function se(e){return _[v(e)].derivedBaseName[y(e.kind)]}function ce(e){return _[v(e)].xctestrunHints[y(e.kind)]}function le(e){let t=v(e);return t===`macOS`?`platform=macOS,arch=${b()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`platform=${t},id=${e.id}`}function ue(e){let t=v(e);return t===`macOS`?`platform=macOS,arch=${b()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`generic/platform=${t}`}function de(e){let t=v(e);return t===`macOS`?`platform=macOS,arch=${b()}`:e.kind===`simulator`?`generic/platform=${t} Simulator`:`generic/platform=${t}`}function y(e){return e===`simulator`?`simulator`:`device`}function b(){return process.arch===`arm64`?`arm64`:`x86_64`}const fe=new Set;function x(e={}){let t=new Map,n=e.now??(()=>Date.now()),r=e=>{e?.timer&&clearTimeout(e.timer)},i={get(e){let r=t.get(e);if(r){if(r.expiresAt!==void 0&&r.expiresAt<=n()){i.delete(e);return}return r.value}},set(i,a){r(t.get(i));let o=pe(e.ttlMs,n),s={value:a,expiresAt:o};e.scheduleExpiry&&o!==void 0&&(s.timer=setTimeout(()=>{t.delete(i)},Math.max(0,o-n())),s.timer.unref?.()),t.set(i,s)},delete(e){let n=t.get(e);return n?(r(n),t.delete(e)):!1},clear(){for(let e of t.values())r(e);t.clear()}};return fe.add(i.clear),i}function pe(e,t){if(!(e===void 0||!Number.isFinite(e)))return t()+Math.max(0,e)}const me=m.join(`apple`,`runner`,`AgentDeviceRunner`),he=m.join(`dist`,`apple`,`runner`,`AgentDeviceRunner`);function S(e){let t=m.join(e,me);return d.existsSync(t)?t:m.join(e,he)}function ge(e){return m.join(S(e),`AgentDeviceRunner.xcodeproj`)}const _e=m.join(p.homedir(),`.agent-device`,`apple-runner`),ve=`.agent-device-runner-cache.json`,ye=[`-IDEPackageSupportDisableManifestSandbox=1`,`-IDEPackageSupportDisablePluginExecutionSandbox=1`,`ENABLE_USER_SCRIPT_SANDBOXING=NO`],C=x();function w(e){return e?.trim()??``}function T(e=process.env){return w(e.AGENT_DEVICE_IOS_BUNDLE_ID)||w(e.AGENT_DEVICE_IOS_RUNNER_APP_BUNDLE_ID)||`com.callstack.agentdevice.runner`}function E(e=process.env){return w(e.AGENT_DEVICE_IOS_RUNNER_TEST_BUNDLE_ID)||`${T(e)}.uitests`}function be(e=process.env){let t=T(e),n=E(e);return Array.from(new Set([w(e.AGENT_DEVICE_IOS_RUNNER_CONTAINER_BUNDLE_ID),`${n}.xctrunner`,t].filter(e=>e.length>0)))}const D=be(process.env);function xe(e,t=a()){let n=v(e);return{schemaVersion:2,packageVersion:i(t),runnerSourceFingerprint:Oe(t),...Se(n,e.kind),platformName:n,deviceKind:e.kind,target:e.target??`mobile`,buildDestinationFamily:de(e),runnerBundleBuildSettings:N(process.env),runnerSigningBuildSettings:M(process.env,e.kind===`device`,e),runnerPerformanceBuildSettings:P(),runnerSandboxBuildArgs:F()}}function Se(e,t){let n=Ce(O(`xcodebuild`,[`-version`])),r=oe(e,t);return{xcodeVersion:n.version,xcodeBuildVersion:n.buildVersion,sdkName:r,sdkVersion:O(`xcrun`,[`--sdk`,r,`--show-sdk-version`]),sdkBuildVersion:O(`xcrun`,[`--sdk`,r,`--show-sdk-build-version`])}}function O(e,n){let r=JSON.stringify([e,n]),i=C.get(r);if(i!==void 0)return i;try{let i=t(e,n,{allowFailure:!0,timeoutMs:5e3,maxBuffer:128*1024}),a=i.exitCode===0&&i.stdout.trim()||`unknown`;return C.set(r,a),a}catch{return C.set(r,`unknown`),`unknown`}}function Ce(e){return{version:e.match(/^Xcode\s+(.+)$/m)?.[1]?.trim()||`unknown`,buildVersion:e.match(/^Build version\s+(.+)$/m)?.[1]?.trim()||`unknown`}}function we(e,t){let n=process.env.AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH?.trim();if(n)return m.resolve(n);let r=Ee(t),i=Te(e);return m.join(i,r)}function Te(e){return m.join(_e,`derived`,se(e))}function Ee(e){return`cache-${u.createHash(`sha256`).update(De(k(e))).digest(`hex`).slice(0,16)}`}function k(e){let{artifacts:t,packageVersion:n,...r}=e;return r}function De(e){return JSON.stringify(A(e))}function A(e){return Array.isArray(e)?e.map(e=>A(e)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,A(t)]))}const j=new Map;function Oe(e){let t=S(e),n=Ae(t),r=ke(t,n),i=j.get(t);if(i?.fileStatsFingerprint===r)return i.sourceFingerprint;let a=u.createHash(`sha256`);for(let e of n){let n=m.relative(t,e);a.update(n),a.update(`\0`),a.update(d.readFileSync(e)),a.update(`\0`)}let o=a.digest(`hex`);return j.set(t,{fileStatsFingerprint:r,sourceFingerprint:o}),o}function ke(e,t){let n=u.createHash(`sha256`);for(let r of t){let t=m.relative(e,r),i=d.statSync(r);n.update(t),n.update(`\0`),n.update(String(i.size)),n.update(`\0`),n.update(String(Math.trunc(i.mtimeMs))),n.update(`\0`)}return n.digest(`hex`)}function Ae(e){if(!d.existsSync(e))return[];let t=[],n=[e];for(;n.length>0;){let e=n.pop();for(let r of d.readdirSync(e,{withFileTypes:!0})){let i=m.join(e,r.name);if(r.isDirectory()){if(r.name===`xcuserdata`)continue;n.push(i);continue}r.isFile()&&je(r.name,i)&&t.push(i)}}return t.sort((e,t)=>e.localeCompare(t))}function je(e,t){return e===`project.pbxproj`?t.includes(`${m.sep}.xcodeproj${m.sep}`):[`.jpg`,`.json`,`.png`,`.swift`,`.m`,`.h`,`.plist`,`.entitlements`,`.xctestplan`,`.xcconfig`,`.storyboard`,`.xib`].includes(m.extname(e))}function Me(e){return o(e)||e.kind===`device`?`-maximum-concurrent-test-device-destinations`:`-maximum-concurrent-test-simulator-destinations`}function M(e=process.env,t=!1,n={platform:`apple`}){if(o(n))return[`CODE_SIGNING_ALLOWED=NO`,`CODE_SIGNING_REQUIRED=NO`,`CODE_SIGN_IDENTITY=`,`DEVELOPMENT_TEAM=`];if(!t)return[];let r=e.AGENT_DEVICE_IOS_TEAM_ID?.trim()||``,i=e.AGENT_DEVICE_IOS_SIGNING_IDENTITY?.trim()||``,a=e.AGENT_DEVICE_IOS_PROVISIONING_PROFILE?.trim()||``,s=[`CODE_SIGN_STYLE=Automatic`];return r&&s.push(`DEVELOPMENT_TEAM=${r}`),i&&s.push(`CODE_SIGN_IDENTITY=${i}`),a&&s.push(`PROVISIONING_PROFILE_SPECIFIER=${a}`),s}function N(e=process.env){let t=T(e),n=E(e);return[`AGENT_DEVICE_IOS_RUNNER_APP_BUNDLE_ID=${t}`,`AGENT_DEVICE_IOS_RUNNER_TEST_BUNDLE_ID=${n}`]}function P(){return[`COMPILER_INDEX_STORE_ENABLE=NO`,`ENABLE_CODE_COVERAGE=NO`,`ONLY_ACTIVE_ARCH=YES`,`ENABLE_PREVIEWS=NO`,`ENABLE_DEBUG_DYLIB=NO`]}function F(){return[...ye,`OTHER_SWIFT_FLAGS=${Ne(process.env)}`]}function Ne(e){return te(e.AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS)?`$(inherited) -disable-sandbox -D AGENT_DEVICE_RUNNER_UNIT_TESTS`:`$(inherited) -disable-sandbox`}const Pe=18e4,Fe=6e4,Ie=6e4,Le=1e4,Re=15e3,ze=2e4,Be=15e3,I=2e4,Ve=1e3,He=5e3;async function L(t,n,i={}){let a=[`devicectl`,...t],o=await l(a,{allowFailure:!0,timeoutMs:i.timeoutMs??2e4});if(o.exitCode===0)return;let{stdout:s,stderr:c}=o;if(!i.tolerateOutput?.(s,c))throw new e(`COMMAND_FAILED`,`Failed to ${n.action}`,r(o,{cmd:`xcrun`,args:a,stdout:s,stderr:c,deviceId:n.deviceId,hint:G(s,c)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}))}async function R(e,t){return Ye(qe(await B(e,{jsonPrefix:`agent-device-ios-apps`,args:[`devicectl`,`device`,`info`,`apps`,`--device`,e.id,`--include-all-apps`],failureMessage:`Failed to list iOS apps`,parseFailureMessage:`Failed to parse iOS apps list`})),t)}async function Ue(t){let n=await B(t,{jsonPrefix:`agent-device-ios-processes`,args:[`devicectl`,`device`,`info`,`processes`,`--device`,t.id],failureMessage:`Failed to list iOS processes`,parseFailureMessage:`Failed to parse iOS process list`,fallbackHint:W});if(!Ge(n))throw new e(`COMMAND_FAILED`,`Unsupported iOS process list response`,{deviceId:t.id,hint:W});return Je(n)}async function We(e,t){let{appBundleUrl:n,processes:r}=await z(e,t),i=r.sort((e,t)=>H(e,n)-H(t,n))[0];i&&await B(e,{jsonPrefix:`agent-device-ios-process-terminate`,args:[`devicectl`,`device`,`process`,`terminate`,`--device`,e.id,`--pid`,String(i.pid),`--kill`],failureMessage:`Failed to terminate iOS app`,parseFailureMessage:`Failed to parse iOS process termination response`,tolerateFailurePayload:Ke})}async function z(t,n){let r=(await R(t,`all`)).find(e=>e.bundleId===n);if(!r)throw new e(`APP_NOT_INSTALLED`,`No iOS device app found for ${n}`,{appBundleId:n,deviceId:t.id});if(!r.url)throw new e(`COMMAND_FAILED`,`Missing app bundle URL for ${n}`,{appBundleId:n,deviceId:t.id,hint:`Installed-app metadata from devicectl did not include the bundle URL required to match running processes. Use an Xcode/CoreDevice toolchain that reports app URLs.`});let i=r.url.replace(/\/+$/,``);return{appBundleUrl:i,processes:(await Ue(t)).filter(e=>e.executable.startsWith(`${i}/`))}}async function B(t,n){let i=m.join(p.tmpdir(),`${n.jsonPrefix}-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`),a=[...n.args,`--json-output`,i],o=await l(a,{allowFailure:!0,timeoutMs:2e4});try{if(o.exitCode!==0){let{stdout:s,stderr:c}=o;if(n.tolerateFailurePayload){let e=await V(i).catch(()=>void 0);if(e!==void 0&&n.tolerateFailurePayload(e))return e}throw new e(`COMMAND_FAILED`,n.failureMessage,r(o,{cmd:`xcrun`,args:a,stdout:s,stderr:c,deviceId:t.id,hint:G(s,c)??n.fallbackHint??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}))}return await V(i)}catch(r){throw r instanceof e?r:new e(`COMMAND_FAILED`,n.parseFailureMessage,{deviceId:t.id,cause:String(r)})}finally{await f.unlink(i).catch(()=>{})}}async function V(e){return JSON.parse(await f.readFile(e,`utf8`))}function H(e,t){return e.executable.slice(t.length+1).split(`/`).length}function Ge(e){return Array.isArray(e?.result?.runningProcesses)}function Ke(e){let t=e?.error?.userInfo?.NSUnderlyingError?.error;return t?.domain===`NSPOSIXErrorDomain`&&t.code===3}function qe(e){let t=e?.result?.apps;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!e||typeof e!=`object`)continue;let t=typeof e.bundleIdentifier==`string`?e.bundleIdentifier.trim():``;if(!t)continue;let r=typeof e.name==`string`&&e.name.trim().length>0?e.name.trim():t,i=typeof e.url==`string`&&e.url.trim().length>0?e.url.trim():void 0;n.push({bundleId:t,name:r,url:i})}return n}function Je(e){let t=e?.result?.runningProcesses;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!e||typeof e!=`object`)continue;let t=typeof e.executable==`string`?e.executable.trim():``,r=typeof e.processIdentifier==`number`&&Number.isFinite(e.processIdentifier)?e.processIdentifier:NaN;!t||!Number.isFinite(r)||n.push({executable:t,pid:r})}return n}function Ye(e,t){return ie(e,t)}const U=`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`,W=`This Xcode/CoreDevice toolchain must support 'devicectl device info processes' with JSON runningProcesses so agent-device can resolve app process IDs. Inspect diagnostics for the exact devicectl API failure.`;function G(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`device is busy`)&&n.includes(`connecting`)?`iOS device is still connecting. Keep it unlocked and connected by cable until it is fully available in Xcode Devices, then retry.`:n.includes(`coredeviceservice`)&&n.includes(`timed out`)?`CoreDevice service timed out. Reconnect the device and retry; if it persists restart Xcode and the iOS device.`:null}function K(e,t){return g(e,t)}function Xe(e,t,n){return l(K(e,t),n)}function q(e){return e.includes(`not installed`)||e.includes(`not found`)||e.includes(`no such file`)}async function Ze(e,t){return await R(e,t)}async function Qe(e,t){await L([`device`,`install`,`app`,`--device`,e.id,t],{action:`install iOS app`,deviceId:e.id},{timeoutMs:12e4})}async function $e(e,t){await L([`device`,`uninstall`,`app`,`--device`,e.id,t],{action:`uninstall iOS app ${t}`,deviceId:e.id},{tolerateOutput:(e,t)=>q(`${e}\n${t}`.toLowerCase())})}async function et(e,t){await We(e,t)}async function tt(e,t){return await z(e,t)}const J=1e4;async function nt(e,t,n={}){let r=[`device`,`process`,`launch`,`--device`,e.id,t];n.payloadUrl&&r.push(`--payload-url`,n.payloadUrl),n.launchArgs&&n.launchArgs.length>0&&r.push(`--`,...n.launchArgs),await L(r,{action:`launch iOS app`,deviceId:e.id})}async function rt(t){try{let{result:n,parsed:i}=await Y(t.id,15e3,3e3);if(n.exitCode===0){if(!i.parsed)throw new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{kind:`probe_inconclusive`,deviceId:t.id,stdout:n.stdout,stderr:n.stderr,hint:`CoreDevice returned success but readiness JSON output was missing or invalid. Retry; if it persists restart Xcode and the iOS device.`});let r=i.tunnelState?.toLowerCase();if(r===`connecting`)throw new e(`COMMAND_FAILED`,`iOS device is not ready for automation`,{kind:`not_ready`,deviceId:t.id,tunnelState:r,hint:`Device tunnel is still connecting. Keep the device unlocked and connected by cable until it is fully available in Xcode Devices, then retry.`});return}throw new e(`COMMAND_FAILED`,`iOS device is not ready for automation`,r(n,{kind:`not_ready`,deviceId:t.id,tunnelState:i.tunnelState,hint:Z(n.stdout,n.stderr)}))}catch(e){throw it(t.id,e)}}function it(t,n){return!(n instanceof e)||n.code!==`COMMAND_FAILED`?ot(t,n):(typeof n.details?.kind==`string`?n.details.kind:``)===`not_ready`?n:at(t,n)}function at(t,n){let r=n.details??{},i=String(r.stdout??``),a=String(r.stderr??``),o=Number(r.timeoutMs??15e3),s=`CoreDevice did not respond within ${o}ms. Keep the device unlocked and trusted, then retry; if it persists restart Xcode and the iOS device.`;return new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{deviceId:t,cause:n.message,timeoutMs:o,stdout:i,stderr:a,hint:i||a?Z(i,a):s},n)}function ot(t,n){return new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{deviceId:t,hint:`Reconnect the device, keep it unlocked, and retry.`},n instanceof Error?n:void 0)}async function st(e,t){if(typeof t==`number`&&t<=0)return null;let n=typeof t==`number`?Math.max(1,Math.min(J,t)):J;try{let t=await Y(e.id,n);return t.result.exitCode!==0||!t.parsed.parsed||t.parsed.outcome&&t.parsed.outcome!==`success`?null:t.parsed.tunnelIp??null}catch{return null}}async function Y(e,t,n=0){let r=m.join(p.tmpdir(),`agent-device-coredevice-info-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`),i=Math.max(1,Math.ceil(t/1e3));try{return{result:await l([`devicectl`,`device`,`info`,`details`,`--device`,e,`--json-output`,r,`--timeout`,String(i)],{allowFailure:!0,timeoutMs:t+n}),parsed:await ct(r)}}finally{await f.rm(r,{force:!0}).catch(()=>{})}}async function ct(e){try{return{parsed:!0,...lt(JSON.parse(await f.readFile(e,`utf8`)))}}catch{return{parsed:!1}}}function lt(e){let t=e?.result;if(!t||typeof t!=`object`)return{};let n=t.connectionProperties,r=t.device?.connectionProperties,i=X(n?.tunnelState)??X(r?.tunnelState),a=X(n?.tunnelIPAddress)??X(r?.tunnelIPAddress),o=X(e?.info?.outcome);return{...o?{outcome:o}:{},...i?{tunnelState:i}:{},...a?{tunnelIp:a}:{}}}function X(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function Z(e,t){return G(e,t)||(`${e}\n${t}`.toLowerCase().includes(`timed out waiting for all destinations`)?`Xcode destination did not become available in time. Keep device unlocked and retry.`:U)}async function Q(t,n,r,i=I){let a=re.fromTimeoutMs(i),o={exitCode:1,stdout:``,stderr:``};for(let e of D)if(o=await l([`devicectl`,`device`,`copy`,`from`,`--device`,t.id,`--source`,n,`--destination`,r,`--domain-type`,`appDataContainer`,`--domain-identifier`,e],{allowFailure:!0,timeoutMs:ut(a,i)}),o.exitCode===0)return;throw new e(`COMMAND_FAILED`,`Failed to copy runner file from iOS device: ${o.stderr.trim()||o.stdout.trim()||`devicectl exited with code ${o.exitCode}`}`)}function ut(t,n){let r=t.remainingMs();if(r>0)return r;throw new e(`COMMAND_FAILED`,`iOS runner file copy timed out after ${n}ms`,{timeoutMs:n,step:`runner file copy`})}function $(t){if(!(t instanceof e))return{reason:t instanceof Error?t.message:String(t)};let n=t.details??{},r=Array.isArray(n.args)?n.args.filter(e=>typeof e==`string`).join(` `):void 0;return{errorCode:t.code,reason:t.message,timeoutMs:typeof n.timeoutMs==`number`?n.timeoutMs:void 0,exitCode:typeof n.exitCode==`number`?n.exitCode:void 0,stderr:typeof n.stderr==`string`&&n.stderr.trim()?n.stderr:void 0,stdout:typeof n.stdout==`string`&&n.stdout.trim()?n.stdout:void 0,commandArgs:r}}function dt(e){let t=e.details??{},n=typeof t.stdout==`string`?t.stdout:``,r=typeof t.stderr==`string`?t.stderr:``,i=Array.isArray(t.args)?t.args.filter(e=>typeof e==`string`).join(` `):``;return`${e.message}\n${n}\n${r}\n${i}`.toLowerCase()}async function ft(e,t,n){if(!n.preferRunner)try{await L([`device`,`screenshot`,`--device`,e.id,t],{action:`capture iOS screenshot`,deviceId:e.id});return}catch(t){if(!vt(t))throw t;_t(e,t)}let r=await mt(e,n,!1);await ht(r,t)||await Q(e,gt(r),t)}async function pt(t,n,r){if(!await ht(await mt(t,r,!0),n))throw new e(`COMMAND_FAILED`,`Failed to capture iOS screenshot: XCTest runner returned no inline image`,{deviceId:t.id,backend:`xctest`})}async function mt(e,t,n){return await t.runRunnerCommand(e,{command:`screenshot`,appBundleId:t.appBundleId,fullscreen:t.fullscreen,inlineScreenshot:n},t.runnerOptions??{})}async function ht(e,t){let n=e.imageBase64;return typeof n!=`string`||n.length===0?!1:(await f.writeFile(t,Buffer.from(n,`base64`)),!0)}function gt(t){let n=t.message;if(typeof n==`string`&&n.length>0)return n;throw new e(`COMMAND_FAILED`,`Failed to capture iOS screenshot: runner returned no file path`)}function _t(e,t){n({level:`warn`,phase:`ios_screenshot_fallback`,data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,from:`devicectl_screenshot`,to:`runner`,...$(t)}})}function vt(t){if(!(t instanceof e)||t.code!==`COMMAND_FAILED`)return!1;let n=dt(t);return n.includes(`unknown option '--device'`)||n.includes(`unknown subcommand`)&&n.includes(`screenshot`)||n.includes(`unrecognized subcommand`)&&n.includes(`screenshot`)}const yt={coredevice:{backend:`coredevice`,assertAppInstallationSupported:()=>{},ensureReady:rt,listApps:Ze,installApp:Qe,uninstallApp:$e,launchApp:nt,terminateApp:async(e,t)=>await et(e,t),resolveAppProcesses:tt,captureScreenshot:ft,copyRunnerFile:Q,resolveRunnerTransport:async(e,t)=>({kind:`network`,tunnelIp:await st(e,t)})},xctest:{backend:`xctest`,assertAppInstallationSupported:xt,ensureReady:Et,listApps:Ct,installApp:St,uninstallApp:St,launchApp:Dt,terminateApp:Ot,resolveAppProcesses:wt,captureScreenshot:pt,copyRunnerFile:Tt,resolveRunnerTransport:async()=>({kind:`usbmux`})}};function bt(e){return yt[e.iosPhysicalDeviceBackend===`xctest`?`xctest`:`coredevice`]}function xt(t){throw new e(`UNSUPPORTED_OPERATION`,`Installing apps is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`,hint:`Install the app with Xcode, then open it in agent-device by bundle ID.`})}async function St(e){return xt(e)}async function Ct(t){throw new e(`UNSUPPORTED_OPERATION`,`App inventory is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`,hint:`Use an installed app bundle ID when opening the device.`})}async function wt(t){throw new e(`UNSUPPORTED_OPERATION`,`Process lookup is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`,hint:`Use a CoreDevice-backed iOS device for performance sampling.`})}async function Tt(t){throw new e(`UNSUPPORTED_OPERATION`,`Runner file copy is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`})}async function Et(t){let n=[`xcdevice`,`wait`,`--both`,`--timeout=15`,t.id],i=await l(n,{allowFailure:!0,timeoutMs:18e3});if(i.exitCode!==0)throw new e(`COMMAND_FAILED`,`iOS device is not ready for XCTest automation`,r(i,{cmd:`xcrun`,args:n,deviceId:t.id,backend:`xctest`,hint:"Keep the device unlocked, trusted, connected, and visible in `xcrun xcdevice list`, then retry."}))}async function Dt(t,n,r){if(r.payloadUrl||r.launchArgs&&r.launchArgs.length>0)throw new e(`UNSUPPORTED_OPERATION`,`XCTest-backed physical iOS devices do not support deep links or launch arguments during open.`,{deviceId:t.id,backend:`xctest`,hint:`Open the installed app by bundle ID without a URL or --launch-args.`});await r.runRunnerCommand(t,{command:`activate`,appBundleId:n},r.runnerOptions??{})}async function Ot(e,t,n){await n.runRunnerCommand(e,{command:`terminate`,appBundleId:t},n.runnerOptions??{})}export{De as A,T as C,P as D,Me as E,ce as F,h as I,g as L,x as M,ue as N,F as O,le as P,ae as R,xe as S,we as T,ze as _,Xe as a,ve as b,G as c,I as d,Fe as f,Be as g,He as h,q as i,ge as j,M as k,Ie as l,Ve as m,dt as n,K as o,Le as p,$ as r,U as s,bt as t,Pe as u,Re as v,N as w,k as x,D as y};
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{c as t,g as n,o as r,s as i}from"./sdk-device.js";import{C as a,j as o,p as s}from"./sdk-android-adb.js";import{n as c,t as ee}from"./version.js";import{c as te,o as ne,s as re}from"./boot-diagnostics.js";import{a as l,s as ie}from"./tool-provider.js";import u from"node:path";import d from"node:crypto";import f,{promises as p}from"node:fs";import m from"node:os";function h(e,t={}){let n=ne(t.simulatorSetPath);return n?[`simctl`,`--set`,n,...e]:[`simctl`,...e]}function g(e,t){return!i(e)||e.kind!==`simulator`?[`simctl`,...t]:h(t,{simulatorSetPath:e.simulatorSetPath})}function ae(e,t,n){return l(g(e,t),n)}const _={iOS:{sdkName:{simulator:`iphonesimulator`,device:`iphoneos`},derivedBaseName:{simulator:`ios-simulator`,device:`ios-device`},xctestrunHints:{simulator:{preferred:[`iphonesimulator`],disallowed:[`iphoneos`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`iphoneos`],disallowed:[`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}},tvOS:{sdkName:{simulator:`appletvsimulator`,device:`appletvos`},derivedBaseName:{simulator:`tvos-simulator`,device:`tvos-device`},xctestrunHints:{simulator:{preferred:[`appletvsimulator`],disallowed:[`appletvos`,`iphoneos`,`iphonesimulator`,`macos`]},device:{preferred:[`appletvos`],disallowed:[`appletvsimulator`,`iphoneos`,`iphonesimulator`,`macos`]}}},macOS:{sdkName:{simulator:`macosx`,device:`macosx`},derivedBaseName:{simulator:`macos`,device:`macos`},xctestrunHints:{simulator:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]},device:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]}}},visionOS:{sdkName:{simulator:`xrsimulator`,device:`xros`},derivedBaseName:{simulator:`visionos-simulator`,device:`visionos-device`},xctestrunHints:{simulator:{preferred:[`xrsimulator`],disallowed:[`xros`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`xros`],disallowed:[`xrsimulator`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}}};function v(i){if(!r(i.platform))throw new e(`UNSUPPORTED_PLATFORM`,`Unsupported platform for Apple runner: ${i.platform}`);return t(i)?`macOS`:n(i.target,i.appleOs)}function oe(e,t){return _[e].sdkName[y(t)]}function se(e){return _[v(e)].derivedBaseName[y(e.kind)]}function ce(e){return _[v(e)].xctestrunHints[y(e.kind)]}function le(e){let t=v(e);return t===`macOS`?`platform=macOS,arch=${b()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`platform=${t},id=${e.id}`}function ue(e){let t=v(e);return t===`macOS`?`platform=macOS,arch=${b()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`generic/platform=${t}`}function de(e){let t=v(e);return t===`macOS`?`platform=macOS,arch=${b()}`:e.kind===`simulator`?`generic/platform=${t} Simulator`:`generic/platform=${t}`}function y(e){return e===`simulator`?`simulator`:`device`}function b(){return process.arch===`arm64`?`arm64`:`x86_64`}const fe=new Set;function x(e={}){let t=new Map,n=e.now??(()=>Date.now()),r=e=>{e?.timer&&clearTimeout(e.timer)},i={get(e){let r=t.get(e);if(r){if(r.expiresAt!==void 0&&r.expiresAt<=n()){i.delete(e);return}return r.value}},set(i,a){r(t.get(i));let o=pe(e.ttlMs,n),s={value:a,expiresAt:o};e.scheduleExpiry&&o!==void 0&&(s.timer=setTimeout(()=>{t.delete(i)},Math.max(0,o-n())),s.timer.unref?.()),t.set(i,s)},delete(e){let n=t.get(e);return n?(r(n),t.delete(e)):!1},clear(){for(let e of t.values())r(e);t.clear()}};return fe.add(i.clear),i}function pe(e,t){if(!(e===void 0||!Number.isFinite(e)))return t()+Math.max(0,e)}const me=u.join(`apple`,`runner`,`AgentDeviceRunner`),he=u.join(`dist`,`apple`,`runner`,`AgentDeviceRunner`);function S(e){let t=u.join(e,me);return f.existsSync(t)?t:u.join(e,he)}function ge(e){return u.join(S(e),`AgentDeviceRunner.xcodeproj`)}const _e=u.join(m.homedir(),`.agent-device`,`apple-runner`),ve=`.agent-device-runner-cache.json`,ye=[`-IDEPackageSupportDisableManifestSandbox=1`,`-IDEPackageSupportDisablePluginExecutionSandbox=1`,`ENABLE_USER_SCRIPT_SANDBOXING=NO`],C=x();function w(e){return e?.trim()??``}function T(e=process.env){return w(e.AGENT_DEVICE_IOS_BUNDLE_ID)||w(e.AGENT_DEVICE_IOS_RUNNER_APP_BUNDLE_ID)||`com.callstack.agentdevice.runner`}function E(e=process.env){return w(e.AGENT_DEVICE_IOS_RUNNER_TEST_BUNDLE_ID)||`${T(e)}.uitests`}function be(e=process.env){let t=T(e),n=E(e);return Array.from(new Set([w(e.AGENT_DEVICE_IOS_RUNNER_CONTAINER_BUNDLE_ID),`${n}.xctrunner`,t].filter(e=>e.length>0)))}const D=be(process.env);function xe(e,t=ee()){let n=v(e);return{schemaVersion:2,packageVersion:c(t),runnerSourceFingerprint:Oe(t),...Se(n,e.kind),platformName:n,deviceKind:e.kind,target:e.target??`mobile`,buildDestinationFamily:de(e),runnerBundleBuildSettings:N(process.env),runnerSigningBuildSettings:M(process.env,e.kind===`device`,e),runnerPerformanceBuildSettings:P(),runnerSandboxBuildArgs:F()}}function Se(e,t){let n=Ce(O(`xcodebuild`,[`-version`])),r=oe(e,t);return{xcodeVersion:n.version,xcodeBuildVersion:n.buildVersion,sdkName:r,sdkVersion:O(`xcrun`,[`--sdk`,r,`--show-sdk-version`]),sdkBuildVersion:O(`xcrun`,[`--sdk`,r,`--show-sdk-build-version`])}}function O(e,t){let n=JSON.stringify([e,t]),r=C.get(n);if(r!==void 0)return r;try{let r=a(e,t,{allowFailure:!0,timeoutMs:5e3,maxBuffer:128*1024}),i=r.exitCode===0&&r.stdout.trim()||`unknown`;return C.set(n,i),i}catch{return C.set(n,`unknown`),`unknown`}}function Ce(e){return{version:e.match(/^Xcode\s+(.+)$/m)?.[1]?.trim()||`unknown`,buildVersion:e.match(/^Build version\s+(.+)$/m)?.[1]?.trim()||`unknown`}}function we(e,t){let n=process.env.AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH?.trim();if(n)return u.resolve(n);let r=Ee(t),i=Te(e);return u.join(i,r)}function Te(e){return u.join(_e,`derived`,se(e))}function Ee(e){return`cache-${d.createHash(`sha256`).update(De(k(e))).digest(`hex`).slice(0,16)}`}function k(e){let{artifacts:t,packageVersion:n,...r}=e;return r}function De(e){return JSON.stringify(A(e))}function A(e){return Array.isArray(e)?e.map(e=>A(e)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,A(t)]))}const j=new Map;function Oe(e){let t=S(e),n=Ae(t),r=ke(t,n),i=j.get(t);if(i?.fileStatsFingerprint===r)return i.sourceFingerprint;let a=d.createHash(`sha256`);for(let e of n){let n=u.relative(t,e);a.update(n),a.update(`\0`),a.update(f.readFileSync(e)),a.update(`\0`)}let o=a.digest(`hex`);return j.set(t,{fileStatsFingerprint:r,sourceFingerprint:o}),o}function ke(e,t){let n=d.createHash(`sha256`);for(let r of t){let t=u.relative(e,r),i=f.statSync(r);n.update(t),n.update(`\0`),n.update(String(i.size)),n.update(`\0`),n.update(String(Math.trunc(i.mtimeMs))),n.update(`\0`)}return n.digest(`hex`)}function Ae(e){if(!f.existsSync(e))return[];let t=[],n=[e];for(;n.length>0;){let e=n.pop();for(let r of f.readdirSync(e,{withFileTypes:!0})){let i=u.join(e,r.name);if(r.isDirectory()){if(r.name===`xcuserdata`)continue;n.push(i);continue}r.isFile()&&je(r.name,i)&&t.push(i)}}return t.sort((e,t)=>e.localeCompare(t))}function je(e,t){return e===`project.pbxproj`?t.includes(`${u.sep}.xcodeproj${u.sep}`):[`.jpg`,`.json`,`.png`,`.swift`,`.m`,`.h`,`.plist`,`.entitlements`,`.xctestplan`,`.xcconfig`,`.storyboard`,`.xib`].includes(u.extname(e))}function Me(e){return t(e)||e.kind===`device`?`-maximum-concurrent-test-device-destinations`:`-maximum-concurrent-test-simulator-destinations`}function M(e=process.env,n=!1,r={platform:`apple`}){if(t(r))return[`CODE_SIGNING_ALLOWED=NO`,`CODE_SIGNING_REQUIRED=NO`,`CODE_SIGN_IDENTITY=`,`DEVELOPMENT_TEAM=`];if(!n)return[];let i=e.AGENT_DEVICE_IOS_TEAM_ID?.trim()||``,a=e.AGENT_DEVICE_IOS_SIGNING_IDENTITY?.trim()||``,o=e.AGENT_DEVICE_IOS_PROVISIONING_PROFILE?.trim()||``,s=[`CODE_SIGN_STYLE=Automatic`];return i&&s.push(`DEVELOPMENT_TEAM=${i}`),a&&s.push(`CODE_SIGN_IDENTITY=${a}`),o&&s.push(`PROVISIONING_PROFILE_SPECIFIER=${o}`),s}function N(e=process.env){let t=T(e),n=E(e);return[`AGENT_DEVICE_IOS_RUNNER_APP_BUNDLE_ID=${t}`,`AGENT_DEVICE_IOS_RUNNER_TEST_BUNDLE_ID=${n}`]}function P(){return[`COMPILER_INDEX_STORE_ENABLE=NO`,`ENABLE_CODE_COVERAGE=NO`,`ONLY_ACTIVE_ARCH=YES`,`ENABLE_PREVIEWS=NO`,`ENABLE_DEBUG_DYLIB=NO`]}function F(){return[...ye,`OTHER_SWIFT_FLAGS=${Ne(process.env)}`]}function Ne(e){return te(e.AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS)?`$(inherited) -disable-sandbox -D AGENT_DEVICE_RUNNER_UNIT_TESTS`:`$(inherited) -disable-sandbox`}const Pe=18e4,Fe=6e4,Ie=6e4,Le=1e4,Re=15e3,ze=2e4,Be=15e3,I=2e4,Ve=1e3,He=5e3;async function L(t,n,r={}){let i=[`devicectl`,...t],a=await l(i,{allowFailure:!0,timeoutMs:r.timeoutMs??2e4});if(a.exitCode===0)return;let{stdout:o,stderr:c}=a;if(!r.tolerateOutput?.(o,c))throw new e(`COMMAND_FAILED`,`Failed to ${n.action}`,s(a,{cmd:`xcrun`,args:i,stdout:o,stderr:c,deviceId:n.deviceId,hint:G(o,c)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}))}async function R(e,t){return Ye(qe(await B(e,{jsonPrefix:`agent-device-ios-apps`,args:[`devicectl`,`device`,`info`,`apps`,`--device`,e.id,`--include-all-apps`],failureMessage:`Failed to list iOS apps`,parseFailureMessage:`Failed to parse iOS apps list`})),t)}async function Ue(t){let n=await B(t,{jsonPrefix:`agent-device-ios-processes`,args:[`devicectl`,`device`,`info`,`processes`,`--device`,t.id],failureMessage:`Failed to list iOS processes`,parseFailureMessage:`Failed to parse iOS process list`,fallbackHint:W});if(!Ge(n))throw new e(`COMMAND_FAILED`,`Unsupported iOS process list response`,{deviceId:t.id,hint:W});return Je(n)}async function We(e,t){let{appBundleUrl:n,processes:r}=await z(e,t),i=r.sort((e,t)=>H(e,n)-H(t,n))[0];i&&await B(e,{jsonPrefix:`agent-device-ios-process-terminate`,args:[`devicectl`,`device`,`process`,`terminate`,`--device`,e.id,`--pid`,String(i.pid),`--kill`],failureMessage:`Failed to terminate iOS app`,parseFailureMessage:`Failed to parse iOS process termination response`,tolerateFailurePayload:Ke})}async function z(t,n){let r=(await R(t,`all`)).find(e=>e.bundleId===n);if(!r)throw new e(`APP_NOT_INSTALLED`,`No iOS device app found for ${n}`,{appBundleId:n,deviceId:t.id});if(!r.url)throw new e(`COMMAND_FAILED`,`Missing app bundle URL for ${n}`,{appBundleId:n,deviceId:t.id,hint:`Installed-app metadata from devicectl did not include the bundle URL required to match running processes. Use an Xcode/CoreDevice toolchain that reports app URLs.`});let i=r.url.replace(/\/+$/,``);return{appBundleUrl:i,processes:(await Ue(t)).filter(e=>e.executable.startsWith(`${i}/`))}}async function B(t,n){let r=u.join(m.tmpdir(),`${n.jsonPrefix}-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`),i=[...n.args,`--json-output`,r],a=await l(i,{allowFailure:!0,timeoutMs:2e4});try{if(a.exitCode!==0){let{stdout:o,stderr:c}=a;if(n.tolerateFailurePayload){let e=await V(r).catch(()=>void 0);if(e!==void 0&&n.tolerateFailurePayload(e))return e}throw new e(`COMMAND_FAILED`,n.failureMessage,s(a,{cmd:`xcrun`,args:i,stdout:o,stderr:c,deviceId:t.id,hint:G(o,c)??n.fallbackHint??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}))}return await V(r)}catch(r){throw r instanceof e?r:new e(`COMMAND_FAILED`,n.parseFailureMessage,{deviceId:t.id,cause:String(r)})}finally{await p.unlink(r).catch(()=>{})}}async function V(e){return JSON.parse(await p.readFile(e,`utf8`))}function H(e,t){return e.executable.slice(t.length+1).split(`/`).length}function Ge(e){return Array.isArray(e?.result?.runningProcesses)}function Ke(e){let t=e?.error?.userInfo?.NSUnderlyingError?.error;return t?.domain===`NSPOSIXErrorDomain`&&t.code===3}function qe(e){let t=e?.result?.apps;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!e||typeof e!=`object`)continue;let t=typeof e.bundleIdentifier==`string`?e.bundleIdentifier.trim():``;if(!t)continue;let r=typeof e.name==`string`&&e.name.trim().length>0?e.name.trim():t,i=typeof e.url==`string`&&e.url.trim().length>0?e.url.trim():void 0;n.push({bundleId:t,name:r,url:i})}return n}function Je(e){let t=e?.result?.runningProcesses;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!e||typeof e!=`object`)continue;let t=typeof e.executable==`string`?e.executable.trim():``,r=typeof e.processIdentifier==`number`&&Number.isFinite(e.processIdentifier)?e.processIdentifier:NaN;!t||!Number.isFinite(r)||n.push({executable:t,pid:r})}return n}function Ye(e,t){return ie(e,t)}const U=`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`,W=`This Xcode/CoreDevice toolchain must support 'devicectl device info processes' with JSON runningProcesses so agent-device can resolve app process IDs. Inspect diagnostics for the exact devicectl API failure.`;function G(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`device is busy`)&&n.includes(`connecting`)?`iOS device is still connecting. Keep it unlocked and connected by cable until it is fully available in Xcode Devices, then retry.`:n.includes(`coredeviceservice`)&&n.includes(`timed out`)?`CoreDevice service timed out. Reconnect the device and retry; if it persists restart Xcode and the iOS device.`:n.includes(`developer disk image`)||n.includes(`developer mode is disabled`)?`Enable Developer Mode on the iOS device (Settings > Privacy & Security > Developer Mode), restart it when prompted, unlock it, then retry.`:n.includes(`must be paired`)?`Pair the iOS device with this Mac: connect it by cable, unlock it, accept the Trust prompt, and enter the device passcode, then retry.`:null}function K(e,t){return g(e,t)}function Xe(e,t,n){return l(K(e,t),n)}function q(e){return e.includes(`not installed`)||e.includes(`not found`)||e.includes(`no such file`)}async function Ze(e,t){return await R(e,t)}async function Qe(e,t){await L([`device`,`install`,`app`,`--device`,e.id,t],{action:`install iOS app`,deviceId:e.id},{timeoutMs:12e4})}async function $e(e,t){await L([`device`,`uninstall`,`app`,`--device`,e.id,t],{action:`uninstall iOS app ${t}`,deviceId:e.id},{tolerateOutput:(e,t)=>q(`${e}\n${t}`.toLowerCase())})}async function et(e,t){await We(e,t)}async function tt(e,t){return await z(e,t)}const J=1e4;async function nt(e,t,n={}){let r=[`device`,`process`,`launch`,`--device`,e.id,t];n.payloadUrl&&r.push(`--payload-url`,n.payloadUrl),n.launchArgs&&n.launchArgs.length>0&&r.push(`--`,...n.launchArgs),await L(r,{action:`launch iOS app`,deviceId:e.id})}async function rt(t){try{let{result:n,parsed:r}=await Y(t.id,15e3,3e3);if(n.exitCode===0){if(!r.parsed)throw new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{kind:`probe_inconclusive`,deviceId:t.id,stdout:n.stdout,stderr:n.stderr,hint:`CoreDevice returned success but readiness JSON output was missing or invalid. Retry; if it persists restart Xcode and the iOS device.`});let i=r.tunnelState?.toLowerCase();if(i===`connecting`)throw new e(`COMMAND_FAILED`,`iOS device is not ready for automation`,{kind:`not_ready`,deviceId:t.id,tunnelState:i,hint:`Device tunnel is still connecting. Keep the device unlocked and connected by cable until it is fully available in Xcode Devices, then retry.`});return}throw new e(`COMMAND_FAILED`,`iOS device is not ready for automation`,s(n,{kind:`not_ready`,deviceId:t.id,tunnelState:r.tunnelState,hint:Z(n.stdout,n.stderr)}))}catch(e){throw it(t.id,e)}}function it(t,n){return!(n instanceof e)||n.code!==`COMMAND_FAILED`?ot(t,n):(typeof n.details?.kind==`string`?n.details.kind:``)===`not_ready`?n:at(t,n)}function at(t,n){let r=n.details??{},i=String(r.stdout??``),a=String(r.stderr??``),o=Number(r.timeoutMs??15e3),s=`CoreDevice did not respond within ${o}ms. Keep the device unlocked and trusted, then retry; if it persists restart Xcode and the iOS device.`;return new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{deviceId:t,cause:n.message,timeoutMs:o,stdout:i,stderr:a,hint:i||a?Z(i,a):s},n)}function ot(t,n){return new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{deviceId:t,hint:`Reconnect the device, keep it unlocked, and retry.`},n instanceof Error?n:void 0)}async function st(e,t){if(typeof t==`number`&&t<=0)return null;let n=typeof t==`number`?Math.max(1,Math.min(J,t)):J;try{let t=await Y(e.id,n);return t.result.exitCode!==0||!t.parsed.parsed||t.parsed.outcome&&t.parsed.outcome!==`success`?null:t.parsed.tunnelIp??null}catch{return null}}async function Y(e,t,n=0){let r=u.join(m.tmpdir(),`agent-device-coredevice-info-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`),i=Math.max(1,Math.ceil(t/1e3));try{return{result:await l([`devicectl`,`device`,`info`,`details`,`--device`,e,`--json-output`,r,`--timeout`,String(i)],{allowFailure:!0,timeoutMs:t+n}),parsed:await ct(r)}}finally{await p.rm(r,{force:!0}).catch(()=>{})}}async function ct(e){try{return{parsed:!0,...lt(JSON.parse(await p.readFile(e,`utf8`)))}}catch{return{parsed:!1}}}function lt(e){let t=e?.result;if(!t||typeof t!=`object`)return{};let n=t.connectionProperties,r=t.device?.connectionProperties,i=X(n?.tunnelState)??X(r?.tunnelState),a=X(n?.tunnelIPAddress)??X(r?.tunnelIPAddress),o=X(e?.info?.outcome);return{...o?{outcome:o}:{},...i?{tunnelState:i}:{},...a?{tunnelIp:a}:{}}}function X(e){return typeof e==`string`&&e.trim()?e.trim():void 0}function Z(e,t){return G(e,t)||(`${e}\n${t}`.toLowerCase().includes(`timed out waiting for all destinations`)?`Xcode destination did not become available in time. Keep device unlocked and retry.`:U)}async function Q(t,n,r,i=I){let a=re.fromTimeoutMs(i),o={exitCode:1,stdout:``,stderr:``};for(let e of D)if(o=await l([`devicectl`,`device`,`copy`,`from`,`--device`,t.id,`--source`,n,`--destination`,r,`--domain-type`,`appDataContainer`,`--domain-identifier`,e],{allowFailure:!0,timeoutMs:ut(a,i)}),o.exitCode===0)return;throw new e(`COMMAND_FAILED`,`Failed to copy runner file from iOS device: ${o.stderr.trim()||o.stdout.trim()||`devicectl exited with code ${o.exitCode}`}`)}function ut(t,n){let r=t.remainingMs();if(r>0)return r;throw new e(`COMMAND_FAILED`,`iOS runner file copy timed out after ${n}ms`,{timeoutMs:n,step:`runner file copy`})}function $(t){if(!(t instanceof e))return{reason:t instanceof Error?t.message:String(t)};let n=t.details??{},r=Array.isArray(n.args)?n.args.filter(e=>typeof e==`string`).join(` `):void 0;return{errorCode:t.code,reason:t.message,timeoutMs:typeof n.timeoutMs==`number`?n.timeoutMs:void 0,exitCode:typeof n.exitCode==`number`?n.exitCode:void 0,stderr:typeof n.stderr==`string`&&n.stderr.trim()?n.stderr:void 0,stdout:typeof n.stdout==`string`&&n.stdout.trim()?n.stdout:void 0,commandArgs:r}}function dt(e){let t=e.details??{},n=typeof t.stdout==`string`?t.stdout:``,r=typeof t.stderr==`string`?t.stderr:``,i=Array.isArray(t.args)?t.args.filter(e=>typeof e==`string`).join(` `):``;return`${e.message}\n${n}\n${r}\n${i}`.toLowerCase()}async function ft(e,t,n){if(!n.preferRunner)try{await L([`device`,`screenshot`,`--device`,e.id,t],{action:`capture iOS screenshot`,deviceId:e.id});return}catch(t){if(!vt(t))throw t;_t(e,t)}let r=await mt(e,n,!1);await ht(r,t)||await Q(e,gt(r),t)}async function pt(t,n,r){if(!await ht(await mt(t,r,!0),n))throw new e(`COMMAND_FAILED`,`Failed to capture iOS screenshot: XCTest runner returned no inline image`,{deviceId:t.id,backend:`xctest`})}async function mt(e,t,n){return await t.runRunnerCommand(e,{command:`screenshot`,appBundleId:t.appBundleId,fullscreen:t.fullscreen,inlineScreenshot:n},t.runnerOptions??{})}async function ht(e,t){let n=e.imageBase64;return typeof n!=`string`||n.length===0?!1:(await p.writeFile(t,Buffer.from(n,`base64`)),!0)}function gt(t){let n=t.message;if(typeof n==`string`&&n.length>0)return n;throw new e(`COMMAND_FAILED`,`Failed to capture iOS screenshot: runner returned no file path`)}function _t(e,t){o({level:`warn`,phase:`ios_screenshot_fallback`,data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,from:`devicectl_screenshot`,to:`runner`,...$(t)}})}function vt(t){if(!(t instanceof e)||t.code!==`COMMAND_FAILED`)return!1;let n=dt(t);return n.includes(`unknown option '--device'`)||n.includes(`unknown subcommand`)&&n.includes(`screenshot`)||n.includes(`unrecognized subcommand`)&&n.includes(`screenshot`)}const yt={coredevice:{backend:`coredevice`,assertAppInstallationSupported:()=>{},ensureReady:rt,listApps:Ze,installApp:Qe,uninstallApp:$e,launchApp:nt,terminateApp:async(e,t)=>await et(e,t),resolveAppProcesses:tt,captureScreenshot:ft,copyRunnerFile:Q,resolveTunnel:async(e,t)=>({tunnelIp:await st(e,t)})},xctest:{backend:`xctest`,assertAppInstallationSupported:xt,ensureReady:Dt,listApps:Ct,installApp:St,uninstallApp:St,launchApp:Ot,terminateApp:kt,resolveAppProcesses:wt,captureScreenshot:pt,copyRunnerFile:Et,resolveTunnel:Tt}};function bt(e){return yt[e.iosPhysicalDeviceBackend===`xctest`?`xctest`:`coredevice`]}function xt(t){throw new e(`UNSUPPORTED_OPERATION`,`Installing apps is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`,hint:`Install the app with Xcode, then open it in agent-device by bundle ID.`})}async function St(e){return xt(e)}async function Ct(t){throw new e(`UNSUPPORTED_OPERATION`,`App inventory is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`,hint:`Use an installed app bundle ID when opening the device.`})}async function wt(t){throw new e(`UNSUPPORTED_OPERATION`,`Process lookup is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`,hint:`Use a CoreDevice-backed iOS device for performance sampling.`})}async function Tt(t){throw new e(`UNSUPPORTED_OPERATION`,`XCTest-backed physical iOS devices have no CoreDevice tunnel.`,{deviceId:t.id,backend:`xctest`,hint:`Connect the device by cable so it is reachable through usbmux.`})}async function Et(t){throw new e(`UNSUPPORTED_OPERATION`,`Runner file copy is unavailable on this XCTest-backed physical iOS device.`,{deviceId:t.id,backend:`xctest`})}async function Dt(t){let n=[`xcdevice`,`wait`,`--both`,`--timeout=15`,t.id],r=await l(n,{allowFailure:!0,timeoutMs:18e3});if(r.exitCode!==0)throw new e(`COMMAND_FAILED`,`iOS device is not ready for XCTest automation`,s(r,{cmd:`xcrun`,args:n,deviceId:t.id,backend:`xctest`,hint:"Keep the device unlocked, trusted, connected, and visible in `xcrun xcdevice list`, then retry."}))}async function Ot(t,n,r){if(r.payloadUrl||r.launchArgs&&r.launchArgs.length>0)throw new e(`UNSUPPORTED_OPERATION`,`XCTest-backed physical iOS devices do not support deep links or launch arguments during open.`,{deviceId:t.id,backend:`xctest`,hint:`Open the installed app by bundle ID without a URL or --launch-args.`});await r.runRunnerCommand(t,{command:`activate`,appBundleId:n},r.runnerOptions??{})}async function kt(e,t,n){await n.runRunnerCommand(e,{command:`terminate`,appBundleId:t},n.runnerOptions??{})}export{De as A,T as C,P as D,Me as E,ce as F,h as I,g as L,x as M,ue as N,F as O,le as P,ae as R,xe as S,we as T,ze as _,Xe as a,ve as b,G as c,I as d,Fe as f,Be as g,He as h,q as i,ge as j,M as k,Ie as l,Ve as m,dt as n,K as o,Le as p,$ as r,U as s,bt as t,Pe as u,Re as v,N as w,k as x,D as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(t,n){for(let r of t){if(r.name===`dict`)for(let e=0;e<r.children.length-1;e+=1){let t=r.children[e],i=r.children[e+1];t?.name===`key`&&t.text&&i&&n(t.text,i)}e(r.children,n)}}export{e as t};
|
package/dist/src/plist.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{t as e}from"./parser.js";import{i as t,n}from"./tool-provider.js";import{t as r}from"./plist-xml.js";import{promises as i}from"node:fs";async function a(e,r){try{let t=(await n(e))?.[r];if(typeof t==`string`&&t.length>0)return t}catch{}try{let n=await t(`plutil`,[`-extract`,r,`raw`,`-o`,`-`,e],{allowFailure:!0});if(n.exitCode===0){let e=n.stdout.trim();if(e.length>0)return e}}catch{}try{return o(await i.readFile(e,`utf8`),r)}catch{return}}function o(t,n){let i;return r(e(t),(e,t)=>{i!==void 0||e!==n||t.name!==`string`||(i=t.text??void 0)}),i}export{a as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{deflateSync as t,inflateSync as n}from"node:zlib";const r=Buffer.from([137,80,78,71,13,10,26,10]),i=new Map([[0,1],[2,3],[3,1],[4,2],[6,4]]),a=new Map([[0,new Set([1,2,4,8,16])],[2,new Set([8,16])],[3,new Set([1,2,4,8])],[4,new Set([8,16])],[6,new Set([8,16])]]),o=[{x:0,y:0,dx:8,dy:8},{x:4,y:0,dx:8,dy:8},{x:0,y:4,dx:4,dy:8},{x:2,y:0,dx:4,dy:4},{x:0,y:2,dx:2,dy:4},{x:1,y:0,dx:2,dy:2},{x:0,y:1,dx:1,dy:2}];var s=class{width;height;data;static sync={read:c,write:p};constructor(e){this.width=I(e.width,`width`),this.height=I(e.height,`height`);let t=this.width*this.height*4;if(this.data=e.data?Buffer.from(e.data):Buffer.alloc(t),this.data.length!==t)throw Error(`PNG data length must be ${t} bytes`)}};function c(e){let{metadata:t,idatChunks:n}=l(e);if(!t)throw Error(`PNG is missing IHDR`);if(n.length===0)throw Error(`PNG is missing IDAT`);let r=f(n,t);return new s({width:t.width,height:t.height,data:t.interlace===1?b(r,t):y(g(r,t),t)})}function l(e){let t,n=[];for(let r of d(e))if(r.type===`IHDR`?t=m(r.data):r.type===`IDAT`?n.push(Buffer.from(r.data)):t=u(r,t),r.type===`IEND`)break;return{metadata:t,idatChunks:n}}function u(e,t){if(e.type===`PLTE`){if(!t)throw Error(`PNG PLTE appeared before IHDR`);t.palette=Buffer.from(e.data)}else if(e.type===`tRNS`){if(!t)throw Error(`PNG tRNS appeared before IHDR`);t.transparency=Buffer.from(e.data)}return t}function*d(e){if(!e.subarray(0,r.length).equals(r))throw Error(`Invalid PNG signature`);let t=r.length;for(;t<e.length;){if(t+12>e.length)throw Error(`Truncated PNG chunk`);let n=e.readUInt32BE(t),r=e.toString(`ascii`,t+4,t+8),i=t+8,a=i+n;if(a+4>e.length)throw Error(`Truncated PNG ${r} chunk`);let o=e.subarray(i,a),s=e.readUInt32BE(a);if(P(e.subarray(t+4,a))!==s)throw Error(`Invalid PNG ${r} chunk CRC`);t=a+4,yield{type:r,data:o}}}function f(e,t){let r=x(t);try{let t=n(Buffer.concat(e),{maxOutputLength:r});if(t.length!==r)throw Error(`PNG pixel data is truncated`);return t}catch(e){throw L(e)?Error(`PNG pixel data exceeds expected length ${r}`):e}}function p(e){let n=e.width*4,i=Buffer.alloc((n+1)*e.height);for(let t=0;t<e.height;t+=1){let r=t*(n+1);i[r]=0,e.data.copy(i,r+1,t*n,(t+1)*n)}let a=Buffer.alloc(13);return a.writeUInt32BE(e.width,0),a.writeUInt32BE(e.height,4),a[8]=8,a[9]=6,a[10]=0,a[11]=0,a[12]=0,Buffer.concat([r,N(`IHDR`,a),N(`IDAT`,t(i)),N(`IEND`,Buffer.alloc(0))])}function m(e){if(e.length!==13)throw Error(`Invalid PNG IHDR length`);let t=e.readUInt32BE(0),n=e.readUInt32BE(4),r=e[8],i=e[9],o=e[10],s=e[11],c=e[12];if(!h(i))throw Error(`Unsupported PNG color type ${i}`);if(!a.get(i)?.has(r))throw Error(`Unsupported PNG color type ${i} with bit depth ${r}`);if(o!==0)throw Error(`Unsupported PNG compression method ${o}`);if(s!==0)throw Error(`Unsupported PNG filter method ${s}`);if(c!==0&&c!==1)throw Error(`Unsupported PNG interlace method ${c}`);return{width:I(t,`width`),height:I(n,`height`),bitDepth:r,colorType:i,interlace:c}}function h(e){return i.has(e)}function g(e,t){return _({inflated:e,offset:0,scanlineLength:O(t),height:t.height,bytesPerPixel:k(t)}).raw}function _(e){let{inflated:t,offset:n,scanlineLength:r,height:i,bytesPerPixel:a}=e,o=n+(r+1)*i;if(t.length<o)throw Error(`PNG pixel data is truncated`);let s=Buffer.alloc(r*i);for(let e=0;e<i;e+=1){let i=n+e*(r+1),o=e*r,c=t[i];for(let n=0;n<r;n+=1){let l=t[i+1+n],u=n>=a?s[o+n-a]:0,d=e>0?s[o+n-r]:0,f=e>0&&n>=a?s[o+n-r-a]:0;s[o+n]=v(c,l,u,d,f)}}return{raw:s,offset:o}}function v(e,t,n,r,i){if(e===0)return t;if(e===1)return t+n&255;if(e===2)return t+r&255;if(e===3)return t+Math.floor((n+r)/2)&255;if(e===4)return t+F(n,r,i)&255;throw Error(`Unsupported PNG filter type ${e}`)}function y(e,t){let n=Buffer.alloc(t.width*t.height*4),r=O(t);for(let i=0;i<t.height;i+=1){let a=e.subarray(i*r,(i+1)*r);for(let e=0;e<t.width;e+=1){let r=(i*t.width+e)*4,[o,s,c,l]=w(a,e,t);n[r]=o,n[r+1]=s,n[r+2]=c,n[r+3]=l}}return n}function b(e,t){let n=Buffer.alloc(t.width*t.height*4),r=0;for(let i of o){let a=C(t.width,i.x,i.dx),o=C(t.height,i.y,i.dy);if(a===0||o===0)continue;let s={...t,width:a,height:o,interlace:0},c=_({inflated:e,offset:r,scanlineLength:O(s),height:o,bytesPerPixel:k(s)});r=c.offset;let l=O(s);for(let e=0;e<o;e+=1){let r=c.raw.subarray(e*l,(e+1)*l);for(let o=0;o<a;o+=1){let a=i.x+o*i.dx,c=((i.y+e*i.dy)*t.width+a)*4,[l,u,d,f]=w(r,o,s);n[c]=l,n[c+1]=u,n[c+2]=d,n[c+3]=f}}}return n}function x(e){if(e.interlace===0)return S(e,e.height);let t=0;for(let n of o){let r=C(e.width,n.x,n.dx),i=C(e.height,n.y,n.dy);r===0||i===0||(t+=S({...e,width:r,height:i},i))}return t}function S(e,t){return(O(e)+1)*t}function C(e,t,n){return e<=t?0:Math.floor((e-t+n-1)/n)}function w(e,t,n){if(n.colorType===3)return T(e,t,n);if(n.bitDepth<8)return E(e,t,n);let r=n.bitDepth===16?2:1,a=t*i.get(n.colorType)*r,o=t=>n.bitDepth===16?e.readUInt16BE(a+t*2):e[a+t*r],s=e=>A(o(e),n.bitDepth);if(n.colorType===0){let e=s(0);return[e,e,e,j(o(0),n)?0:255]}if(n.colorType===2)return[s(0),s(1),s(2),M(o(0),o(1),o(2),n)?0:255];if(n.colorType===4){let e=s(0);return[e,e,e,s(1)]}return[s(0),s(1),s(2),s(3)]}function T(e,t,n){if(!n.palette)throw Error(`Indexed PNG is missing PLTE`);let r=D(e,t,n.bitDepth),i=r*3;if(i+2>=n.palette.length)throw Error(`Indexed PNG palette is invalid`);return[n.palette[i],n.palette[i+1],n.palette[i+2],n.transparency?.[r]??255]}function E(e,t,n){let r=D(e,t,n.bitDepth),i=(1<<n.bitDepth)-1,a=Math.round(r/i*255);return[a,a,a,n.transparency&&n.transparency.length>=2&&r===n.transparency.readUInt16BE(0)?0:255]}function D(e,t,n){let r=t*n;return e[Math.floor(r/8)]>>8-n-r%8&(1<<n)-1}function O(e){let t=i.get(e.colorType);return Math.ceil(e.width*t*e.bitDepth/8)}function k(e){let t=i.get(e.colorType);return Math.max(1,Math.ceil(t*e.bitDepth/8))}function A(e,t){return t===16?Math.round(e/65535*255):e}function j(e,t){return!t.transparency||t.transparency.length<2?!1:e===t.transparency.readUInt16BE(0)}function M(e,t,n,r){return!r.transparency||r.transparency.length<6?!1:e===r.transparency.readUInt16BE(0)&&t===r.transparency.readUInt16BE(2)&&n===r.transparency.readUInt16BE(4)}function N(e,t){let n=Buffer.from(e,`ascii`),r=Buffer.alloc(8+t.length+4);return r.writeUInt32BE(t.length,0),n.copy(r,4),t.copy(r,8),r.writeUInt32BE(P(Buffer.concat([n,t])),8+t.length),r}function P(e){let t=4294967295;for(let n of e){t^=n;for(let e=0;e<8;e+=1)t=t&1?3988292384^t>>>1:t>>>1}return(t^4294967295)>>>0}function F(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}function I(e,t){if(!Number.isInteger(e)||e<1)throw Error(`PNG ${t} must be positive`);return e}function L(e){return e instanceof Error&&`code`in e&&e.code===`ERR_BUFFER_TOO_LARGE`}function R(t,n){try{return s.sync.read(t)}catch(t){throw new e(`COMMAND_FAILED`,`Failed to decode ${n} as PNG`,{label:n,reason:t instanceof Error?t.message:String(t)})}}const z=.78,B={r:220,g:0,b:0};function V(e){let{baselineData:t,currentData:n,maxColorDistance:r}=e,i=e.width*e.height,a=Buffer.alloc(i*4),o=new Uint8Array(i),s=0;for(let e=0,i=0;e<t.length;e+=4,i+=1){let c=t[e]-n[e],l=t[e+1]-n[e+1],u=t[e+2]-n[e+2];if(Math.sqrt(c**2+l**2+u**2)>r){s+=1,o[i]=1;let t=H(n,e);a[e]=U(t,B.r,z),a[e+1]=U(t,B.g,z),a[e+2]=U(t,B.b,z),a[e+3]=255;continue}let d=H(n,e);a[e]=d,a[e+1]=d,a[e+2]=d,a[e+3]=255}return{diffData:a,diffMask:o,differentPixels:s}}function H(e,t){return U(Math.round(e[t]*.299+e[t+1]*.587+e[t+2]*.114),255,.72)}function U(e,t,n){return Math.round(e*(1-n)+t*n)}function W(e,t){let n={first:{width:e.width,height:e.height,dataLength:e.data.length},second:{width:t.width,height:t.height,dataLength:t.data.length}};if(e.width!==t.width||e.height!==t.height)return{...n,status:`dimension_mismatch`};let r=e.width*e.height;if(e.data.length!==t.data.length||e.data.length!==r*4)return{...n,status:`data_length_mismatch`};let i=0;for(let n=0;n<e.data.length;n+=4)i+=Math.abs(e.data[n]-t.data[n]),i+=Math.abs(e.data[n+1]-t.data[n+1]),i+=Math.abs(e.data[n+2]-t.data[n+2]);return{...n,status:`compared`,differencePercent:100*i/(765*r)}}function G(e){return Buffer.from(e.buffer,e.byteOffset,e.byteLength)}export{s as a,R as i,W as n,V as r,G as t};
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{createRequire as t}from"node:module";var n=Object.defineProperty,r=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),i=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},a=t(import.meta.url),o=r(((e,t)=>{let n=a(`util`),r=a(`stream`),i=t.exports=function(){r.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding=`utf8`,this.writable=!0};n.inherits(i,r),i.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit(`drain`))}.bind(this))},i.prototype.write=function(e,t){if(!this.writable)return this.emit(`error`,Error(`Stream not writable`)),!1;let n;return n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0&&(this._paused=!0),this.writable&&!this._paused},i.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(this._buffers.length===0?this._end():(this._buffers.push(null),this._process()))},i.prototype.destroySoon=i.prototype.end,i.prototype._end=function(){this._reads.length>0&&this.emit(`error`,Error(`Unexpected end of input`)),this.destroy()},i.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit(`close`))},i.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},i.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let i=this._buffers[n++],a=Math.min(i.length,e.length-t);i.copy(r,t,0,a),t+=a,a!==i.length&&(this._buffers[--n]=i.slice(a))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},i.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit(`error`,e)}}})),s=r((e=>{let t=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];e.getImagePasses=function(e,n){let r=[],i=e%8,a=n%8,o=(e-i)/8,s=(n-a)/8;for(let e=0;e<t.length;e++){let n=t[e],c=o*n.x.length,l=s*n.y.length;for(let e=0;e<n.x.length&&n.x[e]<i;e++)c++;for(let e=0;e<n.y.length&&n.y[e]<a;e++)l++;c>0&&l>0&&r.push({width:c,height:l,index:e})}return r},e.getInterlaceIterator=function(e){return function(n,r,i){let a=n%t[i].x.length,o=(n-a)/t[i].x.length*8+t[i].x[a],s=r%t[i].y.length,c=(r-s)/t[i].y.length*8+t[i].y[s];return o*4+c*e*4}}})),c=r(((e,t)=>{t.exports=function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}})),l=r(((e,t)=>{let n=s(),r=c();function i(e,t,n){let r=e*t;return n!==8&&(r=Math.ceil(r/(8/n))),r}let a=t.exports=function(e,t){let r=e.width,a=e.height,o=e.interlace,s=e.bpp,c=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],o){let e=n.getImagePasses(r,a);for(let t=0;t<e.length;t++)this._images.push({byteWidth:i(e[t].width,s,c),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:i(r,s,c),height:a,lineIndex:0});c===8?this._xComparison=s:c===16?this._xComparison=s*2:this._xComparison=1};a.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},a.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,i=r-1;for(let a=0;a<n;a++)t[a]=e[1+a]+(a>i?t[a-r]:0)},a.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let i=0;i<n;i++)t[i]=e[1+i]+(r?r[i]:0)},a.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,i=r-1,a=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],s=a?a[o]:0,c=o>i?t[o-r]:0;t[o]=n+Math.floor((c+s)/2)}},a.prototype._unFilterType4=function(e,t,n){let i=this._xComparison,a=i-1,o=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],c=o?o[s]:0,l=s>a?t[s-i]:0,u=s>a&&o?o[s-i]:0;t[s]=n+r(l,c,u)}},a.prototype._reverseFilterLine=function(e){let t=e[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(t===0)n=e.slice(1,i+1);else switch(n=Buffer.alloc(i),t){case 1:this._unFilterType1(e,n,i);break;case 2:this._unFilterType2(e,n,i);break;case 3:this._unFilterType3(e,n,i);break;case 4:this._unFilterType4(e,n,i);break;default:throw Error(`Unrecognised filter type - `+t)}this.write(n),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=n,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}})),u=r(((e,t)=>{let n=a(`util`),r=o(),i=l(),s=t.exports=function(e){r.call(this);let t=[],n=this;this._filter=new i(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit(`complete`,Buffer.concat(t))}}),this._filter.start()};n.inherits(s,r)})),d=r(((e,t)=>{t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}})),f=r(((e,t)=>{let n=[];(function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;n[e]=t}})();let r=t.exports=function(){this._crc=-1};r.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=n[(this._crc^e[t])&255]^this._crc>>>8;return!0},r.prototype.crc32=function(){return this._crc^-1},r.crc32=function(e){let t=-1;for(let r=0;r<e.length;r++)t=n[(t^e[r])&255]^t>>>8;return t^-1}})),p=r(((e,t)=>{let n=d(),r=f(),i=t.exports=function(e,t){this._options=e,e.checkCRC=e.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[n.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[n.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[n.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[n.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[n.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[n.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(n.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=n.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n]){this.error(Error(`Invalid file signature`));return}this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),i=e.readUInt32BE(4),a=``;for(let t=4;t<8;t++)a+=String.fromCharCode(e[t]);let o=!!(e[4]&32);if(!this._hasIHDR&&i!==n.TYPE_IHDR){this.error(Error(`Expected IHDR on beggining`));return}if(this._crc=new r,this._crc.write(Buffer.from(a)),this._chunks[i])return this._chunks[i](t);if(!o){this.error(Error(`Unsupported critical chunk type `+a));return}this.read(t+4,this._skipChunk.bind(this))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==t){this.error(Error(`Crc error - `+t+` - `+n));return}this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],c=e[12];if(i!==8&&i!==4&&i!==2&&i!==1&&i!==16){this.error(Error(`Unsupported bit depth `+i));return}if(!(a in n.COLORTYPE_TO_BPP_MAP)){this.error(Error(`Unsupported color type`));return}if(o!==0){this.error(Error(`Unsupported compression method`));return}if(s!==0){this.error(Error(`Unsupported filter method`));return}if(c!==0&&c!==1){this.error(Error(`Unsupported interlace method`));return}this._colorType=a;let l=n.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:r,depth:i,interlace:!!c,palette:!!(a&n.COLORTYPE_PALETTE),color:!!(a&n.COLORTYPE_COLOR),alpha:!!(a&n.COLORTYPE_ALPHA),bpp:l,colorType:a}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[n*3],e[n*3+1],e[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===n.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error(`Transparency chunk must be after palette`));return}if(e.length>this._palette.length){this.error(Error(`More transparent colors than palette size`));return}for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===n.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===n.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/n.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===n.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error(`Expected palette not found`);this.inflateData(t);let r=e-t.length;r>0?this._handleIDAT(r):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}})),m=r((e=>{let t=s(),n=[function(){},function(e,t,n,r){if(r===t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],r=[function(){},function(e,t,n,r){let i=t[0];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];function i(e,t){let n=[],r=0;function i(){if(r===e.length)throw Error(`Ran out of data`);let i=e[r];r++;let a,o,s,c,l,u,d,f;switch(t){default:throw Error(`unrecognised depth`);case 16:d=e[r],r++,n.push((i<<8)+d);break;case 4:d=i&15,f=i>>4,n.push(f,d);break;case 2:l=i&3,u=i>>2&3,d=i>>4&3,f=i>>6&3,n.push(f,d,u,l);break;case 1:a=i&1,o=i>>1&1,s=i>>2&1,c=i>>3&1,l=i>>4&1,u=i>>5&1,d=i>>6&1,f=i>>7&1,n.push(f,d,u,l,c,s,o,a);break}}return{get:function(e){for(;n.length<e;)i();let t=n.slice(0,e);return n=n.slice(e),t},resetAfterLine:function(){n.length=0},end:function(){if(r!==e.length)throw Error(`extra data found`)}}}function a(e,t,r,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++)for(let c=0;c<s;c++){let s=r(c,e,l);n[i](t,a,s,o),o+=i}return o}function o(e,t,n,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++){for(let c=0;c<s;c++){let s=a.get(i),u=n(c,e,l);r[i](t,s,u,o)}a.resetAfterLine()}}e.dataToBitMap=function(e,n){let r=n.width,s=n.height,c=n.depth,l=n.bpp,u=n.interlace,d;c!==8&&(d=i(e,c));let f;f=c<=8?Buffer.alloc(r*s*4):new Uint16Array(r*s*4);let p=2**c-1,m=0,h,g;if(u)h=t.getImagePasses(r,s),g=t.getInterlaceIterator(r,s);else{let e=0;g=function(){let t=e;return e+=4,t},h=[{width:r,height:s}]}for(let t=0;t<h.length;t++)c===8?m=a(h[t],f,g,l,e,m):o(h[t],f,g,l,d,p);if(c===8){if(m!==e.length)throw Error(`extra data found`)}else d.end();return f}})),h=r(((e,t)=>{function n(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=i[e[a]];if(!n)throw Error(`index `+e[a]+` not in palette`);for(let e=0;e<4;e++)t[a+e]=n[e];a+=4}}function r(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=!1;if(i.length===1?i[0]===e[a]&&(n=!0):i[0]===e[a]&&i[1]===e[a+1]&&i[2]===e[a+2]&&(n=!0),n)for(let e=0;e<4;e++)t[a+e]=0;a+=4}}function i(e,t,n,r,i){let a=2**i-1,o=0;for(let i=0;i<r;i++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[o+n]=Math.floor(e[o+n]*255/a+.5);o+=4}}t.exports=function(e,t,a=!1){let o=t.depth,s=t.width,c=t.height,l=t.colorType,u=t.transColor,d=t.palette,f=e;return l===3?n(e,f,s,c,d):(u&&r(e,f,s,c,u),o!==8&&!a&&(o===16&&(f=Buffer.alloc(s*c*4)),i(e,f,s,c,o))),f}})),g=r(((e,t)=>{let n=a(`util`),r=a(`zlib`),i=o(),s=u(),c=p(),l=m(),d=h(),f=t.exports=function(e){i.call(this),this._parser=new c(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,`gamma`),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};n.inherits(f,i),f.prototype._handleError=function(e){this.emit(`error`,e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on(`error`,function(){})),this.errord=!0},f.prototype._inflateData=function(e){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=r.createInflate(),this._inflate.on(`error`,this.emit.bind(this,`error`)),this._filter.on(`complete`,this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,r.Z_MIN_CHUNK);this._inflate=r.createInflate({chunkSize:t});let n=e,i=this.emit.bind(this,`error`);this._inflate.on(`error`,function(e){n&&i(e)}),this._filter.on(`complete`,this._complete.bind(this));let a=this._filter.write.bind(this._filter);this._inflate.on(`data`,function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,a(e))}),this._inflate.on(`end`,this._filter.end.bind(this._filter))}this._inflate.write(e)},f.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new s(this._bitmapInfo)},f.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},f.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},f.prototype._simpleTransparency=function(){this._metaData.alpha=!0},f.prototype._headersFinished=function(){this.emit(`metadata`,this._metaData)},f.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit(`error`,`No Inflate block`))},f.prototype._complete=function(e){if(this.errord)return;let t;try{let n=l.dataToBitMap(e,this._bitmapInfo);t=d(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(e){this._handleError(e);return}this.emit(`parsed`,t)}})),_=r(((e,t)=>{let n=d();t.exports=function(e,t,r,i){let a=[n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(i.colorType)!==-1;if(i.colorType===i.inputColorType){let t=(function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]!==256})();if(i.bitDepth===8||i.bitDepth===16&&t)return e}let o=i.bitDepth===16?new Uint16Array(e.buffer):e,s=255,c=n.COLORTYPE_TO_BPP_MAP[i.inputColorType];c===4&&!i.inputHasAlpha&&(c=3);let l=n.COLORTYPE_TO_BPP_MAP[i.colorType];i.bitDepth===16&&(s=65535,l*=2);let u=Buffer.alloc(t*r*l),d=0,f=0,p=i.bgColor||{};p.red===void 0&&(p.red=s),p.green===void 0&&(p.green=s),p.blue===void 0&&(p.blue=s);function m(){let e,t,r,c=s;switch(i.inputColorType){case n.COLORTYPE_COLOR_ALPHA:c=o[d+3],e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_COLOR:e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_ALPHA:c=o[d+1],e=o[d],t=e,r=e;break;case n.COLORTYPE_GRAYSCALE:e=o[d],t=e,r=e;break;default:throw Error(`input color type:`+i.inputColorType+` is not supported at present`)}return i.inputHasAlpha&&(a||(c/=s,e=Math.min(Math.max(Math.round((1-c)*p.red+c*e),0),s),t=Math.min(Math.max(Math.round((1-c)*p.green+c*t),0),s),r=Math.min(Math.max(Math.round((1-c)*p.blue+c*r),0),s))),{red:e,green:t,blue:r,alpha:c}}for(let e=0;e<r;e++)for(let e=0;e<t;e++){let e=m(o,d);switch(i.colorType){case n.COLORTYPE_COLOR_ALPHA:case n.COLORTYPE_COLOR:i.bitDepth===8?(u[f]=e.red,u[f+1]=e.green,u[f+2]=e.blue,a&&(u[f+3]=e.alpha)):(u.writeUInt16BE(e.red,f),u.writeUInt16BE(e.green,f+2),u.writeUInt16BE(e.blue,f+4),a&&u.writeUInt16BE(e.alpha,f+6));break;case n.COLORTYPE_ALPHA:case n.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;i.bitDepth===8?(u[f]=t,a&&(u[f+1]=e.alpha)):(u.writeUInt16BE(t,f),a&&u.writeUInt16BE(e.alpha,f+2));break}default:throw Error(`unrecognised color Type `+i.colorType)}d+=c,f+=l}return u}})),v=r(((e,t)=>{let n=c();function r(e,t,n,r,i){for(let a=0;a<n;a++)r[i+a]=e[t+a]}function i(e,t,n){let r=0,i=t+n;for(let n=t;n<i;n++)r+=Math.abs(e[n]);return r}function a(e,t,n,r,i,a){for(let o=0;o<n;o++){let n=o>=a?e[t+o-a]:0,s=e[t+o]-n;r[i+o]=s}}function o(e,t,n,r){let i=0;for(let a=0;a<n;a++){let n=a>=r?e[t+a-r]:0,o=e[t+a]-n;i+=Math.abs(o)}return i}function s(e,t,n,r,i){for(let a=0;a<n;a++){let o=t>0?e[t+a-n]:0,s=e[t+a]-o;r[i+a]=s}}function l(e,t,n){let r=0,i=t+n;for(let a=t;a<i;a++){let i=t>0?e[a-n]:0,o=e[a]-i;r+=Math.abs(o)}return r}function u(e,t,n,r,i,a){for(let o=0;o<n;o++){let s=o>=a?e[t+o-a]:0,c=t>0?e[t+o-n]:0,l=e[t+o]-(s+c>>1);r[i+o]=l}}function d(e,t,n,r){let i=0;for(let a=0;a<n;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-n]:0,c=e[t+a]-(o+s>>1);i+=Math.abs(c)}return i}function f(e,t,r,i,a,o){for(let s=0;s<r;s++){let c=s>=o?e[t+s-o]:0,l=t>0?e[t+s-r]:0,u=t>0&&s>=o?e[t+s-(r+o)]:0,d=e[t+s]-n(c,l,u);i[a+s]=d}}function p(e,t,r,i){let a=0;for(let o=0;o<r;o++){let s=o>=i?e[t+o-i]:0,c=t>0?e[t+o-r]:0,l=t>0&&o>=i?e[t+o-(r+i)]:0,u=e[t+o]-n(s,c,l);a+=Math.abs(u)}return a}let m={0:r,1:a,2:s,3:u,4:f},h={0:i,1:o,2:l,3:d,4:p};t.exports=function(e,t,n,r,i){let a;if(!(`filterType`in r)||r.filterType===-1)a=[0,1,2,3,4];else if(typeof r.filterType==`number`)a=[r.filterType];else throw Error(`unrecognised filter types`);r.bitDepth===16&&(i*=2);let o=t*i,s=0,c=0,l=Buffer.alloc((o+1)*n),u=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=h[a[n]](e,c,o,i);r<t&&(u=a[n],t=r)}}l[s]=u,s++,m[u](e,c,o,l,s,i),s+=o,c+=o}return l}})),y=r(((e,t)=>{let n=d(),r=f(),i=_(),o=v(),s=a(`zlib`),c=t.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32*1024,e.deflateLevel=e.deflateLevel==null?9:e.deflateLevel,e.deflateStrategy=e.deflateStrategy==null?3:e.deflateStrategy,e.inputHasAlpha=e.inputHasAlpha==null?!0:e.inputHasAlpha,e.deflateFactory=e.deflateFactory||s.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType=typeof e.colorType==`number`?e.colorType:n.COLORTYPE_COLOR_ALPHA,e.inputColorType=typeof e.inputColorType==`number`?e.inputColorType:n.COLORTYPE_COLOR_ALPHA,[n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.colorType)===-1)throw Error(`option color type:`+e.colorType+` is not supported at present`);if([n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.inputColorType)===-1)throw Error(`option input color type:`+e.inputColorType+` is not supported at present`);if(e.bitDepth!==8&&e.bitDepth!==16)throw Error(`option bit depth:`+e.bitDepth+` is not supported at present`)};c.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},c.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},c.prototype.filterData=function(e,t,r){let a=i(e,t,r,this._options),s=n.COLORTYPE_TO_BPP_MAP[this._options.colorType];return o(a,t,r,this._options,s)},c.prototype._packChunk=function(e,t){let n=t?t.length:0,i=Buffer.alloc(n+12);return i.writeUInt32BE(n,0),i.writeUInt32BE(e,4),t&&t.copy(i,8),i.writeInt32BE(r.crc32(i.slice(4,i.length-4)),i.length-4),i},c.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*n.GAMMA_DIVISION),0),this._packChunk(n.TYPE_gAMA,t)},c.prototype.packIHDR=function(e,t){let r=Buffer.alloc(13);return r.writeUInt32BE(e,0),r.writeUInt32BE(t,4),r[8]=this._options.bitDepth,r[9]=this._options.colorType,r[10]=0,r[11]=0,r[12]=0,this._packChunk(n.TYPE_IHDR,r)},c.prototype.packIDAT=function(e){return this._packChunk(n.TYPE_IDAT,e)},c.prototype.packIEND=function(){return this._packChunk(n.TYPE_IEND,null)}})),b=r(((e,t)=>{let n=a(`util`),r=a(`stream`),i=d(),o=y(),s=t.exports=function(e){r.call(this);let t=e||{};this._packer=new o(t),this._deflate=this._packer.createDeflate(),this.readable=!0};n.inherits(s,r),s.prototype.pack=function(e,t,n,r){this.emit(`data`,Buffer.from(i.PNG_SIGNATURE)),this.emit(`data`,this._packer.packIHDR(t,n)),r&&this.emit(`data`,this._packer.packGAMA(r));let a=this._packer.filterData(e,t,n);this._deflate.on(`error`,this.emit.bind(this,`error`)),this._deflate.on(`data`,function(e){this.emit(`data`,this._packer.packIDAT(e))}.bind(this)),this._deflate.on(`end`,function(){this.emit(`data`,this._packer.packIEND()),this.emit(`end`)}.bind(this)),this._deflate.end(a)}})),x=r(((e,t)=>{let n=a(`assert`).ok,r=a(`zlib`),i=a(`util`),o=a(`buffer`).kMaxLength;function s(e){if(!(this instanceof s))return new s(e);e&&e.chunkSize<r.Z_MIN_CHUNK&&(e.chunkSize=r.Z_MIN_CHUNK),r.Inflate.call(this,e),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&e.maxLength!=null&&(this._maxLength=e.maxLength)}function c(e){return new s(e)}function l(e,t){t&&process.nextTick(t),e._handle&&=(e._handle.close(),null)}s.prototype._processChunk=function(e,t,i){if(typeof i==`function`)return r.Inflate._processChunk.call(this,e,t,i);let a=this,s=e&&e.length,c=this._chunkSize-this._offset,u=this._maxLength,d=0,f=[],p=0,m;this.on(`error`,function(e){m=e});function h(e,t){if(a._hadError)return;let r=c-t;if(n(r>=0,`have should not go down`),r>0){let e=a._buffer.slice(a._offset,a._offset+r);if(a._offset+=r,e.length>u&&(e=e.slice(0,u)),f.push(e),p+=e.length,u-=e.length,u===0)return!1}return(t===0||a._offset>=a._chunkSize)&&(c=a._chunkSize,a._offset=0,a._buffer=Buffer.allocUnsafe(a._chunkSize)),t===0?(d+=s-e,s=e,!0):!1}n(this._handle,`zlib binding closed`);let g;do g=this._handle.writeSync(t,e,d,s,this._buffer,this._offset,c),g||=this._writeState;while(!this._hadError&&h(g[0],g[1]));if(this._hadError)throw m;if(p>=o)throw l(this),RangeError(`Cannot create final Buffer. It would be larger than 0x`+o.toString(16)+` bytes`);let _=Buffer.concat(f,p);return l(this),_},i.inherits(s,r.Inflate);function u(e,t){if(typeof t==`string`&&(t=Buffer.from(t)),!(t instanceof Buffer))throw TypeError(`Not a string or buffer`);let n=e._finishFlushFlag;return n??=r.Z_FINISH,e._processChunk(t,n)}function d(e,t){return u(new s(t),e)}t.exports=e=d,e.Inflate=s,e.createInflate=c,e.inflateSync=d})),S=r(((e,t)=>{let n=t.exports=function(e){this._buffer=e,this._reads=[]};n.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},n.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}if(this._reads.length>0)throw Error(`There are some read requests waitng on finished stream`);if(this._buffer.length>0)throw Error(`unrecognised content at end of stream`)}})),C=r((e=>{let t=S(),n=l();e.process=function(e,r){let i=[],a=new t(e);return new n(r,{read:a.read.bind(a),write:function(e){i.push(e)},complete:function(){}}).start(),a.process(),Buffer.concat(i)}})),w=r(((e,t)=>{let n=!0,r=a(`zlib`),i=x();r.deflateSync||(n=!1);let o=S(),s=C(),c=p(),l=m(),u=h();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let a;function d(e){a=e}let f;function p(e){f=e}function m(e){f.transColor=e}function h(e){f.palette=e}function g(){f.alpha=!0}let _;function v(e){_=e}let y=[];function b(e){y.push(e)}let x=new o(e);if(new c(t,{read:x.read.bind(x),error:d,metadata:p,gamma:v,palette:h,transColor:m,inflateData:b,simpleTransparency:g}).start(),x.process(),a)throw a;let S=Buffer.concat(y);y.length=0;let C;if(f.interlace)C=r.inflateSync(S);else{let e=((f.width*f.bpp*f.depth+7>>3)+1)*f.height;C=i(S,{chunkSize:e,maxLength:e})}if(S=null,!C||!C.length)throw Error(`bad png - invalid inflate data response`);let w=s.process(C,f);S=null;let T=l.dataToBitMap(w,f);w=null;let E=u(T,f,t.skipRescale);return f.data=E,f.gamma=_||0,f}})),T=r(((e,t)=>{let n=!0,r=a(`zlib`);r.deflateSync||(n=!1);let i=d(),o=y();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let a=new o(t||{}),s=[];s.push(Buffer.from(i.PNG_SIGNATURE)),s.push(a.packIHDR(e.width,e.height)),e.gamma&&s.push(a.packGAMA(e.gamma));let c=a.filterData(e.data,e.width,e.height),l=r.deflateSync(c,a.getDeflateOptions());if(c=null,!l||!l.length)throw Error(`bad png - invalid compressed data response`);return s.push(a.packIDAT(l)),s.push(a.packIEND()),Buffer.concat(s)}})),E=r((e=>{let t=w(),n=T();e.read=function(e,n){return t(e,n||{})},e.write=function(e,t){return n(e,t)}})),D=r((e=>{let t=a(`util`),n=a(`stream`),r=g(),i=b(),o=E(),s=e.PNG=function(e){n.call(this),e||={},this.width=e.width|0,this.height=e.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new r(e),this._parser.on(`error`,this.emit.bind(this,`error`)),this._parser.on(`close`,this._handleClose.bind(this)),this._parser.on(`metadata`,this._metadata.bind(this)),this._parser.on(`gamma`,this._gamma.bind(this)),this._parser.on(`parsed`,function(e){this.data=e,this.emit(`parsed`,e)}.bind(this)),this._packer=new i(e),this._packer.on(`data`,this.emit.bind(this,`data`)),this._packer.on(`end`,this.emit.bind(this,`end`)),this._parser.on(`close`,this._handleClose.bind(this)),this._packer.on(`error`,this.emit.bind(this,`error`))};t.inherits(s,n),s.sync=o,s.prototype.pack=function(){return!this.data||!this.data.length?(this.emit(`error`,`No data provided`),this):(process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this)},s.prototype.parse=function(e,t){if(t){let e,n;e=function(e){this.removeListener(`error`,n),this.data=e,t(null,this)}.bind(this),n=function(n){this.removeListener(`parsed`,e),t(n,null)}.bind(this),this.once(`parsed`,e),this.once(`error`,n)}return this.end(e),this},s.prototype.write=function(e){return this._parser.write(e),!0},s.prototype.end=function(e){this._parser.end(e)},s.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit(`metadata`,e)},s.prototype._gamma=function(e){this.gamma=e},s.prototype._handleClose=function(){!this._parser.writable&&!this._packer.readable&&this.emit(`close`)},s.bitblt=function(e,t,n,r,i,a,o,s){if(n|=0,r|=0,i|=0,a|=0,o|=0,s|=0,n>e.width||r>e.height||n+i>e.width||r+a>e.height)throw Error(`bitblt reading outside image`);if(o>t.width||s>t.height||o+i>t.width||s+a>t.height)throw Error(`bitblt writing outside image`);for(let c=0;c<a;c++)e.data.copy(t.data,(s+c)*t.width+o<<2,(r+c)*e.width+n<<2,(r+c)*e.width+n+i<<2)},s.prototype.bitblt=function(e,t,n,r,i,a,o){return s.bitblt(this,e,t,n,r,i,a,o),this},s.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n**=1/2.2/e.gamma,e.data[r+t]=Math.round(n*255)}}e.gamma=0}},s.prototype.adjustGamma=function(){s.adjustGamma(this)}}))();function O(t,n){try{return D.PNG.sync.read(t)}catch(t){throw new e(`COMMAND_FAILED`,`Failed to decode ${n} as PNG`,{label:n,reason:t instanceof Error?t.message:String(t)})}}const k=.78,A={r:220,g:0,b:0};function j(e){let{baselineData:t,currentData:n,maxColorDistance:r}=e,i=e.width*e.height,a=Buffer.alloc(i*4),o=new Uint8Array(i),s=0;for(let e=0,i=0;e<t.length;e+=4,i+=1){let c=t[e]-n[e],l=t[e+1]-n[e+1],u=t[e+2]-n[e+2];if(Math.sqrt(c**2+l**2+u**2)>r){s+=1,o[i]=1;let t=M(n,e);a[e]=N(t,A.r,k),a[e+1]=N(t,A.g,k),a[e+2]=N(t,A.b,k),a[e+3]=255;continue}let d=M(n,e);a[e]=d,a[e+1]=d,a[e+2]=d,a[e+3]=255}return{diffData:a,diffMask:o,differentPixels:s}}function M(e,t){return N(Math.round(e[t]*.299+e[t+1]*.587+e[t+2]*.114),255,.72)}function N(e,t,n){return Math.round(e*(1-n)+t*n)}function P(e,t){let n={first:{width:e.width,height:e.height,dataLength:e.data.length},second:{width:t.width,height:t.height,dataLength:t.data.length}};if(e.width!==t.width||e.height!==t.height)return{...n,status:`dimension_mismatch`};let r=e.width*e.height;if(e.data.length!==t.data.length||e.data.length!==r*4)return{...n,status:`data_length_mismatch`};let i=0;for(let n=0;n<e.data.length;n+=4)i+=Math.abs(e.data[n]-t.data[n]),i+=Math.abs(e.data[n+1]-t.data[n+1]),i+=Math.abs(e.data[n+2]-t.data[n+2]);return{...n,status:`compared`,differencePercent:100*i/(765*r)}}function F(e){return Buffer.from(e.buffer,e.byteOffset,e.byteLength)}export{D as a,O as i,P as n,i as o,j as r,F as t};
|
package/dist/src/process-lock.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{t}from"./timeouts.js";import{n,o as r}from"./host-process.js";import i from"node:
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{t}from"./timeouts.js";import{n,o as r}from"./host-process.js";import i from"node:path";import a from"node:fs";async function o(n){let{lockDirPath:r,owner:o}=n,l=i.join(r,`owner.json`),d=Date.now()+(n.timeoutMs??3e4),f=n.pollMs??100,p=n.ownerGraceMs??5e3,m=n.description??`process lock`;for(a.mkdirSync(i.dirname(r),{recursive:!0});Date.now()<d;)try{a.mkdirSync(r),s(l,o);let e=!1;return async()=>{e||(e=!0,a.rmSync(r,{recursive:!0,force:!0}))}}catch(e){let n=e;if(n.code!==`EEXIST`)throw n;if(c(r,l,p))continue;await t(f)}throw new e(`COMMAND_FAILED`,`Timed out waiting for ${m}`,{lockDirPath:r,...u(r,l)})}function s(e,t){let n=`${e}.${process.pid}.${Date.now()}.tmp`;a.writeFileSync(n,JSON.stringify(t),`utf8`),a.renameSync(n,e)}function c(e,t,n){let r=null;try{r=a.statSync(e)}catch{return!0}let i=l(t);return i?d(i)?!1:(a.rmSync(e,{recursive:!0,force:!0}),!0):Date.now()-r.mtimeMs<n?!1:(a.rmSync(e,{recursive:!0,force:!0}),!0)}function l(e){try{return JSON.parse(a.readFileSync(e,`utf8`))}catch{return null}}function u(e,t){let n=Date.now(),r=l(t),i;try{i=Math.max(0,Math.round(n-a.statSync(e).mtimeMs))}catch{}return{...i===void 0?{}:{lockAgeMs:i},...r?{ownerPid:r.pid,ownerStartTime:r.startTime,ownerAgeMs:Math.max(0,Math.round(n-r.acquiredAtMs))}:{}}}function d(e){return!Number.isInteger(e.pid)||e.pid<=0||!n(e.pid)?!1:e.startTime?r(e.pid)===e.startTime:!0}export{o as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./png-worker-contract.js";import{_ as t}from"./sdk-contracts.js";import{p as n,v as r}from"./sdk-android-adb.js";import{n as i}from"./version.js";import{n as a,r as o}from"./src.js";import{n as s}from"./android.js";function c(){return{clientVersion:i(),android:{createInteractor:(e,t)=>s(e,t),createPortReverse:async e=>{let{createAndroidPortReverseManager:t}=await import(`./sdk-android-adb.js`).then(e=>e.t);return t(e)},inferAppName:async e=>{let{inferAndroidAppName:t}=await import(`./app-lifecycle.js`).then(e=>e.t);return t(e)},listApps:async(e,t)=>{let{listAndroidAppsWithAdb:n}=await import(`./app-helpers.js`).then(e=>e.t);return(await n(e,{filter:t,target:`mobile`})).map(e=>({id:e.package,name:e.name}))},getForegroundApp:async e=>{let{getAndroidAppStateWithAdb:t}=await import(`./app-helpers.js`).then(e=>e.t),n=await t(e);return n.package?{appId:n.package,activity:n.activity}:void 0},getKeyboardState:async e=>{let{getAndroidKeyboardStatusWithAdb:t}=await import(`./device-input-state.js`).then(e=>e.t);return await t(e)},dismissKeyboard:async e=>{let{dismissAndroidKeyboardWithAdb:t}=await import(`./device-input-state.js`).then(e=>e.t);return await t(e)},readLogs:async(e,t)=>{let{captureAndroidLogcatWithAdb:n}=await import(`./logcat.js`).then(e=>e.n);return await n(e,{lines:t,timeoutMs:5e3})},adbError:async(e,t,n)=>{let{androidAdbResultError:r}=await import(`./sdk-android-adb.js`).then(e=>e.t);return r(e,t,n)}},host:{runAdb:async(e,t)=>await r(`adb`,e,t),archiveDirectory:async({sourceDirectory:e,entryName:i,archivePath:a})=>{let o=[`-qr`,a,i],s=await r(`zip`,o,{cwd:e,timeoutMs:12e4});if(s.exitCode!==0)throw new t(`COMMAND_FAILED`,`Failed to package iOS .app for Limrun install`,{command:[`zip`,...o].join(` `),...n(s)})}},ios:{resolveAppAlias:async e=>{let{resolveIosAppAlias:t}=await import(`./app-resolution.js`).then(e=>e.t);return t(e)},readBundleAppName:async e=>{let{readIosBundleInfo:t}=await import(`./install-artifact2.js`).then(e=>e.t);return(await t(e)).appName}}}}var l=e({LimrunRuntime:()=>u}),u=class{implementation;provider=o;constructor(e){this.implementation=a(e,c())}get leaseLifecycle(){return this.implementation.leaseLifecycle}get recoverExpiredLease(){return this.implementation.recoverExpiredLease}get deviceInventoryProvider(){return this.implementation.deviceInventoryProvider}ownsDevice(e){return this.implementation.ownsDevice(e)}getInteractor(e){return this.implementation.getInteractor(e)}getDeviceSession(e){return this.implementation.getDeviceSession(e)}async installApp(e,t,n,r){return await this.implementation.installApp?.(e,t,n,r)}async installInstallablePath(e,t,n){return await this.implementation.installInstallablePath?.(e,t,n)}async configurePortReverse(e){return await this.implementation.configurePortReverse?.(e)}async shutdown(){await this.implementation.shutdown()}};export{l as n,u as t};
|
package/dist/src/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{S as e}from"./sdk-contracts.js";import{Ht as t,M as n,rn as r}from"./viewport-dimension.js";import{it as i}from"./sdk-batch-runner.js";import{f as a}from"./runtime.js";import{c as o,l as s,n as c,s as l}from"./context.js";import{Jt as u}from"./internal/daemon.js";import{i as d,n as f,t as p}from"./interaction-snapshot.js";async function m(r){let{req:i,sessionName:c,sessionStore:l}=r;if(i.command!==t.reactNative)return null;let u=h(i.positionals??[]);if(!u.ok)return u.response;let d=l.get(c);if(!d)return o();let f=s(t.reactNative,d.device,{message:`react-native dismiss-overlay is not supported on this device`});if(f)return f;try{let e=await p(d,i.flags,l,r.contextFromFlags,{interactiveOnly:!0});if(n(e.snapshotQuality))return _(e.snapshotQuality);let t=a(e.nodes),o=t.primaryAction;return o?await v(r,d,e,o):g(t.detected)}catch(t){return{ok:!1,error:e(t)}}}function h(e){return e.length===1&&e[0]===`dismiss-overlay`?{ok:!0}:{ok:!1,response:l(`INVALID_ARGS`,`react-native supports only: dismiss-overlay`)}}function g(e){return e?l(`COMMAND_FAILED`,`React Native overlay detected, but no safe dismiss target was found`,{hint:`Use screenshot --overlay-refs for visual evidence and report the overlay instead of pressing the warning body.`}):{ok:!0,data:{action:`dismiss-overlay`,detected:!1,dismissed:!1,...r(`No React Native overlay detected`)}}}function _(e){return l(`COMMAND_FAILED`,`React Native overlay state could not be determined because the accessibility tree is unreadable`,{reason:e.reason,hint:`The snapshot quality verdict is sparse. Use screenshot as visual truth; if an overlay is visible, report it or navigate with coordinates, then retry snapshot or dismiss-overlay on a readable screen.`})}async function v(e,t,n,a){let{req:o,sessionStore:s}=e,l=Date.now();u(t);let p=await c(t.device,`press`,[String(a.point.x),String(a.point.y)],o.flags?.out,e.contextFromFlags(o.flags,t.appBundleId,t.trace?.outPath))??{},m=Date.now(),h=await y(e,t),g=i({...f(n.nodes),...p,action:`dismiss-overlay`,overlayAction:a.action,x:a.point.x,y:a.point.y,ref:a.ref,label:a.label,warning:a.warning,dismissed:!0,verified:h.verified,verificationRequired:!h.verified,verificationWarning:h.verificationWarning,nextCommand:h.nextCommand,...r(b(h))});return d({session:t,sessionStore:s,command:o.command,positionals:o.positionals??[],flags:o.flags,result:g,responseData:g,actionStartedAt:l,actionFinishedAt:m})}async function y(e,t){let{req:r,sessionStore:i}=e,o=await p(t,r.flags,i,e.contextFromFlags,{interactiveOnly:!0});return n(o.snapshotQuality)?{verified:!1,verificationWarning:`React Native overlay dismissal could not be verified because the post-dismiss accessibility tree is unreadable. Use screenshot as visual truth.`,nextCommand:`agent-device screenshot`}:a(o.nodes).detected?{verified:!1,verificationWarning:`React Native overlay is still detected after dismissal. Use screenshot --overlay-refs for visual evidence and report the overlay instead of pressing the warning body.`,nextCommand:`agent-device screenshot --overlay-refs`}:{verified:!0}}function b(e){return e.verified?`React Native overlay dismiss action sent and verified gone`:`React Native overlay dismiss action sent, but verification still detects an overlay`}export{m as handleReactNativeCommands};
|
package/dist/src/record-trace.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{C as e}from"./screenshot-result.js";import{s as t}from"./context.js";import{c as n,h as r}from"./internal/daemon.js";import i from"node:path";import a from"node:fs";async function o(o){let{req:s,sessionName:c,sessionStore:l,logPath:u}=o,d=s.command;if(d===`record`)return n({req:s,sessionName:c,sessionStore:l,logPath:u});if(d===`trace`){let n=(s.positionals?.[0]??``).toLowerCase();if(![`start`,`stop`].includes(n))return t(`INVALID_ARGS`,`trace requires start|stop`);let o=l.get(c);if(!o)return t(`SESSION_NOT_FOUND`,`No active session`);if(n===`start`){if(o.trace)return t(`INVALID_ARGS`,`trace already in progress`);let n=s.positionals?.[1]??l.defaultTracePath(o),c=e.expandHome(n);return a.mkdirSync(i.dirname(c),{recursive:!0}),a.appendFileSync(c,``),o.trace={outPath:c,startedAt:Date.now()},r(l,o,s,d,{action:`start`,outPath:c}),{ok:!0,data:{trace:`started`,outPath:c}}}if(!o.trace)return t(`INVALID_ARGS`,`no active trace`);let u=o.trace.outPath;if(s.positionals?.[1]){let t=e.expandHome(s.positionals[1]);a.mkdirSync(i.dirname(t),{recursive:!0}),a.existsSync(u)?a.renameSync(u,t):a.appendFileSync(t,``),u=t}o.trace=void 0,r(l,o,s,d,{action:`stop`,outPath:u});let f=s.meta?.clientArtifactPaths?.outPath??u;return{ok:!0,data:{trace:`stopped`,outPath:u,artifacts:[{field:`outPath`,artifactType:`trace-log`,path:u,localPath:f,fileName:i.basename(f)}]}}}return null}export{o as handleRecordTraceCommands};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{Ht as t}from"./viewport-dimension.js";import{c as n,f as r,o as i,y as a}from"./sdk-device.js";import{l as o,o as s,p as c,s as l}from"./device.js";async function u(e){if(e.platform===`web`)return[l];if(o(e)){let{listMacosDevices:e}=await import(`./devices.js`);return await e()}if(e.platform===`linux`){let{listLinuxDevices:e}=await import(`./devices3.js`);return await e()}if(e.platform===`android`){let{listAndroidDevices:t}=await import(`./install-artifact.js`).then(e=>e.o);return await t({serialAllowlist:d(e)})}if(e.platform===`vega`){let{listVegaDevices:e}=await import(`./devices4.js`);return await e()}if(e.platform){let{listAppleDevices:t}=await import(`./devices2.js`);return await t({simulatorSetPath:e.iosSimulatorSetPath,udid:e.udid})}return(await Promise.all(s.map(async t=>{try{let n=await u({...e,platform:t});return Array.isArray(n)?n:[]}catch{return[]}}))).flat()}function d(e){let t=e.androidSerialAllowlist,n=e.serial?.trim();return n?t?new Set(t.includes(n)?[n]:[]):new Set([n]):t?new Set(t):void 0}const f=new Map;function p(e){for(let t of e.platforms){if(f.has(t))throw Error(`PlatformPlugin already registered for platform "${t}"`);f.set(t,e)}}function m(t){let n=f.get(t);if(!n)throw new e(`UNSUPPORTED_PLATFORM`,`Unsupported platform: ${t}`);return n}function h(e){return f.get(e)}const g={appAndDeviceLifecycle:!0,keyboard:!0,orientation:!0,physicalDeviceSurfaces:!1},_={ios:g,ipados:g,visionos:{appAndDeviceLifecycle:!0,keyboard:!0,orientation:!0,physicalDeviceSurfaces:!1},tvos:{appAndDeviceLifecycle:!0,keyboard:!1,orientation:!1,physicalDeviceSurfaces:!1},macos:{appAndDeviceLifecycle:!1,keyboard:!1,orientation:!1,physicalDeviceSurfaces:!0},watchos:{appAndDeviceLifecycle:!1,keyboard:!1,orientation:!1,physicalDeviceSurfaces:!1}};function v(e){return i(e.platform)?_[a(e)]:void 0}const y=e=>{let t=v(e);return t?t.appAndDeviceLifecycle:!0},b=e=>e.platform!==`apple`||e.kind!==`device`||e.iosPhysicalDeviceBackend!==`xctest`,x=e=>y(e)&&b(e),S=e=>{let t=v(e);return t?t.keyboard:e.platform===`android`},C=e=>{let t=v(e);return t?t.orientation:e.platform===`android`},w=e=>{let t=v(e);return t&&t.physicalDeviceSurfaces||e.kind===`simulator`},T=e=>e.platform===`android`||e.platform===`apple`&&a(e)===`ios`||w(e),E=e=>e.platform===`android`?e.target===`tv`:r(e),D={[t.boot]:y,[t.apps]:b,[t.install]:x,[t.reinstall]:x,[t.installFromSource]:x,[t.logs]:b,[t.perf]:b,[t.record]:b,[t.push]:y,[t.home]:y,[t.appSwitcher]:y,[t.clipboard]:e=>e.platform===`android`||e.platform===`linux`||w(e),[t.keyboard]:S,[t.orientation]:C,[t.tvRemote]:E,[t.alert]:T,[t.settings]:e=>e.platform===`android`||w(e),[t.audio]:c},O={[t.apps]:k,[t.install]:k,[t.reinstall]:k,[t.installFromSource]:k,[t.logs]:k,[t.perf]:k,[t.record]:k,[t.viewport]:e=>e.platform===`apple`?`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`:void 0,[t.tvRemote]:e=>e.platform===`android`?e.target===`tv`?void 0:`tv-remote is supported only on Android TV targets.`:v(e)?r(e)?void 0:`tv-remote is supported only on tvOS devices.`:void 0};function k(e){if(!b(e))return`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`}const A={id:`apple`,platforms:[`apple`],familySelector:`apple`,capability:{bucket:`apple`,supportsByDefault:D,unsupportedHintByDefault:O},appLog:{resolveBackend:e=>n(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`},perf:{supportsMetrics:()=>!0,metricsSamplerTag:()=>`apple`},recording:{resolveBackendTag:e=>n(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`},providers:{platformGatedResolvers:[`appleRunnerProvider`,`appleToolProvider`]},createInteractor:async(e,t)=>{let{createAppleInteractor:n}=await import(`./interactor.js`);return n(e,t)},discoverDevices:async e=>{if(o(e)){let{listMacosDevices:e}=await import(`./devices.js`);return await e()}let{listAppleDevices:t}=await import(`./devices2.js`);return await t({simulatorSetPath:e.iosSimulatorSetPath,udid:e.udid})}},j=[t.open,t.close,t.back,t.home,t.tvRemote],M=e=>e.target===`tv`,N=e=>e.kind===`emulator`&&M(e),P={id:`vega`,platforms:[`vega`],capability:{bucket:`vega`,supportsByDefault:Object.fromEntries(j.map(e=>[e,M])),unsupportedHintByDefault:Object.fromEntries(j.map(e=>[e,t=>N(t)?void 0:`${e} currently supports only Vega Virtual Devices.`]))},providers:{platformGatedResolvers:[`vegaToolProvider`]},createInteractor:async(e,t)=>{let{createVegaInteractor:n}=await import(`./interactor2.js`);return n(e,t)},discoverDevices:async e=>{let{listVegaDevices:t}=await import(`./devices4.js`);return await t()}},F=[A,{id:`android`,platforms:[`android`],capability:{bucket:`android`,supportsByDefault:{[t.audio]:c,[t.tvRemote]:e=>e.target===`tv`},unsupportedHintByDefault:{[t.tvRemote]:e=>e.target===`tv`?void 0:`tv-remote is supported only on Android TV targets.`}},appLog:{resolveBackend:()=>`android`},perf:{supportsMetrics:()=>!0,metricsSamplerTag:()=>`android`},recording:{resolveBackendTag:()=>`android`},providers:{platformGatedResolvers:[`androidAdbProvider`]},createInteractor:async(e,t)=>{let{createAndroidInteractor:n}=await import(`./android.js`).then(e=>e.t);return n(e,void 0,t)},discoverDevices:async e=>{let{listAndroidDevices:t}=await import(`./install-artifact.js`).then(e=>e.o);return await t({serialAllowlist:d(e)})}},P,{id:`linux`,platforms:[`linux`],capability:{bucket:`linux`},providers:{platformGatedResolvers:[`linuxToolProvider`]},createInteractor:async()=>{let{createLinuxInteractor:e}=await import(`./linux.js`);return e()},discoverDevices:async()=>{let{listLinuxDevices:e}=await import(`./devices3.js`);return await e()}},{id:`web`,platforms:[`web`],capability:{bucket:`web`},recording:{resolveBackendTag:()=>`web`},providers:{platformGatedResolvers:[`webProvider`]},createInteractor:async()=>{let{createWebInteractor:e}=await import(`./web.js`);return e()},discoverDevices:async()=>[l]}];let I=!1;function L(){if(!I){for(let e of F)p(e);I=!0}}export{u as i,m as n,h as r,L as t};
|