@deeeed/metamask-harness 0.5.1 → 0.6.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 +37 -20
- package/adapters/core/inject.sh +1 -0
- package/adapters/extension/cleanup.mjs +1 -1
- package/adapters/extension/inject.mjs +2 -1
- package/adapters/extension/launch-browser.cjs +18 -4
- package/adapters/extension/live.sh +14 -2
- package/adapters/extension/sidepanel-toggle.sh +33 -12
- package/adapters/extension/wallet-fixture-state.cjs +38 -24
- package/adapters/manifest.json +13 -0
- package/adapters/mobile/inject.sh +1 -0
- package/adapters/mobile/stop-metro.sh +20 -0
- package/adapters/shared/cli-ux.sh +20 -2
- package/adapters/shared/ensure-runner-deps.sh +30 -0
- package/adapters/shared/reap-checkout-metros.sh +53 -0
- package/adapters/shared/recipe-harness-root.mjs +23 -0
- package/adapters/shared/resolve-farmslot-ports-core.mjs +15 -6
- package/bin/mm-harness +45 -4
- package/dist/adapters/extension/runtime.js +3 -1
- package/dist/adapters/mobile/provision.js +34 -1
- package/dist/adapters/slot-ports.js +3 -8
- package/dist/cli.js +32 -1463
- package/dist/commands/call.js +183 -0
- package/dist/commands/completion-candidates.js +58 -0
- package/dist/commands/doctor.js +101 -0
- package/dist/commands/ensure-ready.js +24 -0
- package/dist/commands/flows.js +62 -0
- package/dist/commands/launch/extension.js +40 -0
- package/dist/commands/{launch.js → launch/index.js} +15 -47
- package/dist/commands/launch/mobile.js +10 -0
- package/dist/commands/manifest.js +72 -0
- package/dist/commands/parse-args.js +189 -0
- package/dist/commands/provision.js +136 -0
- package/dist/commands/resolve-extension.js +23 -0
- package/dist/commands/run-engine.js +341 -0
- package/dist/commands/run.js +217 -0
- package/dist/commands/runtime-decision.js +58 -0
- package/dist/commands/runtime-health.js +25 -0
- package/dist/commands/runtime-launch.js +139 -0
- package/dist/commands/self-test.js +52 -0
- package/dist/commands/stop.js +52 -0
- package/dist/harness.js +8 -48
- package/dist/mm-harness-cli.js +13 -8
- package/docs/CLI-SPEC.md +1 -1
- package/docs/CODE-MAP.md +62 -0
- package/library/README.md +14 -0
- package/library/actions/extension/platform/cdp.mjs +1 -1
- package/library/actions/extension/wallet/ensure_unlocked.mjs +6 -0
- package/library/actions/mobile/wallet/ensure_unlocked.mjs +13 -1
- package/package.json +6 -7
- package/src/adapters/core/surface.ts +0 -71
- package/src/adapters/extension/ensure-ready.ts +0 -185
- package/src/adapters/extension/extension-id.ts +0 -107
- package/src/adapters/extension/runtime-decision.ts +0 -445
- package/src/adapters/extension/runtime.ts +0 -407
- package/src/adapters/extension/surface.ts +0 -88
- package/src/adapters/mobile/deps-markers.ts +0 -21
- package/src/adapters/mobile/prepare.ts +0 -246
- package/src/adapters/mobile/provision.ts +0 -594
- package/src/adapters/mobile/runtime-decision.ts +0 -466
- package/src/adapters/mobile/surface.ts +0 -71
- package/src/adapters/resolve-farmslot-ports.ts +0 -13
- package/src/adapters/slot-ports.ts +0 -158
- package/src/adapters/surface.ts +0 -117
- package/src/adapters.ts +0 -601
- package/src/cli-color.ts +0 -92
- package/src/cli-commands.ts +0 -250
- package/src/cli-version.ts +0 -141
- package/src/cli.ts +0 -2091
- package/src/commands/debug.ts +0 -65
- package/src/commands/fixtures.ts +0 -198
- package/src/commands/launch.ts +0 -470
- package/src/commands/logs.ts +0 -99
- package/src/commands/shared.ts +0 -235
- package/src/commands/update.ts +0 -316
- package/src/completions-cache.ts +0 -86
- package/src/doctor.ts +0 -215
- package/src/harness.ts +0 -797
- package/src/heal-bounds.ts +0 -198
- package/src/index.ts +0 -15
- package/src/leaf-invoke.ts +0 -28
- package/src/live-adapter-contract.ts +0 -274
- package/src/manifest.ts +0 -47
- package/src/mm-harness-cli.ts +0 -655
- package/src/paths.ts +0 -198
- package/src/progress.ts +0 -117
- package/src/recording-target.ts +0 -147
- package/src/run-recording.ts +0 -329
- package/src/runner.ts +0 -108
- package/src/types.ts +0 -57
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
clearDecisionState,
|
|
7
|
-
depsCheck,
|
|
8
|
-
recordDepsBaseline,
|
|
9
|
-
type DepsCheck,
|
|
10
|
-
} from '@farmslot/recipe-harness/runtime/deps-readiness';
|
|
11
|
-
import {
|
|
12
|
-
analyzeBundleLog,
|
|
13
|
-
evaluatePersistentBundleError,
|
|
14
|
-
supersededErrorCapture,
|
|
15
|
-
type BundleLogAnalysis,
|
|
16
|
-
} from '@farmslot/recipe-harness/runtime/log-analysis';
|
|
17
|
-
import { probeMetroPackager, type MetroReachabilityCheck } from '@farmslot/recipe-harness/runtime/metro-probe';
|
|
18
|
-
|
|
19
|
-
import { recipeRuntimePath } from '../../paths.ts';
|
|
20
|
-
import { mobileProductMarkers } from './deps-markers.ts';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* MetaMask Mobile runtime-readiness adapter.
|
|
24
|
-
*
|
|
25
|
-
* Generic deps/log/metro primitives live in `@farmslot/recipe-harness/runtime/*`.
|
|
26
|
-
* This file owns MetaMask-specific markers, Nitro staleness regex, and action ids.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
export type MobileReadinessDecision = 'install' | 'launch' | 'ready' | 'blocked' | 'unknown';
|
|
30
|
-
|
|
31
|
-
export interface MobileRuntimeDecisionAction {
|
|
32
|
-
id: string;
|
|
33
|
-
argv?: string[];
|
|
34
|
-
cwd?: string;
|
|
35
|
-
paths?: string[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type MetroLogCheck = BundleLogAnalysis;
|
|
39
|
-
|
|
40
|
-
export interface MobileRuntimeDecisionReport {
|
|
41
|
-
schemaVersion: 1;
|
|
42
|
-
adapter: 'mobile';
|
|
43
|
-
target: string;
|
|
44
|
-
decision: MobileReadinessDecision;
|
|
45
|
-
reasonCode: string;
|
|
46
|
-
reasons: string[];
|
|
47
|
-
// A single teaching escape for the caller's actual situation, set on decisions
|
|
48
|
-
// the runner deliberately refuses to auto-resolve (e.g. fast-mode deps gaps).
|
|
49
|
-
userAction?: string;
|
|
50
|
-
checks: {
|
|
51
|
-
deps: DepsCheck;
|
|
52
|
-
metroLog: MetroLogCheck;
|
|
53
|
-
metro: MetroReachabilityCheck;
|
|
54
|
-
};
|
|
55
|
-
actions: MobileRuntimeDecisionAction[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface MobileRuntimeDecisionOptions {
|
|
59
|
-
watcherPort?: number;
|
|
60
|
-
metroLog?: string;
|
|
61
|
-
platform?: string;
|
|
62
|
-
record?: boolean;
|
|
63
|
-
// 'fast' (quick launch / no --build) makes deps readiness a presence check only:
|
|
64
|
-
// freshness is the orchestrator's deps-phase contract, never re-decided here.
|
|
65
|
-
preflightMode?: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const BUNDLE_ERR = /Bundling failed|Unable to resolve /u;
|
|
69
|
-
const BUNDLE_OK = /Bundled \d+ms|iOS Bundled|Android Bundled|Finished bundling/u;
|
|
70
|
-
const NATIVE_MODULE_STALE =
|
|
71
|
-
/\[runtime not ready\].*HybridObject "([^"]+)" - It has not yet been registered in the Nitro Modules HybridObjectRegistry/u;
|
|
72
|
-
|
|
73
|
-
// The metro.log location honors RECIPE_RUNTIME_DIR via the shared recipeRuntimePath
|
|
74
|
-
// resolver (relative, validated), so the decision engine reads metro.log from the
|
|
75
|
-
// same per-run dir the mobile leaf scripts write — two jobs sharing one checkout
|
|
76
|
-
// stay isolated. An explicit metroLog override (a --metro-log flag) still wins.
|
|
77
|
-
function resolveMetroLog(target: string, metroLog?: string): string | null {
|
|
78
|
-
const abs = metroLog
|
|
79
|
-
? (path.isAbsolute(metroLog) ? metroLog : path.join(target, metroLog))
|
|
80
|
-
: recipeRuntimePath(target, 'metro.log');
|
|
81
|
-
return fs.existsSync(abs) ? abs : null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// A metro.log is stale when the yarn install markers are newer — a yarn install
|
|
85
|
-
// happened after the last bundle run, so the log describes a now-superseded module
|
|
86
|
-
// tree. Ignoring it lets launch start fresh instead of deciding off stale content.
|
|
87
|
-
function isMetroLogStale(target: string, logAbs: string): boolean {
|
|
88
|
-
try {
|
|
89
|
-
const logMtime = fs.statSync(logAbs).mtimeMs;
|
|
90
|
-
// Check against the same install markers as depsCheck; they are updated by
|
|
91
|
-
// yarn on every successful install, making them a reliable freshness signal.
|
|
92
|
-
const INSTALL_MARKERS = ['node_modules/.yarn-state.yml', '.yarn/install-state.gz'];
|
|
93
|
-
return INSTALL_MARKERS.some((rel) => {
|
|
94
|
-
try {
|
|
95
|
-
return logMtime < fs.statSync(path.join(target, rel)).mtimeMs;
|
|
96
|
-
} catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
} catch {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function metroLogCheck(target: string, metroLog?: string): MetroLogCheck {
|
|
106
|
-
const abs = resolveMetroLog(target, metroLog);
|
|
107
|
-
if (!abs) return { status: 'no-log' };
|
|
108
|
-
if (isMetroLogStale(target, abs)) return { status: 'no-log' };
|
|
109
|
-
const logText = fs.readFileSync(abs, 'utf8');
|
|
110
|
-
return analyzeBundleLog({
|
|
111
|
-
target,
|
|
112
|
-
logText,
|
|
113
|
-
errorPattern: BUNDLE_ERR,
|
|
114
|
-
okPattern: BUNDLE_OK,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Returns names of top-level package.json dependencies absent from node_modules.
|
|
119
|
-
// Catches the case where a dep was added in a branch merge but yarn install was not
|
|
120
|
-
// re-run — install markers and fingerprint may both be satisfied while a required
|
|
121
|
-
// package directory is simply missing (real case: 249s Metro bundle discovers it
|
|
122
|
-
// too late).
|
|
123
|
-
function missingRequiredDeps(target: string): string[] {
|
|
124
|
-
try {
|
|
125
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(target, 'package.json'), 'utf8')) as {
|
|
126
|
-
dependencies?: Record<string, unknown>;
|
|
127
|
-
devDependencies?: Record<string, unknown>;
|
|
128
|
-
};
|
|
129
|
-
const all = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
|
|
130
|
-
return Object.keys(all).filter(
|
|
131
|
-
(name) => !fs.existsSync(path.join(target, 'node_modules', name)),
|
|
132
|
-
);
|
|
133
|
-
} catch {
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const installActions = (target: string): MobileRuntimeDecisionAction[] => [
|
|
139
|
-
{ id: 'yarn-setup', argv: ['yarn', 'setup'], cwd: target },
|
|
140
|
-
];
|
|
141
|
-
|
|
142
|
-
// True when a MetaMask dev client process is alive on the target device
|
|
143
|
-
// (IOS_SIMULATOR / ADB_SERIAL, falling back to the booted simulator). Probe
|
|
144
|
-
// failures count as not-running: the worst case is an idempotent relaunch,
|
|
145
|
-
// while failing open would declare a dead app "ready".
|
|
146
|
-
function appRunningOnDevice(platform?: string): boolean {
|
|
147
|
-
try {
|
|
148
|
-
if (platform === 'android') {
|
|
149
|
-
const serial = process.env.ADB_SERIAL || process.env.ANDROID_SERIAL;
|
|
150
|
-
const args = serial ? ['-s', serial] : [];
|
|
151
|
-
const out = execFileSync('adb', [...args, 'shell', 'ps', '-A'], {
|
|
152
|
-
encoding: 'utf8',
|
|
153
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
154
|
-
timeout: 5_000,
|
|
155
|
-
});
|
|
156
|
-
return out.includes('io.metamask');
|
|
157
|
-
}
|
|
158
|
-
const device = process.env.IOS_SIMULATOR || 'booted';
|
|
159
|
-
const out = execFileSync('xcrun', ['simctl', 'spawn', device, 'launchctl', 'list'], {
|
|
160
|
-
encoding: 'utf8',
|
|
161
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
162
|
-
timeout: 5_000,
|
|
163
|
-
});
|
|
164
|
-
return out.toLowerCase().includes('io.metamask');
|
|
165
|
-
} catch {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const launchActions = (target: string, clearMetro = false): MobileRuntimeDecisionAction[] => {
|
|
171
|
-
const actions: MobileRuntimeDecisionAction[] = [];
|
|
172
|
-
// start-metro ensures Metro is running; --clear resets the bundle cache.
|
|
173
|
-
actions.push({
|
|
174
|
-
id: 'start-metro',
|
|
175
|
-
argv: clearMetro ? ['--clear'] : [],
|
|
176
|
-
cwd: target,
|
|
177
|
-
});
|
|
178
|
-
// Prewarm the bundle before opening the dev client so the app connects instantly.
|
|
179
|
-
actions.push({ id: 'prewarm-bundle', cwd: target });
|
|
180
|
-
// Open the dev client via the expo-development-client deep link.
|
|
181
|
-
actions.push({ id: 'launch-mobile-runtime' });
|
|
182
|
-
// Poll the CDP bridge until a route target registers (confirms app is bridged).
|
|
183
|
-
actions.push({ id: 'wait-for-bridge', cwd: target });
|
|
184
|
-
return actions;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export async function decideMobileReadiness(
|
|
188
|
-
target: string,
|
|
189
|
-
options: MobileRuntimeDecisionOptions = {},
|
|
190
|
-
): Promise<MobileRuntimeDecisionReport> {
|
|
191
|
-
const resolved = path.resolve(target);
|
|
192
|
-
if (options.record) recordDepsBaseline(resolved);
|
|
193
|
-
|
|
194
|
-
const fast = options.preflightMode === 'fast';
|
|
195
|
-
const report = await computeMobileReadiness(resolved, options, fast);
|
|
196
|
-
|
|
197
|
-
// mtime churn is already neutralized above, so a fast-mode 'install' verdict
|
|
198
|
-
// means deps genuinely need work (absent markers, an absent required package, a
|
|
199
|
-
// fingerprint-baseline drift, or Metro unable to resolve a module). In an
|
|
200
|
-
// orchestrated run the deps phase owns installation; having the runner install
|
|
201
|
-
// mid-launch is inverted authority. Surface a teaching block, not an implicit
|
|
202
|
-
// setup, so a runway preflight never re-does the orchestrator's deps work.
|
|
203
|
-
if (fast && report.decision === 'install') {
|
|
204
|
-
// A checkout without node_modules cannot even run yarn scripts (yarn exits
|
|
205
|
-
// with "Couldn't find the node_modules state file"), so the taught command
|
|
206
|
-
// must lead with the install when that is the caller's actual state.
|
|
207
|
-
const hasNodeModules = fs.existsSync(path.join(resolved, 'node_modules'));
|
|
208
|
-
const standalone = hasNodeModules
|
|
209
|
-
? '`yarn setup:expo --no-build-ios --no-build-android`'
|
|
210
|
-
: '`yarn install --immutable && yarn setup:expo --no-build-ios --no-build-android`';
|
|
211
|
-
return {
|
|
212
|
-
...report,
|
|
213
|
-
decision: 'blocked',
|
|
214
|
-
reasonCode: 'deps-not-ready',
|
|
215
|
-
reasons: [
|
|
216
|
-
'Fast preflight found dependencies not ready and does not install them (the orchestrator deps phase owns installation).',
|
|
217
|
-
...report.reasons,
|
|
218
|
-
],
|
|
219
|
-
userAction:
|
|
220
|
-
`run the slot deps/prepare phase; standalone: ${standalone} in the checkout, then re-run \`mm-harness launch <platform>\``,
|
|
221
|
-
actions: [],
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
return report;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async function computeMobileReadiness(
|
|
228
|
-
resolved: string,
|
|
229
|
-
options: MobileRuntimeDecisionOptions,
|
|
230
|
-
fast: boolean,
|
|
231
|
-
): Promise<MobileRuntimeDecisionReport> {
|
|
232
|
-
const rawDeps = depsCheck(resolved, {
|
|
233
|
-
productMarkers: mobileProductMarkers(options.platform),
|
|
234
|
-
});
|
|
235
|
-
// Presence is authoritative; mtime is only a hint. Without a recorded baseline
|
|
236
|
-
// the only way depsCheck reports 'stale' is mtime drift (a manifest newer than
|
|
237
|
-
// the install markers). In a managed checkout the orchestrator's git phase
|
|
238
|
-
// refreshes tracked-file mtimes on every sync while its deps phase leaves
|
|
239
|
-
// node_modules untouched, so "manifest newer than markers" is normal and NOT
|
|
240
|
-
// proof of drift — treating it as stale re-ran the full yarn setup inside every
|
|
241
|
-
// launch. Trust the installed node_modules and warn; genuine drift is caught by
|
|
242
|
-
// the recorded-baseline fingerprint when one exists (hasBaseline=true stays 'stale').
|
|
243
|
-
let deps: DepsCheck = rawDeps;
|
|
244
|
-
if (rawDeps.status === 'stale' && !rawDeps.hasBaseline) {
|
|
245
|
-
deps = { installed: rawDeps.installed, status: 'current', hasBaseline: false };
|
|
246
|
-
process.stderr.write(
|
|
247
|
-
'[runtime-decision] manifest is newer than install markers (no recorded baseline); ' +
|
|
248
|
-
'trusting installed node_modules — run yarn setup manually if deps truly changed.\n',
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
// Required-dep absence is a presence check (both modes): a top-level dependency
|
|
252
|
-
// can be absent from node_modules even when markers + fingerprint report
|
|
253
|
-
// 'current' (e.g. added in a branch merge but install not re-run). Catch at
|
|
254
|
-
// pre-flight before Metro discovers it during a long bundle run.
|
|
255
|
-
if (deps.status === 'current') {
|
|
256
|
-
const absent = missingRequiredDeps(resolved);
|
|
257
|
-
if (absent.length > 0) {
|
|
258
|
-
deps = { installed: deps.installed, status: 'partial', hasBaseline: deps.hasBaseline, missingProducts: absent };
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const metroLog = metroLogCheck(resolved, options.metroLog);
|
|
262
|
-
const metro = options.watcherPort
|
|
263
|
-
? await probeMetroPackager(options.watcherPort)
|
|
264
|
-
: { status: 'skipped' as const };
|
|
265
|
-
|
|
266
|
-
if (metroLog.status === 'ok') {
|
|
267
|
-
clearDecisionState(resolved, 'bundle-error-state.json');
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const checks = { deps, metroLog, metro };
|
|
271
|
-
|
|
272
|
-
if (deps.status === 'missing') {
|
|
273
|
-
return {
|
|
274
|
-
schemaVersion: 1,
|
|
275
|
-
adapter: 'mobile',
|
|
276
|
-
target: resolved,
|
|
277
|
-
decision: 'install',
|
|
278
|
-
reasonCode: 'deps-missing',
|
|
279
|
-
reasons: ['Dependencies are not installed (no yarn install-state markers).'],
|
|
280
|
-
checks,
|
|
281
|
-
actions: installActions(resolved),
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (deps.status === 'partial') {
|
|
286
|
-
const missing = deps.missingProducts?.join(', ') ?? 'product markers';
|
|
287
|
-
return {
|
|
288
|
-
schemaVersion: 1,
|
|
289
|
-
adapter: 'mobile',
|
|
290
|
-
target: resolved,
|
|
291
|
-
decision: 'install',
|
|
292
|
-
reasonCode: 'deps-partial',
|
|
293
|
-
reasons: [`node_modules tree is incomplete (missing: ${missing}).`],
|
|
294
|
-
checks,
|
|
295
|
-
actions: installActions(resolved),
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (deps.status === 'stale') {
|
|
300
|
-
return {
|
|
301
|
-
schemaVersion: 1,
|
|
302
|
-
adapter: 'mobile',
|
|
303
|
-
target: resolved,
|
|
304
|
-
decision: 'install',
|
|
305
|
-
reasonCode: 'deps-stale',
|
|
306
|
-
reasons: ['package.json/yarn.lock changed since the recorded install baseline.'],
|
|
307
|
-
checks,
|
|
308
|
-
actions: installActions(resolved),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const metroLogAbs = resolveMetroLog(resolved, options.metroLog);
|
|
313
|
-
const metroLogText =
|
|
314
|
-
metroLogAbs && !isMetroLogStale(resolved, metroLogAbs)
|
|
315
|
-
? fs.readFileSync(metroLogAbs, 'utf8')
|
|
316
|
-
: '';
|
|
317
|
-
const staleNativeModule = supersededErrorCapture(metroLogText, {
|
|
318
|
-
errorPattern: NATIVE_MODULE_STALE,
|
|
319
|
-
okPattern: BUNDLE_OK,
|
|
320
|
-
});
|
|
321
|
-
if (staleNativeModule) {
|
|
322
|
-
return {
|
|
323
|
-
schemaVersion: 1,
|
|
324
|
-
adapter: 'mobile',
|
|
325
|
-
target: resolved,
|
|
326
|
-
decision: 'launch',
|
|
327
|
-
reasonCode: 'native-module-stale',
|
|
328
|
-
reasons: [
|
|
329
|
-
`Installed dev client is missing native module "${staleNativeModule}" (JS deps are current). Rebuild the native app (yarn start:ios / yarn start:android or --preflight-mode rebuild-native).`,
|
|
330
|
-
'Metro may report a successful bundle while the installed dev client binary predates the native Nitro module link.',
|
|
331
|
-
],
|
|
332
|
-
checks,
|
|
333
|
-
actions: [
|
|
334
|
-
{ id: 'rebuild-native-dev-client' },
|
|
335
|
-
...launchActions(resolved, true),
|
|
336
|
-
],
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (metroLog.status === 'errors') {
|
|
341
|
-
const depsSatisfied = deps.status === 'current';
|
|
342
|
-
if (
|
|
343
|
-
depsSatisfied
|
|
344
|
-
&& (metroLog.reason === 'stale-bundle-error'
|
|
345
|
-
|| metroLog.reason === 'bundle-error')
|
|
346
|
-
) {
|
|
347
|
-
const excerpt = metroLog.excerpt ?? '';
|
|
348
|
-
const persistent = evaluatePersistentBundleError(resolved, excerpt);
|
|
349
|
-
if (persistent.blocked) {
|
|
350
|
-
return {
|
|
351
|
-
schemaVersion: 1,
|
|
352
|
-
adapter: 'mobile',
|
|
353
|
-
target: resolved,
|
|
354
|
-
decision: 'blocked',
|
|
355
|
-
reasonCode: 'bundle-error-persistent',
|
|
356
|
-
reasons: [
|
|
357
|
-
'Metro bundle keeps failing with the same error after a cache-cleared relaunch was already suggested; fix the bundle error in app code before retrying recipe up.',
|
|
358
|
-
...(excerpt ? [excerpt] : []),
|
|
359
|
-
],
|
|
360
|
-
checks,
|
|
361
|
-
actions: [],
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
return {
|
|
365
|
-
schemaVersion: 1,
|
|
366
|
-
adapter: 'mobile',
|
|
367
|
-
target: resolved,
|
|
368
|
-
decision: 'launch',
|
|
369
|
-
reasonCode: metroLog.reason === 'stale-bundle-error' ? 'metro-stale-log' : 'bundle-errors-recoverable',
|
|
370
|
-
reasons: [
|
|
371
|
-
metroLog.reason === 'stale-bundle-error'
|
|
372
|
-
? 'Metro log shows prior bundle failures but cited modules are installed; restart Metro with a cleared cache.'
|
|
373
|
-
: 'Metro bundle is failing with current deps; restart Metro (clear cache) before relaunching the dev client.',
|
|
374
|
-
...(excerpt ? [excerpt] : []),
|
|
375
|
-
],
|
|
376
|
-
checks,
|
|
377
|
-
actions: launchActions(resolved, true),
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
schemaVersion: 1,
|
|
382
|
-
adapter: 'mobile',
|
|
383
|
-
target: resolved,
|
|
384
|
-
decision: 'install',
|
|
385
|
-
reasonCode: metroLog.reason === 'unresolved-module' ? 'deps-unresolved-module' : 'bundle-errors',
|
|
386
|
-
reasons: [
|
|
387
|
-
metroLog.reason === 'unresolved-module'
|
|
388
|
-
? 'Metro cannot resolve modules that are absent from node_modules; run yarn setup.'
|
|
389
|
-
: 'Metro bundle is failing; reinstall deps or clear Metro cache before retrying.',
|
|
390
|
-
...(metroLog.excerpt ? [metroLog.excerpt] : []),
|
|
391
|
-
],
|
|
392
|
-
checks,
|
|
393
|
-
actions: installActions(resolved),
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (metro.status === 'down') {
|
|
398
|
-
return {
|
|
399
|
-
schemaVersion: 1,
|
|
400
|
-
adapter: 'mobile',
|
|
401
|
-
target: resolved,
|
|
402
|
-
decision: 'launch',
|
|
403
|
-
reasonCode: 'metro-down',
|
|
404
|
-
reasons: ['Metro is not reachable; start Metro and launch the dev client.'],
|
|
405
|
-
checks,
|
|
406
|
-
actions: launchActions(resolved),
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (metroLog.status === 'bundling' || metroLog.status === 'no-log') {
|
|
411
|
-
return {
|
|
412
|
-
schemaVersion: 1,
|
|
413
|
-
adapter: 'mobile',
|
|
414
|
-
target: resolved,
|
|
415
|
-
decision: 'launch',
|
|
416
|
-
reasonCode: metroLog.status === 'bundling' ? 'bundle-in-progress' : 'runtime-cold',
|
|
417
|
-
reasons: [
|
|
418
|
-
metroLog.status === 'bundling'
|
|
419
|
-
? 'Metro bundle is still in progress; launch or wait for a successful bundle.'
|
|
420
|
-
: 'No successful Metro bundle recorded; start Metro and launch the dev client.',
|
|
421
|
-
],
|
|
422
|
-
checks,
|
|
423
|
-
actions: launchActions(resolved),
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (metro.status === 'up' && metroLog.status === 'ok') {
|
|
428
|
-
// Metro health alone is not runtime readiness: the dev client may be
|
|
429
|
-
// installed but not running on the target device (launch must launch).
|
|
430
|
-
// Probe the device before declaring ready; a healthy Metro with a dead
|
|
431
|
-
// app relaunches the client without touching Metro.
|
|
432
|
-
if (!appRunningOnDevice(options.platform)) {
|
|
433
|
-
return {
|
|
434
|
-
schemaVersion: 1,
|
|
435
|
-
adapter: 'mobile',
|
|
436
|
-
target: resolved,
|
|
437
|
-
decision: 'launch',
|
|
438
|
-
reasonCode: 'app-not-running',
|
|
439
|
-
reasons: ['Metro is healthy but the dev client is not running on the target device; launching it.'],
|
|
440
|
-
checks,
|
|
441
|
-
actions: launchActions(resolved),
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
return {
|
|
445
|
-
schemaVersion: 1,
|
|
446
|
-
adapter: 'mobile',
|
|
447
|
-
target: resolved,
|
|
448
|
-
decision: 'ready',
|
|
449
|
-
reasonCode: 'healthy',
|
|
450
|
-
reasons: ['Dependencies are current, Metro reports a successful bundle, and the dev client is running. Verify bridge before replay.'],
|
|
451
|
-
checks,
|
|
452
|
-
actions: [],
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return {
|
|
457
|
-
schemaVersion: 1,
|
|
458
|
-
adapter: 'mobile',
|
|
459
|
-
target: resolved,
|
|
460
|
-
decision: 'launch',
|
|
461
|
-
reasonCode: 'runtime-unverified',
|
|
462
|
-
reasons: ['Dependencies are current; start or refresh Metro + dev client before replay.'],
|
|
463
|
-
checks,
|
|
464
|
-
actions: launchActions(resolved),
|
|
465
|
-
};
|
|
466
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Mobile surface: delegates to the existing mobile readiness/port plumbing.
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { recipeRuntimePath, runnerDir } from '../../paths.ts';
|
|
6
|
-
import { resolveMobileSlotPorts } from '../slot-ports.ts';
|
|
7
|
-
import { mobileRuntimeStatus } from './prepare.ts';
|
|
8
|
-
import { hasRunwayProvisionBaseline, provisionRunwayMobile } from './provision.ts';
|
|
9
|
-
import type {
|
|
10
|
-
AdapterDevServerStop,
|
|
11
|
-
AdapterLogSource,
|
|
12
|
-
AdapterRuntimeStatus,
|
|
13
|
-
AdapterRunwayProvisionResult,
|
|
14
|
-
AdapterSurface,
|
|
15
|
-
} from '../surface.ts';
|
|
16
|
-
|
|
17
|
-
export const mobileSurface: AdapterSurface = {
|
|
18
|
-
adapter: 'mobile',
|
|
19
|
-
headless: false,
|
|
20
|
-
|
|
21
|
-
resolveSlotPorts(target: string): void {
|
|
22
|
-
resolveMobileSlotPorts(target);
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
async runtimeStatus(target: string): Promise<AdapterRuntimeStatus> {
|
|
26
|
-
const watcherPort = process.env.WATCHER_PORT ? parseInt(process.env.WATCHER_PORT, 10) : undefined;
|
|
27
|
-
const report = await mobileRuntimeStatus(target, { watcherPort });
|
|
28
|
-
const runwayProvisioned = hasRunwayProvisionBaseline(target);
|
|
29
|
-
const depsPending = runwayProvisioned && report.checks?.deps?.status !== 'current';
|
|
30
|
-
return {
|
|
31
|
-
decision: depsPending ? 'launch' : report.decision,
|
|
32
|
-
reasonCode: depsPending ? 'app-installed-deps-pending' : report.reasonCode,
|
|
33
|
-
reasons: depsPending
|
|
34
|
-
? ['Runway app is installed; JavaScript dependencies are pending until dispatch-time launch.']
|
|
35
|
-
: report.reasons,
|
|
36
|
-
deps: runwayProvisioned && report.checks?.deps?.status !== 'current' ? 'pending' : report.checks?.deps?.status,
|
|
37
|
-
devServer: { label: 'metro', status: report.checks?.metro?.status ?? 'unprobed' },
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
runwayProvision: {
|
|
42
|
-
async run(target, options): Promise<AdapterRunwayProvisionResult> {
|
|
43
|
-
return provisionRunwayMobile(target, options) as Promise<AdapterRunwayProvisionResult>;
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
devServer: {
|
|
48
|
-
describe: () => 'Metro dev server',
|
|
49
|
-
stop(target: string): AdapterDevServerStop {
|
|
50
|
-
const leaf = path.join(runnerDir, 'adapters', 'mobile', 'stop-metro.sh');
|
|
51
|
-
const args = ['--target', target];
|
|
52
|
-
if (process.env.WATCHER_PORT) args.push('--port', process.env.WATCHER_PORT);
|
|
53
|
-
const result = spawnSync('bash', [leaf, ...args], { encoding: 'utf8' });
|
|
54
|
-
const status = result.status ?? 1;
|
|
55
|
-
const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
|
|
56
|
-
const summary = status === 0
|
|
57
|
-
? `stopped Metro dev server for ${target}`
|
|
58
|
-
: `failed to stop Metro for ${target}`;
|
|
59
|
-
return { kind: 'stopped', status, summary, output };
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
logSources(target: string): AdapterLogSource[] {
|
|
64
|
-
return [{ label: 'metro', path: recipeRuntimePath(target, 'metro.log') }];
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
hints: {
|
|
68
|
-
launch: 'mm-harness launch ios',
|
|
69
|
-
relaunch: 'mm-harness launch ios',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// TypeScript surface for slot-port resolution — delegates to the self-contained core leaf.
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
formatKvLines,
|
|
5
|
-
inferSlotSuffix,
|
|
6
|
-
realRepoPath,
|
|
7
|
-
resolveDefaultExtensionPorts,
|
|
8
|
-
resolveExtensionRuntimePorts,
|
|
9
|
-
resolveFarmslotPortsByRepo,
|
|
10
|
-
resolveMobileRuntimeContext,
|
|
11
|
-
resolveMobileRuntimePorts,
|
|
12
|
-
resolveMobileSlotDefaults,
|
|
13
|
-
} from '../../adapters/shared/resolve-farmslot-ports-core.mjs';
|