@aarwitz/tapp 0.33.0 → 0.35.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/.claude-plugin/plugin.json +2 -2
- package/MacHarness/tapp-mac-ax.swift +291 -0
- package/README.md +1 -0
- package/bin/tapp.js +75 -11
- package/browser/app.css +25 -0
- package/browser/app.js +77 -4
- package/browser/index.html +6 -0
- package/browser/product-contract.js +8 -2
- package/mcp-server/src/browser-product.js +75 -15
- package/mcp-server/src/index.js +59 -1
- package/mcp-server/src/macos-driver.js +253 -0
- package/mcp-server/src/macos-explorer.js +210 -0
- package/mcp-server/src/macos-flow.js +138 -0
- package/mcp-server/src/platforms.js +164 -0
- package/package.json +4 -2
- package/scripts/run-macos-flow.js +32 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Bounded deterministic exploration of a macOS application.
|
|
2
|
+
//
|
|
3
|
+
// It emits the same marker contract as the XCUITest harness and the Android explorer, so
|
|
4
|
+
// report.js, the UI Map, journeys, baselines and the CI gate do not know or care which platform
|
|
5
|
+
// produced the evidence.
|
|
6
|
+
//
|
|
7
|
+
// Two rules are specific to the desktop, and both exist because this is the person's own
|
|
8
|
+
// machine rather than a simulator:
|
|
9
|
+
//
|
|
10
|
+
// • Destructive controls are never pressed. The driver refuses them too; this is the second
|
|
11
|
+
// of the two locks (mcp-server/src/macos-driver.js).
|
|
12
|
+
// • Menu items are INVENTORIED, NOT PRESSED. A desktop menu is where "Quit", "Delete" and
|
|
13
|
+
// "Move to Trash" live, and it is also full of items that open modal file pickers a crawler
|
|
14
|
+
// cannot close. The report says what the menus contain and says plainly that nothing in them
|
|
15
|
+
// was exercised, which is an honest coverage boundary rather than a silent one.
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
import { MacosDriver, macActionableElements } from "./macos-driver.js";
|
|
20
|
+
|
|
21
|
+
const ERROR_RE = /\b(something went wrong|an error occurred|failed to load|unexpected error|could not be completed|unable to)\b/i;
|
|
22
|
+
const AUTH_SUBMIT_RE = /\b(sign[ -]?in|log[ -]?in|continue|submit|unlock)\b/i;
|
|
23
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
|
+
|
|
25
|
+
export function macStateHash(snap) {
|
|
26
|
+
return (snap.elements || []).filter((element) => !element.inMenu)
|
|
27
|
+
.map((element) => `${element.type}:${element.id}:${element.label}:${element.value}`).join("|");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isMacAuthSubmit(element) {
|
|
31
|
+
return AUTH_SUBMIT_RE.test(`${element?.label || ""} ${element?.id || ""}`.replace(/[_-]+/g, " "));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The control inventory a UI Map node wants, for the window only. */
|
|
35
|
+
export function macMapControls(elements) {
|
|
36
|
+
// A disabled button is still part of the screen's inventory — "enabled: false" is a state a
|
|
37
|
+
// UI Map should record, not a reason to omit the control (same as the Android map).
|
|
38
|
+
const PRESSABLE = new Set(["button", "checkbox", "radio", "tabs", "link", "disclosure"]);
|
|
39
|
+
return elements.filter((element) => !element.inMenu && (element.clickable || PRESSABLE.has(element.kind) || element.kind === "field" || element.kind === "secureField"))
|
|
40
|
+
.map((element) => ({
|
|
41
|
+
kind: element.kind === "secureField" ? "secureField" : element.kind === "field" ? "field" : element.kind === "checkbox" || element.kind === "radio" ? "toggle" : "button",
|
|
42
|
+
type: element.type,
|
|
43
|
+
id: element.id || "",
|
|
44
|
+
accessibilityId: element.id || "",
|
|
45
|
+
label: element.label,
|
|
46
|
+
secure: Boolean(element.secure),
|
|
47
|
+
enabled: element.enabled !== false,
|
|
48
|
+
hittable: Boolean(element.hittable),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A window with nothing in it is a finding, not a successful visit. */
|
|
53
|
+
export function isMacBlankSnapshot(snap) {
|
|
54
|
+
const elements = (snap?.elements || []).filter((element) => !element.inMenu);
|
|
55
|
+
const meaningful = elements.some((element) => String(element.label || "").trim() || String(element.value || "").trim());
|
|
56
|
+
const interactive = elements.some((element) => element.clickable || element.kind === "field");
|
|
57
|
+
return !meaningful && !interactive;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function exploreMacos({
|
|
61
|
+
appPath, maxActions = 40, timeoutSec = 300, outDir,
|
|
62
|
+
testEmail = "", testPassword = "", onProgress = () => {}, driver, home,
|
|
63
|
+
}) {
|
|
64
|
+
const d = driver || new MacosDriver({ home });
|
|
65
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
66
|
+
const screenshots = path.join(outDir, "screenshots");
|
|
67
|
+
fs.mkdirSync(screenshots, { recursive: true });
|
|
68
|
+
const markersPath = path.join(outDir, "ocqa-markers.txt");
|
|
69
|
+
fs.rmSync(markersPath, { force: true });
|
|
70
|
+
const emit = (kind, payload) => fs.appendFileSync(markersPath, `OCQA_${kind}:${JSON.stringify(payload)}\n`);
|
|
71
|
+
|
|
72
|
+
const deadline = Date.now() + timeoutSec * 1000;
|
|
73
|
+
const tried = new Set();
|
|
74
|
+
const visited = new Map();
|
|
75
|
+
let issues = 0;
|
|
76
|
+
let actions = 0;
|
|
77
|
+
let loginTried = false;
|
|
78
|
+
let shotsUnavailable = false;
|
|
79
|
+
|
|
80
|
+
const launched = d.launch(appPath);
|
|
81
|
+
emit("ACTION", { type: "open", target: launched.name || appPath, via: appPath, narrative: `Launched ${launched.name || path.basename(appPath)}` });
|
|
82
|
+
let snap = d.settle();
|
|
83
|
+
|
|
84
|
+
const stillRunning = () => {
|
|
85
|
+
try { process.kill(d.pid, 0); return true; } catch { return false; }
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const recordState = (snapshot) => {
|
|
89
|
+
const hash = macStateHash(snapshot);
|
|
90
|
+
const screen = snapshot.screen || snapshot.app || "Window";
|
|
91
|
+
if (!visited.has(hash)) {
|
|
92
|
+
visited.set(hash, screen);
|
|
93
|
+
const file = path.join(screenshots, `${String(visited.size).padStart(2, "0")}-${screen.replace(/[^a-z0-9]+/gi, "-").toLowerCase().slice(0, 50) || "window"}.png`);
|
|
94
|
+
const shot = d.screenshot(file, snapshot);
|
|
95
|
+
if (shot.status !== "ok") shotsUnavailable = true;
|
|
96
|
+
}
|
|
97
|
+
const inputs = snapshot.elements.filter((element) => element.kind === "field" || element.kind === "secureField")
|
|
98
|
+
.map((element) => ({ key: element.id || element.label, label: element.label, secure: Boolean(element.secure) }));
|
|
99
|
+
emit("STATE", {
|
|
100
|
+
screen, hash, elements: snapshot.elements.length, action: actions,
|
|
101
|
+
role: inputs.some((input) => input.secure) ? "login" : "app",
|
|
102
|
+
inputs, controls: macMapControls(snapshot.elements),
|
|
103
|
+
});
|
|
104
|
+
return { hash, screen, inputs };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Everything in the application's own menus, recorded once as coverage. Nothing here is
|
|
108
|
+
// pressed; see the note at the top of this file.
|
|
109
|
+
const menuInventory = [...new Set(snap.elements.filter((element) => element.inMenu && element.label)
|
|
110
|
+
.map((element) => `${element.menu} › ${element.label}`))].slice(0, 400);
|
|
111
|
+
if (menuInventory.length) emit("COVERAGE", { kind: "menu-items", listed: menuInventory.length, pressed: 0, items: menuInventory });
|
|
112
|
+
|
|
113
|
+
while (actions < maxActions && Date.now() < deadline) {
|
|
114
|
+
if (!stillRunning()) {
|
|
115
|
+
emit("ISSUE", { type: "crash", severity: "critical", title: "The application exited during exploration", screen: visited.size ? [...visited.values()].at(-1) : "Launch", step: actions });
|
|
116
|
+
issues += 1;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const { hash, screen, inputs } = recordState(snap);
|
|
120
|
+
onProgress({ action: actions, max: maxActions, states: visited.size });
|
|
121
|
+
|
|
122
|
+
const visibleText = snap.elements.filter((element) => !element.inMenu).map((element) => element.label || element.value).filter(Boolean).join(" ");
|
|
123
|
+
if (ERROR_RE.test(visibleText)) {
|
|
124
|
+
emit("ISSUE", { type: "error_surface", severity: "high", title: "Visible error surface", screen, step: actions });
|
|
125
|
+
issues += 1;
|
|
126
|
+
}
|
|
127
|
+
if (isMacBlankSnapshot(snap)) {
|
|
128
|
+
emit("ISSUE", { type: "blank_screen", severity: "high", title: "No usable controls or content", screen, step: actions });
|
|
129
|
+
issues += 1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Fill a field before pressing things, so a form is submitted with something in it.
|
|
133
|
+
const unfilled = snap.elements.find((element) => !element.inMenu && (element.kind === "field" || element.kind === "secureField")
|
|
134
|
+
&& element.enabled && !tried.has(`${screen}|input|${element.id || element.label}`));
|
|
135
|
+
if (unfilled) {
|
|
136
|
+
const key = unfilled.id || unfilled.label;
|
|
137
|
+
const lower = `${key} ${unfilled.label}`.toLowerCase();
|
|
138
|
+
const value = unfilled.secure || lower.includes("password") ? (testPassword || "TestPass123!")
|
|
139
|
+
: lower.includes("email") ? (testEmail || "test@example.com") : "Tapp test";
|
|
140
|
+
tried.add(`${screen}|input|${key}`);
|
|
141
|
+
const typed = d.type(key, value, snap);
|
|
142
|
+
actions += 1;
|
|
143
|
+
emit("ACTION", {
|
|
144
|
+
type: "type", target: key, screen, status: typed.status,
|
|
145
|
+
valueSource: unfilled.secure || lower.includes("password") ? "test-password" : lower.includes("email") ? "test-email" : "generated-text",
|
|
146
|
+
reason: "complete_form", step: actions, narrative: `Typed into “${unfilled.label || key}”`,
|
|
147
|
+
});
|
|
148
|
+
snap = d.settle();
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const candidate = macActionableElements(snap.elements)
|
|
153
|
+
.find((element) => !element.inMenu && !tried.has(`${hash}|tap|${element.label}`));
|
|
154
|
+
if (candidate) {
|
|
155
|
+
const target = candidate.label;
|
|
156
|
+
const loginSubmit = inputs.some((input) => input.secure) && isMacAuthSubmit(candidate);
|
|
157
|
+
if (loginSubmit) loginTried = true;
|
|
158
|
+
tried.add(`${hash}|tap|${target}`);
|
|
159
|
+
const pressed = d.tap(target, snap);
|
|
160
|
+
actions += 1;
|
|
161
|
+
await sleep(250);
|
|
162
|
+
snap = d.settle();
|
|
163
|
+
const after = macStateHash(snap);
|
|
164
|
+
emit("ACTION", {
|
|
165
|
+
type: loginSubmit ? "login_submit" : "tap", target, screen, status: pressed.status,
|
|
166
|
+
reason: "untried_control", step: actions, narrative: `Pressed “${target}”`,
|
|
167
|
+
});
|
|
168
|
+
emit("TRANSITION", { from: screen, to: snap.screen, action: target, changed: hash !== after });
|
|
169
|
+
const authFailed = loginSubmit && snap.elements.some((element) => element.secure && !element.inMenu);
|
|
170
|
+
if (pressed.status === "ok" && authFailed) {
|
|
171
|
+
emit("ISSUE", { type: "auth_failed", severity: "high", title: "Sign-in attempt remained on the sign-in window", screen, target, step: actions });
|
|
172
|
+
issues += 1;
|
|
173
|
+
} else if (pressed.status === "ok" && hash === after) {
|
|
174
|
+
emit("ISSUE", { type: "unresponsive_element", severity: "medium", title: `Control did not respond: ${target}`, screen, target, step: actions });
|
|
175
|
+
issues += 1;
|
|
176
|
+
}
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Nothing left here. Escape closes a sheet, a popover or a menu — the desktop's "back".
|
|
181
|
+
const escapeKey = `${hash}|escape`;
|
|
182
|
+
if (!tried.has(escapeKey)) {
|
|
183
|
+
tried.add(escapeKey);
|
|
184
|
+
d.key("escape");
|
|
185
|
+
actions += 1;
|
|
186
|
+
await sleep(250);
|
|
187
|
+
const next = d.settle();
|
|
188
|
+
emit("ACTION", { type: "back", target: "escape", reason: "state_exhausted", step: actions, screen, narrative: "Pressed Escape" });
|
|
189
|
+
emit("TRANSITION", { from: screen, to: next.screen, action: "escape", changed: macStateHash(next) !== hash });
|
|
190
|
+
if (macStateHash(next) !== hash) { snap = next; continue; }
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const timedOut = Date.now() >= deadline;
|
|
196
|
+
emit("COMPLETE", {
|
|
197
|
+
actions, states: visited.size, issues,
|
|
198
|
+
screens: [...new Set(visited.values())].join(","),
|
|
199
|
+
outcome: timedOut ? "timeout" : "complete", timedOut,
|
|
200
|
+
credentialsProvided: Boolean(testEmail || testPassword), credentialsUsed: loginTried,
|
|
201
|
+
// Said out loud, every run: what a desktop run deliberately does not touch.
|
|
202
|
+
notChecked: [
|
|
203
|
+
`${menuInventory.length} menu item(s) were listed but not pressed — a desktop menu holds Quit, Delete and file pickers.`,
|
|
204
|
+
...(shotsUnavailable ? ["Screenshots were unavailable: macOS Screen Recording permission is not granted to whatever runs tapp."] : []),
|
|
205
|
+
],
|
|
206
|
+
...(timedOut ? { timeoutSeconds: timeoutSec } : {}),
|
|
207
|
+
});
|
|
208
|
+
onProgress({ action: actions, max: maxActions, states: visited.size });
|
|
209
|
+
return { markersPath, outDir, actions, states: visited.size, issues, timedOut, menuItems: menuInventory.length, screenshots: !shotsUnavailable };
|
|
210
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Deterministic replay of a Flow against a macOS application.
|
|
2
|
+
//
|
|
3
|
+
// Same vocabulary as every other platform, so a journey kept from a macOS exploration is an
|
|
4
|
+
// ordinary Flow file and the Studio, the scheduler and the agent token all work unchanged.
|
|
5
|
+
// `swipe` is the one step with no sensible desktop meaning; it is skipped and said so, rather
|
|
6
|
+
// than silently passing.
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
|
|
10
|
+
import { MacosDriver } from "./macos-driver.js";
|
|
11
|
+
import { FlowLog, flowVariables, normalizeFlowStep, substituteFlowValue } from "./flow-runtime.js";
|
|
12
|
+
import { chooseSignInSubmit } from "./sign-in.js";
|
|
13
|
+
|
|
14
|
+
const DEFAULT_TIMEOUT = 6000;
|
|
15
|
+
|
|
16
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
|
+
|
|
18
|
+
function screenMatches(snap, wanted) {
|
|
19
|
+
return String(snap.screen || "").trim().toLowerCase() === String(wanted || "").trim().toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function waitFor(driver, predicate, timeout) {
|
|
23
|
+
const deadline = Date.now() + timeout;
|
|
24
|
+
let snap = driver.settle();
|
|
25
|
+
while (Date.now() < deadline) {
|
|
26
|
+
if (predicate(snap)) return snap;
|
|
27
|
+
await sleep(200);
|
|
28
|
+
snap = driver.settle();
|
|
29
|
+
}
|
|
30
|
+
return predicate(snap) ? snap : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function runMacosFlow({ flow, appPath, logPath, screenshotDir, driver, home }) {
|
|
34
|
+
const target = appPath || flow.app || flow.url;
|
|
35
|
+
if (!target) throw new Error("A macOS Flow needs `app:` with the path to the application");
|
|
36
|
+
if (logPath) fs.rmSync(logPath, { force: true });
|
|
37
|
+
const d = driver || new MacosDriver({ home });
|
|
38
|
+
d.launch(target);
|
|
39
|
+
let snap = d.settle();
|
|
40
|
+
const log = new FlowLog({ logPath, flow });
|
|
41
|
+
const vars = flowVariables(flow);
|
|
42
|
+
|
|
43
|
+
for (let index = 0; index < flow.steps.length; index += 1) {
|
|
44
|
+
const raw = normalizeFlowStep(flow.steps[index]);
|
|
45
|
+
const action = raw.action;
|
|
46
|
+
const stepTarget = substituteFlowValue(raw.target, vars);
|
|
47
|
+
const value = substituteFlowValue(raw.value, vars);
|
|
48
|
+
const timeout = Number(raw.params.timeoutMs ?? raw.params.timeout) || DEFAULT_TIMEOUT;
|
|
49
|
+
let status = "pass";
|
|
50
|
+
let detail = "";
|
|
51
|
+
try {
|
|
52
|
+
if (action === "tap") {
|
|
53
|
+
const result = d.tap(stepTarget, snap);
|
|
54
|
+
if (result.status !== "ok") throw new Error(result.detail || `could not press ‘${stepTarget}’`);
|
|
55
|
+
} else if (action === "type") {
|
|
56
|
+
const result = d.type(stepTarget, value, snap);
|
|
57
|
+
if (result.status !== "ok") throw new Error(result.detail || `no field ‘${stepTarget}’ to type into`);
|
|
58
|
+
} else if (action === "login") {
|
|
59
|
+
const fields = snap.elements.filter((element) => !element.inMenu && (element.kind === "field" || element.kind === "secureField"));
|
|
60
|
+
const emailField = fields.find((element) => /email|user|account/i.test(`${element.id} ${element.label}`)) || fields.find((element) => !element.secure);
|
|
61
|
+
const passwordField = fields.find((element) => element.secure || /password|passcode/i.test(`${element.id} ${element.label}`));
|
|
62
|
+
if (!emailField || !passwordField) throw new Error("could not identify email and password fields");
|
|
63
|
+
const emailValue = substituteFlowValue(raw.params.email || "$TEST_EMAIL", vars);
|
|
64
|
+
const passwordValue = substituteFlowValue(raw.params.password || "$TEST_PASSWORD", vars);
|
|
65
|
+
const filledEmail = d.type(emailField.id || emailField.label, emailValue, snap);
|
|
66
|
+
if (filledEmail.status !== "ok") throw new Error(filledEmail.detail || "could not fill the email field");
|
|
67
|
+
snap = d.settle();
|
|
68
|
+
const filledPassword = d.type(passwordField.id || passwordField.label, passwordValue, snap);
|
|
69
|
+
if (filledPassword.status !== "ok") throw new Error(filledPassword.detail || "could not fill the password field");
|
|
70
|
+
snap = d.settle();
|
|
71
|
+
// The one sign-in rule, shared with web, Android and the explorer: rule out "Forgot
|
|
72
|
+
// password" and "Continue with Google" by name, prefer a sign-in name, otherwise take
|
|
73
|
+
// the first pressable control after the password field (mcp-server/src/sign-in.js).
|
|
74
|
+
const passwordIndex = snap.elements.findIndex((element) => element.secure);
|
|
75
|
+
const choice = chooseSignInSubmit(snap.elements.map((element, position) => ({
|
|
76
|
+
index: position,
|
|
77
|
+
name: element.label || element.id,
|
|
78
|
+
visible: Boolean(element.clickable) && !element.inMenu,
|
|
79
|
+
disabled: element.enabled === false,
|
|
80
|
+
after: position > passwordIndex,
|
|
81
|
+
})));
|
|
82
|
+
const submit = choice ? snap.elements[choice.index] : null;
|
|
83
|
+
if (!submit) throw new Error("could not identify a sign-in control");
|
|
84
|
+
const pressed = d.tap(submit.label || submit.id, snap);
|
|
85
|
+
if (pressed.status !== "ok") throw new Error(pressed.detail || "could not submit the sign-in form");
|
|
86
|
+
} else if (action === "back") {
|
|
87
|
+
d.key("escape");
|
|
88
|
+
} else if (action === "wait_for") {
|
|
89
|
+
const seen = await waitFor(d, (candidate) => screenMatches(candidate, stepTarget)
|
|
90
|
+
|| candidate.elements.some((element) => `${element.label} ${element.value}`.toLowerCase().includes(String(stepTarget).toLowerCase())), timeout);
|
|
91
|
+
if (!seen) throw new Error(`‘${stepTarget}’ never appeared within ${timeout}ms`);
|
|
92
|
+
snap = seen;
|
|
93
|
+
} else if (action === "wait") {
|
|
94
|
+
await sleep(timeout);
|
|
95
|
+
} else if (action === "assert_screen") {
|
|
96
|
+
const wanted = value || stepTarget;
|
|
97
|
+
const seen = await waitFor(d, (candidate) => screenMatches(candidate, wanted), timeout);
|
|
98
|
+
if (!seen) throw new Error(`expected window ‘${wanted}’, saw ‘${d.settle().screen}’`);
|
|
99
|
+
snap = seen;
|
|
100
|
+
} else if (action === "assert_exists") {
|
|
101
|
+
const seen = await waitFor(d, (candidate) => Boolean(d.find(stepTarget, candidate)), timeout);
|
|
102
|
+
if (!seen) throw new Error(`‘${stepTarget}’ not found`);
|
|
103
|
+
snap = seen;
|
|
104
|
+
} else if (action === "assert_absent") {
|
|
105
|
+
snap = d.settle();
|
|
106
|
+
if (d.find(stepTarget, snap)) throw new Error(`‘${stepTarget}’ was present but should be absent`);
|
|
107
|
+
} else if (action === "assert_text") {
|
|
108
|
+
const of = substituteFlowValue(raw.params.of || stepTarget, vars);
|
|
109
|
+
const needle = substituteFlowValue(raw.params.contains || value, vars);
|
|
110
|
+
snap = d.settle();
|
|
111
|
+
const element = d.find(of, snap);
|
|
112
|
+
if (!element || !`${element.value || element.label}`.toLowerCase().includes(String(needle).toLowerCase())) {
|
|
113
|
+
throw new Error(`‘${of}’ did not contain ‘${needle}’`);
|
|
114
|
+
}
|
|
115
|
+
} else if (action === "swipe") {
|
|
116
|
+
status = "skip";
|
|
117
|
+
detail = "swipe has no meaning on a desktop window";
|
|
118
|
+
} else if (action === "assert_ai") {
|
|
119
|
+
status = "skip";
|
|
120
|
+
detail = "AI assertions are advisory and are not part of deterministic macOS replay";
|
|
121
|
+
} else {
|
|
122
|
+
throw new Error(`unknown action ‘${action}’`);
|
|
123
|
+
}
|
|
124
|
+
if (!["wait_for", "assert_screen", "assert_exists", "assert_absent", "assert_text", "assert_ai", "swipe"].includes(action)) {
|
|
125
|
+
await sleep(200);
|
|
126
|
+
snap = d.settle();
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
status = "fail";
|
|
130
|
+
detail = error.message || String(error);
|
|
131
|
+
if (screenshotDir) d.screenshot(path.join(screenshotDir, `flow-failure-${index + 1}.png`), snap);
|
|
132
|
+
}
|
|
133
|
+
log.step({ index: index + 1, action, target: action === "login" ? "sign-in form" : stepTarget || value, status, detail, task: raw.task });
|
|
134
|
+
if (status === "fail" && !flow.continueOnFailure) break;
|
|
135
|
+
}
|
|
136
|
+
if (screenshotDir) d.screenshot(path.join(screenshotDir, "flow-final.png"), snap);
|
|
137
|
+
return log.finish();
|
|
138
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Every surface tapp aims at, and whether THIS Studio can drive it.
|
|
2
|
+
//
|
|
3
|
+
// tapp is not a web tool. The engine drives websites, iOS simulators and Android devices, and the
|
|
4
|
+
// Studio in `browser/` is the same program wherever it runs — on a laptop it can start an iOS run,
|
|
5
|
+
// and on a Linux box in a data centre it cannot, because there is no Mac attached to it.
|
|
6
|
+
//
|
|
7
|
+
// The product used to leave that implicit: the hosted Studio answered an .app with a bare 400,
|
|
8
|
+
// and nothing anywhere said that tapp drives phones at all. Someone arriving at app.runtapp.com
|
|
9
|
+
// reasonably concluded it was a website checker.
|
|
10
|
+
//
|
|
11
|
+
// So this module is the one place that answers, for a given host: what can tapp drive, what does
|
|
12
|
+
// each one need, and what should this person do next. Every state below is computed from the
|
|
13
|
+
// machine the Studio is on — never declared — and a platform with no driver says so in those
|
|
14
|
+
// words. Nothing here may describe a capability that does not exist.
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
|
|
18
|
+
import { resolveAdbPath } from "./android-driver.js";
|
|
19
|
+
import { macAccessibilityTrusted } from "./macos-driver.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The states a platform can be in, worst-named-first so nobody mistakes one for another:
|
|
23
|
+
*
|
|
24
|
+
* ready — this Studio can start a run now.
|
|
25
|
+
* needs-machine — tapp drives it, but not from this host. There is an exact command for the
|
|
26
|
+
* machine that can, because self-hosting is the same product, not a lesser one.
|
|
27
|
+
* pilot — tapp does NOT drive it yet. No driver exists. Early work is done with a
|
|
28
|
+
* person while the driver lands (owner decision, 2026-09-14, for Windows).
|
|
29
|
+
*/
|
|
30
|
+
export const PLATFORM_STATES = Object.freeze(["ready", "needs-machine", "pilot"]);
|
|
31
|
+
|
|
32
|
+
/** What tapp aims at, in the order a person should see them. */
|
|
33
|
+
export const PLATFORM_TARGETS = Object.freeze([
|
|
34
|
+
{
|
|
35
|
+
id: "web", label: "Web", give: "A website URL",
|
|
36
|
+
driver: "playwright", needs: "Playwright and Chromium, which tapp installs",
|
|
37
|
+
machine: "any machine",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "ios", label: "iOS", give: "A simulator .app or a bundle id",
|
|
41
|
+
driver: "xcuitest", needs: "macOS with Xcode",
|
|
42
|
+
machine: "a Mac with Xcode",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "android", label: "Android", give: "An .apk or a connected device",
|
|
46
|
+
driver: "adb", needs: "the Android SDK and adb",
|
|
47
|
+
machine: "a machine with the Android SDK",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "macos", label: "macOS app", give: "A .app on your Mac",
|
|
51
|
+
driver: "accessibility", needs: "macOS, and the Accessibility permission",
|
|
52
|
+
machine: "a Mac",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "windows", label: "Windows app", give: "A WPF, WinForms or WinUI app",
|
|
56
|
+
driver: null, needs: "Windows",
|
|
57
|
+
machine: "a Windows machine",
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
// "A simulator .app" mid-sentence, without lowercasing the file extension or the brand.
|
|
62
|
+
const lower = (text) => String(text).replace(/^(An?|The) /, (word) => word.toLowerCase());
|
|
63
|
+
|
|
64
|
+
const onPath = (name, env) => String(env.PATH || "").split(path.delimiter).some((dir) => dir && fs.existsSync(path.join(dir, name)));
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What this machine actually has. The same checks `runnerSummary` used, in one place, so the
|
|
68
|
+
* Studio and the runner list can never disagree about whether Xcode is installed.
|
|
69
|
+
*/
|
|
70
|
+
export function hostToolchain({ env = process.env, platform = process.platform } = {}) {
|
|
71
|
+
return {
|
|
72
|
+
ios: platform === "darwin" && (fs.existsSync("/usr/bin/xcodebuild") || onPath("xcodebuild", env)),
|
|
73
|
+
// The driver's own resolver, not a PATH guess: the SDK is commonly an unlinked Homebrew
|
|
74
|
+
// cask with ANDROID_HOME unset, and the Studio must not say "no Android" about a machine
|
|
75
|
+
// where `tapp explore` would happily find adb.
|
|
76
|
+
android: platform === "linux" || platform === "darwin" || platform === "win32" ? Boolean(resolveAdbPath(env)) : false,
|
|
77
|
+
// Driven through the Accessibility API, which needs a permission nothing can grant for
|
|
78
|
+
// itself. A Mac without it is not ready, and saying otherwise would promise a run that
|
|
79
|
+
// fails on its first action.
|
|
80
|
+
macos: platform === "darwin" && macAccessibilityTrusted(),
|
|
81
|
+
// Chromium is fetched on demand, so web is reachable from any host; whether this particular
|
|
82
|
+
// one has it unpacked is checked when the run starts, which is where the error belongs.
|
|
83
|
+
web: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The command that opens this same Studio on a machine that can do the work. */
|
|
88
|
+
export const SELF_HOST_COMMAND = "npx -y @aarwitz/tapp@latest app";
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The honest state of every platform for one host.
|
|
92
|
+
*
|
|
93
|
+
* @param {object} options
|
|
94
|
+
* @param {boolean} options.hosted true for app.runtapp.com, false for `tapp app` on a laptop
|
|
95
|
+
*/
|
|
96
|
+
export function platformStates({ hosted = false, env = process.env, platform = process.platform, toolchain = null } = {}) {
|
|
97
|
+
const has = toolchain || hostToolchain({ env, platform });
|
|
98
|
+
return PLATFORM_TARGETS.map((target) => {
|
|
99
|
+
// No driver is no driver, on any host — so this must not read as "buy a Mac and it works".
|
|
100
|
+
// But the machine still matters: when the driver lands, running it locally will need one,
|
|
101
|
+
// and somebody deciding today should know which. State both, and the way round it.
|
|
102
|
+
if (!target.driver) {
|
|
103
|
+
return {
|
|
104
|
+
...target,
|
|
105
|
+
state: "pilot", because: "no-driver",
|
|
106
|
+
summary: `tapp has no ${target.label} driver yet — it is being built.`,
|
|
107
|
+
how: `Running ${lower(target.label)}s locally will need ${target.machine}. Until the driver lands we do these runs with you: tell us about your app, or have tapp run it for you.`,
|
|
108
|
+
command: "",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// A public Studio starts website runs and nothing else, whatever the machine under it
|
|
112
|
+
// happens to own (ADR-0008). Saying "ready" because this particular host has Xcode would
|
|
113
|
+
// promise a run the server then refuses — so the deployment has a say, not just the disk.
|
|
114
|
+
const exposed = hosted ? target.id === "web" : true;
|
|
115
|
+
if (has[target.id] && exposed) {
|
|
116
|
+
return {
|
|
117
|
+
...target,
|
|
118
|
+
state: "ready", because: "",
|
|
119
|
+
summary: hosted ? `Ready here. ${target.give}.` : `Ready on this machine. ${target.give}.`,
|
|
120
|
+
how: `Paste ${lower(target.give)} in the box above.`,
|
|
121
|
+
command: "",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const because = has[target.id] && !exposed ? "not-exposed" : "no-toolchain";
|
|
125
|
+
return {
|
|
126
|
+
...target,
|
|
127
|
+
state: "needs-machine", because,
|
|
128
|
+
summary: because === "not-exposed"
|
|
129
|
+
? `tapp drives ${target.label}, and this machine could — but a public Studio only starts website runs.`
|
|
130
|
+
: `tapp drives ${target.label}, but this Studio is not on ${target.machine}.`,
|
|
131
|
+
// Two ways out, always both: self-host is the same product without the hosting (ADR-0006),
|
|
132
|
+
// and not everyone has the machine or wants to keep it awake.
|
|
133
|
+
how: `Run this Studio on ${target.machine} and give it ${lower(target.give)} there — or have tapp run it for you.`,
|
|
134
|
+
command: SELF_HOST_COMMAND,
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** One platform's state, by id. */
|
|
140
|
+
export function platformState(id, options = {}) {
|
|
141
|
+
return platformStates(options).find((entry) => entry.id === String(id)) || null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The platforms this Studio can start a run on right now. */
|
|
145
|
+
export function readyPlatforms(options = {}) {
|
|
146
|
+
return platformStates(options).filter((entry) => entry.state === "ready").map((entry) => entry.id);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The answer to "I gave you an .app and you are a Linux box": where it runs, and how to get there.
|
|
151
|
+
* Shaped like every other self-host answer the Studio already knows how to show.
|
|
152
|
+
*/
|
|
153
|
+
export function selfHostAnswer(platformId, target = "", options = {}) {
|
|
154
|
+
const entry = platformState(platformId, options);
|
|
155
|
+
if (!entry) return null;
|
|
156
|
+
const what = target ? `“${target}”` : `a ${entry.label} target`;
|
|
157
|
+
if (entry.state === "pilot") {
|
|
158
|
+
return { kind: "self-host", platform: entry.id, state: entry.state, target,
|
|
159
|
+
message: `${what} is a ${entry.label} target, and tapp has no ${entry.label} driver yet. ${entry.how}`, command: "" };
|
|
160
|
+
}
|
|
161
|
+
return { kind: "self-host", platform: entry.id, state: entry.state, target,
|
|
162
|
+
message: `Running ${what} needs ${entry.machine}, which this Studio is not on. Start the Studio there: ${SELF_HOST_COMMAND}`,
|
|
163
|
+
command: SELF_HOST_COMMAND };
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
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",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"scripts/platform-gate.js",
|
|
41
41
|
"scripts/pr-plan.js",
|
|
42
42
|
"scripts/quick-capture.sh",
|
|
43
|
+
"scripts/run-macos-flow.js",
|
|
43
44
|
"scripts/run-android-flow.js",
|
|
44
45
|
"scripts/run-flow.sh",
|
|
45
46
|
"scripts/run-web-flow.js",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"Harness/OCQAHarnessUITests/",
|
|
49
50
|
"Harness/OCQAHarness.xcodeproj/",
|
|
50
51
|
"Harness/generate-harness-xcodeproj.rb",
|
|
52
|
+
"MacHarness/",
|
|
51
53
|
"skills/",
|
|
52
54
|
".claude-plugin/",
|
|
53
55
|
"AGENTS.md"
|
|
@@ -96,7 +98,7 @@
|
|
|
96
98
|
"mobile"
|
|
97
99
|
],
|
|
98
100
|
"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-overlay.test.js tests/web-audit.test.js tests/page-observations.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/alerts.test.js tests/access-jwt.test.js tests/oauth.test.js tests/studio-client.test.js tests/journeys.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/job-lanes.test.js tests/browser-product.test.js tests/browser-chat-narration.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",
|
|
101
|
+
"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-overlay.test.js tests/web-audit.test.js tests/page-observations.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/alerts.test.js tests/access-jwt.test.js tests/oauth.test.js tests/studio-client.test.js tests/journeys.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/sign-in.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-flow.test.js tests/macos-driver.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/job-lanes.test.js tests/browser-product.test.js tests/browser-chat-narration.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/platforms.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
102
|
"test:browser-journey": "node --test tests/browser-journey.test.js",
|
|
101
103
|
"test:browser-native": "TAPP_RUN_NATIVE_BROWSER=1 node --test tests/browser-native-journey.test.js"
|
|
102
104
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Replay a Flow against a macOS application. Mirrors scripts/run-android-flow.js: the platform
|
|
3
|
+
// runner the CLI spawns, so evidence and the log land where every other platform puts them.
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
|
|
7
|
+
import { loadFlowFile } from "../mcp-server/src/flow-runtime.js";
|
|
8
|
+
import { runMacosFlow } from "../mcp-server/src/macos-flow.js";
|
|
9
|
+
|
|
10
|
+
const [, , flowPath, appPath = ""] = process.argv;
|
|
11
|
+
if (!flowPath) {
|
|
12
|
+
console.error("usage: run-macos-flow.js <flow.yml> [/path/to/App.app]");
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const evidenceDir = process.env.TAPP_FLOW_EVIDENCE_DIR || "";
|
|
17
|
+
if (evidenceDir) fs.mkdirSync(evidenceDir, { recursive: true });
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const flow = loadFlowFile(path.resolve(flowPath));
|
|
21
|
+
const result = await runMacosFlow({
|
|
22
|
+
flow,
|
|
23
|
+
appPath: appPath || flow.app || "",
|
|
24
|
+
logPath: process.env.FLOW_LOG || (evidenceDir ? path.join(evidenceDir, "flow.log") : ""),
|
|
25
|
+
screenshotDir: evidenceDir || "",
|
|
26
|
+
});
|
|
27
|
+
console.log(`${result.passed ? "✅" : "❌"} ${result.name} — ${result.executed}/${result.total} steps, ${result.failed} failed`);
|
|
28
|
+
process.exit(result.passed ? 0 : 1);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(`❌ ${error.message || error}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|