@deeeed/metamask-harness 0.73.0 → 0.75.0
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/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/adapters/shared/ensure-runner-deps.sh +15 -3
- package/dist/action-values.js +15 -0
- package/dist/adapters/core/actions.js +20 -0
- package/dist/adapters/core/live-script-env.js +36 -0
- package/dist/adapters/core/run.js +54 -0
- package/dist/adapters/core/surface.js +8 -1
- package/dist/adapters/extension/action-inputs.js +206 -0
- package/dist/adapters/extension/actions.js +51 -0
- package/dist/adapters/extension/console-capture.js +13 -1
- package/dist/adapters/extension/launch.js +315 -0
- package/dist/adapters/extension/launched-browser.js +51 -0
- package/dist/adapters/extension/run.js +105 -0
- package/dist/adapters/extension/surface.js +17 -1
- package/dist/adapters/mobile/actions.js +54 -0
- package/dist/adapters/mobile/launch.js +192 -0
- package/dist/adapters/mobile/lifecycle.js +300 -0
- package/dist/adapters/mobile/run.js +156 -0
- package/dist/adapters/mobile/runtime-identity.js +34 -0
- package/dist/adapters/mobile/surface.js +19 -1
- package/dist/adapters/mobile/ui.js +701 -0
- package/dist/adapters/performance/cdp-trace.js +24 -6
- package/dist/adapters/performance/device-platform.js +10 -0
- package/dist/adapters/registry.js +17 -0
- package/dist/adapters/surface.js +6 -11
- package/dist/adapters/terminal/actions.js +43 -0
- package/dist/adapters/terminal/console-capture.js +14 -1
- package/dist/adapters/terminal/launch.js +85 -0
- package/dist/adapters/terminal/run.js +30 -0
- package/dist/adapters/terminal/surface.js +9 -1
- package/dist/adapters.js +32 -824
- package/dist/cli-commands.js +1 -0
- package/dist/command-contract.js +3 -0
- package/dist/commands/call.js +2 -5
- package/dist/commands/launch/device.js +342 -0
- package/dist/commands/launch/index.js +9 -942
- package/dist/commands/launch/quote.js +7 -0
- package/dist/commands/pin.js +226 -0
- package/dist/commands/review.js +3 -1
- package/dist/commands/run-engine.js +38 -138
- package/dist/commands/run-report.js +4 -48
- package/dist/commands/run.js +6 -48
- package/dist/commands/shared.js +2 -2
- package/dist/doctor.js +3 -1
- package/dist/execution-provenance.js +3 -2
- package/dist/harness-pin.js +10 -0
- package/dist/heal-bounds.js +3 -2
- package/dist/live-adapter-contract.js +8 -34
- package/dist/manifest.js +3 -5
- package/dist/metamask-action-validation.js +5 -196
- package/dist/mm-harness-cli.js +27 -2
- package/dist/network-observation.js +10 -3
- package/dist/performance-observation.js +15 -22
- package/dist/pr-body/render.js +3 -1
- package/dist/recording-target.js +4 -39
- package/dist/run-diagnostics.js +21 -60
- package/dist/run-recording.js +5 -4
- package/dist/runner.js +20 -368
- package/docs/CONTRIBUTING.md +20 -3
- package/package.json +2 -1
- package/scripts/completions.sh +2 -1
package/dist/runner.js
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
2
|
import { OFFICIAL_RECIPE_ACTIONS } from "@farmslot/protocol";
|
|
3
|
-
import { createAndroidMirrorVideoRecorder } from "@farmslot/recipe-harness";
|
|
4
3
|
import { createMetaMaskAdapters, createMetaMaskUiTransport } from "./adapters.js";
|
|
5
|
-
import {
|
|
6
|
-
bridgeCommand,
|
|
7
|
-
MOBILE_BRIDGE_ERROR_CODES
|
|
8
|
-
} from "../library/actions/mobile/platform/bridge.mjs";
|
|
9
|
-
import { resolveMobileToolPath } from "../library/actions/mobile/platform/tool-paths.mjs";
|
|
10
|
-
import {
|
|
11
|
-
mobileSourceFingerprint,
|
|
12
|
-
recordMobileSourceBaseline
|
|
13
|
-
} from "./adapters/mobile/source-freshness.js";
|
|
14
|
-
import { readAndroidNativeRuntimeIdentity } from "./adapters/mobile/release-artifact.js";
|
|
15
|
-
import { readMobileReleaseArtifactState } from "./adapters/mobile/release-artifact-state.js";
|
|
16
|
-
import {
|
|
17
|
-
createAndroidVideoRecorder,
|
|
18
|
-
createIosSimulatorVideoRecorder
|
|
19
|
-
} from "./adapters/mobile/video-recorder.js";
|
|
4
|
+
import { getAdapterSurface } from "./adapters/surface.js";
|
|
20
5
|
import {
|
|
21
6
|
bindMetaMaskMobileLifecycleDeadline,
|
|
22
7
|
createMetaMaskMobileLifecycleCommandRunner,
|
|
23
|
-
MOBILE_LIFECYCLE_DEADLINE_FIELD,
|
|
24
|
-
MOBILE_LIFECYCLE_PREPARED,
|
|
25
8
|
resolveMetaMaskMobileLifecycleTarget
|
|
26
9
|
} from "./app-lifecycle.js";
|
|
27
10
|
import { loadMetaMaskExtensionActionManifest, loadMetaMaskMobileActionManifest } from "./manifest.js";
|
|
@@ -29,11 +12,7 @@ import { actionSourceIntegrity, metaMaskActionExecutionCapabilities } from "./re
|
|
|
29
12
|
import {
|
|
30
13
|
prepareLiveAdapterScript
|
|
31
14
|
} from "./live-adapter-contract.js";
|
|
32
|
-
import {
|
|
33
|
-
createMetaMaskRecordingTargetProvider,
|
|
34
|
-
resolveAndroidDeviceSerial,
|
|
35
|
-
resolveMobileIosSimulatorName
|
|
36
|
-
} from "./recording-target.js";
|
|
15
|
+
import { createMetaMaskRecordingTargetProvider } from "./recording-target.js";
|
|
37
16
|
import {
|
|
38
17
|
importMetaMaskNativeUiProvider,
|
|
39
18
|
importRecipeHarness,
|
|
@@ -92,16 +71,15 @@ async function createMetaMaskRunner(adapter, actionManifest, options = {}) {
|
|
|
92
71
|
}, preparedLiveAdapters, { hudPolicy: options.autoHud === true ? "show" : "auto" })
|
|
93
72
|
});
|
|
94
73
|
const existing = new Set([...core, ...ui].map((entry) => entry.action));
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
103
|
-
)
|
|
74
|
+
const surface = getAdapterSurface(adapter);
|
|
75
|
+
const lifecycleAdapters = bindMetaMaskMobileLifecycleDeadline(
|
|
76
|
+
createAppLifecycleAdapters({
|
|
77
|
+
actions,
|
|
78
|
+
commandRunner: createMetaMaskMobileLifecycleCommandRunner(),
|
|
79
|
+
targetProvider: { resolveTarget: resolveMetaMaskMobileLifecycleTarget }
|
|
80
|
+
})
|
|
104
81
|
);
|
|
82
|
+
const lifecycle = surface.actions.lifecycle ? await surface.actions.lifecycle(lifecycleAdapters) : lifecycleAdapters;
|
|
105
83
|
const custom = createMetaMaskAdapters(
|
|
106
84
|
adapter,
|
|
107
85
|
customActions,
|
|
@@ -117,31 +95,22 @@ async function createMetaMaskRunner(adapter, actionManifest, options = {}) {
|
|
|
117
95
|
options.quietStdout ? new console.Console(process.stderr) : console,
|
|
118
96
|
options.suppressLibraryResolutionLogs
|
|
119
97
|
);
|
|
120
|
-
const
|
|
121
|
-
const
|
|
98
|
+
const videoRecorder = await surface.recording?.videoRecorder?.();
|
|
99
|
+
const secured = [...core, ...ui, ...lifecycle, ...custom].map((entry) => ({
|
|
100
|
+
...entry,
|
|
101
|
+
...adapterSecurity(entry.action, actionSources, options.trustTaskActions)
|
|
102
|
+
}));
|
|
103
|
+
const mutationBound = surface.actions.trustedMutation ? withTrustedMutationContext(secured, options.trustedMutation, externalMutationActions) : secured;
|
|
122
104
|
return createRecipeRunner({
|
|
123
105
|
actionManifest,
|
|
124
106
|
adapters: withActionProgress(
|
|
125
|
-
|
|
126
|
-
adapter,
|
|
127
|
-
withTrustedMutationContext(
|
|
128
|
-
[...core, ...ui, ...lifecycle, ...custom].map((entry) => ({
|
|
129
|
-
...entry,
|
|
130
|
-
...adapterSecurity(entry.action, actionSources, options.trustTaskActions)
|
|
131
|
-
})),
|
|
132
|
-
options.trustedMutation,
|
|
133
|
-
externalMutationActions,
|
|
134
|
-
adapter
|
|
135
|
-
)
|
|
136
|
-
),
|
|
107
|
+
surface.actions.wrap ? await surface.actions.wrap(mutationBound) : mutationBound,
|
|
137
108
|
options.onActionEvent
|
|
138
109
|
),
|
|
139
110
|
logger,
|
|
140
111
|
recording: {
|
|
141
112
|
targetProvider: createMetaMaskRecordingTargetProvider(adapter),
|
|
142
|
-
...
|
|
143
|
-
videoRecorder: createIosSimulatorVideoRecorder(iosRecordingSimulator)
|
|
144
|
-
} : {}
|
|
113
|
+
...videoRecorder ? { videoRecorder } : {}
|
|
145
114
|
},
|
|
146
115
|
runner: runnerProvenance(),
|
|
147
116
|
defaultSource: {
|
|
@@ -161,38 +130,7 @@ async function createMetaMaskRunner(adapter, actionManifest, options = {}) {
|
|
|
161
130
|
}
|
|
162
131
|
});
|
|
163
132
|
}
|
|
164
|
-
function
|
|
165
|
-
state: readMobileReleaseArtifactState,
|
|
166
|
-
read: readAndroidNativeRuntimeIdentity
|
|
167
|
-
}) {
|
|
168
|
-
if (adapter !== "mobile") return adapters;
|
|
169
|
-
return adapters.map((entry) => ({
|
|
170
|
-
...entry,
|
|
171
|
-
async execute(node, context) {
|
|
172
|
-
const state = identity.state(context.projectRoot);
|
|
173
|
-
if (!state) {
|
|
174
|
-
if (context.env.METAMASK_RECIPE_MOBILE_OPAQUE_RUNTIME === "1") {
|
|
175
|
-
throw new Error("Mobile release-artifact actions require current trusted runtime state. Next: rerun runtime-launch with the exact artifact.");
|
|
176
|
-
}
|
|
177
|
-
return entry.execute(node, context);
|
|
178
|
-
}
|
|
179
|
-
identity.read(state);
|
|
180
|
-
const result = await entry.execute(node, context);
|
|
181
|
-
const nativeRuntimeIdentity = identity.read(state);
|
|
182
|
-
const output = result.output && typeof result.output === "object" && !Array.isArray(result.output) ? result.output : { result: result.output };
|
|
183
|
-
return {
|
|
184
|
-
...result,
|
|
185
|
-
output: {
|
|
186
|
-
...output,
|
|
187
|
-
nativeRuntimeIdentity,
|
|
188
|
-
runtimeSessionId: nativeRuntimeIdentity.runtimeSessionId
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}));
|
|
193
|
-
}
|
|
194
|
-
function withTrustedMutationContext(adapters, base, externalMutationActions, adapter = "extension") {
|
|
195
|
-
if (adapter !== "extension") return adapters;
|
|
133
|
+
function withTrustedMutationContext(adapters, base, externalMutationActions) {
|
|
196
134
|
let selectedIdentitySha256;
|
|
197
135
|
const identityProofAction = "metamask.wallet.import";
|
|
198
136
|
const identityInvalidatingActions = /* @__PURE__ */ new Set([
|
|
@@ -353,289 +291,6 @@ function isAutomaticHudProgress(action, node, nodeId) {
|
|
|
353
291
|
const progress = payload.progress;
|
|
354
292
|
return nodeId === "recipe-complete" && progress !== null && typeof progress === "object" && !Array.isArray(progress) && progress.complete === true;
|
|
355
293
|
}
|
|
356
|
-
function mobileSourceAwareLifecycleAdapters(adapter, lifecycle, readinessProbe = probeMobileLifecycleRuntime, sourceFreshness = {
|
|
357
|
-
fingerprint: mobileSourceFingerprint,
|
|
358
|
-
record: recordMobileSourceBaseline
|
|
359
|
-
}, processIdentity = {
|
|
360
|
-
readIosPid: readIosAppPid,
|
|
361
|
-
readAndroidPid: readAndroidAppPid
|
|
362
|
-
}, runtimeMarker = readMobileLifecycleRuntimeIdentity) {
|
|
363
|
-
if (adapter !== "mobile") return lifecycle;
|
|
364
|
-
return lifecycle.map((entry) => ({
|
|
365
|
-
...entry,
|
|
366
|
-
async execute(node, context) {
|
|
367
|
-
const command = node.command ?? node.event ?? node.state;
|
|
368
|
-
const opaqueRuntime = context.env?.METAMASK_RECIPE_MOBILE_OPAQUE_RUNTIME === "1";
|
|
369
|
-
const requiresProcessContinuity = command !== "restart" && node.require_process_continuity === true;
|
|
370
|
-
if (opaqueRuntime && !requiresProcessContinuity) {
|
|
371
|
-
return entry.execute(node, context);
|
|
372
|
-
}
|
|
373
|
-
const reloadsSource = !opaqueRuntime && (command === "launch" || command === "foreground" || command === "restart");
|
|
374
|
-
const recordsSource = !opaqueRuntime && command === "restart";
|
|
375
|
-
const androidLifecycle = isAndroidLifecycle(node, context.env ?? {});
|
|
376
|
-
const checksIosContinuity = command === "foreground" && !androidLifecycle;
|
|
377
|
-
const checksRequiredContinuity = requiresProcessContinuity;
|
|
378
|
-
const recordsProcessIdentity = checksIosContinuity || checksRequiredContinuity;
|
|
379
|
-
const readProcessId = androidLifecycle ? processIdentity.readAndroidPid ?? readAndroidAppPid : processIdentity.readIosPid;
|
|
380
|
-
const processBefore = recordsProcessIdentity ? readProcessId(node, context) : void 0;
|
|
381
|
-
const fingerprint = recordsSource ? sourceFreshness.fingerprint(context.projectRoot) : void 0;
|
|
382
|
-
const previousRuntimeIdentity = recordsSource ? await runtimeMarker(node, context) : void 0;
|
|
383
|
-
const androidRestart = command === "restart" && androidLifecycle;
|
|
384
|
-
const initialResult = await entry.execute(node, context);
|
|
385
|
-
const readinessDeadline = reloadsSource ? mobileLifecycleReadinessDeadline(command, node) : void 0;
|
|
386
|
-
let result = initialResult;
|
|
387
|
-
let runtimeReady = false;
|
|
388
|
-
if (androidRestart) {
|
|
389
|
-
try {
|
|
390
|
-
const remainingMs = Math.max(
|
|
391
|
-
1,
|
|
392
|
-
(readinessDeadline ?? Date.now()) - Date.now()
|
|
393
|
-
);
|
|
394
|
-
const handoffDeadline = Math.min(
|
|
395
|
-
readinessDeadline ?? Number.POSITIVE_INFINITY,
|
|
396
|
-
Date.now() + Math.min(1e4, Math.max(1, remainingMs / 2))
|
|
397
|
-
);
|
|
398
|
-
await readinessProbe(
|
|
399
|
-
node,
|
|
400
|
-
context,
|
|
401
|
-
previousRuntimeIdentity,
|
|
402
|
-
handoffDeadline
|
|
403
|
-
);
|
|
404
|
-
runtimeReady = true;
|
|
405
|
-
} catch (error) {
|
|
406
|
-
if (readinessDeadline !== void 0 && Date.now() >= readinessDeadline) {
|
|
407
|
-
throw error;
|
|
408
|
-
}
|
|
409
|
-
const foregroundTimeoutMs = Math.max(
|
|
410
|
-
1,
|
|
411
|
-
(readinessDeadline ?? Date.now() + 1) - Date.now()
|
|
412
|
-
);
|
|
413
|
-
const foregroundResult = await entry.execute(
|
|
414
|
-
{
|
|
415
|
-
...node,
|
|
416
|
-
command: "foreground",
|
|
417
|
-
settle_ms: 0,
|
|
418
|
-
timeout_ms: foregroundTimeoutMs,
|
|
419
|
-
[MOBILE_LIFECYCLE_DEADLINE_FIELD]: readinessDeadline,
|
|
420
|
-
[MOBILE_LIFECYCLE_PREPARED]: true
|
|
421
|
-
},
|
|
422
|
-
context
|
|
423
|
-
);
|
|
424
|
-
result = mergeAndroidRestartResults(initialResult, foregroundResult);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if (reloadsSource && !runtimeReady) {
|
|
428
|
-
if (readinessDeadline !== void 0 && Date.now() >= readinessDeadline) {
|
|
429
|
-
throw new Error(
|
|
430
|
-
`Mobile lifecycle ${String(command)} exhausted its runtime readiness deadline before recovery completed.`
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
await readinessProbe(
|
|
434
|
-
node,
|
|
435
|
-
context,
|
|
436
|
-
previousRuntimeIdentity,
|
|
437
|
-
readinessDeadline
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
if (recordsProcessIdentity) {
|
|
441
|
-
const processAfter = readProcessId(node, context);
|
|
442
|
-
const processPreserved = processBefore !== null && processBefore === processAfter;
|
|
443
|
-
const actualTransition = processPreserved ? command === "background" ? "background_same_process" : "foreground_resume" : processAfter !== null ? "cold_relaunch" : "unknown";
|
|
444
|
-
const processContinuity = processPreserved ? "preserved" : processAfter === null ? "unknown" : "changed";
|
|
445
|
-
const resultRecord = asRecord(result);
|
|
446
|
-
result = {
|
|
447
|
-
...resultRecord,
|
|
448
|
-
output: {
|
|
449
|
-
...asRecord(resultRecord.output),
|
|
450
|
-
actualTransition,
|
|
451
|
-
processContinuity,
|
|
452
|
-
processBefore,
|
|
453
|
-
processAfter
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
if (checksRequiredContinuity && !processPreserved) {
|
|
457
|
-
const platform = androidLifecycle ? "Android" : "iOS";
|
|
458
|
-
throw new Error(
|
|
459
|
-
`${platform} ${String(command)} did not prove app-process continuity (actualTransition=${actualTransition}, before=${String(processBefore)}, after=${String(processAfter)}); this lifecycle sample cannot be classified as a same-process reconnect.`
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (fingerprint !== void 0 && !sourceFreshness.record(context.projectRoot, fingerprint)) {
|
|
464
|
-
throw new Error(
|
|
465
|
-
"Mobile source changed while the app was reloading; the loaded-source baseline was not recorded. Next: retry app.lifecycle restart."
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
return result;
|
|
469
|
-
}
|
|
470
|
-
}));
|
|
471
|
-
}
|
|
472
|
-
function readAndroidAppPid(node, context) {
|
|
473
|
-
const env = context.env ?? {};
|
|
474
|
-
const device = node.adb_serial ?? node.android_device ?? node.device ?? env.ADB_SERIAL ?? env.ANDROID_SERIAL ?? process.env.ADB_SERIAL ?? process.env.ANDROID_SERIAL;
|
|
475
|
-
const packageId = node.package_id ?? node.packageName ?? node.app_id ?? env.ANDROID_PACKAGE_ID ?? process.env.ANDROID_PACKAGE_ID ?? "io.metamask";
|
|
476
|
-
if (typeof device !== "string" || typeof packageId !== "string") return null;
|
|
477
|
-
try {
|
|
478
|
-
const adb = resolveMobileToolPath("adb", { required: true });
|
|
479
|
-
const output = execFileSync(
|
|
480
|
-
adb,
|
|
481
|
-
["-s", device, "shell", "pidof", packageId],
|
|
482
|
-
{ encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }
|
|
483
|
-
);
|
|
484
|
-
const pid = Number.parseInt(output.trim().split(/\s+/u)[0] ?? "", 10);
|
|
485
|
-
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
486
|
-
} catch {
|
|
487
|
-
return null;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function readIosAppPid(node, context) {
|
|
491
|
-
const env = context.env ?? {};
|
|
492
|
-
const device = node.simulator ?? node.ios_simulator ?? env.SIM_UDID ?? env.IOS_SIMULATOR ?? process.env.SIM_UDID ?? process.env.IOS_SIMULATOR;
|
|
493
|
-
const bundleId = node.bundle_id ?? node.bundleId ?? env.IOS_BUNDLE_ID ?? process.env.IOS_BUNDLE_ID ?? "io.metamask.MetaMask";
|
|
494
|
-
if (typeof device !== "string" || typeof bundleId !== "string") return null;
|
|
495
|
-
try {
|
|
496
|
-
const output = execFileSync(
|
|
497
|
-
"xcrun",
|
|
498
|
-
["simctl", "spawn", device, "launchctl", "list"],
|
|
499
|
-
{ encoding: "utf8", timeout: 5e3 }
|
|
500
|
-
);
|
|
501
|
-
const labelPrefix = `UIKitApplication:${bundleId}[`;
|
|
502
|
-
const line = output.split("\n").find((candidate) => candidate.includes(labelPrefix));
|
|
503
|
-
if (!line) return null;
|
|
504
|
-
const pid = Number.parseInt(line.trim().split(/\s+/u)[0] ?? "", 10);
|
|
505
|
-
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
506
|
-
} catch {
|
|
507
|
-
return null;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
function isAndroidLifecycle(node, env) {
|
|
511
|
-
const platform = node.platform ?? env.PLATFORM ?? process.env.PLATFORM;
|
|
512
|
-
if (platform === "android") return true;
|
|
513
|
-
if (platform === "ios") return false;
|
|
514
|
-
return Boolean(
|
|
515
|
-
node.adb_serial ?? node.android_device ?? env.ADB_SERIAL ?? env.ANDROID_SERIAL ?? process.env.ADB_SERIAL ?? process.env.ANDROID_SERIAL
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
function mergeAndroidRestartResults(initialResult, foregroundResult) {
|
|
519
|
-
const initial = asRecord(initialResult);
|
|
520
|
-
const foreground = asRecord(foregroundResult);
|
|
521
|
-
const initialOutput = asRecord(initial.output);
|
|
522
|
-
const foregroundOutput = asRecord(foreground.output);
|
|
523
|
-
return {
|
|
524
|
-
...initial,
|
|
525
|
-
output: {
|
|
526
|
-
...initialOutput,
|
|
527
|
-
command: "restart",
|
|
528
|
-
calls: [
|
|
529
|
-
...Array.isArray(initialOutput.calls) ? initialOutput.calls : [],
|
|
530
|
-
...Array.isArray(foregroundOutput.calls) ? foregroundOutput.calls : []
|
|
531
|
-
],
|
|
532
|
-
settleMs: foregroundOutput.settleMs ?? initialOutput.settleMs ?? 0,
|
|
533
|
-
foregroundEnsured: true
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
async function probeMobileLifecycleRuntime(node, context, previousRuntimeIdentity, deadlineMs) {
|
|
538
|
-
const command = node.command ?? node.event ?? node.state;
|
|
539
|
-
const timeoutMs = resolveMobileLifecycleReadinessTimeout(
|
|
540
|
-
command,
|
|
541
|
-
node.runtime_ready_timeout_ms
|
|
542
|
-
);
|
|
543
|
-
const startedAt = Date.now();
|
|
544
|
-
const deadline = deadlineMs ?? startedAt + timeoutMs;
|
|
545
|
-
let lastError;
|
|
546
|
-
while (Date.now() < deadline) {
|
|
547
|
-
try {
|
|
548
|
-
const status = await bridgeCommand(
|
|
549
|
-
{
|
|
550
|
-
action: "app.lifecycle",
|
|
551
|
-
node: {
|
|
552
|
-
...node,
|
|
553
|
-
cdp_timeout_ms: Math.min(8e3, Math.max(1, deadline - Date.now()))
|
|
554
|
-
},
|
|
555
|
-
context
|
|
556
|
-
},
|
|
557
|
-
["status-selected"]
|
|
558
|
-
);
|
|
559
|
-
if (status?.agenticPresent === true && status.route && (!previousRuntimeIdentity || status.runtimeIdentity !== previousRuntimeIdentity)) {
|
|
560
|
-
return status;
|
|
561
|
-
}
|
|
562
|
-
lastError = new Error(
|
|
563
|
-
previousRuntimeIdentity && status?.runtimeIdentity === previousRuntimeIdentity ? "retiring Mobile runtime is still selected" : "selected Mobile runtime is not ready"
|
|
564
|
-
);
|
|
565
|
-
} catch (error) {
|
|
566
|
-
lastError = error;
|
|
567
|
-
}
|
|
568
|
-
const remainingMs = deadline - Date.now();
|
|
569
|
-
if (remainingMs > 0) {
|
|
570
|
-
await new Promise(
|
|
571
|
-
(resolve) => setTimeout(resolve, Math.min(1e3, remainingMs))
|
|
572
|
-
);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
throw new Error(
|
|
576
|
-
`Mobile lifecycle ${String(command)} did not expose a usable pinned __AGENTIC__ runtime within ${Math.max(0, deadline - startedAt)}ms: ${lastError instanceof Error ? lastError.message : String(lastError)}`
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
async function readMobileLifecycleRuntimeIdentity(node, context) {
|
|
580
|
-
const deadline = Date.now() + 5e3;
|
|
581
|
-
let lastError;
|
|
582
|
-
do {
|
|
583
|
-
try {
|
|
584
|
-
const status = await bridgeCommand(
|
|
585
|
-
{
|
|
586
|
-
action: "app.lifecycle",
|
|
587
|
-
node: {
|
|
588
|
-
...node,
|
|
589
|
-
cdp_timeout_ms: Math.min(1e3, Math.max(1, deadline - Date.now()))
|
|
590
|
-
},
|
|
591
|
-
context
|
|
592
|
-
},
|
|
593
|
-
["target-identity-selected"]
|
|
594
|
-
);
|
|
595
|
-
if (typeof status?.runtimeIdentity === "string") {
|
|
596
|
-
return status.runtimeIdentity;
|
|
597
|
-
}
|
|
598
|
-
lastError = new Error("selected Mobile runtime has no stable identity");
|
|
599
|
-
} catch (error) {
|
|
600
|
-
if (error instanceof Error && "code" in error && error.code === MOBILE_BRIDGE_ERROR_CODES.NO_TARGET) {
|
|
601
|
-
return void 0;
|
|
602
|
-
}
|
|
603
|
-
lastError = error;
|
|
604
|
-
}
|
|
605
|
-
const remainingMs = deadline - Date.now();
|
|
606
|
-
if (remainingMs <= 0) {
|
|
607
|
-
break;
|
|
608
|
-
}
|
|
609
|
-
await new Promise(
|
|
610
|
-
(resolve) => setTimeout(resolve, Math.min(250, remainingMs))
|
|
611
|
-
);
|
|
612
|
-
} while (Date.now() < deadline);
|
|
613
|
-
throw new Error(
|
|
614
|
-
`Mobile lifecycle restart could not identify the retiring runtime: ${lastError instanceof Error ? lastError.message : String(lastError)}`
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
function mobileLifecycleReadinessDeadline(command, node) {
|
|
618
|
-
const timeoutMs = resolveMobileLifecycleReadinessTimeout(
|
|
619
|
-
command,
|
|
620
|
-
node.runtime_ready_timeout_ms
|
|
621
|
-
);
|
|
622
|
-
return Date.now() + timeoutMs;
|
|
623
|
-
}
|
|
624
|
-
function resolveMobileLifecycleReadinessTimeout(command, value) {
|
|
625
|
-
if (value === void 0) {
|
|
626
|
-
return command === "launch" || command === "restart" || command === "foreground" ? 6e4 : 3e4;
|
|
627
|
-
}
|
|
628
|
-
const timeout = Number(value);
|
|
629
|
-
if (!Number.isInteger(timeout) || timeout < 1e3 || timeout > 12e4) {
|
|
630
|
-
throw new Error(
|
|
631
|
-
"app.lifecycle.runtime_ready_timeout_ms must be an integer from 1000 through 120000."
|
|
632
|
-
);
|
|
633
|
-
}
|
|
634
|
-
return timeout;
|
|
635
|
-
}
|
|
636
|
-
function asRecord(value) {
|
|
637
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
638
|
-
}
|
|
639
294
|
function runnerProvenance() {
|
|
640
295
|
return {
|
|
641
296
|
source: runnerDir,
|
|
@@ -659,8 +314,5 @@ export {
|
|
|
659
314
|
createMetaMaskMobileRunner,
|
|
660
315
|
createMetaMaskRunner,
|
|
661
316
|
isAutomaticHudProgress,
|
|
662
|
-
mobileSourceAwareLifecycleAdapters,
|
|
663
|
-
resolveMobileLifecycleReadinessTimeout,
|
|
664
|
-
withMobileNativeRuntimeIdentity,
|
|
665
317
|
withTrustedMutationContext
|
|
666
318
|
};
|
package/docs/CONTRIBUTING.md
CHANGED
|
@@ -61,9 +61,26 @@ exits.
|
|
|
61
61
|
## Adapter surface
|
|
62
62
|
|
|
63
63
|
Commands resolve shared platform behavior through
|
|
64
|
-
`src/adapters/surface.ts`.
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
`src/adapters/surface.ts`. Each platform's surface registers itself in
|
|
65
|
+
`src/adapters/registry.ts` when its module loads. A platform registered the same
|
|
66
|
+
way is reached by `launch`, by the `run`/`call` engine and by the runner's
|
|
67
|
+
action set with no edit to shared code (`tests/fixtures/example-adapter.ts`).
|
|
68
|
+
The CLI front door still validates `--adapter` against the four built-ins
|
|
69
|
+
(`src/command-contract.ts`), and the other commands still branch on the name,
|
|
70
|
+
so a new platform reaches `bin/mm-harness` only when those families move and a
|
|
71
|
+
plugin loader registers it.
|
|
72
|
+
|
|
73
|
+
Extend `AdapterSurface` when a platform owns the behavior; members a platform
|
|
74
|
+
does not need are optional (`actions` is required: every platform has an
|
|
75
|
+
action set), and Core reports headless/N/A explicitly. Put each platform's
|
|
76
|
+
implementation under `src/adapters/<adapter>/` (`launch.ts`, `run.ts`,
|
|
77
|
+
`actions.ts`). Do not add command-local platform ladders for surface-owned
|
|
78
|
+
behavior: `launch` dispatches through `AdapterSurface.launch` (the device
|
|
79
|
+
platforms share `src/commands/launch/device.ts` through a
|
|
80
|
+
`DeviceLaunchProfile`), `run`/`call` read `run`, `recording`, `diagnostics`,
|
|
81
|
+
`observation` and `sourceFingerprint`, and the runner reads `actions`
|
|
82
|
+
(manifest, bundled semantic actions, live adapter scripts, `cdp.target`, the
|
|
83
|
+
`ui.*` transport, adapter wrappers, input checks).
|
|
67
84
|
|
|
68
85
|
Each checkout owns:
|
|
69
86
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deeeed/metamask-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.75.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mm-harness": "bin/mm-harness"
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@vitest/coverage-v8": "^4.1.10",
|
|
46
46
|
"eslint": "^9",
|
|
47
47
|
"globals": "^17.7.0",
|
|
48
|
+
"proper-lockfile": "^4.1.2",
|
|
48
49
|
"tsx": "^4.23.0",
|
|
49
50
|
"typescript": "^5.6.0",
|
|
50
51
|
"typescript-eslint": "^8",
|
package/scripts/completions.sh
CHANGED
|
@@ -29,13 +29,14 @@ _mmh_bin() {
|
|
|
29
29
|
return 1
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
_mmh_commands="launch stop logs debug reload fixtures actions call run doctor check checklist execution-template recipe-quality install verify cleanup completions"
|
|
32
|
+
_mmh_commands="launch stop logs debug reload fixtures actions call run doctor check checklist execution-template recipe-quality install verify cleanup pin completions"
|
|
33
33
|
|
|
34
34
|
# Per-command flags (static, from the mm-harness surface).
|
|
35
35
|
_mmh_flags_for() {
|
|
36
36
|
case "$1" in
|
|
37
37
|
launch) printf '%s' "--build --watch --verify --sidepanel --fullscreen --runway --device --cdp-port --watcher-port --heal --adapter --target --json" ;;
|
|
38
38
|
stop) printf '%s' "--port --target --json" ;;
|
|
39
|
+
pin) printf '%s' "--json" ;;
|
|
39
40
|
logs) printf '%s' "--full --events --source --adapter --target --json" ;;
|
|
40
41
|
debug) printf '%s' "--worker --dev-menu --adapter --target --json" ;;
|
|
41
42
|
reload) printf '%s' "--adapter --platform --target --json" ;;
|