@ait-co/devtools 0.1.137 → 0.1.138
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.
- package/dist/{attach-orchestrator-Cjdhir2U.js → attach-orchestrator-6kz_ZdWL.js} +5 -3
- package/dist/{attach-orchestrator-Cjdhir2U.js.map → attach-orchestrator-6kz_ZdWL.js.map} +1 -1
- package/dist/{attach-orchestrator-CE0S09YU.js → attach-orchestrator-BEiz3wAx.js} +5 -3
- package/dist/{attach-orchestrator-CMoDuG2A.js.map → attach-orchestrator-BEiz3wAx.js.map} +1 -1
- package/dist/{attach-orchestrator-CMoDuG2A.js → attach-orchestrator-BG8TGJOZ.js} +5 -3
- package/dist/{attach-orchestrator-CE0S09YU.js.map → attach-orchestrator-BG8TGJOZ.js.map} +1 -1
- package/dist/{bundle-BKqyhEK9.d.ts → bundle-C796JIwG.d.ts} +65 -2
- package/dist/bundle-C796JIwG.d.ts.map +1 -0
- package/dist/{capture-ltuV0gZa.d.ts → capture-DsP525OZ.d.ts} +1 -1
- package/dist/{capture-ltuV0gZa.d.ts.map → capture-DsP525OZ.d.ts.map} +1 -1
- package/dist/{cdp-connection-BYE9meXe.d.ts → cdp-connection-rP1WdnH5.d.ts} +1 -1
- package/dist/{cdp-connection-BYE9meXe.d.ts.map → cdp-connection-rP1WdnH5.d.ts.map} +1 -1
- package/dist/{cell-D1y4shoV.js → cell-BMlFh08P.js} +2 -2
- package/dist/cell-BMlFh08P.js.map +1 -0
- package/dist/{cell-DHA578lX.js → cell-Dtgtusog.js} +90 -16
- package/dist/cell-Dtgtusog.js.map +1 -0
- package/dist/{cell-BIdSQb9T.js → cell-KsRXFdDs.js} +122 -16
- package/dist/cell-KsRXFdDs.js.map +1 -0
- package/dist/{debug-server-CBK7dn8O.js → debug-server-6c22qSWa.js} +132 -9
- package/dist/debug-server-6c22qSWa.js.map +1 -0
- package/dist/{debug-server-BQplCzf8.js → debug-server-BQHbaKPT.js} +134 -11
- package/dist/debug-server-BQHbaKPT.js.map +1 -0
- package/dist/{debug-server-D2wpPK3_.js → debug-server-DWat7d-9.js} +82 -6
- package/dist/debug-server-DWat7d-9.js.map +1 -0
- package/dist/devtools-opener-3Drge_RJ.js +75 -0
- package/dist/devtools-opener-3Drge_RJ.js.map +1 -0
- package/dist/devtools-opener-CJpEsXXQ.js +76 -0
- package/dist/devtools-opener-CJpEsXXQ.js.map +1 -0
- package/dist/devtools-opener-CxtryS8c.js +75 -0
- package/dist/devtools-opener-CxtryS8c.js.map +1 -0
- package/dist/in-app/auto.js +59 -12
- package/dist/in-app/auto.js.map +1 -1
- package/dist/in-app/index.d.ts +21 -2
- package/dist/in-app/index.d.ts.map +1 -1
- package/dist/in-app/index.js +60 -13
- package/dist/in-app/index.js.map +1 -1
- package/dist/mcp/cli.js +299 -60
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/mock/index.d.ts +64 -1
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +221 -14
- package/dist/mock/index.js.map +1 -1
- package/dist/panel/index.js +178 -23
- package/dist/panel/index.js.map +1 -1
- package/dist/{pool-CmfvXnwh.d.ts → pool-CrP5CPvU.d.ts} +3 -3
- package/dist/{pool-CmfvXnwh.d.ts.map → pool-CrP5CPvU.d.ts.map} +1 -1
- package/dist/{qr-http-server-ZkT6F7is.js → qr-http-server-D1hpoyBF.js} +1 -1
- package/dist/{qr-http-server-ZkT6F7is.js.map → qr-http-server-D1hpoyBF.js.map} +1 -1
- package/dist/qr-http-server-D4rGz8M7.js +1640 -0
- package/dist/qr-http-server-D4rGz8M7.js.map +1 -0
- package/dist/{qr-http-server-C7q8Gn04.js → qr-http-server-DIjCV7h_.js} +1 -1
- package/dist/{qr-http-server-C7q8Gn04.js.map → qr-http-server-DIjCV7h_.js.map} +1 -1
- package/dist/{relay-factory-DVzpBRxz.js → relay-factory-C1X3G3WY.js} +71 -15
- package/dist/relay-factory-C1X3G3WY.js.map +1 -0
- package/dist/{relay-secret-store-CLEGyHou.js → relay-secret-store-Bmyleu0A.js} +1 -1
- package/dist/{relay-secret-store-CLEGyHou.js.map → relay-secret-store-Bmyleu0A.js.map} +1 -1
- package/dist/{relay-secret-store-DhzAnnj-.js → relay-secret-store-CQenfcSL.js} +2 -2
- package/dist/{relay-secret-store-DhzAnnj-.js.map → relay-secret-store-CQenfcSL.js.map} +1 -1
- package/dist/{relay-secret-store-BcVrWwTq.js → relay-secret-store-DKxs7zwq.js} +1 -1
- package/dist/{relay-secret-store-BcVrWwTq.js.map → relay-secret-store-DKxs7zwq.js.map} +1 -1
- package/dist/{relay-secret-store-DGduVJhs.js → relay-secret-store-WJ8EGkIl.js} +1 -1
- package/dist/{relay-secret-store-DGduVJhs.js.map → relay-secret-store-WJ8EGkIl.js.map} +1 -1
- package/dist/{relay-url-store-CKW8RQzf.js → relay-url-store-BR2XodiO.js} +2 -2
- package/dist/{relay-url-store-CKW8RQzf.js.map → relay-url-store-BR2XodiO.js.map} +1 -1
- package/dist/{relay-url-store-CdA58fgw.js → relay-url-store-CH63fVCm.js} +2 -2
- package/dist/{relay-url-store-B0X8TsGr.js.map → relay-url-store-CH63fVCm.js.map} +1 -1
- package/dist/{relay-url-store-CwKT7i04.js → relay-url-store-DaY1QPes.js} +2 -2
- package/dist/{relay-url-store-CwKT7i04.js.map → relay-url-store-DaY1QPes.js.map} +1 -1
- package/dist/{relay-url-store-B0X8TsGr.js → relay-url-store-xmUuTjXA.js} +2 -2
- package/dist/{relay-url-store-CdA58fgw.js.map → relay-url-store-xmUuTjXA.js.map} +1 -1
- package/dist/{relay-worker-6fy1eaIo.js → relay-worker-BUXI0K0b.js} +8 -4
- package/dist/{relay-worker-6fy1eaIo.js.map → relay-worker-BUXI0K0b.js.map} +1 -1
- package/dist/{relay-worker-DJnZkXza.d.ts → relay-worker-DcyboK43.d.ts} +30 -5
- package/dist/relay-worker-DcyboK43.d.ts.map +1 -0
- package/dist/{runtime-DfHHZms2.d.ts → runtime-BiigOuvb.d.ts} +30 -3
- package/dist/runtime-BiigOuvb.d.ts.map +1 -0
- package/dist/test-runner/bin.js +376 -38
- package/dist/test-runner/bin.js.map +1 -1
- package/dist/test-runner/bundle.d.ts +2 -2
- package/dist/test-runner/bundle.js +66 -13
- package/dist/test-runner/bundle.js.map +1 -1
- package/dist/test-runner/capture.d.ts +1 -1
- package/dist/test-runner/config.d.ts +58 -5
- package/dist/test-runner/config.d.ts.map +1 -1
- package/dist/test-runner/config.js +1 -1
- package/dist/test-runner/method-pace.d.ts +82 -0
- package/dist/test-runner/method-pace.d.ts.map +1 -0
- package/dist/test-runner/method-pace.js +120 -0
- package/dist/test-runner/method-pace.js.map +1 -0
- package/dist/test-runner/pool.d.ts +1 -1
- package/dist/test-runner/pool.js +1 -1
- package/dist/test-runner/relay-factory.d.ts +57 -4
- package/dist/test-runner/relay-factory.d.ts.map +1 -1
- package/dist/test-runner/relay-factory.js +70 -14
- package/dist/test-runner/relay-factory.js.map +1 -1
- package/dist/test-runner/relay-worker.d.ts +1 -1
- package/dist/test-runner/relay-worker.js +1 -1
- package/dist/test-runner/report.d.ts +3 -3
- package/dist/test-runner/rpc.d.ts +2 -2
- package/dist/test-runner/runtime.d.ts +2 -2
- package/dist/test-runner/runtime.js +83 -6
- package/dist/test-runner/runtime.js.map +1 -1
- package/dist/test-runner/task-graph.d.ts +1 -1
- package/dist/throttle-DKKzX1qC.js +59 -0
- package/dist/throttle-DKKzX1qC.js.map +1 -0
- package/dist/totp-Dwft0Kz7.js +3 -0
- package/package.json +1 -1
- package/dist/bundle-BKqyhEK9.d.ts.map +0 -1
- package/dist/cell-BIdSQb9T.js.map +0 -1
- package/dist/cell-D1y4shoV.js.map +0 -1
- package/dist/cell-DHA578lX.js.map +0 -1
- package/dist/debug-server-BQplCzf8.js.map +0 -1
- package/dist/debug-server-CBK7dn8O.js.map +0 -1
- package/dist/debug-server-D2wpPK3_.js.map +0 -1
- package/dist/relay-factory-DVzpBRxz.js.map +0 -1
- package/dist/relay-worker-DJnZkXza.d.ts.map +0 -1
- package/dist/runtime-DfHHZms2.d.ts.map +0 -1
- package/dist/totp-D1pulXLa.js +0 -3
|
@@ -76,6 +76,69 @@ interface BundleResult {
|
|
|
76
76
|
code: string;
|
|
77
77
|
warnings: string[];
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* esbuild plugin that intercepts SDK imports and redirects them to the
|
|
81
|
+
* `window.__sdk` proxy that `src/in-app/auto.ts` installs at runtime.
|
|
82
|
+
*
|
|
83
|
+
* Strategy: for every import of `@apps-in-toss/web-framework` (or sub-paths),
|
|
84
|
+
* esbuild resolves it to a virtual module that re-exports all named exports
|
|
85
|
+
* via `window.__sdk[name]`. This avoids bundling the real SDK (which may not
|
|
86
|
+
* be available in the test environment) while still making named imports work.
|
|
87
|
+
*
|
|
88
|
+
* If `window.__sdk` is absent (non-dog-food build), every access throws a
|
|
89
|
+
* descriptive error rather than returning `undefined` silently.
|
|
90
|
+
*
|
|
91
|
+
* Bridge-stub interception (devtools#740, DT-2): the virtual module runs the
|
|
92
|
+
* resolved `window.__sdk` object through `wrapSdkWithStub` before exporting
|
|
93
|
+
* it. `wrapSdkWithStub` is a pass-through (returns the same object,
|
|
94
|
+
* unwrapped) unless `isStubBlockingEnabled()` reads `true` off
|
|
95
|
+
* `globalThis.__AIT_STUB_BLOCKING__` — an opt-in flag injected the same way
|
|
96
|
+
* `__AIT_CELL__` is (`cell.ts#injectGlobals`, wired from the CLI's
|
|
97
|
+
* `--stub-blocking` flag). Default off => zero behavior change: every existing
|
|
98
|
+
* (non-stub) test run resolves the exact same `window.__sdk` reference it did
|
|
99
|
+
* before this plugin learned about stubbing.
|
|
100
|
+
*
|
|
101
|
+
* Per-method pacing (devtools#769): BEFORE the stub wrap, `window.__sdk` is
|
|
102
|
+
* run through `wrapWithMethodPacing`, which enforces a minimum interval
|
|
103
|
+
* between calls to the SAME named SDK function (`getPaceMethodMs()` reads the
|
|
104
|
+
* `__AIT_PACE_METHOD_MS__` page global — see `method-pace.ts`). Composition
|
|
105
|
+
* order is pacing INSIDE the stub (`wrapSdkWithStub(wrapWithMethodPacing(sdk,
|
|
106
|
+
* gap), enabled)`): a stubbed name resolves instantly from
|
|
107
|
+
* `bridge-stub.ts`'s fixtures without ever reaching the paced wrapper, and
|
|
108
|
+
* only calls that fall through to the real bridge — the ones that can
|
|
109
|
+
* actually trigger `APP_BRIDGE_THROTTLED` — pay the pacing cost. `gapMs <= 0`
|
|
110
|
+
* (default, no `--pace-method` / non-2.x cell) is a no-op fast path — see
|
|
111
|
+
* `method-pace.ts#wrapWithMethodPacing`'s doc for the full contract.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Builds the virtual CommonJS-style module contents the `sdk-redirect`
|
|
115
|
+
* esbuild plugin loads for every `@apps-in-toss/web-framework` import.
|
|
116
|
+
*
|
|
117
|
+
* Pulled out to a pure, exported function (rather than inlined at the
|
|
118
|
+
* `build.onLoad` call site) so unit tests can assert the exact composition
|
|
119
|
+
* order (pacing wraps the raw SDK; the stub wraps the paced result) as a
|
|
120
|
+
* string-level contract, independent of esbuild — esbuild cannot run inside
|
|
121
|
+
* this repo's jsdom vitest environment (see `bundleTestFile`'s module doc's
|
|
122
|
+
* lazy-import note), so a real bundling round-trip is out of unit-test reach
|
|
123
|
+
* here; `wrapSdkWithStub`/`wrapWithMethodPacing`'s own composed-call behavior
|
|
124
|
+
* is covered directly (see `bundle.test.ts`).
|
|
125
|
+
*
|
|
126
|
+
* Generates a virtual CommonJS-style module so that esbuild does NOT perform
|
|
127
|
+
* strict named-export matching. When `format:'iife'` bundles a CJS module, it
|
|
128
|
+
* wraps it with its own `__toCommonJS` helper and satisfies named imports via
|
|
129
|
+
* property access on the `module.exports` object — which is our Proxy. This
|
|
130
|
+
* means `import { getPlatformOS } from '...'` becomes
|
|
131
|
+
* `__proxy.getPlatformOS` at runtime, which correctly reads from
|
|
132
|
+
* `window.__sdk`.
|
|
133
|
+
*
|
|
134
|
+
* The bridge-stub and method-pace imports are STATIC imports of the real
|
|
135
|
+
* `bridge-stub.ts`/`method-pace.ts` modules (not inlined JS) so esbuild
|
|
136
|
+
* bundles each once and the fixture registry / pacing registry have a single
|
|
137
|
+
* source of truth shared with their own unit tests.
|
|
138
|
+
*
|
|
139
|
+
* Exported for unit testing.
|
|
140
|
+
*/
|
|
141
|
+
declare function buildSdkRedirectModuleContents(): string;
|
|
79
142
|
/**
|
|
80
143
|
* Bundles `absPath` into a single IIFE string suitable for `Runtime.evaluate`.
|
|
81
144
|
*
|
|
@@ -92,5 +155,5 @@ interface BundleResult {
|
|
|
92
155
|
*/
|
|
93
156
|
declare function bundleTestFile(absPath: string, opts?: BundleOptions): Promise<BundleResult>;
|
|
94
157
|
//#endregion
|
|
95
|
-
export { BundleResult as n,
|
|
96
|
-
//# sourceMappingURL=bundle-
|
|
158
|
+
export { bundleTestFile as i, BundleResult as n, buildSdkRedirectModuleContents as r, BundleOptions as t };
|
|
159
|
+
//# sourceMappingURL=bundle-C796JIwG.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-C796JIwG.d.ts","names":[],"sources":["../src/test-runner/bundle.ts"],"mappings":";;AAqEA;;;;;AAmBA;;;;;AA+FA;;;;;AA4UA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA9biB,aAAA;;;;;;;EAOf,cAAA;;;;;EAKA,UAAA;AAAA;;;;;UAOe,YAAA;EACf,IAAA;EACA,QAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6Fc,8BAAA,CAAA;;;;;;;;;;;;;;;iBA4UM,cAAA,CAAe,OAAA,UAAiB,IAAA,GAAO,aAAA,GAAgB,OAAA,CAAQ,YAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture-
|
|
1
|
+
{"version":3,"file":"capture-DsP525OZ.d.ts","names":[],"sources":["../src/test-runner/capture.ts"],"mappings":";;AA+BA;;;;;AAyBA;;;;;;;;;;;;;;;;;;;;;;;;UAzBiB,cAAA;;EAEf,QAAA;;EAEA,IAAA;AAAA;;;;;;;;;;;;;;;;iBAqBc,iBAAA,CAAkB,GAAA,EAAK,aAAA;EAAgB,IAAA;AAAA,KAAkB,cAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp-connection-
|
|
1
|
+
{"version":3,"file":"cdp-connection-rP1WdnH5.d.ts","names":[],"sources":["../src/mcp/cdp-connection.ts"],"mappings":";;AAwBA;;;;;;;;;AAUA;;;;;;;;;;;AASA;;UAnBiB,SAAA;EA2BI;EAzBnB,EAAA;EAoBA;EAlBA,KAAA;EAoBA;EAlBA,GAAA;AAAA;;UAIe,eAAA;EACf,IAAA;EACA,OAAA;EACA,KAAA;EACA,WAAA;EACA,SAAA;AAAA;AAsBF;AAAA,UAlBiB,qBAAA;;EAEf,IAAA;EACA,IAAA,EAAM,eAAA;EAiBN;EAfA,SAAA;EACA,kBAAA;EACA,UAAA;IACE,UAAA,EAAY,KAAA;MACV,YAAA;MACA,GAAA;MACA,UAAA;MACA,YAAA;IAAA;EAAA;AAAA;;UAMW,6BAAA;EACf,SAAA;EACA,OAAA;IACE,GAAA;IACA,MAAA;IACA,OAAA,GAAU,MAAA;EAAA;EAkBZ;EAfA,SAAA;EAgBI;EAdJ,QAAA;EACA,IAAA;AAAA;;UAIe,4BAAA;EACf,SAAA;EACA,QAAA;IACE,GAAA;IACA,MAAA;IACA,UAAA;IACA,QAAA;EAAA;EAEF,SAAA;EACA,IAAA;AAAA;;;;;UAOe,YAAA;EACf,YAAA;EACA,QAAA;EACA,GAAA;EACA,UAAA;EACA,YAAA;AAAA;;UAIe,2BAAA;EAcD;EAZd,SAAA;EACA,gBAAA;IACE,WAAA;IACA,IAAA;IACA,UAAA;IACA,YAAA;IACA,QAAA;IACA,GAAA;IACA,UAAA;MACE,UAAA,EAAY,YAAA;IAAA,GAShB;IANE,SAAA,GAAY,eAAA;EAAA;AAAA;;UAKC,WAAA;EACf,0BAAA,EAA4B,qBAAA;EAC5B,2BAAA,EAA6B,6BAAA;EAC7B,0BAAA,EAA4B,4BAAA;EAC5B,yBAAA,EAA2B,2BAAA;AAAA;AAAA,KAGjB,YAAA,SAAqB,WAAA;;UAOhB,UAAA;EACf,MAAA;EADe;EAGf,QAAA;EACA,QAAA;EAOqB;EALrB,SAAA;EACA,SAAA;EAHA;EAKA,UAAA;EACA,cAAA;EACA,QAAA,GAAW,UAAA;EACX,WAAA;EACA,OAAA;AAAA;;UAIe,oBAAA;EACf,IAAA,EAAM,UAAA;AAAA;AADR;AAAA,UAKiB,iBAAA;EACf,SAAA;EACA,OAAA;AAAA;AAFF;AAAA,UAMiB,2BAAA;;EAEf,IAAA;AAAA;AAFF;;;;AAAA,UASiB,qBAAA;EAAA;EAEf,UAAA;;EAEA,aAAA;EAFA;EAIA,YAAA;AAAA;;UAIe,qBAAA;EAAA;EAEf,MAAA,EAAQ,eAAA;;EAER,gBAAA;IACE,IAAA;IACA,SAAA,GAAY,eAAA;EAAA;AAAA;;;;;UAQC,aAAA;EACf,iBAAA;IACE,MAAA;MAAU,KAAA;MAAgB,MAAA;IAAA;IAC1B,MAAA,EAAQ,oBAAA;EAAA;EAEV,6BAAA;IACE,MAAA;MAAU,cAAA;IAAA;IACV,MAAA,EAAQ,iBAAA;EAAA;EAEV,wBAAA;IACE,MAAA;MAAU,MAAA;MAAkC,OAAA;IAAA;IAC5C,MAAA,EAAQ,2BAAA;EAAA;EAEV,kBAAA;IACE,MAAA,EAAQ,qBAAA;IACR,MAAA,EAAQ,qBAAA;EAAA;AAAA;AAAA,KAIA,cAAA,SAAuB,aAAA;;;;;;;;UASlB,aAAA;EATS;;;;AAS1B;;;;;;;;;;;EAT0B,SAyBf,IAAA;EAgBgD;;;;;EATzD,aAAA,IAAiB,OAAA;EA4BN;EAzBX,WAAA,IAAe,SAAA;EAyBZ;EAtBH,iBAAA,WAA4B,YAAA,EAAc,KAAA,EAAO,CAAA,GAAI,aAAA,CAAc,WAAA,CAAY,CAAA;EAyC5D;EAtCnB,EAAA,WAAa,YAAA,EAAc,KAAA,EAAO,CAAA,EAAG,QAAA,GAAW,OAAA,EAAS,WAAA,CAAY,CAAA;EAuD1D;;;;;;;;;;;;;EAxCX,IAAA,WAAe,cAAA,EACb,MAAA,EAAQ,CAAA,EACR,MAAA,GAAS,aAAA,CAAc,CAAA,aACvB,IAAA;IAAS,SAAA;EAAA,IACR,OAAA,CAAQ,aAAA,CAAc,CAAA;EAtBsD;;;;;;EA8B/E,KAAA;EA3BqE;;;;;;;;;EAsCrE,cAAA,KAAmB,OAAA,CAAQ,SAAA;EArBzB;;;;;;;;;;;EAkCF,kBAAA,EACE,QAAA,GAAW,OAAA,EAAS,SAAA,gBACpB,SAAA,WACA,cAAA,YACC,OAAA,CAAQ,SAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildIndicatorExpression } from "./attach-orchestrator-
|
|
1
|
+
import { buildIndicatorExpression } from "./attach-orchestrator-6kz_ZdWL.js";
|
|
2
2
|
//#region src/test-runner/cell.ts
|
|
3
3
|
/**
|
|
4
4
|
* Injects each key of `globals` into `globalThis` in the page via a single
|
|
@@ -65,4 +65,4 @@ async function injectDebugIndicator(conn, opts) {
|
|
|
65
65
|
//#endregion
|
|
66
66
|
export { injectDebugIndicator, injectGlobals };
|
|
67
67
|
|
|
68
|
-
//# sourceMappingURL=cell-
|
|
68
|
+
//# sourceMappingURL=cell-BMlFh08P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-BMlFh08P.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":";;;;;;;;;;;;AAuSA,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,13 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
-
import { a as buildIndicatorExpression } from "./attach-orchestrator-
|
|
2
|
+
import { a as buildIndicatorExpression } from "./attach-orchestrator-BG8TGJOZ.js";
|
|
3
|
+
import { n as THROTTLED_MESSAGE_SUBSTRING, t as THROTTLED_ERROR_CODE } from "./throttle-DKKzX1qC.js";
|
|
3
4
|
//#region src/test-runner/cell.ts
|
|
4
|
-
var cell_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
-
PERMISSION_PREFLIGHT_TIMEOUT_MS: () => PERMISSION_PREFLIGHT_TIMEOUT_MS,
|
|
6
|
-
buildPermissionPreflightExpression: () => buildPermissionPreflightExpression,
|
|
7
|
-
injectDebugIndicator: () => injectDebugIndicator,
|
|
8
|
-
injectGlobals: () => injectGlobals,
|
|
9
|
-
runPermissionPreflight: () => runPermissionPreflight
|
|
10
|
-
});
|
|
11
5
|
/**
|
|
12
6
|
* Cell injection utility for the `devtools-test` CLI (issue #684 §4.1).
|
|
13
7
|
*
|
|
@@ -28,6 +22,13 @@ var cell_exports = /* @__PURE__ */ __exportAll({
|
|
|
28
22
|
*
|
|
29
23
|
* Node-only. react-free. CdpConnection only.
|
|
30
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
|
+
});
|
|
31
32
|
/**
|
|
32
33
|
* `__AIT_PERMS__` key → SDK function name whose `.getPermission()` is probed
|
|
33
34
|
* (devtools#739). This is the exact contract sdk-example#265 consumes — do
|
|
@@ -53,8 +54,43 @@ const PERMISSION_PROBE_MAP = {
|
|
|
53
54
|
contacts: "fetchContacts",
|
|
54
55
|
location: "getCurrentLocation"
|
|
55
56
|
};
|
|
56
|
-
/**
|
|
57
|
-
|
|
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;
|
|
58
94
|
/**
|
|
59
95
|
* Builds the `Runtime.evaluate` expression for the permission-state preflight
|
|
60
96
|
* (devtools#739). Evaluated ONCE per relay session, before the first test
|
|
@@ -69,6 +105,29 @@ const PERMISSION_PREFLIGHT_TIMEOUT_MS = 1e4;
|
|
|
69
105
|
* caller, and a single slow/broken permission must not fail the others (each
|
|
70
106
|
* probe is awaited independently, not short-circuited).
|
|
71
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
|
+
*
|
|
72
131
|
* Tests (sdk-example#265) read `globalThis.__AIT_PERMS__` to branch
|
|
73
132
|
* deterministically per permission state instead of blanket outcome-branching.
|
|
74
133
|
*
|
|
@@ -79,9 +138,18 @@ const PERMISSION_PREFLIGHT_TIMEOUT_MS = 1e4;
|
|
|
79
138
|
*
|
|
80
139
|
* Pure function — no I/O, no CDP call. Callers pass the returned string to
|
|
81
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.
|
|
82
145
|
*/
|
|
83
|
-
function buildPermissionPreflightExpression() {
|
|
84
|
-
|
|
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);})()`;
|
|
85
153
|
}
|
|
86
154
|
/**
|
|
87
155
|
* Runs the permission-state preflight (devtools#739) via `Runtime.evaluate`
|
|
@@ -100,13 +168,19 @@ function buildPermissionPreflightExpression() {
|
|
|
100
168
|
*
|
|
101
169
|
* @param conn - The live CDP connection (relay-attached page).
|
|
102
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.
|
|
103
177
|
*/
|
|
104
|
-
async function runPermissionPreflight(conn, timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS) {
|
|
178
|
+
async function runPermissionPreflight(conn, timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS, pace = true) {
|
|
105
179
|
const TIMEOUT_SENTINEL = Symbol("permission-preflight-timeout");
|
|
106
180
|
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(TIMEOUT_SENTINEL), timeoutMs));
|
|
107
181
|
try {
|
|
108
182
|
const evalPromise = conn.send("Runtime.evaluate", {
|
|
109
|
-
expression: buildPermissionPreflightExpression(),
|
|
183
|
+
expression: buildPermissionPreflightExpression(pace),
|
|
110
184
|
returnByValue: true,
|
|
111
185
|
awaitPromise: true
|
|
112
186
|
});
|
|
@@ -195,6 +269,6 @@ async function injectDebugIndicator(conn, opts) {
|
|
|
195
269
|
}
|
|
196
270
|
}
|
|
197
271
|
//#endregion
|
|
198
|
-
export {
|
|
272
|
+
export { cell_exports as n, runPermissionPreflight as r, PERMISSION_PREFLIGHT_TIMEOUT_MS as t };
|
|
199
273
|
|
|
200
|
-
//# sourceMappingURL=cell-
|
|
274
|
+
//# sourceMappingURL=cell-Dtgtusog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-Dtgtusog.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,14 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as __exportAll } from "./rolldown-runtime-DGkTqVfb.js";
|
|
3
|
-
import { a as buildIndicatorExpression } from "./attach-orchestrator-
|
|
3
|
+
import { a as buildIndicatorExpression } from "./attach-orchestrator-BEiz3wAx.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
|
|
4
37
|
//#region src/test-runner/cell.ts
|
|
5
|
-
var cell_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
-
PERMISSION_PREFLIGHT_TIMEOUT_MS: () => PERMISSION_PREFLIGHT_TIMEOUT_MS,
|
|
7
|
-
buildPermissionPreflightExpression: () => buildPermissionPreflightExpression,
|
|
8
|
-
injectDebugIndicator: () => injectDebugIndicator,
|
|
9
|
-
injectGlobals: () => injectGlobals,
|
|
10
|
-
runPermissionPreflight: () => runPermissionPreflight
|
|
11
|
-
});
|
|
12
38
|
/**
|
|
13
39
|
* Cell injection utility for the `devtools-test` CLI (issue #684 §4.1).
|
|
14
40
|
*
|
|
@@ -29,6 +55,13 @@ var cell_exports = /* @__PURE__ */ __exportAll({
|
|
|
29
55
|
*
|
|
30
56
|
* Node-only. react-free. CdpConnection only.
|
|
31
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
|
+
});
|
|
32
65
|
/**
|
|
33
66
|
* `__AIT_PERMS__` key → SDK function name whose `.getPermission()` is probed
|
|
34
67
|
* (devtools#739). This is the exact contract sdk-example#265 consumes — do
|
|
@@ -54,8 +87,43 @@ const PERMISSION_PROBE_MAP = {
|
|
|
54
87
|
contacts: "fetchContacts",
|
|
55
88
|
location: "getCurrentLocation"
|
|
56
89
|
};
|
|
57
|
-
/**
|
|
58
|
-
|
|
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;
|
|
59
127
|
/**
|
|
60
128
|
* Builds the `Runtime.evaluate` expression for the permission-state preflight
|
|
61
129
|
* (devtools#739). Evaluated ONCE per relay session, before the first test
|
|
@@ -70,6 +138,29 @@ const PERMISSION_PREFLIGHT_TIMEOUT_MS = 1e4;
|
|
|
70
138
|
* caller, and a single slow/broken permission must not fail the others (each
|
|
71
139
|
* probe is awaited independently, not short-circuited).
|
|
72
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
|
+
*
|
|
73
164
|
* Tests (sdk-example#265) read `globalThis.__AIT_PERMS__` to branch
|
|
74
165
|
* deterministically per permission state instead of blanket outcome-branching.
|
|
75
166
|
*
|
|
@@ -80,9 +171,18 @@ const PERMISSION_PREFLIGHT_TIMEOUT_MS = 1e4;
|
|
|
80
171
|
*
|
|
81
172
|
* Pure function — no I/O, no CDP call. Callers pass the returned string to
|
|
82
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.
|
|
83
178
|
*/
|
|
84
|
-
function buildPermissionPreflightExpression() {
|
|
85
|
-
|
|
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);})()`;
|
|
86
186
|
}
|
|
87
187
|
/**
|
|
88
188
|
* Runs the permission-state preflight (devtools#739) via `Runtime.evaluate`
|
|
@@ -101,13 +201,19 @@ function buildPermissionPreflightExpression() {
|
|
|
101
201
|
*
|
|
102
202
|
* @param conn - The live CDP connection (relay-attached page).
|
|
103
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.
|
|
104
210
|
*/
|
|
105
|
-
async function runPermissionPreflight(conn, timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS) {
|
|
211
|
+
async function runPermissionPreflight(conn, timeoutMs = PERMISSION_PREFLIGHT_TIMEOUT_MS, pace = true) {
|
|
106
212
|
const TIMEOUT_SENTINEL = Symbol("permission-preflight-timeout");
|
|
107
213
|
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(TIMEOUT_SENTINEL), timeoutMs));
|
|
108
214
|
try {
|
|
109
215
|
const evalPromise = conn.send("Runtime.evaluate", {
|
|
110
|
-
expression: buildPermissionPreflightExpression(),
|
|
216
|
+
expression: buildPermissionPreflightExpression(pace),
|
|
111
217
|
returnByValue: true,
|
|
112
218
|
awaitPromise: true
|
|
113
219
|
});
|
|
@@ -196,6 +302,6 @@ async function injectDebugIndicator(conn, opts) {
|
|
|
196
302
|
}
|
|
197
303
|
}
|
|
198
304
|
//#endregion
|
|
199
|
-
export {
|
|
305
|
+
export { cell_exports as n, runPermissionPreflight as r, PERMISSION_PREFLIGHT_TIMEOUT_MS as t };
|
|
200
306
|
|
|
201
|
-
//# sourceMappingURL=cell-
|
|
307
|
+
//# sourceMappingURL=cell-KsRXFdDs.js.map
|