spana-test 0.0.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.agents/skills/spana-testing/SKILL.md +304 -0
  2. package/README.md +308 -88
  3. package/dist/agent/index.d.ts +110 -0
  4. package/dist/agent/index.js +25 -0
  5. package/dist/allure-PTTVORQ6.js +124 -0
  6. package/dist/allure-PTTVORQ6.js.map +1 -0
  7. package/dist/android-PAPJJWVN.js +34 -0
  8. package/dist/android-PAPJJWVN.js.map +1 -0
  9. package/dist/chunk-3FSZNKEF.js +62 -0
  10. package/dist/chunk-3FSZNKEF.js.map +1 -0
  11. package/dist/chunk-3YR4GUGE.js +249 -0
  12. package/dist/chunk-3YR4GUGE.js.map +1 -0
  13. package/dist/{discover-XIRJTZ7Z.js → chunk-AEKDFFPJ.js} +12 -5
  14. package/dist/{discover-XIRJTZ7Z.js.map → chunk-AEKDFFPJ.js.map} +1 -1
  15. package/dist/chunk-BF37W5EG.js +125 -0
  16. package/dist/chunk-BF37W5EG.js.map +1 -0
  17. package/dist/chunk-DGUM43GV.js +11 -0
  18. package/dist/chunk-DGUM43GV.js.map +1 -0
  19. package/dist/chunk-EXLUY7KT.js +21 -0
  20. package/dist/chunk-EXLUY7KT.js.map +1 -0
  21. package/dist/chunk-FNDOEMOL.js +62 -0
  22. package/dist/chunk-FNDOEMOL.js.map +1 -0
  23. package/dist/{chunk-CYEDLQJ4.js → chunk-GZK22EIE.js} +76 -102
  24. package/dist/chunk-GZK22EIE.js.map +1 -0
  25. package/dist/chunk-HWFDXIXR.js +183 -0
  26. package/dist/chunk-HWFDXIXR.js.map +1 -0
  27. package/dist/chunk-IJIASIX5.js +314 -0
  28. package/dist/chunk-IJIASIX5.js.map +1 -0
  29. package/dist/chunk-KJPHH2TW.js +168 -0
  30. package/dist/chunk-KJPHH2TW.js.map +1 -0
  31. package/dist/chunk-L7MFJF46.js +137 -0
  32. package/dist/chunk-L7MFJF46.js.map +1 -0
  33. package/dist/chunk-MRH7SK52.js +134 -0
  34. package/dist/chunk-MRH7SK52.js.map +1 -0
  35. package/dist/chunk-P7JQRLP4.js +114 -0
  36. package/dist/chunk-P7JQRLP4.js.map +1 -0
  37. package/dist/chunk-S2XNAKSO.js +1087 -0
  38. package/dist/chunk-S2XNAKSO.js.map +1 -0
  39. package/dist/chunk-S4R4OR7T.js +358 -0
  40. package/dist/chunk-S4R4OR7T.js.map +1 -0
  41. package/dist/chunk-SFBRFB2N.js +277 -0
  42. package/dist/chunk-SFBRFB2N.js.map +1 -0
  43. package/dist/chunk-VNYF5BHX.js +494 -0
  44. package/dist/chunk-VNYF5BHX.js.map +1 -0
  45. package/dist/chunk-WBU34APM.js +38 -0
  46. package/dist/chunk-WBU34APM.js.map +1 -0
  47. package/dist/chunk-WQ4GXUUE.js +2402 -0
  48. package/dist/chunk-WQ4GXUUE.js.map +1 -0
  49. package/dist/chunk-YBZCOQXJ.js +311 -0
  50. package/dist/chunk-YBZCOQXJ.js.map +1 -0
  51. package/dist/cli.js +428 -34
  52. package/dist/cli.js.map +1 -1
  53. package/dist/compiler-74VGKZO6.js +312 -0
  54. package/dist/compiler-74VGKZO6.js.map +1 -0
  55. package/dist/config-loader-BJJ3IJJ7.js +9 -0
  56. package/dist/config-loader-BJJ3IJJ7.js.map +1 -0
  57. package/dist/console-XWKUTP3D.js +164 -0
  58. package/dist/console-XWKUTP3D.js.map +1 -0
  59. package/dist/coordinator-BbUjvvnX.d.ts +383 -0
  60. package/dist/discover-KZKXHZZA.js +14 -0
  61. package/dist/discover-KZKXHZZA.js.map +1 -0
  62. package/dist/doctor-command-T2UX5RV5.js +732 -0
  63. package/dist/doctor-command-T2UX5RV5.js.map +1 -0
  64. package/dist/element-DZ0HyJ3C.d.ts +25 -0
  65. package/dist/flow-BUC9Mf8W.d.ts +128 -0
  66. package/dist/gherkin/steps.d.ts +32 -0
  67. package/dist/gherkin/steps.js +39 -0
  68. package/dist/gherkin/steps.js.map +1 -0
  69. package/dist/{html-GRB34S6X.js → html-GE6Q4DCG.js} +76 -22
  70. package/dist/html-GE6Q4DCG.js.map +1 -0
  71. package/dist/index.d.ts +159 -144
  72. package/dist/index.js +39 -165
  73. package/dist/index.js.map +1 -1
  74. package/dist/init-command-GVMRXIMY.js +121 -0
  75. package/dist/init-command-GVMRXIMY.js.map +1 -0
  76. package/dist/init-flow-command-R76AXF4Z.js +34 -0
  77. package/dist/init-flow-command-R76AXF4Z.js.map +1 -0
  78. package/dist/installer-YZJ4DV3F.js +22 -0
  79. package/dist/installer-YZJ4DV3F.js.map +1 -0
  80. package/dist/ios-ZW6XVNLG.js +50 -0
  81. package/dist/ios-ZW6XVNLG.js.map +1 -0
  82. package/dist/json-KS67BZYU.js +39 -0
  83. package/dist/json-KS67BZYU.js.map +1 -0
  84. package/dist/{junit-NAGZJOGQ.js → junit-HLC62MK6.js} +15 -4
  85. package/dist/junit-HLC62MK6.js.map +1 -0
  86. package/dist/provider-A57C3MU6.js +12 -0
  87. package/dist/provider-A57C3MU6.js.map +1 -0
  88. package/dist/redact-U72BUBBR.js +77 -0
  89. package/dist/redact-U72BUBBR.js.map +1 -0
  90. package/dist/runner-UXNHVVGG.js +20 -0
  91. package/dist/runner-UXNHVVGG.js.map +1 -0
  92. package/dist/server-W7OA3DDN.js +530 -0
  93. package/dist/server-W7OA3DDN.js.map +1 -0
  94. package/dist/session-TMNOKYLG.js +17 -0
  95. package/dist/session-TMNOKYLG.js.map +1 -0
  96. package/dist/studio-command-6VHTHDUK.js +24 -0
  97. package/dist/studio-command-6VHTHDUK.js.map +1 -0
  98. package/dist/test-command-AHMOZLV4.js +2852 -0
  99. package/dist/test-command-AHMOZLV4.js.map +1 -0
  100. package/dist/validator-35624P7S.js +20 -0
  101. package/dist/validator-35624P7S.js.map +1 -0
  102. package/package.json +41 -4
  103. package/studio-dist/assets/index-DC6DIXfl.js +188 -0
  104. package/studio-dist/assets/index-DDKsnBwD.css +1 -0
  105. package/studio-dist/index.html +13 -0
  106. package/dist/chunk-CYEDLQJ4.js.map +0 -1
  107. package/dist/chunk-PVNNKPBW.js +0 -64
  108. package/dist/chunk-PVNNKPBW.js.map +0 -1
  109. package/dist/chunk-VZZH66U5.js +0 -1781
  110. package/dist/chunk-VZZH66U5.js.map +0 -1
  111. package/dist/console-GPV3M3PC.js +0 -71
  112. package/dist/console-GPV3M3PC.js.map +0 -1
  113. package/dist/html-GRB34S6X.js.map +0 -1
  114. package/dist/json-FK2NSRGC.js +0 -20
  115. package/dist/json-FK2NSRGC.js.map +0 -1
  116. package/dist/junit-NAGZJOGQ.js.map +0 -1
  117. package/dist/runner-LBQUCG3K.js +0 -12
  118. package/dist/session-U7VP5J2C.js +0 -122
  119. package/dist/session-U7VP5J2C.js.map +0 -1
  120. package/dist/test-command-WPYLJYIK.js +0 -636
  121. package/dist/test-command-WPYLJYIK.js.map +0 -1
  122. package/dist/validator-J4YSBB66.js +0 -33
  123. package/dist/validator-J4YSBB66.js.map +0 -1
  124. /package/dist/{runner-LBQUCG3K.js.map → agent/index.js.map} +0 -0
@@ -0,0 +1,125 @@
1
+ import {
2
+ adbForward,
3
+ adbInstall,
4
+ adbShell,
5
+ findADB
6
+ } from "./chunk-GZK22EIE.js";
7
+ import {
8
+ allocatePort,
9
+ releasePort
10
+ } from "./chunk-3YR4GUGE.js";
11
+
12
+ // src/drivers/uiautomator2/installer.ts
13
+ import { execSync } from "child_process";
14
+ import { existsSync, readdirSync } from "fs";
15
+ import { createRequire } from "module";
16
+ import { dirname, resolve, join } from "path";
17
+ import { fileURLToPath } from "url";
18
+ var __dirname = fileURLToPath(new URL(".", import.meta.url));
19
+ var require2 = createRequire(import.meta.url);
20
+ function resolveOptionalPackageDir(packageName, subpath) {
21
+ try {
22
+ const packageJsonPath = require2.resolve(`${packageName}/package.json`);
23
+ return resolve(dirname(packageJsonPath), subpath);
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ function findUiAutomator2APK() {
29
+ const appiumServerApks = resolveOptionalPackageDir("appium-uiautomator2-server", "apks");
30
+ const projectDrivers = resolve(process.cwd(), "drivers/android");
31
+ const provDrivers = resolve(__dirname, "../../../../drivers/android");
32
+ const maestroRunnerDrivers = resolve(
33
+ __dirname,
34
+ "../../../../../../maestro-runner/drivers/android"
35
+ );
36
+ for (const dir of [projectDrivers, provDrivers, maestroRunnerDrivers, appiumServerApks]) {
37
+ if (!dir) continue;
38
+ if (!existsSync(dir)) continue;
39
+ const files = readdirSync(dir);
40
+ const serverApk = files.find(
41
+ (f) => f.startsWith("appium-uiautomator2-server") && !f.includes("androidTest") && f.endsWith(".apk")
42
+ );
43
+ const testApk = files.find((f) => f.includes("androidTest") && f.endsWith(".apk"));
44
+ if (serverApk && testApk) {
45
+ return { serverApk: join(dir, serverApk), testApk: join(dir, testApk) };
46
+ }
47
+ }
48
+ return null;
49
+ }
50
+ function installUiAutomator2(serial) {
51
+ const apks = findUiAutomator2APK();
52
+ if (!apks) {
53
+ throw new Error(
54
+ "UiAutomator2 server APK not found. Install appium-uiautomator2-server or place APKs in drivers/android/"
55
+ );
56
+ }
57
+ console.log(`Installing UiAutomator2 server on ${serial}...`);
58
+ adbInstall(serial, apks.serverApk);
59
+ adbInstall(serial, apks.testApk);
60
+ console.log("UiAutomator2 server installed.");
61
+ }
62
+ function isUiAutomator2Installed(serial) {
63
+ try {
64
+ const output = adbShell(serial, "pm list packages io.appium.uiautomator2.server");
65
+ return output.includes("io.appium.uiautomator2.server");
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+ function startUiAutomator2Server(serial) {
71
+ const adb = findADB();
72
+ if (!adb) throw new Error("adb not found");
73
+ try {
74
+ execSync(
75
+ `${adb} -s ${serial} shell am instrument -w -e disableAnalytics true io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner &`,
76
+ { stdio: "ignore", timeout: 5e3 }
77
+ );
78
+ } catch {
79
+ }
80
+ }
81
+ async function setupUiAutomator2(serial, hostPort) {
82
+ const port = hostPort ?? allocatePort(8200);
83
+ if (!isUiAutomator2Installed(serial)) {
84
+ installUiAutomator2(serial);
85
+ }
86
+ const adb = findADB();
87
+ if (adb) {
88
+ try {
89
+ execSync(`${adb} -s ${serial} forward --remove tcp:${port}`, { stdio: "ignore" });
90
+ } catch {
91
+ }
92
+ }
93
+ startUiAutomator2Server(serial);
94
+ await new Promise((r) => setTimeout(r, 2e3));
95
+ const devicePort = 6790;
96
+ adbForward(serial, port, devicePort);
97
+ const maxRetries = 10;
98
+ for (let i = 0; i < maxRetries; i++) {
99
+ try {
100
+ const res = await fetch(`http://localhost:${port}/status`);
101
+ if (res.ok) {
102
+ console.log(`UiAutomator2 server ready on port ${port}`);
103
+ const cleanup = () => {
104
+ try {
105
+ if (adb)
106
+ execSync(`${adb} -s ${serial} forward --remove tcp:${port}`, { stdio: "ignore" });
107
+ } catch {
108
+ }
109
+ releasePort(port);
110
+ };
111
+ return { host: "localhost", port, cleanup };
112
+ }
113
+ } catch {
114
+ }
115
+ await new Promise((r) => setTimeout(r, 1e3));
116
+ }
117
+ releasePort(port);
118
+ throw new Error(`UiAutomator2 server did not start within ${maxRetries} seconds`);
119
+ }
120
+
121
+ export {
122
+ findUiAutomator2APK,
123
+ setupUiAutomator2
124
+ };
125
+ //# sourceMappingURL=chunk-BF37W5EG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/drivers/uiautomator2/installer.ts"],"sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { findADB, adbShell, adbInstall, adbForward } from \"../../device/android.js\";\nimport { allocatePort, releasePort } from \"../../core/port-allocator.js\";\n\nconst __dirname = fileURLToPath(new URL(\".\", import.meta.url));\nconst require = createRequire(import.meta.url);\n\nfunction resolveOptionalPackageDir(packageName: string, subpath: string): string | null {\n try {\n const packageJsonPath = require.resolve(`${packageName}/package.json`);\n return resolve(dirname(packageJsonPath), subpath);\n } catch {\n return null;\n }\n}\n\n/** Find the UiAutomator2 server APKs */\nexport function findUiAutomator2APK(): { serverApk: string; testApk: string } | null {\n const appiumServerApks = resolveOptionalPackageDir(\"appium-uiautomator2-server\", \"apks\");\n // Check in the current project first\n const projectDrivers = resolve(process.cwd(), \"drivers/android\");\n // Check in spana's drivers/ directory as a fallback for development\n const provDrivers = resolve(__dirname, \"../../../../drivers/android\");\n // Check in maestro-runner's drivers/ directory as fallback\n const maestroRunnerDrivers = resolve(\n __dirname,\n \"../../../../../../maestro-runner/drivers/android\",\n );\n\n for (const dir of [projectDrivers, provDrivers, maestroRunnerDrivers, appiumServerApks]) {\n if (!dir) continue;\n if (!existsSync(dir)) continue;\n const files = readdirSync(dir);\n const serverApk = files.find(\n (f) =>\n f.startsWith(\"appium-uiautomator2-server\") &&\n !f.includes(\"androidTest\") &&\n f.endsWith(\".apk\"),\n );\n const testApk = files.find((f) => f.includes(\"androidTest\") && f.endsWith(\".apk\"));\n if (serverApk && testApk) {\n return { serverApk: join(dir, serverApk), testApk: join(dir, testApk) };\n }\n }\n return null;\n}\n\n/** Install UiAutomator2 server on device */\nexport function installUiAutomator2(serial: string): void {\n const apks = findUiAutomator2APK();\n if (!apks) {\n throw new Error(\n \"UiAutomator2 server APK not found. Install appium-uiautomator2-server or place APKs in drivers/android/\",\n );\n }\n\n console.log(`Installing UiAutomator2 server on ${serial}...`);\n adbInstall(serial, apks.serverApk);\n adbInstall(serial, apks.testApk);\n console.log(\"UiAutomator2 server installed.\");\n}\n\n/** Check if UiAutomator2 server is installed on device */\nexport function isUiAutomator2Installed(serial: string): boolean {\n try {\n const output = adbShell(serial, \"pm list packages io.appium.uiautomator2.server\");\n return output.includes(\"io.appium.uiautomator2.server\");\n } catch {\n return false;\n }\n}\n\n/** Start UiAutomator2 server on device via adb instrument */\nexport function startUiAutomator2Server(serial: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n\n // Start the instrumentation in the background.\n // The server starts listening on port 6790 on the device.\n // The command blocks while the server is running — timeout is expected.\n try {\n execSync(\n `${adb} -s ${serial} shell am instrument -w -e disableAnalytics true io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner &`,\n { stdio: \"ignore\", timeout: 5000 },\n );\n } catch {\n // The command may timeout because it blocks — that's expected.\n // The server is starting in the background.\n }\n}\n\n/** Full setup: install if needed, start server, forward port */\nexport async function setupUiAutomator2(\n serial: string,\n hostPort?: number,\n): Promise<{ host: string; port: number; cleanup: () => void }> {\n const port = hostPort ?? allocatePort(8200);\n\n if (!isUiAutomator2Installed(serial)) {\n installUiAutomator2(serial);\n }\n\n // Clean up only our specific port forward (not all)\n const adb = findADB();\n if (adb) {\n try {\n execSync(`${adb} -s ${serial} forward --remove tcp:${port}`, { stdio: \"ignore\" });\n } catch {\n /* ignore — may not exist */\n }\n }\n\n startUiAutomator2Server(serial);\n\n // Give the server a moment to start before forwarding\n await new Promise((r) => setTimeout(r, 2000));\n\n // Forward device port to host\n const devicePort = 6790;\n adbForward(serial, port, devicePort);\n\n // Poll until the server responds\n const maxRetries = 10;\n for (let i = 0; i < maxRetries; i++) {\n try {\n const res = await fetch(`http://localhost:${port}/status`);\n if (res.ok) {\n console.log(`UiAutomator2 server ready on port ${port}`);\n const cleanup = () => {\n try {\n if (adb)\n execSync(`${adb} -s ${serial} forward --remove tcp:${port}`, { stdio: \"ignore\" });\n } catch {\n /* ignore */\n }\n releasePort(port);\n };\n return { host: \"localhost\", port, cleanup };\n }\n } catch {\n // Not ready yet\n }\n await new Promise((r) => setTimeout(r, 1000));\n }\n\n releasePort(port);\n throw new Error(`UiAutomator2 server did not start within ${maxRetries} seconds`);\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY,mBAAmB;AACxC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,SAAS,YAAY;AACvC,SAAS,qBAAqB;AAI9B,IAAM,YAAY,cAA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AER;AACA,sBAAY,IAAI;AAAA,QAClB;AACA,eAAO,EAAE,MAAM,aAAa,MAAM,QAAQ;AAAA,MAC5C;AAAA,IACF,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,GAAI,CAAC;AAAA,EAC9C;AAEA,cAAY,IAAI;AAChB,QAAM,IAAI,MAAM,4CAA4C,UAAU,UAAU;AAClF;","names":["require"]}
@@ -0,0 +1,11 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ export {
9
+ __require
10
+ };
11
+ //# sourceMappingURL=chunk-DGUM43GV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,21 @@
1
+ // src/runtime/capabilities.ts
2
+ import { readFile } from "fs/promises";
3
+ async function resolveCapabilities(config, opts) {
4
+ const configCaps = config.capabilities ?? {};
5
+ let fileCaps = {};
6
+ const capsFilePath = opts.capsPath ?? config.capabilitiesFile;
7
+ if (capsFilePath) {
8
+ const raw = await readFile(capsFilePath, "utf-8");
9
+ fileCaps = JSON.parse(raw);
10
+ }
11
+ let cliCaps = {};
12
+ if (opts.capsJson) {
13
+ cliCaps = JSON.parse(opts.capsJson);
14
+ }
15
+ return { ...configCaps, ...fileCaps, ...cliCaps };
16
+ }
17
+
18
+ export {
19
+ resolveCapabilities
20
+ };
21
+ //# sourceMappingURL=chunk-EXLUY7KT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/capabilities.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport type { AppiumExecutionConfig } from \"../schemas/config.js\";\n\nexport interface ResolveCapabilitiesOptions {\n capsPath?: string;\n capsJson?: string;\n}\n\n/**\n * Merge capabilities from three sources (later sources override earlier):\n * 1. Config file capabilities (execution.appium.capabilities)\n * 2. Capabilities JSON file (--caps or execution.appium.capabilitiesFile)\n * 3. Inline CLI JSON (--caps-json)\n */\nexport async function resolveCapabilities(\n config: AppiumExecutionConfig,\n opts: ResolveCapabilitiesOptions,\n): Promise<Record<string, unknown>> {\n const configCaps = config.capabilities ?? {};\n\n // Load file caps from --caps flag or config capabilitiesFile\n let fileCaps: Record<string, unknown> = {};\n const capsFilePath = opts.capsPath ?? config.capabilitiesFile;\n if (capsFilePath) {\n const raw = await readFile(capsFilePath, \"utf-8\");\n fileCaps = JSON.parse(raw) as Record<string, unknown>;\n }\n\n // Parse inline JSON caps\n let cliCaps: Record<string, unknown> = {};\n if (opts.capsJson) {\n cliCaps = JSON.parse(opts.capsJson) as Record<string, unknown>;\n }\n\n return { ...configCaps, ...fileCaps, ...cliCaps };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAczB,eAAsB,oBACpB,QACA,MACkC;AAClC,QAAM,aAAa,OAAO,gBAAgB,CAAC;AAG3C,MAAI,WAAoC,CAAC;AACzC,QAAM,eAAe,KAAK,YAAY,OAAO;AAC7C,MAAI,cAAc;AAChB,UAAM,MAAM,MAAM,SAAS,cAAc,OAAO;AAChD,eAAW,KAAK,MAAM,GAAG;AAAA,EAC3B;AAGA,MAAI,UAAmC,CAAC;AACxC,MAAI,KAAK,UAAU;AACjB,cAAU,KAAK,MAAM,KAAK,QAAQ;AAAA,EACpC;AAEA,SAAO,EAAE,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ;AAClD;","names":[]}
@@ -0,0 +1,62 @@
1
+ // src/machine.ts
2
+ var MACHINE_SCHEMA_VERSION = 1;
3
+ var DOCS_ROOT = "https://wezter96.github.io/spana";
4
+ function buildDocsUrl(path) {
5
+ const normalized = path.startsWith("/") ? path : `/${path}`;
6
+ return `${DOCS_ROOT}${normalized.endsWith("/") ? normalized : `${normalized}/`}`;
7
+ }
8
+ function createMachineSuccess(command, data) {
9
+ return {
10
+ schemaVersion: MACHINE_SCHEMA_VERSION,
11
+ command,
12
+ ok: true,
13
+ data
14
+ };
15
+ }
16
+ function createMachineFailure(command, error) {
17
+ return {
18
+ schemaVersion: MACHINE_SCHEMA_VERSION,
19
+ command,
20
+ ok: false,
21
+ error
22
+ };
23
+ }
24
+ function printMachinePayload(payload, pretty = false) {
25
+ console.log(JSON.stringify(payload, null, pretty ? 2 : void 0));
26
+ }
27
+ function failureCategoryToErrorCode(category) {
28
+ return category.replaceAll("-", "_").toUpperCase();
29
+ }
30
+ function failureCategoryToDocsUrl(category) {
31
+ switch (category) {
32
+ case "config-error":
33
+ return buildDocsUrl("/getting-started/configuration");
34
+ case "element-not-found":
35
+ case "element-not-visible":
36
+ case "element-off-screen":
37
+ case "element-not-interactive":
38
+ return buildDocsUrl("/writing-tests/selectors");
39
+ case "text-mismatch":
40
+ case "timeout":
41
+ return buildDocsUrl("/writing-tests/assertions");
42
+ case "device-disconnected":
43
+ case "app-not-installed":
44
+ return buildDocsUrl("/guides/device-setup");
45
+ case "app-crashed":
46
+ case "driver-error":
47
+ case "unknown":
48
+ default:
49
+ return buildDocsUrl("/guides/debugging");
50
+ }
51
+ }
52
+
53
+ export {
54
+ MACHINE_SCHEMA_VERSION,
55
+ buildDocsUrl,
56
+ createMachineSuccess,
57
+ createMachineFailure,
58
+ printMachinePayload,
59
+ failureCategoryToErrorCode,
60
+ failureCategoryToDocsUrl
61
+ };
62
+ //# sourceMappingURL=chunk-FNDOEMOL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/machine.ts"],"sourcesContent":["export const MACHINE_SCHEMA_VERSION = 1 as const;\n\nconst DOCS_ROOT = \"https://wezter96.github.io/spana\";\n\nexport interface MachineErrorDescriptor {\n errorCode: string;\n message: string;\n suggestedFix?: string;\n docsUrl?: string;\n details?: unknown;\n}\n\nexport interface MachineCommandSuccess<T> {\n schemaVersion: typeof MACHINE_SCHEMA_VERSION;\n command: string;\n ok: true;\n data: T;\n}\n\nexport interface MachineCommandFailure {\n schemaVersion: typeof MACHINE_SCHEMA_VERSION;\n command: string;\n ok: false;\n error: MachineErrorDescriptor;\n}\n\nexport function buildDocsUrl(path: string): string {\n const normalized = path.startsWith(\"/\") ? path : `/${path}`;\n return `${DOCS_ROOT}${normalized.endsWith(\"/\") ? normalized : `${normalized}/`}`;\n}\n\nexport function createMachineSuccess<T>(command: string, data: T): MachineCommandSuccess<T> {\n return {\n schemaVersion: MACHINE_SCHEMA_VERSION,\n command,\n ok: true,\n data,\n };\n}\n\nexport function createMachineFailure(\n command: string,\n error: MachineErrorDescriptor,\n): MachineCommandFailure {\n return {\n schemaVersion: MACHINE_SCHEMA_VERSION,\n command,\n ok: false,\n error,\n };\n}\n\nexport function printMachinePayload(payload: unknown, pretty = false): void {\n console.log(JSON.stringify(payload, null, pretty ? 2 : undefined));\n}\n\nexport function failureCategoryToErrorCode(category: string): string {\n return category.replaceAll(\"-\", \"_\").toUpperCase();\n}\n\nexport function failureCategoryToDocsUrl(category: string): string {\n switch (category) {\n case \"config-error\":\n return buildDocsUrl(\"/getting-started/configuration\");\n case \"element-not-found\":\n case \"element-not-visible\":\n case \"element-off-screen\":\n case \"element-not-interactive\":\n return buildDocsUrl(\"/writing-tests/selectors\");\n case \"text-mismatch\":\n case \"timeout\":\n return buildDocsUrl(\"/writing-tests/assertions\");\n case \"device-disconnected\":\n case \"app-not-installed\":\n return buildDocsUrl(\"/guides/device-setup\");\n case \"app-crashed\":\n case \"driver-error\":\n case \"unknown\":\n default:\n return buildDocsUrl(\"/guides/debugging\");\n }\n}\n"],"mappings":";AAAO,IAAM,yBAAyB;AAEtC,IAAM,YAAY;AAwBX,SAAS,aAAa,MAAsB;AACjD,QAAM,aAAa,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AACzD,SAAO,GAAG,SAAS,GAAG,WAAW,SAAS,GAAG,IAAI,aAAa,GAAG,UAAU,GAAG;AAChF;AAEO,SAAS,qBAAwB,SAAiB,MAAmC;AAC1F,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA,IAAI;AAAA,IACJ;AAAA,EACF;AACF;AAEO,SAAS,qBACd,SACA,OACuB;AACvB,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA,IAAI;AAAA,IACJ;AAAA,EACF;AACF;AAEO,SAAS,oBAAoB,SAAkB,SAAS,OAAa;AAC1E,UAAQ,IAAI,KAAK,UAAU,SAAS,MAAM,SAAS,IAAI,MAAS,CAAC;AACnE;AAEO,SAAS,2BAA2B,UAA0B;AACnE,SAAO,SAAS,WAAW,KAAK,GAAG,EAAE,YAAY;AACnD;AAEO,SAAS,yBAAyB,UAA0B;AACjE,UAAQ,UAAU;AAAA,IAChB,KAAK;AACH,aAAO,aAAa,gCAAgC;AAAA,IACtD,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,aAAa,0BAA0B;AAAA,IAChD,KAAK;AAAA,IACL,KAAK;AACH,aAAO,aAAa,2BAA2B;AAAA,IACjD,KAAK;AAAA,IACL,KAAK;AACH,aAAO,aAAa,sBAAsB;AAAA,IAC5C,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL;AACE,aAAO,aAAa,mBAAmB;AAAA,EAC3C;AACF;","names":[]}
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env node
1
+ import {
2
+ __require
3
+ } from "./chunk-DGUM43GV.js";
2
4
 
3
5
  // src/device/android.ts
4
6
  import { execFileSync, execSync } from "child_process";
@@ -56,6 +58,70 @@ function firstAndroidDevice() {
56
58
  const devices = listAndroidDevices();
57
59
  return devices.find((d) => d.state === "device") ?? null;
58
60
  }
61
+ function findEmulator() {
62
+ const candidates = [
63
+ "emulator",
64
+ `${process.env.ANDROID_HOME}/emulator/emulator`,
65
+ `${process.env.ANDROID_SDK_ROOT}/emulator/emulator`,
66
+ `${process.env.HOME}/Library/Android/sdk/emulator/emulator`
67
+ ];
68
+ for (const candidate of candidates) {
69
+ if (!candidate) continue;
70
+ try {
71
+ execSync(`${candidate} -version`, { stdio: "ignore" });
72
+ return candidate;
73
+ } catch {
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+ function listAVDs() {
79
+ const emulator = findEmulator();
80
+ if (!emulator) return [];
81
+ try {
82
+ const output = execSync(`${emulator} -list-avds`, { encoding: "utf-8" });
83
+ return output.split("\n").map((l) => l.trim()).filter(Boolean);
84
+ } catch {
85
+ return [];
86
+ }
87
+ }
88
+ function startEmulator(avdName, timeoutMs = 6e4) {
89
+ const emulator = findEmulator();
90
+ if (!emulator) throw new Error("Android emulator not found");
91
+ const { spawn } = __require("child_process");
92
+ const proc = spawn(emulator, ["-avd", avdName, "-no-snapshot-save", "-no-audio", "-no-window"], {
93
+ detached: true,
94
+ stdio: "ignore"
95
+ });
96
+ proc.unref();
97
+ const adb = findADB();
98
+ if (!adb) throw new Error("adb not found");
99
+ const start = Date.now();
100
+ while (Date.now() - start < timeoutMs) {
101
+ const device = firstAndroidDevice();
102
+ if (device) {
103
+ try {
104
+ const bootAnim = execSync(`${adb} -s ${device.serial} shell getprop sys.boot_completed`, {
105
+ encoding: "utf-8",
106
+ timeout: 5e3
107
+ }).trim();
108
+ if (bootAnim === "1") return device.serial;
109
+ } catch {
110
+ }
111
+ }
112
+ execSync("sleep 2");
113
+ }
114
+ throw new Error(`Emulator "${avdName}" did not boot within ${timeoutMs / 1e3}s`);
115
+ }
116
+ function ensureAndroidDevice(timeoutMs = 6e4) {
117
+ const existing = firstAndroidDevice();
118
+ if (existing) return existing;
119
+ const avds = listAVDs();
120
+ if (avds.length === 0) return null;
121
+ console.log(`No Android device connected. Starting emulator "${avds[0]}"...`);
122
+ const serial = startEmulator(avds[0], timeoutMs);
123
+ return { serial, state: "device", type: "emulator" };
124
+ }
59
125
  function adbForward(serial, hostPort, devicePort) {
60
126
  const adb = findADB();
61
127
  if (!adb) throw new Error("adb not found");
@@ -92,12 +158,15 @@ function adbClearApp(serial, packageName) {
92
158
  function adbOpenLink(serial, url, packageName) {
93
159
  const adb = findADB();
94
160
  if (!adb) throw new Error("adb not found");
161
+ const flags = 67108864 | 268435456;
95
162
  const command = [
96
163
  "am",
97
164
  "start",
98
165
  "-W",
99
166
  "-a",
100
167
  "android.intent.action.VIEW",
168
+ "-f",
169
+ String(flags),
101
170
  "-d",
102
171
  shellQuote(url)
103
172
  ];
@@ -107,115 +176,20 @@ function adbOpenLink(serial, url, packageName) {
107
176
  execFileSync(adb, ["-s", serial, "shell", command.join(" ")], { stdio: "ignore" });
108
177
  }
109
178
 
110
- // src/device/ios.ts
111
- import { execFileSync as execFileSync2, execSync as execSync2 } from "child_process";
112
- function listIOSSimulators() {
113
- try {
114
- const output = execSync2("xcrun simctl list devices -j", { encoding: "utf-8" });
115
- const data = JSON.parse(output);
116
- const simulators = [];
117
- for (const [runtime, devices] of Object.entries(data.devices ?? {})) {
118
- const runtimeName = runtime.replace("com.apple.CoreSimulator.SimRuntime.", "").replace(/-/g, ".");
119
- for (const device of devices) {
120
- simulators.push({
121
- udid: device.udid,
122
- name: device.name,
123
- state: device.state,
124
- runtime: runtimeName,
125
- isAvailable: device.isAvailable ?? true
126
- });
127
- }
128
- }
129
- return simulators;
130
- } catch {
131
- return [];
132
- }
133
- }
134
- function listBootedSimulators() {
135
- return listIOSSimulators().filter((s) => s.state === "Booted" && s.isAvailable);
136
- }
137
- function firstIOSSimulator() {
138
- const booted = listBootedSimulators();
139
- if (booted.length > 0) return booted[0];
140
- const available = listIOSSimulators().filter((s) => s.isAvailable);
141
- return available[0] ?? null;
142
- }
143
- function hasAppInstalledOnSimulator(udid, bundleId) {
144
- if (!bundleId) return false;
145
- try {
146
- execSync2(`xcrun simctl get_app_container ${udid} ${bundleId} app`, { stdio: "ignore" });
147
- return true;
148
- } catch {
149
- return false;
150
- }
151
- }
152
- function firstIOSSimulatorWithApp(bundleId) {
153
- const bootedWithApp = listBootedSimulators().find(
154
- (sim) => hasAppInstalledOnSimulator(sim.udid, bundleId)
155
- );
156
- if (bootedWithApp) return bootedWithApp;
157
- const availableWithApp = listIOSSimulators().filter((sim) => sim.isAvailable).find((sim) => hasAppInstalledOnSimulator(sim.udid, bundleId));
158
- if (availableWithApp) return availableWithApp;
159
- return firstIOSSimulator();
160
- }
161
- function bootSimulator(udid) {
162
- try {
163
- execSync2(`xcrun simctl boot ${udid}`, { stdio: "ignore" });
164
- } catch {
165
- }
166
- }
167
- function launchOnSimulator(udid, bundleId) {
168
- execSync2(`xcrun simctl launch ${udid} ${bundleId}`);
169
- }
170
- function launchWithUrlOnSimulator(udid, bundleId, url) {
171
- execFileSync2("xcrun", ["simctl", "launch", udid, bundleId, "--open-url", url]);
172
- }
173
- function installedUrlSchemesOnSimulator(udid, bundleId) {
174
- if (!bundleId) return [];
175
- try {
176
- const appPath = execSync2(`xcrun simctl get_app_container ${udid} ${bundleId} app`, {
177
- encoding: "utf-8"
178
- }).trim();
179
- const raw = execFileSync2("plutil", [
180
- "-extract",
181
- "CFBundleURLTypes",
182
- "json",
183
- "-o",
184
- "-",
185
- `${appPath}/Info.plist`
186
- ], {
187
- encoding: "utf-8"
188
- });
189
- const urlTypes = JSON.parse(raw);
190
- return urlTypes.flatMap((entry) => entry.CFBundleURLSchemes ?? []);
191
- } catch {
192
- return [];
193
- }
194
- }
195
- function terminateOnSimulator(udid, bundleId) {
196
- try {
197
- execSync2(`xcrun simctl terminate ${udid} ${bundleId}`, { stdio: "ignore" });
198
- } catch {
199
- }
200
- }
201
-
202
179
  export {
203
180
  findADB,
204
181
  listAndroidDevices,
205
182
  firstAndroidDevice,
183
+ findEmulator,
184
+ listAVDs,
185
+ startEmulator,
186
+ ensureAndroidDevice,
206
187
  adbForward,
207
188
  adbShell,
208
189
  adbInstall,
209
190
  adbLaunchApp,
210
191
  adbForceStop,
211
192
  adbClearApp,
212
- adbOpenLink,
213
- listBootedSimulators,
214
- firstIOSSimulatorWithApp,
215
- bootSimulator,
216
- launchOnSimulator,
217
- launchWithUrlOnSimulator,
218
- installedUrlSchemesOnSimulator,
219
- terminateOnSimulator
193
+ adbOpenLink
220
194
  };
221
- //# sourceMappingURL=chunk-CYEDLQJ4.js.map
195
+ //# sourceMappingURL=chunk-GZK22EIE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/device/android.ts"],"sourcesContent":["import { execFileSync, execSync } from \"node:child_process\";\n\nexport interface AndroidDevice {\n serial: string;\n state: string; // \"device\", \"offline\", \"unauthorized\"\n type: \"emulator\" | \"device\";\n}\n\n/** Find the adb binary */\nexport function findADB(): string | null {\n // Check common locations\n const candidates = [\n \"adb\", // on PATH\n `${process.env.ANDROID_HOME}/platform-tools/adb`,\n `${process.env.ANDROID_SDK_ROOT}/platform-tools/adb`,\n \"/usr/local/bin/adb\",\n `${process.env.HOME}/Library/Android/sdk/platform-tools/adb`,\n ];\n\n for (const candidate of candidates) {\n if (!candidate) continue;\n try {\n execSync(`${candidate} version`, { stdio: \"ignore\" });\n return candidate;\n } catch {\n // try next\n }\n }\n return null;\n}\n\n/** List connected Android devices */\nexport function listAndroidDevices(): AndroidDevice[] {\n const adb = findADB();\n if (!adb) return [];\n\n try {\n const output = execSync(`${adb} devices`, { encoding: \"utf-8\" });\n return parseDeviceList(output);\n } catch {\n return [];\n }\n}\n\nfunction parseDeviceList(output: string): AndroidDevice[] {\n const devices: AndroidDevice[] = [];\n const lines = output.split(\"\\n\");\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"List of\")) continue;\n\n const parts = trimmed.split(/\\s+/);\n if (parts.length < 2) continue;\n\n const serial = parts[0]!;\n const state = parts[1]!;\n\n devices.push({\n serial,\n state,\n type: serial.startsWith(\"emulator-\") ? \"emulator\" : \"device\",\n });\n }\n\n return devices;\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\n}\n\n/** Get first available (state === \"device\") Android device */\nexport function firstAndroidDevice(): AndroidDevice | null {\n const devices = listAndroidDevices();\n return devices.find((d) => d.state === \"device\") ?? null;\n}\n\n/** Find the emulator binary */\nexport function findEmulator(): string | null {\n const candidates = [\n \"emulator\",\n `${process.env.ANDROID_HOME}/emulator/emulator`,\n `${process.env.ANDROID_SDK_ROOT}/emulator/emulator`,\n `${process.env.HOME}/Library/Android/sdk/emulator/emulator`,\n ];\n for (const candidate of candidates) {\n if (!candidate) continue;\n try {\n execSync(`${candidate} -version`, { stdio: \"ignore\" });\n return candidate;\n } catch {\n // try next\n }\n }\n return null;\n}\n\n/** List available Android Virtual Devices */\nexport function listAVDs(): string[] {\n const emulator = findEmulator();\n if (!emulator) return [];\n try {\n const output = execSync(`${emulator} -list-avds`, { encoding: \"utf-8\" });\n return output\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean);\n } catch {\n return [];\n }\n}\n\n/**\n * Start an Android emulator and wait for it to boot.\n * Returns the device serial (e.g. \"emulator-5554\") once ready.\n */\nexport function startEmulator(avdName: string, timeoutMs = 60_000): string {\n const emulator = findEmulator();\n if (!emulator) throw new Error(\"Android emulator not found\");\n\n // Launch in background\n const { spawn } = require(\"node:child_process\") as typeof import(\"node:child_process\");\n const proc = spawn(emulator, [\"-avd\", avdName, \"-no-snapshot-save\", \"-no-audio\", \"-no-window\"], {\n detached: true,\n stdio: \"ignore\",\n });\n proc.unref();\n\n // Wait for device to appear in adb\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n const device = firstAndroidDevice();\n if (device) {\n // Wait for boot to complete\n try {\n const bootAnim = execSync(`${adb} -s ${device.serial} shell getprop sys.boot_completed`, {\n encoding: \"utf-8\",\n timeout: 5000,\n }).trim();\n if (bootAnim === \"1\") return device.serial;\n } catch {\n // not ready yet\n }\n }\n execSync(\"sleep 2\");\n }\n\n throw new Error(`Emulator \"${avdName}\" did not boot within ${timeoutMs / 1000}s`);\n}\n\n/**\n * Ensure an Android device is available.\n * If none connected, attempts to start the first available AVD.\n * Returns the device or null if no AVDs available.\n */\nexport function ensureAndroidDevice(timeoutMs = 60_000): AndroidDevice | null {\n const existing = firstAndroidDevice();\n if (existing) return existing;\n\n const avds = listAVDs();\n if (avds.length === 0) return null;\n\n console.log(`No Android device connected. Starting emulator \"${avds[0]}\"...`);\n const serial = startEmulator(avds[0]!, timeoutMs);\n return { serial, state: \"device\", type: \"emulator\" };\n}\n\n/** Forward a port from host to device via adb */\nexport function adbForward(serial: string, hostPort: number, devicePort: number): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} forward tcp:${hostPort} tcp:${devicePort}`);\n}\n\n/** Run adb shell command on device */\nexport function adbShell(serial: string, command: string): string {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n return execSync(`${adb} -s ${serial} shell ${command}`, { encoding: \"utf-8\" });\n}\n\n/** Install APK on device */\nexport function adbInstall(serial: string, apkPath: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} install -r ${apkPath}`, { stdio: \"ignore\" });\n}\n\n/** Launch an installed app via the launcher intent */\nexport function adbLaunchApp(serial: string, packageName: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(\n `${adb} -s ${serial} shell monkey -p ${packageName} -c android.intent.category.LAUNCHER 1`,\n { stdio: \"ignore\" },\n );\n}\n\n/** Force-stop an installed app */\nexport function adbForceStop(serial: string, packageName: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} shell am force-stop ${packageName}`, { stdio: \"ignore\" });\n}\n\n/** Clear app data and cache */\nexport function adbClearApp(serial: string, packageName: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} shell pm clear ${packageName}`, { stdio: \"ignore\" });\n}\n\n/** Open a deep link or URL on the device */\nexport function adbOpenLink(serial: string, url: string, packageName?: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n\n // FLAG_ACTIVITY_CLEAR_TOP (0x04000000) + FLAG_ACTIVITY_NEW_TASK (0x10000000)\n // ensures the deeplink resets the navigation stack\n const flags = 0x04000000 | 0x10000000;\n const command = [\n \"am\",\n \"start\",\n \"-W\",\n \"-a\",\n \"android.intent.action.VIEW\",\n \"-f\",\n String(flags),\n \"-d\",\n shellQuote(url),\n ];\n\n if (packageName) {\n command.push(shellQuote(packageName));\n }\n\n execFileSync(adb, [\"-s\", serial, \"shell\", command.join(\" \")], { stdio: \"ignore\" });\n}\n"],"mappings":";;;;;AAAA,SAAS,cAAc,gBAAgB;AAShC,SAAS,UAAyB;AAEvC,QAAM,aAAa;AAAA,IACjB;AAAA;AAAA,IACA,GAAG,QAAQ,IAAI,YAAY;AAAA,IAC3B,GAAG,QAAQ,IAAI,gBAAgB;AAAA,IAC/B;AAAA,IACA,GAAG,QAAQ,IAAI,IAAI;AAAA,EACrB;AAEA,aAAW,aAAa,YAAY;AAClC,QAAI,CAAC,UAAW;AAChB,QAAI;AACF,eAAS,GAAG,SAAS,YAAY,EAAE,OAAO,SAAS,CAAC;AACpD,aAAO;AAAA,IACT,QAAQ;AAAA,IAER;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,qBAAsC;AACpD,QAAM,MAAM,QAAQ;AACpB,MAAI,CAAC,IAAK,QAAO,CAAC;AAElB,MAAI;AACF,UAAM,SAAS,SAAS,GAAG,GAAG,YAAY,EAAE,UAAU,QAAQ,CAAC;AAC/D,WAAO,gBAAgB,MAAM;AAAA,EAC/B,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEA,SAAS,gBAAgB,QAAiC;AACxD,QAAM,UAA2B,CAAC;AAClC,QAAM,QAAQ,OAAO,MAAM,IAAI;AAE/B,aAAW,QAAQ,OAAO;AACxB,UAAM,UAAU,KAAK,KAAK;AAC1B,QAAI,CAAC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