@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.js CHANGED
@@ -1793,7 +1793,11 @@ var init_constants = __esm({
1793
1793
  "home",
1794
1794
  "waitForElement",
1795
1795
  "assertVisible",
1796
- "assertText"
1796
+ "assertText",
1797
+ /** Capture list labels / badge counts into run-local state bag (Phase 1 oracles). */
1798
+ "captureState",
1799
+ /** Assert a prior captureState delta (removed id, count change, etc.). */
1800
+ "assertStateDelta"
1797
1801
  ];
1798
1802
  BLOCKED_ENV_VARS = /* @__PURE__ */ new Set([
1799
1803
  // Execution / code-injection vectors
@@ -2228,7 +2232,10 @@ function readMobileMetadata(value) {
2228
2232
  webCss: typeof value.webCss === "string" && value.webCss.trim() ? value.webCss.trim() : void 0,
2229
2233
  webviewContext: typeof value.webviewContext === "string" && /^WEBVIEW/i.test(value.webviewContext.trim()) ? value.webviewContext.trim() : void 0,
2230
2234
  matchIndex: hasValidMatchPair ? rawMatchIndex : void 0,
2231
- expectedMatchCount: hasValidMatchPair ? rawExpectedMatchCount : void 0
2235
+ expectedMatchCount: hasValidMatchPair ? rawExpectedMatchCount : void 0,
2236
+ stateKey: typeof value.stateKey === "string" && value.stateKey.trim() ? value.stateKey.trim() : void 0,
2237
+ stateKind: typeof value.stateKind === "string" && value.stateKind.trim() ? value.stateKind.trim() : void 0,
2238
+ expect: typeof value.expect === "string" && value.expect.trim() ? value.expect.trim() : void 0
2232
2239
  };
2233
2240
  }
2234
2241
  function nonEmpty(value) {
@@ -2311,6 +2318,10 @@ function descriptionForStep(action, stepAction, metadata) {
2311
2318
  return `Assert ${label} is visible`;
2312
2319
  case "assertText":
2313
2320
  return `Assert ${label} shows "${action.value ?? action.innerText ?? ""}"`;
2321
+ case "captureState":
2322
+ return `Capture UI state "${metadata.stateKey ?? label}" (${metadata.stateKind ?? "list_ids"})`;
2323
+ case "assertStateDelta":
2324
+ return `Assert state delta "${metadata.stateKey ?? label}" expect=${metadata.expect ?? action.value ?? "changed"}`;
2314
2325
  default:
2315
2326
  return `Execute ${stepAction}`;
2316
2327
  }
@@ -2356,6 +2367,8 @@ function buildMobileStep(action, order) {
2356
2367
  step.assertion = `${labelForAction(action, metadata)} should be visible`;
2357
2368
  } else if (stepAction === "assertText") {
2358
2369
  step.assertion = action.value ?? action.innerText ?? void 0;
2370
+ } else if (stepAction === "assertStateDelta") {
2371
+ step.assertion = metadata.expect ?? action.value ?? "changed";
2359
2372
  }
2360
2373
  if ((stepAction === "swipe" || stepAction === "scroll") && (metadata.direction || metadata.distance)) {
2361
2374
  const stepMetadata = ensureMetadata(step);
@@ -2364,6 +2377,24 @@ function buildMobileStep(action, order) {
2364
2377
  if (metadata.distance)
2365
2378
  stepMetadata.distance = metadata.distance;
2366
2379
  }
2380
+ if (stepAction === "captureState" || stepAction === "assertStateDelta") {
2381
+ const stepMetadata = ensureMetadata(step);
2382
+ const stateKey = nonEmpty(metadata.stateKey) ?? nonEmpty(action.selector) ?? nonEmpty(metadata.targetLabel) ?? `state-${order}`;
2383
+ stepMetadata.stateKey = stateKey;
2384
+ if (stepAction === "captureState") {
2385
+ stepMetadata.stateKind = nonEmpty(metadata.stateKind) ?? "list_ids";
2386
+ }
2387
+ if (stepAction === "assertStateDelta") {
2388
+ stepMetadata.expect = nonEmpty(metadata.expect) ?? nonEmpty(action.value) ?? "changed";
2389
+ }
2390
+ if (!step.target) {
2391
+ step.target = {
2392
+ primary: stateKey,
2393
+ fallbacks: [],
2394
+ screenName: metadata.screenName || "UnknownScreen"
2395
+ };
2396
+ }
2397
+ }
2367
2398
  return step;
2368
2399
  }
2369
2400
  function buildLaunchStep(target, medium, appResetOnLaunch = false) {
@@ -2575,6 +2606,9 @@ function buildAppiumCode(testName, target, steps) {
2575
2606
  used.find = true;
2576
2607
  }
2577
2608
  break;
2609
+ case "captureState":
2610
+ case "assertStateDelta":
2611
+ break;
2578
2612
  default:
2579
2613
  break;
2580
2614
  }
@@ -2693,6 +2727,8 @@ function buildAppiumCode(testName, target, steps) {
2693
2727
  const expectedLiteral = toJsStringLiteral(step.assertion ?? "");
2694
2728
  const replayExpected = step.assertion?.includes("{{") ? `resolveValue(${expectedLiteral})` : expectedLiteral;
2695
2729
  pushAction(`await expectText(driver, ${sel}, ${replayExpected});`);
2730
+ } else if (step.action === "captureState" || step.action === "assertStateDelta") {
2731
+ lines.push(` // ${step.action}: ${step.description.replace(/\n/g, " ").slice(0, 120)}`);
2696
2732
  } else if (step.action === "back") {
2697
2733
  lines.push(` await driver.back();`);
2698
2734
  } else if (step.action === "home") {
@@ -3035,7 +3071,9 @@ var init_mobile_test_generation = __esm({
3035
3071
  HOME: "home",
3036
3072
  WAIT_FOR_ELEMENT: "waitForElement",
3037
3073
  ASSERT_VISIBLE: "assertVisible",
3038
- ASSERT_TEXT: "assertText"
3074
+ ASSERT_TEXT: "assertText",
3075
+ CAPTURE_STATE: "captureState",
3076
+ ASSERT_STATE_DELTA: "assertStateDelta"
3039
3077
  };
3040
3078
  MOBILE_VALUE_PLACEHOLDER_RE = /\{\{([A-Za-z0-9_]+)\}\}/g;
3041
3079
  }
@@ -3266,7 +3304,9 @@ var init_mobile_step_healer = __esm({
3266
3304
  "home",
3267
3305
  "waitForElement",
3268
3306
  "assertVisible",
3269
- "assertText"
3307
+ "assertText",
3308
+ "captureState",
3309
+ "assertStateDelta"
3270
3310
  ]);
3271
3311
  FOREIGN_PACKAGE_RE = /\b[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*){2,}\b/gi;
3272
3312
  ANDROID_RESOURCE_OWNER_RE = /([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+):id\//gi;
@@ -80305,6 +80345,306 @@ ${JSON.stringify(gatePlan)}`;
80305
80345
  }
80306
80346
  });
80307
80347
 
80348
+ // ../runner-core/dist/services/mobile/scenario-taxonomy.js
80349
+ var require_scenario_taxonomy = __commonJS({
80350
+ "../runner-core/dist/services/mobile/scenario-taxonomy.js"(exports2) {
80351
+ "use strict";
80352
+ Object.defineProperty(exports2, "__esModule", { value: true });
80353
+ exports2.ALL_SCENARIO_KINDS = void 0;
80354
+ exports2.extractUiSignals = extractUiSignals;
80355
+ exports2.requiredScenarioKinds = requiredScenarioKinds;
80356
+ exports2.coverageGaps = coverageGaps;
80357
+ exports2.inferScenarioKind = inferScenarioKind;
80358
+ exports2.inferScenarioKinds = inferScenarioKinds;
80359
+ exports2.isStrongOracleKind = isStrongOracleKind;
80360
+ exports2.formatRequiredScenarioKindsPrompt = formatRequiredScenarioKindsPrompt;
80361
+ exports2.formatCoverageGapLog = formatCoverageGapLog;
80362
+ exports2.ALL_SCENARIO_KINDS = [
80363
+ "smoke_nav",
80364
+ "happy_submit",
80365
+ "negative_validation",
80366
+ "crud_identity",
80367
+ "count_delta",
80368
+ "persistence_roundtrip",
80369
+ "auth_session",
80370
+ "navigation_integrity",
80371
+ "permission_system",
80372
+ "double_submit"
80373
+ ];
80374
+ var DELETE_RE = /\b(delete|remove|archive|trash)\b/i;
80375
+ var EMAIL_RE = /\b(e-?mail|email address)\b/i;
80376
+ var PASSWORD_RE = /\b(password|passcode|pin)\b/i;
80377
+ var SIGN_OUT_RE = /\b(sign\s*out|log\s*out|logout)\b/i;
80378
+ var TOGGLE_RE = /\b(toggle|switch|enable|disable|on\/off)\b/i;
80379
+ var SUBMIT_RE = /\b(submit|save|send|create|confirm|apply|done|update|post)\b/i;
80380
+ var BADGE_OR_COUNT_RE = /\b(\d+)\s*(item|items|open|unread|invoice|message|result|pending|new)\b/i;
80381
+ var BADGE_LABEL_RE = /\b(badge|count|open invoices|unread|notifications?)\b/i;
80382
+ var PERMISSION_RE = /\b(camera|microphone|location|photos?|permission|allow access|not now)\b/i;
80383
+ var SETTINGS_RE = /\b(settings|preferences|profile|account)\b/i;
80384
+ var TAB_RE = /\b(tab|home|catalog|forms|edges|inbox|feed|dashboard)\b/i;
80385
+ function elementText(el) {
80386
+ return [
80387
+ el.label ?? "",
80388
+ el.text ?? "",
80389
+ el.accessibilityId ?? "",
80390
+ el.resourceId ?? "",
80391
+ el.role ?? ""
80392
+ ].join(" ");
80393
+ }
80394
+ function isEditable(el) {
80395
+ const role = el.role ?? "";
80396
+ return /EditText|TextField|SecureTextField|SearchField|AutoComplete|textbox|searchbox/i.test(role) || el.role === "textbox" || el.role === "searchbox";
80397
+ }
80398
+ function isToggle(el) {
80399
+ const role = el.role ?? "";
80400
+ return /Switch|CheckBox|Toggle|RadioButton/i.test(role) || TOGGLE_RE.test(elementText(el));
80401
+ }
80402
+ function isRowAction(el) {
80403
+ const t = elementText(el);
80404
+ return DELETE_RE.test(t) && el.actionable !== false;
80405
+ }
80406
+ function extractUiSignals(graph, appId) {
80407
+ const screens = [...graph.screens.values()].filter((s) => {
80408
+ if (!appId)
80409
+ return true;
80410
+ return s.screenId === appId || s.screenId.startsWith(`${appId}#`) || s.screenId.startsWith(`${appId}.`);
80411
+ });
80412
+ let hasListWithRowActions = false;
80413
+ let hasFormFields = false;
80414
+ let hasEmailField = false;
80415
+ let hasNumericBadge = false;
80416
+ let hasSettingsToggles = false;
80417
+ let hasSignOut = false;
80418
+ let hasDestructiveConfirm = false;
80419
+ let hasPrimarySubmit = false;
80420
+ let hasTabOrDrawerNav = false;
80421
+ let hasPermissionCopy = false;
80422
+ for (const state2 of screens) {
80423
+ const labels = state2.elements.map(elementText);
80424
+ const blob = [state2.screenName ?? "", state2.screenType ?? "", ...state2.observations ?? [], ...labels].join(" ");
80425
+ if (PASSWORD_RE.test(blob) || state2.elements.some(isEditable))
80426
+ hasFormFields = true;
80427
+ if (labels.some((t) => EMAIL_RE.test(t)) || state2.elements.some((el) => isEditable(el) && EMAIL_RE.test(elementText(el)))) {
80428
+ hasEmailField = true;
80429
+ hasFormFields = true;
80430
+ }
80431
+ if (state2.elements.some(isRowAction))
80432
+ hasListWithRowActions = true;
80433
+ if (!hasListWithRowActions && state2.elements.filter((el) => el.actionable).length >= 6 && DELETE_RE.test(blob)) {
80434
+ hasListWithRowActions = true;
80435
+ }
80436
+ if (BADGE_OR_COUNT_RE.test(blob) || BADGE_LABEL_RE.test(blob))
80437
+ hasNumericBadge = true;
80438
+ if (state2.elements.some(isToggle) || SETTINGS_RE.test(blob) && TOGGLE_RE.test(blob)) {
80439
+ hasSettingsToggles = true;
80440
+ }
80441
+ if (SIGN_OUT_RE.test(blob))
80442
+ hasSignOut = true;
80443
+ if (DELETE_RE.test(blob) && /\b(confirm|are you sure|permanently)\b/i.test(blob)) {
80444
+ hasDestructiveConfirm = true;
80445
+ }
80446
+ if (labels.some((t) => SUBMIT_RE.test(t)))
80447
+ hasPrimarySubmit = true;
80448
+ if (TAB_RE.test(blob) || state2.screenType === "TAB" || /\btab\b/i.test(state2.screenName ?? "")) {
80449
+ hasTabOrDrawerNav = true;
80450
+ }
80451
+ if (PERMISSION_RE.test(blob) || state2.screenType === "PERMISSION")
80452
+ hasPermissionCopy = true;
80453
+ }
80454
+ return {
80455
+ hasListWithRowActions,
80456
+ hasFormFields,
80457
+ hasEmailField,
80458
+ hasNumericBadge,
80459
+ hasSettingsToggles,
80460
+ hasSignOut,
80461
+ hasDestructiveConfirm,
80462
+ hasPrimarySubmit,
80463
+ hasTabOrDrawerNav,
80464
+ hasPermissionCopy
80465
+ };
80466
+ }
80467
+ function requiredScenarioKinds(signals) {
80468
+ const kinds = /* @__PURE__ */ new Set(["smoke_nav"]);
80469
+ if (signals.hasFormFields || signals.hasPrimarySubmit) {
80470
+ kinds.add("happy_submit");
80471
+ }
80472
+ if (signals.hasFormFields || signals.hasEmailField) {
80473
+ kinds.add("negative_validation");
80474
+ }
80475
+ if (signals.hasListWithRowActions) {
80476
+ kinds.add("crud_identity");
80477
+ }
80478
+ if (signals.hasNumericBadge) {
80479
+ kinds.add("count_delta");
80480
+ }
80481
+ if (signals.hasSettingsToggles) {
80482
+ kinds.add("persistence_roundtrip");
80483
+ }
80484
+ if (signals.hasSignOut) {
80485
+ kinds.add("auth_session");
80486
+ }
80487
+ if (signals.hasTabOrDrawerNav) {
80488
+ kinds.add("navigation_integrity");
80489
+ }
80490
+ if (signals.hasPermissionCopy) {
80491
+ kinds.add("permission_system");
80492
+ }
80493
+ if (signals.hasPrimarySubmit && signals.hasFormFields) {
80494
+ kinds.add("double_submit");
80495
+ }
80496
+ return exports2.ALL_SCENARIO_KINDS.filter((k) => kinds.has(k));
80497
+ }
80498
+ function coverageGaps(signals, plannedKinds) {
80499
+ const planned = new Set(plannedKinds);
80500
+ return requiredScenarioKinds(signals).filter((k) => !planned.has(k));
80501
+ }
80502
+ function inferScenarioKind(scenario) {
80503
+ const text = `${scenario.name} ${scenario.goal} ${scenario.variant ?? ""} ${scenario.type}`.toLowerCase();
80504
+ 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)) {
80505
+ return "negative_validation";
80506
+ }
80507
+ if (/\b(delete|remove|wrong row|entity|archive)\b/.test(text) && /\b(list|row|item|record)\b/.test(text)) {
80508
+ return "crud_identity";
80509
+ }
80510
+ if (/\b(badge|count|unread|open invoices|\+\d|increment|decrement)\b/.test(text)) {
80511
+ return "count_delta";
80512
+ }
80513
+ if (/\b(persist|revisit|return|leave|settings|toggle|favorite|remember)\b/.test(text)) {
80514
+ return "persistence_roundtrip";
80515
+ }
80516
+ 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)) {
80517
+ return "auth_session";
80518
+ }
80519
+ if (/\b(tab|navigate|navigation|back|deep link|empty.?state)\b/.test(text)) {
80520
+ return "navigation_integrity";
80521
+ }
80522
+ if (/\b(permission|camera|microphone|location|allow)\b/.test(text)) {
80523
+ return "permission_system";
80524
+ }
80525
+ if (/\b(double|twice|duplicate submit|double.?tap)\b/.test(text)) {
80526
+ return "double_submit";
80527
+ }
80528
+ if (scenario.type === "HAPPY_PATH" || scenario.variant === "happy") {
80529
+ return "happy_submit";
80530
+ }
80531
+ if (scenario.type === "USER_JOURNEY" || scenario.type === "REGRESSION") {
80532
+ return "navigation_integrity";
80533
+ }
80534
+ return "smoke_nav";
80535
+ }
80536
+ function inferScenarioKinds(scenarios) {
80537
+ return [...new Set(scenarios.map(inferScenarioKind))];
80538
+ }
80539
+ function isStrongOracleKind(kind) {
80540
+ return kind !== "smoke_nav" && kind !== "navigation_integrity";
80541
+ }
80542
+ function formatRequiredScenarioKindsPrompt(signals) {
80543
+ const required = requiredScenarioKinds(signals);
80544
+ if (required.length === 0)
80545
+ return "";
80546
+ const lines = required.map((kind) => {
80547
+ switch (kind) {
80548
+ case "smoke_nav":
80549
+ return '- smoke_nav: reach a primary destination and prove it with a durable product signal (not only "tab visible")';
80550
+ case "happy_submit":
80551
+ return "- happy_submit: complete a form/primary action and assert the durable result (new row, saved state, success that outlives a toast)";
80552
+ case "negative_validation":
80553
+ 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";
80554
+ case "crud_identity":
80555
+ 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")';
80556
+ case "count_delta":
80557
+ return "- count_delta: capture a numeric badge/count, perform an action, assert the number changed as expected";
80558
+ case "persistence_roundtrip":
80559
+ return "- persistence_roundtrip: change a setting/toggle, leave the screen (or relaunch if policy allows), return, assert value persisted";
80560
+ case "auth_session":
80561
+ return "- auth_session: prove sign-in session (profile/sign-out) and/or sign-out leaves only logged-out chrome";
80562
+ case "navigation_integrity":
80563
+ return "- navigation_integrity: tab/drawer/back reaches the intended screen family";
80564
+ case "permission_system":
80565
+ return "- permission_system: permission prompt or settings path behaves honestly (allow/deny/settings)";
80566
+ case "double_submit":
80567
+ return "- double_submit: single user intent must not double-create (assert count +1 not +2, or single confirmation)";
80568
+ default:
80569
+ return `- ${kind}`;
80570
+ }
80571
+ });
80572
+ 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");
80573
+ }
80574
+ function formatCoverageGapLog(gaps) {
80575
+ if (gaps.length === 0)
80576
+ return "Scenario taxonomy: all required kinds covered by plan";
80577
+ return `Scenario taxonomy coverage gaps (required but not planned): ${gaps.join(", ")}`;
80578
+ }
80579
+ }
80580
+ });
80581
+
80582
+ // ../runner-core/dist/services/mobile/coverage-map.js
80583
+ var require_coverage_map = __commonJS({
80584
+ "../runner-core/dist/services/mobile/coverage-map.js"(exports2) {
80585
+ "use strict";
80586
+ Object.defineProperty(exports2, "__esModule", { value: true });
80587
+ exports2.buildMobileCoverageMap = buildMobileCoverageMap;
80588
+ var scenario_taxonomy_js_1 = require_scenario_taxonomy();
80589
+ function strongLookup(name, map2) {
80590
+ if (!map2)
80591
+ return false;
80592
+ if (map2 instanceof Map)
80593
+ return map2.get(name) === true;
80594
+ return Object.prototype.hasOwnProperty.call(map2, name) && map2[name] === true;
80595
+ }
80596
+ function buildMobileCoverageMap(input) {
80597
+ const signals = (0, scenario_taxonomy_js_1.extractUiSignals)(input.graph, input.appId);
80598
+ const required = (0, scenario_taxonomy_js_1.requiredScenarioKinds)(signals);
80599
+ const planned = input.plannedScenarios ?? [];
80600
+ const plannedKinds = planned.map(scenario_taxonomy_js_1.inferScenarioKind);
80601
+ const plannedSet = new Set(plannedKinds);
80602
+ const gaps = (0, scenario_taxonomy_js_1.coverageGaps)(signals, plannedKinds);
80603
+ const kindsWithStrong = /* @__PURE__ */ new Set();
80604
+ for (const s of planned) {
80605
+ const kind = (0, scenario_taxonomy_js_1.inferScenarioKind)(s);
80606
+ const isStrong = (0, scenario_taxonomy_js_1.isStrongOracleKind)(kind) || strongLookup(s.name, input.strongByScenarioName);
80607
+ if (isStrong)
80608
+ kindsWithStrong.add(kind);
80609
+ }
80610
+ const warnings = [];
80611
+ const entries = required.map((kind) => {
80612
+ const isPlanned = plannedSet.has(kind);
80613
+ const strongPlanned = kindsWithStrong.has(kind);
80614
+ let warning;
80615
+ if (!isPlanned) {
80616
+ warning = `Required kind "${kind}" has no planned scenario`;
80617
+ warnings.push(warning);
80618
+ } else if (!strongPlanned && (0, scenario_taxonomy_js_1.isStrongOracleKind)(kind)) {
80619
+ warning = `Kind "${kind}" is planned but has no strong-oracle scenario (smoke-only coverage)`;
80620
+ warnings.push(warning);
80621
+ }
80622
+ return {
80623
+ kind,
80624
+ required: true,
80625
+ planned: isPlanned,
80626
+ strongPlanned,
80627
+ warning
80628
+ };
80629
+ });
80630
+ if (planned.length > 0 && plannedKinds.every((k) => k === "smoke_nav" || k === "navigation_integrity")) {
80631
+ const w = "All planned scenarios are smoke/nav \u2014 no strong product oracles";
80632
+ if (!warnings.includes(w))
80633
+ warnings.push(w);
80634
+ }
80635
+ 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)}`;
80636
+ return {
80637
+ signals,
80638
+ requiredKinds: required,
80639
+ gaps,
80640
+ entries,
80641
+ warnings,
80642
+ summary
80643
+ };
80644
+ }
80645
+ }
80646
+ });
80647
+
80308
80648
  // ../runner-core/dist/services/mobile/mobile-discovery-prompts.js
80309
80649
  var require_mobile_discovery_prompts = __commonJS({
80310
80650
  "../runner-core/dist/services/mobile/mobile-discovery-prompts.js"(exports2) {
@@ -80322,6 +80662,8 @@ var require_mobile_discovery_prompts = __commonJS({
80322
80662
  var ai_provider_js_1 = require_ai_provider();
80323
80663
  var discover_ai_planner_js_1 = require_discover_ai_planner();
80324
80664
  var mobile_observation_js_1 = require_mobile_observation();
80665
+ var scenario_taxonomy_js_1 = require_scenario_taxonomy();
80666
+ var coverage_map_js_1 = require_coverage_map();
80325
80667
  function isTargetAppScreenId(screenId, appId) {
80326
80668
  if (!appId)
80327
80669
  return true;
@@ -80403,7 +80745,7 @@ Return ONLY one valid JSON object matching the schema below. Do NOT include <thi
80403
80745
  9. **No duplicates** - check existing test names before adding
80404
80746
  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.
80405
80747
  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.
80406
- 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:
80748
+ 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:
80407
80749
  - The trigger step (Tap Submit / Generate / Send / Upload / Run / Analyze / Save / Pay / etc.)
80408
80750
  - 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.
80409
80751
  - 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.
@@ -80803,6 +81145,14 @@ SCOPE: this is a feature-focused deep run. Plan scenarios ONLY for the "${contex
80803
81145
  sections.push(`## Operator notes
80804
81146
  ${context.userNotes.trim()}`);
80805
81147
  }
81148
+ if (context.mode === "deep" || context.mode === "full") {
81149
+ const signals = (0, scenario_taxonomy_js_1.extractUiSignals)(graph, context.appId);
81150
+ const requiredBlock = (0, scenario_taxonomy_js_1.formatRequiredScenarioKindsPrompt)(signals);
81151
+ if (requiredBlock) {
81152
+ sections.push(requiredBlock);
81153
+ 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.');
81154
+ }
81155
+ }
80806
81156
  const orderedScreens = plannableTargetAppScreens(graph, context.appId).sort((a, b) => a.firstSeenIteration - b.firstSeenIteration || a.screenId.localeCompare(b.screenId));
80807
81157
  const includedScreenIds = new Set(orderedScreens.map((state2) => state2.screenId));
80808
81158
  const maxElementsPerScreen = context.mode === "survey" ? SURVEY_MAX_ELEMENTS_PER_SCREEN : MAX_ELEMENTS_PER_SCREEN;
@@ -81526,6 +81876,43 @@ ${constraints.join("\n")}`);
81526
81876
  mobileAdaptationLogs.push(`Dropped ${guestWallFilter.dropped} guest-wall scenario(s) \u2014 explore session was authenticated; re-exec would not see sign-in gates`);
81527
81877
  }
81528
81878
  const plannedScenarios = guestWallFilter.scenarios;
81879
+ let taxonomyGapLogs = [];
81880
+ let taxonomyCoverageGaps = result.coverageGaps ?? [];
81881
+ if (input.mode !== "survey" && plannedScenarios.length > 0) {
81882
+ const signals = (0, scenario_taxonomy_js_1.extractUiSignals)(input.graph, input.appId);
81883
+ const plannedKinds = (0, scenario_taxonomy_js_1.inferScenarioKinds)(plannedScenarios);
81884
+ const gaps = (0, scenario_taxonomy_js_1.coverageGaps)(signals, plannedKinds);
81885
+ const coverageMap = (0, coverage_map_js_1.buildMobileCoverageMap)({
81886
+ graph: input.graph,
81887
+ appId: input.appId,
81888
+ plannedScenarios
81889
+ });
81890
+ taxonomyGapLogs = [(0, scenario_taxonomy_js_1.formatCoverageGapLog)(gaps), coverageMap.summary];
81891
+ if (coverageMap.warnings.length > 0) {
81892
+ taxonomyGapLogs.push(...coverageMap.warnings.slice(0, 12));
81893
+ }
81894
+ if (gaps.length > 0) {
81895
+ 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}`);
81896
+ const detectedAt = (/* @__PURE__ */ new Date()).toISOString();
81897
+ taxonomyCoverageGaps = [
81898
+ ...taxonomyCoverageGaps,
81899
+ ...gaps.map((kind) => ({
81900
+ scenarioName: `[taxonomy] ${kind}`,
81901
+ reason: `Required scenario kind "${kind}" not represented in the planned set`,
81902
+ suggestion: `Add a ${kind} scenario backed by observed controls, or document impossibility`,
81903
+ unmetPrerequisites: [],
81904
+ detectedAt
81905
+ })),
81906
+ ...coverageMap.warnings.filter((w) => /smoke-only|no strong-oracle/i.test(w)).map((w) => ({
81907
+ scenarioName: "[coverage-map] strong-oracle gap",
81908
+ reason: w,
81909
+ suggestion: "Author durable assertStateDelta/assertText outcomes for this kind",
81910
+ unmetPrerequisites: [],
81911
+ detectedAt
81912
+ }))
81913
+ ];
81914
+ }
81915
+ }
81529
81916
  if (input.mode !== "survey" && plannedScenarios.length === 0 && input.graph.screens.size > 0) {
81530
81917
  const fallbackScenarios = buildMobileFallbackScenarios(input);
81531
81918
  if (fallbackScenarios.length > 0) {
@@ -81584,7 +81971,8 @@ ${constraints.join("\n")}`);
81584
81971
  ...result,
81585
81972
  scenarios: plannedScenarios,
81586
81973
  featureGroups: mobileFeatureGroups,
81587
- logs: [...result.logs, ...mobileAdaptationLogs]
81974
+ coverageGaps: taxonomyCoverageGaps.length > 0 ? taxonomyCoverageGaps : result.coverageGaps,
81975
+ logs: [...result.logs, ...mobileAdaptationLogs, ...taxonomyGapLogs]
81588
81976
  };
81589
81977
  }
81590
81978
  }
@@ -81663,6 +82051,7 @@ var require_mobile_generator = __commonJS({
81663
82051
  var ai_retry_js_1 = require_ai_retry();
81664
82052
  var mobile_session_keepalive_js_1 = require_mobile_session_keepalive();
81665
82053
  var discovery_lint_flags_js_1 = require_discovery_lint_flags();
82054
+ var scenario_taxonomy_js_1 = require_scenario_taxonomy();
81666
82055
  var mobile_source_parser_js_1 = require_mobile_source_parser();
81667
82056
  var mobile_source_parser_js_2 = require_mobile_source_parser();
81668
82057
  var mobile_observation_js_1 = require_mobile_observation();
@@ -81804,6 +82193,50 @@ var require_mobile_generator = __commonJS({
81804
82193
  }
81805
82194
  }
81806
82195
  };
82196
+ var MOBILE_CAPTURE_STATE_TOOL = {
82197
+ type: "function",
82198
+ function: {
82199
+ name: "mobile_capture_state",
82200
+ 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".',
82201
+ parameters: {
82202
+ type: "object",
82203
+ properties: {
82204
+ stateKey: {
82205
+ type: "string",
82206
+ description: 'Short key for this bag entry (e.g. "invoice_list", "open_count"). Reuse the same key in mobile_assert_state_delta.'
82207
+ },
82208
+ kind: {
82209
+ type: "string",
82210
+ enum: ["list_ids", "badge_count"],
82211
+ description: "list_ids = unique visible labels; badge_count = numeric count tokens. Default list_ids."
82212
+ }
82213
+ },
82214
+ required: ["stateKey"]
82215
+ }
82216
+ }
82217
+ };
82218
+ var MOBILE_ASSERT_STATE_DELTA_TOOL = {
82219
+ type: "function",
82220
+ function: {
82221
+ name: "mobile_assert_state_delta",
82222
+ 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.",
82223
+ parameters: {
82224
+ type: "object",
82225
+ properties: {
82226
+ stateKey: {
82227
+ type: "string",
82228
+ description: "Must match a prior mobile_capture_state stateKey in this scenario."
82229
+ },
82230
+ expect: {
82231
+ type: "string",
82232
+ enum: ["changed", "entity_removed", "count_decreased", "count_increased", "unchanged", "persisted"],
82233
+ description: "What must differ (or persist) vs the prior capture. Default: changed."
82234
+ }
82235
+ },
82236
+ required: ["stateKey"]
82237
+ }
82238
+ }
82239
+ };
81807
82240
  var MOBILE_FILL_CREDENTIAL_TOOL = {
81808
82241
  type: "function",
81809
82242
  function: {
@@ -81826,7 +82259,7 @@ var require_mobile_generator = __commonJS({
81826
82259
  type: "function",
81827
82260
  function: {
81828
82261
  name: "finish_generate",
81829
- 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.",
82262
+ 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.",
81830
82263
  parameters: {
81831
82264
  type: "object",
81832
82265
  properties: {
@@ -81858,6 +82291,8 @@ var require_mobile_generator = __commonJS({
81858
82291
  MOBILE_RELAUNCH_TOOL,
81859
82292
  MOBILE_ASSERT_VISIBLE_TOOL,
81860
82293
  MOBILE_ASSERT_TEXT_TOOL,
82294
+ MOBILE_CAPTURE_STATE_TOOL,
82295
+ MOBILE_ASSERT_STATE_DELTA_TOOL,
81861
82296
  FINISH_GENERATE_TOOL
81862
82297
  ];
81863
82298
  var STRUCTURAL_KEY_MAX_ELEMENTS = 16;
@@ -82124,6 +82559,7 @@ The scenario name + goal + steps describe ONE product behavior from survey/disco
82124
82559
  - Navigation scenarios: you MUST land on the destination and assert something unique to it.
82125
82560
  4. PROVE the outcome with an assert tool that matches the scenario \u2014 not ambient chrome:
82126
82561
  - mobile_assert_visible({ref}) / mobile_assert_text({ref, expected})
82562
+ - 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".
82127
82563
  - 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.
82128
82564
  - Do NOT assert bottom-nav tab labels alone, notification badge counts ("N unread"), or one-time empty-state CTAs as the scenario outcome.
82129
82565
  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.
@@ -82237,6 +82673,7 @@ Start by calling mobile_snapshot, then execute ONLY the steps needed for this go
82237
82673
  const { scenario, driver, platform: platform3, maxIterations, agentModel, provider, aiClient, auditGroupId, onAICall, onScreenshot, targetAppId, credentials, redactionCredentials, log: emitLog, allowRelaunch } = args;
82238
82674
  const log2 = (line) => emitLog(redactCredentialValues(line, redactionCredentials));
82239
82675
  const actions = [];
82676
+ const stateBag = /* @__PURE__ */ new Map();
82240
82677
  let assertCount = 0;
82241
82678
  let finish = null;
82242
82679
  let finishIntentRejections = 0;
@@ -82706,7 +83143,9 @@ ${statePacket}`, redactionCredentials) },
82706
83143
  const screenDependentTools = /* @__PURE__ */ new Set([
82707
83144
  ...screenMutatingTools,
82708
83145
  "mobile_assert_visible",
82709
- "mobile_assert_text"
83146
+ "mobile_assert_text",
83147
+ "mobile_capture_state",
83148
+ "mobile_assert_state_delta"
82710
83149
  ]);
82711
83150
  for (const toolCall of assistantMessage.tool_calls) {
82712
83151
  const toolName = toolCall.function.name;
@@ -82750,7 +83189,7 @@ ${statePacket}`, redactionCredentials) },
82750
83189
  if (intentReason)
82751
83190
  reasons.push(intentReason);
82752
83191
  if (verifiedWithoutAssert) {
82753
- reasons.push("claimed verified:true but never called mobile_assert_visible / mobile_assert_text");
83192
+ reasons.push("claimed verified:true but never called mobile_assert_visible / mobile_assert_text / mobile_assert_state_delta");
82754
83193
  }
82755
83194
  if (strengthRejectReason !== null) {
82756
83195
  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.`);
@@ -82821,10 +83260,12 @@ ${statePacket}`, redactionCredentials) },
82821
83260
  }
82822
83261
  } : action;
82823
83262
  actions.push((0, shared_1.placeholderizeRecordedMobileAction)(finalizeAction(stamped), credentials));
82824
- if (action.type === "ASSERT_VISIBLE" || action.type === "ASSERT_TEXT")
83263
+ if (action.type === "ASSERT_VISIBLE" || action.type === "ASSERT_TEXT" || action.type === "ASSERT_STATE_DELTA") {
82825
83264
  assertCount++;
83265
+ }
82826
83266
  },
82827
83267
  recordedActions: actions,
83268
+ stateBag,
82828
83269
  log: log2
82829
83270
  });
82830
83271
  if (screenMutatingTools.has(toolName))
@@ -82843,7 +83284,7 @@ ${statePacket}`, redactionCredentials) },
82843
83284
  return { actions, assertCount, finish, lastSnapshot: lastTargetSnapshot, lastScreenName: lastTargetScreenName };
82844
83285
  }
82845
83286
  async function dispatchGenerateTool(args) {
82846
- const { toolName, toolArgs, driver, platform: platform3, targetAppId, latest, absorbObservation, resolveRef, resolveHybridRef, maybeEnrichHybridWeb, setLatest, credentials, screenName, allowRelaunch, recordAction, recordedActions, log: log2 } = args;
83287
+ const { toolName, toolArgs, driver, platform: platform3, targetAppId, latest, absorbObservation, resolveRef, resolveHybridRef, maybeEnrichHybridWeb, setLatest, credentials, screenName, allowRelaunch, recordAction, recordedActions, stateBag, log: log2 } = args;
82847
83288
  const unknownRef = (ref) => ({
82848
83289
  ok: false,
82849
83290
  error: `Unknown element ref "${String(ref)}". Call mobile_snapshot first; refs are only valid for the latest snapshot.`
@@ -83388,10 +83829,170 @@ ${statePacket}`, redactionCredentials) },
83388
83829
  target: metadata.targetLabel
83389
83830
  };
83390
83831
  }
83832
+ case "mobile_capture_state": {
83833
+ const stateKey = nonEmpty3(typeof toolArgs.stateKey === "string" ? toolArgs.stateKey : "");
83834
+ if (!stateKey) {
83835
+ return { ok: false, error: "mobile_capture_state requires a non-empty stateKey." };
83836
+ }
83837
+ const kindRaw = typeof toolArgs.kind === "string" ? toolArgs.kind.trim() : "list_ids";
83838
+ const kind = kindRaw === "badge_count" ? "badge_count" : "list_ids";
83839
+ const snap = latest();
83840
+ if (!snap) {
83841
+ return { ok: false, error: "No snapshot yet \u2014 call mobile_snapshot before mobile_capture_state." };
83842
+ }
83843
+ const values = captureValuesFromElements(snap.screen.elements, kind);
83844
+ stateBag.set(stateKey, { kind, values });
83845
+ recordAction({
83846
+ type: "CAPTURE_STATE",
83847
+ selector: stateKey,
83848
+ metadata: {
83849
+ screenName: screenName(),
83850
+ targetLabel: stateKey,
83851
+ stateKey,
83852
+ stateKind: kind
83853
+ }
83854
+ });
83855
+ log2(` capture_state: key=${stateKey} kind=${kind} n=${values.length}`);
83856
+ return {
83857
+ ok: true,
83858
+ captured: true,
83859
+ stateKey,
83860
+ kind,
83861
+ sample: values.slice(0, 8),
83862
+ count: values.length
83863
+ };
83864
+ }
83865
+ case "mobile_assert_state_delta": {
83866
+ const stateKey = nonEmpty3(typeof toolArgs.stateKey === "string" ? toolArgs.stateKey : "");
83867
+ if (!stateKey) {
83868
+ return { ok: false, error: "mobile_assert_state_delta requires a non-empty stateKey." };
83869
+ }
83870
+ const prior = stateBag.get(stateKey);
83871
+ if (!prior) {
83872
+ return {
83873
+ ok: false,
83874
+ error: `No prior mobile_capture_state for key "${stateKey}". Capture before the mutating action, then assert.`
83875
+ };
83876
+ }
83877
+ const expectRaw = typeof toolArgs.expect === "string" ? toolArgs.expect.trim() : "changed";
83878
+ const expect = expectRaw || "changed";
83879
+ const snap = latest();
83880
+ if (!snap) {
83881
+ return { ok: false, error: "No snapshot yet \u2014 call mobile_snapshot after the action, then assert_state_delta." };
83882
+ }
83883
+ const current = captureValuesFromElements(snap.screen.elements, prior.kind);
83884
+ const liveError = liveAssertStateDelta(prior.values, current, expect, stateKey);
83885
+ if (liveError) {
83886
+ return {
83887
+ ok: false,
83888
+ error: liveError,
83889
+ beforeSample: prior.values.slice(0, 8),
83890
+ afterSample: current.slice(0, 8)
83891
+ };
83892
+ }
83893
+ recordAction({
83894
+ type: "ASSERT_STATE_DELTA",
83895
+ value: expect,
83896
+ selector: stateKey,
83897
+ metadata: {
83898
+ screenName: screenName(),
83899
+ targetLabel: stateKey,
83900
+ stateKey,
83901
+ stateKind: prior.kind,
83902
+ expect
83903
+ }
83904
+ });
83905
+ log2(` assert_state_delta: key=${stateKey} expect=${expect}`);
83906
+ return {
83907
+ ok: true,
83908
+ asserted: "state_delta",
83909
+ stateKey,
83910
+ expect,
83911
+ beforeCount: prior.values.length,
83912
+ afterCount: current.length
83913
+ };
83914
+ }
83391
83915
  default:
83392
83916
  return { ok: false, error: `Unknown tool: ${toolName}` };
83393
83917
  }
83394
83918
  }
83919
+ function captureValuesFromElements(elements, kind) {
83920
+ if (kind === "badge_count") {
83921
+ const nums = /* @__PURE__ */ new Set();
83922
+ const preferred = /* @__PURE__ */ new Set();
83923
+ for (const el of elements) {
83924
+ const t = [el.label, el.text, el.accessibilityId].filter(Boolean).join(" ");
83925
+ for (const m of t.matchAll(/\b(\d{1,6})\b/g))
83926
+ nums.add(m[1]);
83927
+ if (/(?:count|badge|open|unread|item|invoice|result|pending)/i.test(t)) {
83928
+ for (const m of t.matchAll(/\b(\d{1,6})\b/g))
83929
+ preferred.add(m[1]);
83930
+ }
83931
+ }
83932
+ return preferred.size > 0 ? [...preferred] : [...nums].slice(0, 20);
83933
+ }
83934
+ const labels = /* @__PURE__ */ new Set();
83935
+ for (const el of elements) {
83936
+ for (const raw of [el.label, el.text, el.accessibilityId]) {
83937
+ const t = raw?.trim() ?? "";
83938
+ if (t.length < 2 || t.length > 80)
83939
+ continue;
83940
+ if (/^(true|false|null|OK|Cancel)$/i.test(t))
83941
+ continue;
83942
+ labels.add(t);
83943
+ }
83944
+ }
83945
+ return [...labels].slice(0, 80);
83946
+ }
83947
+ function liveAssertStateDelta(before, after, expect, key) {
83948
+ const beforeSet = new Set(before);
83949
+ const afterSet = new Set(after);
83950
+ const removed = before.filter((v) => !afterSet.has(v));
83951
+ const added = after.filter((v) => !beforeSet.has(v));
83952
+ const exp = expect.toLowerCase().trim();
83953
+ if (exp === "changed" || exp === "any_change") {
83954
+ if (removed.length === 0 && added.length === 0) {
83955
+ return `assertStateDelta(${key}): expected change, captures identical (${before.length} values)`;
83956
+ }
83957
+ return null;
83958
+ }
83959
+ if (exp === "removed" || exp === "entity_removed" || exp.startsWith("removed:")) {
83960
+ if (removed.length === 0) {
83961
+ return `assertStateDelta(${key}): expected at least one entity removed`;
83962
+ }
83963
+ return null;
83964
+ }
83965
+ if (exp === "count_decreased" || exp === "count-1") {
83966
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
83967
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
83968
+ const bMax = b.length ? Math.max(...b) : NaN;
83969
+ const aMax = a.length ? Math.max(...a) : NaN;
83970
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax >= bMax) {
83971
+ return `assertStateDelta(${key}): expected count decrease (before max=${bMax}, after max=${aMax})`;
83972
+ }
83973
+ return null;
83974
+ }
83975
+ if (exp === "count_increased" || exp === "count+1") {
83976
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
83977
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
83978
+ const bMax = b.length ? Math.max(...b) : NaN;
83979
+ const aMax = a.length ? Math.max(...a) : NaN;
83980
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax <= bMax) {
83981
+ return `assertStateDelta(${key}): expected count increase (before max=${bMax}, after max=${aMax})`;
83982
+ }
83983
+ return null;
83984
+ }
83985
+ if (exp === "unchanged" || exp === "persisted") {
83986
+ if (removed.length > 0 || added.length > 0) {
83987
+ return `assertStateDelta(${key}): expected persistence/unchanged but set changed`;
83988
+ }
83989
+ return null;
83990
+ }
83991
+ if (removed.length === 0 && added.length === 0) {
83992
+ return `assertStateDelta(${key}): expected change (expect=${expect}), state identical`;
83993
+ }
83994
+ return null;
83995
+ }
83395
83996
  function recordAssertVisible(toolArgs, ctx) {
83396
83997
  const { resolveRef, latest, screenName, platform: platform3, recordAction } = ctx;
83397
83998
  const element = resolveRef(toolArgs.ref);
@@ -84371,6 +84972,14 @@ ${statePacket}`, redactionCredentials) },
84371
84972
  lines.push(` await expect(page.getByText('${expected}')).toBeVisible();`);
84372
84973
  break;
84373
84974
  }
84975
+ case "CAPTURE_STATE":
84976
+ lines.push(` // captureState ${escape((action.metadata.stateKey ?? label).slice(0, 40))}`);
84977
+ break;
84978
+ case "ASSERT_STATE_DELTA": {
84979
+ const expect = escape((action.metadata.expect ?? action.value ?? "changed").slice(0, 40));
84980
+ lines.push(` await expect(page.getByText('state:${expect}')).toBeVisible();`);
84981
+ break;
84982
+ }
84374
84983
  case "CLEAR":
84375
84984
  lines.push(` await page.getByLabel('${label}').fill('');`);
84376
84985
  break;
@@ -84414,6 +85023,22 @@ ${statePacket}`, redactionCredentials) },
84414
85023
  return [action.selector, action.value, action.innerText, action.metadata?.targetLabel].filter((v) => typeof v === "string" && v.trim().length > 0).join(" ");
84415
85024
  }
84416
85025
  function evaluateMobileAssertionStrength(actions) {
85026
+ if (actions.some((a) => a.type === "ASSERT_STATE_DELTA")) {
85027
+ return {
85028
+ ok: true,
85029
+ severity: "none",
85030
+ reason: "state-delta oracle proves a durable product change (identity/count/persistence)",
85031
+ signals: {
85032
+ apiTest: false,
85033
+ interacted: actions.some((a) => a.type === "TAP" || a.type === "TYPE" || a.type === "CLEAR"),
85034
+ mutated: actions.some((a) => a.type === "TYPE" || a.type === "CLEAR" || a.type === "TAP"),
85035
+ navOnly: false,
85036
+ hasOutcomeProof: true,
85037
+ errorBanner: false,
85038
+ terminal: null
85039
+ }
85040
+ };
85041
+ }
84417
85042
  const modelAsserts = actions.filter((a) => a.type === "ASSERT_VISIBLE" || a.type === "ASSERT_TEXT");
84418
85043
  if (modelAsserts.length === 0) {
84419
85044
  return {
@@ -84583,6 +85208,16 @@ ${statePacket}`, redactionCredentials) },
84583
85208
  if (coldResetUnavailable)
84584
85209
  tags.push("@warm-state");
84585
85210
  const strengthBlocked = !strengthVerdict.ok || strengthVerdict.severity === "block" || strengthVerdict.severity === "route-bug" || !verified || coldResetUnavailable;
85211
+ {
85212
+ const kind = (0, scenario_taxonomy_js_1.inferScenarioKind)(scenario);
85213
+ const hasStateOracle = compiled.steps.some((s) => s.action === "assertStateDelta" || s.action === "assertText" || s.action === "captureState");
85214
+ const strong = verified && !strengthBlocked && strengthVerdict.severity === "none" && ((0, scenario_taxonomy_js_1.isStrongOracleKind)(kind) || hasStateOracle);
85215
+ if (strong)
85216
+ tags.push("@strong-oracle");
85217
+ else if (!tags.includes("@smoke") && (kind === "smoke_nav" || kind === "navigation_integrity")) {
85218
+ tags.push("@smoke");
85219
+ }
85220
+ }
84586
85221
  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;
84587
85222
  const test = {
84588
85223
  name: compiled.name,
@@ -84830,6 +85465,344 @@ Mobile generate phase complete: ${tests.length}/${scenarios.length} test(s) gene
84830
85465
  }
84831
85466
  });
84832
85467
 
85468
+ // ../runner-core/dist/services/mobile/failure-triage.js
85469
+ var require_failure_triage = __commonJS({
85470
+ "../runner-core/dist/services/mobile/failure-triage.js"(exports2) {
85471
+ "use strict";
85472
+ Object.defineProperty(exports2, "__esModule", { value: true });
85473
+ exports2.hasStrongMobileOracle = hasStrongMobileOracle;
85474
+ exports2.isStrongOracleStep = isStrongOracleStep;
85475
+ exports2.listStrongOracleKinds = listStrongOracleKinds;
85476
+ exports2.triageMobileFailure = triageMobileFailure;
85477
+ exports2.triageToHealTerminal = triageToHealTerminal;
85478
+ var STRONG_ACTIONS = /* @__PURE__ */ new Set(["assertStateDelta", "assertText", "captureState"]);
85479
+ var CHROME_VISIBLE_RE = /\b(tab|home|settings|back|menu|navigation|nav bar|bottom nav|status bar)\b/i;
85480
+ function hasStrongMobileOracle(steps) {
85481
+ return steps.some(isStrongOracleStep);
85482
+ }
85483
+ function isStrongOracleStep(step) {
85484
+ if (STRONG_ACTIONS.has(step.action))
85485
+ return true;
85486
+ if (step.action !== "assertVisible")
85487
+ return false;
85488
+ const blob = [
85489
+ step.assertion ?? "",
85490
+ step.description ?? "",
85491
+ step.target?.primary ?? "",
85492
+ ...step.target?.fallbacks ?? []
85493
+ ].join(" ");
85494
+ if (/\b(error|invalid|required|must|cannot|failed|denied|blocked|empty|missing|deleted|removed|saved|success|created|updated)\b/i.test(blob)) {
85495
+ return true;
85496
+ }
85497
+ if (CHROME_VISIBLE_RE.test(blob) && blob.length < 80)
85498
+ return false;
85499
+ return false;
85500
+ }
85501
+ function listStrongOracleKinds(steps) {
85502
+ const kinds = /* @__PURE__ */ new Set();
85503
+ for (const step of steps) {
85504
+ if (step.action === "assertStateDelta")
85505
+ kinds.add("assertStateDelta");
85506
+ else if (step.action === "assertText")
85507
+ kinds.add("assertText");
85508
+ else if (step.action === "captureState")
85509
+ kinds.add("captureState");
85510
+ else if (isStrongOracleStep(step))
85511
+ kinds.add(step.action);
85512
+ }
85513
+ return [...kinds];
85514
+ }
85515
+ function errorText(error2, logs2) {
85516
+ return `${error2 ?? ""}
85517
+ ${logs2 ?? ""}`.trim();
85518
+ }
85519
+ function leadingPrefix(error2) {
85520
+ if (!error2)
85521
+ return null;
85522
+ const m = error2.match(/^(CONFIG_ISSUE|APP_BUG|RATE_LIMIT_BLOCKED|PREREQ_UNMET|HEAL_SECRET_LEAK)\s*:/i);
85523
+ return m ? m[1].toUpperCase() : null;
85524
+ }
85525
+ function looksLikeConfig(text) {
85526
+ if (/CONFIG_ISSUE\s*:/i.test(text))
85527
+ return true;
85528
+ if (/RATE_LIMIT_BLOCKED\s*:/i.test(text))
85529
+ return true;
85530
+ if (/Missing mobile test variable/i.test(text))
85531
+ return true;
85532
+ if (/\b(quota|rate.?limit|429|lockout)\b/i.test(text))
85533
+ return true;
85534
+ if (/\b(device (?:offline|disconnected|not found)|session (?:not started|terminated|deleted))\b/i.test(text)) {
85535
+ return true;
85536
+ }
85537
+ if (/\b(Appium|adbExec|UiAutomator2|XCUITest)\b/i.test(text) && /\b(ECONNREFUSED|timeout|not available|could not start|driver)\b/i.test(text)) {
85538
+ return true;
85539
+ }
85540
+ return false;
85541
+ }
85542
+ function looksLikePrereq(text) {
85543
+ return /PREREQ_UNMET\s*:/i.test(text) || /\b(prerequisite|fixture missing|no test data|account (?:missing|not provisioned)|required entity)\b/i.test(text);
85544
+ }
85545
+ function looksLikeFlake(text) {
85546
+ 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);
85547
+ }
85548
+ function looksLikeLocatorMiss(text) {
85549
+ return /not found|no such element|No identity locator|unable to locate/i.test(text);
85550
+ }
85551
+ function looksLikeOracleFailure(text) {
85552
+ 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);
85553
+ }
85554
+ function triageMobileFailure(input) {
85555
+ const failureCount = Math.max(1, input.failureCount ?? 1);
85556
+ const tags = input.tags ?? [];
85557
+ const text = errorText(input.error, input.logs);
85558
+ const prefix = leadingPrefix(input.error);
85559
+ const strongKinds = listStrongOracleKinds(input.steps);
85560
+ const hasStrong = strongKinds.length > 0 || tags.some((t) => t === "@strong-oracle" || t === "strong-oracle");
85561
+ const evidence = {
85562
+ hasStrongOracle: hasStrong,
85563
+ strongOracleKinds: strongKinds,
85564
+ failureCount,
85565
+ errorPrefix: prefix
85566
+ };
85567
+ if (prefix === "CONFIG_ISSUE" || prefix === "RATE_LIMIT_BLOCKED") {
85568
+ return {
85569
+ verdict: "config_issue",
85570
+ reason: `Environment/config prefix on error (${prefix})`,
85571
+ shouldHeal: false,
85572
+ healVerdict: "config_issue",
85573
+ evidence
85574
+ };
85575
+ }
85576
+ if (prefix === "APP_BUG") {
85577
+ return {
85578
+ verdict: "app_bug_candidate",
85579
+ reason: "Error already classified APP_BUG",
85580
+ shouldHeal: false,
85581
+ healVerdict: "app_bug",
85582
+ evidence
85583
+ };
85584
+ }
85585
+ if (prefix === "PREREQ_UNMET") {
85586
+ return {
85587
+ verdict: "prereq_unmet",
85588
+ reason: "Error already classified PREREQ_UNMET",
85589
+ shouldHeal: false,
85590
+ healVerdict: "prereq_unmet",
85591
+ evidence
85592
+ };
85593
+ }
85594
+ if (looksLikeConfig(text)) {
85595
+ return {
85596
+ verdict: "config_issue",
85597
+ reason: "Failure matches environment/config/device patterns",
85598
+ shouldHeal: false,
85599
+ healVerdict: "config_issue",
85600
+ evidence
85601
+ };
85602
+ }
85603
+ if (looksLikePrereq(text)) {
85604
+ return {
85605
+ verdict: "prereq_unmet",
85606
+ reason: "Failure matches missing prerequisite / fixture patterns",
85607
+ shouldHeal: false,
85608
+ healVerdict: "prereq_unmet",
85609
+ evidence
85610
+ };
85611
+ }
85612
+ if (input.uiSuccessWithFailedWriteApi && hasStrong) {
85613
+ return {
85614
+ verdict: "app_bug_candidate",
85615
+ reason: "UI path completed but a write API failed (network secondary oracle)",
85616
+ shouldHeal: false,
85617
+ healVerdict: "app_bug",
85618
+ evidence
85619
+ };
85620
+ }
85621
+ if (hasStrong && failureCount >= 2 && (looksLikeOracleFailure(text) || !looksLikeLocatorMiss(text))) {
85622
+ if (looksLikeLocatorMiss(text) && failureCount < 3) {
85623
+ return {
85624
+ verdict: "needs_heal",
85625
+ reason: "Strong oracle present but error looks like a locator miss \u2014 attempt heal",
85626
+ shouldHeal: true,
85627
+ evidence
85628
+ };
85629
+ }
85630
+ return {
85631
+ verdict: "app_bug_candidate",
85632
+ reason: `Strong oracle (${strongKinds.join(", ") || "tagged"}) failed ${failureCount}\xD7 with product-shaped error`,
85633
+ shouldHeal: false,
85634
+ healVerdict: "app_bug",
85635
+ evidence
85636
+ };
85637
+ }
85638
+ if (looksLikeFlake(text) && failureCount === 1 && !hasStrong) {
85639
+ return {
85640
+ verdict: "flake_candidate",
85641
+ reason: "Transient interactability / race signals on a weak-oracle test",
85642
+ shouldHeal: true,
85643
+ // still allow heal, but tag flaky path
85644
+ extraTags: ["@flaky"],
85645
+ evidence
85646
+ };
85647
+ }
85648
+ if (tags.includes("@smoke") && !hasStrong && looksLikeLocatorMiss(text)) {
85649
+ return {
85650
+ verdict: "needs_heal",
85651
+ reason: "Smoke/nav locator failure \u2014 heal allowed",
85652
+ shouldHeal: true,
85653
+ evidence
85654
+ };
85655
+ }
85656
+ return {
85657
+ verdict: "needs_heal",
85658
+ reason: hasStrong ? "Strong oracle first failure \u2014 allow heal once before APP_BUG escalation" : "Default: attempt script/live heal",
85659
+ shouldHeal: true,
85660
+ evidence
85661
+ };
85662
+ }
85663
+ function triageToHealTerminal(triage) {
85664
+ if (triage.shouldHeal || !triage.healVerdict)
85665
+ return null;
85666
+ return {
85667
+ verdict: triage.healVerdict,
85668
+ healReason: triage.reason,
85669
+ extraTags: triage.extraTags
85670
+ };
85671
+ }
85672
+ }
85673
+ });
85674
+
85675
+ // ../runner-core/dist/services/mobile/oracle-protection.js
85676
+ var require_oracle_protection = __commonJS({
85677
+ "../runner-core/dist/services/mobile/oracle-protection.js"(exports2) {
85678
+ "use strict";
85679
+ Object.defineProperty(exports2, "__esModule", { value: true });
85680
+ exports2.fingerprintOracles = fingerprintOracles;
85681
+ exports2.rejectOracleWeakeningPatch = rejectOracleWeakeningPatch;
85682
+ exports2.oraclesPreserved = oraclesPreserved;
85683
+ var failure_triage_js_1 = require_failure_triage();
85684
+ var EXPECT_STRENGTH = {
85685
+ entity_removed: 5,
85686
+ removed: 5,
85687
+ count_decreased: 4,
85688
+ "count-1": 4,
85689
+ count_increased: 4,
85690
+ "count+1": 4,
85691
+ persisted: 3,
85692
+ unchanged: 3,
85693
+ changed: 2,
85694
+ any_change: 2
85695
+ };
85696
+ function normalizeText(value) {
85697
+ return (value ?? "").trim().toLowerCase().replace(/\s+/g, " ");
85698
+ }
85699
+ function stateKeyOf(step) {
85700
+ const meta = step.metadata;
85701
+ const key = typeof meta?.stateKey === "string" ? meta.stateKey.trim() : "";
85702
+ return key || normalizeText(step.target?.primary) || normalizeText(step.description) || `order-${step.order}`;
85703
+ }
85704
+ function expectOf(step) {
85705
+ const meta = step.metadata;
85706
+ const fromMeta = typeof meta?.expect === "string" ? meta.expect : "";
85707
+ return normalizeText(fromMeta || step.assertion || step.value || "changed");
85708
+ }
85709
+ function fingerprintOracles(steps) {
85710
+ const assertTexts = [];
85711
+ const stateExpects = {};
85712
+ let stateDeltas = 0;
85713
+ let captures = 0;
85714
+ let strongVisible = 0;
85715
+ for (const step of steps) {
85716
+ if (step.action === "assertStateDelta") {
85717
+ stateDeltas += 1;
85718
+ stateExpects[stateKeyOf(step)] = expectOf(step);
85719
+ } else if (step.action === "captureState")
85720
+ captures += 1;
85721
+ else if (step.action === "assertText") {
85722
+ const t = normalizeText(step.assertion ?? step.value ?? step.description);
85723
+ if (t)
85724
+ assertTexts.push(t);
85725
+ } else if (step.action === "assertVisible" && (0, failure_triage_js_1.isStrongOracleStep)(step)) {
85726
+ strongVisible += 1;
85727
+ }
85728
+ }
85729
+ return {
85730
+ stateDeltas,
85731
+ captures,
85732
+ assertTexts,
85733
+ stateExpects,
85734
+ strongVisible,
85735
+ strongTotal: stateDeltas + captures + assertTexts.length + strongVisible
85736
+ };
85737
+ }
85738
+ function expectStrength(expect) {
85739
+ const e = expect.toLowerCase().trim();
85740
+ if (e.startsWith("removed:"))
85741
+ return 5;
85742
+ return EXPECT_STRENGTH[e] ?? 1;
85743
+ }
85744
+ function rejectOracleWeakeningPatch(original, patched) {
85745
+ if (!Array.isArray(patched) || patched.length === 0) {
85746
+ return "healed steps missing \u2014 refusing empty patch that would drop oracles";
85747
+ }
85748
+ const before = fingerprintOracles(original);
85749
+ const after = fingerprintOracles(patched);
85750
+ if (before.stateDeltas > 0 && after.stateDeltas < before.stateDeltas) {
85751
+ return `heal patch removed assertStateDelta oracle(s) (${before.stateDeltas} \u2192 ${after.stateDeltas}) \u2014 refusing to go green by dropping state proof`;
85752
+ }
85753
+ for (const [key, beforeExpect] of Object.entries(before.stateExpects)) {
85754
+ const afterExpect = after.stateExpects[key];
85755
+ if (!afterExpect) {
85756
+ return `heal patch removed assertStateDelta for key "${key}" (expect was ${beforeExpect})`;
85757
+ }
85758
+ if (expectStrength(afterExpect) < expectStrength(beforeExpect)) {
85759
+ return `heal patch softened assertStateDelta expect for "${key}" (${beforeExpect} \u2192 ${afterExpect})`;
85760
+ }
85761
+ }
85762
+ if (before.captures > 0 && after.captures < before.captures && after.stateDeltas === 0) {
85763
+ return `heal patch removed captureState without keeping assertStateDelta (${before.captures} \u2192 ${after.captures})`;
85764
+ }
85765
+ if (before.assertTexts.length > 0) {
85766
+ const afterSet = new Set(after.assertTexts);
85767
+ const lost = before.assertTexts.filter((t) => !afterSet.has(t));
85768
+ if (after.assertTexts.length < before.assertTexts.length) {
85769
+ return `heal patch dropped assertText outcome proof (${before.assertTexts.length} \u2192 ${after.assertTexts.length})`;
85770
+ }
85771
+ if (lost.length > 0) {
85772
+ const softKept = lost.every((t) => after.assertTexts.some((a) => a.includes(t) || t.includes(a)));
85773
+ if (!softKept) {
85774
+ return `heal patch replaced assertText expectations (${lost.slice(0, 2).join("; ")}) \u2014 outcome must stay`;
85775
+ }
85776
+ }
85777
+ }
85778
+ if (before.strongVisible > 0 && after.strongVisible + after.assertTexts.length + after.stateDeltas < before.strongVisible) {
85779
+ return `heal patch weakened strong assertVisible validation oracles (${before.strongVisible} \u2192 ${after.strongVisible})`;
85780
+ }
85781
+ if (before.strongTotal > 0 && after.strongTotal === 0) {
85782
+ return "heal patch removed all strong oracles \u2014 refusing visibility-only green path";
85783
+ }
85784
+ for (const orig of original) {
85785
+ if (orig.action !== "assertStateDelta" && orig.action !== "assertText")
85786
+ continue;
85787
+ const key = normalizeText(orig.description ?? orig.assertion ?? "");
85788
+ if (!key)
85789
+ continue;
85790
+ const stillStrong = patched.some((p) => (p.action === "assertStateDelta" || p.action === "assertText") && normalizeText(p.description ?? p.assertion ?? "") === key);
85791
+ if (stillStrong)
85792
+ continue;
85793
+ const onlyVisible = patched.some((p) => p.action === "assertVisible" && normalizeText(p.description ?? p.assertion ?? "") === key);
85794
+ if (onlyVisible) {
85795
+ return `heal patch downgraded strong oracle "${key.slice(0, 60)}" to assertVisible`;
85796
+ }
85797
+ }
85798
+ return null;
85799
+ }
85800
+ function oraclesPreserved(original, patched) {
85801
+ return rejectOracleWeakeningPatch(original, patched) === null;
85802
+ }
85803
+ }
85804
+ });
85805
+
84833
85806
  // ../runner-core/dist/services/mobile/mobile-heal-postprocess.js
84834
85807
  var require_mobile_heal_postprocess = __commonJS({
84835
85808
  "../runner-core/dist/services/mobile/mobile-heal-postprocess.js"(exports2) {
@@ -84838,6 +85811,7 @@ var require_mobile_heal_postprocess = __commonJS({
84838
85811
  exports2.redactMobileSecretsFromText = redactMobileSecretsFromText;
84839
85812
  exports2.detectMobileStepSecretLeak = detectMobileStepSecretLeak;
84840
85813
  exports2.computeMobileHealOutcome = computeMobileHealOutcome2;
85814
+ var oracle_protection_js_1 = require_oracle_protection();
84841
85815
  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;
84842
85816
  var DETECT_KEY_RE = /password|secret|token|api[_]?key|\bpass\b|credential|bearer|\bpat\b/i;
84843
85817
  var MIN_REDACT_LEN = 4;
@@ -84903,18 +85877,27 @@ var require_mobile_heal_postprocess = __commonJS({
84903
85877
  function computeMobileHealOutcome2(args) {
84904
85878
  const { heal } = args;
84905
85879
  const hasFix = Array.isArray(heal.healedSteps) && heal.healedSteps.length > 0;
84906
- const isVerifiedFix = heal.passed === true && heal.verdict === "fix" && hasFix;
85880
+ let isVerifiedFix = heal.passed === true && heal.verdict === "fix" && hasFix;
84907
85881
  const secretLeak = isVerifiedFix ? detectMobileStepSecretLeak(heal.healedSteps, args.testVariables) : null;
85882
+ const oracleWeakening = isVerifiedFix && args.originalSteps ? (0, oracle_protection_js_1.rejectOracleWeakeningPatch)(args.originalSteps, heal.healedSteps ?? []) : null;
85883
+ if (oracleWeakening)
85884
+ isVerifiedFix = false;
84908
85885
  const isConfigIssue = heal.verdict === "config_issue";
84909
- const isAppBug = heal.verdict === "app_bug";
85886
+ const isAppBug = heal.verdict === "app_bug" || Boolean(oracleWeakening && heal.passed);
84910
85887
  const extraTags = new Set((heal.extraTags ?? []).filter((t) => typeof t === "string" && t.length > 0));
84911
85888
  if (secretLeak)
84912
85889
  extraTags.add("@needs-review");
85890
+ if (oracleWeakening) {
85891
+ extraTags.add("@needs-review");
85892
+ extraTags.add("@bug-found");
85893
+ }
84913
85894
  if (!heal.passed && NEEDS_REVIEW_VERDICTS.has(heal.verdict))
84914
85895
  extraTags.add("@needs-review");
84915
85896
  let status;
84916
85897
  if (secretLeak)
84917
85898
  status = "FAILED";
85899
+ else if (oracleWeakening)
85900
+ status = "FAILED";
84918
85901
  else if (isVerifiedFix)
84919
85902
  status = "PASSED";
84920
85903
  else if (isConfigIssue)
@@ -84926,6 +85909,8 @@ var require_mobile_heal_postprocess = __commonJS({
84926
85909
  error2 = void 0;
84927
85910
  } else if (secretLeak) {
84928
85911
  error2 = `HEAL_SECRET_LEAK: healed steps contained a literal secret (${secretLeak}); patch dropped, tagged @needs-review`;
85912
+ } else if (oracleWeakening) {
85913
+ error2 = `APP_BUG: heal attempted to drop strong oracle (${oracleWeakening}); patch refused`;
84929
85914
  } else if (isConfigIssue) {
84930
85915
  error2 = `CONFIG_ISSUE: ${heal.healReason ?? args.finalError ?? args.reproduceError ?? "environment/rate-limit blocker"}`;
84931
85916
  } else if (isAppBug) {
@@ -84942,13 +85927,64 @@ var require_mobile_heal_postprocess = __commonJS({
84942
85927
  error: error2,
84943
85928
  extraTags: extraTags.size > 0 ? [...extraTags] : void 0,
84944
85929
  removeTags: heal.removeTags,
84945
- shouldPatch: isVerifiedFix && !secretLeak,
85930
+ shouldPatch: isVerifiedFix && !secretLeak && !oracleWeakening,
84946
85931
  secretLeak
84947
85932
  };
84948
85933
  }
84949
85934
  }
84950
85935
  });
84951
85936
 
85937
+ // ../runner-core/dist/services/mobile/network-oracle.js
85938
+ var require_network_oracle = __commonJS({
85939
+ "../runner-core/dist/services/mobile/network-oracle.js"(exports2) {
85940
+ "use strict";
85941
+ Object.defineProperty(exports2, "__esModule", { value: true });
85942
+ exports2.evaluateNetworkSecondaryOracle = evaluateNetworkSecondaryOracle;
85943
+ exports2.uiSuccessWithFailedWriteApi = uiSuccessWithFailedWriteApi;
85944
+ var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
85945
+ function isWrite(method) {
85946
+ return WRITE_METHODS.has(method.toUpperCase());
85947
+ }
85948
+ function isServerOrClientError(status) {
85949
+ return status >= 400 && status < 600;
85950
+ }
85951
+ function isNoiseUrl(url) {
85952
+ return /\b(analytics|telemetry|sentry|bugsnag|crashlytics|facebook\.com\/tr|google-analytics|doubleclick|hotjar|segment\.io|amplitude|mixpanel)\b/i.test(url);
85953
+ }
85954
+ function evaluateNetworkSecondaryOracle(input) {
85955
+ const calls = input.apiCalls;
85956
+ if (!calls || calls.length === 0)
85957
+ return null;
85958
+ if (input.uiPathSucceeded === false)
85959
+ return null;
85960
+ for (const call of calls) {
85961
+ const method = String(call.method ?? "GET");
85962
+ const url = String(call.url ?? "");
85963
+ const status = typeof call.status === "number" ? call.status : 0;
85964
+ if (!isWrite(method))
85965
+ continue;
85966
+ if (!isServerOrClientError(status))
85967
+ continue;
85968
+ if (!url || isNoiseUrl(url))
85969
+ continue;
85970
+ if (status === 401 || status === 403)
85971
+ continue;
85972
+ return {
85973
+ kind: "write_api_failed",
85974
+ method: method.toUpperCase(),
85975
+ url: url.slice(0, 200),
85976
+ status,
85977
+ reason: `Write API ${method.toUpperCase()} ${url.slice(0, 120)} returned ${status} while UI path appeared successful`
85978
+ };
85979
+ }
85980
+ return null;
85981
+ }
85982
+ function uiSuccessWithFailedWriteApi(input) {
85983
+ return evaluateNetworkSecondaryOracle(input) !== null;
85984
+ }
85985
+ }
85986
+ });
85987
+
84952
85988
  // ../runner-core/dist/services/selector-registry-context.js
84953
85989
  var require_selector_registry_context = __commonJS({
84954
85990
  "../runner-core/dist/services/selector-registry-context.js"(exports2) {
@@ -85316,6 +86352,9 @@ var require_mobile_heal_loop = __commonJS({
85316
86352
  var ai_retry_js_1 = require_ai_retry();
85317
86353
  var mobile_source_parser_js_1 = require_mobile_source_parser();
85318
86354
  var mobile_heal_postprocess_js_1 = require_mobile_heal_postprocess();
86355
+ var failure_triage_js_1 = require_failure_triage();
86356
+ var oracle_protection_js_1 = require_oracle_protection();
86357
+ var network_oracle_js_1 = require_network_oracle();
85319
86358
  var mobile_observation_js_1 = require_mobile_observation();
85320
86359
  var selector_registry_context_js_1 = require_selector_registry_context();
85321
86360
  var mobile_session_keepalive_js_1 = require_mobile_session_keepalive();
@@ -85338,7 +86377,12 @@ Reason over steps + error + tree + registry and return working healed steps. Do
85338
86377
  {"verdict":"state_stale","reason":"leftover data blocks a baseline assertion"}
85339
86378
  {"verdict":"test_invalid","reason":"scenario cannot be made to pass"}
85340
86379
  {"verdict":"unhealable_dynamic","reason":"asserted value is inherently volatile (timestamps, counters, feeds) \u2014 no durable locator can exist; needs human review"}
85341
- For a fix, return the COMPLETE steps array (not a diff).`;
86380
+ For a fix, return the COMPLETE steps array (not a diff).
86381
+ ## Strong oracle protection (non-negotiable)
86382
+ - NEVER remove or downgrade assertStateDelta, captureState, or assertText outcome proof to go green.
86383
+ - NEVER replace a durable outcome assert with mere assertVisible of a tab/header.
86384
+ - You MAY fix locators, waits, and navigation around those oracles.
86385
+ - If the app truly violates the oracle, return verdict "app_bug" instead of stripping the assert.`;
85342
86386
  var DEFAULT_SCRIPT_MAX_ATTEMPTS = 6;
85343
86387
  var RECOVERABLE_MAX = 3;
85344
86388
  var MAX_CONSECUTIVE_INVALID_VERDICTS = 3;
@@ -85368,7 +86412,9 @@ For a fix, return the COMPLETE steps array (not a diff).`;
85368
86412
  "home",
85369
86413
  "waitForElement",
85370
86414
  "assertVisible",
85371
- "assertText"
86415
+ "assertText",
86416
+ "captureState",
86417
+ "assertStateDelta"
85372
86418
  ]);
85373
86419
  var MAX_HEALED_STEPS = 300;
85374
86420
  var TERMINAL_VERDICTS = /* @__PURE__ */ new Set([
@@ -85395,6 +86441,28 @@ For a fix, return the COMPLETE steps array (not a diff).`;
85395
86441
  function isMobileHealVerdict(value) {
85396
86442
  return MOBILE_HEAL_VERDICTS.includes(value);
85397
86443
  }
86444
+ function normalizeMobileHealVerdict(raw) {
86445
+ const v = raw.trim().toLowerCase().replace(/[\s-]+/g, "_");
86446
+ if (isMobileHealVerdict(v))
86447
+ return v;
86448
+ if (v === "appbug" || v === "application_bug" || v === "bug_found")
86449
+ return "app_bug";
86450
+ if (v === "config" || v === "configuration_issue" || v === "env" || v === "environment")
86451
+ return "config_issue";
86452
+ if (v === "prereq" || v === "prerequisite" || v === "prereq_missing")
86453
+ return "prereq_unmet";
86454
+ if (v === "stale" || v === "stale_state")
86455
+ return "state_stale";
86456
+ if (v === "invalid_test" || v === "bad_test")
86457
+ return "test_invalid";
86458
+ if (v === "unhealable" || v === "dynamic")
86459
+ return "unhealable_dynamic";
86460
+ if (v === "need_device" || v === "needs_appium" || v === "needs_live")
86461
+ return "needs_device";
86462
+ if (v === "healed" || v === "ok" || v === "pass" || v === "passed")
86463
+ return "fix";
86464
+ return null;
86465
+ }
85398
86466
  function isLocatorNotFound(error2) {
85399
86467
  return /not found|no such element/i.test(error2 ?? "");
85400
86468
  }
@@ -85676,15 +86744,43 @@ For a fix, return the COMPLETE steps array (not a diff).`;
85676
86744
  const sub = extractBracesSubstring(cleaned);
85677
86745
  obj = sub ? safeJsonParse(sub) : void 0;
85678
86746
  }
85679
- if (!isRecord(obj))
86747
+ if (!isRecord(obj)) {
86748
+ const line = cleaned.match(/\bverdict\s*[:=]\s*["']?([a-zA-Z_ -]+)["']?/i);
86749
+ if (line) {
86750
+ const verdict2 = normalizeMobileHealVerdict(line[1]);
86751
+ if (verdict2) {
86752
+ return {
86753
+ verdict: verdict2,
86754
+ reason: cleaned.slice(0, 2e3)
86755
+ };
86756
+ }
86757
+ }
86758
+ const prefix = cleaned.match(/^\s*(APP_BUG|CONFIG_ISSUE|PREREQ_UNMET|TEST_INVALID|STATE_STALE)\s*:\s*(.*)$/im);
86759
+ if (prefix) {
86760
+ const map2 = {
86761
+ APP_BUG: "app_bug",
86762
+ CONFIG_ISSUE: "config_issue",
86763
+ PREREQ_UNMET: "prereq_unmet",
86764
+ TEST_INVALID: "test_invalid",
86765
+ STATE_STALE: "state_stale"
86766
+ };
86767
+ const verdict2 = map2[prefix[1].toUpperCase()];
86768
+ if (verdict2) {
86769
+ return { verdict: verdict2, reason: (prefix[2] || cleaned).slice(0, 2e3) };
86770
+ }
86771
+ }
86772
+ return null;
86773
+ }
86774
+ const rawVerdict = obj.verdict ?? obj.Verdict ?? obj.status;
86775
+ if (typeof rawVerdict !== "string")
85680
86776
  return null;
85681
- const rawVerdict = obj.verdict;
85682
- if (typeof rawVerdict !== "string" || !isMobileHealVerdict(rawVerdict))
86777
+ const verdict = normalizeMobileHealVerdict(rawVerdict);
86778
+ if (!verdict)
85683
86779
  return null;
85684
86780
  return {
85685
- verdict: rawVerdict,
86781
+ verdict,
85686
86782
  steps: coerceSteps(obj.steps),
85687
- reason: typeof obj.reason === "string" ? obj.reason : void 0,
86783
+ reason: typeof obj.reason === "string" ? obj.reason : typeof obj.rationale === "string" ? obj.rationale : typeof obj.message === "string" ? obj.message : void 0,
85688
86784
  confidence: typeof obj.confidence === "number" ? obj.confidence : void 0
85689
86785
  };
85690
86786
  }
@@ -86033,7 +87129,7 @@ ${args.directive}`);
86033
87129
  };
86034
87130
  }
86035
87131
  markRecoverableTurn();
86036
- pendingDirective = "Your last response was not valid JSON matching the verdict schema. Return exactly one JSON verdict object \u2014 no prose, no markdown fences.";
87132
+ 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.';
86037
87133
  continue;
86038
87134
  }
86039
87135
  consecutiveInvalidVerdicts = 0;
@@ -86062,6 +87158,13 @@ ${args.directive}`);
86062
87158
  pendingDirective = 'You returned verdict "fix" but no usable steps array. Return the COMPLETE healed MobileTestStep array.';
86063
87159
  continue;
86064
87160
  }
87161
+ const oracleRejection = (0, oracle_protection_js_1.rejectOracleWeakeningPatch)(steps, healedSteps);
87162
+ if (oracleRejection) {
87163
+ markRecoverableTurn();
87164
+ lastVerdict = "fix";
87165
+ 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".`;
87166
+ continue;
87167
+ }
86065
87168
  if (activeFailingSource && isLocatorNotFound(activeError) && !isDrift(activeError)) {
86066
87169
  const failingSourceSnapshot = activeFailingSource;
86067
87170
  const missing = timedSync("device-op", `phase1-attempt-${attempt}-static-verify`, options.onProgress, () => {
@@ -86205,6 +87308,28 @@ ${args.directive}`);
86205
87308
  if (invalidAuthSetup) {
86206
87309
  return { passed: false, verdict: "test_invalid", healReason: invalidAuthSetup };
86207
87310
  }
87311
+ const networkBug = (0, network_oracle_js_1.uiSuccessWithFailedWriteApi)({
87312
+ apiCalls: ctx.apiCalls,
87313
+ uiPathSucceeded: ctx.uiPathSucceeded
87314
+ });
87315
+ const triage = (0, failure_triage_js_1.triageMobileFailure)({
87316
+ steps,
87317
+ error: ctx.error,
87318
+ logs: ctx.logs,
87319
+ tags: ctx.tags,
87320
+ failureCount: ctx.failureCount,
87321
+ uiSuccessWithFailedWriteApi: networkBug
87322
+ });
87323
+ options.onProgress?.(`Pre-heal triage: ${triage.verdict} \u2014 ${triage.reason}`);
87324
+ const terminal = (0, failure_triage_js_1.triageToHealTerminal)(triage);
87325
+ if (terminal) {
87326
+ return {
87327
+ passed: false,
87328
+ verdict: terminal.verdict,
87329
+ healReason: terminal.healReason,
87330
+ extraTags: terminal.extraTags
87331
+ };
87332
+ }
86208
87333
  const preflight = await tryRegistryPreflight(steps, target, ctx, options);
86209
87334
  if (preflight)
86210
87335
  return preflight;
@@ -86454,6 +87579,11 @@ For a fix, return the COMPLETE steps array (not a diff). Use "observe" only to r
86454
87579
  if (parsed.verdict !== "fix" || !parsed.steps)
86455
87580
  continue;
86456
87581
  const healedSteps = parsed.steps;
87582
+ const liveOracleRejection = (0, oracle_protection_js_1.rejectOracleWeakeningPatch)(args.steps, healedSteps);
87583
+ if (liveOracleRejection) {
87584
+ options.onProgress?.(`ORACLE PROTECTION (live): ${liveOracleRejection}`);
87585
+ continue;
87586
+ }
86457
87587
  let verify;
86458
87588
  try {
86459
87589
  verify = await timed("reexec", `phase2-pass-${pass}-verify`, options.onProgress, () => runNativeTest({ steps: healedSteps, target, testVariables }));
@@ -353976,7 +355106,7 @@ var require_package4 = __commonJS({
353976
355106
  "package.json"(exports2, module2) {
353977
355107
  module2.exports = {
353978
355108
  name: "@validate.qa/runner",
353979
- version: "1.0.88",
355109
+ version: "1.0.89",
353980
355110
  description: "validate local test runner - execute Playwright tests on your machine, connected to validate.qa cloud.",
353981
355111
  bin: {
353982
355112
  "validate-runner": "dist/cli.js"
@@ -354837,6 +355967,68 @@ async function waitForUiSettle(sessionPath, opts = {}) {
354837
355967
  }
354838
355968
  return { settled: false, lastFingerprint, frames };
354839
355969
  }
355970
+ var SYSTEM_UI_DISMISS_LABELS = [
355971
+ "OK",
355972
+ "Got it",
355973
+ "GOT IT",
355974
+ "Continue",
355975
+ "Close",
355976
+ "Dismiss",
355977
+ "I understand",
355978
+ "Accept",
355979
+ // Android 15+ / 16 KB page-size compatibility dialog primary action.
355980
+ "OK, got it"
355981
+ ];
355982
+ function extractElementId(value) {
355983
+ if (!value || typeof value !== "object") return null;
355984
+ const v = value;
355985
+ const elementId = v.ELEMENT ?? v["element-6066-11e4-a52e-4f735466cecf"] ?? null;
355986
+ if (typeof elementId !== "string" || !ELEMENT_ID_PATTERN.test(elementId)) return null;
355987
+ return elementId;
355988
+ }
355989
+ async function dismissBlockingSystemUi(sessionPath, platform3, opts = {}) {
355990
+ const maxDismisses = Math.max(1, Math.min(5, opts.maxDismisses ?? 3));
355991
+ const dismissed = [];
355992
+ for (let i = 0; i < maxDismisses; i++) {
355993
+ let tapped = false;
355994
+ for (const label of SYSTEM_UI_DISMISS_LABELS) {
355995
+ try {
355996
+ const strategies = platform3 === "ANDROID" ? [
355997
+ { using: "-android uiautomator", value: `new UiSelector().text("${label.replace(/"/g, '\\"')}")` },
355998
+ { using: "accessibility id", value: label }
355999
+ ] : [
356000
+ { using: "accessibility id", value: label },
356001
+ { using: "-ios predicate string", value: `label == "${label.replace(/"/g, '\\"')}" OR name == "${label.replace(/"/g, '\\"')}"` }
356002
+ ];
356003
+ for (const strategy of strategies) {
356004
+ try {
356005
+ const elResult = await appiumRequest(`${sessionPath}/element`, {
356006
+ method: "POST",
356007
+ body: JSON.stringify(strategy)
356008
+ });
356009
+ const elementId = extractElementId(readValue(elResult));
356010
+ if (!elementId) continue;
356011
+ await appiumRequest(`${sessionPath}/element/${elementId}/click`, {
356012
+ method: "POST",
356013
+ body: "{}"
356014
+ });
356015
+ dismissed.push(label);
356016
+ tapped = true;
356017
+ await waitForUiSettle(sessionPath, { timeoutMs: 1200, pollMs: 200, minStableFrames: 1 });
356018
+ break;
356019
+ } catch (err) {
356020
+ if (isAppiumDriverDeadError(err)) throw err;
356021
+ }
356022
+ }
356023
+ if (tapped) break;
356024
+ } catch (err) {
356025
+ if (isAppiumDriverDeadError(err)) throw err;
356026
+ }
356027
+ }
356028
+ if (!tapped) break;
356029
+ }
356030
+ return { dismissed, ok: dismissed.length > 0 };
356031
+ }
354840
356032
  async function waitForColdBootSettle(sessionPath) {
354841
356033
  await waitForUiSettle(sessionPath, {
354842
356034
  timeoutMs: MOBILE_COLD_BOOT_SETTLE_MS,
@@ -357574,6 +358766,107 @@ async function waitForColdBootContent(sessionId, log2, timeoutMs = 2e4) {
357574
358766
  }
357575
358767
  log2(` Cold-boot wait timed out after ${timeoutMs}ms (last tree had ${lastCount} node(s)) \u2014 proceeding anyway.`);
357576
358768
  }
358769
+ async function dismissSystemUiAfterColdBoot(sessionId, platform3, log2) {
358770
+ try {
358771
+ const result = await dismissBlockingSystemUi(`/session/${sessionId}`, platform3);
358772
+ if (result.dismissed.length > 0) {
358773
+ log2(` Dismissed system UI: ${result.dismissed.join(" \u2192 ")}`);
358774
+ }
358775
+ } catch (err) {
358776
+ log2(` System UI dismiss skipped (${err instanceof Error ? err.message : String(err)})`);
358777
+ }
358778
+ }
358779
+ async function captureMobileStateValues(sessionId, kind) {
358780
+ const res = await wdRequest(`/session/${sessionId}/source`);
358781
+ const xml = typeof res?.value === "string" ? res.value : "";
358782
+ if (kind === "badge_count") {
358783
+ const nums = /* @__PURE__ */ new Set();
358784
+ for (const m of xml.matchAll(/\b(\d{1,6})\b/g)) {
358785
+ nums.add(m[1]);
358786
+ }
358787
+ const preferred = /* @__PURE__ */ new Set();
358788
+ for (const m of xml.matchAll(/(?:count|badge|open|unread|item|invoice|result|pending)[^>]{0,80}?\b(\d{1,6})\b/gi)) {
358789
+ preferred.add(m[1]);
358790
+ }
358791
+ for (const m of xml.matchAll(/\b(\d{1,6})\b[^>]{0,80}?(?:count|badge|open|unread|items?)/gi)) {
358792
+ preferred.add(m[1]);
358793
+ }
358794
+ return preferred.size > 0 ? [...preferred] : [...nums].slice(0, 20);
358795
+ }
358796
+ const labels = /* @__PURE__ */ new Set();
358797
+ const attrRe = /(?:text|content-desc|name|label)="([^"]{2,80})"/gi;
358798
+ for (const m of xml.matchAll(attrRe)) {
358799
+ const t = m[1].trim();
358800
+ if (t.length < 2 || t.length > 80) continue;
358801
+ if (/^(true|false|null|OK|Cancel)$/i.test(t)) continue;
358802
+ labels.add(t);
358803
+ }
358804
+ return [...labels].slice(0, 80);
358805
+ }
358806
+ function assertMobileStateDelta(before, after, expect, key, log2) {
358807
+ const beforeSet = new Set(before);
358808
+ const afterSet = new Set(after);
358809
+ const removed = before.filter((v) => !afterSet.has(v));
358810
+ const added = after.filter((v) => !beforeSet.has(v));
358811
+ log2(` assertStateDelta key=${key} expect=${expect} removed=${removed.length} added=${added.length}`);
358812
+ const exp = expect.toLowerCase().trim();
358813
+ if (exp === "changed" || exp === "any_change") {
358814
+ if (removed.length === 0 && added.length === 0) {
358815
+ throw new Error(`assertStateDelta(${key}): expected state to change, but capture is identical (${before.length} values)`);
358816
+ }
358817
+ return;
358818
+ }
358819
+ if (exp === "removed" || exp === "entity_removed" || exp.startsWith("removed:")) {
358820
+ const target = exp.startsWith("removed:") ? expect.slice("removed:".length).trim() : "";
358821
+ if (target) {
358822
+ if (!removed.includes(target) && afterSet.has(target)) {
358823
+ throw new Error(`assertStateDelta(${key}): expected "${target}" removed, but it is still present`);
358824
+ }
358825
+ if (!beforeSet.has(target)) {
358826
+ throw new Error(`assertStateDelta(${key}): expected "${target}" to have been in the prior capture`);
358827
+ }
358828
+ if (afterSet.has(target)) {
358829
+ throw new Error(`assertStateDelta(${key}): "${target}" was not removed`);
358830
+ }
358831
+ return;
358832
+ }
358833
+ if (removed.length === 0) {
358834
+ throw new Error(`assertStateDelta(${key}): expected at least one entity removed`);
358835
+ }
358836
+ return;
358837
+ }
358838
+ if (exp === "count_decreased" || exp === "count-1") {
358839
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
358840
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
358841
+ const bMax = b.length ? Math.max(...b) : NaN;
358842
+ const aMax = a.length ? Math.max(...a) : NaN;
358843
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax >= bMax) {
358844
+ throw new Error(`assertStateDelta(${key}): expected count decrease (before max=${bMax}, after max=${aMax})`);
358845
+ }
358846
+ return;
358847
+ }
358848
+ if (exp === "count_increased" || exp === "count+1") {
358849
+ const b = before.map(Number).filter((n) => Number.isFinite(n));
358850
+ const a = after.map(Number).filter((n) => Number.isFinite(n));
358851
+ const bMax = b.length ? Math.max(...b) : NaN;
358852
+ const aMax = a.length ? Math.max(...a) : NaN;
358853
+ if (!Number.isFinite(bMax) || !Number.isFinite(aMax) || aMax <= bMax) {
358854
+ throw new Error(`assertStateDelta(${key}): expected count increase (before max=${bMax}, after max=${aMax})`);
358855
+ }
358856
+ return;
358857
+ }
358858
+ if (exp === "unchanged" || exp === "persisted") {
358859
+ if (removed.length > 0 || added.length > 0) {
358860
+ throw new Error(
358861
+ `assertStateDelta(${key}): expected persistence/unchanged, but removed=[${removed.slice(0, 5).join(", ")}] added=[${added.slice(0, 5).join(", ")}]`
358862
+ );
358863
+ }
358864
+ return;
358865
+ }
358866
+ if (removed.length === 0 && added.length === 0) {
358867
+ throw new Error(`assertStateDelta(${key}): expected change (expect=${expect}), state identical`);
358868
+ }
358869
+ }
357577
358870
  async function restoreTargetAppIfExternal(sessionId, target, log2, source, failOnExternal) {
357578
358871
  let boundary = null;
357579
358872
  try {
@@ -358719,6 +360012,7 @@ async function executeMobileTest(options) {
358719
360012
  }
358720
360013
  const stepResults = [];
358721
360014
  const screenshots = [];
360015
+ const stateBag = /* @__PURE__ */ new Map();
358722
360016
  let apiCalls = [];
358723
360017
  let sessionId = null;
358724
360018
  let selectedDevice;
@@ -358929,6 +360223,9 @@ async function executeMobileTest(options) {
358929
360223
  if (clearedAppDataBeforeLaunch) {
358930
360224
  await waitForColdBootContent(sessionId, log2);
358931
360225
  }
360226
+ if (options.target.launchMode !== "RESUME") {
360227
+ await dismissSystemUiAfterColdBoot(sessionId, options.target.platform, log2);
360228
+ }
358932
360229
  if (options.target.launchMode === "DEEP_LINK" && options.target.deeplink) {
358933
360230
  try {
358934
360231
  log2(`Opening deep link: ${options.target.deeplink}`);
@@ -359023,6 +360320,25 @@ async function executeMobileTest(options) {
359023
360320
  case "assertText":
359024
360321
  await executeAssertText(sessionId, step, runPlatform, isCrossPlatform);
359025
360322
  break;
360323
+ case "captureState": {
360324
+ const key = String(step.metadata?.stateKey ?? step.target?.primary ?? `state-${step.order}`);
360325
+ const kind = String(step.metadata?.stateKind ?? "list_ids");
360326
+ const values = await captureMobileStateValues(sessionId, kind);
360327
+ stateBag.set(key, { kind, values, capturedAt: Date.now() });
360328
+ log2(` captureState key=${key} kind=${kind} n=${values.length}`);
360329
+ break;
360330
+ }
360331
+ case "assertStateDelta": {
360332
+ const key = String(step.metadata?.stateKey ?? step.target?.primary ?? "");
360333
+ const expect = String(step.metadata?.expect ?? step.assertion ?? "changed");
360334
+ const prior = stateBag.get(key);
360335
+ if (!prior) {
360336
+ throw new Error(`assertStateDelta: no prior captureState for key "${key}"`);
360337
+ }
360338
+ const current = await captureMobileStateValues(sessionId, prior.kind);
360339
+ assertMobileStateDelta(prior.values, current, expect, key, log2);
360340
+ break;
360341
+ }
359026
360342
  default: {
359027
360343
  const _exhaustive = step.action;
359028
360344
  status = "failed";
@@ -359201,6 +360517,10 @@ async function createMobileDiscoverySession(target, options) {
359201
360517
  );
359202
360518
  }
359203
360519
  }
360520
+ try {
360521
+ await dismissBlockingSystemUi(`/session/${sessionId}`, target.platform);
360522
+ } catch {
360523
+ }
359204
360524
  let stopped = false;
359205
360525
  return {
359206
360526
  sessionId,
@@ -359338,6 +360658,8 @@ async function driveHarvestStep(sessionId, step, elementId, platform3) {
359338
360658
  case "waitForElement":
359339
360659
  case "assertVisible":
359340
360660
  case "assertText":
360661
+ case "captureState":
360662
+ case "assertStateDelta":
359341
360663
  return true;
359342
360664
  }
359343
360665
  }
@@ -359371,6 +360693,7 @@ async function harvestPlatformLocators(options) {
359371
360693
  try {
359372
360694
  options.onSessionReady?.(session.sessionId, session.deviceId, platform3);
359373
360695
  await freshLaunchTargetApp(session.sessionId, platform3, options.target.appId, log2);
360696
+ await dismissSystemUiAfterColdBoot(session.sessionId, platform3, log2);
359374
360697
  if (options.target.launchMode === "DEEP_LINK" && options.target.deeplink) {
359375
360698
  await openDeepLink(session.sessionId, platform3, options.target.deeplink, options.target.appId);
359376
360699
  }
@@ -359646,7 +360969,9 @@ function decideMobileDeviceGate(input) {
359646
360969
  }
359647
360970
  }
359648
360971
  const isHealForHeldTest = runMode === "heal" && !!testCaseId && healHoldTestCaseIds.has(testCaseId);
359649
- const reservedForHeals = isHealForHeldTest ? Math.max(0, healHoldTestCaseIds.size - 1) : healHoldTestCaseIds.size;
360972
+ const rawReservedForHeals = isHealForHeldTest ? Math.max(0, healHoldTestCaseIds.size - 1) : healHoldTestCaseIds.size;
360973
+ const maxHealReserve = capacity <= 1 ? capacity : Math.max(1, capacity - 1);
360974
+ const reservedForHeals = Math.min(rawReservedForHeals, maxHealReserve);
359650
360975
  if (activeMobileOps + reservedForHeals >= capacity) {
359651
360976
  const reason = reservedForHeals > 0 ? `capacity reserved for pending auto-heal: ${activeMobileOps}+${reservedForHeals}/${capacity}` : `mobile capacity reached: ${activeMobileOps}/${capacity} in use`;
359652
360977
  return { claim: false, disposition: "defer", reason };
@@ -361482,6 +362807,11 @@ var MobileBridgeDriver = class {
361482
362807
  } catch (err) {
361483
362808
  if (isRecoverableAppiumSessionFailure(err)) throw err;
361484
362809
  }
362810
+ try {
362811
+ await dismissBlockingSystemUi(this.sessionPath, this.platform);
362812
+ } catch (err) {
362813
+ if (isRecoverableAppiumSessionFailure(err) || isAppiumDriverDeadError(err)) throw err;
362814
+ }
361485
362815
  });
361486
362816
  }
361487
362817
  /**
@@ -361519,6 +362849,11 @@ var MobileBridgeDriver = class {
361519
362849
  } catch (err) {
361520
362850
  if (isRecoverableAppiumSessionFailure(err)) throw err;
361521
362851
  }
362852
+ try {
362853
+ await dismissBlockingSystemUi(this.sessionPath, this.platform);
362854
+ } catch (err) {
362855
+ if (isRecoverableAppiumSessionFailure(err) || isAppiumDriverDeadError(err)) throw err;
362856
+ }
361522
362857
  return true;
361523
362858
  } catch (err) {
361524
362859
  if (isRecoverableAppiumSessionFailure(err)) throw err;
@@ -364878,6 +366213,17 @@ ${finalVerifyResult.logs ?? ""}`;
364878
366213
  }
364879
366214
  };
364880
366215
  log.info("\u{1FA7A} Mobile AI heal \u2014 Phase 1 (script) \u2192 Phase 2 (live device, lazy)...");
366216
+ const tagList = Array.isArray(run2.tags) ? run2.tags : [];
366217
+ const failureCount = Math.max(
366218
+ 1,
366219
+ typeof run2.consecutiveFails === "number" && run2.consecutiveFails > 0 ? run2.consecutiveFails : tagList.includes("@bug-found") ? 2 : 1
366220
+ );
366221
+ const reproduceApiCalls = Array.isArray(nativeVerify.last?.apiCalls) ? nativeVerify.last.apiCalls.map((c) => ({
366222
+ method: typeof c.method === "string" ? c.method : void 0,
366223
+ url: typeof c.url === "string" ? c.url : void 0,
366224
+ status: typeof c.status === "number" ? c.status : void 0
366225
+ })) : void 0;
366226
+ const uiPathSucceeded = Array.isArray(reproduce.stepResults) && reproduce.stepResults.filter((s) => s.status === "passed").length >= Math.max(1, reproduce.stepResults.length - 1);
364881
366227
  const heal = await (0, import_runner_core14.executeMobileTestWithHealing)(
364882
366228
  mobileSteps,
364883
366229
  healTarget,
@@ -364886,7 +366232,11 @@ ${finalVerifyResult.logs ?? ""}`;
364886
366232
  logs: reproduce.logs,
364887
366233
  failingSource: reproduce.failingSource,
364888
366234
  testVariables: run2.testVariables,
364889
- testName: run2.testName
366235
+ testName: run2.testName,
366236
+ tags: tagList,
366237
+ failureCount,
366238
+ apiCalls: reproduceApiCalls,
366239
+ uiPathSucceeded
364890
366240
  },
364891
366241
  healerOptions
364892
366242
  );
@@ -364895,7 +366245,8 @@ ${finalVerifyResult.logs ?? ""}`;
364895
366245
  heal,
364896
366246
  finalError: finalRes?.error ?? null,
364897
366247
  reproduceError,
364898
- testVariables: run2.testVariables
366248
+ testVariables: run2.testVariables,
366249
+ originalSteps: mobileSteps
364899
366250
  });
364900
366251
  await postResult(opts.serverUrl, headers, run2.runId, {
364901
366252
  status: outcome.status,