@validate.qa/runner 1.0.88 → 1.0.89

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.
Files changed (3) hide show
  1. package/dist/cli.js +1377 -26
  2. package/dist/cli.mjs +1377 -26
  3. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1798,7 +1798,11 @@ var init_constants = __esm({
1798
1798
  "home",
1799
1799
  "waitForElement",
1800
1800
  "assertVisible",
1801
- "assertText"
1801
+ "assertText",
1802
+ /** Capture list labels / badge counts into run-local state bag (Phase 1 oracles). */
1803
+ "captureState",
1804
+ /** Assert a prior captureState delta (removed id, count change, etc.). */
1805
+ "assertStateDelta"
1802
1806
  ];
1803
1807
  BLOCKED_ENV_VARS = /* @__PURE__ */ new Set([
1804
1808
  // Execution / code-injection vectors
@@ -2233,7 +2237,10 @@ function readMobileMetadata(value) {
2233
2237
  webCss: typeof value.webCss === "string" && value.webCss.trim() ? value.webCss.trim() : void 0,
2234
2238
  webviewContext: typeof value.webviewContext === "string" && /^WEBVIEW/i.test(value.webviewContext.trim()) ? value.webviewContext.trim() : void 0,
2235
2239
  matchIndex: hasValidMatchPair ? rawMatchIndex : void 0,
2236
- expectedMatchCount: hasValidMatchPair ? rawExpectedMatchCount : void 0
2240
+ expectedMatchCount: hasValidMatchPair ? rawExpectedMatchCount : void 0,
2241
+ stateKey: typeof value.stateKey === "string" && value.stateKey.trim() ? value.stateKey.trim() : void 0,
2242
+ stateKind: typeof value.stateKind === "string" && value.stateKind.trim() ? value.stateKind.trim() : void 0,
2243
+ expect: typeof value.expect === "string" && value.expect.trim() ? value.expect.trim() : void 0
2237
2244
  };
2238
2245
  }
2239
2246
  function nonEmpty(value) {
@@ -2316,6 +2323,10 @@ function descriptionForStep(action, stepAction, metadata) {
2316
2323
  return `Assert ${label} is visible`;
2317
2324
  case "assertText":
2318
2325
  return `Assert ${label} shows "${action.value ?? action.innerText ?? ""}"`;
2326
+ case "captureState":
2327
+ return `Capture UI state "${metadata.stateKey ?? label}" (${metadata.stateKind ?? "list_ids"})`;
2328
+ case "assertStateDelta":
2329
+ return `Assert state delta "${metadata.stateKey ?? label}" expect=${metadata.expect ?? action.value ?? "changed"}`;
2319
2330
  default:
2320
2331
  return `Execute ${stepAction}`;
2321
2332
  }
@@ -2361,6 +2372,8 @@ function buildMobileStep(action, order) {
2361
2372
  step.assertion = `${labelForAction(action, metadata)} should be visible`;
2362
2373
  } else if (stepAction === "assertText") {
2363
2374
  step.assertion = action.value ?? action.innerText ?? void 0;
2375
+ } else if (stepAction === "assertStateDelta") {
2376
+ step.assertion = metadata.expect ?? action.value ?? "changed";
2364
2377
  }
2365
2378
  if ((stepAction === "swipe" || stepAction === "scroll") && (metadata.direction || metadata.distance)) {
2366
2379
  const stepMetadata = ensureMetadata(step);
@@ -2369,6 +2382,24 @@ function buildMobileStep(action, order) {
2369
2382
  if (metadata.distance)
2370
2383
  stepMetadata.distance = metadata.distance;
2371
2384
  }
2385
+ if (stepAction === "captureState" || stepAction === "assertStateDelta") {
2386
+ const stepMetadata = ensureMetadata(step);
2387
+ const stateKey = nonEmpty(metadata.stateKey) ?? nonEmpty(action.selector) ?? nonEmpty(metadata.targetLabel) ?? `state-${order}`;
2388
+ stepMetadata.stateKey = stateKey;
2389
+ if (stepAction === "captureState") {
2390
+ stepMetadata.stateKind = nonEmpty(metadata.stateKind) ?? "list_ids";
2391
+ }
2392
+ if (stepAction === "assertStateDelta") {
2393
+ stepMetadata.expect = nonEmpty(metadata.expect) ?? nonEmpty(action.value) ?? "changed";
2394
+ }
2395
+ if (!step.target) {
2396
+ step.target = {
2397
+ primary: stateKey,
2398
+ fallbacks: [],
2399
+ screenName: metadata.screenName || "UnknownScreen"
2400
+ };
2401
+ }
2402
+ }
2372
2403
  return step;
2373
2404
  }
2374
2405
  function buildLaunchStep(target, medium, appResetOnLaunch = false) {
@@ -2580,6 +2611,9 @@ function buildAppiumCode(testName, target, steps) {
2580
2611
  used.find = true;
2581
2612
  }
2582
2613
  break;
2614
+ case "captureState":
2615
+ case "assertStateDelta":
2616
+ break;
2583
2617
  default:
2584
2618
  break;
2585
2619
  }
@@ -2698,6 +2732,8 @@ function buildAppiumCode(testName, target, steps) {
2698
2732
  const expectedLiteral = toJsStringLiteral(step.assertion ?? "");
2699
2733
  const replayExpected = step.assertion?.includes("{{") ? `resolveValue(${expectedLiteral})` : expectedLiteral;
2700
2734
  pushAction(`await expectText(driver, ${sel}, ${replayExpected});`);
2735
+ } else if (step.action === "captureState" || step.action === "assertStateDelta") {
2736
+ lines.push(` // ${step.action}: ${step.description.replace(/\n/g, " ").slice(0, 120)}`);
2701
2737
  } else if (step.action === "back") {
2702
2738
  lines.push(` await driver.back();`);
2703
2739
  } else if (step.action === "home") {
@@ -3040,7 +3076,9 @@ var init_mobile_test_generation = __esm({
3040
3076
  HOME: "home",
3041
3077
  WAIT_FOR_ELEMENT: "waitForElement",
3042
3078
  ASSERT_VISIBLE: "assertVisible",
3043
- ASSERT_TEXT: "assertText"
3079
+ ASSERT_TEXT: "assertText",
3080
+ CAPTURE_STATE: "captureState",
3081
+ ASSERT_STATE_DELTA: "assertStateDelta"
3044
3082
  };
3045
3083
  MOBILE_VALUE_PLACEHOLDER_RE = /\{\{([A-Za-z0-9_]+)\}\}/g;
3046
3084
  }
@@ -3271,7 +3309,9 @@ var init_mobile_step_healer = __esm({
3271
3309
  "home",
3272
3310
  "waitForElement",
3273
3311
  "assertVisible",
3274
- "assertText"
3312
+ "assertText",
3313
+ "captureState",
3314
+ "assertStateDelta"
3275
3315
  ]);
3276
3316
  FOREIGN_PACKAGE_RE = /\b[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*){2,}\b/gi;
3277
3317
  ANDROID_RESOURCE_OWNER_RE = /([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+):id\//gi;
@@ -80310,6 +80350,306 @@ ${JSON.stringify(gatePlan)}`;
80310
80350
  }
80311
80351
  });
80312
80352
 
80353
+ // ../runner-core/dist/services/mobile/scenario-taxonomy.js
80354
+ var require_scenario_taxonomy = __commonJS({
80355
+ "../runner-core/dist/services/mobile/scenario-taxonomy.js"(exports) {
80356
+ "use strict";
80357
+ Object.defineProperty(exports, "__esModule", { value: true });
80358
+ exports.ALL_SCENARIO_KINDS = void 0;
80359
+ exports.extractUiSignals = extractUiSignals;
80360
+ exports.requiredScenarioKinds = requiredScenarioKinds;
80361
+ exports.coverageGaps = coverageGaps;
80362
+ exports.inferScenarioKind = inferScenarioKind;
80363
+ exports.inferScenarioKinds = inferScenarioKinds;
80364
+ exports.isStrongOracleKind = isStrongOracleKind;
80365
+ exports.formatRequiredScenarioKindsPrompt = formatRequiredScenarioKindsPrompt;
80366
+ exports.formatCoverageGapLog = formatCoverageGapLog;
80367
+ exports.ALL_SCENARIO_KINDS = [
80368
+ "smoke_nav",
80369
+ "happy_submit",
80370
+ "negative_validation",
80371
+ "crud_identity",
80372
+ "count_delta",
80373
+ "persistence_roundtrip",
80374
+ "auth_session",
80375
+ "navigation_integrity",
80376
+ "permission_system",
80377
+ "double_submit"
80378
+ ];
80379
+ var DELETE_RE = /\b(delete|remove|archive|trash)\b/i;
80380
+ var EMAIL_RE = /\b(e-?mail|email address)\b/i;
80381
+ var PASSWORD_RE = /\b(password|passcode|pin)\b/i;
80382
+ var SIGN_OUT_RE = /\b(sign\s*out|log\s*out|logout)\b/i;
80383
+ var TOGGLE_RE = /\b(toggle|switch|enable|disable|on\/off)\b/i;
80384
+ var SUBMIT_RE = /\b(submit|save|send|create|confirm|apply|done|update|post)\b/i;
80385
+ var BADGE_OR_COUNT_RE = /\b(\d+)\s*(item|items|open|unread|invoice|message|result|pending|new)\b/i;
80386
+ var BADGE_LABEL_RE = /\b(badge|count|open invoices|unread|notifications?)\b/i;
80387
+ var PERMISSION_RE = /\b(camera|microphone|location|photos?|permission|allow access|not now)\b/i;
80388
+ var SETTINGS_RE = /\b(settings|preferences|profile|account)\b/i;
80389
+ var TAB_RE = /\b(tab|home|catalog|forms|edges|inbox|feed|dashboard)\b/i;
80390
+ function elementText(el) {
80391
+ return [
80392
+ el.label ?? "",
80393
+ el.text ?? "",
80394
+ el.accessibilityId ?? "",
80395
+ el.resourceId ?? "",
80396
+ el.role ?? ""
80397
+ ].join(" ");
80398
+ }
80399
+ function isEditable(el) {
80400
+ const role = el.role ?? "";
80401
+ return /EditText|TextField|SecureTextField|SearchField|AutoComplete|textbox|searchbox/i.test(role) || el.role === "textbox" || el.role === "searchbox";
80402
+ }
80403
+ function isToggle(el) {
80404
+ const role = el.role ?? "";
80405
+ return /Switch|CheckBox|Toggle|RadioButton/i.test(role) || TOGGLE_RE.test(elementText(el));
80406
+ }
80407
+ function isRowAction(el) {
80408
+ const t = elementText(el);
80409
+ return DELETE_RE.test(t) && el.actionable !== false;
80410
+ }
80411
+ function extractUiSignals(graph, appId) {
80412
+ const screens = [...graph.screens.values()].filter((s) => {
80413
+ if (!appId)
80414
+ return true;
80415
+ return s.screenId === appId || s.screenId.startsWith(`${appId}#`) || s.screenId.startsWith(`${appId}.`);
80416
+ });
80417
+ let hasListWithRowActions = false;
80418
+ let hasFormFields = false;
80419
+ let hasEmailField = false;
80420
+ let hasNumericBadge = false;
80421
+ let hasSettingsToggles = false;
80422
+ let hasSignOut = false;
80423
+ let hasDestructiveConfirm = false;
80424
+ let hasPrimarySubmit = false;
80425
+ let hasTabOrDrawerNav = false;
80426
+ let hasPermissionCopy = false;
80427
+ for (const state2 of screens) {
80428
+ const labels = state2.elements.map(elementText);
80429
+ const blob = [state2.screenName ?? "", state2.screenType ?? "", ...state2.observations ?? [], ...labels].join(" ");
80430
+ if (PASSWORD_RE.test(blob) || state2.elements.some(isEditable))
80431
+ hasFormFields = true;
80432
+ if (labels.some((t) => EMAIL_RE.test(t)) || state2.elements.some((el) => isEditable(el) && EMAIL_RE.test(elementText(el)))) {
80433
+ hasEmailField = true;
80434
+ hasFormFields = true;
80435
+ }
80436
+ if (state2.elements.some(isRowAction))
80437
+ hasListWithRowActions = true;
80438
+ if (!hasListWithRowActions && state2.elements.filter((el) => el.actionable).length >= 6 && DELETE_RE.test(blob)) {
80439
+ hasListWithRowActions = true;
80440
+ }
80441
+ if (BADGE_OR_COUNT_RE.test(blob) || BADGE_LABEL_RE.test(blob))
80442
+ hasNumericBadge = true;
80443
+ if (state2.elements.some(isToggle) || SETTINGS_RE.test(blob) && TOGGLE_RE.test(blob)) {
80444
+ hasSettingsToggles = true;
80445
+ }
80446
+ if (SIGN_OUT_RE.test(blob))
80447
+ hasSignOut = true;
80448
+ if (DELETE_RE.test(blob) && /\b(confirm|are you sure|permanently)\b/i.test(blob)) {
80449
+ hasDestructiveConfirm = true;
80450
+ }
80451
+ if (labels.some((t) => SUBMIT_RE.test(t)))
80452
+ hasPrimarySubmit = true;
80453
+ if (TAB_RE.test(blob) || state2.screenType === "TAB" || /\btab\b/i.test(state2.screenName ?? "")) {
80454
+ hasTabOrDrawerNav = true;
80455
+ }
80456
+ if (PERMISSION_RE.test(blob) || state2.screenType === "PERMISSION")
80457
+ hasPermissionCopy = true;
80458
+ }
80459
+ return {
80460
+ hasListWithRowActions,
80461
+ hasFormFields,
80462
+ hasEmailField,
80463
+ hasNumericBadge,
80464
+ hasSettingsToggles,
80465
+ hasSignOut,
80466
+ hasDestructiveConfirm,
80467
+ hasPrimarySubmit,
80468
+ hasTabOrDrawerNav,
80469
+ hasPermissionCopy
80470
+ };
80471
+ }
80472
+ function requiredScenarioKinds(signals) {
80473
+ const kinds = /* @__PURE__ */ new Set(["smoke_nav"]);
80474
+ if (signals.hasFormFields || signals.hasPrimarySubmit) {
80475
+ kinds.add("happy_submit");
80476
+ }
80477
+ if (signals.hasFormFields || signals.hasEmailField) {
80478
+ kinds.add("negative_validation");
80479
+ }
80480
+ if (signals.hasListWithRowActions) {
80481
+ kinds.add("crud_identity");
80482
+ }
80483
+ if (signals.hasNumericBadge) {
80484
+ kinds.add("count_delta");
80485
+ }
80486
+ if (signals.hasSettingsToggles) {
80487
+ kinds.add("persistence_roundtrip");
80488
+ }
80489
+ if (signals.hasSignOut) {
80490
+ kinds.add("auth_session");
80491
+ }
80492
+ if (signals.hasTabOrDrawerNav) {
80493
+ kinds.add("navigation_integrity");
80494
+ }
80495
+ if (signals.hasPermissionCopy) {
80496
+ kinds.add("permission_system");
80497
+ }
80498
+ if (signals.hasPrimarySubmit && signals.hasFormFields) {
80499
+ kinds.add("double_submit");
80500
+ }
80501
+ return exports.ALL_SCENARIO_KINDS.filter((k) => kinds.has(k));
80502
+ }
80503
+ function coverageGaps(signals, plannedKinds) {
80504
+ const planned = new Set(plannedKinds);
80505
+ return requiredScenarioKinds(signals).filter((k) => !planned.has(k));
80506
+ }
80507
+ function inferScenarioKind(scenario) {
80508
+ const text = `${scenario.name} ${scenario.goal} ${scenario.variant ?? ""} ${scenario.type}`.toLowerCase();
80509
+ if (/\b(invalid|empty|required|validation|too short|malformed|reject|error message)\b/.test(text) || scenario.variant === "validation" || scenario.type === "EDGE_CASE" && /\b(empty|invalid|required)\b/.test(text)) {
80510
+ return "negative_validation";
80511
+ }
80512
+ if (/\b(delete|remove|wrong row|entity|archive)\b/.test(text) && /\b(list|row|item|record)\b/.test(text)) {
80513
+ return "crud_identity";
80514
+ }
80515
+ if (/\b(badge|count|unread|open invoices|\+\d|increment|decrement)\b/.test(text)) {
80516
+ return "count_delta";
80517
+ }
80518
+ if (/\b(persist|revisit|return|leave|settings|toggle|favorite|remember)\b/.test(text)) {
80519
+ return "persistence_roundtrip";
80520
+ }
80521
+ if (/\b(sign\s*out|log\s*out|session|sign\s*in|remember me|auth)\b/.test(text) || scenario.type === "HAPPY_PATH" && /\b(login|sign in)\b/.test(text)) {
80522
+ return "auth_session";
80523
+ }
80524
+ if (/\b(tab|navigate|navigation|back|deep link|empty.?state)\b/.test(text)) {
80525
+ return "navigation_integrity";
80526
+ }
80527
+ if (/\b(permission|camera|microphone|location|allow)\b/.test(text)) {
80528
+ return "permission_system";
80529
+ }
80530
+ if (/\b(double|twice|duplicate submit|double.?tap)\b/.test(text)) {
80531
+ return "double_submit";
80532
+ }
80533
+ if (scenario.type === "HAPPY_PATH" || scenario.variant === "happy") {
80534
+ return "happy_submit";
80535
+ }
80536
+ if (scenario.type === "USER_JOURNEY" || scenario.type === "REGRESSION") {
80537
+ return "navigation_integrity";
80538
+ }
80539
+ return "smoke_nav";
80540
+ }
80541
+ function inferScenarioKinds(scenarios) {
80542
+ return [...new Set(scenarios.map(inferScenarioKind))];
80543
+ }
80544
+ function isStrongOracleKind(kind) {
80545
+ return kind !== "smoke_nav" && kind !== "navigation_integrity";
80546
+ }
80547
+ function formatRequiredScenarioKindsPrompt(signals) {
80548
+ const required = requiredScenarioKinds(signals);
80549
+ if (required.length === 0)
80550
+ return "";
80551
+ const lines = required.map((kind) => {
80552
+ switch (kind) {
80553
+ case "smoke_nav":
80554
+ return '- smoke_nav: reach a primary destination and prove it with a durable product signal (not only "tab visible")';
80555
+ case "happy_submit":
80556
+ return "- happy_submit: complete a form/primary action and assert the durable result (new row, saved state, success that outlives a toast)";
80557
+ case "negative_validation":
80558
+ return "- negative_validation: submit empty/invalid input (e.g. empty required, malformed email-like field) and assert error OR blocked submit \u2014 never invent success copy";
80559
+ case "crud_identity":
80560
+ return '- crud_identity: create or note an entity id/label, perform delete/edit on THAT entity, assert identity set changed correctly (not "list still visible")';
80561
+ case "count_delta":
80562
+ return "- count_delta: capture a numeric badge/count, perform an action, assert the number changed as expected";
80563
+ case "persistence_roundtrip":
80564
+ return "- persistence_roundtrip: change a setting/toggle, leave the screen (or relaunch if policy allows), return, assert value persisted";
80565
+ case "auth_session":
80566
+ return "- auth_session: prove sign-in session (profile/sign-out) and/or sign-out leaves only logged-out chrome";
80567
+ case "navigation_integrity":
80568
+ return "- navigation_integrity: tab/drawer/back reaches the intended screen family";
80569
+ case "permission_system":
80570
+ return "- permission_system: permission prompt or settings path behaves honestly (allow/deny/settings)";
80571
+ case "double_submit":
80572
+ return "- double_submit: single user intent must not double-create (assert count +1 not +2, or single confirmation)";
80573
+ default:
80574
+ return `- ${kind}`;
80575
+ }
80576
+ });
80577
+ return "## Required scenario kinds (from observed UI \u2014 fill each or explain impossibility in reasoning)\nThese kinds are derived ONLY from controls/screens the explorer saw. Plan at least one scenario per kind when evidence supports it.\n" + lines.join("\n");
80578
+ }
80579
+ function formatCoverageGapLog(gaps) {
80580
+ if (gaps.length === 0)
80581
+ return "Scenario taxonomy: all required kinds covered by plan";
80582
+ return `Scenario taxonomy coverage gaps (required but not planned): ${gaps.join(", ")}`;
80583
+ }
80584
+ }
80585
+ });
80586
+
80587
+ // ../runner-core/dist/services/mobile/coverage-map.js
80588
+ var require_coverage_map = __commonJS({
80589
+ "../runner-core/dist/services/mobile/coverage-map.js"(exports) {
80590
+ "use strict";
80591
+ Object.defineProperty(exports, "__esModule", { value: true });
80592
+ exports.buildMobileCoverageMap = buildMobileCoverageMap;
80593
+ var scenario_taxonomy_js_1 = require_scenario_taxonomy();
80594
+ function strongLookup(name, map2) {
80595
+ if (!map2)
80596
+ return false;
80597
+ if (map2 instanceof Map)
80598
+ return map2.get(name) === true;
80599
+ return Object.prototype.hasOwnProperty.call(map2, name) && map2[name] === true;
80600
+ }
80601
+ function buildMobileCoverageMap(input) {
80602
+ const signals = (0, scenario_taxonomy_js_1.extractUiSignals)(input.graph, input.appId);
80603
+ const required = (0, scenario_taxonomy_js_1.requiredScenarioKinds)(signals);
80604
+ const planned = input.plannedScenarios ?? [];
80605
+ const plannedKinds = planned.map(scenario_taxonomy_js_1.inferScenarioKind);
80606
+ const plannedSet = new Set(plannedKinds);
80607
+ const gaps = (0, scenario_taxonomy_js_1.coverageGaps)(signals, plannedKinds);
80608
+ const kindsWithStrong = /* @__PURE__ */ new Set();
80609
+ for (const s of planned) {
80610
+ const kind = (0, scenario_taxonomy_js_1.inferScenarioKind)(s);
80611
+ const isStrong = (0, scenario_taxonomy_js_1.isStrongOracleKind)(kind) || strongLookup(s.name, input.strongByScenarioName);
80612
+ if (isStrong)
80613
+ kindsWithStrong.add(kind);
80614
+ }
80615
+ const warnings = [];
80616
+ const entries = required.map((kind) => {
80617
+ const isPlanned = plannedSet.has(kind);
80618
+ const strongPlanned = kindsWithStrong.has(kind);
80619
+ let warning;
80620
+ if (!isPlanned) {
80621
+ warning = `Required kind "${kind}" has no planned scenario`;
80622
+ warnings.push(warning);
80623
+ } else if (!strongPlanned && (0, scenario_taxonomy_js_1.isStrongOracleKind)(kind)) {
80624
+ warning = `Kind "${kind}" is planned but has no strong-oracle scenario (smoke-only coverage)`;
80625
+ warnings.push(warning);
80626
+ }
80627
+ return {
80628
+ kind,
80629
+ required: true,
80630
+ planned: isPlanned,
80631
+ strongPlanned,
80632
+ warning
80633
+ };
80634
+ });
80635
+ if (planned.length > 0 && plannedKinds.every((k) => k === "smoke_nav" || k === "navigation_integrity")) {
80636
+ const w = "All planned scenarios are smoke/nav \u2014 no strong product oracles";
80637
+ if (!warnings.includes(w))
80638
+ warnings.push(w);
80639
+ }
80640
+ const summary = warnings.length === 0 ? `Coverage map: ${required.length} required kinds, all covered with strong scenarios where needed` : `Coverage map: ${warnings.length} warning(s); ${(0, scenario_taxonomy_js_1.formatCoverageGapLog)(gaps)}`;
80641
+ return {
80642
+ signals,
80643
+ requiredKinds: required,
80644
+ gaps,
80645
+ entries,
80646
+ warnings,
80647
+ summary
80648
+ };
80649
+ }
80650
+ }
80651
+ });
80652
+
80313
80653
  // ../runner-core/dist/services/mobile/mobile-discovery-prompts.js
80314
80654
  var require_mobile_discovery_prompts = __commonJS({
80315
80655
  "../runner-core/dist/services/mobile/mobile-discovery-prompts.js"(exports) {
@@ -80327,6 +80667,8 @@ var require_mobile_discovery_prompts = __commonJS({
80327
80667
  var ai_provider_js_1 = require_ai_provider();
80328
80668
  var discover_ai_planner_js_1 = require_discover_ai_planner();
80329
80669
  var mobile_observation_js_1 = require_mobile_observation();
80670
+ var scenario_taxonomy_js_1 = require_scenario_taxonomy();
80671
+ var coverage_map_js_1 = require_coverage_map();
80330
80672
  function isTargetAppScreenId(screenId, appId) {
80331
80673
  if (!appId)
80332
80674
  return true;
@@ -80408,7 +80750,7 @@ Return ONLY one valid JSON object matching the schema below. Do NOT include <thi
80408
80750
  9. **No duplicates** - check existing test names before adding
80409
80751
  10. **All tests start from the app launch entry** - every generated test starts by launching the target app. The runner clears app data when the device/reset policy safely supports it; otherwise it performs a terminate + activate relaunch, which can preserve app session data. Therefore scenarios MUST navigate through the app's own UI from whatever launch state is valid, and MUST NOT rely on mutable data from a prior scenario disappearing. Steps must reflect this: say "Launch the app and tap Sign In" not "deep-link to the login screen". Do NOT navigate by deep-link; the app's launch + tab/drawer navigation is the only entry path. \`targetPages\` lists the screen-ids involved in the flow.
80410
80752
  11. **targetPages must be copied CHARACTER-FOR-CHARACTER from the screen-ids in the evidence** (they look like \`com.example.app.MainActivity#ab12cd34\`). NEVER invent, prettify, or abbreviate them \u2014 no "Landing", "AUTH", "Home Screen", or any name that is not literally in the provided screens. A scenario whose targetPages contains even ONE id not present in the evidence is REJECTED WHOLESALE by the validator, so a single made-up route silently destroys the entire scenario. If you are unsure which screen-id a step touches, use the screen-id of the screen where the flow STARTS.
80411
- 12. **Happy paths must verify the DURABLE OUTCOME, not just the trigger.** A HAPPY_PATH is NOT complete until it verifies the feature's real output. "Button tapped" / "Sheet opened" / "Spinner appeared" / "Settings screen opened" is NOT a happy path - that is a UI interaction test. Form-mutation happy paths (change password, create/edit/save a record, send a message, checkout, etc.) MUST include typing into the relevant fields AND committing the form (submit/save/send or keyboard Enter/Done) \u2014 navigating to the form screen alone is insufficient. Apply this to any feature where an action produces a result the user then sees or uses: CRUD creates, photo/file uploads, searches that return results, imports, exports, payments, messages sent, AI/ML outputs, generated documents, sync runs, analysis runs, conversion, data processing. The scenario MUST include:
80753
+ 12. **Happy paths must verify the DURABLE OUTCOME, not just the trigger.** A HAPPY_PATH is NOT complete until it verifies the feature's real output. "Button tapped" / "Sheet opened" / "Spinner appeared" / "Settings screen opened" is NOT a happy path - that is a UI interaction test. When the explorer observed list rows with delete/remove, plan at least one scenario that captures entity identity before the action and asserts that identity is gone or changed afterward (not merely that the list screen is still visible). When numeric badges/counts were observed, plan a before/after count check. Form-mutation happy paths (change password, create/edit/save a record, send a message, checkout, etc.) MUST include typing into the relevant fields AND committing the form (submit/save/send or keyboard Enter/Done) \u2014 navigating to the form screen alone is insufficient. Apply this to any feature where an action produces a result the user then sees or uses: CRUD creates, photo/file uploads, searches that return results, imports, exports, payments, messages sent, AI/ML outputs, generated documents, sync runs, analysis runs, conversion, data processing. The scenario MUST include:
80412
80754
  - The trigger step (Tap Submit / Generate / Send / Upload / Run / Analyze / Save / Pay / etc.)
80413
80755
  - A wait step for the operation to complete. Phrase it by SIGNAL, not wall-clock ("Wait for the result to appear - up to 60 seconds"). Prefer signals the app actually uses: spinner disappears, status badge flips to a success state, a new row appears, an item count increments, a success toast/snackbar shows, the screen transitions to a result screen.
80414
80756
  - A verification step on the DURABLE RESULT - the thing that outlives the transient UI: a new list row, a persisted record, a received message, a committed state change, visible output text. Do NOT assert on the spinner disappearing alone; assert on what replaced it.
@@ -80808,6 +81150,14 @@ SCOPE: this is a feature-focused deep run. Plan scenarios ONLY for the "${contex
80808
81150
  sections.push(`## Operator notes
80809
81151
  ${context.userNotes.trim()}`);
80810
81152
  }
81153
+ if (context.mode === "deep" || context.mode === "full") {
81154
+ const signals = (0, scenario_taxonomy_js_1.extractUiSignals)(graph, context.appId);
81155
+ const requiredBlock = (0, scenario_taxonomy_js_1.formatRequiredScenarioKindsPrompt)(signals);
81156
+ if (requiredBlock) {
81157
+ sections.push(requiredBlock);
81158
+ sections.push('## Scenario kind coverage rules\n1. Prefer scenarios whose expectedOutcomes prove durable product results (state deltas, validation errors, persistence), not only "control X is visible".\n2. For negative_validation: empty required field and/or malformed email-like input when an email field was observed.\n3. For crud_identity: assert the specific entity identity is gone/changed \u2014 never only that the list screen is still visible.\n4. For count_delta: mention the before/after numeric expectation in expectedOutcomes.\n5. If a required kind is impossible given evidence, say so in "reasoning" \u2014 do not invent unobserved screens.');
81159
+ }
81160
+ }
80811
81161
  const orderedScreens = plannableTargetAppScreens(graph, context.appId).sort((a, b) => a.firstSeenIteration - b.firstSeenIteration || a.screenId.localeCompare(b.screenId));
80812
81162
  const includedScreenIds = new Set(orderedScreens.map((state2) => state2.screenId));
80813
81163
  const maxElementsPerScreen = context.mode === "survey" ? SURVEY_MAX_ELEMENTS_PER_SCREEN : MAX_ELEMENTS_PER_SCREEN;
@@ -81531,6 +81881,43 @@ ${constraints.join("\n")}`);
81531
81881
  mobileAdaptationLogs.push(`Dropped ${guestWallFilter.dropped} guest-wall scenario(s) \u2014 explore session was authenticated; re-exec would not see sign-in gates`);
81532
81882
  }
81533
81883
  const plannedScenarios = guestWallFilter.scenarios;
81884
+ let taxonomyGapLogs = [];
81885
+ let taxonomyCoverageGaps = result.coverageGaps ?? [];
81886
+ if (input.mode !== "survey" && plannedScenarios.length > 0) {
81887
+ const signals = (0, scenario_taxonomy_js_1.extractUiSignals)(input.graph, input.appId);
81888
+ const plannedKinds = (0, scenario_taxonomy_js_1.inferScenarioKinds)(plannedScenarios);
81889
+ const gaps = (0, scenario_taxonomy_js_1.coverageGaps)(signals, plannedKinds);
81890
+ const coverageMap = (0, coverage_map_js_1.buildMobileCoverageMap)({
81891
+ graph: input.graph,
81892
+ appId: input.appId,
81893
+ plannedScenarios
81894
+ });
81895
+ taxonomyGapLogs = [(0, scenario_taxonomy_js_1.formatCoverageGapLog)(gaps), coverageMap.summary];
81896
+ if (coverageMap.warnings.length > 0) {
81897
+ taxonomyGapLogs.push(...coverageMap.warnings.slice(0, 12));
81898
+ }
81899
+ if (gaps.length > 0) {
81900
+ taxonomyGapLogs.push(`UI signals: listRowActions=${signals.hasListWithRowActions} forms=${signals.hasFormFields} email=${signals.hasEmailField} badge=${signals.hasNumericBadge} toggles=${signals.hasSettingsToggles} signOut=${signals.hasSignOut} tabs=${signals.hasTabOrDrawerNav}`);
81901
+ const detectedAt = (/* @__PURE__ */ new Date()).toISOString();
81902
+ taxonomyCoverageGaps = [
81903
+ ...taxonomyCoverageGaps,
81904
+ ...gaps.map((kind) => ({
81905
+ scenarioName: `[taxonomy] ${kind}`,
81906
+ reason: `Required scenario kind "${kind}" not represented in the planned set`,
81907
+ suggestion: `Add a ${kind} scenario backed by observed controls, or document impossibility`,
81908
+ unmetPrerequisites: [],
81909
+ detectedAt
81910
+ })),
81911
+ ...coverageMap.warnings.filter((w) => /smoke-only|no strong-oracle/i.test(w)).map((w) => ({
81912
+ scenarioName: "[coverage-map] strong-oracle gap",
81913
+ reason: w,
81914
+ suggestion: "Author durable assertStateDelta/assertText outcomes for this kind",
81915
+ unmetPrerequisites: [],
81916
+ detectedAt
81917
+ }))
81918
+ ];
81919
+ }
81920
+ }
81534
81921
  if (input.mode !== "survey" && plannedScenarios.length === 0 && input.graph.screens.size > 0) {
81535
81922
  const fallbackScenarios = buildMobileFallbackScenarios(input);
81536
81923
  if (fallbackScenarios.length > 0) {
@@ -81589,7 +81976,8 @@ ${constraints.join("\n")}`);
81589
81976
  ...result,
81590
81977
  scenarios: plannedScenarios,
81591
81978
  featureGroups: mobileFeatureGroups,
81592
- logs: [...result.logs, ...mobileAdaptationLogs]
81979
+ coverageGaps: taxonomyCoverageGaps.length > 0 ? taxonomyCoverageGaps : result.coverageGaps,
81980
+ logs: [...result.logs, ...mobileAdaptationLogs, ...taxonomyGapLogs]
81593
81981
  };
81594
81982
  }
81595
81983
  }
@@ -81668,6 +82056,7 @@ var require_mobile_generator = __commonJS({
81668
82056
  var ai_retry_js_1 = require_ai_retry();
81669
82057
  var mobile_session_keepalive_js_1 = require_mobile_session_keepalive();
81670
82058
  var discovery_lint_flags_js_1 = require_discovery_lint_flags();
82059
+ var scenario_taxonomy_js_1 = require_scenario_taxonomy();
81671
82060
  var mobile_source_parser_js_1 = require_mobile_source_parser();
81672
82061
  var mobile_source_parser_js_2 = require_mobile_source_parser();
81673
82062
  var mobile_observation_js_1 = require_mobile_observation();
@@ -81809,6 +82198,50 @@ var require_mobile_generator = __commonJS({
81809
82198
  }
81810
82199
  }
81811
82200
  };
82201
+ var MOBILE_CAPTURE_STATE_TOOL = {
82202
+ type: "function",
82203
+ function: {
82204
+ name: "mobile_capture_state",
82205
+ description: 'Capture list labels or numeric badge counts into a named state key BEFORE a mutating action (delete/create/toggle). Pair with mobile_assert_state_delta afterward to prove durable identity/count outcomes \u2014 stronger than "list still visible".',
82206
+ parameters: {
82207
+ type: "object",
82208
+ properties: {
82209
+ stateKey: {
82210
+ type: "string",
82211
+ description: 'Short key for this bag entry (e.g. "invoice_list", "open_count"). Reuse the same key in mobile_assert_state_delta.'
82212
+ },
82213
+ kind: {
82214
+ type: "string",
82215
+ enum: ["list_ids", "badge_count"],
82216
+ description: "list_ids = unique visible labels; badge_count = numeric count tokens. Default list_ids."
82217
+ }
82218
+ },
82219
+ required: ["stateKey"]
82220
+ }
82221
+ }
82222
+ };
82223
+ var MOBILE_ASSERT_STATE_DELTA_TOOL = {
82224
+ type: "function",
82225
+ function: {
82226
+ name: "mobile_assert_state_delta",
82227
+ description: "Compare the current screen to a prior mobile_capture_state. Verifies LIVE then records assertStateDelta. Use after delete/create/count-changing actions. expect: changed | entity_removed | count_decreased | count_increased | unchanged | persisted.",
82228
+ parameters: {
82229
+ type: "object",
82230
+ properties: {
82231
+ stateKey: {
82232
+ type: "string",
82233
+ description: "Must match a prior mobile_capture_state stateKey in this scenario."
82234
+ },
82235
+ expect: {
82236
+ type: "string",
82237
+ enum: ["changed", "entity_removed", "count_decreased", "count_increased", "unchanged", "persisted"],
82238
+ description: "What must differ (or persist) vs the prior capture. Default: changed."
82239
+ }
82240
+ },
82241
+ required: ["stateKey"]
82242
+ }
82243
+ }
82244
+ };
81812
82245
  var MOBILE_FILL_CREDENTIAL_TOOL = {
81813
82246
  type: "function",
81814
82247
  function: {
@@ -81831,7 +82264,7 @@ var require_mobile_generator = __commonJS({
81831
82264
  type: "function",
81832
82265
  function: {
81833
82266
  name: "finish_generate",
81834
- description: "Call when the scenario is fully exercised and its outcome is asserted. verified:true requires you to have called at least one assert tool (mobile_assert_visible / mobile_assert_text) \u2014 claiming verified without any assert is auto-downgraded.",
82267
+ description: "Call when the scenario is fully exercised and its outcome is asserted. verified:true requires you to have called at least one assert tool (mobile_assert_visible / mobile_assert_text / mobile_assert_state_delta) \u2014 claiming verified without any assert is auto-downgraded.",
81835
82268
  parameters: {
81836
82269
  type: "object",
81837
82270
  properties: {
@@ -81863,6 +82296,8 @@ var require_mobile_generator = __commonJS({
81863
82296
  MOBILE_RELAUNCH_TOOL,
81864
82297
  MOBILE_ASSERT_VISIBLE_TOOL,
81865
82298
  MOBILE_ASSERT_TEXT_TOOL,
82299
+ MOBILE_CAPTURE_STATE_TOOL,
82300
+ MOBILE_ASSERT_STATE_DELTA_TOOL,
81866
82301
  FINISH_GENERATE_TOOL
81867
82302
  ];
81868
82303
  var STRUCTURAL_KEY_MAX_ELEMENTS = 16;
@@ -82129,6 +82564,7 @@ The scenario name + goal + steps describe ONE product behavior from survey/disco
82129
82564
  - Navigation scenarios: you MUST land on the destination and assert something unique to it.
82130
82565
  4. PROVE the outcome with an assert tool that matches the scenario \u2014 not ambient chrome:
82131
82566
  - mobile_assert_visible({ref}) / mobile_assert_text({ref, expected})
82567
+ - For list delete/create or count changes: mobile_capture_state({stateKey, kind}) BEFORE the mutation, then mobile_assert_state_delta({stateKey, expect}) AFTER \u2014 proves identity/count change, not only "list screen still visible".
82132
82568
  - After sign-in \u2192 signed-in product signal; after like \u2192 liked/unlike control or durable like state; after open Settings \u2192 a settings-specific control.
82133
82569
  - Do NOT assert bottom-nav tab labels alone, notification badge counts ("N unread"), or one-time empty-state CTAs as the scenario outcome.
82134
82570
  5. Call finish_generate with verified:true ONLY if you completed the goal AND asserted a matching durable outcome. If the app cannot complete the goal, finish with verified:false and explain \u2014 never invent a green path from unrelated screens.
@@ -82242,6 +82678,7 @@ Start by calling mobile_snapshot, then execute ONLY the steps needed for this go
82242
82678
  const { scenario, driver, platform: platform3, maxIterations, agentModel, provider, aiClient, auditGroupId, onAICall, onScreenshot, targetAppId, credentials, redactionCredentials, log: emitLog, allowRelaunch } = args;
82243
82679
  const log2 = (line) => emitLog(redactCredentialValues(line, redactionCredentials));
82244
82680
  const actions = [];
82681
+ const stateBag = /* @__PURE__ */ new Map();
82245
82682
  let assertCount = 0;
82246
82683
  let finish = null;
82247
82684
  let finishIntentRejections = 0;
@@ -82711,7 +83148,9 @@ ${statePacket}`, redactionCredentials) },
82711
83148
  const screenDependentTools = /* @__PURE__ */ new Set([
82712
83149
  ...screenMutatingTools,
82713
83150
  "mobile_assert_visible",
82714
- "mobile_assert_text"
83151
+ "mobile_assert_text",
83152
+ "mobile_capture_state",
83153
+ "mobile_assert_state_delta"
82715
83154
  ]);
82716
83155
  for (const toolCall of assistantMessage.tool_calls) {
82717
83156
  const toolName = toolCall.function.name;
@@ -82755,7 +83194,7 @@ ${statePacket}`, redactionCredentials) },
82755
83194
  if (intentReason)
82756
83195
  reasons.push(intentReason);
82757
83196
  if (verifiedWithoutAssert) {
82758
- reasons.push("claimed verified:true but never called mobile_assert_visible / mobile_assert_text");
83197
+ reasons.push("claimed verified:true but never called mobile_assert_visible / mobile_assert_text / mobile_assert_state_delta");
82759
83198
  }
82760
83199
  if (strengthRejectReason !== null) {
82761
83200
  reasons.push(`assertion strength: ${strengthRejectReason} \u2014 your only live proof re-checks a control you already used. Assert the scenario OUTCOME instead: an element on the resulting screen, the created/updated row, or the success/error message.`);
@@ -82826,10 +83265,12 @@ ${statePacket}`, redactionCredentials) },
82826
83265
  }
82827
83266
  } : action;
82828
83267
  actions.push((0, shared_1.placeholderizeRecordedMobileAction)(finalizeAction(stamped), credentials));
82829
- if (action.type === "ASSERT_VISIBLE" || action.type === "ASSERT_TEXT")
83268
+ if (action.type === "ASSERT_VISIBLE" || action.type === "ASSERT_TEXT" || action.type === "ASSERT_STATE_DELTA") {
82830
83269
  assertCount++;
83270
+ }
82831
83271
  },
82832
83272
  recordedActions: actions,
83273
+ stateBag,
82833
83274
  log: log2
82834
83275
  });
82835
83276
  if (screenMutatingTools.has(toolName))
@@ -82848,7 +83289,7 @@ ${statePacket}`, redactionCredentials) },
82848
83289
  return { actions, assertCount, finish, lastSnapshot: lastTargetSnapshot, lastScreenName: lastTargetScreenName };
82849
83290
  }
82850
83291
  async function dispatchGenerateTool(args) {
82851
- const { toolName, toolArgs, driver, platform: platform3, targetAppId, latest, absorbObservation, resolveRef, resolveHybridRef, maybeEnrichHybridWeb, setLatest, credentials, screenName, allowRelaunch, recordAction, recordedActions, log: log2 } = args;
83292
+ const { toolName, toolArgs, driver, platform: platform3, targetAppId, latest, absorbObservation, resolveRef, resolveHybridRef, maybeEnrichHybridWeb, setLatest, credentials, screenName, allowRelaunch, recordAction, recordedActions, stateBag, log: log2 } = args;
82852
83293
  const unknownRef = (ref) => ({
82853
83294
  ok: false,
82854
83295
  error: `Unknown element ref "${String(ref)}". Call mobile_snapshot first; refs are only valid for the latest snapshot.`
@@ -83393,10 +83834,170 @@ ${statePacket}`, redactionCredentials) },
83393
83834
  target: metadata.targetLabel
83394
83835
  };
83395
83836
  }
83837
+ case "mobile_capture_state": {
83838
+ const stateKey = nonEmpty3(typeof toolArgs.stateKey === "string" ? toolArgs.stateKey : "");
83839
+ if (!stateKey) {
83840
+ return { ok: false, error: "mobile_capture_state requires a non-empty stateKey." };
83841
+ }
83842
+ const kindRaw = typeof toolArgs.kind === "string" ? toolArgs.kind.trim() : "list_ids";
83843
+ const kind = kindRaw === "badge_count" ? "badge_count" : "list_ids";
83844
+ const snap = latest();
83845
+ if (!snap) {
83846
+ return { ok: false, error: "No snapshot yet \u2014 call mobile_snapshot before mobile_capture_state." };
83847
+ }
83848
+ const values = captureValuesFromElements(snap.screen.elements, kind);
83849
+ stateBag.set(stateKey, { kind, values });
83850
+ recordAction({
83851
+ type: "CAPTURE_STATE",
83852
+ selector: stateKey,
83853
+ metadata: {
83854
+ screenName: screenName(),
83855
+ targetLabel: stateKey,
83856
+ stateKey,
83857
+ stateKind: kind
83858
+ }
83859
+ });
83860
+ log2(` capture_state: key=${stateKey} kind=${kind} n=${values.length}`);
83861
+ return {
83862
+ ok: true,
83863
+ captured: true,
83864
+ stateKey,
83865
+ kind,
83866
+ sample: values.slice(0, 8),
83867
+ count: values.length
83868
+ };
83869
+ }
83870
+ case "mobile_assert_state_delta": {
83871
+ const stateKey = nonEmpty3(typeof toolArgs.stateKey === "string" ? toolArgs.stateKey : "");
83872
+ if (!stateKey) {
83873
+ return { ok: false, error: "mobile_assert_state_delta requires a non-empty stateKey." };
83874
+ }
83875
+ const prior = stateBag.get(stateKey);
83876
+ if (!prior) {
83877
+ return {
83878
+ ok: false,
83879
+ error: `No prior mobile_capture_state for key "${stateKey}". Capture before the mutating action, then assert.`
83880
+ };
83881
+ }
83882
+ const expectRaw = typeof toolArgs.expect === "string" ? toolArgs.expect.trim() : "changed";
83883
+ const expect = expectRaw || "changed";
83884
+ const snap = latest();
83885
+ if (!snap) {
83886
+ return { ok: false, error: "No snapshot yet \u2014 call mobile_snapshot after the action, then assert_state_delta." };
83887
+ }
83888
+ const current = captureValuesFromElements(snap.screen.elements, prior.kind);
83889
+ const liveError = liveAssertStateDelta(prior.values, current, expect, stateKey);
83890
+ if (liveError) {
83891
+ return {
83892
+ ok: false,
83893
+ error: liveError,
83894
+ beforeSample: prior.values.slice(0, 8),
83895
+ afterSample: current.slice(0, 8)
83896
+ };
83897
+ }
83898
+ recordAction({
83899
+ type: "ASSERT_STATE_DELTA",
83900
+ value: expect,
83901
+ selector: stateKey,
83902
+ metadata: {
83903
+ screenName: screenName(),
83904
+ targetLabel: stateKey,
83905
+ stateKey,
83906
+ stateKind: prior.kind,
83907
+ expect
83908
+ }
83909
+ });
83910
+ log2(` assert_state_delta: key=${stateKey} expect=${expect}`);
83911
+ return {
83912
+ ok: true,
83913
+ asserted: "state_delta",
83914
+ stateKey,
83915
+ expect,
83916
+ beforeCount: prior.values.length,
83917
+ afterCount: current.length
83918
+ };
83919
+ }
83396
83920
  default:
83397
83921
  return { ok: false, error: `Unknown tool: ${toolName}` };
83398
83922
  }
83399
83923
  }
83924
+ function captureValuesFromElements(elements, kind) {
83925
+ if (kind === "badge_count") {
83926
+ const nums = /* @__PURE__ */ new Set();
83927
+ const preferred = /* @__PURE__ */ new Set();
83928
+ for (const el of elements) {
83929
+ const t = [el.label, el.text, el.accessibilityId].filter(Boolean).join(" ");
83930
+ for (const m of t.matchAll(/\b(\d{1,6})\b/g))
83931
+ nums.add(m[1]);
83932
+ if (/(?:count|badge|open|unread|item|invoice|result|pending)/i.test(t)) {
83933
+ for (const m of t.matchAll(/\b(\d{1,6})\b/g))
83934
+ preferred.add(m[1]);
83935
+ }
83936
+ }
83937
+ return preferred.size > 0 ? [...preferred] : [...nums].slice(0, 20);
83938
+ }
83939
+ const labels = /* @__PURE__ */ new Set();
83940
+ for (const el of elements) {
83941
+ for (const raw of [el.label, el.text, el.accessibilityId]) {
83942
+ const t = raw?.trim() ?? "";
83943
+ if (t.length < 2 || t.length > 80)
83944
+ continue;
83945
+ if (/^(true|false|null|OK|Cancel)$/i.test(t))
83946
+ continue;
83947
+ labels.add(t);
83948
+ }
83949
+ }
83950
+ return [...labels].slice(0, 80);
83951
+ }
83952
+ function liveAssertStateDelta(before, after, expect, key) {
83953
+ const beforeSet = new Set(before);
83954
+ const afterSet = new Set(after);
83955
+ const removed = before.filter((v) => !afterSet.has(v));
83956
+ const added = after.filter((v) => !beforeSet.has(v));
83957
+ const exp = expect.toLowerCase().trim();
83958
+ if (exp === "changed" || exp === "any_change") {
83959
+ if (removed.length === 0 && added.length === 0) {
83960
+ return `assertStateDelta(${key}): expected change, captures identical (${before.length} values)`;
83961
+ }
83962
+ return null;
83963
+ }
83964
+ if (exp === "removed" || exp === "entity_removed" || exp.startsWith("removed:")) {
83965
+ if (removed.length === 0) {
83966
+ return `assertStateDelta(${key}): expected at least one entity removed`;
83967
+ }
83968
+ return null;
83969
+ }
83970
+ if (exp === "count_decreased" || exp === "count-1") {
83971
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
83972
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
83973
+ const bMax = b.length ? Math.max(...b) : NaN;
83974
+ const aMax = a.length ? Math.max(...a) : NaN;
83975
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax >= bMax) {
83976
+ return `assertStateDelta(${key}): expected count decrease (before max=${bMax}, after max=${aMax})`;
83977
+ }
83978
+ return null;
83979
+ }
83980
+ if (exp === "count_increased" || exp === "count+1") {
83981
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
83982
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
83983
+ const bMax = b.length ? Math.max(...b) : NaN;
83984
+ const aMax = a.length ? Math.max(...a) : NaN;
83985
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax <= bMax) {
83986
+ return `assertStateDelta(${key}): expected count increase (before max=${bMax}, after max=${aMax})`;
83987
+ }
83988
+ return null;
83989
+ }
83990
+ if (exp === "unchanged" || exp === "persisted") {
83991
+ if (removed.length > 0 || added.length > 0) {
83992
+ return `assertStateDelta(${key}): expected persistence/unchanged but set changed`;
83993
+ }
83994
+ return null;
83995
+ }
83996
+ if (removed.length === 0 && added.length === 0) {
83997
+ return `assertStateDelta(${key}): expected change (expect=${expect}), state identical`;
83998
+ }
83999
+ return null;
84000
+ }
83400
84001
  function recordAssertVisible(toolArgs, ctx) {
83401
84002
  const { resolveRef, latest, screenName, platform: platform3, recordAction } = ctx;
83402
84003
  const element = resolveRef(toolArgs.ref);
@@ -84376,6 +84977,14 @@ ${statePacket}`, redactionCredentials) },
84376
84977
  lines.push(` await expect(page.getByText('${expected}')).toBeVisible();`);
84377
84978
  break;
84378
84979
  }
84980
+ case "CAPTURE_STATE":
84981
+ lines.push(` // captureState ${escape((action.metadata.stateKey ?? label).slice(0, 40))}`);
84982
+ break;
84983
+ case "ASSERT_STATE_DELTA": {
84984
+ const expect = escape((action.metadata.expect ?? action.value ?? "changed").slice(0, 40));
84985
+ lines.push(` await expect(page.getByText('state:${expect}')).toBeVisible();`);
84986
+ break;
84987
+ }
84379
84988
  case "CLEAR":
84380
84989
  lines.push(` await page.getByLabel('${label}').fill('');`);
84381
84990
  break;
@@ -84419,6 +85028,22 @@ ${statePacket}`, redactionCredentials) },
84419
85028
  return [action.selector, action.value, action.innerText, action.metadata?.targetLabel].filter((v) => typeof v === "string" && v.trim().length > 0).join(" ");
84420
85029
  }
84421
85030
  function evaluateMobileAssertionStrength(actions) {
85031
+ if (actions.some((a) => a.type === "ASSERT_STATE_DELTA")) {
85032
+ return {
85033
+ ok: true,
85034
+ severity: "none",
85035
+ reason: "state-delta oracle proves a durable product change (identity/count/persistence)",
85036
+ signals: {
85037
+ apiTest: false,
85038
+ interacted: actions.some((a) => a.type === "TAP" || a.type === "TYPE" || a.type === "CLEAR"),
85039
+ mutated: actions.some((a) => a.type === "TYPE" || a.type === "CLEAR" || a.type === "TAP"),
85040
+ navOnly: false,
85041
+ hasOutcomeProof: true,
85042
+ errorBanner: false,
85043
+ terminal: null
85044
+ }
85045
+ };
85046
+ }
84422
85047
  const modelAsserts = actions.filter((a) => a.type === "ASSERT_VISIBLE" || a.type === "ASSERT_TEXT");
84423
85048
  if (modelAsserts.length === 0) {
84424
85049
  return {
@@ -84588,6 +85213,16 @@ ${statePacket}`, redactionCredentials) },
84588
85213
  if (coldResetUnavailable)
84589
85214
  tags.push("@warm-state");
84590
85215
  const strengthBlocked = !strengthVerdict.ok || strengthVerdict.severity === "block" || strengthVerdict.severity === "route-bug" || !verified || coldResetUnavailable;
85216
+ {
85217
+ const kind = (0, scenario_taxonomy_js_1.inferScenarioKind)(scenario);
85218
+ const hasStateOracle = compiled.steps.some((s) => s.action === "assertStateDelta" || s.action === "assertText" || s.action === "captureState");
85219
+ const strong = verified && !strengthBlocked && strengthVerdict.severity === "none" && ((0, scenario_taxonomy_js_1.isStrongOracleKind)(kind) || hasStateOracle);
85220
+ if (strong)
85221
+ tags.push("@strong-oracle");
85222
+ else if (!tags.includes("@smoke") && (kind === "smoke_nav" || kind === "navigation_integrity")) {
85223
+ tags.push("@smoke");
85224
+ }
85225
+ }
84591
85226
  const strengthReason = coldResetUnavailable ? `Cold app-data reset unavailable${coldResetReason ? ` (${coldResetReason})` : ""} \u2014 generation may not match cold-boot replay. ${strengthVerdict.reason}` : !verified && recording.assertCount === 0 ? "Mobile scenario finished unverified \u2014 the agent never proved the scenario outcome live, so the recording may not demonstrate the goal (e.g. a happy path that never completed). Review before promotion." : strengthVerdict.reason;
84592
85227
  const test = {
84593
85228
  name: compiled.name,
@@ -84835,6 +85470,344 @@ Mobile generate phase complete: ${tests.length}/${scenarios.length} test(s) gene
84835
85470
  }
84836
85471
  });
84837
85472
 
85473
+ // ../runner-core/dist/services/mobile/failure-triage.js
85474
+ var require_failure_triage = __commonJS({
85475
+ "../runner-core/dist/services/mobile/failure-triage.js"(exports) {
85476
+ "use strict";
85477
+ Object.defineProperty(exports, "__esModule", { value: true });
85478
+ exports.hasStrongMobileOracle = hasStrongMobileOracle;
85479
+ exports.isStrongOracleStep = isStrongOracleStep;
85480
+ exports.listStrongOracleKinds = listStrongOracleKinds;
85481
+ exports.triageMobileFailure = triageMobileFailure;
85482
+ exports.triageToHealTerminal = triageToHealTerminal;
85483
+ var STRONG_ACTIONS = /* @__PURE__ */ new Set(["assertStateDelta", "assertText", "captureState"]);
85484
+ var CHROME_VISIBLE_RE = /\b(tab|home|settings|back|menu|navigation|nav bar|bottom nav|status bar)\b/i;
85485
+ function hasStrongMobileOracle(steps) {
85486
+ return steps.some(isStrongOracleStep);
85487
+ }
85488
+ function isStrongOracleStep(step) {
85489
+ if (STRONG_ACTIONS.has(step.action))
85490
+ return true;
85491
+ if (step.action !== "assertVisible")
85492
+ return false;
85493
+ const blob = [
85494
+ step.assertion ?? "",
85495
+ step.description ?? "",
85496
+ step.target?.primary ?? "",
85497
+ ...step.target?.fallbacks ?? []
85498
+ ].join(" ");
85499
+ if (/\b(error|invalid|required|must|cannot|failed|denied|blocked|empty|missing|deleted|removed|saved|success|created|updated)\b/i.test(blob)) {
85500
+ return true;
85501
+ }
85502
+ if (CHROME_VISIBLE_RE.test(blob) && blob.length < 80)
85503
+ return false;
85504
+ return false;
85505
+ }
85506
+ function listStrongOracleKinds(steps) {
85507
+ const kinds = /* @__PURE__ */ new Set();
85508
+ for (const step of steps) {
85509
+ if (step.action === "assertStateDelta")
85510
+ kinds.add("assertStateDelta");
85511
+ else if (step.action === "assertText")
85512
+ kinds.add("assertText");
85513
+ else if (step.action === "captureState")
85514
+ kinds.add("captureState");
85515
+ else if (isStrongOracleStep(step))
85516
+ kinds.add(step.action);
85517
+ }
85518
+ return [...kinds];
85519
+ }
85520
+ function errorText(error2, logs2) {
85521
+ return `${error2 ?? ""}
85522
+ ${logs2 ?? ""}`.trim();
85523
+ }
85524
+ function leadingPrefix(error2) {
85525
+ if (!error2)
85526
+ return null;
85527
+ const m = error2.match(/^(CONFIG_ISSUE|APP_BUG|RATE_LIMIT_BLOCKED|PREREQ_UNMET|HEAL_SECRET_LEAK)\s*:/i);
85528
+ return m ? m[1].toUpperCase() : null;
85529
+ }
85530
+ function looksLikeConfig(text) {
85531
+ if (/CONFIG_ISSUE\s*:/i.test(text))
85532
+ return true;
85533
+ if (/RATE_LIMIT_BLOCKED\s*:/i.test(text))
85534
+ return true;
85535
+ if (/Missing mobile test variable/i.test(text))
85536
+ return true;
85537
+ if (/\b(quota|rate.?limit|429|lockout)\b/i.test(text))
85538
+ return true;
85539
+ if (/\b(device (?:offline|disconnected|not found)|session (?:not started|terminated|deleted))\b/i.test(text)) {
85540
+ return true;
85541
+ }
85542
+ if (/\b(Appium|adbExec|UiAutomator2|XCUITest)\b/i.test(text) && /\b(ECONNREFUSED|timeout|not available|could not start|driver)\b/i.test(text)) {
85543
+ return true;
85544
+ }
85545
+ return false;
85546
+ }
85547
+ function looksLikePrereq(text) {
85548
+ return /PREREQ_UNMET\s*:/i.test(text) || /\b(prerequisite|fixture missing|no test data|account (?:missing|not provisioned)|required entity)\b/i.test(text);
85549
+ }
85550
+ function looksLikeFlake(text) {
85551
+ return /\b(stale element|animation|transition|intermittent|flaky|race condition)\b/i.test(text) || /\b(element (?:is )?not interactable|obscured|covered by)\b/i.test(text);
85552
+ }
85553
+ function looksLikeLocatorMiss(text) {
85554
+ return /not found|no such element|No identity locator|unable to locate/i.test(text);
85555
+ }
85556
+ function looksLikeOracleFailure(text) {
85557
+ return /assertStateDelta/i.test(text) || /expected state/i.test(text) || /expected (?:["'].+["'] )?(?:to be |text|visible|removed|count)/i.test(text) || /assertion failed|Assert .+ (?:visible|shows|contains)/i.test(text);
85558
+ }
85559
+ function triageMobileFailure(input) {
85560
+ const failureCount = Math.max(1, input.failureCount ?? 1);
85561
+ const tags = input.tags ?? [];
85562
+ const text = errorText(input.error, input.logs);
85563
+ const prefix = leadingPrefix(input.error);
85564
+ const strongKinds = listStrongOracleKinds(input.steps);
85565
+ const hasStrong = strongKinds.length > 0 || tags.some((t) => t === "@strong-oracle" || t === "strong-oracle");
85566
+ const evidence = {
85567
+ hasStrongOracle: hasStrong,
85568
+ strongOracleKinds: strongKinds,
85569
+ failureCount,
85570
+ errorPrefix: prefix
85571
+ };
85572
+ if (prefix === "CONFIG_ISSUE" || prefix === "RATE_LIMIT_BLOCKED") {
85573
+ return {
85574
+ verdict: "config_issue",
85575
+ reason: `Environment/config prefix on error (${prefix})`,
85576
+ shouldHeal: false,
85577
+ healVerdict: "config_issue",
85578
+ evidence
85579
+ };
85580
+ }
85581
+ if (prefix === "APP_BUG") {
85582
+ return {
85583
+ verdict: "app_bug_candidate",
85584
+ reason: "Error already classified APP_BUG",
85585
+ shouldHeal: false,
85586
+ healVerdict: "app_bug",
85587
+ evidence
85588
+ };
85589
+ }
85590
+ if (prefix === "PREREQ_UNMET") {
85591
+ return {
85592
+ verdict: "prereq_unmet",
85593
+ reason: "Error already classified PREREQ_UNMET",
85594
+ shouldHeal: false,
85595
+ healVerdict: "prereq_unmet",
85596
+ evidence
85597
+ };
85598
+ }
85599
+ if (looksLikeConfig(text)) {
85600
+ return {
85601
+ verdict: "config_issue",
85602
+ reason: "Failure matches environment/config/device patterns",
85603
+ shouldHeal: false,
85604
+ healVerdict: "config_issue",
85605
+ evidence
85606
+ };
85607
+ }
85608
+ if (looksLikePrereq(text)) {
85609
+ return {
85610
+ verdict: "prereq_unmet",
85611
+ reason: "Failure matches missing prerequisite / fixture patterns",
85612
+ shouldHeal: false,
85613
+ healVerdict: "prereq_unmet",
85614
+ evidence
85615
+ };
85616
+ }
85617
+ if (input.uiSuccessWithFailedWriteApi && hasStrong) {
85618
+ return {
85619
+ verdict: "app_bug_candidate",
85620
+ reason: "UI path completed but a write API failed (network secondary oracle)",
85621
+ shouldHeal: false,
85622
+ healVerdict: "app_bug",
85623
+ evidence
85624
+ };
85625
+ }
85626
+ if (hasStrong && failureCount >= 2 && (looksLikeOracleFailure(text) || !looksLikeLocatorMiss(text))) {
85627
+ if (looksLikeLocatorMiss(text) && failureCount < 3) {
85628
+ return {
85629
+ verdict: "needs_heal",
85630
+ reason: "Strong oracle present but error looks like a locator miss \u2014 attempt heal",
85631
+ shouldHeal: true,
85632
+ evidence
85633
+ };
85634
+ }
85635
+ return {
85636
+ verdict: "app_bug_candidate",
85637
+ reason: `Strong oracle (${strongKinds.join(", ") || "tagged"}) failed ${failureCount}\xD7 with product-shaped error`,
85638
+ shouldHeal: false,
85639
+ healVerdict: "app_bug",
85640
+ evidence
85641
+ };
85642
+ }
85643
+ if (looksLikeFlake(text) && failureCount === 1 && !hasStrong) {
85644
+ return {
85645
+ verdict: "flake_candidate",
85646
+ reason: "Transient interactability / race signals on a weak-oracle test",
85647
+ shouldHeal: true,
85648
+ // still allow heal, but tag flaky path
85649
+ extraTags: ["@flaky"],
85650
+ evidence
85651
+ };
85652
+ }
85653
+ if (tags.includes("@smoke") && !hasStrong && looksLikeLocatorMiss(text)) {
85654
+ return {
85655
+ verdict: "needs_heal",
85656
+ reason: "Smoke/nav locator failure \u2014 heal allowed",
85657
+ shouldHeal: true,
85658
+ evidence
85659
+ };
85660
+ }
85661
+ return {
85662
+ verdict: "needs_heal",
85663
+ reason: hasStrong ? "Strong oracle first failure \u2014 allow heal once before APP_BUG escalation" : "Default: attempt script/live heal",
85664
+ shouldHeal: true,
85665
+ evidence
85666
+ };
85667
+ }
85668
+ function triageToHealTerminal(triage) {
85669
+ if (triage.shouldHeal || !triage.healVerdict)
85670
+ return null;
85671
+ return {
85672
+ verdict: triage.healVerdict,
85673
+ healReason: triage.reason,
85674
+ extraTags: triage.extraTags
85675
+ };
85676
+ }
85677
+ }
85678
+ });
85679
+
85680
+ // ../runner-core/dist/services/mobile/oracle-protection.js
85681
+ var require_oracle_protection = __commonJS({
85682
+ "../runner-core/dist/services/mobile/oracle-protection.js"(exports) {
85683
+ "use strict";
85684
+ Object.defineProperty(exports, "__esModule", { value: true });
85685
+ exports.fingerprintOracles = fingerprintOracles;
85686
+ exports.rejectOracleWeakeningPatch = rejectOracleWeakeningPatch;
85687
+ exports.oraclesPreserved = oraclesPreserved;
85688
+ var failure_triage_js_1 = require_failure_triage();
85689
+ var EXPECT_STRENGTH = {
85690
+ entity_removed: 5,
85691
+ removed: 5,
85692
+ count_decreased: 4,
85693
+ "count-1": 4,
85694
+ count_increased: 4,
85695
+ "count+1": 4,
85696
+ persisted: 3,
85697
+ unchanged: 3,
85698
+ changed: 2,
85699
+ any_change: 2
85700
+ };
85701
+ function normalizeText(value) {
85702
+ return (value ?? "").trim().toLowerCase().replace(/\s+/g, " ");
85703
+ }
85704
+ function stateKeyOf(step) {
85705
+ const meta = step.metadata;
85706
+ const key = typeof meta?.stateKey === "string" ? meta.stateKey.trim() : "";
85707
+ return key || normalizeText(step.target?.primary) || normalizeText(step.description) || `order-${step.order}`;
85708
+ }
85709
+ function expectOf(step) {
85710
+ const meta = step.metadata;
85711
+ const fromMeta = typeof meta?.expect === "string" ? meta.expect : "";
85712
+ return normalizeText(fromMeta || step.assertion || step.value || "changed");
85713
+ }
85714
+ function fingerprintOracles(steps) {
85715
+ const assertTexts = [];
85716
+ const stateExpects = {};
85717
+ let stateDeltas = 0;
85718
+ let captures = 0;
85719
+ let strongVisible = 0;
85720
+ for (const step of steps) {
85721
+ if (step.action === "assertStateDelta") {
85722
+ stateDeltas += 1;
85723
+ stateExpects[stateKeyOf(step)] = expectOf(step);
85724
+ } else if (step.action === "captureState")
85725
+ captures += 1;
85726
+ else if (step.action === "assertText") {
85727
+ const t = normalizeText(step.assertion ?? step.value ?? step.description);
85728
+ if (t)
85729
+ assertTexts.push(t);
85730
+ } else if (step.action === "assertVisible" && (0, failure_triage_js_1.isStrongOracleStep)(step)) {
85731
+ strongVisible += 1;
85732
+ }
85733
+ }
85734
+ return {
85735
+ stateDeltas,
85736
+ captures,
85737
+ assertTexts,
85738
+ stateExpects,
85739
+ strongVisible,
85740
+ strongTotal: stateDeltas + captures + assertTexts.length + strongVisible
85741
+ };
85742
+ }
85743
+ function expectStrength(expect) {
85744
+ const e = expect.toLowerCase().trim();
85745
+ if (e.startsWith("removed:"))
85746
+ return 5;
85747
+ return EXPECT_STRENGTH[e] ?? 1;
85748
+ }
85749
+ function rejectOracleWeakeningPatch(original, patched) {
85750
+ if (!Array.isArray(patched) || patched.length === 0) {
85751
+ return "healed steps missing \u2014 refusing empty patch that would drop oracles";
85752
+ }
85753
+ const before = fingerprintOracles(original);
85754
+ const after = fingerprintOracles(patched);
85755
+ if (before.stateDeltas > 0 && after.stateDeltas < before.stateDeltas) {
85756
+ return `heal patch removed assertStateDelta oracle(s) (${before.stateDeltas} \u2192 ${after.stateDeltas}) \u2014 refusing to go green by dropping state proof`;
85757
+ }
85758
+ for (const [key, beforeExpect] of Object.entries(before.stateExpects)) {
85759
+ const afterExpect = after.stateExpects[key];
85760
+ if (!afterExpect) {
85761
+ return `heal patch removed assertStateDelta for key "${key}" (expect was ${beforeExpect})`;
85762
+ }
85763
+ if (expectStrength(afterExpect) < expectStrength(beforeExpect)) {
85764
+ return `heal patch softened assertStateDelta expect for "${key}" (${beforeExpect} \u2192 ${afterExpect})`;
85765
+ }
85766
+ }
85767
+ if (before.captures > 0 && after.captures < before.captures && after.stateDeltas === 0) {
85768
+ return `heal patch removed captureState without keeping assertStateDelta (${before.captures} \u2192 ${after.captures})`;
85769
+ }
85770
+ if (before.assertTexts.length > 0) {
85771
+ const afterSet = new Set(after.assertTexts);
85772
+ const lost = before.assertTexts.filter((t) => !afterSet.has(t));
85773
+ if (after.assertTexts.length < before.assertTexts.length) {
85774
+ return `heal patch dropped assertText outcome proof (${before.assertTexts.length} \u2192 ${after.assertTexts.length})`;
85775
+ }
85776
+ if (lost.length > 0) {
85777
+ const softKept = lost.every((t) => after.assertTexts.some((a) => a.includes(t) || t.includes(a)));
85778
+ if (!softKept) {
85779
+ return `heal patch replaced assertText expectations (${lost.slice(0, 2).join("; ")}) \u2014 outcome must stay`;
85780
+ }
85781
+ }
85782
+ }
85783
+ if (before.strongVisible > 0 && after.strongVisible + after.assertTexts.length + after.stateDeltas < before.strongVisible) {
85784
+ return `heal patch weakened strong assertVisible validation oracles (${before.strongVisible} \u2192 ${after.strongVisible})`;
85785
+ }
85786
+ if (before.strongTotal > 0 && after.strongTotal === 0) {
85787
+ return "heal patch removed all strong oracles \u2014 refusing visibility-only green path";
85788
+ }
85789
+ for (const orig of original) {
85790
+ if (orig.action !== "assertStateDelta" && orig.action !== "assertText")
85791
+ continue;
85792
+ const key = normalizeText(orig.description ?? orig.assertion ?? "");
85793
+ if (!key)
85794
+ continue;
85795
+ const stillStrong = patched.some((p) => (p.action === "assertStateDelta" || p.action === "assertText") && normalizeText(p.description ?? p.assertion ?? "") === key);
85796
+ if (stillStrong)
85797
+ continue;
85798
+ const onlyVisible = patched.some((p) => p.action === "assertVisible" && normalizeText(p.description ?? p.assertion ?? "") === key);
85799
+ if (onlyVisible) {
85800
+ return `heal patch downgraded strong oracle "${key.slice(0, 60)}" to assertVisible`;
85801
+ }
85802
+ }
85803
+ return null;
85804
+ }
85805
+ function oraclesPreserved(original, patched) {
85806
+ return rejectOracleWeakeningPatch(original, patched) === null;
85807
+ }
85808
+ }
85809
+ });
85810
+
84838
85811
  // ../runner-core/dist/services/mobile/mobile-heal-postprocess.js
84839
85812
  var require_mobile_heal_postprocess = __commonJS({
84840
85813
  "../runner-core/dist/services/mobile/mobile-heal-postprocess.js"(exports) {
@@ -84843,6 +85816,7 @@ var require_mobile_heal_postprocess = __commonJS({
84843
85816
  exports.redactMobileSecretsFromText = redactMobileSecretsFromText;
84844
85817
  exports.detectMobileStepSecretLeak = detectMobileStepSecretLeak;
84845
85818
  exports.computeMobileHealOutcome = computeMobileHealOutcome2;
85819
+ var oracle_protection_js_1 = require_oracle_protection();
84846
85820
  var REDACT_KEY_RE = /email|username|user|phone|password|secret|token|api[_-]?key|access[_-]?key|\bpass\b|credential|bearer|\bpat\b|session|cookie|jwt|otp|pin/i;
84847
85821
  var DETECT_KEY_RE = /password|secret|token|api[_]?key|\bpass\b|credential|bearer|\bpat\b/i;
84848
85822
  var MIN_REDACT_LEN = 4;
@@ -84908,18 +85882,27 @@ var require_mobile_heal_postprocess = __commonJS({
84908
85882
  function computeMobileHealOutcome2(args) {
84909
85883
  const { heal } = args;
84910
85884
  const hasFix = Array.isArray(heal.healedSteps) && heal.healedSteps.length > 0;
84911
- const isVerifiedFix = heal.passed === true && heal.verdict === "fix" && hasFix;
85885
+ let isVerifiedFix = heal.passed === true && heal.verdict === "fix" && hasFix;
84912
85886
  const secretLeak = isVerifiedFix ? detectMobileStepSecretLeak(heal.healedSteps, args.testVariables) : null;
85887
+ const oracleWeakening = isVerifiedFix && args.originalSteps ? (0, oracle_protection_js_1.rejectOracleWeakeningPatch)(args.originalSteps, heal.healedSteps ?? []) : null;
85888
+ if (oracleWeakening)
85889
+ isVerifiedFix = false;
84913
85890
  const isConfigIssue = heal.verdict === "config_issue";
84914
- const isAppBug = heal.verdict === "app_bug";
85891
+ const isAppBug = heal.verdict === "app_bug" || Boolean(oracleWeakening && heal.passed);
84915
85892
  const extraTags = new Set((heal.extraTags ?? []).filter((t) => typeof t === "string" && t.length > 0));
84916
85893
  if (secretLeak)
84917
85894
  extraTags.add("@needs-review");
85895
+ if (oracleWeakening) {
85896
+ extraTags.add("@needs-review");
85897
+ extraTags.add("@bug-found");
85898
+ }
84918
85899
  if (!heal.passed && NEEDS_REVIEW_VERDICTS.has(heal.verdict))
84919
85900
  extraTags.add("@needs-review");
84920
85901
  let status;
84921
85902
  if (secretLeak)
84922
85903
  status = "FAILED";
85904
+ else if (oracleWeakening)
85905
+ status = "FAILED";
84923
85906
  else if (isVerifiedFix)
84924
85907
  status = "PASSED";
84925
85908
  else if (isConfigIssue)
@@ -84931,6 +85914,8 @@ var require_mobile_heal_postprocess = __commonJS({
84931
85914
  error2 = void 0;
84932
85915
  } else if (secretLeak) {
84933
85916
  error2 = `HEAL_SECRET_LEAK: healed steps contained a literal secret (${secretLeak}); patch dropped, tagged @needs-review`;
85917
+ } else if (oracleWeakening) {
85918
+ error2 = `APP_BUG: heal attempted to drop strong oracle (${oracleWeakening}); patch refused`;
84934
85919
  } else if (isConfigIssue) {
84935
85920
  error2 = `CONFIG_ISSUE: ${heal.healReason ?? args.finalError ?? args.reproduceError ?? "environment/rate-limit blocker"}`;
84936
85921
  } else if (isAppBug) {
@@ -84947,13 +85932,64 @@ var require_mobile_heal_postprocess = __commonJS({
84947
85932
  error: error2,
84948
85933
  extraTags: extraTags.size > 0 ? [...extraTags] : void 0,
84949
85934
  removeTags: heal.removeTags,
84950
- shouldPatch: isVerifiedFix && !secretLeak,
85935
+ shouldPatch: isVerifiedFix && !secretLeak && !oracleWeakening,
84951
85936
  secretLeak
84952
85937
  };
84953
85938
  }
84954
85939
  }
84955
85940
  });
84956
85941
 
85942
+ // ../runner-core/dist/services/mobile/network-oracle.js
85943
+ var require_network_oracle = __commonJS({
85944
+ "../runner-core/dist/services/mobile/network-oracle.js"(exports) {
85945
+ "use strict";
85946
+ Object.defineProperty(exports, "__esModule", { value: true });
85947
+ exports.evaluateNetworkSecondaryOracle = evaluateNetworkSecondaryOracle;
85948
+ exports.uiSuccessWithFailedWriteApi = uiSuccessWithFailedWriteApi;
85949
+ var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
85950
+ function isWrite(method) {
85951
+ return WRITE_METHODS.has(method.toUpperCase());
85952
+ }
85953
+ function isServerOrClientError(status) {
85954
+ return status >= 400 && status < 600;
85955
+ }
85956
+ function isNoiseUrl(url) {
85957
+ return /\b(analytics|telemetry|sentry|bugsnag|crashlytics|facebook\.com\/tr|google-analytics|doubleclick|hotjar|segment\.io|amplitude|mixpanel)\b/i.test(url);
85958
+ }
85959
+ function evaluateNetworkSecondaryOracle(input) {
85960
+ const calls = input.apiCalls;
85961
+ if (!calls || calls.length === 0)
85962
+ return null;
85963
+ if (input.uiPathSucceeded === false)
85964
+ return null;
85965
+ for (const call of calls) {
85966
+ const method = String(call.method ?? "GET");
85967
+ const url = String(call.url ?? "");
85968
+ const status = typeof call.status === "number" ? call.status : 0;
85969
+ if (!isWrite(method))
85970
+ continue;
85971
+ if (!isServerOrClientError(status))
85972
+ continue;
85973
+ if (!url || isNoiseUrl(url))
85974
+ continue;
85975
+ if (status === 401 || status === 403)
85976
+ continue;
85977
+ return {
85978
+ kind: "write_api_failed",
85979
+ method: method.toUpperCase(),
85980
+ url: url.slice(0, 200),
85981
+ status,
85982
+ reason: `Write API ${method.toUpperCase()} ${url.slice(0, 120)} returned ${status} while UI path appeared successful`
85983
+ };
85984
+ }
85985
+ return null;
85986
+ }
85987
+ function uiSuccessWithFailedWriteApi(input) {
85988
+ return evaluateNetworkSecondaryOracle(input) !== null;
85989
+ }
85990
+ }
85991
+ });
85992
+
84957
85993
  // ../runner-core/dist/services/selector-registry-context.js
84958
85994
  var require_selector_registry_context = __commonJS({
84959
85995
  "../runner-core/dist/services/selector-registry-context.js"(exports) {
@@ -85321,6 +86357,9 @@ var require_mobile_heal_loop = __commonJS({
85321
86357
  var ai_retry_js_1 = require_ai_retry();
85322
86358
  var mobile_source_parser_js_1 = require_mobile_source_parser();
85323
86359
  var mobile_heal_postprocess_js_1 = require_mobile_heal_postprocess();
86360
+ var failure_triage_js_1 = require_failure_triage();
86361
+ var oracle_protection_js_1 = require_oracle_protection();
86362
+ var network_oracle_js_1 = require_network_oracle();
85324
86363
  var mobile_observation_js_1 = require_mobile_observation();
85325
86364
  var selector_registry_context_js_1 = require_selector_registry_context();
85326
86365
  var mobile_session_keepalive_js_1 = require_mobile_session_keepalive();
@@ -85343,7 +86382,12 @@ Reason over steps + error + tree + registry and return working healed steps. Do
85343
86382
  {"verdict":"state_stale","reason":"leftover data blocks a baseline assertion"}
85344
86383
  {"verdict":"test_invalid","reason":"scenario cannot be made to pass"}
85345
86384
  {"verdict":"unhealable_dynamic","reason":"asserted value is inherently volatile (timestamps, counters, feeds) \u2014 no durable locator can exist; needs human review"}
85346
- For a fix, return the COMPLETE steps array (not a diff).`;
86385
+ For a fix, return the COMPLETE steps array (not a diff).
86386
+ ## Strong oracle protection (non-negotiable)
86387
+ - NEVER remove or downgrade assertStateDelta, captureState, or assertText outcome proof to go green.
86388
+ - NEVER replace a durable outcome assert with mere assertVisible of a tab/header.
86389
+ - You MAY fix locators, waits, and navigation around those oracles.
86390
+ - If the app truly violates the oracle, return verdict "app_bug" instead of stripping the assert.`;
85347
86391
  var DEFAULT_SCRIPT_MAX_ATTEMPTS = 6;
85348
86392
  var RECOVERABLE_MAX = 3;
85349
86393
  var MAX_CONSECUTIVE_INVALID_VERDICTS = 3;
@@ -85373,7 +86417,9 @@ For a fix, return the COMPLETE steps array (not a diff).`;
85373
86417
  "home",
85374
86418
  "waitForElement",
85375
86419
  "assertVisible",
85376
- "assertText"
86420
+ "assertText",
86421
+ "captureState",
86422
+ "assertStateDelta"
85377
86423
  ]);
85378
86424
  var MAX_HEALED_STEPS = 300;
85379
86425
  var TERMINAL_VERDICTS = /* @__PURE__ */ new Set([
@@ -85400,6 +86446,28 @@ For a fix, return the COMPLETE steps array (not a diff).`;
85400
86446
  function isMobileHealVerdict(value) {
85401
86447
  return MOBILE_HEAL_VERDICTS.includes(value);
85402
86448
  }
86449
+ function normalizeMobileHealVerdict(raw) {
86450
+ const v = raw.trim().toLowerCase().replace(/[\s-]+/g, "_");
86451
+ if (isMobileHealVerdict(v))
86452
+ return v;
86453
+ if (v === "appbug" || v === "application_bug" || v === "bug_found")
86454
+ return "app_bug";
86455
+ if (v === "config" || v === "configuration_issue" || v === "env" || v === "environment")
86456
+ return "config_issue";
86457
+ if (v === "prereq" || v === "prerequisite" || v === "prereq_missing")
86458
+ return "prereq_unmet";
86459
+ if (v === "stale" || v === "stale_state")
86460
+ return "state_stale";
86461
+ if (v === "invalid_test" || v === "bad_test")
86462
+ return "test_invalid";
86463
+ if (v === "unhealable" || v === "dynamic")
86464
+ return "unhealable_dynamic";
86465
+ if (v === "need_device" || v === "needs_appium" || v === "needs_live")
86466
+ return "needs_device";
86467
+ if (v === "healed" || v === "ok" || v === "pass" || v === "passed")
86468
+ return "fix";
86469
+ return null;
86470
+ }
85403
86471
  function isLocatorNotFound(error2) {
85404
86472
  return /not found|no such element/i.test(error2 ?? "");
85405
86473
  }
@@ -85681,15 +86749,43 @@ For a fix, return the COMPLETE steps array (not a diff).`;
85681
86749
  const sub = extractBracesSubstring(cleaned);
85682
86750
  obj = sub ? safeJsonParse(sub) : void 0;
85683
86751
  }
85684
- if (!isRecord(obj))
86752
+ if (!isRecord(obj)) {
86753
+ const line = cleaned.match(/\bverdict\s*[:=]\s*["']?([a-zA-Z_ -]+)["']?/i);
86754
+ if (line) {
86755
+ const verdict2 = normalizeMobileHealVerdict(line[1]);
86756
+ if (verdict2) {
86757
+ return {
86758
+ verdict: verdict2,
86759
+ reason: cleaned.slice(0, 2e3)
86760
+ };
86761
+ }
86762
+ }
86763
+ const prefix = cleaned.match(/^\s*(APP_BUG|CONFIG_ISSUE|PREREQ_UNMET|TEST_INVALID|STATE_STALE)\s*:\s*(.*)$/im);
86764
+ if (prefix) {
86765
+ const map2 = {
86766
+ APP_BUG: "app_bug",
86767
+ CONFIG_ISSUE: "config_issue",
86768
+ PREREQ_UNMET: "prereq_unmet",
86769
+ TEST_INVALID: "test_invalid",
86770
+ STATE_STALE: "state_stale"
86771
+ };
86772
+ const verdict2 = map2[prefix[1].toUpperCase()];
86773
+ if (verdict2) {
86774
+ return { verdict: verdict2, reason: (prefix[2] || cleaned).slice(0, 2e3) };
86775
+ }
86776
+ }
86777
+ return null;
86778
+ }
86779
+ const rawVerdict = obj.verdict ?? obj.Verdict ?? obj.status;
86780
+ if (typeof rawVerdict !== "string")
85685
86781
  return null;
85686
- const rawVerdict = obj.verdict;
85687
- if (typeof rawVerdict !== "string" || !isMobileHealVerdict(rawVerdict))
86782
+ const verdict = normalizeMobileHealVerdict(rawVerdict);
86783
+ if (!verdict)
85688
86784
  return null;
85689
86785
  return {
85690
- verdict: rawVerdict,
86786
+ verdict,
85691
86787
  steps: coerceSteps(obj.steps),
85692
- reason: typeof obj.reason === "string" ? obj.reason : void 0,
86788
+ reason: typeof obj.reason === "string" ? obj.reason : typeof obj.rationale === "string" ? obj.rationale : typeof obj.message === "string" ? obj.message : void 0,
85693
86789
  confidence: typeof obj.confidence === "number" ? obj.confidence : void 0
85694
86790
  };
85695
86791
  }
@@ -86038,7 +87134,7 @@ ${args.directive}`);
86038
87134
  };
86039
87135
  }
86040
87136
  markRecoverableTurn();
86041
- pendingDirective = "Your last response was not valid JSON matching the verdict schema. Return exactly one JSON verdict object \u2014 no prose, no markdown fences.";
87137
+ pendingDirective = 'SCHEMA REPAIR: Your last response was not a valid heal verdict. Reply with ONLY one JSON object (no markdown fences, no prose) of the form:\n{"verdict":"<one of: fix|app_bug|config_issue|needs_device|prereq_unmet|state_stale|test_invalid|unhealable_dynamic>","reason":"<short string>","steps":[/* optional MobileTestStep[] when verdict is fix */],"confidence":0.0}\nUse lowercase snake_case for verdict. Do not invent other verdict values.';
86042
87138
  continue;
86043
87139
  }
86044
87140
  consecutiveInvalidVerdicts = 0;
@@ -86067,6 +87163,13 @@ ${args.directive}`);
86067
87163
  pendingDirective = 'You returned verdict "fix" but no usable steps array. Return the COMPLETE healed MobileTestStep array.';
86068
87164
  continue;
86069
87165
  }
87166
+ const oracleRejection = (0, oracle_protection_js_1.rejectOracleWeakeningPatch)(steps, healedSteps);
87167
+ if (oracleRejection) {
87168
+ markRecoverableTurn();
87169
+ lastVerdict = "fix";
87170
+ pendingDirective = `ORACLE PROTECTION: ${oracleRejection}. Keep all assertStateDelta/assertText/captureState outcome proof; fix locators/navigation only. If the app violates the oracle, return verdict "app_bug".`;
87171
+ continue;
87172
+ }
86070
87173
  if (activeFailingSource && isLocatorNotFound(activeError) && !isDrift(activeError)) {
86071
87174
  const failingSourceSnapshot = activeFailingSource;
86072
87175
  const missing = timedSync("device-op", `phase1-attempt-${attempt}-static-verify`, options.onProgress, () => {
@@ -86210,6 +87313,28 @@ ${args.directive}`);
86210
87313
  if (invalidAuthSetup) {
86211
87314
  return { passed: false, verdict: "test_invalid", healReason: invalidAuthSetup };
86212
87315
  }
87316
+ const networkBug = (0, network_oracle_js_1.uiSuccessWithFailedWriteApi)({
87317
+ apiCalls: ctx.apiCalls,
87318
+ uiPathSucceeded: ctx.uiPathSucceeded
87319
+ });
87320
+ const triage = (0, failure_triage_js_1.triageMobileFailure)({
87321
+ steps,
87322
+ error: ctx.error,
87323
+ logs: ctx.logs,
87324
+ tags: ctx.tags,
87325
+ failureCount: ctx.failureCount,
87326
+ uiSuccessWithFailedWriteApi: networkBug
87327
+ });
87328
+ options.onProgress?.(`Pre-heal triage: ${triage.verdict} \u2014 ${triage.reason}`);
87329
+ const terminal = (0, failure_triage_js_1.triageToHealTerminal)(triage);
87330
+ if (terminal) {
87331
+ return {
87332
+ passed: false,
87333
+ verdict: terminal.verdict,
87334
+ healReason: terminal.healReason,
87335
+ extraTags: terminal.extraTags
87336
+ };
87337
+ }
86213
87338
  const preflight = await tryRegistryPreflight(steps, target, ctx, options);
86214
87339
  if (preflight)
86215
87340
  return preflight;
@@ -86459,6 +87584,11 @@ For a fix, return the COMPLETE steps array (not a diff). Use "observe" only to r
86459
87584
  if (parsed.verdict !== "fix" || !parsed.steps)
86460
87585
  continue;
86461
87586
  const healedSteps = parsed.steps;
87587
+ const liveOracleRejection = (0, oracle_protection_js_1.rejectOracleWeakeningPatch)(args.steps, healedSteps);
87588
+ if (liveOracleRejection) {
87589
+ options.onProgress?.(`ORACLE PROTECTION (live): ${liveOracleRejection}`);
87590
+ continue;
87591
+ }
86462
87592
  let verify;
86463
87593
  try {
86464
87594
  verify = await timed("reexec", `phase2-pass-${pass}-verify`, options.onProgress, () => runNativeTest({ steps: healedSteps, target, testVariables }));
@@ -353981,7 +355111,7 @@ var require_package4 = __commonJS({
353981
355111
  "package.json"(exports, module) {
353982
355112
  module.exports = {
353983
355113
  name: "@validate.qa/runner",
353984
- version: "1.0.88",
355114
+ version: "1.0.89",
353985
355115
  description: "validate local test runner - execute Playwright tests on your machine, connected to validate.qa cloud.",
353986
355116
  bin: {
353987
355117
  "validate-runner": "dist/cli.js"
@@ -354842,6 +355972,68 @@ async function waitForUiSettle(sessionPath, opts = {}) {
354842
355972
  }
354843
355973
  return { settled: false, lastFingerprint, frames };
354844
355974
  }
355975
+ var SYSTEM_UI_DISMISS_LABELS = [
355976
+ "OK",
355977
+ "Got it",
355978
+ "GOT IT",
355979
+ "Continue",
355980
+ "Close",
355981
+ "Dismiss",
355982
+ "I understand",
355983
+ "Accept",
355984
+ // Android 15+ / 16 KB page-size compatibility dialog primary action.
355985
+ "OK, got it"
355986
+ ];
355987
+ function extractElementId(value) {
355988
+ if (!value || typeof value !== "object") return null;
355989
+ const v = value;
355990
+ const elementId = v.ELEMENT ?? v["element-6066-11e4-a52e-4f735466cecf"] ?? null;
355991
+ if (typeof elementId !== "string" || !ELEMENT_ID_PATTERN.test(elementId)) return null;
355992
+ return elementId;
355993
+ }
355994
+ async function dismissBlockingSystemUi(sessionPath, platform3, opts = {}) {
355995
+ const maxDismisses = Math.max(1, Math.min(5, opts.maxDismisses ?? 3));
355996
+ const dismissed = [];
355997
+ for (let i = 0; i < maxDismisses; i++) {
355998
+ let tapped = false;
355999
+ for (const label of SYSTEM_UI_DISMISS_LABELS) {
356000
+ try {
356001
+ const strategies = platform3 === "ANDROID" ? [
356002
+ { using: "-android uiautomator", value: `new UiSelector().text("${label.replace(/"/g, '\\"')}")` },
356003
+ { using: "accessibility id", value: label }
356004
+ ] : [
356005
+ { using: "accessibility id", value: label },
356006
+ { using: "-ios predicate string", value: `label == "${label.replace(/"/g, '\\"')}" OR name == "${label.replace(/"/g, '\\"')}"` }
356007
+ ];
356008
+ for (const strategy of strategies) {
356009
+ try {
356010
+ const elResult = await appiumRequest(`${sessionPath}/element`, {
356011
+ method: "POST",
356012
+ body: JSON.stringify(strategy)
356013
+ });
356014
+ const elementId = extractElementId(readValue(elResult));
356015
+ if (!elementId) continue;
356016
+ await appiumRequest(`${sessionPath}/element/${elementId}/click`, {
356017
+ method: "POST",
356018
+ body: "{}"
356019
+ });
356020
+ dismissed.push(label);
356021
+ tapped = true;
356022
+ await waitForUiSettle(sessionPath, { timeoutMs: 1200, pollMs: 200, minStableFrames: 1 });
356023
+ break;
356024
+ } catch (err) {
356025
+ if (isAppiumDriverDeadError(err)) throw err;
356026
+ }
356027
+ }
356028
+ if (tapped) break;
356029
+ } catch (err) {
356030
+ if (isAppiumDriverDeadError(err)) throw err;
356031
+ }
356032
+ }
356033
+ if (!tapped) break;
356034
+ }
356035
+ return { dismissed, ok: dismissed.length > 0 };
356036
+ }
354845
356037
  async function waitForColdBootSettle(sessionPath) {
354846
356038
  await waitForUiSettle(sessionPath, {
354847
356039
  timeoutMs: MOBILE_COLD_BOOT_SETTLE_MS,
@@ -357582,6 +358774,107 @@ async function waitForColdBootContent(sessionId, log2, timeoutMs = 2e4) {
357582
358774
  }
357583
358775
  log2(` Cold-boot wait timed out after ${timeoutMs}ms (last tree had ${lastCount} node(s)) \u2014 proceeding anyway.`);
357584
358776
  }
358777
+ async function dismissSystemUiAfterColdBoot(sessionId, platform3, log2) {
358778
+ try {
358779
+ const result = await dismissBlockingSystemUi(`/session/${sessionId}`, platform3);
358780
+ if (result.dismissed.length > 0) {
358781
+ log2(` Dismissed system UI: ${result.dismissed.join(" \u2192 ")}`);
358782
+ }
358783
+ } catch (err) {
358784
+ log2(` System UI dismiss skipped (${err instanceof Error ? err.message : String(err)})`);
358785
+ }
358786
+ }
358787
+ async function captureMobileStateValues(sessionId, kind) {
358788
+ const res = await wdRequest(`/session/${sessionId}/source`);
358789
+ const xml = typeof res?.value === "string" ? res.value : "";
358790
+ if (kind === "badge_count") {
358791
+ const nums = /* @__PURE__ */ new Set();
358792
+ for (const m of xml.matchAll(/\b(\d{1,6})\b/g)) {
358793
+ nums.add(m[1]);
358794
+ }
358795
+ const preferred = /* @__PURE__ */ new Set();
358796
+ for (const m of xml.matchAll(/(?:count|badge|open|unread|item|invoice|result|pending)[^>]{0,80}?\b(\d{1,6})\b/gi)) {
358797
+ preferred.add(m[1]);
358798
+ }
358799
+ for (const m of xml.matchAll(/\b(\d{1,6})\b[^>]{0,80}?(?:count|badge|open|unread|items?)/gi)) {
358800
+ preferred.add(m[1]);
358801
+ }
358802
+ return preferred.size > 0 ? [...preferred] : [...nums].slice(0, 20);
358803
+ }
358804
+ const labels = /* @__PURE__ */ new Set();
358805
+ const attrRe = /(?:text|content-desc|name|label)="([^"]{2,80})"/gi;
358806
+ for (const m of xml.matchAll(attrRe)) {
358807
+ const t = m[1].trim();
358808
+ if (t.length < 2 || t.length > 80) continue;
358809
+ if (/^(true|false|null|OK|Cancel)$/i.test(t)) continue;
358810
+ labels.add(t);
358811
+ }
358812
+ return [...labels].slice(0, 80);
358813
+ }
358814
+ function assertMobileStateDelta(before, after, expect, key, log2) {
358815
+ const beforeSet = new Set(before);
358816
+ const afterSet = new Set(after);
358817
+ const removed = before.filter((v) => !afterSet.has(v));
358818
+ const added = after.filter((v) => !beforeSet.has(v));
358819
+ log2(` assertStateDelta key=${key} expect=${expect} removed=${removed.length} added=${added.length}`);
358820
+ const exp = expect.toLowerCase().trim();
358821
+ if (exp === "changed" || exp === "any_change") {
358822
+ if (removed.length === 0 && added.length === 0) {
358823
+ throw new Error(`assertStateDelta(${key}): expected state to change, but capture is identical (${before.length} values)`);
358824
+ }
358825
+ return;
358826
+ }
358827
+ if (exp === "removed" || exp === "entity_removed" || exp.startsWith("removed:")) {
358828
+ const target = exp.startsWith("removed:") ? expect.slice("removed:".length).trim() : "";
358829
+ if (target) {
358830
+ if (!removed.includes(target) && afterSet.has(target)) {
358831
+ throw new Error(`assertStateDelta(${key}): expected "${target}" removed, but it is still present`);
358832
+ }
358833
+ if (!beforeSet.has(target)) {
358834
+ throw new Error(`assertStateDelta(${key}): expected "${target}" to have been in the prior capture`);
358835
+ }
358836
+ if (afterSet.has(target)) {
358837
+ throw new Error(`assertStateDelta(${key}): "${target}" was not removed`);
358838
+ }
358839
+ return;
358840
+ }
358841
+ if (removed.length === 0) {
358842
+ throw new Error(`assertStateDelta(${key}): expected at least one entity removed`);
358843
+ }
358844
+ return;
358845
+ }
358846
+ if (exp === "count_decreased" || exp === "count-1") {
358847
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
358848
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
358849
+ const bMax = b.length ? Math.max(...b) : NaN;
358850
+ const aMax = a.length ? Math.max(...a) : NaN;
358851
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax >= bMax) {
358852
+ throw new Error(`assertStateDelta(${key}): expected count decrease (before max=${bMax}, after max=${aMax})`);
358853
+ }
358854
+ return;
358855
+ }
358856
+ if (exp === "count_increased" || exp === "count+1") {
358857
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
358858
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
358859
+ const bMax = b.length ? Math.max(...b) : NaN;
358860
+ const aMax = a.length ? Math.max(...a) : NaN;
358861
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax <= bMax) {
358862
+ throw new Error(`assertStateDelta(${key}): expected count increase (before max=${bMax}, after max=${aMax})`);
358863
+ }
358864
+ return;
358865
+ }
358866
+ if (exp === "unchanged" || exp === "persisted") {
358867
+ if (removed.length > 0 || added.length > 0) {
358868
+ throw new Error(
358869
+ `assertStateDelta(${key}): expected persistence/unchanged, but removed=[${removed.slice(0, 5).join(", ")}] added=[${added.slice(0, 5).join(", ")}]`
358870
+ );
358871
+ }
358872
+ return;
358873
+ }
358874
+ if (removed.length === 0 && added.length === 0) {
358875
+ throw new Error(`assertStateDelta(${key}): expected change (expect=${expect}), state identical`);
358876
+ }
358877
+ }
357585
358878
  async function restoreTargetAppIfExternal(sessionId, target, log2, source, failOnExternal) {
357586
358879
  let boundary = null;
357587
358880
  try {
@@ -358727,6 +360020,7 @@ async function executeMobileTest(options) {
358727
360020
  }
358728
360021
  const stepResults = [];
358729
360022
  const screenshots = [];
360023
+ const stateBag = /* @__PURE__ */ new Map();
358730
360024
  let apiCalls = [];
358731
360025
  let sessionId = null;
358732
360026
  let selectedDevice;
@@ -358937,6 +360231,9 @@ async function executeMobileTest(options) {
358937
360231
  if (clearedAppDataBeforeLaunch) {
358938
360232
  await waitForColdBootContent(sessionId, log2);
358939
360233
  }
360234
+ if (options.target.launchMode !== "RESUME") {
360235
+ await dismissSystemUiAfterColdBoot(sessionId, options.target.platform, log2);
360236
+ }
358940
360237
  if (options.target.launchMode === "DEEP_LINK" && options.target.deeplink) {
358941
360238
  try {
358942
360239
  log2(`Opening deep link: ${options.target.deeplink}`);
@@ -359031,6 +360328,25 @@ async function executeMobileTest(options) {
359031
360328
  case "assertText":
359032
360329
  await executeAssertText(sessionId, step, runPlatform, isCrossPlatform);
359033
360330
  break;
360331
+ case "captureState": {
360332
+ const key = String(step.metadata?.stateKey ?? step.target?.primary ?? `state-${step.order}`);
360333
+ const kind = String(step.metadata?.stateKind ?? "list_ids");
360334
+ const values = await captureMobileStateValues(sessionId, kind);
360335
+ stateBag.set(key, { kind, values, capturedAt: Date.now() });
360336
+ log2(` captureState key=${key} kind=${kind} n=${values.length}`);
360337
+ break;
360338
+ }
360339
+ case "assertStateDelta": {
360340
+ const key = String(step.metadata?.stateKey ?? step.target?.primary ?? "");
360341
+ const expect = String(step.metadata?.expect ?? step.assertion ?? "changed");
360342
+ const prior = stateBag.get(key);
360343
+ if (!prior) {
360344
+ throw new Error(`assertStateDelta: no prior captureState for key "${key}"`);
360345
+ }
360346
+ const current = await captureMobileStateValues(sessionId, prior.kind);
360347
+ assertMobileStateDelta(prior.values, current, expect, key, log2);
360348
+ break;
360349
+ }
359034
360350
  default: {
359035
360351
  const _exhaustive = step.action;
359036
360352
  status = "failed";
@@ -359209,6 +360525,10 @@ async function createMobileDiscoverySession(target, options) {
359209
360525
  );
359210
360526
  }
359211
360527
  }
360528
+ try {
360529
+ await dismissBlockingSystemUi(`/session/${sessionId}`, target.platform);
360530
+ } catch {
360531
+ }
359212
360532
  let stopped = false;
359213
360533
  return {
359214
360534
  sessionId,
@@ -359346,6 +360666,8 @@ async function driveHarvestStep(sessionId, step, elementId, platform3) {
359346
360666
  case "waitForElement":
359347
360667
  case "assertVisible":
359348
360668
  case "assertText":
360669
+ case "captureState":
360670
+ case "assertStateDelta":
359349
360671
  return true;
359350
360672
  }
359351
360673
  }
@@ -359379,6 +360701,7 @@ async function harvestPlatformLocators(options) {
359379
360701
  try {
359380
360702
  options.onSessionReady?.(session.sessionId, session.deviceId, platform3);
359381
360703
  await freshLaunchTargetApp(session.sessionId, platform3, options.target.appId, log2);
360704
+ await dismissSystemUiAfterColdBoot(session.sessionId, platform3, log2);
359382
360705
  if (options.target.launchMode === "DEEP_LINK" && options.target.deeplink) {
359383
360706
  await openDeepLink(session.sessionId, platform3, options.target.deeplink, options.target.appId);
359384
360707
  }
@@ -359654,7 +360977,9 @@ function decideMobileDeviceGate(input) {
359654
360977
  }
359655
360978
  }
359656
360979
  const isHealForHeldTest = runMode === "heal" && !!testCaseId && healHoldTestCaseIds.has(testCaseId);
359657
- const reservedForHeals = isHealForHeldTest ? Math.max(0, healHoldTestCaseIds.size - 1) : healHoldTestCaseIds.size;
360980
+ const rawReservedForHeals = isHealForHeldTest ? Math.max(0, healHoldTestCaseIds.size - 1) : healHoldTestCaseIds.size;
360981
+ const maxHealReserve = capacity <= 1 ? capacity : Math.max(1, capacity - 1);
360982
+ const reservedForHeals = Math.min(rawReservedForHeals, maxHealReserve);
359658
360983
  if (activeMobileOps + reservedForHeals >= capacity) {
359659
360984
  const reason = reservedForHeals > 0 ? `capacity reserved for pending auto-heal: ${activeMobileOps}+${reservedForHeals}/${capacity}` : `mobile capacity reached: ${activeMobileOps}/${capacity} in use`;
359660
360985
  return { claim: false, disposition: "defer", reason };
@@ -361490,6 +362815,11 @@ var MobileBridgeDriver = class {
361490
362815
  } catch (err) {
361491
362816
  if (isRecoverableAppiumSessionFailure(err)) throw err;
361492
362817
  }
362818
+ try {
362819
+ await dismissBlockingSystemUi(this.sessionPath, this.platform);
362820
+ } catch (err) {
362821
+ if (isRecoverableAppiumSessionFailure(err) || isAppiumDriverDeadError(err)) throw err;
362822
+ }
361493
362823
  });
361494
362824
  }
361495
362825
  /**
@@ -361527,6 +362857,11 @@ var MobileBridgeDriver = class {
361527
362857
  } catch (err) {
361528
362858
  if (isRecoverableAppiumSessionFailure(err)) throw err;
361529
362859
  }
362860
+ try {
362861
+ await dismissBlockingSystemUi(this.sessionPath, this.platform);
362862
+ } catch (err) {
362863
+ if (isRecoverableAppiumSessionFailure(err) || isAppiumDriverDeadError(err)) throw err;
362864
+ }
361530
362865
  return true;
361531
362866
  } catch (err) {
361532
362867
  if (isRecoverableAppiumSessionFailure(err)) throw err;
@@ -364886,6 +366221,17 @@ ${finalVerifyResult.logs ?? ""}`;
364886
366221
  }
364887
366222
  };
364888
366223
  log.info("\u{1FA7A} Mobile AI heal \u2014 Phase 1 (script) \u2192 Phase 2 (live device, lazy)...");
366224
+ const tagList = Array.isArray(run2.tags) ? run2.tags : [];
366225
+ const failureCount = Math.max(
366226
+ 1,
366227
+ typeof run2.consecutiveFails === "number" && run2.consecutiveFails > 0 ? run2.consecutiveFails : tagList.includes("@bug-found") ? 2 : 1
366228
+ );
366229
+ const reproduceApiCalls = Array.isArray(nativeVerify.last?.apiCalls) ? nativeVerify.last.apiCalls.map((c) => ({
366230
+ method: typeof c.method === "string" ? c.method : void 0,
366231
+ url: typeof c.url === "string" ? c.url : void 0,
366232
+ status: typeof c.status === "number" ? c.status : void 0
366233
+ })) : void 0;
366234
+ const uiPathSucceeded = Array.isArray(reproduce.stepResults) && reproduce.stepResults.filter((s) => s.status === "passed").length >= Math.max(1, reproduce.stepResults.length - 1);
364889
366235
  const heal = await (0, import_runner_core14.executeMobileTestWithHealing)(
364890
366236
  mobileSteps,
364891
366237
  healTarget,
@@ -364894,7 +366240,11 @@ ${finalVerifyResult.logs ?? ""}`;
364894
366240
  logs: reproduce.logs,
364895
366241
  failingSource: reproduce.failingSource,
364896
366242
  testVariables: run2.testVariables,
364897
- testName: run2.testName
366243
+ testName: run2.testName,
366244
+ tags: tagList,
366245
+ failureCount,
366246
+ apiCalls: reproduceApiCalls,
366247
+ uiPathSucceeded
364898
366248
  },
364899
366249
  healerOptions
364900
366250
  );
@@ -364903,7 +366253,8 @@ ${finalVerifyResult.logs ?? ""}`;
364903
366253
  heal,
364904
366254
  finalError: finalRes?.error ?? null,
364905
366255
  reproduceError,
364906
- testVariables: run2.testVariables
366256
+ testVariables: run2.testVariables,
366257
+ originalSteps: mobileSteps
364907
366258
  });
364908
366259
  await postResult(opts.serverUrl, headers, run2.runId, {
364909
366260
  status: outcome.status,