@ait-co/devtools 0.1.144 → 0.2.1

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 (182) hide show
  1. package/README.en.md +47 -218
  2. package/README.md +36 -246
  3. package/dist/in-app/auto.d.ts +1 -138
  4. package/dist/in-app/auto.js +28 -1102
  5. package/dist/in-app/auto.js.map +1 -1
  6. package/dist/in-app/index.d.ts +38 -547
  7. package/dist/in-app/index.d.ts.map +1 -1
  8. package/dist/in-app/index.js +62 -939
  9. package/dist/in-app/index.js.map +1 -1
  10. package/dist/mcp/cli.d.ts +1 -54
  11. package/dist/mcp/cli.js +33 -9720
  12. package/dist/mcp/cli.js.map +1 -1
  13. package/dist/mcp/server.d.ts +1 -88
  14. package/dist/mcp/server.js +36 -1076
  15. package/dist/mcp/server.js.map +1 -1
  16. package/dist/mock/index.d.ts +35 -21
  17. package/dist/mock/index.d.ts.map +1 -1
  18. package/dist/mock/index.js +81 -2
  19. package/dist/mock/index.js.map +1 -1
  20. package/dist/panel/index.js +80 -104
  21. package/dist/panel/index.js.map +1 -1
  22. package/dist/relay-url-store-CkVSQZMq.cjs +110 -0
  23. package/dist/relay-url-store-CkVSQZMq.cjs.map +1 -0
  24. package/dist/relay-url-store-dkII-DHD.js +109 -0
  25. package/dist/relay-url-store-dkII-DHD.js.map +1 -0
  26. package/dist/stubs/bin-devtools-mcp.js +58 -0
  27. package/dist/stubs/bin-devtools-mcp.js.map +1 -0
  28. package/dist/stubs/bin-devtools-test.d.ts +2 -0
  29. package/dist/stubs/bin-devtools-test.js +55 -0
  30. package/dist/stubs/bin-devtools-test.js.map +1 -0
  31. package/dist/test-runner/config.d.ts +1 -231
  32. package/dist/test-runner/config.js +41 -45
  33. package/dist/test-runner/config.js.map +1 -1
  34. package/dist/{tunnel-BGT9Curk.cjs → tunnel-BKZkOyQp.cjs} +1 -1
  35. package/dist/{tunnel-BGT9Curk.cjs.map → tunnel-BKZkOyQp.cjs.map} +1 -1
  36. package/dist/{tunnel-BOKmLzBO.js → tunnel-CqSCIrdU.js} +1 -1
  37. package/dist/{tunnel-BOKmLzBO.js.map → tunnel-CqSCIrdU.js.map} +1 -1
  38. package/dist/unplugin/index.cjs +9 -18
  39. package/dist/unplugin/index.cjs.map +1 -1
  40. package/dist/unplugin/index.d.cts +26 -5
  41. package/dist/unplugin/index.d.cts.map +1 -1
  42. package/dist/unplugin/index.d.ts +27 -6
  43. package/dist/unplugin/index.d.ts.map +1 -1
  44. package/dist/unplugin/index.js +10 -19
  45. package/dist/unplugin/index.js.map +1 -1
  46. package/package.json +10 -25
  47. package/dist/attach-orchestrator-0F0m_UqQ.js +0 -1845
  48. package/dist/attach-orchestrator-0F0m_UqQ.js.map +0 -1
  49. package/dist/attach-orchestrator-D65KxFy_.js +0 -1831
  50. package/dist/attach-orchestrator-D65KxFy_.js.map +0 -1
  51. package/dist/attach-orchestrator-DL3NQ9ca.js +0 -1846
  52. package/dist/attach-orchestrator-DL3NQ9ca.js.map +0 -1
  53. package/dist/bundle-C796JIwG.d.ts +0 -159
  54. package/dist/bundle-C796JIwG.d.ts.map +0 -1
  55. package/dist/capture-DsP525OZ.d.ts +0 -58
  56. package/dist/capture-DsP525OZ.d.ts.map +0 -1
  57. package/dist/cdp-connection-rP1WdnH5.d.ts +0 -287
  58. package/dist/cdp-connection-rP1WdnH5.d.ts.map +0 -1
  59. package/dist/cell-BaLvusOl.js +0 -68
  60. package/dist/cell-BaLvusOl.js.map +0 -1
  61. package/dist/cell-CBUS3-nT.js +0 -274
  62. package/dist/cell-CBUS3-nT.js.map +0 -1
  63. package/dist/cell-EBKKpAAT.js +0 -307
  64. package/dist/cell-EBKKpAAT.js.map +0 -1
  65. package/dist/chii-relay-B3ZhjGMi.js +0 -304
  66. package/dist/chii-relay-B3ZhjGMi.js.map +0 -1
  67. package/dist/chii-relay-CGMlePMd.cjs +0 -304
  68. package/dist/chii-relay-CGMlePMd.cjs.map +0 -1
  69. package/dist/debug-server-B3ABDrRI.js +0 -456
  70. package/dist/debug-server-B3ABDrRI.js.map +0 -1
  71. package/dist/debug-server-BWhwrVXa.js +0 -1158
  72. package/dist/debug-server-BWhwrVXa.js.map +0 -1
  73. package/dist/debug-server-CfQNxxGW.js +0 -600
  74. package/dist/debug-server-CfQNxxGW.js.map +0 -1
  75. package/dist/devtools-opener-3Drge_RJ.js +0 -75
  76. package/dist/devtools-opener-3Drge_RJ.js.map +0 -1
  77. package/dist/devtools-opener-CJpEsXXQ.js +0 -76
  78. package/dist/devtools-opener-CJpEsXXQ.js.map +0 -1
  79. package/dist/devtools-opener-CxtryS8c.js +0 -75
  80. package/dist/devtools-opener-CxtryS8c.js.map +0 -1
  81. package/dist/in-app/auto.d.ts.map +0 -1
  82. package/dist/mcp/cli.d.ts.map +0 -1
  83. package/dist/mcp/server.d.ts.map +0 -1
  84. package/dist/pool-DcaaOwUq.d.ts +0 -14761
  85. package/dist/pool-DcaaOwUq.d.ts.map +0 -1
  86. package/dist/qr-http-server-C_lqOrgc.js +0 -1644
  87. package/dist/qr-http-server-C_lqOrgc.js.map +0 -1
  88. package/dist/qr-http-server-CopuMbub.js +0 -1644
  89. package/dist/qr-http-server-CopuMbub.js.map +0 -1
  90. package/dist/qr-http-server-DrbIVDjO.js +0 -1645
  91. package/dist/qr-http-server-DrbIVDjO.js.map +0 -1
  92. package/dist/relay-factory-N9QobQxG.js +0 -206
  93. package/dist/relay-factory-N9QobQxG.js.map +0 -1
  94. package/dist/relay-secret-store-BR0YIkNv.cjs +0 -241
  95. package/dist/relay-secret-store-BR0YIkNv.cjs.map +0 -1
  96. package/dist/relay-secret-store-Bmyleu0A.js +0 -154
  97. package/dist/relay-secret-store-Bmyleu0A.js.map +0 -1
  98. package/dist/relay-secret-store-CQenfcSL.js +0 -154
  99. package/dist/relay-secret-store-CQenfcSL.js.map +0 -1
  100. package/dist/relay-secret-store-CYM8CBIF.js +0 -240
  101. package/dist/relay-secret-store-CYM8CBIF.js.map +0 -1
  102. package/dist/relay-secret-store-DKxs7zwq.js +0 -153
  103. package/dist/relay-secret-store-DKxs7zwq.js.map +0 -1
  104. package/dist/relay-secret-store-WJ8EGkIl.js +0 -153
  105. package/dist/relay-secret-store-WJ8EGkIl.js.map +0 -1
  106. package/dist/relay-url-store-BR2XodiO.js +0 -123
  107. package/dist/relay-url-store-BR2XodiO.js.map +0 -1
  108. package/dist/relay-url-store-C1as_m5G.cjs +0 -115
  109. package/dist/relay-url-store-C1as_m5G.cjs.map +0 -1
  110. package/dist/relay-url-store-CH63fVCm.js +0 -122
  111. package/dist/relay-url-store-CH63fVCm.js.map +0 -1
  112. package/dist/relay-url-store-CzFo_84F.js +0 -114
  113. package/dist/relay-url-store-CzFo_84F.js.map +0 -1
  114. package/dist/relay-url-store-DaY1QPes.js +0 -123
  115. package/dist/relay-url-store-DaY1QPes.js.map +0 -1
  116. package/dist/relay-url-store-xmUuTjXA.js +0 -122
  117. package/dist/relay-url-store-xmUuTjXA.js.map +0 -1
  118. package/dist/relay-worker-B5HKkGUY.js +0 -832
  119. package/dist/relay-worker-B5HKkGUY.js.map +0 -1
  120. package/dist/relay-worker-YdlpZQl9.d.ts +0 -214
  121. package/dist/relay-worker-YdlpZQl9.d.ts.map +0 -1
  122. package/dist/rolldown-runtime-DGkTqVfb.js +0 -15
  123. package/dist/rolldown-runtime-DUslC3ob.js +0 -14
  124. package/dist/runtime-kn9DxOeg.d.ts +0 -249
  125. package/dist/runtime-kn9DxOeg.d.ts.map +0 -1
  126. package/dist/test-runner/bin.js +0 -2584
  127. package/dist/test-runner/bin.js.map +0 -1
  128. package/dist/test-runner/bridge-stub.d.ts +0 -125
  129. package/dist/test-runner/bridge-stub.d.ts.map +0 -1
  130. package/dist/test-runner/bridge-stub.js +0 -92
  131. package/dist/test-runner/bridge-stub.js.map +0 -1
  132. package/dist/test-runner/bundle.d.ts +0 -2
  133. package/dist/test-runner/bundle.js +0 -439
  134. package/dist/test-runner/bundle.js.map +0 -1
  135. package/dist/test-runner/capture.d.ts +0 -2
  136. package/dist/test-runner/capture.js +0 -44
  137. package/dist/test-runner/capture.js.map +0 -1
  138. package/dist/test-runner/config.d.ts.map +0 -1
  139. package/dist/test-runner/method-pace.d.ts +0 -82
  140. package/dist/test-runner/method-pace.d.ts.map +0 -1
  141. package/dist/test-runner/method-pace.js +0 -120
  142. package/dist/test-runner/method-pace.js.map +0 -1
  143. package/dist/test-runner/pool.d.ts +0 -2
  144. package/dist/test-runner/pool.js +0 -136
  145. package/dist/test-runner/pool.js.map +0 -1
  146. package/dist/test-runner/relay-factory.d.ts +0 -11245
  147. package/dist/test-runner/relay-factory.d.ts.map +0 -1
  148. package/dist/test-runner/relay-factory.js +0 -206
  149. package/dist/test-runner/relay-factory.js.map +0 -1
  150. package/dist/test-runner/relay-worker.d.ts +0 -2
  151. package/dist/test-runner/relay-worker.js +0 -2
  152. package/dist/test-runner/report.d.ts +0 -163
  153. package/dist/test-runner/report.d.ts.map +0 -1
  154. package/dist/test-runner/report.js +0 -198
  155. package/dist/test-runner/report.js.map +0 -1
  156. package/dist/test-runner/rpc.d.ts +0 -56
  157. package/dist/test-runner/rpc.d.ts.map +0 -1
  158. package/dist/test-runner/rpc.js +0 -98
  159. package/dist/test-runner/rpc.js.map +0 -1
  160. package/dist/test-runner/runtime.d.ts +0 -2
  161. package/dist/test-runner/runtime.js +0 -659
  162. package/dist/test-runner/runtime.js.map +0 -1
  163. package/dist/test-runner/task-graph.d.ts +0 -38
  164. package/dist/test-runner/task-graph.d.ts.map +0 -1
  165. package/dist/test-runner/task-graph.js +0 -182
  166. package/dist/test-runner/task-graph.js.map +0 -1
  167. package/dist/throttle-DKKzX1qC.js +0 -59
  168. package/dist/throttle-DKKzX1qC.js.map +0 -1
  169. package/dist/totp-BqmCLSNA.js +0 -189
  170. package/dist/totp-BqmCLSNA.js.map +0 -1
  171. package/dist/totp-CMHR5lsW.cjs +0 -191
  172. package/dist/totp-CMHR5lsW.cjs.map +0 -1
  173. package/dist/totp-CZLLKfOC.js +0 -200
  174. package/dist/totp-CZLLKfOC.js.map +0 -1
  175. package/dist/totp-DAxys-r0.js +0 -199
  176. package/dist/totp-DAxys-r0.js.map +0 -1
  177. package/dist/totp-DfekTBk3.js +0 -211
  178. package/dist/totp-DfekTBk3.js.map +0 -1
  179. package/dist/totp-Dwft0Kz7.js +0 -3
  180. package/dist/totp-WY6l0ysP.js +0 -190
  181. package/dist/totp-WY6l0ysP.js.map +0 -1
  182. /package/dist/{test-runner/bin.d.ts → stubs/bin-devtools-mcp.d.ts} +0 -0
@@ -1,274 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
- import { a as buildIndicatorExpression } from "./attach-orchestrator-0F0m_UqQ.js";
3
- import { n as THROTTLED_MESSAGE_SUBSTRING, t as THROTTLED_ERROR_CODE } from "./throttle-DKKzX1qC.js";
4
- //#region src/test-runner/cell.ts
5
- /**
6
- * Cell injection utility for the `devtools-test` CLI (issue #684 §4.1).
7
- *
8
- * Injects arbitrary globals into the page via `Runtime.evaluate` BEFORE the
9
- * first test bundle is injected. The injected values are session-global — one
10
- * call covers all files in the run.
11
- *
12
- * The primary use-case is injecting `__AIT_CELL__` (sdkLine/platform) so
13
- * sdk-example's `aitCapture.ts` picks up the correct test-axis values instead
14
- * of falling back to `'2.x'`/`'mock'`.
15
- *
16
- * devtools does NOT know the shape of `__AIT_CELL__` — it only provides the
17
- * general injection mechanism. The caller (CLI or MCP auto-attach path) is
18
- * responsible for constructing the cell object.
19
- *
20
- * SECRET-HANDLING: cell values (sdkLine/platform) are not secrets and may be
21
- * logged at the caller's discretion. This module does NOT log them itself.
22
- *
23
- * Node-only. react-free. CdpConnection only.
24
- */
25
- var cell_exports = /* @__PURE__ */ __exportAll({
26
- PERMISSION_PREFLIGHT_TIMEOUT_MS: () => PERMISSION_PREFLIGHT_TIMEOUT_MS,
27
- buildPermissionPreflightExpression: () => buildPermissionPreflightExpression,
28
- injectDebugIndicator: () => injectDebugIndicator,
29
- injectGlobals: () => injectGlobals,
30
- runPermissionPreflight: () => runPermissionPreflight
31
- });
32
- /**
33
- * `__AIT_PERMS__` key → SDK function name whose `.getPermission()` is probed
34
- * (devtools#739). This is the exact contract sdk-example#265 consumes — do
35
- * not rename keys without a coordinated sdk-example update.
36
- *
37
- * Each SDK function is reached via `window.__sdk` — the SAME page-global
38
- * bridge `src/in-app/auto.ts` installs for `call_sdk`/`__sdkCall` (see
39
- * `src/test-runner/bundle.ts`'s `sdkRedirectPlugin`, which redirects bundled
40
- * `@apps-in-toss/web-framework` imports to this same object at runtime). The
41
- * test-runner bundle owns no independent SDK import — `window.__sdk` is a
42
- * page global regardless of whether a bundle has been injected yet, so this
43
- * preflight runs standalone via `injectGlobals`'s `Runtime.evaluate`
44
- * mechanism BEFORE the first bundle, rather than being prepended into
45
- * `rpc.ts#buildRunTestsExpression`. (Design choice documented in PR #739 —
46
- * bundle-prepend was the fallback plan if the SDK were only reachable from
47
- * inside bundle scope, which reality ruled out.)
48
- */
49
- const PERMISSION_PROBE_MAP = {
50
- clipboardRead: "getClipboardText",
51
- clipboardWrite: "setClipboardText",
52
- album: "fetchAlbumPhotos",
53
- camera: "openCamera",
54
- contacts: "fetchContacts",
55
- location: "getCurrentLocation"
56
- };
57
- /**
58
- * Inter-probe spacing (ms) applied BEFORE every probe after the first
59
- * (devtools#767). The native per-method bridge rate limit observed
60
- * 2026-07-10 rejects a SECOND call to the same method within a short window
61
- * with `APP_BRIDGE_THROTTLED` — the permission preflight's un-paced burst
62
- * (6 probes fired back-to-back) was the FIRST trigger of that limiter in the
63
- * wild (only the first probe passed; the remaining 5 came back throttled →
64
- * `unavailable`, cascading into skipped `__AIT_PERMS__`-branching tests).
65
- * Sequential-with-spacing is cheap insurance even though each probe targets a
66
- * DIFFERENT method — the limiter's exact scope (per-method vs. a shared
67
- * bridge-wide window) was not reverse-engineered (explicitly out of scope,
68
- * devtools#767) so spacing every probe is the conservative choice.
69
- */
70
- const PROBE_INTER_CALL_DELAY_MS = 250;
71
- /**
72
- * Backoff delays (ms) between retry attempts when a probe is throttled. Its
73
- * `.length` IS the max retry count (devtools#767: "최대 2회 재시도") — the
74
- * generated page-side expression below derives `attempt < backoff.length`
75
- * from this same array (via `backoffArray`), so there is a single source for
76
- * both the delay ladder and the retry count; no separate max-retries
77
- * constant is kept in this module (unlike `runtime.ts`'s `TEST_MAX_RETRIES`,
78
- * which IS consumed directly by a Node-side loop condition).
79
- */
80
- const PROBE_RETRY_BACKOFF_MS = [500, 1e3];
81
- /**
82
- * Non-fatal bound for the permission preflight `Runtime.evaluate` round-trip
83
- * (devtools#767: raised from the pre-pacing 10s to cover the new sequential +
84
- * backoff time budget).
85
- *
86
- * Worst-case budget with 6 probes, each requiring the full retry ladder:
87
- * - inter-probe spacing: only BEFORE probes 2‑6 (none before the first) =
88
- * 5 × {@link PROBE_INTER_CALL_DELAY_MS} = 1 250ms
89
- * - per-probe backoff (both retries taken): 6 × (500 + 1000) = 9 000ms
90
- * - probe round-trips themselves (headroom, not just the sleeps): ~4 500ms
91
- * total ≈ 14 750ms, rounded up to a clean 20 000ms for headroom.
92
- */
93
- const PERMISSION_PREFLIGHT_TIMEOUT_MS = 2e4;
94
- /**
95
- * Builds the `Runtime.evaluate` expression for the permission-state preflight
96
- * (devtools#739). Evaluated ONCE per relay session, before the first test
97
- * bundle is injected (see `relay-worker.ts#runTestFilesOverRelay`).
98
- *
99
- * For each entry in {@link PERMISSION_PROBE_MAP}, probes
100
- * `window.__sdk.<fn>.getPermission()` — a NON-blocking query (never
101
- * `openPermissionDialog`/`requestPermission`, which open native UI) — and
102
- * assigns the resolved `'allowed'|'denied'|'notDetermined'` status to
103
- * `globalThis.__AIT_PERMS__[<key>]`. A probe that is absent, throws, or
104
- * rejects resolves to `'unavailable'` — this expression never throws to its
105
- * caller, and a single slow/broken permission must not fail the others (each
106
- * probe is awaited independently, not short-circuited).
107
- *
108
- * devtools#767: probes run SEQUENTIALLY (not a parallel burst) with a
109
- * {@link PROBE_INTER_CALL_DELAY_MS} gap before each probe after the first, and
110
- * a probe that comes back `APP_BRIDGE_THROTTLED` (native per-method bridge
111
- * rate limit) is retried up to {@link PROBE_RETRY_BACKOFF_MS}`.length` times
112
- * with the same {@link PROBE_RETRY_BACKOFF_MS} ladder before falling back to
113
- * `'unavailable'`.
114
- * The THROTTLED detection mirrors `throttle.ts#isThrottledError` inline (this
115
- * expression is raw JS text evaluated via CDP, not an esbuild-bundled module,
116
- * so it cannot statically `import` that helper) — kept in sync by checking
117
- * BOTH `e.code === 'APP_BRIDGE_THROTTLED'` and a message substring match, the
118
- * same two signals `isThrottledError` checks.
119
- *
120
- * devtools#767 acceptance criteria 2 ("3.x run duration은 유의미하게 늘지 않음,
121
- * pacing은 opt-in 또는 throttle-adaptive") requires this NOT be an unconditional
122
- * cost — `pace` (default `true`, matching the pre-existing sequential+spacing
123
- * behavior for 2.x/unknown cells) lets a 3.x caller skip BOTH the inter-probe
124
- * `sleep(250)` AND the retry backoff ladder, since `APP_BRIDGE_THROTTLED` is a
125
- * 2.x-bridge-only limiter (see `--pace`'s own doc in `cli.ts`: "3.x cells are
126
- * unaffected by that limiter"). When `pace` is `false`, probes still run
127
- * sequentially (never a parallel burst) but back-to-back with no added delay,
128
- * and a THROTTLED result resolves to `'unavailable'` immediately (no retry) —
129
- * this matches the 3.x runtime, which never emits `APP_BRIDGE_THROTTLED`.
130
- *
131
- * Tests (sdk-example#265) read `globalThis.__AIT_PERMS__` to branch
132
- * deterministically per permission state instead of blanket outcome-branching.
133
- *
134
- * Returns a JSON-serialised string (the same double-serialisation pattern
135
- * `rpc.ts#buildRunTestsExpression` uses) rather than relying on CDP
136
- * `returnByValue` structural fidelity for a plain object across the Chii
137
- * relay — the Node side re-parses via `JSON.parse`.
138
- *
139
- * Pure function — no I/O, no CDP call. Callers pass the returned string to
140
- * `Runtime.evaluate`.
141
- *
142
- * @param pace - Defaults to `true` (today's sequential+spacing+backoff
143
- * behavior). Pass `false` for a 3.x cell to skip the inter-probe delay and
144
- * the THROTTLED retry ladder entirely.
145
- */
146
- function buildPermissionPreflightExpression(pace = true) {
147
- const probeCalls = Object.keys(PERMISSION_PROBE_MAP).map((key, i) => {
148
- const fnName = PERMISSION_PROBE_MAP[key];
149
- return `${i === 0 || !pace ? "" : ` await sleep(${PROBE_INTER_CALL_DELAY_MS});\n`} result[${JSON.stringify(key)}] = await probeWithRetry(${JSON.stringify(fnName)});`;
150
- }).join("\n");
151
- const backoffArray = pace ? `[${PROBE_RETRY_BACKOFF_MS.join(",")}]` : "[]";
152
- return `(async () => { const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const isThrottled = (e) => { if (!e) return false; if (e.code === ${JSON.stringify(THROTTLED_ERROR_CODE)}) return true; const msg = typeof e.message === 'string' ? e.message : ''; return msg.indexOf(${JSON.stringify(THROTTLED_MESSAGE_SUBSTRING)}) !== -1; }; const probe = async (fnName) => { const fn = globalThis.__sdk && globalThis.__sdk[fnName]; if (!fn || typeof fn.getPermission !== 'function') return { ok: true, value: 'unavailable' }; const status = await fn.getPermission(); if (status === 'allowed' || status === 'denied' || status === 'notDetermined') return { ok: true, value: status }; return { ok: true, value: 'unavailable' }; }; const backoff = ${backoffArray}; const probeWithRetry = async (fnName) => { for (let attempt = 0; attempt <= backoff.length; attempt++) { try { const r = await probe(fnName); return r.value; } catch (e) { if (isThrottled(e) && attempt < backoff.length) { await sleep(backoff[attempt]); continue; } return 'unavailable'; } } return 'unavailable'; }; const result = {};${probeCalls}\n globalThis.__AIT_PERMS__ = result; return JSON.stringify(result);})()`;
153
- }
154
- /**
155
- * Runs the permission-state preflight (devtools#739) via `Runtime.evaluate`
156
- * and returns the collected `__AIT_PERMS__` map, or `undefined` when the
157
- * preflight itself failed or timed out.
158
- *
159
- * NON-FATAL by design: any failure (CDP exception, timeout, page-side throw)
160
- * is caught here, logged as ONE stderr line, and swallowed — the whole test
161
- * run must proceed even when the preflight cannot complete (e.g. `window.__sdk`
162
- * not yet installed, or a page navigation mid-attach). Callers that want the
163
- * result for report provenance (`RelayRunReport.preflight`) get `undefined`
164
- * in that case, which downstream code treats the same as "not run".
165
- *
166
- * SECRET-HANDLING: no relay/wss/secret values are read or logged; only
167
- * permission-state strings cross this boundary.
168
- *
169
- * @param conn - The live CDP connection (relay-attached page).
170
- * @param timeoutMs - Round-trip bound. Defaults to {@link PERMISSION_PREFLIGHT_TIMEOUT_MS}.
171
- * @param pace - Forwarded to {@link buildPermissionPreflightExpression}.
172
- * Defaults to `true` (today's sequential+spacing+backoff behavior, correct
173
- * for 2.x/unknown cells). Callers that know the cell is 3.x should pass
174
- * `false` — devtools#767 acceptance criteria 2 requires 3.x run duration not
175
- * grow from this preflight, and 3.x never hits the 2.x-only
176
- * `APP_BRIDGE_THROTTLED` limiter this pacing exists to dodge.
177
- */
178
- async function runPermissionPreflight(conn, timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS, pace = true) {
179
- const TIMEOUT_SENTINEL = Symbol("permission-preflight-timeout");
180
- const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(TIMEOUT_SENTINEL), timeoutMs));
181
- try {
182
- const evalPromise = conn.send("Runtime.evaluate", {
183
- expression: buildPermissionPreflightExpression(pace),
184
- returnByValue: true,
185
- awaitPromise: true
186
- });
187
- const raceResult = await Promise.race([evalPromise.then((v) => ({
188
- tag: "eval",
189
- v
190
- })), timeoutPromise.then(() => ({ tag: "timeout" }))]);
191
- if (raceResult.tag === "timeout") {
192
- process.stderr.write(`test-runner: permission preflight timed out after ${timeoutMs}ms — proceeding with __AIT_PERMS__ unset\n`);
193
- return;
194
- }
195
- if (raceResult.v.exceptionDetails) {
196
- process.stderr.write("test-runner: permission preflight threw — proceeding with __AIT_PERMS__ unset\n");
197
- return;
198
- }
199
- const rawValue = raceResult.v.result.value;
200
- if (typeof rawValue !== "string") return void 0;
201
- const parsed = JSON.parse(rawValue);
202
- if (typeof parsed !== "object" || parsed === null) return void 0;
203
- return parsed;
204
- } catch (e) {
205
- process.stderr.write(`test-runner: permission preflight failed (${e instanceof Error ? e.message : String(e)}) — proceeding with __AIT_PERMS__ unset\n`);
206
- return;
207
- }
208
- }
209
- /**
210
- * Injects each key of `globals` into `globalThis` in the page via a single
211
- * `Runtime.evaluate` call. Must be called BEFORE the first `bundleTestFile`
212
- * inject — the cell is session-global and applies to all subsequent files.
213
- *
214
- * Throws if the CDP evaluate returns an exception.
215
- *
216
- * @param conn - The live CDP connection (relay-attached page).
217
- * @param globals - Plain-JSON-serialisable key→value map to assign onto `globalThis`.
218
- */
219
- async function injectGlobals(conn, globals) {
220
- const expr = `(() => { Object.assign(globalThis, ${JSON.stringify(globals)}); return true; })()`;
221
- const result = await conn.send("Runtime.evaluate", {
222
- expression: expr,
223
- returnByValue: true
224
- });
225
- if (result.exceptionDetails) {
226
- const msg = result.exceptionDetails.exception?.description ?? result.exceptionDetails.text ?? "unknown error";
227
- throw new Error(`injectGlobals: Runtime.evaluate threw: ${msg}`);
228
- }
229
- }
230
- /**
231
- * Injects (or updates) the "Debugger Connected"/"Debugger Disconnected"
232
- * on-phone indicator via `Runtime.evaluate` (#730).
233
- *
234
- * Uses the same CDP mechanism as {@link injectGlobals} — a single
235
- * `Runtime.evaluate` round-trip with the expression built by
236
- * {@link buildIndicatorExpression}. The indicator is a LIVE badge rendered at
237
- * the bottom-left of the page (position:fixed, safe-area-aware): the badge's
238
- * controller is idempotent, so calling this again (e.g. right before
239
- * `close()` with `{ state: 'disconnected' }`) UPDATES the existing badge in
240
- * place instead of injecting a duplicate.
241
- *
242
- * **Isolation**: unlike {@link injectGlobals}, this function NEVER throws to
243
- * its caller. Injection failure (e.g. page detached during inject, CSS not
244
- * supported) is swallowed and logged as `console.debug` — the badge is
245
- * informational UI and must never block attach success or test execution.
246
- * This is the same fire-and-forget spirit as the in-page console mount in
247
- * `src/in-app/attach.ts`.
248
- *
249
- * Call this ONLY on the manual debug paths (start_attach MCP, devtools-test
250
- * CLI). Do NOT call on the `run_tests` auto-attach path — the badge
251
- * would contaminate screenshots, measure_safe_area probes, and DOM snapshots
252
- * taken during automated measurement runs.
253
- *
254
- * SECRET-HANDLING: the injected expression contains no secrets, relay URLs,
255
- * wss addresses, or TOTP codes — it is pure DOM UI text + enum state built by
256
- * {@link buildIndicatorExpression}.
257
- *
258
- * @param conn - The live CDP connection (relay-attached page).
259
- * @param opts - Optional overrides forwarded to {@link buildIndicatorExpression}.
260
- */
261
- async function injectDebugIndicator(conn, opts) {
262
- try {
263
- await conn.send("Runtime.evaluate", {
264
- expression: buildIndicatorExpression(opts),
265
- returnByValue: true
266
- });
267
- } catch (err) {
268
- console.debug("[@ait-co/devtools] debug indicator inject skipped:", err);
269
- }
270
- }
271
- //#endregion
272
- export { cell_exports as n, runPermissionPreflight as r, PERMISSION_PREFLIGHT_TIMEOUT_MS as t };
273
-
274
- //# sourceMappingURL=cell-CBUS3-nT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cell-CBUS3-nT.js","names":[],"sources":["../src/test-runner/cell.ts"],"sourcesContent":["/**\n * Cell injection utility for the `devtools-test` CLI (issue #684 §4.1).\n *\n * Injects arbitrary globals into the page via `Runtime.evaluate` BEFORE the\n * first test bundle is injected. The injected values are session-global — one\n * call covers all files in the run.\n *\n * The primary use-case is injecting `__AIT_CELL__` (sdkLine/platform) so\n * sdk-example's `aitCapture.ts` picks up the correct test-axis values instead\n * of falling back to `'2.x'`/`'mock'`.\n *\n * devtools does NOT know the shape of `__AIT_CELL__` — it only provides the\n * general injection mechanism. The caller (CLI or MCP auto-attach path) is\n * responsible for constructing the cell object.\n *\n * SECRET-HANDLING: cell values (sdkLine/platform) are not secrets and may be\n * logged at the caller's discretion. This module does NOT log them itself.\n *\n * Node-only. react-free. CdpConnection only.\n */\n\nimport { THROTTLED_ERROR_CODE, THROTTLED_MESSAGE_SUBSTRING } from './throttle.js';\n\n/**\n * `__AIT_PERMS__` key → SDK function name whose `.getPermission()` is probed\n * (devtools#739). This is the exact contract sdk-example#265 consumes — do\n * not rename keys without a coordinated sdk-example update.\n *\n * Each SDK function is reached via `window.__sdk` — the SAME page-global\n * bridge `src/in-app/auto.ts` installs for `call_sdk`/`__sdkCall` (see\n * `src/test-runner/bundle.ts`'s `sdkRedirectPlugin`, which redirects bundled\n * `@apps-in-toss/web-framework` imports to this same object at runtime). The\n * test-runner bundle owns no independent SDK import — `window.__sdk` is a\n * page global regardless of whether a bundle has been injected yet, so this\n * preflight runs standalone via `injectGlobals`'s `Runtime.evaluate`\n * mechanism BEFORE the first bundle, rather than being prepended into\n * `rpc.ts#buildRunTestsExpression`. (Design choice documented in PR #739 —\n * bundle-prepend was the fallback plan if the SDK were only reachable from\n * inside bundle scope, which reality ruled out.)\n */\nconst PERMISSION_PROBE_MAP: Record<string, string> = {\n clipboardRead: 'getClipboardText',\n clipboardWrite: 'setClipboardText',\n album: 'fetchAlbumPhotos',\n camera: 'openCamera',\n contacts: 'fetchContacts',\n location: 'getCurrentLocation',\n};\n\n/**\n * Inter-probe spacing (ms) applied BEFORE every probe after the first\n * (devtools#767). The native per-method bridge rate limit observed\n * 2026-07-10 rejects a SECOND call to the same method within a short window\n * with `APP_BRIDGE_THROTTLED` — the permission preflight's un-paced burst\n * (6 probes fired back-to-back) was the FIRST trigger of that limiter in the\n * wild (only the first probe passed; the remaining 5 came back throttled →\n * `unavailable`, cascading into skipped `__AIT_PERMS__`-branching tests).\n * Sequential-with-spacing is cheap insurance even though each probe targets a\n * DIFFERENT method — the limiter's exact scope (per-method vs. a shared\n * bridge-wide window) was not reverse-engineered (explicitly out of scope,\n * devtools#767) so spacing every probe is the conservative choice.\n */\nconst PROBE_INTER_CALL_DELAY_MS = 250;\n\n/**\n * Backoff delays (ms) between retry attempts when a probe is throttled. Its\n * `.length` IS the max retry count (devtools#767: \"최대 2회 재시도\") — the\n * generated page-side expression below derives `attempt < backoff.length`\n * from this same array (via `backoffArray`), so there is a single source for\n * both the delay ladder and the retry count; no separate max-retries\n * constant is kept in this module (unlike `runtime.ts`'s `TEST_MAX_RETRIES`,\n * which IS consumed directly by a Node-side loop condition).\n */\nconst PROBE_RETRY_BACKOFF_MS = [500, 1000] as const;\n\n/**\n * Non-fatal bound for the permission preflight `Runtime.evaluate` round-trip\n * (devtools#767: raised from the pre-pacing 10s to cover the new sequential +\n * backoff time budget).\n *\n * Worst-case budget with 6 probes, each requiring the full retry ladder:\n * - inter-probe spacing: only BEFORE probes 2‑6 (none before the first) =\n * 5 × {@link PROBE_INTER_CALL_DELAY_MS} = 1 250ms\n * - per-probe backoff (both retries taken): 6 × (500 + 1000) = 9 000ms\n * - probe round-trips themselves (headroom, not just the sleeps): ~4 500ms\n * total ≈ 14 750ms, rounded up to a clean 20 000ms for headroom.\n */\nexport const PERMISSION_PREFLIGHT_TIMEOUT_MS = 20_000;\n\n/**\n * Builds the `Runtime.evaluate` expression for the permission-state preflight\n * (devtools#739). Evaluated ONCE per relay session, before the first test\n * bundle is injected (see `relay-worker.ts#runTestFilesOverRelay`).\n *\n * For each entry in {@link PERMISSION_PROBE_MAP}, probes\n * `window.__sdk.<fn>.getPermission()` — a NON-blocking query (never\n * `openPermissionDialog`/`requestPermission`, which open native UI) — and\n * assigns the resolved `'allowed'|'denied'|'notDetermined'` status to\n * `globalThis.__AIT_PERMS__[<key>]`. A probe that is absent, throws, or\n * rejects resolves to `'unavailable'` — this expression never throws to its\n * caller, and a single slow/broken permission must not fail the others (each\n * probe is awaited independently, not short-circuited).\n *\n * devtools#767: probes run SEQUENTIALLY (not a parallel burst) with a\n * {@link PROBE_INTER_CALL_DELAY_MS} gap before each probe after the first, and\n * a probe that comes back `APP_BRIDGE_THROTTLED` (native per-method bridge\n * rate limit) is retried up to {@link PROBE_RETRY_BACKOFF_MS}`.length` times\n * with the same {@link PROBE_RETRY_BACKOFF_MS} ladder before falling back to\n * `'unavailable'`.\n * The THROTTLED detection mirrors `throttle.ts#isThrottledError` inline (this\n * expression is raw JS text evaluated via CDP, not an esbuild-bundled module,\n * so it cannot statically `import` that helper) — kept in sync by checking\n * BOTH `e.code === 'APP_BRIDGE_THROTTLED'` and a message substring match, the\n * same two signals `isThrottledError` checks.\n *\n * devtools#767 acceptance criteria 2 (\"3.x run duration은 유의미하게 늘지 않음,\n * pacing은 opt-in 또는 throttle-adaptive\") requires this NOT be an unconditional\n * cost — `pace` (default `true`, matching the pre-existing sequential+spacing\n * behavior for 2.x/unknown cells) lets a 3.x caller skip BOTH the inter-probe\n * `sleep(250)` AND the retry backoff ladder, since `APP_BRIDGE_THROTTLED` is a\n * 2.x-bridge-only limiter (see `--pace`'s own doc in `cli.ts`: \"3.x cells are\n * unaffected by that limiter\"). When `pace` is `false`, probes still run\n * sequentially (never a parallel burst) but back-to-back with no added delay,\n * and a THROTTLED result resolves to `'unavailable'` immediately (no retry) —\n * this matches the 3.x runtime, which never emits `APP_BRIDGE_THROTTLED`.\n *\n * Tests (sdk-example#265) read `globalThis.__AIT_PERMS__` to branch\n * deterministically per permission state instead of blanket outcome-branching.\n *\n * Returns a JSON-serialised string (the same double-serialisation pattern\n * `rpc.ts#buildRunTestsExpression` uses) rather than relying on CDP\n * `returnByValue` structural fidelity for a plain object across the Chii\n * relay — the Node side re-parses via `JSON.parse`.\n *\n * Pure function — no I/O, no CDP call. Callers pass the returned string to\n * `Runtime.evaluate`.\n *\n * @param pace - Defaults to `true` (today's sequential+spacing+backoff\n * behavior). Pass `false` for a 3.x cell to skip the inter-probe delay and\n * the THROTTLED retry ladder entirely.\n */\nexport function buildPermissionPreflightExpression(pace = true): string {\n const probeKeys = Object.keys(PERMISSION_PROBE_MAP);\n const probeCalls = probeKeys\n .map((key, i) => {\n const fnName = PERMISSION_PROBE_MAP[key];\n // Every probe after the first waits PROBE_INTER_CALL_DELAY_MS first —\n // sequential execution with spacing, never a parallel burst. Skipped\n // entirely when `pace` is false (3.x cell — no native limiter to dodge).\n const spacing = i === 0 || !pace ? '' : ` await sleep(${PROBE_INTER_CALL_DELAY_MS});\\n`;\n return (\n `${spacing}` +\n ` result[${JSON.stringify(key)}] = await probeWithRetry(${JSON.stringify(fnName)});`\n );\n })\n .join('\\n');\n\n // 3.x cells never emit APP_BRIDGE_THROTTLED (it's a 2.x-bridge-only native\n // limiter) — an empty backoff ladder makes `probeWithRetry` resolve any\n // throw (throttled or not) to 'unavailable' on the FIRST attempt, with zero\n // retry sleeps, satisfying devtools#767 acceptance criteria 2.\n const backoffArray = pace ? `[${PROBE_RETRY_BACKOFF_MS.join(',')}]` : '[]';\n\n return (\n `(async () => {` +\n ` const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));` +\n ` const isThrottled = (e) => {` +\n ` if (!e) return false;` +\n ` if (e.code === ${JSON.stringify(THROTTLED_ERROR_CODE)}) return true;` +\n ` const msg = typeof e.message === 'string' ? e.message : '';` +\n ` return msg.indexOf(${JSON.stringify(THROTTLED_MESSAGE_SUBSTRING)}) !== -1;` +\n ` };` +\n ` const probe = async (fnName) => {` +\n ` const fn = globalThis.__sdk && globalThis.__sdk[fnName];` +\n ` if (!fn || typeof fn.getPermission !== 'function') return { ok: true, value: 'unavailable' };` +\n ` const status = await fn.getPermission();` +\n ` if (status === 'allowed' || status === 'denied' || status === 'notDetermined') return { ok: true, value: status };` +\n ` return { ok: true, value: 'unavailable' };` +\n ` };` +\n // probeWithRetry: up to PROBE_RETRY_BACKOFF_MS.length retries on THROTTLED,\n // backing off per PROBE_RETRY_BACKOFF_MS. Any OTHER throw (or a\n // non-throttled outcome) resolves to 'unavailable' immediately — only\n // THROTTLED gets a retry.\n ` const backoff = ${backoffArray};` +\n ` const probeWithRetry = async (fnName) => {` +\n ` for (let attempt = 0; attempt <= backoff.length; attempt++) {` +\n ` try {` +\n ` const r = await probe(fnName);` +\n ` return r.value;` +\n ` } catch (e) {` +\n ` if (isThrottled(e) && attempt < backoff.length) {` +\n ` await sleep(backoff[attempt]);` +\n ` continue;` +\n ` }` +\n ` return 'unavailable';` +\n ` }` +\n ` }` +\n ` return 'unavailable';` +\n ` };` +\n ` const result = {};` +\n `${probeCalls}\\n` +\n ` globalThis.__AIT_PERMS__ = result;` +\n ` return JSON.stringify(result);` +\n `})()`\n );\n}\n\n/**\n * Runs the permission-state preflight (devtools#739) via `Runtime.evaluate`\n * and returns the collected `__AIT_PERMS__` map, or `undefined` when the\n * preflight itself failed or timed out.\n *\n * NON-FATAL by design: any failure (CDP exception, timeout, page-side throw)\n * is caught here, logged as ONE stderr line, and swallowed — the whole test\n * run must proceed even when the preflight cannot complete (e.g. `window.__sdk`\n * not yet installed, or a page navigation mid-attach). Callers that want the\n * result for report provenance (`RelayRunReport.preflight`) get `undefined`\n * in that case, which downstream code treats the same as \"not run\".\n *\n * SECRET-HANDLING: no relay/wss/secret values are read or logged; only\n * permission-state strings cross this boundary.\n *\n * @param conn - The live CDP connection (relay-attached page).\n * @param timeoutMs - Round-trip bound. Defaults to {@link PERMISSION_PREFLIGHT_TIMEOUT_MS}.\n * @param pace - Forwarded to {@link buildPermissionPreflightExpression}.\n * Defaults to `true` (today's sequential+spacing+backoff behavior, correct\n * for 2.x/unknown cells). Callers that know the cell is 3.x should pass\n * `false` — devtools#767 acceptance criteria 2 requires 3.x run duration not\n * grow from this preflight, and 3.x never hits the 2.x-only\n * `APP_BRIDGE_THROTTLED` limiter this pacing exists to dodge.\n */\nexport async function runPermissionPreflight(\n conn: CdpConnection,\n timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS,\n pace = true,\n): Promise<Record<string, string> | undefined> {\n const TIMEOUT_SENTINEL = Symbol('permission-preflight-timeout');\n const timeoutPromise = new Promise<typeof TIMEOUT_SENTINEL>((resolve) =>\n setTimeout(() => resolve(TIMEOUT_SENTINEL), timeoutMs),\n );\n\n try {\n const evalPromise = conn.send('Runtime.evaluate', {\n expression: buildPermissionPreflightExpression(pace),\n returnByValue: true,\n awaitPromise: true,\n });\n\n const raceResult = await Promise.race([\n evalPromise.then((v) => ({ tag: 'eval' as const, v })),\n timeoutPromise.then(() => ({ tag: 'timeout' as const })),\n ]);\n\n if (raceResult.tag === 'timeout') {\n process.stderr.write(\n `test-runner: permission preflight timed out after ${timeoutMs}ms — proceeding with __AIT_PERMS__ unset\\n`,\n );\n return undefined;\n }\n\n if (raceResult.v.exceptionDetails) {\n process.stderr.write(\n 'test-runner: permission preflight threw — proceeding with __AIT_PERMS__ unset\\n',\n );\n return undefined;\n }\n\n const rawValue = raceResult.v.result.value;\n if (typeof rawValue !== 'string') return undefined;\n const parsed: unknown = JSON.parse(rawValue);\n if (typeof parsed !== 'object' || parsed === null) return undefined;\n return parsed as Record<string, string>;\n } catch (e) {\n process.stderr.write(\n `test-runner: permission preflight failed (${\n e instanceof Error ? e.message : String(e)\n }) — proceeding with __AIT_PERMS__ unset\\n`,\n );\n return undefined;\n }\n}\n\nimport { buildIndicatorExpression } from '../mcp/attach-orchestrator.js';\nimport type { CdpConnection } from '../mcp/cdp-connection.js';\n\n/**\n * Injects each key of `globals` into `globalThis` in the page via a single\n * `Runtime.evaluate` call. Must be called BEFORE the first `bundleTestFile`\n * inject — the cell is session-global and applies to all subsequent files.\n *\n * Throws if the CDP evaluate returns an exception.\n *\n * @param conn - The live CDP connection (relay-attached page).\n * @param globals - Plain-JSON-serialisable key→value map to assign onto `globalThis`.\n */\nexport async function injectGlobals(\n conn: CdpConnection,\n globals: Record<string, unknown>,\n): Promise<void> {\n // JSON.stringify is safe here: globals values are plain data (sdkLine/platform\n // strings or simple objects). If a value is not JSON-serialisable this throws\n // at call time, which surfaces the error early and clearly.\n const expr = `(() => { Object.assign(globalThis, ${JSON.stringify(globals)}); return true; })()`;\n const result = await conn.send('Runtime.evaluate', { expression: expr, returnByValue: true });\n if (result.exceptionDetails) {\n const msg =\n result.exceptionDetails.exception?.description ??\n result.exceptionDetails.text ??\n 'unknown error';\n throw new Error(`injectGlobals: Runtime.evaluate threw: ${msg}`);\n }\n}\n\n/**\n * Injects (or updates) the \"Debugger Connected\"/\"Debugger Disconnected\"\n * on-phone indicator via `Runtime.evaluate` (#730).\n *\n * Uses the same CDP mechanism as {@link injectGlobals} — a single\n * `Runtime.evaluate` round-trip with the expression built by\n * {@link buildIndicatorExpression}. The indicator is a LIVE badge rendered at\n * the bottom-left of the page (position:fixed, safe-area-aware): the badge's\n * controller is idempotent, so calling this again (e.g. right before\n * `close()` with `{ state: 'disconnected' }`) UPDATES the existing badge in\n * place instead of injecting a duplicate.\n *\n * **Isolation**: unlike {@link injectGlobals}, this function NEVER throws to\n * its caller. Injection failure (e.g. page detached during inject, CSS not\n * supported) is swallowed and logged as `console.debug` — the badge is\n * informational UI and must never block attach success or test execution.\n * This is the same fire-and-forget spirit as the in-page console mount in\n * `src/in-app/attach.ts`.\n *\n * Call this ONLY on the manual debug paths (start_attach MCP, devtools-test\n * CLI). Do NOT call on the `run_tests` auto-attach path — the badge\n * would contaminate screenshots, measure_safe_area probes, and DOM snapshots\n * taken during automated measurement runs.\n *\n * SECRET-HANDLING: the injected expression contains no secrets, relay URLs,\n * wss addresses, or TOTP codes — it is pure DOM UI text + enum state built by\n * {@link buildIndicatorExpression}.\n *\n * @param conn - The live CDP connection (relay-attached page).\n * @param opts - Optional overrides forwarded to {@link buildIndicatorExpression}.\n */\nexport async function injectDebugIndicator(\n conn: CdpConnection,\n opts?: { label?: string; disconnectedLabel?: string; state?: 'attached' | 'disconnected' },\n): Promise<void> {\n try {\n await conn.send('Runtime.evaluate', {\n expression: buildIndicatorExpression(opts),\n returnByValue: true,\n });\n } catch (err) {\n // Badge injection is informational UI — swallow and log; never propagate.\n console.debug('[@ait-co/devtools] debug indicator inject skipped:', err);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,uBAA+C;CACnD,eAAe;CACf,gBAAgB;CAChB,OAAO;CACP,QAAQ;CACR,UAAU;CACV,UAAU;CACX;;;;;;;;;;;;;;AAeD,MAAM,4BAA4B;;;;;;;;;;AAWlC,MAAM,yBAAyB,CAAC,KAAK,IAAK;;;;;;;;;;;;;AAc1C,MAAa,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsD/C,SAAgB,mCAAmC,OAAO,MAAc;CAEtE,MAAM,aADY,OAAO,KAAK,qBAAqB,CAEhD,KAAK,KAAK,MAAM;EACf,MAAM,SAAS,qBAAqB;AAKpC,SACE,GAFc,MAAM,KAAK,CAAC,OAAO,KAAK,mBAAmB,0BAA0B,MAAA,aAGrE,KAAK,UAAU,IAAI,CAAC,2BAA2B,KAAK,UAAU,OAAO,CAAC;GAEtF,CACD,KAAK,KAAK;CAMb,MAAM,eAAe,OAAO,IAAI,uBAAuB,KAAK,IAAI,CAAC,KAAK;AAEtE,QACE,qKAIsB,KAAK,UAAU,qBAAqB,CAAC,sGAEjC,KAAK,UAAU,4BAA4B,CAAC,qbAajD,aAAa,kaAiB/B,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BlB,eAAsB,uBACpB,MACA,YAAY,iCACZ,OAAO,MACsC;CAC7C,MAAM,mBAAmB,OAAO,+BAA+B;CAC/D,MAAM,iBAAiB,IAAI,SAAkC,YAC3D,iBAAiB,QAAQ,iBAAiB,EAAE,UAAU,CACvD;AAED,KAAI;EACF,MAAM,cAAc,KAAK,KAAK,oBAAoB;GAChD,YAAY,mCAAmC,KAAK;GACpD,eAAe;GACf,cAAc;GACf,CAAC;EAEF,MAAM,aAAa,MAAM,QAAQ,KAAK,CACpC,YAAY,MAAM,OAAO;GAAE,KAAK;GAAiB;GAAG,EAAE,EACtD,eAAe,YAAY,EAAE,KAAK,WAAoB,EAAE,CACzD,CAAC;AAEF,MAAI,WAAW,QAAQ,WAAW;AAChC,WAAQ,OAAO,MACb,qDAAqD,UAAU,4CAChE;AACD;;AAGF,MAAI,WAAW,EAAE,kBAAkB;AACjC,WAAQ,OAAO,MACb,kFACD;AACD;;EAGF,MAAM,WAAW,WAAW,EAAE,OAAO;AACrC,MAAI,OAAO,aAAa,SAAU,QAAO,KAAA;EACzC,MAAM,SAAkB,KAAK,MAAM,SAAS;AAC5C,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO,KAAA;AAC1D,SAAO;UACA,GAAG;AACV,UAAQ,OAAO,MACb,6CACE,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAC3C,2CACF;AACD;;;;;;;;;;;;;AAiBJ,eAAsB,cACpB,MACA,SACe;CAIf,MAAM,OAAO,sCAAsC,KAAK,UAAU,QAAQ,CAAC;CAC3E,MAAM,SAAS,MAAM,KAAK,KAAK,oBAAoB;EAAE,YAAY;EAAM,eAAe;EAAM,CAAC;AAC7F,KAAI,OAAO,kBAAkB;EAC3B,MAAM,MACJ,OAAO,iBAAiB,WAAW,eACnC,OAAO,iBAAiB,QACxB;AACF,QAAM,IAAI,MAAM,0CAA0C,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCpE,eAAsB,qBACpB,MACA,MACe;AACf,KAAI;AACF,QAAM,KAAK,KAAK,oBAAoB;GAClC,YAAY,yBAAyB,KAAK;GAC1C,eAAe;GAChB,CAAC;UACK,KAAK;AAEZ,UAAQ,MAAM,sDAAsD,IAAI"}
@@ -1,307 +0,0 @@
1
- #!/usr/bin/env node
2
- import { t as __exportAll } from "./rolldown-runtime-DGkTqVfb.js";
3
- import { a as buildIndicatorExpression } from "./attach-orchestrator-DL3NQ9ca.js";
4
- //#region src/test-runner/throttle.ts
5
- /**
6
- * Shared `APP_BRIDGE_THROTTLED` detection (devtools#767).
7
- *
8
- * 2026-07-10 real-device observation: the Toss app native side added a
9
- * per-method rate limit to the 2.x bridge — calling the SAME bridge method
10
- * twice within a short window rejects the second call immediately with a
11
- * 2.x native envelope (`{name, code, userInfo, moduleName, __isError}`) whose
12
- * `code` is `'APP_BRIDGE_THROTTLED'` and whose `message` reads
13
- * `"Too many app bridge calls from <method>."`. The 3.x bridge path is
14
- * unaffected (devtools#767 issue body, sdk-example#284 2026-07-10 comment).
15
- *
16
- * This module is the SINGLE source of the detection predicate. Today's only
17
- * consumer is `runtime.ts` (in-page, per-test retry loop) — a plain static
18
- * import; esbuild inlines this file into the same IIFE bundle (same
19
- * mechanism as `bridge-stub.ts`, see `bundle.ts#getPageSideModulePath`). It
20
- * is exported from this standalone, dependency-free module (rather than
21
- * defined inline in `runtime.ts`) so a Node-side consumer could import the
22
- * exact same predicate in future if whole-FILE throttle-aware retry is ever
23
- * added on top of the per-test retry `runtime.ts` already performs — no such
24
- * Node-side caller exists yet (whole-file retry today only triggers on an
25
- * `injectAndRunBundle`-level timeout/exception, a distinct failure mode from
26
- * a `RunReport` that completed normally but contains a THROTTLED-failed
27
- * test — see `relay-worker.ts`'s `EVALUATE_TIMEOUT_MARKER` gate).
28
- *
29
- * Browser-compatible, dependency-free (no Node APIs) — safe to import from
30
- * either side of the CDP boundary, mirroring `runtime.ts`'s own constraint.
31
- */
32
- /** The native error code the Toss app bridge returns when rate-limited. */
33
- const THROTTLED_ERROR_CODE = "APP_BRIDGE_THROTTLED";
34
- /** The message substring the native envelope carries when rate-limited. */
35
- const THROTTLED_MESSAGE_SUBSTRING = "Too many app bridge calls";
36
- //#endregion
37
- //#region src/test-runner/cell.ts
38
- /**
39
- * Cell injection utility for the `devtools-test` CLI (issue #684 §4.1).
40
- *
41
- * Injects arbitrary globals into the page via `Runtime.evaluate` BEFORE the
42
- * first test bundle is injected. The injected values are session-global — one
43
- * call covers all files in the run.
44
- *
45
- * The primary use-case is injecting `__AIT_CELL__` (sdkLine/platform) so
46
- * sdk-example's `aitCapture.ts` picks up the correct test-axis values instead
47
- * of falling back to `'2.x'`/`'mock'`.
48
- *
49
- * devtools does NOT know the shape of `__AIT_CELL__` — it only provides the
50
- * general injection mechanism. The caller (CLI or MCP auto-attach path) is
51
- * responsible for constructing the cell object.
52
- *
53
- * SECRET-HANDLING: cell values (sdkLine/platform) are not secrets and may be
54
- * logged at the caller's discretion. This module does NOT log them itself.
55
- *
56
- * Node-only. react-free. CdpConnection only.
57
- */
58
- var cell_exports = /* @__PURE__ */ __exportAll({
59
- PERMISSION_PREFLIGHT_TIMEOUT_MS: () => PERMISSION_PREFLIGHT_TIMEOUT_MS,
60
- buildPermissionPreflightExpression: () => buildPermissionPreflightExpression,
61
- injectDebugIndicator: () => injectDebugIndicator,
62
- injectGlobals: () => injectGlobals,
63
- runPermissionPreflight: () => runPermissionPreflight
64
- });
65
- /**
66
- * `__AIT_PERMS__` key → SDK function name whose `.getPermission()` is probed
67
- * (devtools#739). This is the exact contract sdk-example#265 consumes — do
68
- * not rename keys without a coordinated sdk-example update.
69
- *
70
- * Each SDK function is reached via `window.__sdk` — the SAME page-global
71
- * bridge `src/in-app/auto.ts` installs for `call_sdk`/`__sdkCall` (see
72
- * `src/test-runner/bundle.ts`'s `sdkRedirectPlugin`, which redirects bundled
73
- * `@apps-in-toss/web-framework` imports to this same object at runtime). The
74
- * test-runner bundle owns no independent SDK import — `window.__sdk` is a
75
- * page global regardless of whether a bundle has been injected yet, so this
76
- * preflight runs standalone via `injectGlobals`'s `Runtime.evaluate`
77
- * mechanism BEFORE the first bundle, rather than being prepended into
78
- * `rpc.ts#buildRunTestsExpression`. (Design choice documented in PR #739 —
79
- * bundle-prepend was the fallback plan if the SDK were only reachable from
80
- * inside bundle scope, which reality ruled out.)
81
- */
82
- const PERMISSION_PROBE_MAP = {
83
- clipboardRead: "getClipboardText",
84
- clipboardWrite: "setClipboardText",
85
- album: "fetchAlbumPhotos",
86
- camera: "openCamera",
87
- contacts: "fetchContacts",
88
- location: "getCurrentLocation"
89
- };
90
- /**
91
- * Inter-probe spacing (ms) applied BEFORE every probe after the first
92
- * (devtools#767). The native per-method bridge rate limit observed
93
- * 2026-07-10 rejects a SECOND call to the same method within a short window
94
- * with `APP_BRIDGE_THROTTLED` — the permission preflight's un-paced burst
95
- * (6 probes fired back-to-back) was the FIRST trigger of that limiter in the
96
- * wild (only the first probe passed; the remaining 5 came back throttled →
97
- * `unavailable`, cascading into skipped `__AIT_PERMS__`-branching tests).
98
- * Sequential-with-spacing is cheap insurance even though each probe targets a
99
- * DIFFERENT method — the limiter's exact scope (per-method vs. a shared
100
- * bridge-wide window) was not reverse-engineered (explicitly out of scope,
101
- * devtools#767) so spacing every probe is the conservative choice.
102
- */
103
- const PROBE_INTER_CALL_DELAY_MS = 250;
104
- /**
105
- * Backoff delays (ms) between retry attempts when a probe is throttled. Its
106
- * `.length` IS the max retry count (devtools#767: "최대 2회 재시도") — the
107
- * generated page-side expression below derives `attempt < backoff.length`
108
- * from this same array (via `backoffArray`), so there is a single source for
109
- * both the delay ladder and the retry count; no separate max-retries
110
- * constant is kept in this module (unlike `runtime.ts`'s `TEST_MAX_RETRIES`,
111
- * which IS consumed directly by a Node-side loop condition).
112
- */
113
- const PROBE_RETRY_BACKOFF_MS = [500, 1e3];
114
- /**
115
- * Non-fatal bound for the permission preflight `Runtime.evaluate` round-trip
116
- * (devtools#767: raised from the pre-pacing 10s to cover the new sequential +
117
- * backoff time budget).
118
- *
119
- * Worst-case budget with 6 probes, each requiring the full retry ladder:
120
- * - inter-probe spacing: only BEFORE probes 2‑6 (none before the first) =
121
- * 5 × {@link PROBE_INTER_CALL_DELAY_MS} = 1 250ms
122
- * - per-probe backoff (both retries taken): 6 × (500 + 1000) = 9 000ms
123
- * - probe round-trips themselves (headroom, not just the sleeps): ~4 500ms
124
- * total ≈ 14 750ms, rounded up to a clean 20 000ms for headroom.
125
- */
126
- const PERMISSION_PREFLIGHT_TIMEOUT_MS = 2e4;
127
- /**
128
- * Builds the `Runtime.evaluate` expression for the permission-state preflight
129
- * (devtools#739). Evaluated ONCE per relay session, before the first test
130
- * bundle is injected (see `relay-worker.ts#runTestFilesOverRelay`).
131
- *
132
- * For each entry in {@link PERMISSION_PROBE_MAP}, probes
133
- * `window.__sdk.<fn>.getPermission()` — a NON-blocking query (never
134
- * `openPermissionDialog`/`requestPermission`, which open native UI) — and
135
- * assigns the resolved `'allowed'|'denied'|'notDetermined'` status to
136
- * `globalThis.__AIT_PERMS__[<key>]`. A probe that is absent, throws, or
137
- * rejects resolves to `'unavailable'` — this expression never throws to its
138
- * caller, and a single slow/broken permission must not fail the others (each
139
- * probe is awaited independently, not short-circuited).
140
- *
141
- * devtools#767: probes run SEQUENTIALLY (not a parallel burst) with a
142
- * {@link PROBE_INTER_CALL_DELAY_MS} gap before each probe after the first, and
143
- * a probe that comes back `APP_BRIDGE_THROTTLED` (native per-method bridge
144
- * rate limit) is retried up to {@link PROBE_RETRY_BACKOFF_MS}`.length` times
145
- * with the same {@link PROBE_RETRY_BACKOFF_MS} ladder before falling back to
146
- * `'unavailable'`.
147
- * The THROTTLED detection mirrors `throttle.ts#isThrottledError` inline (this
148
- * expression is raw JS text evaluated via CDP, not an esbuild-bundled module,
149
- * so it cannot statically `import` that helper) — kept in sync by checking
150
- * BOTH `e.code === 'APP_BRIDGE_THROTTLED'` and a message substring match, the
151
- * same two signals `isThrottledError` checks.
152
- *
153
- * devtools#767 acceptance criteria 2 ("3.x run duration은 유의미하게 늘지 않음,
154
- * pacing은 opt-in 또는 throttle-adaptive") requires this NOT be an unconditional
155
- * cost — `pace` (default `true`, matching the pre-existing sequential+spacing
156
- * behavior for 2.x/unknown cells) lets a 3.x caller skip BOTH the inter-probe
157
- * `sleep(250)` AND the retry backoff ladder, since `APP_BRIDGE_THROTTLED` is a
158
- * 2.x-bridge-only limiter (see `--pace`'s own doc in `cli.ts`: "3.x cells are
159
- * unaffected by that limiter"). When `pace` is `false`, probes still run
160
- * sequentially (never a parallel burst) but back-to-back with no added delay,
161
- * and a THROTTLED result resolves to `'unavailable'` immediately (no retry) —
162
- * this matches the 3.x runtime, which never emits `APP_BRIDGE_THROTTLED`.
163
- *
164
- * Tests (sdk-example#265) read `globalThis.__AIT_PERMS__` to branch
165
- * deterministically per permission state instead of blanket outcome-branching.
166
- *
167
- * Returns a JSON-serialised string (the same double-serialisation pattern
168
- * `rpc.ts#buildRunTestsExpression` uses) rather than relying on CDP
169
- * `returnByValue` structural fidelity for a plain object across the Chii
170
- * relay — the Node side re-parses via `JSON.parse`.
171
- *
172
- * Pure function — no I/O, no CDP call. Callers pass the returned string to
173
- * `Runtime.evaluate`.
174
- *
175
- * @param pace - Defaults to `true` (today's sequential+spacing+backoff
176
- * behavior). Pass `false` for a 3.x cell to skip the inter-probe delay and
177
- * the THROTTLED retry ladder entirely.
178
- */
179
- function buildPermissionPreflightExpression(pace = true) {
180
- const probeCalls = Object.keys(PERMISSION_PROBE_MAP).map((key, i) => {
181
- const fnName = PERMISSION_PROBE_MAP[key];
182
- return `${i === 0 || !pace ? "" : ` await sleep(${PROBE_INTER_CALL_DELAY_MS});\n`} result[${JSON.stringify(key)}] = await probeWithRetry(${JSON.stringify(fnName)});`;
183
- }).join("\n");
184
- const backoffArray = pace ? `[${PROBE_RETRY_BACKOFF_MS.join(",")}]` : "[]";
185
- return `(async () => { const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const isThrottled = (e) => { if (!e) return false; if (e.code === ${JSON.stringify(THROTTLED_ERROR_CODE)}) return true; const msg = typeof e.message === 'string' ? e.message : ''; return msg.indexOf(${JSON.stringify(THROTTLED_MESSAGE_SUBSTRING)}) !== -1; }; const probe = async (fnName) => { const fn = globalThis.__sdk && globalThis.__sdk[fnName]; if (!fn || typeof fn.getPermission !== 'function') return { ok: true, value: 'unavailable' }; const status = await fn.getPermission(); if (status === 'allowed' || status === 'denied' || status === 'notDetermined') return { ok: true, value: status }; return { ok: true, value: 'unavailable' }; }; const backoff = ${backoffArray}; const probeWithRetry = async (fnName) => { for (let attempt = 0; attempt <= backoff.length; attempt++) { try { const r = await probe(fnName); return r.value; } catch (e) { if (isThrottled(e) && attempt < backoff.length) { await sleep(backoff[attempt]); continue; } return 'unavailable'; } } return 'unavailable'; }; const result = {};${probeCalls}\n globalThis.__AIT_PERMS__ = result; return JSON.stringify(result);})()`;
186
- }
187
- /**
188
- * Runs the permission-state preflight (devtools#739) via `Runtime.evaluate`
189
- * and returns the collected `__AIT_PERMS__` map, or `undefined` when the
190
- * preflight itself failed or timed out.
191
- *
192
- * NON-FATAL by design: any failure (CDP exception, timeout, page-side throw)
193
- * is caught here, logged as ONE stderr line, and swallowed — the whole test
194
- * run must proceed even when the preflight cannot complete (e.g. `window.__sdk`
195
- * not yet installed, or a page navigation mid-attach). Callers that want the
196
- * result for report provenance (`RelayRunReport.preflight`) get `undefined`
197
- * in that case, which downstream code treats the same as "not run".
198
- *
199
- * SECRET-HANDLING: no relay/wss/secret values are read or logged; only
200
- * permission-state strings cross this boundary.
201
- *
202
- * @param conn - The live CDP connection (relay-attached page).
203
- * @param timeoutMs - Round-trip bound. Defaults to {@link PERMISSION_PREFLIGHT_TIMEOUT_MS}.
204
- * @param pace - Forwarded to {@link buildPermissionPreflightExpression}.
205
- * Defaults to `true` (today's sequential+spacing+backoff behavior, correct
206
- * for 2.x/unknown cells). Callers that know the cell is 3.x should pass
207
- * `false` — devtools#767 acceptance criteria 2 requires 3.x run duration not
208
- * grow from this preflight, and 3.x never hits the 2.x-only
209
- * `APP_BRIDGE_THROTTLED` limiter this pacing exists to dodge.
210
- */
211
- async function runPermissionPreflight(conn, timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS, pace = true) {
212
- const TIMEOUT_SENTINEL = Symbol("permission-preflight-timeout");
213
- const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(TIMEOUT_SENTINEL), timeoutMs));
214
- try {
215
- const evalPromise = conn.send("Runtime.evaluate", {
216
- expression: buildPermissionPreflightExpression(pace),
217
- returnByValue: true,
218
- awaitPromise: true
219
- });
220
- const raceResult = await Promise.race([evalPromise.then((v) => ({
221
- tag: "eval",
222
- v
223
- })), timeoutPromise.then(() => ({ tag: "timeout" }))]);
224
- if (raceResult.tag === "timeout") {
225
- process.stderr.write(`test-runner: permission preflight timed out after ${timeoutMs}ms — proceeding with __AIT_PERMS__ unset\n`);
226
- return;
227
- }
228
- if (raceResult.v.exceptionDetails) {
229
- process.stderr.write("test-runner: permission preflight threw — proceeding with __AIT_PERMS__ unset\n");
230
- return;
231
- }
232
- const rawValue = raceResult.v.result.value;
233
- if (typeof rawValue !== "string") return void 0;
234
- const parsed = JSON.parse(rawValue);
235
- if (typeof parsed !== "object" || parsed === null) return void 0;
236
- return parsed;
237
- } catch (e) {
238
- process.stderr.write(`test-runner: permission preflight failed (${e instanceof Error ? e.message : String(e)}) — proceeding with __AIT_PERMS__ unset\n`);
239
- return;
240
- }
241
- }
242
- /**
243
- * Injects each key of `globals` into `globalThis` in the page via a single
244
- * `Runtime.evaluate` call. Must be called BEFORE the first `bundleTestFile`
245
- * inject — the cell is session-global and applies to all subsequent files.
246
- *
247
- * Throws if the CDP evaluate returns an exception.
248
- *
249
- * @param conn - The live CDP connection (relay-attached page).
250
- * @param globals - Plain-JSON-serialisable key→value map to assign onto `globalThis`.
251
- */
252
- async function injectGlobals(conn, globals) {
253
- const expr = `(() => { Object.assign(globalThis, ${JSON.stringify(globals)}); return true; })()`;
254
- const result = await conn.send("Runtime.evaluate", {
255
- expression: expr,
256
- returnByValue: true
257
- });
258
- if (result.exceptionDetails) {
259
- const msg = result.exceptionDetails.exception?.description ?? result.exceptionDetails.text ?? "unknown error";
260
- throw new Error(`injectGlobals: Runtime.evaluate threw: ${msg}`);
261
- }
262
- }
263
- /**
264
- * Injects (or updates) the "Debugger Connected"/"Debugger Disconnected"
265
- * on-phone indicator via `Runtime.evaluate` (#730).
266
- *
267
- * Uses the same CDP mechanism as {@link injectGlobals} — a single
268
- * `Runtime.evaluate` round-trip with the expression built by
269
- * {@link buildIndicatorExpression}. The indicator is a LIVE badge rendered at
270
- * the bottom-left of the page (position:fixed, safe-area-aware): the badge's
271
- * controller is idempotent, so calling this again (e.g. right before
272
- * `close()` with `{ state: 'disconnected' }`) UPDATES the existing badge in
273
- * place instead of injecting a duplicate.
274
- *
275
- * **Isolation**: unlike {@link injectGlobals}, this function NEVER throws to
276
- * its caller. Injection failure (e.g. page detached during inject, CSS not
277
- * supported) is swallowed and logged as `console.debug` — the badge is
278
- * informational UI and must never block attach success or test execution.
279
- * This is the same fire-and-forget spirit as the in-page console mount in
280
- * `src/in-app/attach.ts`.
281
- *
282
- * Call this ONLY on the manual debug paths (start_attach MCP, devtools-test
283
- * CLI). Do NOT call on the `run_tests` auto-attach path — the badge
284
- * would contaminate screenshots, measure_safe_area probes, and DOM snapshots
285
- * taken during automated measurement runs.
286
- *
287
- * SECRET-HANDLING: the injected expression contains no secrets, relay URLs,
288
- * wss addresses, or TOTP codes — it is pure DOM UI text + enum state built by
289
- * {@link buildIndicatorExpression}.
290
- *
291
- * @param conn - The live CDP connection (relay-attached page).
292
- * @param opts - Optional overrides forwarded to {@link buildIndicatorExpression}.
293
- */
294
- async function injectDebugIndicator(conn, opts) {
295
- try {
296
- await conn.send("Runtime.evaluate", {
297
- expression: buildIndicatorExpression(opts),
298
- returnByValue: true
299
- });
300
- } catch (err) {
301
- console.debug("[@ait-co/devtools] debug indicator inject skipped:", err);
302
- }
303
- }
304
- //#endregion
305
- export { cell_exports as n, runPermissionPreflight as r, PERMISSION_PREFLIGHT_TIMEOUT_MS as t };
306
-
307
- //# sourceMappingURL=cell-EBKKpAAT.js.map