@sun-asterisk/sungen 3.2.24-beta.6 → 3.2.24

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 (88) hide show
  1. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/biometric-action.hbs +9 -0
  2. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/check-action.hbs +11 -6
  3. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/deep-link-action.hbs +8 -0
  4. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/location-services-action.hbs +11 -0
  5. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/reinstall-app-action.hbs +21 -0
  6. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/restart-app-action.hbs +16 -0
  7. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/set-connectivity-action.hbs +11 -0
  8. package/dist/generators/test-generator/adapters/appium/templates/steps/actions/uncheck-action.hbs +9 -5
  9. package/dist/generators/test-generator/adapters/appium/templates/steps/assertions/checked-assertion.hbs +10 -4
  10. package/dist/generators/test-generator/adapters/appium/templates/steps/assertions/device-log-assertion.hbs +16 -0
  11. package/dist/generators/test-generator/adapters/appium/templates/steps/assertions/disappears-within-assertion.hbs +5 -0
  12. package/dist/generators/test-generator/adapters/appium/templates/steps/assertions/not-checked-assertion.hbs +6 -4
  13. package/dist/generators/test-generator/adapters/appium/templates/steps/assertions/state-with-filter-assertion.hbs +4 -3
  14. package/dist/generators/test-generator/adapters/appium/templates/steps/assertions/still-visible-after-assertion.hbs +4 -0
  15. package/dist/generators/test-generator/adapters/appium/templates/steps/gestures/pull-to-refresh-action.hbs +3 -0
  16. package/dist/generators/test-generator/adapters/appium/templates/steps/gestures/swipe-action.hbs +3 -0
  17. package/dist/generators/test-generator/adapters/appium/templates/steps/partials/appium-selector.hbs +7 -1
  18. package/dist/generators/test-generator/adapters/appium/templates/test-file.hbs +129 -15
  19. package/dist/generators/test-generator/template-engine.d.ts.map +1 -1
  20. package/dist/generators/test-generator/template-engine.js +3 -0
  21. package/dist/generators/test-generator/template-engine.js.map +1 -1
  22. package/dist/generators/test-generator/utils/selector-resolver.d.ts.map +1 -1
  23. package/dist/generators/test-generator/utils/selector-resolver.js +4 -0
  24. package/dist/generators/test-generator/utils/selector-resolver.js.map +1 -1
  25. package/dist/harness/audit.d.ts.map +1 -1
  26. package/dist/harness/audit.js +3 -1
  27. package/dist/harness/audit.js.map +1 -1
  28. package/dist/harness/capability-plan.d.ts.map +1 -1
  29. package/dist/harness/capability-plan.js +6 -1
  30. package/dist/harness/capability-plan.js.map +1 -1
  31. package/dist/harness/parse.d.ts +1 -0
  32. package/dist/harness/parse.d.ts.map +1 -1
  33. package/dist/harness/parse.js +1 -0
  34. package/dist/harness/parse.js.map +1 -1
  35. package/dist/harness/script-check.d.ts.map +1 -1
  36. package/dist/harness/script-check.js +6 -2
  37. package/dist/harness/script-check.js.map +1 -1
  38. package/dist/harness/sensors.d.ts.map +1 -1
  39. package/dist/harness/sensors.js +5 -1
  40. package/dist/harness/sensors.js.map +1 -1
  41. package/dist/orchestrator/mobile-runtime-scaffolder.d.ts.map +1 -1
  42. package/dist/orchestrator/mobile-runtime-scaffolder.js +5 -1
  43. package/dist/orchestrator/mobile-runtime-scaffolder.js.map +1 -1
  44. package/dist/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +10 -4
  45. package/dist/orchestrator/templates/ai-src/skills/sungen-mobile-gestures/SKILL.md +23 -0
  46. package/dist/orchestrator/templates/env.appium.example +11 -0
  47. package/dist/orchestrator/templates/specs-db.d.ts.map +1 -1
  48. package/dist/orchestrator/templates/specs-db.js +79 -6
  49. package/dist/orchestrator/templates/specs-db.js.map +1 -1
  50. package/dist/orchestrator/templates/specs-db.ts +70 -7
  51. package/dist/orchestrator/templates/wdio.conf.ts +100 -3
  52. package/dist/utils/selector-types.d.ts +1 -1
  53. package/dist/utils/selector-types.d.ts.map +1 -1
  54. package/dist/utils/selector-types.js +1 -0
  55. package/dist/utils/selector-types.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/generators/test-generator/adapters/appium/templates/steps/actions/biometric-action.hbs +9 -0
  58. package/src/generators/test-generator/adapters/appium/templates/steps/actions/check-action.hbs +11 -6
  59. package/src/generators/test-generator/adapters/appium/templates/steps/actions/deep-link-action.hbs +8 -0
  60. package/src/generators/test-generator/adapters/appium/templates/steps/actions/location-services-action.hbs +11 -0
  61. package/src/generators/test-generator/adapters/appium/templates/steps/actions/reinstall-app-action.hbs +21 -0
  62. package/src/generators/test-generator/adapters/appium/templates/steps/actions/restart-app-action.hbs +16 -0
  63. package/src/generators/test-generator/adapters/appium/templates/steps/actions/set-connectivity-action.hbs +11 -0
  64. package/src/generators/test-generator/adapters/appium/templates/steps/actions/uncheck-action.hbs +9 -5
  65. package/src/generators/test-generator/adapters/appium/templates/steps/assertions/checked-assertion.hbs +10 -4
  66. package/src/generators/test-generator/adapters/appium/templates/steps/assertions/device-log-assertion.hbs +16 -0
  67. package/src/generators/test-generator/adapters/appium/templates/steps/assertions/disappears-within-assertion.hbs +5 -0
  68. package/src/generators/test-generator/adapters/appium/templates/steps/assertions/not-checked-assertion.hbs +6 -4
  69. package/src/generators/test-generator/adapters/appium/templates/steps/assertions/state-with-filter-assertion.hbs +4 -3
  70. package/src/generators/test-generator/adapters/appium/templates/steps/assertions/still-visible-after-assertion.hbs +4 -0
  71. package/src/generators/test-generator/adapters/appium/templates/steps/gestures/pull-to-refresh-action.hbs +3 -0
  72. package/src/generators/test-generator/adapters/appium/templates/steps/gestures/swipe-action.hbs +3 -0
  73. package/src/generators/test-generator/adapters/appium/templates/steps/partials/appium-selector.hbs +7 -1
  74. package/src/generators/test-generator/adapters/appium/templates/test-file.hbs +129 -15
  75. package/src/generators/test-generator/template-engine.ts +4 -0
  76. package/src/generators/test-generator/utils/selector-resolver.ts +4 -0
  77. package/src/harness/audit.ts +3 -1
  78. package/src/harness/capability-plan.ts +3 -1
  79. package/src/harness/parse.ts +2 -0
  80. package/src/harness/script-check.ts +6 -2
  81. package/src/harness/sensors.ts +5 -1
  82. package/src/orchestrator/mobile-runtime-scaffolder.ts +5 -1
  83. package/src/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +10 -4
  84. package/src/orchestrator/templates/ai-src/skills/sungen-mobile-gestures/SKILL.md +23 -0
  85. package/src/orchestrator/templates/env.appium.example +11 -0
  86. package/src/orchestrator/templates/specs-db.ts +70 -7
  87. package/src/orchestrator/templates/wdio.conf.ts +100 -3
  88. package/src/utils/selector-types.ts +1 -0
@@ -178,6 +178,61 @@ function resolveLocaleCaps(): Record<string, unknown> {
178
178
  }
179
179
  const localeCaps = resolveLocaleCaps();
180
180
 
181
+ // ── Connectivity self-heal (#615) ───────────────────────────────────────────
182
+ // The connectivity/location steps mutate DEVICE state (airplane, wifi, data, GPS). A run that
183
+ // aborts mid-toggle — e.g. an Appium session timeout during an airplane round-trip — leaves the
184
+ // device offline as PERSISTENT state, so every later launch fails with the app's network error
185
+ // and the next run dies at cold start. Restore the baseline around the run via host-side adb:
186
+ // it works even when no Appium session survives (a spec-level after() cannot — the session is
187
+ // exactly what died). Android-only (the mutating steps are Android-only), idempotent (on/on/on
188
+ // is the baseline every suite assumes; offline scenarios set their own state mid-test), and
189
+ // best-effort per command (a device lacking one command just skips that line).
190
+ function restoreConnectivity(hook: string): void {
191
+ if (!RUN_ANDROID) return;
192
+ // Appium finds adb via ANDROID_HOME — PATH may not carry it (fresh CI runner), which would
193
+ // make every heal command fail silently. Resolve the same way Appium does, fall back to PATH.
194
+ const adbBin = process.env.ANDROID_HOME ? path.join(process.env.ANDROID_HOME, 'platform-tools', 'adb') : 'adb';
195
+ const adb = `"${adbBin}" -s ${process.env.ANDROID_UDID || '__ANDROID_UDID__'} shell`;
196
+ // stderr ignored: with a detached device the reads would otherwise spray raw adb errors on every run.
197
+ const sh = (cmd: string) => execSync(`${adb} ${cmd}`, { timeout: 10000, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
198
+ // Detect-first: read each state and only touch what is actually wedged, so a healthy run
199
+ // costs four quick reads, mutates nothing, and logs nothing. Each fix lists every command
200
+ // variant (emulator `svc`, real-device `cmd`, API<30 fallbacks) — all best-effort, same
201
+ // direction, idempotent, so running the inapplicable ones is harmless.
202
+ let touched = false;
203
+ const heal = (read: string, wedged: string, fixes: string[]) => {
204
+ try {
205
+ if (sh(read) !== wedged) return;
206
+ for (const fix of fixes) { try { sh(fix); } catch { /* variant not on this API — fine */ } }
207
+ touched = true;
208
+ } catch { /* unreadable state (device gone / key absent) — leave untouched */ }
209
+ };
210
+ heal('settings get global airplane_mode_on', '1', [
211
+ 'cmd connectivity airplane-mode disable', // API 30+
212
+ 'settings put global airplane_mode_on 0', // API<30 wedge (settings+broadcast)
213
+ 'am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false',
214
+ ]);
215
+ heal('settings get global wifi_on', '0', [
216
+ 'svc wifi enable', // emulator flavor
217
+ 'cmd -w wifi set-wifi-enabled enabled', // real-device flavor (svc can no-op silently)
218
+ ]);
219
+ heal('settings get global mobile_data', '0', [
220
+ 'svc data enable',
221
+ 'cmd phone data enable',
222
+ ]);
223
+ heal('cmd location is-location-enabled', 'false', ['cmd location set-location-enabled true']);
224
+ if (!touched) return;
225
+ console.log(`[sungen] connectivity self-heal (${hook}): device was offline — a previous run likely aborted mid-toggle. Baseline restored (airplane off, wifi/data/location on).`);
226
+ // Radios re-associate asynchronously (emulator wifi can take 10-30s) — wait for REAL IP
227
+ // connectivity before the session starts, or the app's first cold start still lands on its
228
+ // network-error dialog and the auth/first assert fails despite the heal.
229
+ for (let i = 0; i < 10; i++) {
230
+ try { execSync(`${adb} ping -c 1 -W 2 8.8.8.8`, { stdio: 'ignore', timeout: 8000 }); return; } catch { /* not yet */ }
231
+ try { execSync(`${adb} sleep 2`, { stdio: 'ignore', timeout: 8000 }); } catch { /* device gone — stop waiting */ return; }
232
+ }
233
+ console.log('[sungen] connectivity self-heal: no ICMP reply within ~30s — continuing (fine if this network blocks ping; otherwise the device may need a cold boot).');
234
+ }
235
+
181
236
  export const config: WebdriverIO.Config = {
182
237
  runner: 'local',
183
238
  tsConfigPath: './tsconfig.json',
@@ -192,7 +247,10 @@ export const config: WebdriverIO.Config = {
192
247
  // Global auto-wait for $/$$ matchers (toBeDisplayed, click, …). Default is 3s, too short for a
193
248
  // heavy app's cold (re)launch — each scenario terminates+activates its app, so the first
194
249
  // find/click must wait out the splash/first-frame. 20s keeps slow native/Flutter apps green.
195
- waitforTimeout: 20000,
250
+ // 30s (not the classic 20s): on a Compose app with looping in-app animations the accessibility
251
+ // manager can starve for 10s+ per query ("Timed out waiting for the root AccessibilityNodeInfo",
252
+ // observed live) — a 20s budget turns that latency into flaky not-found failures.
253
+ waitforTimeout: 30000,
196
254
 
197
255
  // Capability set(s) selected by MOBILE_PLATFORM (android | ios | both). Each cap carries its OWN
198
256
  // `specs` (per-OS routing): the Android cap runs android + mobile specs, the iOS cap runs ios +
@@ -217,6 +275,14 @@ export const config: WebdriverIO.Config = {
217
275
  'appium:noReset': true,
218
276
  'appium:autoGrantPermissions': true,
219
277
  'appium:newCommandTimeout': 300,
278
+ // Compose/animated UIs (a looping promo animation is enough) never report accessibility-idle,
279
+ // so every find first waits out UiAutomator2's full idle timeout — 10000ms by default. 2s keeps
280
+ // interactions responsive while still absorbing screen transitions. NOTE: milliseconds — the
281
+ // same-named XCUITest cap below is in seconds; the two drivers define the knob differently.
282
+ 'appium:settings[waitForIdleTimeout]': 2000,
283
+ // Disable SYSTEM animation scales for the session — trims accessibility-tree churn so
284
+ // queries stall less on animation-heavy apps (in-app Compose animations still run).
285
+ 'appium:disableWindowAnimation': true,
220
286
  // i18n: when SUNGEN_ENV/SUNGEN_LOCALE is a locale code, this overrides noReset→false and
221
287
  // adds appium:language/appium:locale so the app boots in that locale. Empty otherwise.
222
288
  ...localeCaps,
@@ -275,7 +341,23 @@ export const config: WebdriverIO.Config = {
275
341
  reporters: ['spec', [PwShapeReporter, {}]],
276
342
 
277
343
  // Auto-start a local Appium server on :4723 (base path '/')
278
- services: ['appium'],
344
+ // Appium server options — security-gated features, each opt-in via .env.appium:
345
+ // APPIUM_ALLOW_ADB_SHELL=1 → --allow-insecure uiautomator2:adb_shell
346
+ // (raw shell access — device-level oracles like device-sqlite's run-as fallback)
347
+ // APPIUM_CHROMEDRIVER_AUTODOWNLOAD=1 → --allow-insecure uiautomator2:chromedriver_autodownload
348
+ // (hybrid WebView: downloads the chromedriver matching the device's WebView at session start —
349
+ // without it, `switch to [X] frame` fails with "No Chromedriver found that can automate Chrome N")
350
+ // Both stay OFF by default (see docs/spec/security-and-telemetry-roadmap.md).
351
+ services: [
352
+ ['appium', (() => {
353
+ const feats: string[] = [];
354
+ if (process.env.APPIUM_ALLOW_ADB_SHELL) feats.push('uiautomator2:adb_shell');
355
+ if (process.env.APPIUM_CHROMEDRIVER_AUTODOWNLOAD) feats.push('uiautomator2:chromedriver_autodownload');
356
+ // NOTE: pass a comma-joined STRING — @wdio/appium-service JSON.stringifies arrays, which the
357
+ // appium server then reads as a JSON literal and the features silently never register.
358
+ return feats.length ? { args: { allowInsecure: feats.join(',') } } : {};
359
+ })()],
360
+ ],
279
361
  port: 4723,
280
362
  path: '/',
281
363
 
@@ -291,12 +373,27 @@ export const config: WebdriverIO.Config = {
291
373
  retries: 1,
292
374
  },
293
375
 
376
+ // expect-webdriverio's default assertion budget (~2s wait / 100ms interval) is tuned for
377
+ // sub-second finds. On an accessibility tree churned by looping in-app animations (a rotating
378
+ // promo carousel is enough) a single server-side find can take 5-15s, so every toBeDisplayed()
379
+ // would expire before its first query even returns — align the budget with waitforTimeout.
380
+ before: async () => {
381
+ const { setOptions } = await import('expect-webdriverio');
382
+ setOptions({ wait: 20000, interval: 500 });
383
+ },
384
+
385
+ // Connectivity self-heal (#615): onPrepare heals a device wedged by a previous KILLED run
386
+ // (its onComplete never fired) before the session starts; onComplete restores after this run,
387
+ // pass or fail. Both run in the launcher process, so they fire even when the worker/session died.
388
+ onPrepare: () => restoreConnectivity('onPrepare'),
389
+ onComplete: () => restoreConnectivity('onComplete'),
390
+
294
391
  // iOS + locale: XCUITest's `noReset:false` does NOT actually clear the app's data container
295
392
  // (verified live 2026-06-11) — a Flutter app that persisted its language on a previous launch keeps
296
393
  // it and ignores the new device locale, so the i18n run asserts the wrong language. Wipe the app
297
394
  // data via simctl BEFORE the session so first-launch locale detection re-runs. Android needs no
298
395
  // hook (its noReset:false reset works natively).
299
- beforeSession: async (_config, capabilities) => {
396
+ beforeSession: async (_config, capabilities, specs) => {
300
397
  if (Object.keys(localeCaps).length === 0) return; // not a locale run
301
398
  const caps = capabilities as Record<string, unknown>;
302
399
  if (String(caps['platformName'] || '').toLowerCase() !== 'ios') return;
@@ -20,6 +20,7 @@ export const VALID_SELECTOR_TYPES = [
20
20
  'xpath', // cross-platform, last resort
21
21
  'android-uiautomator', // Android only — UiSelector expressions
22
22
  'ios-predicate', // iOS only — NSPredicate strings
23
+ 'css', // hybrid WebView only — CSS inside a WEBVIEW context (after `switch to [X] frame`)
23
24
  ] as const;
24
25
 
25
26
  export type SelectorType = (typeof VALID_SELECTOR_TYPES)[number];