@aarwitz/tapp 0.18.0 → 0.18.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/.claude-plugin/plugin.json +2 -2
- package/bin/tapp.js +13 -7
- package/browser/app.css +149 -97
- package/browser/app.js +87 -399
- package/browser/index.html +40 -121
- package/browser/product-contract.js +16 -16
- package/docs/BROWSER-PRODUCT.md +42 -65
- package/docs/PRODUCT-ENGINE.md +1 -1
- package/mcp-server/src/browser-product.js +42 -70
- package/mcp-server/src/index.js +69 -23
- package/package.json +4 -4
- package/scripts/quick-capture.sh +17 -5
- package/scripts/run-flow.sh +3 -1
|
@@ -12,19 +12,8 @@ import { fileURLToPath } from "node:url";
|
|
|
12
12
|
import { customerProductContract } from "../../browser/product-contract.js";
|
|
13
13
|
import { BrowserWorkspaceRegistry } from "./browser-workspaces.js";
|
|
14
14
|
import { selectApplicationTarget } from "./ci-setup.js";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
generateProductPlan,
|
|
18
|
-
initializeProductProject,
|
|
19
|
-
installProductCi,
|
|
20
|
-
prepareProductCi,
|
|
21
|
-
prepareProductTarget,
|
|
22
|
-
promoteProductPlan,
|
|
23
|
-
readProductProject,
|
|
24
|
-
reviewProductPlan,
|
|
25
|
-
runProductGate,
|
|
26
|
-
validateProductPlan,
|
|
27
|
-
} from "./product-operations.js";
|
|
15
|
+
import { initializeProductProject, prepareProductTarget, readProductProject, runProductGate } from "./product-operations.js";
|
|
16
|
+
import { readCaptureProvenance } from "./capture-provenance.js";
|
|
28
17
|
|
|
29
18
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
30
19
|
const assetRoot = path.join(packageRoot, "browser");
|
|
@@ -119,6 +108,29 @@ function capturePath(captureId, relative = "report.html") {
|
|
|
119
108
|
return candidate === root || candidate.startsWith(root + path.sep) ? candidate : null;
|
|
120
109
|
}
|
|
121
110
|
|
|
111
|
+
// Read-only website audits live in the captures directory like every other run; the Studio
|
|
112
|
+
// lists the ones with a summary file. Newest first, bounded.
|
|
113
|
+
function listAudits(limit = 50) {
|
|
114
|
+
const root = captureRoot();
|
|
115
|
+
let names;
|
|
116
|
+
try { names = fs.readdirSync(root); } catch { return []; }
|
|
117
|
+
const audits = [];
|
|
118
|
+
for (const name of names) {
|
|
119
|
+
if (!name.startsWith("web-audit-")) continue;
|
|
120
|
+
const summaryPath = path.join(root, name, "audit.json");
|
|
121
|
+
let summary;
|
|
122
|
+
try { summary = JSON.parse(fs.readFileSync(summaryPath, "utf8")); } catch { continue; }
|
|
123
|
+
const provenance = readCaptureProvenance(path.join(root, name));
|
|
124
|
+
audits.push({
|
|
125
|
+
id: name, createdAt: provenance?.createdAt || fs.statSync(summaryPath).mtime.toISOString(),
|
|
126
|
+
url: summary.url, pagesAudited: summary.pagesAudited || 0, pagesWithUnverifiableWiring: summary.pagesWithUnverifiableWiring || 0,
|
|
127
|
+
findingCounts: summary.findingCounts || {}, issueCount: summary.issueCount ?? (summary.issues || []).length,
|
|
128
|
+
issues: (summary.issues || []).slice(0, 60), checkedFor: summary.checkedFor || [], notChecked: summary.notChecked || [],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return audits.sort((a, b) => b.createdAt.localeCompare(a.createdAt)).slice(0, limit);
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
function openBrowser(url) {
|
|
123
135
|
const invocation = process.platform === "darwin" ? ["open", [url]]
|
|
124
136
|
: process.platform === "win32" ? ["cmd", ["/c", "start", "", url]]
|
|
@@ -418,7 +430,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
418
430
|
return;
|
|
419
431
|
}
|
|
420
432
|
if (request.method === "GET" && url.pathname === "/api/repositories") { json(response, 200, hosted ? { current:hostedRepository(registry.current()), repositories:registry.list().map(hostedRepository) } : { current: registry.current(), repositories: registry.list() }); return; }
|
|
421
|
-
if (request.method === "GET" && url.pathname === "/api/
|
|
433
|
+
if (request.method === "GET" && url.pathname === "/api/audits") { json(response, 200, { audits: hosted ? hostedPayload(listAudits()) : listAudits() }); return; }
|
|
422
434
|
if (request.method === "GET" && url.pathname === "/api/project") { json(response, 200, hosted ? hostedPayload(projectSnapshot(registry)) : projectSnapshot(registry)); return; }
|
|
423
435
|
if (request.method === "GET" && url.pathname === "/api/live-session") { json(response, 200, liveSession || { active:false }); return; }
|
|
424
436
|
if (request.method === "GET" && url.pathname === "/api/live-session/frame") {
|
|
@@ -456,35 +468,6 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
456
468
|
return;
|
|
457
469
|
}
|
|
458
470
|
|
|
459
|
-
const uploadFileMatch = url.pathname.match(/^\/api\/repositories\/uploads\/(upload_[a-f0-9]{20})\/files$/);
|
|
460
|
-
if (request.method === "PUT" && uploadFileMatch) {
|
|
461
|
-
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
462
|
-
let relativePath;
|
|
463
|
-
try { relativePath = decodeURIComponent(String(request.headers["x-tapp-relative-path"] || "")); }
|
|
464
|
-
catch { throw Object.assign(new Error("Repository file path header is invalid"), { statusCode: 400 }); }
|
|
465
|
-
const result = await registry.writeUploadFile(uploadFileMatch[1], relativePath, request, request.headers["content-length"]);
|
|
466
|
-
json(response, 200, result);
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
if (request.method === "POST" && url.pathname === "/api/repositories/uploads") {
|
|
470
|
-
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
471
|
-
json(response, 201, registry.createUpload(await readJsonBody(request)));
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
const uploadCompleteMatch = url.pathname.match(/^\/api\/repositories\/uploads\/(upload_[a-f0-9]{20})\/complete$/);
|
|
475
|
-
if (request.method === "POST" && uploadCompleteMatch) {
|
|
476
|
-
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
477
|
-
if (liveSession?.active) throw Object.assign(new Error("End the active live session before changing repositories"), { statusCode:409 });
|
|
478
|
-
const repository = registry.finishUpload(uploadCompleteMatch[1]);
|
|
479
|
-
json(response, 200, { repository: hosted ? hostedRepository(repository) : repository });
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
const uploadAbortMatch = url.pathname.match(/^\/api\/repositories\/uploads\/(upload_[a-f0-9]{20})$/);
|
|
483
|
-
if (request.method === "DELETE" && uploadAbortMatch) {
|
|
484
|
-
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
485
|
-
json(response, 200, { aborted: registry.abortUpload(uploadAbortMatch[1]) });
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
471
|
if (request.method === "POST" && url.pathname === "/api/repositories/select") {
|
|
489
472
|
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
490
473
|
if (activeMutation) throw Object.assign(new Error(`Operation '${activeMutation.operation}' is still running`), { statusCode: 409 });
|
|
@@ -499,14 +482,26 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
499
482
|
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
500
483
|
const body = await readJsonBody(request);
|
|
501
484
|
const operation = url.pathname.slice("/api/operations/".length);
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
485
|
+
// A website audit needs no repository: it is read-only against a URL and writes a capture.
|
|
486
|
+
if (operation === "audit") {
|
|
487
|
+
let target;
|
|
488
|
+
try { target = new URL(String(body.url || "")); } catch { throw Object.assign(new Error("Audit needs a valid http(s) URL"), { statusCode: 400 }); }
|
|
489
|
+
if (!/^https?:$/.test(target.protocol)) throw Object.assign(new Error("Audit needs a valid http(s) URL"), { statusCode: 400 });
|
|
490
|
+
const pages = Math.max(1, Math.min(20, Number(body.pages) || 6));
|
|
491
|
+
const job = startJob(operation, async (progress) => {
|
|
492
|
+
const { auditWebSite } = await import("./web-audit.js");
|
|
493
|
+
progress({ phase: "runtime", text: `Opening ${target.href} read-only (up to ${pages} pages, nothing will be clicked)` });
|
|
494
|
+
const summary = await auditWebSite({
|
|
495
|
+
url: target.href, pages, delayMs: 750, capturesDir: captureRoot(),
|
|
496
|
+
onPage: (page, n) => progress({ phase: "explore", text: `Audited ${page.url} — ${page.findings.length} finding(s)`, current: n, total: pages }),
|
|
497
|
+
});
|
|
498
|
+
return hosted ? hostedPayload(summary) : summary;
|
|
499
|
+
}, null);
|
|
505
500
|
json(response, 202, { job: publicJob(job, { hosted }) });
|
|
506
501
|
return;
|
|
507
502
|
}
|
|
508
503
|
const root = registry.currentRoot();
|
|
509
|
-
if (!root) throw Object.assign(new Error("
|
|
504
|
+
if (!root) throw Object.assign(new Error("Open a repository first: tapp app /path/to/repo"), { statusCode: 409 });
|
|
510
505
|
const repositoryId = registry.current().id;
|
|
511
506
|
const job = startJob(operation, async (progress) => {
|
|
512
507
|
const engine = await import("./index.js");
|
|
@@ -608,21 +603,6 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
608
603
|
onStatus: (text) => progress({ phase: "runtime", text }),
|
|
609
604
|
});
|
|
610
605
|
}
|
|
611
|
-
if (operation === "review") return reviewProductPlan({ projectDir: root, approve: body.approve || [], reject: body.reject || [], defer: body.defer || [] });
|
|
612
|
-
if (operation === "generate") return generateProductPlan({ projectDir: root });
|
|
613
|
-
if (operation === "validate") {
|
|
614
|
-
const selected = selectedTarget(root, body);
|
|
615
|
-
const prepared = await prepareProductTarget({ projectDir: root, platform: selected.platform, target: selected.id, buildIos: engine.buildAppForSim, installIos: engine.installAppOnBootedSim, buildAndroid: engine.buildAndroidApp, onProgress: progress });
|
|
616
|
-
return validateProductPlan({
|
|
617
|
-
projectDir: root, items: body.items || [], platform: selected.platform, target: selected.id,
|
|
618
|
-
url: prepared.runtime.url || "", bundleId: prepared.runtime.bundleId || "", appId: prepared.runtime.appId || "", apkPath: prepared.runtime.apkPath || "", serial: runtime.serial,
|
|
619
|
-
timeout: runtime.timeout, testEmail: runtime.testEmail, testPassword: runtime.testPassword,
|
|
620
|
-
startWebTarget: engine.startManagedWebTarget, stopWebTarget: engine.stopManagedWebTarget, onProgress: progress,
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
if (operation === "promote") return promoteProductPlan({ projectDir: root, items: body.items || [] });
|
|
624
|
-
if (operation === "ci-preview") return prepareProductCi({ projectDir: root, actionRef: body.actionRef, defaultBranch: body.defaultBranch || "main" });
|
|
625
|
-
if (operation === "ci-install") return installProductCi({ projectDir: root, actionRef: body.actionRef, defaultBranch: body.defaultBranch || "main", replace: body.replace === true, allowUnresolved: body.allowUnresolved === true });
|
|
626
606
|
if (operation === "gate") {
|
|
627
607
|
const selected = selectedTarget(root, body);
|
|
628
608
|
const prepared = await prepareProductTarget({ projectDir: root, platform: selected.platform, target: selected.id, buildIos: engine.buildAppForSim, buildAndroid: engine.buildAndroidApp, onProgress: progress });
|
|
@@ -632,14 +612,6 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
632
612
|
actions: runtime.maxActions, timeout: runtime.timeout, baseline: body.baseline || "", testEmail: runtime.testEmail, testPassword: runtime.testPassword, onProgress: progress,
|
|
633
613
|
});
|
|
634
614
|
}
|
|
635
|
-
if (operation === "baseline") {
|
|
636
|
-
const project = readProductProject({ projectDir: root });
|
|
637
|
-
const run = project.evidence.find((item) => item.id === body.runId);
|
|
638
|
-
if (!run?.reportPath) throw new Error("Select a completed local gate run before creating a baseline");
|
|
639
|
-
const platform = run.report?.platform || String(body.platform || "").toLowerCase();
|
|
640
|
-
const target = run.report?.targetKey || body.target || "";
|
|
641
|
-
return createProductBaseline({ projectDir: root, reportPath: run.reportPath, platform, target, replace: body.replace === true });
|
|
642
|
-
}
|
|
643
615
|
throw new Error(`Unsupported product operation '${operation}'`);
|
|
644
616
|
}, repositoryId);
|
|
645
617
|
json(response, 202, { job: publicJob(job, { hosted }) });
|
package/mcp-server/src/index.js
CHANGED
|
@@ -251,13 +251,53 @@ async function listSimulators() {
|
|
|
251
251
|
return { simulators: sims, booted: sims.filter((s) => s.booted) };
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
// Which simulator a run drives. Public issue #31: with two simulators booted, `--device` was
|
|
255
|
+
// honoured for web only and every iOS path took whichever simulator simctl listed first — a
|
|
256
|
+
// production build instead of the sandbox one, then another agent session's simulator. A
|
|
257
|
+
// device is a name or UDID (`TAPP_UDID` is the environment default); with several booted and
|
|
258
|
+
// none chosen the answer is the list, not a guess.
|
|
259
|
+
export function selectSimulator(sims, device = "") {
|
|
260
|
+
const wanted = String(device || process.env.TAPP_UDID || "").trim();
|
|
261
|
+
const all = sims.simulators || [];
|
|
262
|
+
const booted = sims.booted || all.filter((s) => s.booted);
|
|
263
|
+
const describe = (list) => list.map((s) => `${s.name} (${s.udid})`).join(", ");
|
|
264
|
+
if (wanted) {
|
|
265
|
+
const lower = wanted.toLowerCase();
|
|
266
|
+
const match = all.find((s) => s.udid.toLowerCase() === lower)
|
|
267
|
+
|| all.find((s) => s.name.toLowerCase() === lower)
|
|
268
|
+
|| (() => { const p = booted.filter((s) => s.name.toLowerCase().startsWith(lower)); return p.length === 1 ? p[0] : null; })();
|
|
269
|
+
if (!match) return { error: `No simulator matches "${wanted}". Booted: ${booted.length ? describe(booted) : "none"}.` };
|
|
270
|
+
if (!match.booted) return { notBooted: match };
|
|
271
|
+
return { booted: match };
|
|
272
|
+
}
|
|
273
|
+
if (booted.length === 1) return { booted: booted[0] };
|
|
274
|
+
if (booted.length === 0) return { none: true };
|
|
275
|
+
return { error: `simulator-selection-required: ${booted.length} simulators are booted — ${describe(booted)}. Pass device (a name or UDID) or set TAPP_UDID so the run does not drive someone else's simulator.`, ambiguous: booted };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// The simulator the current engine process has chosen. Every simctl call and every spawned
|
|
279
|
+
// harness script must address it by UDID: the `booted` alias means "whichever is first".
|
|
280
|
+
let selectedSimUdid = null;
|
|
281
|
+
function simTarget() { return selectedSimUdid || "booted"; }
|
|
282
|
+
function simEnv() { return selectedSimUdid ? { TAPP_UDID: selectedSimUdid } : {}; }
|
|
283
|
+
|
|
254
284
|
// Pre-flight for every iOS entry point: the #1 first-session failure is "no simulator
|
|
255
285
|
// booted", and the harness's raw failure text is unactionable. Long-running tools
|
|
256
286
|
// (run_qa) auto-boot the first available iPhone; fast tools return an instructive error
|
|
257
287
|
// the agent can act on instead of a shrug.
|
|
258
|
-
export async function ensureBootedSim({ autoBoot = false } = {}) {
|
|
288
|
+
export async function ensureBootedSim({ autoBoot = false, device = "" } = {}) {
|
|
259
289
|
const sims = await listSimulators();
|
|
260
|
-
|
|
290
|
+
const choice = sims.error ? { none: true } : selectSimulator(sims, device);
|
|
291
|
+
if (choice.booted) { selectedSimUdid = choice.booted.udid; return { booted: choice.booted }; }
|
|
292
|
+
if (choice.error) return { error: choice.error };
|
|
293
|
+
if (choice.notBooted) {
|
|
294
|
+
if (!autoBoot) return { error: `${choice.notBooted.name} (${choice.notBooted.udid}) is not booted. Boot it with tapp_build (action boot) and retry.` };
|
|
295
|
+
await runCommand("xcrun", ["simctl", "boot", choice.notBooted.udid], { timeoutMs: 2 * 60 * 1000 });
|
|
296
|
+
const st = await runCommand("xcrun", ["simctl", "bootstatus", choice.notBooted.udid, "-b"], { timeoutMs: 3 * 60 * 1000 });
|
|
297
|
+
if (st.code !== 0) return { error: `Boot of ${choice.notBooted.name} failed — boot it manually with tapp_build (action boot).` };
|
|
298
|
+
selectedSimUdid = choice.notBooted.udid;
|
|
299
|
+
return { booted: { ...choice.notBooted, booted: true }, autoBooted: true };
|
|
300
|
+
}
|
|
261
301
|
// A failed listing is NOT "no simulators" — surface the real reason (was silently
|
|
262
302
|
// misdiagnosed as "No iOS simulators exist" when simctl errored in odd environments).
|
|
263
303
|
if (sims.error) {
|
|
@@ -277,6 +317,7 @@ export async function ensureBootedSim({ autoBoot = false } = {}) {
|
|
|
277
317
|
await runCommand("xcrun", ["simctl", "boot", candidate.udid], { timeoutMs: 2 * 60 * 1000 });
|
|
278
318
|
const st = await runCommand("xcrun", ["simctl", "bootstatus", candidate.udid, "-b"], { timeoutMs: 3 * 60 * 1000 });
|
|
279
319
|
if (st.code !== 0) return { error: `Auto-boot of ${candidate.name} failed — boot one manually with tapp_build (action boot).` };
|
|
320
|
+
selectedSimUdid = candidate.udid;
|
|
280
321
|
return { booted: candidate, autoBooted: true };
|
|
281
322
|
}
|
|
282
323
|
|
|
@@ -284,7 +325,7 @@ export async function ensureBootedSim({ autoBoot = false } = {}) {
|
|
|
284
325
|
// never installed). Without this pre-flight the harness reports a misleading "crashed at launch"
|
|
285
326
|
// and sessions die with an unactionable error — check cheaply up front instead.
|
|
286
327
|
async function appInstalledOnBootedSim(bundleId) {
|
|
287
|
-
const r = await runCommand("xcrun", ["simctl", "get_app_container",
|
|
328
|
+
const r = await runCommand("xcrun", ["simctl", "get_app_container", simTarget(), bundleId, "app"], { timeoutMs: 15_000 });
|
|
288
329
|
return r.code === 0;
|
|
289
330
|
}
|
|
290
331
|
|
|
@@ -302,7 +343,7 @@ function notInstalledError(bundleId, booted) {
|
|
|
302
343
|
// and the tapp_build MCP tool.
|
|
303
344
|
|
|
304
345
|
export async function listInstalledUserApps() {
|
|
305
|
-
const r = await runCommand("xcrun", ["simctl", "listapps",
|
|
346
|
+
const r = await runCommand("xcrun", ["simctl", "listapps", simTarget()], { timeoutMs: 30_000, rawStdout: true });
|
|
306
347
|
if (r.code !== 0) return { error: "Could not list installed apps", details: { stderr: r.stderr } };
|
|
307
348
|
// simctl emits an old-style plist; plutil converts it.
|
|
308
349
|
const tmp = path.join(os.tmpdir(), `tapp-apps-${Date.now().toString(36)}.plist`);
|
|
@@ -510,16 +551,16 @@ export async function installAppOnBootedSim(appPath, { cleanInstall = true, onSt
|
|
|
510
551
|
const bundleId = (bid.stdout || "").trim();
|
|
511
552
|
if (!bundleId) return { error: `Could not read CFBundleIdentifier from ${appPath}/Info.plist — is this a simulator .app build?` };
|
|
512
553
|
if (cleanInstall) {
|
|
513
|
-
const existing = await runCommand("xcrun", ["simctl", "get_app_container",
|
|
554
|
+
const existing = await runCommand("xcrun", ["simctl", "get_app_container", simTarget(), bundleId, "app"], { timeoutMs: 15_000 });
|
|
514
555
|
if (existing.code === 0 && (existing.stdout || "").trim()) onStatus(replacingInstalledBuildNotice(bundleId));
|
|
515
556
|
}
|
|
516
557
|
if (cleanInstall) {
|
|
517
558
|
// Clean install: stale keychain items from a previous install leave apps half-signed-in
|
|
518
559
|
// (Firebase Auth's "error accessing the keychain") — uninstall first for a fresh state.
|
|
519
|
-
await runCommand("xcrun", ["simctl", "terminate",
|
|
520
|
-
await runCommand("xcrun", ["simctl", "uninstall",
|
|
560
|
+
await runCommand("xcrun", ["simctl", "terminate", simTarget(), bundleId], { timeoutMs: 30_000 });
|
|
561
|
+
await runCommand("xcrun", ["simctl", "uninstall", simTarget(), bundleId], { timeoutMs: 60_000 });
|
|
521
562
|
}
|
|
522
|
-
const inst = await runCommand("xcrun", ["simctl", "install",
|
|
563
|
+
const inst = await runCommand("xcrun", ["simctl", "install", simTarget(), appPath], { timeoutMs: 3 * 60 * 1000 });
|
|
523
564
|
if (inst.code !== 0) return { error: `Install failed: ${(inst.stderr || "").trim().slice(0, 300)}` };
|
|
524
565
|
return { bundleId };
|
|
525
566
|
}
|
|
@@ -762,11 +803,11 @@ function focusMetadata(result) {
|
|
|
762
803
|
return metadata;
|
|
763
804
|
}
|
|
764
805
|
|
|
765
|
-
async function startSession(bundleId, extraEnv = {}) {
|
|
806
|
+
async function startSession(bundleId, extraEnv = {}, { device = "" } = {}) {
|
|
766
807
|
if (activeSession && !activeSession.ended) {
|
|
767
808
|
return { error: "A session is already active; call tapp_session (action end) first.", screen: treeSnapshot() };
|
|
768
809
|
}
|
|
769
|
-
const sim = await ensureBootedSim();
|
|
810
|
+
const sim = await ensureBootedSim({ device });
|
|
770
811
|
if (sim.error) return { error: sim.error };
|
|
771
812
|
if (!(await appInstalledOnBootedSim(bundleId))) return { error: notInstalledError(bundleId, sim.booted) };
|
|
772
813
|
const token = Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
|
|
@@ -777,7 +818,7 @@ async function startSession(bundleId, extraEnv = {}) {
|
|
|
777
818
|
const captureScript = path.join(scriptsDir, "quick-capture.sh");
|
|
778
819
|
const proc = spawn("bash", [captureScript, "session", bundleId], {
|
|
779
820
|
cwd: repoRoot,
|
|
780
|
-
env: { ...process.env, ...extraEnv, OCQA_SESSION_CMD_PATH: cmdPath, OCQA_SESSION_RESULT_PATH: resultPath, OCQA_SESSION_TIMEOUT: "7200" },
|
|
821
|
+
env: { ...process.env, ...simEnv(), ...extraEnv, OCQA_SESSION_CMD_PATH: cmdPath, OCQA_SESSION_RESULT_PATH: resultPath, OCQA_SESSION_TIMEOUT: "7200" },
|
|
781
822
|
});
|
|
782
823
|
activeSession = {
|
|
783
824
|
platform:"ios", proc, bundleId, seq: 0, cmdPath, resultPath, latestTree: null, treeVersion: 0, buffer: "", ready: false, ended: false,
|
|
@@ -1403,8 +1444,8 @@ export async function captureInteractiveSessionFrame(maxWidth = 900) {
|
|
|
1403
1444
|
// Fast "just show me a screen": launch the app fresh (optionally bypassing login), grab a screenshot
|
|
1404
1445
|
// while it's on screen, return the tree too, then close it. No exploration. Uses the session
|
|
1405
1446
|
// machinery only to keep the app alive long enough to photograph it.
|
|
1406
|
-
export async function openApp(bundleId, extraEnv, maxWidth) {
|
|
1407
|
-
const start = await startSession(bundleId, extraEnv);
|
|
1447
|
+
export async function openApp(bundleId, extraEnv, maxWidth, { device = "" } = {}) {
|
|
1448
|
+
const start = await startSession(bundleId, extraEnv, { device });
|
|
1408
1449
|
if (start.error) return { error: start.error };
|
|
1409
1450
|
const img = await captureScreenshotImage(maxWidth);
|
|
1410
1451
|
const result = { screenTitle: start.screenTitle ?? null, elements: start.elements ?? [], img };
|
|
@@ -1419,7 +1460,7 @@ async function runExploreStreaming(bundleId, actions, timeout, env, onProgress)
|
|
|
1419
1460
|
const captureScript = path.join(scriptsDir, "quick-capture.sh");
|
|
1420
1461
|
const cmdArgs = [captureScript, "explore", bundleId, "--actions", String(actions), "--timeout", String(timeout)];
|
|
1421
1462
|
const before = new Set(listCaptureRuns(80).map((r) => r.id));
|
|
1422
|
-
const proc = spawn("bash", cmdArgs, { cwd: repoRoot, env: { ...process.env, ...env } });
|
|
1463
|
+
const proc = spawn("bash", cmdArgs, { cwd: repoRoot, env: { ...process.env, ...simEnv(), ...env } });
|
|
1423
1464
|
proc.stdout.on("data", () => {});
|
|
1424
1465
|
let captureStderr = "";
|
|
1425
1466
|
proc.stderr.on("data", (chunk) => {
|
|
@@ -1485,7 +1526,11 @@ async function runExploreStreaming(bundleId, actions, timeout, env, onProgress)
|
|
|
1485
1526
|
if (which === "closed") break;
|
|
1486
1527
|
if (Date.now() > hardDeadline) { try { proc.kill("SIGTERM"); } catch {} timedOut = true; break; }
|
|
1487
1528
|
}
|
|
1488
|
-
|
|
1529
|
+
// 'close' needs every stdio pipe released; a grandchild (the simulator recorder) that survives
|
|
1530
|
+
// the script holds them open, and waiting on it unconditionally turned a finished exploration
|
|
1531
|
+
// into a hang. Give the script a bounded grace period, then carry on with what it wrote.
|
|
1532
|
+
const closedInTime = await Promise.race([closed.then(() => true), sleep(20_000).then(() => false)]);
|
|
1533
|
+
if (!closedInTime) { try { proc.kill("SIGKILL"); } catch {} }
|
|
1489
1534
|
const created = listCaptureRuns(80).find((r) => !before.has(r.id))
|
|
1490
1535
|
|| (captureDir ? { id: path.basename(captureDir), path: captureDir, relativePath: path.relative(repoRoot, captureDir) } : null);
|
|
1491
1536
|
return { created, timedOut, captureStderr };
|
|
@@ -1509,7 +1554,7 @@ export async function captureScreenshotImage(maxWidth) {
|
|
|
1509
1554
|
const stamp = Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
|
|
1510
1555
|
const png = `/tmp/tapp-shot-${stamp}.png`;
|
|
1511
1556
|
const jpg = `/tmp/tapp-shot-${stamp}.jpg`;
|
|
1512
|
-
const r = await runCommand("xcrun", ["simctl", "io",
|
|
1557
|
+
const r = await runCommand("xcrun", ["simctl", "io", simTarget(), "screenshot", png], { timeoutMs: 30_000 });
|
|
1513
1558
|
if (!fs.existsSync(png)) return { error: "Screenshot failed (is a simulator booted?)", stderr: r.stderr };
|
|
1514
1559
|
await runCommand("sips", ["-Z", String(maxWidth), "-s", "format", "jpeg", "-s", "formatOptions", "60", png, "--out", jpg], { timeoutMs: 30_000 });
|
|
1515
1560
|
const file = fs.existsSync(jpg) ? jpg : png;
|
|
@@ -2025,7 +2070,7 @@ export async function runQaAndroid({ appId, apkPath, serial, maxActions, timeout
|
|
|
2025
2070
|
return { structured, text };
|
|
2026
2071
|
}
|
|
2027
2072
|
|
|
2028
|
-
export async function runQaIos({ bundleId, maxActions, timeout, args = {}, surface = "mcp", onProgress = () => {} }) {
|
|
2073
|
+
export async function runQaIos({ bundleId, maxActions, timeout, args = {}, device = "", surface = "mcp", onProgress = () => {} }) {
|
|
2029
2074
|
const { storagePreflight } = await import("./environment-preflight.js");
|
|
2030
2075
|
const storage = storagePreflight(capturesDir);
|
|
2031
2076
|
if (!storage.ok) return { error: storage.message, details: { environment: "storage", storage } };
|
|
@@ -2033,7 +2078,7 @@ export async function runQaIos({ bundleId, maxActions, timeout, args = {}, surfa
|
|
|
2033
2078
|
if (!fs.existsSync(captureScript)) return { error: "Capture script not found", details: { captureScript } };
|
|
2034
2079
|
|
|
2035
2080
|
// run_qa runs for minutes anyway — auto-boot rather than bounce the user.
|
|
2036
|
-
const sim = await ensureBootedSim({ autoBoot: true });
|
|
2081
|
+
const sim = await ensureBootedSim({ autoBoot: true, device });
|
|
2037
2082
|
if (sim.error) return { error: sim.error };
|
|
2038
2083
|
if (!(await appInstalledOnBootedSim(bundleId))) return { error: notInstalledError(bundleId, sim.booted) };
|
|
2039
2084
|
|
|
@@ -2668,7 +2713,7 @@ export const TOOLS = [
|
|
|
2668
2713
|
platform: { ...PLATFORM, description: "goal: optional when no session is active" },
|
|
2669
2714
|
clearData: { type: "boolean", default: true, description: "Android: clear app data before launch" },
|
|
2670
2715
|
watch: { type: "boolean", default: false, description: "Web: show Tapp's controlled Chromium window and a cursor/HUD" },
|
|
2671
|
-
device: { type: "string", description: "Web: Playwright device profile, e.g. \"iPhone 13\"" },
|
|
2716
|
+
device: { type: "string", description: "Web: Playwright device profile, e.g. \"iPhone 13\". iOS: simulator name or UDID — required when more than one simulator is booted (TAPP_UDID is the environment default)" },
|
|
2672
2717
|
viewport: { type: "string", description: "Web: viewport WIDTHxHEIGHT, e.g. \"390x844\"" },
|
|
2673
2718
|
maxActions: { type: "integer", minimum: 1, maximum: 1000, default: 60, description: "Exploration action budget" },
|
|
2674
2719
|
timeout: { type: "integer", minimum: 30, maximum: 3600, default: 600, description: "Max wall-clock seconds" },
|
|
@@ -2732,7 +2777,7 @@ export const TOOLS = [
|
|
|
2732
2777
|
testEmail: { type: "string", description: "Value for $TEST_EMAIL" },
|
|
2733
2778
|
testPassword: { type: "string", description: "Value for $TEST_PASSWORD" },
|
|
2734
2779
|
actor: { type: "string", description: "Configured actor; resolves $TEST_EMAIL/$TEST_PASSWORD from its env-var bindings" },
|
|
2735
|
-
device: { type: "string", description: "Web: Playwright device profile" },
|
|
2780
|
+
device: { type: "string", description: "Web: Playwright device profile. iOS: simulator name or UDID — required when more than one simulator is booted" },
|
|
2736
2781
|
viewport: { type: "string", description: "Web: viewport WIDTHxHEIGHT" },
|
|
2737
2782
|
},
|
|
2738
2783
|
},
|
|
@@ -2913,7 +2958,7 @@ export const TOOLS = [
|
|
|
2913
2958
|
action: { type: "string", enum: ["start", "login", "tap", "type", "swipe", "back", "wait", "tree", "screenshot", "save_flow", "draft_flow", "end"] },
|
|
2914
2959
|
...TARGET_PROPS,
|
|
2915
2960
|
target: { type: "string", description: "start: managed-web target name/path when the workspace has several" },
|
|
2916
|
-
device: { type: "string", description: "start
|
|
2961
|
+
device: { type: "string", description: "start: web Playwright device profile, or iOS simulator name/UDID (required when more than one simulator is booted)" },
|
|
2917
2962
|
viewport: { type: "string", description: "start (web): viewport WIDTHxHEIGHT" },
|
|
2918
2963
|
clearData: { type: "boolean", default: true, description: "start (Android): clear app data" },
|
|
2919
2964
|
testEmail: { type: "string" }, testPassword: { type: "string" },
|
|
@@ -3392,6 +3437,7 @@ async function handleTool(name, args = {}) {
|
|
|
3392
3437
|
maxActions: args.maxActions,
|
|
3393
3438
|
timeout: args.timeout,
|
|
3394
3439
|
args,
|
|
3440
|
+
device: isNonEmptyString(args.device) ? args.device.trim() : "",
|
|
3395
3441
|
onProgress: (p) => {
|
|
3396
3442
|
lastProgress = p;
|
|
3397
3443
|
iosProgress(p);
|
|
@@ -4138,7 +4184,7 @@ async function handleTool(name, args = {}) {
|
|
|
4138
4184
|
}
|
|
4139
4185
|
}
|
|
4140
4186
|
const maxWidth = Math.max(200, Math.min(1400, asInteger(args.maxWidth, 700)));
|
|
4141
|
-
const r = await openApp(String(args.appBundleId).trim(), explorationEnvFromArgs(args), maxWidth);
|
|
4187
|
+
const r = await openApp(String(args.appBundleId).trim(), explorationEnvFromArgs(args), maxWidth, { device: isNonEmptyString(args.device) ? args.device.trim() : "" });
|
|
4142
4188
|
if (r.error) return errorResult(r.error, r.details || {});
|
|
4143
4189
|
const content = [];
|
|
4144
4190
|
content.push({ type: "text", text: `🚀 Launched \`${String(args.appBundleId).trim()}\`\n\n` + formatScreen(r.screenTitle, r.elements) });
|
|
@@ -4250,7 +4296,7 @@ async function handleTool(name, args = {}) {
|
|
|
4250
4296
|
if (!isInsideDir(workspaceRoot, focusProjectDir) || !fs.statSync(focusProjectDir).isDirectory()) return errorResult("projectDir must be an existing directory inside the workspace");
|
|
4251
4297
|
}
|
|
4252
4298
|
const r = ios
|
|
4253
|
-
? await startSession(target, explorationEnvFromArgs(args))
|
|
4299
|
+
? await startSession(target, explorationEnvFromArgs(args), { device: isNonEmptyString(args.device) ? args.device.trim() : "" })
|
|
4254
4300
|
: android
|
|
4255
4301
|
? await startAndroidSession(target, { serial: args.androidSerial, apkPath: args.apkPath, clearData: args.clearData !== false, testEmail: args.testEmail, testPassword: args.testPassword })
|
|
4256
4302
|
: web
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"mcpName": "io.github.aarwitz/tapp",
|
|
5
5
|
"description": "Let coding agents verify UI changes on real iOS, Android, and web surfaces, then enforce reviewed proof in deterministic CI.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"typescript": "^5.9.2"
|
|
58
58
|
},
|
|
59
59
|
"optionalDependencies": {
|
|
60
|
-
"playwright": "1.
|
|
60
|
+
"playwright": "1.64.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
63
|
+
"node": ">=20"
|
|
64
64
|
},
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"mobile"
|
|
97
97
|
],
|
|
98
98
|
"scripts": {
|
|
99
|
-
"test": "node --test tests/report.test.js tests/regression.test.js tests/engine.test.js tests/project-config.test.js tests/application-model.test.js tests/ui-map.test.js tests/focused-navigation.test.js tests/task-runtime.test.js tests/release-contract.test.js tests/pr-selection.test.js tests/flow-runtime.test.js tests/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-audit.test.js tests/capture-provenance.test.js tests/ios-crash-attribution.test.js tests/web-flow.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-flow.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/browser-product.test.js tests/browser-onboarding.test.js tests/managed-operation.test.js tests/
|
|
99
|
+
"test": "node --test tests/report.test.js tests/regression.test.js tests/engine.test.js tests/project-config.test.js tests/application-model.test.js tests/ui-map.test.js tests/focused-navigation.test.js tests/task-runtime.test.js tests/release-contract.test.js tests/pr-selection.test.js tests/flow-runtime.test.js tests/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-audit.test.js tests/capture-provenance.test.js tests/ios-crash-attribution.test.js tests/ios-simulator-selection.test.js tests/ios-recording-stop.test.js tests/web-flow.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-flow.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/browser-product.test.js tests/browser-onboarding.test.js tests/managed-operation.test.js tests/ci-setup.test.js tests/ci-install.test.js tests/cli.test.js tests/mcp-workspace.test.js tests/action.test.js tests/package-surface.test.js tests/agent-surface.test.js tests/presentation-contract.test.js tests/landing-brand.test.js tests/ci-gate.test.js tests/ci-report.test.js tests/desktop-protocol.test.js tests/ios-flow-protocol.test.js tests/feedback-triage-0919.test.js vscode-extension/test/bridge.test.js",
|
|
100
100
|
"test:browser-journey": "node --test tests/browser-journey.test.js",
|
|
101
101
|
"test:browser-native": "TAPP_RUN_NATIVE_BROWSER=1 node --test tests/browser-native-journey.test.js"
|
|
102
102
|
}
|
package/scripts/quick-capture.sh
CHANGED
|
@@ -35,7 +35,9 @@ fi
|
|
|
35
35
|
HARNESS_PROJECT="$PROJECT_ROOT/Harness/OCQAHarness.xcodeproj"
|
|
36
36
|
DEFAULT_BUNDLE="io.github.aarwitz.tapp.demoapp"
|
|
37
37
|
|
|
38
|
+
# TAPP_UDID names the simulator the caller chose (issue #31); without it, the first booted one.
|
|
38
39
|
get_booted_sim() {
|
|
40
|
+
if [[ -n "${TAPP_UDID:-}" ]]; then echo "$TAPP_UDID"; return; fi
|
|
39
41
|
xcrun simctl list devices booted -j 2>/dev/null \
|
|
40
42
|
| python3 -c "
|
|
41
43
|
import sys, json
|
|
@@ -49,13 +51,14 @@ for runtime, devices in d.get('devices', {}).items():
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
get_sim_name() {
|
|
52
|
-
xcrun simctl list devices
|
|
53
|
-
| python3 -c "
|
|
54
|
-
import sys, json
|
|
54
|
+
xcrun simctl list devices -j 2>/dev/null \
|
|
55
|
+
| TAPP_UDID="${TAPP_UDID:-}" python3 -c "
|
|
56
|
+
import os, sys, json
|
|
55
57
|
d = json.load(sys.stdin)
|
|
58
|
+
want = os.environ.get('TAPP_UDID', '')
|
|
56
59
|
for runtime, devices in d.get('devices', {}).items():
|
|
57
60
|
for dev in devices:
|
|
58
|
-
if dev.get('state') == 'Booted':
|
|
61
|
+
if (want and dev.get('udid') == want) or (not want and dev.get('state') == 'Booted'):
|
|
59
62
|
print(dev['name'])
|
|
60
63
|
sys.exit(0)
|
|
61
64
|
" 2>/dev/null
|
|
@@ -376,9 +379,18 @@ OCQA_COMPLETE:{\"actions\":0,\"states\":0,\"issues\":1,\"screens\":\"\",\"outcom
|
|
|
376
379
|
wait "$HARNESS_PID" 2>/dev/null || true
|
|
377
380
|
OUTPUT="$(cat "$local_output_file" 2>/dev/null || true)"
|
|
378
381
|
|
|
379
|
-
# Stop recording
|
|
382
|
+
# Stop recording. simctl's recorder finalizes the file on SIGINT, but on hosted runners it
|
|
383
|
+
# sometimes ignores the signal; an unbounded wait here held the whole run (and its caller)
|
|
384
|
+
# until the test budget expired, with the harness long finished. Escalate on a deadline.
|
|
380
385
|
if [[ -n "$RECORD_PID" ]]; then
|
|
381
386
|
kill -INT "$RECORD_PID" 2>/dev/null || true
|
|
387
|
+
for _ in $(seq 1 40); do kill -0 "$RECORD_PID" 2>/dev/null || break; sleep 0.5; done
|
|
388
|
+
if kill -0 "$RECORD_PID" 2>/dev/null; then
|
|
389
|
+
echo "WARNING: simulator recorder did not stop on SIGINT; terminating it (the recording may be truncated)" >&2
|
|
390
|
+
kill -TERM "$RECORD_PID" 2>/dev/null || true
|
|
391
|
+
for _ in $(seq 1 10); do kill -0 "$RECORD_PID" 2>/dev/null || break; sleep 0.5; done
|
|
392
|
+
kill -KILL "$RECORD_PID" 2>/dev/null || true
|
|
393
|
+
fi
|
|
382
394
|
wait "$RECORD_PID" 2>/dev/null || true
|
|
383
395
|
fi
|
|
384
396
|
rm -f "$RECORDING_STARTED_PATH"
|
package/scripts/run-flow.sh
CHANGED
|
@@ -22,7 +22,9 @@ APP="${2:-}"
|
|
|
22
22
|
[ -z "$APP" ] && APP="$(python3 -c "import sys,json; print(json.loads(sys.argv[1]).get('app','') or '')" "$FLOW_JSON" 2>/dev/null)"
|
|
23
23
|
[ -z "$APP" ] && { echo "❌ No bundleId (pass one or set 'app:' in the flow)"; exit 2; }
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
# TAPP_UDID names the simulator the caller chose (issue #31); without it, the first booted one.
|
|
26
|
+
UDID="${TAPP_UDID:-}"
|
|
27
|
+
[ -z "$UDID" ] && UDID="$(xcrun simctl list devices booted -j 2>/dev/null | python3 -c 'import sys,json; d=json.load(sys.stdin); print(next((x["udid"] for v in d["devices"].values() for x in v if x.get("state")=="Booted"), ""))')"
|
|
26
28
|
[ -z "$UDID" ] && { echo "❌ No booted simulator."; exit 2; }
|
|
27
29
|
# CLI, MCP, sessions, and doctor share the same source/toolchain-validated descriptor.
|
|
28
30
|
XCTR="$(bash "$ROOT/scripts/quick-capture.sh" prepare-harness)" || exit 2
|