@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
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { colorHumanMessage } from "../../cli-color.js";
|
|
3
|
+
import {
|
|
4
|
+
extensionDepsBlock,
|
|
5
|
+
extensionRuntimeReusable,
|
|
6
|
+
installExtensionDeps,
|
|
7
|
+
launchExtension
|
|
8
|
+
} from "../../commands/launch/extension.js";
|
|
9
|
+
import { shellQuote } from "../../commands/launch/quote.js";
|
|
10
|
+
import { EXIT, spawnScript } from "../../commands/shared.js";
|
|
11
|
+
import {
|
|
12
|
+
fixtureFeatureFlags,
|
|
13
|
+
sameFeatureFlags,
|
|
14
|
+
toRemoteFlagSpec
|
|
15
|
+
} from "../../feature-flags.js";
|
|
16
|
+
import { RECOVERY_CODE } from "../../heal-bounds.js";
|
|
17
|
+
import { runnerDir, walletFixturePath } from "../../paths.js";
|
|
18
|
+
import { ensureExtensionConsoleCapture } from "./console-capture.js";
|
|
19
|
+
import { readExtensionPinnedFlags } from "./feature-flags.js";
|
|
20
|
+
import { extensionProductConfigBlock } from "./product-config.js";
|
|
21
|
+
import { releaseArtifactState, runtimeDistCheck } from "./runtime-decision.js";
|
|
22
|
+
const DEFAULT_EXTENSION_DAPP_URL = "https://metamask.github.io/test-dapp/";
|
|
23
|
+
function verifyExtensionPin(target, requested) {
|
|
24
|
+
const pinned = readExtensionPinnedFlags(target);
|
|
25
|
+
if (pinned.error) {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
flags: {},
|
|
29
|
+
code: "RUNTIME_MANIFEST_UNREADABLE",
|
|
30
|
+
message: `the launched dist snapshot manifest could not be read (${pinned.sourcePath ?? "unknown path"}): ${pinned.error}`
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (pinned.overrides !== null && pinned.pinned === null) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
flags: {},
|
|
37
|
+
code: "REMOTE_FLAG_NOT_APPLIED",
|
|
38
|
+
message: `the launched dist snapshot manifest (${pinned.sourcePath ?? "unknown path"}) carries no harness pin record; it was not written by this launch.`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const actual = pinned.pinned ?? {};
|
|
42
|
+
if (!sameFeatureFlags(actual, requested)) {
|
|
43
|
+
const mismatched = [.../* @__PURE__ */ new Set([...Object.keys(requested), ...Object.keys(actual)])].filter(
|
|
44
|
+
(key) => JSON.stringify(actual[key]) !== JSON.stringify(requested[key])
|
|
45
|
+
);
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
flags: {},
|
|
49
|
+
code: "REMOTE_FLAG_NOT_APPLIED",
|
|
50
|
+
message: `the remote feature-flag pin ${toRemoteFlagSpec(requested) || "(none)"} does not match the launched snapshot manifest: ` + mismatched.map((key) => `${key} expected ${JSON.stringify(requested[key])}, got ${JSON.stringify(actual[key])}`).join("; ")
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, flags: actual, message: "" };
|
|
54
|
+
}
|
|
55
|
+
function extensionQuickReattachFailed(output) {
|
|
56
|
+
return /\[reattach\]|extension quick reattach|mm-harness launch --build/u.test(output);
|
|
57
|
+
}
|
|
58
|
+
function extensionRuntimeBlocked(output) {
|
|
59
|
+
return /ERR_BLOCKED_BY_CLIENT|has been blocked by Chromium/u.test(output);
|
|
60
|
+
}
|
|
61
|
+
function extensionBrowserMissing(output) {
|
|
62
|
+
return /Playwright Chromium is not installed|No compatible Chromium binary selected/u.test(output);
|
|
63
|
+
}
|
|
64
|
+
function extensionProductConfigMissing(output) {
|
|
65
|
+
return /EXTENSION_PRODUCT_CONFIG_REQUIRED:/u.test(output);
|
|
66
|
+
}
|
|
67
|
+
function extensionEvmRpcUnreachable(output) {
|
|
68
|
+
return /EVM_RPC_UNREACHABLE|EVM RPC readiness probe failed|Infura configured ≠ RPC reachable/u.test(output);
|
|
69
|
+
}
|
|
70
|
+
const extensionLaunchProfile = {
|
|
71
|
+
refuseFlags({ target }, { watch, runway, clearMetro, remoteFlagSpec }) {
|
|
72
|
+
if (runway) return { message: "runway is mobile-only.", userAction: "drop --runway for the extension" };
|
|
73
|
+
if (clearMetro) return { message: "--clear-metro is mobile-only.", userAction: "drop --clear-metro for the extension" };
|
|
74
|
+
if (remoteFlagSpec !== void 0 && watch) {
|
|
75
|
+
return {
|
|
76
|
+
message: "--remote-flag cannot be applied with --watch: the watcher never re-creates the dist snapshot that carries the pin.",
|
|
77
|
+
userAction: `mm-harness launch --adapter extension --remote-flag ${remoteFlagSpec} --target ${shellQuote(target)}`
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
},
|
|
82
|
+
// --url: initial main-tab page for extension launches (dapp beside the
|
|
83
|
+
// sidepanel); travels to live.sh/launch-browser via env. Sidepanel mode has a
|
|
84
|
+
// useful default so `mm-harness launch --sidepanel` opens a working dapp, not
|
|
85
|
+
// just a wallet panel with no page to connect from.
|
|
86
|
+
start({ options, displayMode, machine, wantWatch, tier }) {
|
|
87
|
+
const requestedUrl = typeof options["url"] === "string" && options["url"] ? options["url"] : "";
|
|
88
|
+
if (requestedUrl || displayMode === "sidepanel") {
|
|
89
|
+
process.env.EXTENSION_START_URL = requestedUrl || DEFAULT_EXTENSION_DAPP_URL;
|
|
90
|
+
}
|
|
91
|
+
if (machine) return;
|
|
92
|
+
const modeNote = displayMode === "sidepanel" ? `sidepanel \xB7 dapp ${process.env.EXTENSION_START_URL ?? DEFAULT_EXTENSION_DAPP_URL}` : "fullscreen";
|
|
93
|
+
const workNote = wantWatch ? "watch only" : tier === "build" ? "clean build" : "quick reuse probe";
|
|
94
|
+
console.error(colorHumanMessage(
|
|
95
|
+
`\u2192 extension launch \u2014 ${modeNote} \xB7 CDP :${process.env.CDP_PORT ?? "default"} \xB7 ${workNote}`
|
|
96
|
+
));
|
|
97
|
+
},
|
|
98
|
+
nativeInputs: ["package.json", "yarn.lock", "webpack.config.js"],
|
|
99
|
+
rebuildCommand: () => "mm-harness launch --build",
|
|
100
|
+
// Source-development launch paths require checkout tooling. A verified local
|
|
101
|
+
// release artifact can reuse its healthy browser without building or watching.
|
|
102
|
+
async healthcheck(launch, state) {
|
|
103
|
+
const { target, tier, wantWatch, heal, stream } = launch;
|
|
104
|
+
const artifact = releaseArtifactState(target);
|
|
105
|
+
const reusable = !wantWatch && tier !== "build" && await extensionRuntimeReusable(target, artifact);
|
|
106
|
+
const verifiedReleaseReuse = artifact.status === "valid" && reusable;
|
|
107
|
+
const verifiedReleaseLaunch = !wantWatch && tier !== "build" && artifact.status === "valid" && runtimeDistCheck(target, artifact).status === "fresh";
|
|
108
|
+
const willBuild = !reusable;
|
|
109
|
+
if (willBuild) {
|
|
110
|
+
const productConfigBlock = extensionProductConfigBlock(target);
|
|
111
|
+
if (productConfigBlock) {
|
|
112
|
+
return launch.fail(state, {
|
|
113
|
+
code: "EXTENSION_PRODUCT_CONFIG_REQUIRED",
|
|
114
|
+
message: productConfigBlock.message,
|
|
115
|
+
recoverable: false,
|
|
116
|
+
userAction: productConfigBlock.userAction,
|
|
117
|
+
exitCode: EXIT.infra
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const depsBlock = verifiedReleaseReuse || verifiedReleaseLaunch ? null : extensionDepsBlock(target);
|
|
122
|
+
if (depsBlock) {
|
|
123
|
+
if (heal === "off") return launch.usage(depsBlock.message, depsBlock.userAction);
|
|
124
|
+
const recoveryCode = "deps.installed";
|
|
125
|
+
state.attemptedRecoveries.push(recoveryCode);
|
|
126
|
+
stream.phase("recover");
|
|
127
|
+
const repaired = await installExtensionDeps(target);
|
|
128
|
+
if (repaired.status !== 0 || extensionDepsBlock(target)) {
|
|
129
|
+
return launch.fail(state, {
|
|
130
|
+
code: "DEPENDENCY_INSTALL_FAILED",
|
|
131
|
+
message: depsBlock.message,
|
|
132
|
+
recoverable: false,
|
|
133
|
+
userAction: "install the checkout-pinned Node version, then re-run mm-harness launch",
|
|
134
|
+
originalError: repaired.output,
|
|
135
|
+
exitCode: EXIT.infra
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
state.recovered.push(recoveryCode);
|
|
139
|
+
state.mutations.push({ type: "dependencies", action: "installed", path: target });
|
|
140
|
+
}
|
|
141
|
+
return void 0;
|
|
142
|
+
},
|
|
143
|
+
compose: ({ target, wantWatch, displayMode, remoteFlagRequest }, tier) => launchExtension(target, tier, wantWatch, displayMode, remoteFlagRequest),
|
|
144
|
+
classify({ target, remoteFlagRequest }, output) {
|
|
145
|
+
if (output.includes("REMOTE_FLAG_NOT_PINNABLE:")) {
|
|
146
|
+
return {
|
|
147
|
+
code: "REMOTE_FLAG_NOT_PINNABLE",
|
|
148
|
+
message: `a verified release artifact cannot carry a remote feature-flag pin (${remoteFlagRequest?.spec ?? ""}); its manifest is signed evidence and is never rewritten. Validate the artifact as shipped (drop --remote-flag and the fixture's remoteFeatureFlags) or validate the variant on a source build.`,
|
|
149
|
+
recoverable: false,
|
|
150
|
+
// The next step must leave the artifact alone: a --build here would replace
|
|
151
|
+
// the artifact under validation with a source build.
|
|
152
|
+
userAction: Object.keys(fixtureFeatureFlags(walletFixturePath(target))).length > 0 ? `remove remoteFeatureFlags from ${shellQuote(walletFixturePath(target))}, then: mm-harness launch --adapter extension --target ${shellQuote(target)}` : `mm-harness launch --adapter extension --target ${shellQuote(target)}`,
|
|
153
|
+
exitCode: EXIT.infra,
|
|
154
|
+
originalError: output.trim() || void 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (extensionProductConfigMissing(output)) {
|
|
158
|
+
const block = extensionProductConfigBlock(target);
|
|
159
|
+
return {
|
|
160
|
+
code: "EXTENSION_PRODUCT_CONFIG_REQUIRED",
|
|
161
|
+
message: block?.message ?? "Extension product configuration was not ready when the build started.",
|
|
162
|
+
recoverable: false,
|
|
163
|
+
userAction: block?.userAction ?? `mm-harness launch --adapter extension --target ${shellQuote(target)}`,
|
|
164
|
+
exitCode: EXIT.infra
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (extensionBrowserMissing(output)) {
|
|
168
|
+
return {
|
|
169
|
+
code: "EXTENSION_BROWSER_REQUIRED",
|
|
170
|
+
message: "the checkout Playwright browser is not installed; system Chrome is not a compatible unpacked-extension fallback. Installing the browser cache requires user approval.",
|
|
171
|
+
recoverable: false,
|
|
172
|
+
userAction: `ask the user for approval, then run: cd ${shellQuote(target)} && yarn playwright install chromium`,
|
|
173
|
+
exitCode: EXIT.infra
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (output.includes("EXTENSION_BACKGROUND_UNRESPONSIVE:") || output.includes("EXTENSION_STARTUP_UNVERIFIED:")) {
|
|
177
|
+
return {
|
|
178
|
+
code: output.includes("EXTENSION_BACKGROUND_UNRESPONSIVE:") ? "EXTENSION_BACKGROUND_UNRESPONSIVE" : "EXTENSION_STARTUP_UNVERIFIED",
|
|
179
|
+
message: "Extension startup is not healthy; inspect the background error before restarting or resetting wallet state.",
|
|
180
|
+
recoverable: false,
|
|
181
|
+
userAction: `mm-harness logs --target ${shellQuote(target)} --full`,
|
|
182
|
+
exitCode: EXIT.runtime,
|
|
183
|
+
originalError: output.trim() || void 0
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (output.includes("EVM_RPC_EXECUTION_FAILED:")) {
|
|
187
|
+
return {
|
|
188
|
+
code: "EVM_RPC_EXECUTION_FAILED",
|
|
189
|
+
message: "Background RPC fetch failed during JavaScript execution; this does not establish an Infura authentication or connectivity failure.",
|
|
190
|
+
recoverable: false,
|
|
191
|
+
userAction: `mm-harness logs --target ${shellQuote(target)} --full`,
|
|
192
|
+
exitCode: EXIT.runtime,
|
|
193
|
+
originalError: output.trim() || void 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (extensionEvmRpcUnreachable(output)) {
|
|
197
|
+
return {
|
|
198
|
+
code: "EVM_RPC_UNREACHABLE",
|
|
199
|
+
message: "EVM RPC readiness failed; Infura configured does not mean RPC reachable.",
|
|
200
|
+
recoverable: false,
|
|
201
|
+
userAction: `Check the effective INFURA_PROJECT_ID from the environment, .metamaskprodrc, or ${shellQuote(path.join(target, ".metamaskrc"))}, then rerun: mm-harness launch --verify --target ${shellQuote(target)}`,
|
|
202
|
+
exitCode: EXIT.runtime,
|
|
203
|
+
originalError: output.trim() || void 0
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return void 0;
|
|
207
|
+
},
|
|
208
|
+
async beforeHeal(launch, attempt, state) {
|
|
209
|
+
if (launch.tier !== "quick" || !extensionQuickReattachFailed(attempt.output)) return void 0;
|
|
210
|
+
const recoveryCode = "chrome.relaunched";
|
|
211
|
+
state.attemptedRecoveries.push(recoveryCode);
|
|
212
|
+
launch.stream.phase("recover");
|
|
213
|
+
const rebuildAttempt = await launch.compose("build");
|
|
214
|
+
if (rebuildAttempt.status === 0) {
|
|
215
|
+
state.recovered.push(recoveryCode);
|
|
216
|
+
return await launch.settle(state, rebuildAttempt.remoteFeatureFlags);
|
|
217
|
+
}
|
|
218
|
+
return launch.fail(state, {
|
|
219
|
+
code: "EXTENSION_RELAUNCH_FAILED",
|
|
220
|
+
message: "quick reattach failed, and clean relaunch failed too.",
|
|
221
|
+
recoverable: false,
|
|
222
|
+
exitCode: EXIT.infra,
|
|
223
|
+
originalError: rebuildAttempt.output.trim() || void 0
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
recovery: () => ({ code: RECOVERY_CODE.extension, restartApp: false }),
|
|
227
|
+
// --watch only restarts the webpack watcher; the snapshot, and its pin, are
|
|
228
|
+
// untouched, so the live record is reported rather than verified against a
|
|
229
|
+
// request the watcher could never apply (--remote-flag is refused with it;
|
|
230
|
+
// the fixture baseline stays whatever the last launch pinned).
|
|
231
|
+
provenFlags({ target, wantWatch, remoteFlagRequest }, requested) {
|
|
232
|
+
if (wantWatch) return { flags: readExtensionPinnedFlags(target).pinned };
|
|
233
|
+
const pinned = verifyExtensionPin(target, requested);
|
|
234
|
+
if (pinned.ok) return { flags: pinned.flags };
|
|
235
|
+
const spec = remoteFlagRequest?.spec;
|
|
236
|
+
return {
|
|
237
|
+
code: pinned.code ?? "REMOTE_FLAG_NOT_APPLIED",
|
|
238
|
+
message: pinned.message,
|
|
239
|
+
recoverable: false,
|
|
240
|
+
// A rebuild re-creates the snapshot; the flag is repeated only when one was asked for.
|
|
241
|
+
userAction: `mm-harness launch --adapter extension --build${spec ? ` --remote-flag ${spec}` : ""} --target ${shellQuote(target)}`,
|
|
242
|
+
exitCode: EXIT.runtime
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
async finish(launch, state, sidepanelRecoveryAllowed) {
|
|
246
|
+
const { target, machine, displayMode, tier, stream } = launch;
|
|
247
|
+
const sidepanelSh = path.join(runnerDir, "adapters/extension/sidepanel-toggle.sh");
|
|
248
|
+
if (displayMode === "fullscreen") {
|
|
249
|
+
const sidepanelArgs = ["close"];
|
|
250
|
+
if (process.env.CDP_PORT) sidepanelArgs.push("--cdp-port", process.env.CDP_PORT);
|
|
251
|
+
const fullscreen = spawnScript(sidepanelSh, sidepanelArgs, target, machine, { REPO: target });
|
|
252
|
+
if (fullscreen.status !== 0) {
|
|
253
|
+
return launch.fail(state, {
|
|
254
|
+
code: "FULLSCREEN_OPEN_FAILED",
|
|
255
|
+
message: "app launched but restoring the fullscreen Extension surface failed.",
|
|
256
|
+
recoverable: false,
|
|
257
|
+
userAction: `bash adapters/extension/sidepanel-toggle.sh close --cdp-port ${process.env.CDP_PORT ?? "<CDP_PORT>"}`,
|
|
258
|
+
exitCode: EXIT.runtime,
|
|
259
|
+
originalError: fullscreen.output.trim() || void 0
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (displayMode === "sidepanel") {
|
|
264
|
+
const sidepanelArgs = ["open"];
|
|
265
|
+
if (process.env.CDP_PORT) sidepanelArgs.push("--cdp-port", process.env.CDP_PORT);
|
|
266
|
+
if (!machine) {
|
|
267
|
+
console.error(
|
|
268
|
+
`[sidepanel] opening panel beside ${process.env.EXTENSION_START_URL ?? DEFAULT_EXTENSION_DAPP_URL}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const sidepanel = spawnScript(sidepanelSh, sidepanelArgs, target, machine, { REPO: target });
|
|
272
|
+
if (sidepanel.status !== 0) {
|
|
273
|
+
const recoveryCode = "chrome.relaunched";
|
|
274
|
+
if (sidepanelRecoveryAllowed && tier === "quick" && extensionRuntimeBlocked(sidepanel.output) && !state.attemptedRecoveries.includes(recoveryCode)) {
|
|
275
|
+
state.attemptedRecoveries.push(recoveryCode);
|
|
276
|
+
stream.phase("recover");
|
|
277
|
+
const rebuildAttempt = await launch.compose("build");
|
|
278
|
+
if (rebuildAttempt.status === 0) {
|
|
279
|
+
state.recovered.push(recoveryCode);
|
|
280
|
+
return await launch.settle(state, void 0, false);
|
|
281
|
+
}
|
|
282
|
+
return launch.fail(state, {
|
|
283
|
+
code: "EXTENSION_RELAUNCH_FAILED",
|
|
284
|
+
message: "sidepanel open found a blocked extension runtime, and clean relaunch failed too.",
|
|
285
|
+
recoverable: false,
|
|
286
|
+
exitCode: EXIT.infra,
|
|
287
|
+
originalError: rebuildAttempt.output.trim() || void 0
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return launch.fail(state, {
|
|
291
|
+
code: "SIDEPANEL_OPEN_FAILED",
|
|
292
|
+
message: "app launched but opening the side panel failed.",
|
|
293
|
+
recoverable: false,
|
|
294
|
+
userAction: `bash adapters/extension/sidepanel-toggle.sh open --cdp-port ${process.env.CDP_PORT ?? "<CDP_PORT>"}`,
|
|
295
|
+
exitCode: EXIT.runtime,
|
|
296
|
+
originalError: sidepanel.output.trim() || void 0
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
await ensureExtensionConsoleCapture(target);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (!machine) {
|
|
304
|
+
console.error(`WARN: Extension console capture unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return void 0;
|
|
308
|
+
},
|
|
309
|
+
verifyArgs: () => process.env.CDP_PORT ? ["--cdp-port", process.env.CDP_PORT] : [],
|
|
310
|
+
platformLabel: ({ mobileTarget, displayMode }) => mobileTarget ?? displayMode,
|
|
311
|
+
deviceLabel: ({ displayMode }) => displayMode
|
|
312
|
+
};
|
|
313
|
+
export {
|
|
314
|
+
extensionLaunchProfile
|
|
315
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isRecord } from "../../commands/parse-args.js";
|
|
5
|
+
import { recipeRuntimeDir } from "../../paths.js";
|
|
6
|
+
function readRecord(file) {
|
|
7
|
+
try {
|
|
8
|
+
const recorded = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
9
|
+
return isRecord(recorded) ? recorded : null;
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const browserCdp = createRequire(import.meta.url)("../../../adapters/shared/browser-cdp.cjs");
|
|
15
|
+
function verifyLaunch(record, cdpPort) {
|
|
16
|
+
const launch = isRecord(record.launch) ? record.launch : {};
|
|
17
|
+
const pid = Number(launch.pid);
|
|
18
|
+
const port = Number(launch.cdpPort);
|
|
19
|
+
if (!Number.isInteger(pid) || !Number.isInteger(port) || typeof launch.profile !== "string" || typeof launch.processStartedAt !== "string") {
|
|
20
|
+
return "the browser record has no process identity (pid, start time, profile, CDP port)";
|
|
21
|
+
}
|
|
22
|
+
if (cdpPort && port !== Number(cdpPort)) return `the browser record is for CDP port ${port}, not ${cdpPort}`;
|
|
23
|
+
try {
|
|
24
|
+
const owner = browserCdp.cdpOwner(port, launch.profile);
|
|
25
|
+
if (owner.pid !== pid || owner.startedAt !== launch.processStartedAt) {
|
|
26
|
+
return `CDP port ${port} is now held by another browser process than the recorded pid ${pid}`;
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return error instanceof Error ? error.message : String(error);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function launchedBrowser(target, artifactsDir, cdpPort) {
|
|
34
|
+
const runtime = readRecord(path.join(artifactsDir, "extension-runtime", "runtime.json"));
|
|
35
|
+
const autolaunched = runtime && isRecord(runtime.browser) ? runtime.browser : null;
|
|
36
|
+
const candidates = [];
|
|
37
|
+
if (autolaunched) candidates.push([autolaunched, "run-autolaunch"]);
|
|
38
|
+
const slot = readRecord(path.join(path.resolve(target), recipeRuntimeDir(), "browser-resolution.json"));
|
|
39
|
+
if (slot) candidates.push([slot, "slot-runtime"]);
|
|
40
|
+
if (candidates.length === 0) return null;
|
|
41
|
+
const reasons = [];
|
|
42
|
+
for (const [record, boundTo] of candidates) {
|
|
43
|
+
const problem = verifyLaunch(record, cdpPort);
|
|
44
|
+
if (problem === null) return { ...record, boundTo };
|
|
45
|
+
reasons.push(`${boundTo}: ${problem}`);
|
|
46
|
+
}
|
|
47
|
+
return { boundTo: "none", reason: reasons.join("; ") };
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
launchedBrowser
|
|
51
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { optionString } from "../../commands/parse-args.js";
|
|
2
|
+
import { resolveExtensionBrowserPid } from "../../recording-target.js";
|
|
3
|
+
import {
|
|
4
|
+
ensureExtensionConsoleCapture,
|
|
5
|
+
extensionCaptureFiles,
|
|
6
|
+
extensionCdpPort,
|
|
7
|
+
verifyExtensionConsoleControl
|
|
8
|
+
} from "./console-capture.js";
|
|
9
|
+
import { launchedBrowser } from "./launched-browser.js";
|
|
10
|
+
const extensionRun = {
|
|
11
|
+
async prepareRuntime(projectRoot, runtimeOptions) {
|
|
12
|
+
if (runtimeOptions.skipExtensionRuntimePrepare === true) return;
|
|
13
|
+
const { releaseArtifactState, runtimeDistCheck } = await import("./runtime-decision.js");
|
|
14
|
+
const artifact = releaseArtifactState(projectRoot);
|
|
15
|
+
const runtimeSnapshot = runtimeDistCheck(projectRoot, artifact);
|
|
16
|
+
if (artifact.status !== "none") {
|
|
17
|
+
if (artifact.status === "valid" && runtimeSnapshot.status === "fresh") return;
|
|
18
|
+
throw new Error(
|
|
19
|
+
"The loaded release artifact identity is invalid or stale. Next: rerun runtime-launch with the same artifact source."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const { prepareExtensionRuntime } = await import("./runtime.js");
|
|
23
|
+
await prepareExtensionRuntime({
|
|
24
|
+
projectRoot,
|
|
25
|
+
cdpPort: runtimeOptions.cdpPort,
|
|
26
|
+
slot: runtimeOptions.slot,
|
|
27
|
+
launchExistingDist: runtimeOptions.launchExistingDist === true,
|
|
28
|
+
validationRuntimeDir: runtimeOptions.validationRuntimeDir,
|
|
29
|
+
pageMode: "home-or-sidepanel"
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
// The proof runtime is checked on the run's own ports: explicit flags win over
|
|
33
|
+
// the slot's for the check, and the slot's come back afterwards.
|
|
34
|
+
runtimeCheck({ target, options, heal, state, json, onRecovery }) {
|
|
35
|
+
return async () => {
|
|
36
|
+
const cliOptions = options;
|
|
37
|
+
const previousCdpPort = process.env.CDP_PORT;
|
|
38
|
+
const previousRecipeCdpPort = process.env.RECIPE_CDP_PORT;
|
|
39
|
+
const previousWatcherPort = process.env.WATCHER_PORT;
|
|
40
|
+
const explicitCdpPort = optionString(cliOptions, "cdpPort");
|
|
41
|
+
const explicitWatcherPort = optionString(cliOptions, "watcherPort") ?? optionString(cliOptions, "metroPort");
|
|
42
|
+
if (explicitCdpPort) {
|
|
43
|
+
process.env.CDP_PORT = explicitCdpPort;
|
|
44
|
+
process.env.RECIPE_CDP_PORT = explicitCdpPort;
|
|
45
|
+
}
|
|
46
|
+
if (explicitWatcherPort) process.env.WATCHER_PORT = explicitWatcherPort;
|
|
47
|
+
try {
|
|
48
|
+
const { ensureExtensionProofRuntime } = await import("../../commands/run-engine.js");
|
|
49
|
+
return await ensureExtensionProofRuntime(target, heal, state, json, { onRecovery });
|
|
50
|
+
} finally {
|
|
51
|
+
restoreEnv("CDP_PORT", previousCdpPort);
|
|
52
|
+
restoreEnv("RECIPE_CDP_PORT", previousRecipeCdpPort);
|
|
53
|
+
restoreEnv("WATCHER_PORT", previousWatcherPort);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
launchedBrowser: (target, artifactsDir, cdpPort) => launchedBrowser(target, artifactsDir, cdpPort)
|
|
58
|
+
};
|
|
59
|
+
const extensionRecording = {
|
|
60
|
+
target: (context) => resolveExtensionRecordingTarget(context),
|
|
61
|
+
framed: {
|
|
62
|
+
browserPid: (projectRoot, artifactsDir, cdpPort) => resolveExtensionBrowserPid(projectRoot, artifactsDir, cdpPort)
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
async function resolveExtensionRecordingTarget(context) {
|
|
66
|
+
const pid = resolveExtensionBrowserPid(
|
|
67
|
+
context.projectRoot,
|
|
68
|
+
context.artifactsDir,
|
|
69
|
+
context.env.CDP_PORT ?? context.env.RECIPE_CDP_PORT ?? process.env.CDP_PORT ?? process.env.RECIPE_CDP_PORT
|
|
70
|
+
);
|
|
71
|
+
if (!pid) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Could not resolve the extension browser PID for --record-video. Ensure the slot browser is running and CDP_PORT is set."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return { kind: "pid", pid };
|
|
77
|
+
}
|
|
78
|
+
const extensionDiagnostics = {
|
|
79
|
+
console: {
|
|
80
|
+
start: (projectRoot) => ensureExtensionConsoleCapture(projectRoot),
|
|
81
|
+
files: (projectRoot) => extensionCaptureFiles(projectRoot),
|
|
82
|
+
cdpPort: () => extensionCdpPort(),
|
|
83
|
+
verifyControl: (capture) => verifyExtensionConsoleControl(capture)
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const extensionObservation = {
|
|
87
|
+
network: {
|
|
88
|
+
backend: async (_target, env, artifactsDir) => (await import("../../network-observation.js")).createExtensionNetworkBackend(env, artifactsDir),
|
|
89
|
+
actions: true
|
|
90
|
+
},
|
|
91
|
+
performance: {
|
|
92
|
+
backend: async (target, env, ports) => (await import("../../performance-observation.js")).createExtensionPerformanceObserver(target, env, ports),
|
|
93
|
+
platform: () => "extension"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function restoreEnv(key, value) {
|
|
97
|
+
if (value === void 0) delete process.env[key];
|
|
98
|
+
else process.env[key] = value;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
extensionDiagnostics,
|
|
102
|
+
extensionObservation,
|
|
103
|
+
extensionRecording,
|
|
104
|
+
extensionRun
|
|
105
|
+
};
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
} from "../slot-ports.js";
|
|
10
10
|
import { decideExtensionReadiness } from "./runtime-decision.js";
|
|
11
11
|
import { extensionProductConfigBlock } from "./product-config.js";
|
|
12
|
+
import { adapterRegistry } from "../registry.js";
|
|
13
|
+
import { extensionActions } from "./actions.js";
|
|
14
|
+
import { extensionDiagnostics, extensionObservation, extensionRecording, extensionRun } from "./run.js";
|
|
12
15
|
function watcherStatus(buildLog) {
|
|
13
16
|
if (buildLog === "ok") return "up";
|
|
14
17
|
if (buildLog === "no-watch") return "down";
|
|
@@ -98,8 +101,21 @@ const extensionSurface = {
|
|
|
98
101
|
launch: "mm-harness launch",
|
|
99
102
|
relaunch: "mm-harness launch --build",
|
|
100
103
|
runtimeProbeRecovery: (target) => `mm-harness launch --adapter extension --target ${shellQuote(path.resolve(target))}`
|
|
101
|
-
}
|
|
104
|
+
},
|
|
105
|
+
launch: async (context) => {
|
|
106
|
+
const [{ runDeviceLaunch }, { extensionLaunchProfile }] = await Promise.all([
|
|
107
|
+
import("../../commands/launch/device.js"),
|
|
108
|
+
import("./launch.js")
|
|
109
|
+
]);
|
|
110
|
+
return runDeviceLaunch(context, extensionLaunchProfile);
|
|
111
|
+
},
|
|
112
|
+
actions: extensionActions,
|
|
113
|
+
run: extensionRun,
|
|
114
|
+
recording: extensionRecording,
|
|
115
|
+
diagnostics: extensionDiagnostics,
|
|
116
|
+
observation: extensionObservation
|
|
102
117
|
};
|
|
118
|
+
adapterRegistry.register(extensionSurface);
|
|
103
119
|
export {
|
|
104
120
|
extensionRuntimeNextAction,
|
|
105
121
|
extensionSurface
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { manifestPath } from "../../paths.js";
|
|
2
|
+
const NATIVE_PROVIDER_UI_ACTIONS = /* @__PURE__ */ new Set([
|
|
3
|
+
"ui.press",
|
|
4
|
+
"ui.key_press",
|
|
5
|
+
"ui.set_input",
|
|
6
|
+
"ui.scroll",
|
|
7
|
+
"ui.swipe",
|
|
8
|
+
"ui.pan",
|
|
9
|
+
"ui.drag",
|
|
10
|
+
"ui.long_press",
|
|
11
|
+
"ui.wait_for",
|
|
12
|
+
"ui.screenshot",
|
|
13
|
+
"ui.capture_surface"
|
|
14
|
+
]);
|
|
15
|
+
const mobileActions = {
|
|
16
|
+
manifestPath: () => manifestPath("mobile"),
|
|
17
|
+
semantic: [
|
|
18
|
+
"app.network_capture",
|
|
19
|
+
"app.network_assert",
|
|
20
|
+
"app.performance_capture",
|
|
21
|
+
"app.performance_assert",
|
|
22
|
+
"metamask.swap_bridge.submit_transaction",
|
|
23
|
+
"metamask.perps.close_positions",
|
|
24
|
+
"metamask.perps.start_state",
|
|
25
|
+
"metamask.perps.clear_performance_caches",
|
|
26
|
+
"metamask.perps.measure_homepage_visible",
|
|
27
|
+
"metamask.perps.prepare_local_snapshot_endpoint"
|
|
28
|
+
],
|
|
29
|
+
cdpTarget: {
|
|
30
|
+
transport: "react-native-debug-bridge",
|
|
31
|
+
probePath: "json/list",
|
|
32
|
+
watcherPortFirst: true,
|
|
33
|
+
requiredProbe: async (node, context) => (await import("./ui.js")).probeMobileBridgeTarget(node, context)
|
|
34
|
+
},
|
|
35
|
+
ui: (harness) => ({
|
|
36
|
+
base: harness.createReactNativeBridgeUiTransport({
|
|
37
|
+
bridge: {
|
|
38
|
+
send: async (command, context) => (await import("./ui.js")).sendMobileBridgeCommand(command, context)
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
async execute(action, node, context, standard) {
|
|
42
|
+
if (NATIVE_PROVIDER_UI_ACTIONS.has(action) && (context.env?.METAMASK_RECIPE_MOBILE_OPAQUE_RUNTIME === "1" || process.env.METAMASK_RECIPE_MOBILE_OPAQUE_RUNTIME === "1" || ["ui.swipe", "ui.pan", "ui.drag", "ui.long_press", "ui.capture_surface"].includes(action))) {
|
|
43
|
+
const { executeNativeProviderAction } = await import("./ui.js");
|
|
44
|
+
return executeNativeProviderAction(action, node, context, harness.createNativeUiTransport);
|
|
45
|
+
}
|
|
46
|
+
return standard();
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
wrap: async (adapters) => (await import("./runtime-identity.js")).withMobileNativeRuntimeIdentity(adapters),
|
|
50
|
+
lifecycle: async (adapters) => (await import("./lifecycle.js")).mobileSourceAwareLifecycleAdapters(adapters)
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
mobileActions
|
|
54
|
+
};
|