@aarwitz/tapp 0.35.3 → 0.35.5

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tapp",
3
3
  "description": "Give Claude hands and eyes on iOS, Android, and web apps, with exploration, replayable flows, evidence, and deterministic CI gates.",
4
- "version": "0.35.3",
4
+ "version": "0.35.5",
5
5
  "author": {
6
6
  "name": "Aaron Horowitz",
7
7
  "url": "https://github.com/aarwitz"
@@ -24,7 +24,7 @@
24
24
  "command": "npx",
25
25
  "args": [
26
26
  "-y",
27
- "@aarwitz/tapp@0.35.3",
27
+ "@aarwitz/tapp@0.35.5",
28
28
  "mcp"
29
29
  ],
30
30
  "cwd": "${CLAUDE_PROJECT_DIR}"
@@ -542,14 +542,32 @@ class ExplorerTests: XCTestCase {
542
542
  guard !h.isEmpty else { return nil }
543
543
  // textViews included deliberately: chat composers / notes / comment boxes are
544
544
  // TextViews, not TextFields — without them "Write a message…" is untypeable.
545
+ // Let a scroll finish before enumerating: the set of fields is read element by element,
546
+ // and a list still gliding changes under the read.
547
+ waitForAnimationsToSettle()
545
548
  let fields = app.textFields.allElementsBoundByIndex + app.secureTextFields.allElementsBoundByIndex + app.textViews.allElementsBoundByIndex
546
- let existing = fields.filter { $0.exists }
547
- if let exact = existing.first(where: {
548
- $0.identifier.lowercased() == h || $0.label.lowercased() == h || ($0.placeholderValue ?? "").lowercased() == h
549
- }) { return exact }
550
- if let contains = existing.first(where: {
551
- ($0.identifier + " " + $0.label + " " + ($0.placeholderValue ?? "")).lowercased().contains(h)
552
- }) { return contains }
549
+ // Read each field's three names ONCE, through the THROWING snapshot API. A bare
550
+ // `element.identifier` re-resolves against the live tree and fails the entire run with
551
+ // "No matches found for Element at index N" if that element has since moved or gone;
552
+ // `try? snapshot()` hands back nil for the same case, so one shifted row no longer
553
+ // takes the run down (TM-496).
554
+ let described: [(element: XCUIElement, identifier: String, label: String, placeholder: String)] =
555
+ fields.compactMap { element in
556
+ guard let snapshot = try? element.snapshot() else { return nil }
557
+ return (element,
558
+ snapshot.identifier.lowercased(),
559
+ snapshot.label.lowercased(),
560
+ ((snapshot.placeholderValue as String?) ?? "").lowercased())
561
+ }
562
+
563
+ // Rank by WHAT matched before where it sits. A single OR pass returns whichever field is
564
+ // highest on screen, so a field whose label happens to equal the hint would beat the
565
+ // field actually named that — precedence the identifier subscripts used to provide, and
566
+ // which was lost when this resolver moved in front of them (caught in review, TM-496).
567
+ if let match = described.first(where: { $0.identifier == h }) { return match.element }
568
+ if let match = described.first(where: { $0.label == h }) { return match.element }
569
+ if let match = described.first(where: { $0.placeholder == h }) { return match.element }
570
+ if let match = described.first(where: { "\($0.identifier) \($0.label) \($0.placeholder)".contains(h) }) { return match.element }
553
571
  if h.contains("password") {
554
572
  let secure = app.secureTextFields.firstMatch
555
573
  if secure.exists { return secure }
@@ -568,7 +586,7 @@ class ExplorerTests: XCTestCase {
568
586
  return !l.isEmpty && (l == h || l.contains(h) || h.contains(l))
569
587
  }) {
570
588
  let zone = overlay.frame.insetBy(dx: -24, dy: -24)
571
- if let field = existing.first(where: { $0.frame.intersects(zone) }) {
589
+ if let field = described.first(where: { (try? $0.element.snapshot().frame.intersects(zone)) == true })?.element {
572
590
  return field
573
591
  }
574
592
  }
@@ -651,11 +669,18 @@ class ExplorerTests: XCTestCase {
651
669
  // submits, and append-on-retry turns "Lemonade" into "LemonadeLemonade" — a malformed
652
670
  // credential the server rejects with no visible cause.
653
671
  if let id = id, !id.isEmpty {
654
- for field in [app.textFields[id], app.secureTextFields[id], app.textViews[id]] where field.exists {
672
+ // Enumerate before subscripting. `app.textFields[hint]` builds a query against
673
+ // IDENTIFIERS, and resolving one of those against a SwiftUI `TextField(axis:
674
+ // .vertical)` raises "Failed to get matching snapshot … Automation type mismatch:
675
+ // computed TextField from legacy attrib", which aborts the whole run instead of
676
+ // failing one step (TM-496). resolveFieldByHint walks allElementsBoundByIndex,
677
+ // which does not, and it already prefers an exact identifier match — so this
678
+ // ordering keeps the same precedence and stops the crash.
679
+ if let field = resolveFieldByHint(id) {
655
680
  guard replaceText(on: field, with: text) else { return false }
656
681
  lastTypedInto = fieldDesc(field); return true
657
682
  }
658
- if let field = resolveFieldByHint(id) {
683
+ for field in [app.textFields[id], app.secureTextFields[id], app.textViews[id]] where field.exists {
659
684
  guard replaceText(on: field, with: text) else { return false }
660
685
  lastTypedInto = fieldDesc(field); return true
661
686
  }
@@ -1022,7 +1047,18 @@ class ExplorerTests: XCTestCase {
1022
1047
  return out
1023
1048
  }
1024
1049
 
1025
- if !targetBundleId.isEmpty { app.launch() } else { app.launch() }
1050
+ // Continue from the screen the app is on, rather than restarting it. A demo is one
1051
+ // story told in several takes, and relaunching between them throws away the first ten
1052
+ // seconds of every recording (home screen, loading, sign-in) and makes each flow sign
1053
+ // in again (TM-498). `activate()` foregrounds a running app; `launch()` always restarts
1054
+ // one. setUp already activates when no launch arguments are configured, so this is the
1055
+ // line that was forcing the restart.
1056
+ let continueFromCurrentScreen = (flow["continue"] as? Bool ?? false) || resolve("OCQA_FLOW_CONTINUE") == "1"
1057
+ if continueFromCurrentScreen && app.state == .runningForeground {
1058
+ app.activate()
1059
+ } else {
1060
+ app.launch()
1061
+ }
1026
1062
  waitForUIStability(timeout: 3.0)
1027
1063
  let contractStart = contractName.isEmpty ? "" : " contract=\(escapeJSON(contractName))"
1028
1064
  print("OCQA_FLOW_RESULT:started total=\(steps.count) name=\(escapeJSON(flow["name"] as? String ?? "flow")) kind=\(evidenceKind)\(contractStart)")
@@ -5148,6 +5184,85 @@ class ExplorerTests: XCTestCase {
5148
5184
  return false
5149
5185
  }
5150
5186
 
5187
+ /// What is sitting in front of a field, in the words a person would use.
5188
+ ///
5189
+ /// "It never took keyboard focus" is true and useless: it sends whoever reads it hunting
5190
+ /// through screenshots for the reason. Nine times out of ten the reason is something drawn
5191
+ /// over the field — a sheet, a drawer, an alert, a popover — and naming it turns the fix
5192
+ /// into one step (TM-496). Alerts first because they also block everything else, then the
5193
+ /// frontmost container whose frame covers the field's centre.
5194
+ private func whatCovers(_ element: XCUIElement) -> String? {
5195
+ let target = element.frame
5196
+ guard target.width > 0, target.height > 0 else { return nil }
5197
+ let centre = CGPoint(x: target.midX, y: target.midY)
5198
+
5199
+ // Everything below reads through `try? snapshot()`. This runs at the moment a step has
5200
+ // already failed, over every sheet, popover and container on screen — exactly when the
5201
+ // tree is most likely to be mid-change — and a live property read on a row that has
5202
+ // moved fails the whole run instead of this one lookup (TM-496).
5203
+ func firstWords(_ snapshot: XCUIElementSnapshot) -> String {
5204
+ let own = snapshot.label.trimmingCharacters(in: .whitespacesAndNewlines)
5205
+ if !own.isEmpty { return own }
5206
+ let texts = snapshot.children
5207
+ .filter { $0.elementType == .staticText }
5208
+ .prefix(3)
5209
+ .map { $0.label.trimmingCharacters(in: .whitespacesAndNewlines) }
5210
+ .filter { !$0.isEmpty }
5211
+ // Enough to recognise it on the screen, not the whole panel read aloud.
5212
+ let joined = texts.joined(separator: " · ")
5213
+ return joined.count > 60 ? String(joined.prefix(57)) + "…" : joined
5214
+ }
5215
+
5216
+ for alert in app.alerts.allElementsBoundByIndex {
5217
+ guard let snapshot = try? alert.snapshot() else { continue }
5218
+ let what = firstWords(snapshot)
5219
+ return what.isEmpty ? "an alert" : "the alert ‘\(what)’"
5220
+ }
5221
+ // Sheets, popovers and dialogs are unambiguous: if one covers the field, it is the
5222
+ // thing in the way. A plain container is not — every ancestor of the field also
5223
+ // "covers" it — so among those, only consider ones the app gave an accessibility
5224
+ // identifier, which is what authors do to drawers and overlays and not to layout
5225
+ // boxes. When nothing qualifies we say nothing rather than guess at an ancestor.
5226
+ let screen = app.frame.width * app.frame.height
5227
+ var best: (area: CGFloat, text: String)? = nil
5228
+ func holdsAField(_ snapshot: XCUIElementSnapshot) -> Bool {
5229
+ if snapshot.elementType == .textField || snapshot.elementType == .secureTextField || snapshot.elementType == .textView { return true }
5230
+ return snapshot.children.contains(where: holdsAField)
5231
+ }
5232
+ func consider(_ candidate: XCUIElement, _ noun: String, mustNotHoldTheField: Bool) {
5233
+ guard let snapshot = try? candidate.snapshot() else { return }
5234
+ let frame = snapshot.frame
5235
+ guard frame.contains(centre), frame.width > 0, frame.height > 0 else { return }
5236
+ guard screen == 0 || frame.width * frame.height < screen * 0.98 else { return }
5237
+ // Every ancestor of the field also "covers" it. Measured discriminator: an ancestor
5238
+ // contains the text fields of the screen, an overlay drawn on top contains none.
5239
+ if mustNotHoldTheField && holdsAField(snapshot) { return }
5240
+ let what = firstWords(snapshot)
5241
+ guard !what.isEmpty else { return }
5242
+ let area = frame.width * frame.height
5243
+ // The smallest covering thing is the one actually in front, not its container.
5244
+ if best == nil || area < best!.area { best = (area, "the \(noun) ‘\(what)’") }
5245
+ }
5246
+ for candidate in app.sheets.allElementsBoundByIndex { consider(candidate, "sheet", mustNotHoldTheField: false) }
5247
+ for candidate in app.popovers.allElementsBoundByIndex { consider(candidate, "popover", mustNotHoldTheField: false) }
5248
+ for candidate in app.otherElements.allElementsBoundByIndex { consider(candidate, "panel", mustNotHoldTheField: true) }
5249
+ if let best { return best.text }
5250
+ if app.keyboards.firstMatch.exists, app.keyboards.firstMatch.frame.intersects(target) { return "the keyboard" }
5251
+ // Measured on a SwiftUI drawer (a VStack with a .regularMaterial background over the
5252
+ // form): NOTHING in the accessibility tree corresponds to it. An identifier put on such
5253
+ // a container is pushed down onto its child texts, which sit elsewhere on the screen,
5254
+ // and the material itself is not an element at all — every candidate covering the field
5255
+ // was an unnamed full-screen ancestor. So the overlay cannot be named, and claiming
5256
+ // otherwise would be a guess.
5257
+ //
5258
+ // What is still true and still saves the search: the field is on screen and not
5259
+ // hittable, which only happens when something is drawn over it.
5260
+ if !element.isHittable {
5261
+ return "something with no accessibility identity (a drawer or a material overlay shows this way)"
5262
+ }
5263
+ return nil
5264
+ }
5265
+
5151
5266
  // Replace existing field contents to avoid repeatedly appending test text. Returns false
5152
5267
  // (and records `lastTypeFailure`) instead of letting XCTest abort the run when the field
5153
5268
  // cannot be focused.
@@ -5156,7 +5271,11 @@ class ExplorerTests: XCTestCase {
5156
5271
  lastTypeFailure = ""
5157
5272
  guard focusForTyping(element) else {
5158
5273
  let f = element.frame
5274
+ // Say what is in the way before saying what did not happen: the covering element is
5275
+ // the actionable half of this message (TM-496).
5276
+ let covering = whatCovers(element)
5159
5277
  lastTypeFailure = "‘\(fieldDesc(element))’ was found (frame \(Int(f.minX)),\(Int(f.minY)) \(Int(f.width))×\(Int(f.height))) but never took keyboard focus, including after dismissing the keyboard and scrolling it into view"
5278
+ + (covering.map { " — \($0) is in front of it" } ?? "")
5160
5279
  + (app.keyboards.count == 0 ? " — no keyboard appeared" : "")
5161
5280
  + (focusedField().map { " — focus is on ‘\(fieldDesc($0))’" } ?? "")
5162
5281
  print("OCQA_STATE:type_focus_failed detail=\(escapeJSON(lastTypeFailure))")
package/bin/tapp.js CHANGED
@@ -428,7 +428,7 @@ function safeCommandUsage(verb) {
428
428
  shot: "tapp look --sim [--out FILE]",
429
429
  apps: "tapp apps",
430
430
  build: "tapp build [repo] [--scheme NAME] [--configuration NAME]",
431
- flow: "tapp run FLOW.yml [--var NAME=VALUE ...] [--actor NAME] [--email VALUE] [--password VALUE] [--device \"iPhone 13\"] [--viewport 390x844]\n iOS: [--device \"iPhone 16\"|UDID] chooses the simulator (required when more than one is booted; TAPP_UDID is the default) [--launch-arg ARG] [--launch-env JSON]\ntapp validate FLOW.yml [--platform PLATFORM] [--map FILE]\ntapp validate --example print a complete starter Flow YAML\n Exit codes: 0 replay passed · 1 replay failed · 2 infrastructure/usage error",
431
+ flow: "tapp run FLOW.yml [--var NAME=VALUE ...] [--actor NAME] [--email VALUE] [--password VALUE] [--device \"iPhone 13\"] [--viewport 390x844] [--no-relaunch]\n --no-relaunch continues from the screen the app is on instead of restarting it (iOS)\n iOS: [--device \"iPhone 16\"|UDID] chooses the simulator (required when more than one is booted; TAPP_UDID is the default) [--launch-arg ARG] [--launch-env JSON]\ntapp validate FLOW.yml [--platform PLATFORM] [--map FILE]\ntapp validate --example print a complete starter Flow YAML\n Exit codes: 0 replay passed · 1 replay failed · 2 infrastructure/usage error",
432
432
  task: "tapp validate TASK.yml [--platform PLATFORM] [--map FILE]\ntapp validate TASK.yml --compile --platform PLATFORM [--inputs JSON] [--out FILE]\ntapp run TASK.yml --platform PLATFORM [--url URL|--bundle-id ID|--app-id ID] [--inputs JSON]",
433
433
  contract: "tapp validate FILE.contract.ts [--platform PLATFORM] [--map FILE]\ntapp validate FILE.contract.ts --compile --platform PLATFORM [--out FILE]\ntapp run FILE.contract.ts --platform PLATFORM [--url URL|--bundle-id ID|--app-id ID]\n Exit codes: 0 contract held · 1 contract failed · 2 infrastructure/usage error",
434
434
  scenario: "tapp validate SCENARIO.yml [--project-dir DIR]\ntapp run SCENARIO.yml --platform web --url URL [--project-dir DIR]\n Exit codes: 0 scenario passed · 1 scenario failed · 2 infrastructure/usage error",
@@ -1591,6 +1591,16 @@ switch (command) {
1591
1591
  flowVars[name] = value.join("=");
1592
1592
  }
1593
1593
  if (Object.keys(flowVars).length) env.TAPP_FLOW_VARS = JSON.stringify(flowVars);
1594
+ // Continue from the screen the app is already on. A demo told in several takes should not
1595
+ // restart and sign in again between them (TM-498). iOS today: the other drivers each have
1596
+ // their own notion of a session and are a separate decision.
1597
+ if (flags["no-relaunch"] === true) {
1598
+ if (platform !== "ios") {
1599
+ console.error(`❌ --no-relaunch applies to iOS flows today (this one is ${platform})`);
1600
+ process.exit(2);
1601
+ }
1602
+ env.TAPP_FLOW_CONTINUE = "1";
1603
+ }
1594
1604
 
1595
1605
  let invocation;
1596
1606
  if (platform === "web") {
@@ -581,10 +581,17 @@ export function computeReachabilityLoss(current, baseline) {
581
581
  if (!current?.screens || !baseline?.screens || !baseline.screens.length) return [];
582
582
  const baseActions = baseline.actionsPerformed || 0;
583
583
  if (baseActions > 0 && (current.actionsPerformed || 0) < baseActions * 0.6) return [];
584
- const reached = new Set(current.screens);
585
- const reachedBaseline = baseline.screens.filter((s) => reached.has(s)).length;
586
- if (reachedBaseline >= baseline.screens.length * 0.6) return [];
587
- return baseline.screens
584
+ // A screen is recorded as "Name::signature" so two in-page states of one screen count
585
+ // separately for coverage. That signature is derived from the page's content and so differs
586
+ // between runs, which made this comparison match nothing: every baseline screen looked
587
+ // unreached and the gate raised a high finding for each. The public CI went red on 24 October,
588
+ // the first release after signatures were added, and stayed red. Compare names (TM-527).
589
+ const bareName = (screen) => String(screen).split("::")[0];
590
+ const reached = new Set((current.screens || []).map(bareName));
591
+ const baselineNames = [...new Set(baseline.screens.map(bareName))];
592
+ const reachedBaseline = baselineNames.filter((s) => reached.has(s)).length;
593
+ if (reachedBaseline >= baselineNames.length * 0.6) return [];
594
+ return baselineNames
588
595
  .filter((s) => !reached.has(s))
589
596
  .map((screen) => ({
590
597
  type: "screen_unreachable",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aarwitz/tapp",
3
- "version": "0.35.3",
3
+ "version": "0.35.5",
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",
@@ -59,6 +59,9 @@ d = {
59
59
  # `tapp run FLOW --var NAME=VALUE`. The harness has read OCQA_FLOW_VARS since Flows gained
60
60
  # variables; nothing ever set it, so on iOS every --var silently resolved to nothing while the
61
61
  # same Flow worked on web (field issue #35). Both ends existed; this is the wire between them.
62
+ # `tapp run --no-relaunch`: drive the app as it stands instead of restarting it.
63
+ if os.environ.get("TAPP_FLOW_CONTINUE", "") == "1":
64
+ d["OCQA_FLOW_CONTINUE"] = "1"
62
65
  flow_vars = os.environ.get("TAPP_FLOW_VARS", "").strip()
63
66
  if flow_vars:
64
67
  json.loads(flow_vars) # refuse malformed input here rather than inside the harness