agentlane 0.0.0 → 0.4.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/LICENSE +27 -0
- package/README.md +167 -2
- package/dist/agents/claude-plugin.js +79 -0
- package/dist/agents/cli.js +258 -0
- package/dist/agents/detect.js +88 -0
- package/dist/agents/init.js +251 -0
- package/dist/agents/launcher.js +32 -0
- package/dist/agents/package.js +119 -0
- package/dist/agents/skills.js +59 -0
- package/dist/agents/toml.js +325 -0
- package/dist/agents/wiring-check.js +117 -0
- package/dist/agents/wiring.js +374 -0
- package/dist/bench/host.js +104 -0
- package/dist/bench/live.js +511 -0
- package/dist/bench/mcp-client.js +91 -0
- package/dist/bench/model.js +15 -0
- package/dist/bench/report.js +162 -0
- package/dist/bench/run.js +121 -0
- package/dist/bench/schedule.js +140 -0
- package/dist/bench/stats.js +59 -0
- package/dist/bench-cli.js +167 -0
- package/dist/browser/aria.js +184 -0
- package/dist/browser/control.js +203 -0
- package/dist/browser/env.js +118 -0
- package/dist/browser/evidence.js +44 -0
- package/dist/browser/install.js +361 -0
- package/dist/browser/kinds.js +10 -0
- package/dist/browser/lane-browser.js +224 -0
- package/dist/browser/libraries.js +56 -0
- package/dist/browser/paths.js +29 -0
- package/dist/browser/release.js +121 -0
- package/dist/browser/screen.js +19 -0
- package/dist/browser/signin.js +154 -0
- package/dist/browser/stop.js +163 -0
- package/dist/browser/tools.js +25 -0
- package/dist/cache/build.js +154 -0
- package/dist/cache/config.js +186 -0
- package/dist/cache/index.js +4 -0
- package/dist/cache/key.js +196 -0
- package/dist/cache/store.js +303 -0
- package/dist/cli.js +178 -0
- package/dist/clock.js +4 -0
- package/dist/devices/adb.js +160 -0
- package/dist/devices/android.js +214 -0
- package/dist/devices/backend.js +7 -0
- package/dist/devices/bundler.js +46 -0
- package/dist/devices/common.js +51 -0
- package/dist/devices/controls.js +65 -0
- package/dist/devices/dial.js +56 -0
- package/dist/devices/emulator.js +396 -0
- package/dist/devices/hygiene.js +202 -0
- package/dist/devices/index.js +5 -0
- package/dist/devices/launch.js +76 -0
- package/dist/devices/simctl.js +119 -0
- package/dist/devices/tools.js +1 -0
- package/dist/devices/variant.js +99 -0
- package/dist/devices/xcrun.js +265 -0
- package/dist/driver/absence.js +54 -0
- package/dist/driver/caller.js +51 -0
- package/dist/driver/client.js +312 -0
- package/dist/driver/diff.js +180 -0
- package/dist/driver/elements.js +70 -0
- package/dist/driver/engine-main.js +13 -0
- package/dist/driver/engine.js +499 -0
- package/dist/driver/errors.js +11 -0
- package/dist/driver/exec.js +66 -0
- package/dist/driver/failure.js +156 -0
- package/dist/driver/flow.js +94 -0
- package/dist/driver/idle.js +100 -0
- package/dist/driver/images.js +68 -0
- package/dist/driver/install.js +272 -0
- package/dist/driver/lock.js +101 -0
- package/dist/driver/look.js +223 -0
- package/dist/driver/maestro-child.js +194 -0
- package/dist/driver/maestro-runs.js +46 -0
- package/dist/driver/paths.js +105 -0
- package/dist/driver/pixels.js +144 -0
- package/dist/driver/plan.js +108 -0
- package/dist/driver/release.js +7 -0
- package/dist/driver/runner.js +42 -0
- package/dist/driver/selector.js +91 -0
- package/dist/driver/session.js +474 -0
- package/dist/driver/suggest.js +86 -0
- package/dist/driver/supervisor.js +251 -0
- package/dist/driver/tree.js +426 -0
- package/dist/driver-cli.js +865 -0
- package/dist/evidence/device.js +177 -0
- package/dist/evidence/evidence.js +304 -0
- package/dist/evidence/files.js +92 -0
- package/dist/hooks/env.js +81 -0
- package/dist/hooks/run.js +101 -0
- package/dist/mcp/server.js +69 -0
- package/dist/mcp/tools.js +246 -0
- package/dist/name.js +22 -0
- package/dist/plugin/aims.js +465 -0
- package/dist/plugin/conventions.js +73 -0
- package/dist/plugin/guard.js +163 -0
- package/dist/plugin/hook-cli.js +216 -0
- package/dist/plugin/session-name.js +28 -0
- package/dist/plugin/shell.js +254 -0
- package/dist/processes.js +77 -0
- package/dist/project/config.js +316 -0
- package/dist/project/schema.js +335 -0
- package/dist/project/validate.js +224 -0
- package/dist/registry/config.js +142 -0
- package/dist/registry/format.js +22 -0
- package/dist/registry/owner.js +265 -0
- package/dist/registry/paths.js +50 -0
- package/dist/registry/ports.js +26 -0
- package/dist/registry/prune.js +160 -0
- package/dist/registry/refusal.js +53 -0
- package/dist/registry/registry.js +1027 -0
- package/dist/registry/resources.js +117 -0
- package/dist/registry/rows.js +115 -0
- package/dist/registry/status.js +85 -0
- package/dist/registry/store.js +274 -0
- package/dist/registry/types.js +1 -0
- package/dist/registry-cli.js +544 -0
- package/dist/services/services.js +268 -0
- package/dist/services/system.js +189 -0
- package/dist/up/deps.js +1 -0
- package/dist/up/doctor.js +424 -0
- package/dist/up/exec.js +133 -0
- package/dist/up/lane-files.js +75 -0
- package/dist/up/lane-services.js +38 -0
- package/dist/up/maestro-env.js +172 -0
- package/dist/up/preflight.js +232 -0
- package/dist/up/release.js +148 -0
- package/dist/up/resources.js +178 -0
- package/dist/up/restart.js +87 -0
- package/dist/up/setup.js +28 -0
- package/dist/up/up.js +610 -0
- package/dist/up-cli.js +258 -0
- package/dist/usage.js +16 -0
- package/package.json +58 -3
- package/schema/agentlane.schema.json +675 -0
- package/skills/create-verification-skill/LICENSE +21 -0
- package/skills/create-verification-skill/SKILL.md +88 -0
- package/skills/dev-loop/LICENSE +21 -0
- package/skills/dev-loop/SKILL.md +61 -0
- package/skills/device/SKILL.md +8 -0
- package/skills/drive/SKILL.md +64 -0
- package/skills/maintain-verification-skill/LICENSE +21 -0
- package/skills/maintain-verification-skill/SKILL.md +42 -0
- package/skills/setup/SKILL.md +80 -0
package/dist/up/up.js
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { setupFix } from "../agents/skills.js";
|
|
4
|
+
import { describeSavedLogin, hasBrowser, openWebApp, signInBrowser, startFailureTrace, stopEndedBrowsers, } from "../browser/lane-browser.js";
|
|
5
|
+
import { realBrowserTools } from "../browser/tools.js";
|
|
6
|
+
import { cachedBuild } from "../cache/build.js";
|
|
7
|
+
import { computeKey } from "../cache/key.js";
|
|
8
|
+
import { BuildCache, cacheDirFor } from "../cache/store.js";
|
|
9
|
+
import { adbTools } from "../devices/adb.js";
|
|
10
|
+
import { applyAndroidHygiene, describeRestored, describeReverse, ensureReverse, intentExtras, launchAndroidApp, launchAndroidDevClient, REACT_NATIVE_DEVICE_PORT, requireAppInstalled, requireEmulatorBooted, restoreReverse, } from "../devices/android.js";
|
|
11
|
+
import { DEVICE_NOUN } from "../devices/backend.js";
|
|
12
|
+
import { pinBundler } from "../devices/bundler.js";
|
|
13
|
+
import { requireBooted, requireInstalled } from "../devices/common.js";
|
|
14
|
+
import { dialDefaults, writeDialDefaults } from "../devices/dial.js";
|
|
15
|
+
import { applyHygiene } from "../devices/hygiene.js";
|
|
16
|
+
import { readIosBundle } from "../devices/variant.js";
|
|
17
|
+
import { ensureSchemeApproval, launchApp, launchDevClient, rebootDevice } from "../devices/launch.js";
|
|
18
|
+
import { laneEnvironment, laneVariables, hookEnvironment, LAUNCH_ARGS_ENV, resourceVariables, webUrl } from "../hooks/env.js";
|
|
19
|
+
import { runHook } from "../hooks/run.js";
|
|
20
|
+
import { CLI, CONFIG_FILE, TOOL } from "../name.js";
|
|
21
|
+
import { identityOf } from "../processes.js";
|
|
22
|
+
import { asMobile, findProjectConfig, forPlatform, loadProjectConfig } from "../project/config.js";
|
|
23
|
+
import { WEB_PLATFORM } from "../project/schema.js";
|
|
24
|
+
import { loadConfig, withProjectBlocks } from "../registry/config.js";
|
|
25
|
+
import { formatAge, shellQuote } from "../registry/format.js";
|
|
26
|
+
import { resolveOwner } from "../registry/owner.js";
|
|
27
|
+
import { stateDir } from "../registry/paths.js";
|
|
28
|
+
import { UsageError } from "../registry/refusal.js";
|
|
29
|
+
import { Registry } from "../registry/registry.js";
|
|
30
|
+
import { resolveFolder } from "../registry-cli.js";
|
|
31
|
+
import { explainInspection, inspectService } from "../services/services.js";
|
|
32
|
+
import { laneDir, hookLog, pruneEndedLaneFiles, readUpRecord, writeUpRecord } from "./lane-files.js";
|
|
33
|
+
import { claimedPort, recordedProcess, startClaimedService, stopClaimedService } from "./lane-services.js";
|
|
34
|
+
import { bundlerPort, diagnose, dialArguments, reversePorts } from "./doctor.js";
|
|
35
|
+
import { driverVariables } from "./maestro-env.js";
|
|
36
|
+
import { androidBuildEnvironment, projectFindings, toolchainFindings, Unmet } from "./preflight.js";
|
|
37
|
+
import { stopEndedLanes } from "./release.js";
|
|
38
|
+
import { createResources, tearDownEndedResources } from "./resources.js";
|
|
39
|
+
function seconds(ms) {
|
|
40
|
+
return `${(ms / 1000).toFixed(1)} s`;
|
|
41
|
+
}
|
|
42
|
+
export function locateConfig(start) {
|
|
43
|
+
const file = findProjectConfig(start);
|
|
44
|
+
if (!file) {
|
|
45
|
+
throw new UsageError(`no ${CONFIG_FILE} in ${start} or the folders above it in this repository`, setupFix(`write one at the project's root ('${CLI} schema' prints its JSON Schema)`));
|
|
46
|
+
}
|
|
47
|
+
return loadProjectConfig(file);
|
|
48
|
+
}
|
|
49
|
+
function projectBlocks(config) {
|
|
50
|
+
const blocks = {};
|
|
51
|
+
for (const s of config.services)
|
|
52
|
+
if (s.ports)
|
|
53
|
+
blocks[s.type] = { first: s.ports[0], last: s.ports[1] };
|
|
54
|
+
return blocks;
|
|
55
|
+
}
|
|
56
|
+
class Run {
|
|
57
|
+
steps = [];
|
|
58
|
+
deps;
|
|
59
|
+
constructor(deps) {
|
|
60
|
+
this.deps = deps;
|
|
61
|
+
}
|
|
62
|
+
async step(name, work, describe) {
|
|
63
|
+
const started = this.deps.clock.now();
|
|
64
|
+
const value = await work();
|
|
65
|
+
const ms = this.deps.clock.now() - started;
|
|
66
|
+
const detail = describe(value);
|
|
67
|
+
this.steps.push({ step: name, ms, detail });
|
|
68
|
+
this.deps.log(`${TOOL} up: ${name}: ${detail} (${seconds(ms)})`);
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function hook(ctx, name, extraEnv = {}) {
|
|
73
|
+
const command = ctx.config.hooks[name];
|
|
74
|
+
if (!command)
|
|
75
|
+
return null;
|
|
76
|
+
const log = hookLog(ctx.dir, name);
|
|
77
|
+
ctx.deps.log(`${TOOL} up: ${name}: ${command} (log: ${log})`);
|
|
78
|
+
ctx.registry.touch(ctx.ref, `up: ${name}`);
|
|
79
|
+
return runHook(name, command, { cwd: ctx.config.dir, env: { ...ctx.env, ...extraEnv }, log });
|
|
80
|
+
}
|
|
81
|
+
async function bootDevice(sim, udid, reboot) {
|
|
82
|
+
const device = await sim.device(udid);
|
|
83
|
+
if (device?.state === 'Booted') {
|
|
84
|
+
if (!reboot)
|
|
85
|
+
return 'already booted';
|
|
86
|
+
await rebootDevice(sim, udid);
|
|
87
|
+
return 'rebooted so the scheme approval takes effect';
|
|
88
|
+
}
|
|
89
|
+
await sim.boot(udid);
|
|
90
|
+
await requireBooted(sim, udid);
|
|
91
|
+
return 'booted';
|
|
92
|
+
}
|
|
93
|
+
function installer(target) {
|
|
94
|
+
return target.platform === 'ios' ? app => target.sim.installApp(target.udid, app) : apk => target.adb.install(apk);
|
|
95
|
+
}
|
|
96
|
+
async function installedApp(ctx, bundleId) {
|
|
97
|
+
const { target } = ctx;
|
|
98
|
+
if (target.platform === 'ios') {
|
|
99
|
+
await requireInstalled(target.sim, target.udid, bundleId);
|
|
100
|
+
const container = await target.sim.appContainer(target.udid, bundleId);
|
|
101
|
+
if (!container)
|
|
102
|
+
throw new Error(`${bundleId} is installed on ${target.udid}, but its app bundle can't be read back`);
|
|
103
|
+
return container;
|
|
104
|
+
}
|
|
105
|
+
await requireAppInstalled(target.adb, bundleId);
|
|
106
|
+
const apks = await target.adb.installedApk(bundleId);
|
|
107
|
+
const [apk] = apks;
|
|
108
|
+
if (apks.length !== 1 || apk === undefined) {
|
|
109
|
+
throw new Error(`${bundleId} is installed on ${target.serial} as ${String(apks.length)} APKs, which the build cache can't store; set app.android.output to the APK the build hook writes`);
|
|
110
|
+
}
|
|
111
|
+
const local = path.join(ctx.dir, 'installed', `${bundleId}.apk`);
|
|
112
|
+
fs.mkdirSync(path.dirname(local), { recursive: true });
|
|
113
|
+
await target.adb.pull(apk, local);
|
|
114
|
+
return local;
|
|
115
|
+
}
|
|
116
|
+
async function requireAppOnDevice(target, bundleId) {
|
|
117
|
+
if (target.platform === 'ios')
|
|
118
|
+
await requireInstalled(target.sim, target.udid, bundleId);
|
|
119
|
+
else
|
|
120
|
+
await requireAppInstalled(target.adb, bundleId);
|
|
121
|
+
}
|
|
122
|
+
async function buildApp(ctx, mode) {
|
|
123
|
+
const { config, target } = ctx;
|
|
124
|
+
const { bundleId, output } = config.app;
|
|
125
|
+
const install = installer(target);
|
|
126
|
+
if (!config.hooks.build) {
|
|
127
|
+
await requireAppOnDevice(target, bundleId);
|
|
128
|
+
return { source: 'installed', reason: 'no-build-hook' };
|
|
129
|
+
}
|
|
130
|
+
const env = config.app.platform === 'android' ? await androidBuildEnvironment(ctx.env, ctx.deps.toolchain) : ctx.env;
|
|
131
|
+
const build = async () => {
|
|
132
|
+
await hook({ ...ctx, env }, 'build');
|
|
133
|
+
if (output !== null) {
|
|
134
|
+
const app = path.resolve(config.dir, output);
|
|
135
|
+
await install(app);
|
|
136
|
+
return app;
|
|
137
|
+
}
|
|
138
|
+
return installedApp(ctx, bundleId);
|
|
139
|
+
};
|
|
140
|
+
const cacheConfig = config.buildCache;
|
|
141
|
+
if (!cacheConfig) {
|
|
142
|
+
await build();
|
|
143
|
+
return { source: 'build', reason: 'no-cache-config' };
|
|
144
|
+
}
|
|
145
|
+
const cache = new BuildCache({ dir: await cacheDirFor(config.dir), config: cacheConfig });
|
|
146
|
+
const builder = identityOf(ctx.deps.processes, process.pid);
|
|
147
|
+
return cachedBuild({
|
|
148
|
+
cache,
|
|
149
|
+
variant: config.app.variant,
|
|
150
|
+
worktree: ctx.lane.worktree,
|
|
151
|
+
mode,
|
|
152
|
+
key: async () => computeKey({
|
|
153
|
+
root: config.dir,
|
|
154
|
+
inputs: cacheConfig.inputs,
|
|
155
|
+
platform: config.app.platform,
|
|
156
|
+
variant: config.app.variant,
|
|
157
|
+
toolchain: config.app.platform === 'ios'
|
|
158
|
+
? await ctx.deps.toolchain.xcodeVersion()
|
|
159
|
+
: await ctx.deps.toolchain.androidToolchain(config.dir, env),
|
|
160
|
+
...(cacheConfig.envFile !== undefined ? { envFile: cacheConfig.envFile } : {}),
|
|
161
|
+
env: ctx.env,
|
|
162
|
+
}),
|
|
163
|
+
install,
|
|
164
|
+
build,
|
|
165
|
+
...(builder
|
|
166
|
+
? {
|
|
167
|
+
wait: {
|
|
168
|
+
builder,
|
|
169
|
+
processes: ctx.deps.processes,
|
|
170
|
+
clock: ctx.deps.clock,
|
|
171
|
+
log: line => {
|
|
172
|
+
ctx.deps.log(`${TOOL} up: build: ${line}`);
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
: {}),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function describeBuild(result) {
|
|
180
|
+
if (result.source === 'cache') {
|
|
181
|
+
const waited = result.waited ? `, after waiting ${formatAge(result.waited.ms)} for that build` : '';
|
|
182
|
+
return `served from the build cache (key ${result.key.slice(0, 12)}, built in ${result.origin.worktree} at ${result.origin.storedAt.toISOString()}${waited})`;
|
|
183
|
+
}
|
|
184
|
+
if (result.source === 'installed')
|
|
185
|
+
return 'no build hook; the installed app is used';
|
|
186
|
+
if (result.reason === 'no-cache-config')
|
|
187
|
+
return 'built (no build cache configured)';
|
|
188
|
+
const stored = result.stored ? `, stored as ${result.storedKey?.slice(0, 12) ?? ''}` : '';
|
|
189
|
+
const waited = result.waited ? [`waited ${formatAge(result.waited.ms)} for ${result.waited.worktree}'s build first`] : [];
|
|
190
|
+
const notes = [...waited, ...result.problems];
|
|
191
|
+
const problems = notes.length > 0 ? `; ${notes.join('; ')}` : '';
|
|
192
|
+
return `built (cache ${result.reason}${stored})${problems}`;
|
|
193
|
+
}
|
|
194
|
+
async function ensureService(ctx, service) {
|
|
195
|
+
const { deps, lane } = ctx;
|
|
196
|
+
const port = claimedPort(lane, service.name);
|
|
197
|
+
if (port === undefined)
|
|
198
|
+
throw new Error(`lane ${lane.id} has no port for ${service.name}`);
|
|
199
|
+
const recorded = recordedProcess(lane, service.name);
|
|
200
|
+
if (recorded) {
|
|
201
|
+
const seen = await inspectService(deps.system, service, port, recorded);
|
|
202
|
+
if (seen.healthy)
|
|
203
|
+
return `already running on ${String(port)} (pid ${String(recorded.pid)}); ${seen.readyDetail}`;
|
|
204
|
+
const stopped = await stopClaimedService(ctx, recorded);
|
|
205
|
+
const started = await startClaimedService(ctx, service, port);
|
|
206
|
+
return `${started}, replacing pid ${String(recorded.pid)}, which failed its check (${explainInspection(seen)}): ${stopped}`;
|
|
207
|
+
}
|
|
208
|
+
return startClaimedService(ctx, service, port);
|
|
209
|
+
}
|
|
210
|
+
async function launchAndroid(ctx, adb) {
|
|
211
|
+
const { config, lane } = ctx;
|
|
212
|
+
const { bundleId } = config.app;
|
|
213
|
+
const launchArgs = dialArguments(config, lane);
|
|
214
|
+
const port = bundlerPort(config, lane);
|
|
215
|
+
switch (config.app.launch) {
|
|
216
|
+
case 'dev-client': {
|
|
217
|
+
if (port === undefined)
|
|
218
|
+
throw new Error(`no port for the bundler service ${config.app.bundler ?? '(none)'}`);
|
|
219
|
+
if (config.app.scheme === null) {
|
|
220
|
+
throw new UsageError("an Expo dev client on Android opens its bundler through a link in the app's URL scheme, and app.scheme is not set", `set app.scheme in ${CONFIG_FILE} to the scheme in app.json`);
|
|
221
|
+
}
|
|
222
|
+
const report = await launchAndroidDevClient(adb, { pkg: bundleId, scheme: config.app.scheme, port, launchArgs });
|
|
223
|
+
return `dev client opened with am start ${report.intent.join(' ')}`;
|
|
224
|
+
}
|
|
225
|
+
case 'bundler-pin': {
|
|
226
|
+
const report = await launchAndroidApp(adb, { pkg: bundleId, launchArgs });
|
|
227
|
+
return `bundler pinned by adb reverse (localhost:${String(REACT_NATIVE_DEVICE_PORT)} on the emulator is Metro); launched with am start ${report.intent.join(' ')}`;
|
|
228
|
+
}
|
|
229
|
+
case 'hook': {
|
|
230
|
+
await hook(ctx, 'launch', { [LAUNCH_ARGS_ENV]: intentLaunchArgs(launchArgs) });
|
|
231
|
+
return 'the launch hook ran';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function intentLaunchArgs(launchArgs) {
|
|
236
|
+
return intentExtras(launchArgs).map(shellQuote).join(' ');
|
|
237
|
+
}
|
|
238
|
+
async function launch(ctx) {
|
|
239
|
+
ctx.registry.touch(ctx.ref, 'up: launch');
|
|
240
|
+
if (ctx.target.platform === 'android')
|
|
241
|
+
return launchAndroid(ctx, ctx.target.adb);
|
|
242
|
+
const { config, lane } = ctx;
|
|
243
|
+
const { sim, udid } = ctx.target;
|
|
244
|
+
const { bundleId } = config.app;
|
|
245
|
+
const launchArgs = dialArguments(config, lane);
|
|
246
|
+
const port = bundlerPort(config, lane);
|
|
247
|
+
switch (config.app.launch) {
|
|
248
|
+
case 'dev-client': {
|
|
249
|
+
if (port === undefined)
|
|
250
|
+
throw new Error(`no port for the bundler service ${config.app.bundler ?? '(none)'}`);
|
|
251
|
+
const report = await launchDevClient(sim, { udid, bundleId, port, launchArgs });
|
|
252
|
+
return `dev client launched with ${report.args.join(' ')}`;
|
|
253
|
+
}
|
|
254
|
+
case 'bundler-pin': {
|
|
255
|
+
if (port === undefined)
|
|
256
|
+
throw new Error(`no port for the bundler service ${config.app.bundler ?? '(none)'}`);
|
|
257
|
+
const pin = await pinBundler(sim, { udid, bundleId, port });
|
|
258
|
+
const record = readUpRecord(ctx.dir);
|
|
259
|
+
if (record)
|
|
260
|
+
writeUpRecord(ctx.dir, { ...record, pinned: true, updatedAt: ctx.deps.clock.now() });
|
|
261
|
+
const dials = dialDefaults(launchArgs);
|
|
262
|
+
await writeDialDefaults(sim, { udid, bundleId, dials });
|
|
263
|
+
const report = await launchApp(sim, { udid, bundleId, launchArgs });
|
|
264
|
+
const kept = dials.length > 0 ? `; ${dials.map(d => d.key).join(', ')} kept in its defaults for relaunches` : '';
|
|
265
|
+
return `bundler pinned to ${pin.readBack}; launched with ${report.args.join(' ') || 'no arguments'}${kept}`;
|
|
266
|
+
}
|
|
267
|
+
case 'hook': {
|
|
268
|
+
await hook(ctx, 'launch', { [LAUNCH_ARGS_ENV]: launchArgs.map(shellQuote).join(' ') });
|
|
269
|
+
return 'the launch hook ran';
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function keepDeviceNetwork(ctx, wanted, step) {
|
|
274
|
+
if (ctx.target.platform !== 'android' || wanted.size === 0)
|
|
275
|
+
return false;
|
|
276
|
+
const after = `after ${step}`;
|
|
277
|
+
const restored = await restoreReverse(ctx.target.adb, wanted, after);
|
|
278
|
+
if (restored.size > 0)
|
|
279
|
+
ctx.deps.log(`${TOOL} up: ${describeRestored(restored, ctx.target.serial, after)}`);
|
|
280
|
+
return restored.size > 0;
|
|
281
|
+
}
|
|
282
|
+
const DETAILED_FINDINGS = new Set(['Xcode', 'simulator runtime', 'Android SDK', 'emulator image', 'Java 17']);
|
|
283
|
+
function deviceTarget(deps, config, lane, options) {
|
|
284
|
+
const claimed = lane.device;
|
|
285
|
+
if (!claimed)
|
|
286
|
+
throw new Error(`lane ${lane.id} holds no device`);
|
|
287
|
+
if (claimed.platform !== config.platform) {
|
|
288
|
+
throw new UsageError(`this folder's lane ${lane.id} holds ${claimed.name}, ${DEVICE_NOUN[claimed.platform]}, and up is running for ${config.platform}`, `${CLI} release here, then ${CLI} up${options.platform === undefined ? '' : ` --platform ${options.platform}`}; or run ${CLI} up --platform ${claimed.platform}`);
|
|
289
|
+
}
|
|
290
|
+
if (claimed.platform === 'android') {
|
|
291
|
+
if (claimed.serial === null)
|
|
292
|
+
throw new Error(`lane ${lane.id}'s emulator ${claimed.name} has no adb serial`);
|
|
293
|
+
return { platform: 'android', adb: adbTools(deps, claimed.serial), serial: claimed.serial };
|
|
294
|
+
}
|
|
295
|
+
if (!deps.sim)
|
|
296
|
+
throw new UsageError('this machine has no iOS simulators', 'run up on a Mac with Xcode installed');
|
|
297
|
+
return { platform: 'ios', sim: deps.sim, udid: claimed.id };
|
|
298
|
+
}
|
|
299
|
+
async function deviceSteps(ctx, run, options, booting, approval, setup) {
|
|
300
|
+
const { deps, target, config, registry, lane, dir } = ctx;
|
|
301
|
+
const udid = target.platform === 'ios' ? target.udid : target.serial;
|
|
302
|
+
const booted = await booting;
|
|
303
|
+
if (!booted.ok)
|
|
304
|
+
throw booted.error;
|
|
305
|
+
run.steps.push({ step: 'boot', ms: booted.ms, detail: booted.detail });
|
|
306
|
+
deps.log(`${TOOL} up: boot: ${lane.device?.name ?? udid} ${booted.detail}${approval?.changed ? `, ${config.app.scheme ?? ''}:// approved before boot` : ''} (${seconds(booted.ms)}${setup ? ', alongside setup' : ''})`);
|
|
307
|
+
const build = await run.step('build', () => buildApp(ctx, options.cacheMode), describeBuild);
|
|
308
|
+
if (target.platform === 'ios' && build.source !== 'installed') {
|
|
309
|
+
const container = await target.sim.appContainer(udid, config.app.bundleId);
|
|
310
|
+
const sha256 = container === undefined ? undefined : readIosBundle(container).sha256;
|
|
311
|
+
const record = readUpRecord(dir);
|
|
312
|
+
if (record && sha256 !== undefined) {
|
|
313
|
+
writeUpRecord(dir, { ...record, installed: { variant: config.app.variant, sha256 }, updatedAt: deps.clock.now() });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
await serviceSteps(ctx, run);
|
|
317
|
+
const wanted = target.platform === 'android' ? reversePorts(config, lane) : new Map();
|
|
318
|
+
if (target.platform === 'android') {
|
|
319
|
+
await run.step('device network', async () => {
|
|
320
|
+
registry.touch(ctx.ref, 'up: device network');
|
|
321
|
+
const report = await ensureReverse(target.adb, wanted);
|
|
322
|
+
const record = readUpRecord(dir);
|
|
323
|
+
if (record)
|
|
324
|
+
writeUpRecord(dir, { ...record, reversed: [...wanted.keys()], updatedAt: deps.clock.now() });
|
|
325
|
+
return report;
|
|
326
|
+
}, report => wanted.size === 0
|
|
327
|
+
? 'nothing to forward'
|
|
328
|
+
: `adb reverse ${describeReverse(wanted)}${report.added.length === 0 ? ' (already in place)' : ''}`);
|
|
329
|
+
}
|
|
330
|
+
await run.step('hygiene', async () => {
|
|
331
|
+
registry.touch(ctx.ref, 'up: hygiene');
|
|
332
|
+
return target.platform === 'ios'
|
|
333
|
+
? applyHygiene(target.sim, udid, config.hygiene)
|
|
334
|
+
: applyAndroidHygiene(target.adb, config.hygiene);
|
|
335
|
+
}, report => report.changed
|
|
336
|
+
? `applied ${report.steps
|
|
337
|
+
.filter(s => s.changed)
|
|
338
|
+
.map(s => s.step)
|
|
339
|
+
.join(', ')}`
|
|
340
|
+
: 'already in place');
|
|
341
|
+
await run.step('launch', () => launch(ctx), detail => detail);
|
|
342
|
+
let relaunched = false;
|
|
343
|
+
const relaunchIfDropped = async (step) => {
|
|
344
|
+
if (!(await keepDeviceNetwork(ctx, wanted, step)) || relaunched)
|
|
345
|
+
return;
|
|
346
|
+
relaunched = true;
|
|
347
|
+
await run.step('relaunch', () => launch(ctx), detail => `${detail}, so the app loads its bundle again over the restored rules`);
|
|
348
|
+
await keepDeviceNetwork(ctx, wanted, 'relaunch');
|
|
349
|
+
};
|
|
350
|
+
await relaunchIfDropped('launch');
|
|
351
|
+
if (config.hooks.signin) {
|
|
352
|
+
await run.step('signin', async () => hook(ctx, 'signin', await driverVariables(deps, config, lane, dir)), () => 'done');
|
|
353
|
+
await keepDeviceNetwork(ctx, wanted, 'signin');
|
|
354
|
+
}
|
|
355
|
+
if (config.driver) {
|
|
356
|
+
await run.step('driver', async () => {
|
|
357
|
+
registry.touch(ctx.ref, 'up: driver');
|
|
358
|
+
try {
|
|
359
|
+
await deps.startDriver(lane, stateDir(deps.env));
|
|
360
|
+
return 'started; the first look is warm';
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
return `not started (${(error instanceof Error ? error.message : String(error)).split('\n')[0] ?? ''}); the first look starts it`;
|
|
364
|
+
}
|
|
365
|
+
}, detail => detail);
|
|
366
|
+
if (config.hooks.signin)
|
|
367
|
+
await keepDeviceNetwork(ctx, wanted, 'the driver started');
|
|
368
|
+
else
|
|
369
|
+
await relaunchIfDropped('the driver started');
|
|
370
|
+
}
|
|
371
|
+
return build;
|
|
372
|
+
}
|
|
373
|
+
async function serviceSteps(ctx, run) {
|
|
374
|
+
for (const service of ctx.config.services) {
|
|
375
|
+
await run.step(`service ${service.name}`, () => ensureService(ctx, service), detail => detail);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const TRACE_NOTE = "; the driver's actions are traced from here, and the trace is kept when a command under exec fails";
|
|
379
|
+
async function browserSteps(ctx, run, tools, driverChanged) {
|
|
380
|
+
const { lane, deps } = ctx;
|
|
381
|
+
if (!hasBrowser(lane))
|
|
382
|
+
throw new Error(`lane ${lane.id} holds no browser`);
|
|
383
|
+
const browserCtx = {
|
|
384
|
+
tools,
|
|
385
|
+
stateDir: stateDir(deps.env),
|
|
386
|
+
lane,
|
|
387
|
+
config: ctx.config,
|
|
388
|
+
url: webUrl(ctx.config, lane),
|
|
389
|
+
env: deps.env,
|
|
390
|
+
laneEnv: ctx.env,
|
|
391
|
+
cwd: ctx.config.dir,
|
|
392
|
+
log: line => {
|
|
393
|
+
deps.log(`${TOOL} up: browser: ${line}`);
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
const opened = await run.step('browser', async () => {
|
|
397
|
+
ctx.registry.touch(ctx.ref, 'up: browser');
|
|
398
|
+
const done = await openWebApp(browserCtx, deps.clock, driverChanged);
|
|
399
|
+
const traced = !ctx.config.hooks.signin && (await startFailureTrace(done.browser));
|
|
400
|
+
return { ...done, detail: `${done.detail}${traced ? TRACE_NOTE : ''}` };
|
|
401
|
+
}, o => o.detail);
|
|
402
|
+
if (!ctx.config.hooks.signin)
|
|
403
|
+
return;
|
|
404
|
+
await run.step('signin', async () => {
|
|
405
|
+
fs.rmSync(opened.browser.setting.paths.storageState, { force: true });
|
|
406
|
+
await hook(ctx, 'signin', opened.browser.vars);
|
|
407
|
+
const login = await signInBrowser(browserCtx, opened.browser);
|
|
408
|
+
const traced = await startFailureTrace(opened.browser);
|
|
409
|
+
return `the browser starts with the saved login, ${describeSavedLogin(login)}${traced ? TRACE_NOTE : ''}`;
|
|
410
|
+
}, detail => detail);
|
|
411
|
+
}
|
|
412
|
+
function describeResources(made) {
|
|
413
|
+
const parts = [
|
|
414
|
+
made.created.length > 0 ? `created ${made.created.join(', ')}` : '',
|
|
415
|
+
made.kept.length > 0 ? `kept ${made.kept.join(', ')} from an earlier up of this lane` : '',
|
|
416
|
+
];
|
|
417
|
+
return parts.filter(p => p !== '').join('; ');
|
|
418
|
+
}
|
|
419
|
+
export async function up(deps, options) {
|
|
420
|
+
const started = deps.clock.now();
|
|
421
|
+
const run = new Run(deps);
|
|
422
|
+
const start = options.worktree ?? deps.cwd;
|
|
423
|
+
const located = locateConfig(start);
|
|
424
|
+
const config = forPlatform(located, options.platform ?? located.platform);
|
|
425
|
+
const mobile = asMobile(config);
|
|
426
|
+
const folder = resolveFolder(start);
|
|
427
|
+
const backend = mobile ? deps.devices[mobile.platform] : undefined;
|
|
428
|
+
await run.step('preflight', async () => {
|
|
429
|
+
const found = await toolchainFindings(config, { env: deps.env, toolchain: deps.toolchain, backend }, true);
|
|
430
|
+
const failed = found.findings.find(f => !f.ok);
|
|
431
|
+
if (failed)
|
|
432
|
+
throw new Unmet(failed, deps.clock.now() - started);
|
|
433
|
+
const project = await projectFindings(config, 'claim', hookEnvironment(deps.env, {}, resourceVariables(config)), true);
|
|
434
|
+
const unmet = project.find(f => !f.ok);
|
|
435
|
+
if (unmet)
|
|
436
|
+
throw new Unmet(unmet, deps.clock.now() - started);
|
|
437
|
+
return [...found.findings, ...project];
|
|
438
|
+
}, findings => findings.map(f => (DETAILED_FINDINGS.has(f.name) ? f.detail : f.name)).join('; '));
|
|
439
|
+
if (mobile && (!backend || (mobile.platform === 'ios' && !deps.sim))) {
|
|
440
|
+
throw mobile.platform === 'android'
|
|
441
|
+
? new UsageError('this machine has no Android emulator backend', 'install the Android SDK and set ANDROID_HOME')
|
|
442
|
+
: new UsageError('this machine has no iOS simulators', 'run up on a Mac with Xcode installed');
|
|
443
|
+
}
|
|
444
|
+
const state = stateDir(deps.env);
|
|
445
|
+
const registry = Registry.open({
|
|
446
|
+
dir: state,
|
|
447
|
+
processes: deps.processes,
|
|
448
|
+
ports: deps.ports,
|
|
449
|
+
devices: deps.devices,
|
|
450
|
+
config: withProjectBlocks(loadConfig(state), projectBlocks(config), config.file),
|
|
451
|
+
clock: deps.clock,
|
|
452
|
+
...(deps.pollMs !== undefined ? { pollMs: deps.pollMs } : {}),
|
|
453
|
+
});
|
|
454
|
+
try {
|
|
455
|
+
const owner = resolveOwner(deps.env, deps.processes, deps.selfPid);
|
|
456
|
+
const outcome = await run.step('claim', async () => {
|
|
457
|
+
const stop = deps.onCancel?.(() => registry.cancelPending());
|
|
458
|
+
try {
|
|
459
|
+
return await registry.claim({
|
|
460
|
+
owner,
|
|
461
|
+
worktree: folder.worktree,
|
|
462
|
+
projectRoot: folder.projectRoot,
|
|
463
|
+
services: config.services.map(s => ({ name: s.name, type: s.type })),
|
|
464
|
+
device: mobile
|
|
465
|
+
? {
|
|
466
|
+
platform: mobile.platform,
|
|
467
|
+
deviceType: mobile.app.device.type,
|
|
468
|
+
runtime: mobile.app.device.runtime,
|
|
469
|
+
strict: mobile.app.device.strict,
|
|
470
|
+
}
|
|
471
|
+
: null,
|
|
472
|
+
browser: config.platform === WEB_PLATFORM && config.web ? { driver: config.web.browser.driver } : null,
|
|
473
|
+
waitMs: options.waitMs,
|
|
474
|
+
action: 'up',
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
finally {
|
|
478
|
+
stop?.();
|
|
479
|
+
}
|
|
480
|
+
}, o => `${o.created ? 'claimed lane' : 'reusing lane'} ${o.lane.id}: ${o.lane.device?.name ?? 'no device'}${o.lane.device ? ` (${o.lane.device.id})` : ''}${o.lane.browser ? `, a ${o.lane.browser.driver} browser` : ''}, ${o.lane.ports.map(p => `${p.service} ${String(p.port)}`).join(', ')}`);
|
|
481
|
+
for (const note of outcome.notes)
|
|
482
|
+
deps.log(`${TOOL} up: ${note}`);
|
|
483
|
+
for (const e of [...outcome.freed, ...outcome.tookOver]) {
|
|
484
|
+
deps.log(`${TOOL} up: ended lane ${e.id} of ${e.owner} in ${e.worktree} (${e.reason}, idle ${formatAge(e.endedAt - e.lastUsedAt)})`);
|
|
485
|
+
}
|
|
486
|
+
const browsers = deps.browser ?? realBrowserTools;
|
|
487
|
+
const ended = [
|
|
488
|
+
...(await stopEndedLanes(deps, state, [...outcome.freed, ...outcome.tookOver])),
|
|
489
|
+
...(await stopEndedBrowsers(browsers, registry, state, deps.clock)),
|
|
490
|
+
...(await tearDownEndedResources(deps, registry, state)),
|
|
491
|
+
];
|
|
492
|
+
for (const stopped of ended) {
|
|
493
|
+
for (const line of [...stopped.notes, ...stopped.problems])
|
|
494
|
+
deps.log(`${TOOL} up: lane ${stopped.lane}: ${line}`);
|
|
495
|
+
}
|
|
496
|
+
const { lane } = outcome;
|
|
497
|
+
const target = mobile ? deviceTarget(deps, mobile, lane, options) : null;
|
|
498
|
+
const dir = laneDir(state, lane.id);
|
|
499
|
+
const previous = readUpRecord(dir);
|
|
500
|
+
writeUpRecord(dir, {
|
|
501
|
+
version: 1,
|
|
502
|
+
lane: lane.id,
|
|
503
|
+
config: config.file,
|
|
504
|
+
platform: config.platform,
|
|
505
|
+
platforms: [...new Set([...(previous?.platforms ?? (previous ? [previous.platform] : [])), config.platform])],
|
|
506
|
+
bundleId: mobile?.app.bundleId ?? previous?.bundleId ?? null,
|
|
507
|
+
launch: mobile?.app.launch ?? previous?.launch ?? null,
|
|
508
|
+
pinned: previous?.pinned ?? false,
|
|
509
|
+
updatedAt: deps.clock.now(),
|
|
510
|
+
});
|
|
511
|
+
pruneEndedLaneFiles(state, new Set([...registry.status().lanes.map(c => c.id), ...registry.pendingTeardowns().map(t => t.lane)]), deps.clock.now(), deps.env);
|
|
512
|
+
const ctx = {
|
|
513
|
+
deps,
|
|
514
|
+
registry,
|
|
515
|
+
ref: { id: lane.id, token: lane.token },
|
|
516
|
+
lane,
|
|
517
|
+
config,
|
|
518
|
+
dir,
|
|
519
|
+
env: laneEnvironment(deps.env, lane, config, dir),
|
|
520
|
+
};
|
|
521
|
+
const device = mobile && target ? { ...ctx, config: mobile, target } : null;
|
|
522
|
+
const beforeResources = { ...ctx, env: laneEnvironment(deps.env, { ...lane, resources: [] }, config, dir) };
|
|
523
|
+
const approval = target?.platform === 'ios' && mobile?.app.scheme
|
|
524
|
+
? await ensureSchemeApproval(target.sim, { udid: target.udid, scheme: mobile.app.scheme, bundleId: mobile.app.bundleId })
|
|
525
|
+
: null;
|
|
526
|
+
const startBoot = (t) => {
|
|
527
|
+
const bootStarted = deps.clock.now();
|
|
528
|
+
const booting = t.platform === 'ios'
|
|
529
|
+
? bootDevice(t.sim, t.udid, approval?.needsReboot ?? false)
|
|
530
|
+
: requireEmulatorBooted(t.adb).then(() => `booted by the lane as ${t.serial}`);
|
|
531
|
+
return booting.then(detail => ({ ok: true, detail, ms: deps.clock.now() - bootStarted }), (error) => ({ ok: false, error }));
|
|
532
|
+
};
|
|
533
|
+
const setup = options.setup && config.hooks.setup !== undefined;
|
|
534
|
+
const bootingWithSetup = setup && target ? startBoot(target) : null;
|
|
535
|
+
try {
|
|
536
|
+
if (setup) {
|
|
537
|
+
await run.step('setup', () => hook(beforeResources, 'setup'), () => 'done');
|
|
538
|
+
}
|
|
539
|
+
await run.step('build preconditions', async () => {
|
|
540
|
+
const project = await projectFindings(config, 'build', beforeResources.env, true);
|
|
541
|
+
const unmet = project.find(f => !f.ok);
|
|
542
|
+
if (unmet)
|
|
543
|
+
throw new Unmet(unmet, deps.clock.now() - started);
|
|
544
|
+
return project;
|
|
545
|
+
}, found => (found.length === 0 ? 'none declared' : found.map(f => f.name).join('; ')));
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
if (bootingWithSetup)
|
|
549
|
+
await bootingWithSetup;
|
|
550
|
+
if (error instanceof Unmet && outcome.created) {
|
|
551
|
+
registry.release(ctx.ref, owner);
|
|
552
|
+
deps.log(`${TOOL} up: released lane ${lane.id}, which this run made, so the refusal leaves nothing behind`);
|
|
553
|
+
}
|
|
554
|
+
throw error;
|
|
555
|
+
}
|
|
556
|
+
const booting = bootingWithSetup ?? (target ? startBoot(target) : null);
|
|
557
|
+
if (config.resources.length > 0) {
|
|
558
|
+
try {
|
|
559
|
+
const made = await run.step('resources', () => createResources(ctx, ctx.lane), describeResources);
|
|
560
|
+
ctx.lane = made.lane;
|
|
561
|
+
ctx.env = laneEnvironment(deps.env, made.lane, config, dir);
|
|
562
|
+
if (device) {
|
|
563
|
+
device.lane = made.lane;
|
|
564
|
+
device.env = ctx.env;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
if (booting)
|
|
569
|
+
await booting;
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
let build = null;
|
|
574
|
+
if (device && booting)
|
|
575
|
+
build = await deviceSteps(device, run, options, booting, approval, setup);
|
|
576
|
+
else {
|
|
577
|
+
await serviceSteps(ctx, run);
|
|
578
|
+
if (config.platform === WEB_PLATFORM)
|
|
579
|
+
await browserSteps(ctx, run, browsers, outcome.replacedDriver !== null);
|
|
580
|
+
}
|
|
581
|
+
const fresh = registry.find(owner, folder.worktree);
|
|
582
|
+
if (!fresh)
|
|
583
|
+
throw new Error(`lane ${lane.id} ended while up was running`);
|
|
584
|
+
registry.touch(ctx.ref, 'up: doctor');
|
|
585
|
+
const doctor = await run.step('doctor', () => diagnose(deps, {
|
|
586
|
+
config,
|
|
587
|
+
configProblem: null,
|
|
588
|
+
lane: fresh,
|
|
589
|
+
ownerState: 'alive',
|
|
590
|
+
folder: folder.worktree,
|
|
591
|
+
installed: readUpRecord(dir)?.installed,
|
|
592
|
+
}), report => (report.ok ? 'ready' : `${String(report.checks.filter(c => !c.ok).length)} check(s) failed`));
|
|
593
|
+
return {
|
|
594
|
+
lane: fresh,
|
|
595
|
+
created: outcome.created,
|
|
596
|
+
platform: config.platform,
|
|
597
|
+
url: webUrl(config, fresh),
|
|
598
|
+
config: config.file,
|
|
599
|
+
logs: dir,
|
|
600
|
+
env: laneVariables(fresh, config, dir),
|
|
601
|
+
build,
|
|
602
|
+
steps: run.steps,
|
|
603
|
+
totalMs: deps.clock.now() - started,
|
|
604
|
+
doctor,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
finally {
|
|
608
|
+
registry.close();
|
|
609
|
+
}
|
|
610
|
+
}
|