@ait-co/devtools 0.1.143 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +65 -163
- package/README.md +65 -192
- package/dist/in-app/auto.d.ts +1 -138
- package/dist/in-app/auto.js +28 -1102
- package/dist/in-app/auto.js.map +1 -1
- package/dist/in-app/index.d.ts +38 -547
- package/dist/in-app/index.d.ts.map +1 -1
- package/dist/in-app/index.js +62 -939
- package/dist/in-app/index.js.map +1 -1
- package/dist/mcp/cli.d.ts +1 -54
- package/dist/mcp/cli.js +33 -9720
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/server.d.ts +1 -88
- package/dist/mcp/server.js +36 -1076
- package/dist/mcp/server.js.map +1 -1
- package/dist/mock/index.d.ts +19 -20
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js.map +1 -1
- package/dist/optional-peers-CDEFhlhJ.cjs +131 -0
- package/dist/optional-peers-CDEFhlhJ.cjs.map +1 -0
- package/dist/optional-peers-FdVbUJst.js +96 -0
- package/dist/optional-peers-FdVbUJst.js.map +1 -0
- package/dist/panel/index.js +1 -103
- package/dist/panel/index.js.map +1 -1
- package/dist/relay-url-store-CPZAn-T5.js +107 -0
- package/dist/relay-url-store-CPZAn-T5.js.map +1 -0
- package/dist/relay-url-store-DLjlvMSA.cjs +108 -0
- package/dist/relay-url-store-DLjlvMSA.cjs.map +1 -0
- package/dist/stubs/bin-devtools-mcp.js +58 -0
- package/dist/stubs/bin-devtools-mcp.js.map +1 -0
- package/dist/stubs/bin-devtools-test.d.ts +2 -0
- package/dist/stubs/bin-devtools-test.js +55 -0
- package/dist/stubs/bin-devtools-test.js.map +1 -0
- package/dist/test-runner/config.d.ts +1 -231
- package/dist/test-runner/config.js +41 -45
- package/dist/test-runner/config.js.map +1 -1
- package/dist/{tunnel-BVSMXctM.cjs → tunnel-BKZkOyQp.cjs} +27 -75
- package/dist/tunnel-BKZkOyQp.cjs.map +1 -0
- package/dist/{tunnel-D7xkimBu.js → tunnel-CqSCIrdU.js} +27 -75
- package/dist/tunnel-CqSCIrdU.js.map +1 -0
- package/dist/unplugin/index.cjs +17 -30
- package/dist/unplugin/index.cjs.map +1 -1
- package/dist/unplugin/index.d.cts +34 -5
- package/dist/unplugin/index.d.cts.map +1 -1
- package/dist/unplugin/index.d.ts +35 -6
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +17 -30
- package/dist/unplugin/index.js.map +1 -1
- package/dist/unplugin/tunnel.cjs +61 -74
- package/dist/unplugin/tunnel.cjs.map +1 -1
- package/dist/unplugin/tunnel.d.cts +22 -16
- package/dist/unplugin/tunnel.d.cts.map +1 -1
- package/dist/unplugin/tunnel.d.ts +22 -16
- package/dist/unplugin/tunnel.d.ts.map +1 -1
- package/dist/unplugin/tunnel.js +61 -74
- package/dist/unplugin/tunnel.js.map +1 -1
- package/package.json +17 -22
- package/dist/attach-orchestrator-0F0m_UqQ.js +0 -1845
- package/dist/attach-orchestrator-0F0m_UqQ.js.map +0 -1
- package/dist/attach-orchestrator-D65KxFy_.js +0 -1831
- package/dist/attach-orchestrator-D65KxFy_.js.map +0 -1
- package/dist/attach-orchestrator-DL3NQ9ca.js +0 -1846
- package/dist/attach-orchestrator-DL3NQ9ca.js.map +0 -1
- package/dist/bundle-C796JIwG.d.ts +0 -159
- package/dist/bundle-C796JIwG.d.ts.map +0 -1
- package/dist/capture-DsP525OZ.d.ts +0 -58
- package/dist/capture-DsP525OZ.d.ts.map +0 -1
- package/dist/cdp-connection-rP1WdnH5.d.ts +0 -287
- package/dist/cdp-connection-rP1WdnH5.d.ts.map +0 -1
- package/dist/cell-BaLvusOl.js +0 -68
- package/dist/cell-BaLvusOl.js.map +0 -1
- package/dist/cell-CBUS3-nT.js +0 -274
- package/dist/cell-CBUS3-nT.js.map +0 -1
- package/dist/cell-EBKKpAAT.js +0 -307
- package/dist/cell-EBKKpAAT.js.map +0 -1
- package/dist/chii-relay-BZ3HqWL5.js +0 -304
- package/dist/chii-relay-BZ3HqWL5.js.map +0 -1
- package/dist/chii-relay-D7eK2acz.cjs +0 -304
- package/dist/chii-relay-D7eK2acz.cjs.map +0 -1
- package/dist/debug-server-B3ABDrRI.js +0 -456
- package/dist/debug-server-B3ABDrRI.js.map +0 -1
- package/dist/debug-server-BWhwrVXa.js +0 -1158
- package/dist/debug-server-BWhwrVXa.js.map +0 -1
- package/dist/debug-server-CfQNxxGW.js +0 -600
- package/dist/debug-server-CfQNxxGW.js.map +0 -1
- package/dist/deeplink-B5-Hxu0Q.js +0 -62
- package/dist/deeplink-B5-Hxu0Q.js.map +0 -1
- package/dist/deeplink-BpO9qc-D.js +0 -62
- package/dist/deeplink-BpO9qc-D.js.map +0 -1
- package/dist/deeplink-BzdbA1gV.cjs +0 -62
- package/dist/deeplink-BzdbA1gV.cjs.map +0 -1
- package/dist/deeplink-DCScMYcp.cjs +0 -62
- package/dist/deeplink-DCScMYcp.cjs.map +0 -1
- package/dist/devtools-opener-3Drge_RJ.js +0 -75
- package/dist/devtools-opener-3Drge_RJ.js.map +0 -1
- package/dist/devtools-opener-B8nxrxqu.js +0 -71
- package/dist/devtools-opener-B8nxrxqu.js.map +0 -1
- package/dist/devtools-opener-BDY0w3_0.cjs +0 -68
- package/dist/devtools-opener-BDY0w3_0.cjs.map +0 -1
- package/dist/devtools-opener-BTl5A6Cd.js +0 -71
- package/dist/devtools-opener-BTl5A6Cd.js.map +0 -1
- package/dist/devtools-opener-CJpEsXXQ.js +0 -76
- package/dist/devtools-opener-CJpEsXXQ.js.map +0 -1
- package/dist/devtools-opener-CxtryS8c.js +0 -75
- package/dist/devtools-opener-CxtryS8c.js.map +0 -1
- package/dist/devtools-opener-iv1OwfJN.cjs +0 -68
- package/dist/devtools-opener-iv1OwfJN.cjs.map +0 -1
- package/dist/in-app/auto.d.ts.map +0 -1
- package/dist/mcp/cli.d.ts.map +0 -1
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/pool-DcaaOwUq.d.ts +0 -14761
- package/dist/pool-DcaaOwUq.d.ts.map +0 -1
- package/dist/qr-http-server--gl2-WKc.cjs +0 -1644
- package/dist/qr-http-server--gl2-WKc.cjs.map +0 -1
- package/dist/qr-http-server-Bb7lMeqi.js +0 -1644
- package/dist/qr-http-server-Bb7lMeqi.js.map +0 -1
- package/dist/qr-http-server-C_lqOrgc.js +0 -1644
- package/dist/qr-http-server-C_lqOrgc.js.map +0 -1
- package/dist/qr-http-server-CopuMbub.js +0 -1644
- package/dist/qr-http-server-CopuMbub.js.map +0 -1
- package/dist/qr-http-server-D-Off6K1.cjs +0 -1644
- package/dist/qr-http-server-D-Off6K1.cjs.map +0 -1
- package/dist/qr-http-server-DrbIVDjO.js +0 -1645
- package/dist/qr-http-server-DrbIVDjO.js.map +0 -1
- package/dist/qr-http-server-n1twN18z.js +0 -1644
- package/dist/qr-http-server-n1twN18z.js.map +0 -1
- package/dist/relay-factory-N9QobQxG.js +0 -206
- package/dist/relay-factory-N9QobQxG.js.map +0 -1
- package/dist/relay-secret-store-BPhN1upr.js +0 -240
- package/dist/relay-secret-store-BPhN1upr.js.map +0 -1
- package/dist/relay-secret-store-Bmyleu0A.js +0 -154
- package/dist/relay-secret-store-Bmyleu0A.js.map +0 -1
- package/dist/relay-secret-store-CQenfcSL.js +0 -154
- package/dist/relay-secret-store-CQenfcSL.js.map +0 -1
- package/dist/relay-secret-store-DKxs7zwq.js +0 -153
- package/dist/relay-secret-store-DKxs7zwq.js.map +0 -1
- package/dist/relay-secret-store-DWKdV-eY.cjs +0 -241
- package/dist/relay-secret-store-DWKdV-eY.cjs.map +0 -1
- package/dist/relay-secret-store-WJ8EGkIl.js +0 -153
- package/dist/relay-secret-store-WJ8EGkIl.js.map +0 -1
- package/dist/relay-url-store-1FGuSYAn.cjs +0 -115
- package/dist/relay-url-store-1FGuSYAn.cjs.map +0 -1
- package/dist/relay-url-store-BR2XodiO.js +0 -123
- package/dist/relay-url-store-BR2XodiO.js.map +0 -1
- package/dist/relay-url-store-Bskcyeg8.js +0 -114
- package/dist/relay-url-store-Bskcyeg8.js.map +0 -1
- package/dist/relay-url-store-CH63fVCm.js +0 -122
- package/dist/relay-url-store-CH63fVCm.js.map +0 -1
- package/dist/relay-url-store-DaY1QPes.js +0 -123
- package/dist/relay-url-store-DaY1QPes.js.map +0 -1
- package/dist/relay-url-store-xmUuTjXA.js +0 -122
- package/dist/relay-url-store-xmUuTjXA.js.map +0 -1
- package/dist/relay-worker-B5HKkGUY.js +0 -832
- package/dist/relay-worker-B5HKkGUY.js.map +0 -1
- package/dist/relay-worker-YdlpZQl9.d.ts +0 -214
- package/dist/relay-worker-YdlpZQl9.d.ts.map +0 -1
- package/dist/rolldown-runtime-DGkTqVfb.js +0 -15
- package/dist/rolldown-runtime-DUslC3ob.js +0 -14
- package/dist/runtime-kn9DxOeg.d.ts +0 -249
- package/dist/runtime-kn9DxOeg.d.ts.map +0 -1
- package/dist/test-runner/bin.js +0 -2584
- package/dist/test-runner/bin.js.map +0 -1
- package/dist/test-runner/bridge-stub.d.ts +0 -125
- package/dist/test-runner/bridge-stub.d.ts.map +0 -1
- package/dist/test-runner/bridge-stub.js +0 -92
- package/dist/test-runner/bridge-stub.js.map +0 -1
- package/dist/test-runner/bundle.d.ts +0 -2
- package/dist/test-runner/bundle.js +0 -439
- package/dist/test-runner/bundle.js.map +0 -1
- package/dist/test-runner/capture.d.ts +0 -2
- package/dist/test-runner/capture.js +0 -44
- package/dist/test-runner/capture.js.map +0 -1
- package/dist/test-runner/config.d.ts.map +0 -1
- package/dist/test-runner/method-pace.d.ts +0 -82
- package/dist/test-runner/method-pace.d.ts.map +0 -1
- package/dist/test-runner/method-pace.js +0 -120
- package/dist/test-runner/method-pace.js.map +0 -1
- package/dist/test-runner/pool.d.ts +0 -2
- package/dist/test-runner/pool.js +0 -136
- package/dist/test-runner/pool.js.map +0 -1
- package/dist/test-runner/relay-factory.d.ts +0 -11245
- package/dist/test-runner/relay-factory.d.ts.map +0 -1
- package/dist/test-runner/relay-factory.js +0 -206
- package/dist/test-runner/relay-factory.js.map +0 -1
- package/dist/test-runner/relay-worker.d.ts +0 -2
- package/dist/test-runner/relay-worker.js +0 -2
- package/dist/test-runner/report.d.ts +0 -163
- package/dist/test-runner/report.d.ts.map +0 -1
- package/dist/test-runner/report.js +0 -198
- package/dist/test-runner/report.js.map +0 -1
- package/dist/test-runner/rpc.d.ts +0 -56
- package/dist/test-runner/rpc.d.ts.map +0 -1
- package/dist/test-runner/rpc.js +0 -98
- package/dist/test-runner/rpc.js.map +0 -1
- package/dist/test-runner/runtime.d.ts +0 -2
- package/dist/test-runner/runtime.js +0 -659
- package/dist/test-runner/runtime.js.map +0 -1
- package/dist/test-runner/task-graph.d.ts +0 -38
- package/dist/test-runner/task-graph.d.ts.map +0 -1
- package/dist/test-runner/task-graph.js +0 -182
- package/dist/test-runner/task-graph.js.map +0 -1
- package/dist/throttle-DKKzX1qC.js +0 -59
- package/dist/throttle-DKKzX1qC.js.map +0 -1
- package/dist/totp-95OAa20j.js +0 -64
- package/dist/totp-95OAa20j.js.map +0 -1
- package/dist/totp-BjtoQNfu.cjs +0 -64
- package/dist/totp-BjtoQNfu.cjs.map +0 -1
- package/dist/totp-CZLLKfOC.js +0 -200
- package/dist/totp-CZLLKfOC.js.map +0 -1
- package/dist/totp-DAxys-r0.js +0 -199
- package/dist/totp-DAxys-r0.js.map +0 -1
- package/dist/totp-DIbrZtI7.js +0 -189
- package/dist/totp-DIbrZtI7.js.map +0 -1
- package/dist/totp-Df252ZdA.cjs +0 -192
- package/dist/totp-Df252ZdA.cjs.map +0 -1
- package/dist/totp-DfekTBk3.js +0 -211
- package/dist/totp-DfekTBk3.js.map +0 -1
- package/dist/totp-Dwft0Kz7.js +0 -3
- package/dist/totp-WY6l0ysP.js +0 -190
- package/dist/totp-WY6l0ysP.js.map +0 -1
- package/dist/tunnel-BVSMXctM.cjs.map +0 -1
- package/dist/tunnel-D7xkimBu.js.map +0 -1
- /package/dist/{test-runner/bin.d.ts → stubs/bin-devtools-mcp.d.ts} +0 -0
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
import { accessSync } from "node:fs";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path$1 from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
//#region src/test-runner/bundle.ts
|
|
6
|
-
/**
|
|
7
|
-
* esbuild-based bundler for user test files.
|
|
8
|
-
*
|
|
9
|
-
* Bundles a single test file into a self-contained IIFE string that can be
|
|
10
|
-
* injected into a WebView via `Runtime.evaluate`. The bundle includes the
|
|
11
|
-
* test runtime (`runtime.ts`), which provides `describe/it/test/expect` and
|
|
12
|
-
* the `runTestModule(factory)` entry point.
|
|
13
|
-
*
|
|
14
|
-
* ## How the wiring works
|
|
15
|
-
*
|
|
16
|
-
* The bundle exposes two exports on `globalThis.__testBundle`:
|
|
17
|
-
* - `runTestModule` — the runtime's entry function.
|
|
18
|
-
* - `__userFactory` — an async function whose body is the user's top-level
|
|
19
|
-
* test registration code (describe/it/test calls).
|
|
20
|
-
*
|
|
21
|
-
* The Node-side RPC (`rpc.ts`) calls:
|
|
22
|
-
* `globalThis.__testBundle.runTestModule(globalThis.__testBundle.__userFactory)`
|
|
23
|
-
*
|
|
24
|
-
* `runTestModule` then installs `describe/it/test/expect` as globals, invokes
|
|
25
|
-
* the factory (which registers all tests), runs them, and returns a `RunReport`.
|
|
26
|
-
*
|
|
27
|
-
* ## Why a factory wrapper is needed
|
|
28
|
-
*
|
|
29
|
-
* Naively adding the runtime to `entryPoints` and bundling the user file would
|
|
30
|
-
* fail for two reasons:
|
|
31
|
-
* 1. `describe/it/test/expect` from the runtime are module-local in the IIFE
|
|
32
|
-
* scope. The user's top-level `describe(...)` calls expect them as globals —
|
|
33
|
-
* they are not globals until `runTestModule` installs them.
|
|
34
|
-
* 2. Even with globals pre-installed, the user file runs at IIFE-evaluation
|
|
35
|
-
* time, before the RPC layer calls `runTestModule` to reset state and start
|
|
36
|
-
* the test clock.
|
|
37
|
-
*
|
|
38
|
-
* The factory approach solves both: the user's registration code is deferred
|
|
39
|
-
* into a function that `runTestModule` calls AFTER installing the globals.
|
|
40
|
-
*
|
|
41
|
-
* ## Factory extraction algorithm
|
|
42
|
-
*
|
|
43
|
-
* The `userFactoryPlugin` reads the user file and splits lines into:
|
|
44
|
-
* - **top-level**: `import …` and re-export lines — kept at module scope
|
|
45
|
-
* (the only valid position for static `import` in ESM).
|
|
46
|
-
* - **body**: all other statements — moved into the body of the exported
|
|
47
|
-
* `__userFactory` async function.
|
|
48
|
-
*
|
|
49
|
-
* esbuild processes the re-generated module, following each static import
|
|
50
|
-
* through the normal dependency graph (including the SDK-redirect plugin).
|
|
51
|
-
*
|
|
52
|
-
* ## SDK redirect
|
|
53
|
-
*
|
|
54
|
-
* Imports of `@apps-in-toss/web-framework` (and sub-paths) are intercepted via
|
|
55
|
-
* the `sdkRedirectPlugin` and replaced with a virtual `window.__sdk` proxy that
|
|
56
|
-
* `src/in-app/auto.ts` installs at runtime. This works for both 2.x and 3.x SDK.
|
|
57
|
-
*
|
|
58
|
-
* SECRET-HANDLING: the returned bundle code is caller-managed; never log it.
|
|
59
|
-
*/
|
|
60
|
-
/** The SDK package name that mini-app test code imports from. */
|
|
61
|
-
const SDK_PACKAGE = "@apps-in-toss/web-framework";
|
|
62
|
-
/**
|
|
63
|
-
* Names the runtime installs as globals before invoking the user factory.
|
|
64
|
-
* The `vitest` virtual module re-exports each as a lazy getter that reads from
|
|
65
|
-
* `globalThis` at access time. Keep in sync with the globals installed in
|
|
66
|
-
* `runtime.ts#runTestModule`.
|
|
67
|
-
*/
|
|
68
|
-
const VITEST_GLOBAL_NAMES = [
|
|
69
|
-
"describe",
|
|
70
|
-
"it",
|
|
71
|
-
"test",
|
|
72
|
-
"expect",
|
|
73
|
-
"beforeAll",
|
|
74
|
-
"afterAll",
|
|
75
|
-
"beforeEach",
|
|
76
|
-
"afterEach",
|
|
77
|
-
"vi"
|
|
78
|
-
];
|
|
79
|
-
/**
|
|
80
|
-
* Matches the bare SDK package and any sub-path import
|
|
81
|
-
* (`@apps-in-toss/web-framework`, `@apps-in-toss/web-framework/foo`).
|
|
82
|
-
* Built from {@link SDK_PACKAGE} so the package name has a single source.
|
|
83
|
-
*/
|
|
84
|
-
const SDK_IMPORT_FILTER = new RegExp(`^${SDK_PACKAGE.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`);
|
|
85
|
-
/**
|
|
86
|
-
* esbuild plugin that intercepts SDK imports and redirects them to the
|
|
87
|
-
* `window.__sdk` proxy that `src/in-app/auto.ts` installs at runtime.
|
|
88
|
-
*
|
|
89
|
-
* Strategy: for every import of `@apps-in-toss/web-framework` (or sub-paths),
|
|
90
|
-
* esbuild resolves it to a virtual module that re-exports all named exports
|
|
91
|
-
* via `window.__sdk[name]`. This avoids bundling the real SDK (which may not
|
|
92
|
-
* be available in the test environment) while still making named imports work.
|
|
93
|
-
*
|
|
94
|
-
* If `window.__sdk` is absent (non-dog-food build), every access throws a
|
|
95
|
-
* descriptive error rather than returning `undefined` silently.
|
|
96
|
-
*
|
|
97
|
-
* Bridge-stub interception (devtools#740, DT-2): the virtual module runs the
|
|
98
|
-
* resolved `window.__sdk` object through `wrapSdkWithStub` before exporting
|
|
99
|
-
* it. `wrapSdkWithStub` is a pass-through (returns the same object,
|
|
100
|
-
* unwrapped) unless `isStubBlockingEnabled()` reads `true` off
|
|
101
|
-
* `globalThis.__AIT_STUB_BLOCKING__` — an opt-in flag injected the same way
|
|
102
|
-
* `__AIT_CELL__` is (`cell.ts#injectGlobals`, wired from the CLI's
|
|
103
|
-
* `--stub-blocking` flag). Default off => zero behavior change: every existing
|
|
104
|
-
* (non-stub) test run resolves the exact same `window.__sdk` reference it did
|
|
105
|
-
* before this plugin learned about stubbing.
|
|
106
|
-
*
|
|
107
|
-
* Per-method pacing (devtools#769): BEFORE the stub wrap, `window.__sdk` is
|
|
108
|
-
* run through `wrapWithMethodPacing`, which enforces a minimum interval
|
|
109
|
-
* between calls to the SAME named SDK function (`getPaceMethodMs()` reads the
|
|
110
|
-
* `__AIT_PACE_METHOD_MS__` page global — see `method-pace.ts`). Composition
|
|
111
|
-
* order is pacing INSIDE the stub (`wrapSdkWithStub(wrapWithMethodPacing(sdk,
|
|
112
|
-
* gap), enabled)`): a stubbed name resolves instantly from
|
|
113
|
-
* `bridge-stub.ts`'s fixtures without ever reaching the paced wrapper, and
|
|
114
|
-
* only calls that fall through to the real bridge — the ones that can
|
|
115
|
-
* actually trigger `APP_BRIDGE_THROTTLED` — pay the pacing cost. `gapMs <= 0`
|
|
116
|
-
* (default, no `--pace-method` / non-2.x cell) is a no-op fast path — see
|
|
117
|
-
* `method-pace.ts#wrapWithMethodPacing`'s doc for the full contract.
|
|
118
|
-
*/
|
|
119
|
-
/**
|
|
120
|
-
* Builds the virtual CommonJS-style module contents the `sdk-redirect`
|
|
121
|
-
* esbuild plugin loads for every `@apps-in-toss/web-framework` import.
|
|
122
|
-
*
|
|
123
|
-
* Pulled out to a pure, exported function (rather than inlined at the
|
|
124
|
-
* `build.onLoad` call site) so unit tests can assert the exact composition
|
|
125
|
-
* order (pacing wraps the raw SDK; the stub wraps the paced result) as a
|
|
126
|
-
* string-level contract, independent of esbuild — esbuild cannot run inside
|
|
127
|
-
* this repo's jsdom vitest environment (see `bundleTestFile`'s module doc's
|
|
128
|
-
* lazy-import note), so a real bundling round-trip is out of unit-test reach
|
|
129
|
-
* here; `wrapSdkWithStub`/`wrapWithMethodPacing`'s own composed-call behavior
|
|
130
|
-
* is covered directly (see `bundle.test.ts`).
|
|
131
|
-
*
|
|
132
|
-
* Generates a virtual CommonJS-style module so that esbuild does NOT perform
|
|
133
|
-
* strict named-export matching. When `format:'iife'` bundles a CJS module, it
|
|
134
|
-
* wraps it with its own `__toCommonJS` helper and satisfies named imports via
|
|
135
|
-
* property access on the `module.exports` object — which is our Proxy. This
|
|
136
|
-
* means `import { getPlatformOS } from '...'` becomes
|
|
137
|
-
* `__proxy.getPlatformOS` at runtime, which correctly reads from
|
|
138
|
-
* `window.__sdk`.
|
|
139
|
-
*
|
|
140
|
-
* The bridge-stub and method-pace imports are STATIC imports of the real
|
|
141
|
-
* `bridge-stub.ts`/`method-pace.ts` modules (not inlined JS) so esbuild
|
|
142
|
-
* bundles each once and the fixture registry / pacing registry have a single
|
|
143
|
-
* source of truth shared with their own unit tests.
|
|
144
|
-
*
|
|
145
|
-
* Exported for unit testing.
|
|
146
|
-
*/
|
|
147
|
-
function buildSdkRedirectModuleContents() {
|
|
148
|
-
return `
|
|
149
|
-
import { wrapSdkWithStub, isStubBlockingEnabled } from ${JSON.stringify(getBridgeStubPath())};
|
|
150
|
-
import { wrapWithMethodPacing, getPaceMethodMs } from ${JSON.stringify(getMethodPacePath())};
|
|
151
|
-
var __rawSdk = (typeof window !== 'undefined' && window.__sdk)
|
|
152
|
-
? window.__sdk
|
|
153
|
-
: new Proxy({}, {
|
|
154
|
-
get: function(_t, p) {
|
|
155
|
-
throw new Error('window.__sdk is not installed — run in a dog-food build. Missing: ' + String(p));
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
var __pacedSdk = wrapWithMethodPacing(__rawSdk, getPaceMethodMs());
|
|
159
|
-
var __proxy = wrapSdkWithStub(__pacedSdk, isStubBlockingEnabled());
|
|
160
|
-
module.exports = __proxy;
|
|
161
|
-
`;
|
|
162
|
-
}
|
|
163
|
-
function sdkRedirectPlugin() {
|
|
164
|
-
return {
|
|
165
|
-
name: "sdk-redirect",
|
|
166
|
-
setup(build) {
|
|
167
|
-
build.onResolve({ filter: SDK_IMPORT_FILTER }, (args) => ({
|
|
168
|
-
path: args.path,
|
|
169
|
-
namespace: "sdk-redirect"
|
|
170
|
-
}));
|
|
171
|
-
build.onLoad({
|
|
172
|
-
filter: /.*/,
|
|
173
|
-
namespace: "sdk-redirect"
|
|
174
|
-
}, () => ({
|
|
175
|
-
contents: buildSdkRedirectModuleContents(),
|
|
176
|
-
loader: "js",
|
|
177
|
-
resolveDir: process.cwd()
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* esbuild plugin that intercepts `import … from 'vitest'` and replaces it with
|
|
184
|
-
* a virtual module that delegates every named import to `globalThis` at ACCESS
|
|
185
|
-
* time (not at bundle-evaluation time).
|
|
186
|
-
*
|
|
187
|
-
* The runtime installs `describe/it/test/expect/beforeAll/afterAll/beforeEach/
|
|
188
|
-
* afterEach/vi` as globals inside `runTestModule`, which runs AFTER the bundle
|
|
189
|
-
* IIFE is evaluated. A value-copy redirect (`export var describe =
|
|
190
|
-
* globalThis.describe`) would therefore capture `undefined` at evaluation time
|
|
191
|
-
* and the user's `describe(...)` calls would be no-ops — registering zero tests.
|
|
192
|
-
*
|
|
193
|
-
* The fix defers the lookup to call time using per-name **getter** exports.
|
|
194
|
-
* We emit a CommonJS module that:
|
|
195
|
-
* 1. sets `__esModule = true` so esbuild's `__toESM` interop maps each named
|
|
196
|
-
* import directly to a property access on the module (NOT wrapped under a
|
|
197
|
-
* `default` shim — which is what happens for a bare Proxy whose own-keys
|
|
198
|
-
* are empty, leaving every named import `undefined`);
|
|
199
|
-
* 2. defines each global name as a getter that reads `globalThis[name]` on
|
|
200
|
-
* every access. So `import { describe } from 'vitest'` compiles to
|
|
201
|
-
* `import_vitest.describe`, whose getter returns the real `describe` only
|
|
202
|
-
* when the factory calls it — after `runTestModule` installs the globals.
|
|
203
|
-
*
|
|
204
|
-
* A plain `module.exports = new Proxy(...)` does NOT work here: esbuild routes
|
|
205
|
-
* the virtual module through `__toESM`, which enumerates own-keys (none on an
|
|
206
|
-
* empty Proxy target) and therefore exposes zero named exports. Explicit getter
|
|
207
|
-
* properties give `__toESM` real keys to map while keeping access lazy.
|
|
208
|
-
*/
|
|
209
|
-
function vitestRedirectPlugin() {
|
|
210
|
-
return {
|
|
211
|
-
name: "vitest-redirect",
|
|
212
|
-
setup(build) {
|
|
213
|
-
build.onResolve({ filter: /^vitest$/ }, () => ({
|
|
214
|
-
path: "vitest",
|
|
215
|
-
namespace: "vitest-redirect"
|
|
216
|
-
}));
|
|
217
|
-
build.onLoad({
|
|
218
|
-
filter: /^vitest$/,
|
|
219
|
-
namespace: "vitest-redirect"
|
|
220
|
-
}, () => {
|
|
221
|
-
return {
|
|
222
|
-
contents: `Object.defineProperty(exports, '__esModule', { value: true });\n${VITEST_GLOBAL_NAMES.map((name) => `Object.defineProperty(exports, ${JSON.stringify(name)}, { enumerable: true, get: function() { return globalThis[${JSON.stringify(name)}]; } });`).join("\n")}\n`,
|
|
223
|
-
loader: "js"
|
|
224
|
-
};
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* esbuild plugin that transforms the user test file into a module that exports
|
|
231
|
-
* an async `__userFactory` function. The factory defers the user's top-level
|
|
232
|
-
* test registration code (describe/it/test calls) so it only runs when
|
|
233
|
-
* `runTestModule(__userFactory)` explicitly invokes it — AFTER the runtime has
|
|
234
|
-
* installed describe/it/test/expect as globals.
|
|
235
|
-
*
|
|
236
|
-
* Algorithm:
|
|
237
|
-
* - Import declarations and re-export statements are kept at module top-level
|
|
238
|
-
* (the only valid ESM position for static `import`). A statement that spans
|
|
239
|
-
* multiple lines — e.g. a named import with one member per line:
|
|
240
|
-
* import {
|
|
241
|
-
* appLogin,
|
|
242
|
-
* getAnonymousKey,
|
|
243
|
-
* } from '@apps-in-toss/web-framework';
|
|
244
|
-
* is tracked as a single block: every line from the opening `import {` /
|
|
245
|
-
* `export {` through the closing `from '…'` (or side-effect `'…'`) line is
|
|
246
|
-
* kept together at top-level. This prevents the member lines and the
|
|
247
|
-
* closing `} from '…'` line from leaking into the factory body, which would
|
|
248
|
-
* leave an unterminated `import {` at module scope (the #678 env3 failure:
|
|
249
|
-
* esbuild threw `Expected "as" but found "{"` on multi-line SDK imports).
|
|
250
|
-
* - All other lines (describe/it/test calls, local declarations, etc.) are
|
|
251
|
-
* moved into the body of the exported async factory function.
|
|
252
|
-
*
|
|
253
|
-
* This preserves SDK import resolution (the sdk-redirect plugin processes
|
|
254
|
-
* top-level imports normally) while deferring test registration to the factory.
|
|
255
|
-
*/
|
|
256
|
-
function userFactoryPlugin(absPath) {
|
|
257
|
-
const NAMESPACE = "user-test-factory";
|
|
258
|
-
return {
|
|
259
|
-
name: "user-test-factory",
|
|
260
|
-
setup(build) {
|
|
261
|
-
build.onResolve({ filter: /^user-test-factory$/ }, () => ({
|
|
262
|
-
path: absPath,
|
|
263
|
-
namespace: NAMESPACE
|
|
264
|
-
}));
|
|
265
|
-
build.onLoad({
|
|
266
|
-
filter: /.*/,
|
|
267
|
-
namespace: NAMESPACE
|
|
268
|
-
}, async (args) => {
|
|
269
|
-
const lines = (await fs.readFile(args.path, "utf8")).split("\n");
|
|
270
|
-
const topLevelLines = [];
|
|
271
|
-
const bodyLines = [];
|
|
272
|
-
const EXPORT_DECLARATION_RE = /^(export\s+)(default\s+|async\s+function\s+|function\s+|class\s+|const\s+|let\s+|var\s+)/;
|
|
273
|
-
const isImportStart = (trimmed) => trimmed.startsWith("import ") || trimmed.startsWith("import{") || trimmed.startsWith("import'") || trimmed.startsWith("import\"");
|
|
274
|
-
const endsStatement = (trimmed) => /['"]\s*;?\s*$/.test(trimmed.replace(/\/\/.*$/, "").trimEnd());
|
|
275
|
-
let inImportBlock = false;
|
|
276
|
-
for (const line of lines) {
|
|
277
|
-
const trimmed = line.trimStart();
|
|
278
|
-
const indent = line.slice(0, line.length - trimmed.length);
|
|
279
|
-
if (inImportBlock) {
|
|
280
|
-
topLevelLines.push(line);
|
|
281
|
-
if (endsStatement(trimmed)) inImportBlock = false;
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (isImportStart(trimmed)) {
|
|
285
|
-
topLevelLines.push(line);
|
|
286
|
-
if (!endsStatement(trimmed)) inImportBlock = true;
|
|
287
|
-
} else if (trimmed.startsWith("export ")) if (trimmed.match(EXPORT_DECLARATION_RE)) bodyLines.push(indent + trimmed.slice(7));
|
|
288
|
-
else {
|
|
289
|
-
topLevelLines.push(line);
|
|
290
|
-
if (/\bfrom\b/.test(trimmed) ? !endsStatement(trimmed) : trimmed.endsWith("{")) inImportBlock = true;
|
|
291
|
-
}
|
|
292
|
-
else bodyLines.push(line);
|
|
293
|
-
}
|
|
294
|
-
return {
|
|
295
|
-
contents: [
|
|
296
|
-
...topLevelLines,
|
|
297
|
-
"",
|
|
298
|
-
"// biome-ignore lint: generated factory wrapper",
|
|
299
|
-
"export default async function __userFactory(): Promise<void> {",
|
|
300
|
-
...bodyLines.map((l) => ` ${l}`),
|
|
301
|
-
"}"
|
|
302
|
-
].join("\n"),
|
|
303
|
-
loader: "ts",
|
|
304
|
-
resolveDir: path$1.dirname(absPath)
|
|
305
|
-
};
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Returns the absolute filesystem path to a page-side leaf module shipped
|
|
312
|
-
* alongside `bundle.ts` in dist (e.g. `runtime.js`, `bridge-stub.js`) — a
|
|
313
|
-
* fully self-contained module with no further page-side deps of its own.
|
|
314
|
-
*
|
|
315
|
-
* Rolldown code-splitting duplicates this bundling logic into shared chunks
|
|
316
|
-
* emitted at ARBITRARY dist depths: the `devtools-test` CLI pulls it from
|
|
317
|
-
* dist/test-runner/bundle.js (dir = dist/test-runner/), while the `devtools-mcp`
|
|
318
|
-
* daemon (dist/mcp/cli.js) pulls it through a ROOT chunk
|
|
319
|
-
* (dist/debug-server-<hash>.js, dir = dist/). A fixed `..`-hop candidate list
|
|
320
|
-
* is therefore wrong from at least one chunk — the live #697 regression.
|
|
321
|
-
*
|
|
322
|
-
* This resolves WITHOUT assuming chunk depth: from `import.meta.url`'s dir it
|
|
323
|
-
* probes the co-located `<name>.js` and the nested `test-runner/<name>.js`,
|
|
324
|
-
* then ascends one directory at a time (bounded) repeating both probes. The
|
|
325
|
-
* nested probe catches dist/test-runner/<name>.js from the dist/ root level no
|
|
326
|
-
* matter which depth the chunk was hoisted to (root, dist/mcp/, or a future
|
|
327
|
-
* relocation). The build always emits dist/test-runner/<name>.js (tsdown entry
|
|
328
|
-
* `'test-runner/<name>'`; guarded by scripts/check-test-runner-dist.sh for
|
|
329
|
-
* `runtime`).
|
|
330
|
-
*
|
|
331
|
-
* An ABSOLUTE path is returned deliberately: esbuild loads it as a literal file
|
|
332
|
-
* read, bypassing Node module resolution entirely, so this works identically in
|
|
333
|
-
* the npx-daemon context (its own dist tree) and the consumer-CLI context
|
|
334
|
-
* (the mini-app's installed @ait-co/devtools dist) — neither needs the package
|
|
335
|
-
* to be node-resolvable from the caller.
|
|
336
|
-
*
|
|
337
|
-
* @param moduleName - The leaf module's basename without extension, e.g.
|
|
338
|
-
* `'runtime'` or `'bridge-stub'`.
|
|
339
|
-
*/
|
|
340
|
-
function getPageSideModulePath(moduleName) {
|
|
341
|
-
const startDir = path$1.dirname(fileURLToPath(import.meta.url));
|
|
342
|
-
const RELATIVE_PROBES = [
|
|
343
|
-
[`${moduleName}.js`],
|
|
344
|
-
["test-runner", `${moduleName}.js`],
|
|
345
|
-
[`${moduleName}.ts`],
|
|
346
|
-
["test-runner", `${moduleName}.ts`]
|
|
347
|
-
];
|
|
348
|
-
let dir = startDir;
|
|
349
|
-
for (let i = 0; i < 12; i++) {
|
|
350
|
-
for (const segs of RELATIVE_PROBES) {
|
|
351
|
-
const candidate = path$1.join(dir, ...segs);
|
|
352
|
-
try {
|
|
353
|
-
accessSync(candidate);
|
|
354
|
-
return candidate;
|
|
355
|
-
} catch {}
|
|
356
|
-
}
|
|
357
|
-
const parent = path$1.dirname(dir);
|
|
358
|
-
if (parent === dir) break;
|
|
359
|
-
dir = parent;
|
|
360
|
-
}
|
|
361
|
-
return path$1.join(startDir, `${moduleName}.js`);
|
|
362
|
-
}
|
|
363
|
-
/** Absolute path to the test-runner page-side runtime (describe/it/test/expect). */
|
|
364
|
-
function getRuntimePath() {
|
|
365
|
-
return getPageSideModulePath("runtime");
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Absolute path to the bridge-stub interceptor (devtools#740, DT-2) —
|
|
369
|
-
* `wrapSdkWithStub`/`isStubBlockingEnabled`, statically imported by the
|
|
370
|
-
* `sdk-redirect` virtual module.
|
|
371
|
-
*/
|
|
372
|
-
function getBridgeStubPath() {
|
|
373
|
-
return getPageSideModulePath("bridge-stub");
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Absolute path to the per-method pacing wrapper (devtools#769) —
|
|
377
|
-
* `wrapWithMethodPacing`/`getPaceMethodMs`, statically imported by the
|
|
378
|
-
* `sdk-redirect` virtual module.
|
|
379
|
-
*/
|
|
380
|
-
function getMethodPacePath() {
|
|
381
|
-
return getPageSideModulePath("method-pace");
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Bundles `absPath` into a single IIFE string suitable for `Runtime.evaluate`.
|
|
385
|
-
*
|
|
386
|
-
* The IIFE installs `window.__testBundle` (or the custom `globalName`) with:
|
|
387
|
-
* - `runTestModule` — the runtime entry (from `runtime.ts`).
|
|
388
|
-
* - `__userFactory` — an async function wrapping the user's test registration
|
|
389
|
-
* code so it runs AFTER `runTestModule` installs the globals.
|
|
390
|
-
*
|
|
391
|
-
* Callers (rpc.ts) invoke:
|
|
392
|
-
* `globalThis.__testBundle.runTestModule(globalThis.__testBundle.__userFactory)`
|
|
393
|
-
*
|
|
394
|
-
* @param absPath - Absolute path to the user test file.
|
|
395
|
-
* @param opts - Optional bundling overrides.
|
|
396
|
-
*/
|
|
397
|
-
async function bundleTestFile(absPath, opts) {
|
|
398
|
-
const globalName = opts?.globalName ?? "__testBundle";
|
|
399
|
-
const extraExternals = opts?.extraExternals ?? [];
|
|
400
|
-
const esbuild = await import("esbuild");
|
|
401
|
-
const runtimePath = getRuntimePath();
|
|
402
|
-
const wrapperContent = [
|
|
403
|
-
`import { runTestModule } from ${JSON.stringify(runtimePath)};`,
|
|
404
|
-
`import __userFactory from "user-test-factory";`,
|
|
405
|
-
`export { runTestModule, __userFactory };`
|
|
406
|
-
].join("\n");
|
|
407
|
-
const result = await esbuild.build({
|
|
408
|
-
stdin: {
|
|
409
|
-
contents: wrapperContent,
|
|
410
|
-
loader: "ts",
|
|
411
|
-
resolveDir: path$1.dirname(absPath)
|
|
412
|
-
},
|
|
413
|
-
bundle: true,
|
|
414
|
-
format: "iife",
|
|
415
|
-
globalName,
|
|
416
|
-
platform: "browser",
|
|
417
|
-
target: "es2022",
|
|
418
|
-
write: false,
|
|
419
|
-
plugins: [
|
|
420
|
-
userFactoryPlugin(absPath),
|
|
421
|
-
vitestRedirectPlugin(),
|
|
422
|
-
sdkRedirectPlugin()
|
|
423
|
-
],
|
|
424
|
-
external: extraExternals,
|
|
425
|
-
treeShaking: true,
|
|
426
|
-
footer: { js: `globalThis[${JSON.stringify(globalName)}] = ${globalName};` }
|
|
427
|
-
});
|
|
428
|
-
const warnings = result.warnings.map((w) => `${path$1.relative(process.cwd(), w.location?.file ?? "")}:${w.location?.line ?? "?"}: ${w.text}`);
|
|
429
|
-
const outputFile = result.outputFiles?.[0];
|
|
430
|
-
if (!outputFile) throw new Error("bundleTestFile: esbuild produced no output — check entryPoints");
|
|
431
|
-
return {
|
|
432
|
-
code: outputFile.text,
|
|
433
|
-
warnings
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
//#endregion
|
|
437
|
-
export { buildSdkRedirectModuleContents, bundleTestFile };
|
|
438
|
-
|
|
439
|
-
//# sourceMappingURL=bundle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","names":["path"],"sources":["../../src/test-runner/bundle.ts"],"sourcesContent":["/**\n * esbuild-based bundler for user test files.\n *\n * Bundles a single test file into a self-contained IIFE string that can be\n * injected into a WebView via `Runtime.evaluate`. The bundle includes the\n * test runtime (`runtime.ts`), which provides `describe/it/test/expect` and\n * the `runTestModule(factory)` entry point.\n *\n * ## How the wiring works\n *\n * The bundle exposes two exports on `globalThis.__testBundle`:\n * - `runTestModule` — the runtime's entry function.\n * - `__userFactory` — an async function whose body is the user's top-level\n * test registration code (describe/it/test calls).\n *\n * The Node-side RPC (`rpc.ts`) calls:\n * `globalThis.__testBundle.runTestModule(globalThis.__testBundle.__userFactory)`\n *\n * `runTestModule` then installs `describe/it/test/expect` as globals, invokes\n * the factory (which registers all tests), runs them, and returns a `RunReport`.\n *\n * ## Why a factory wrapper is needed\n *\n * Naively adding the runtime to `entryPoints` and bundling the user file would\n * fail for two reasons:\n * 1. `describe/it/test/expect` from the runtime are module-local in the IIFE\n * scope. The user's top-level `describe(...)` calls expect them as globals —\n * they are not globals until `runTestModule` installs them.\n * 2. Even with globals pre-installed, the user file runs at IIFE-evaluation\n * time, before the RPC layer calls `runTestModule` to reset state and start\n * the test clock.\n *\n * The factory approach solves both: the user's registration code is deferred\n * into a function that `runTestModule` calls AFTER installing the globals.\n *\n * ## Factory extraction algorithm\n *\n * The `userFactoryPlugin` reads the user file and splits lines into:\n * - **top-level**: `import …` and re-export lines — kept at module scope\n * (the only valid position for static `import` in ESM).\n * - **body**: all other statements — moved into the body of the exported\n * `__userFactory` async function.\n *\n * esbuild processes the re-generated module, following each static import\n * through the normal dependency graph (including the SDK-redirect plugin).\n *\n * ## SDK redirect\n *\n * Imports of `@apps-in-toss/web-framework` (and sub-paths) are intercepted via\n * the `sdkRedirectPlugin` and replaced with a virtual `window.__sdk` proxy that\n * `src/in-app/auto.ts` installs at runtime. This works for both 2.x and 3.x SDK.\n *\n * SECRET-HANDLING: the returned bundle code is caller-managed; never log it.\n */\n\nimport { accessSync } from 'node:fs';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n// esbuild is imported for TYPES only at module scope; the runtime module is\n// loaded lazily inside `bundleTestFile` via dynamic import. esbuild runs a\n// startup invariant check (`TextEncoder().encode('') instanceof Uint8Array`)\n// that fails in a jsdom realm — a static import would break every MCP/test\n// module that merely *imports* this file's transitive graph (e.g. debug-server →\n// run_tests). Lazy load keeps esbuild off the import graph until a bundle is\n// actually built, and mirrors the cloudflared/chii dynamic-import precedent.\nimport type * as esbuild from 'esbuild';\n\n/** Options accepted by `bundleTestFile`. */\nexport interface BundleOptions {\n /**\n * Additional esbuild `external` patterns. The SDK package\n * (`@apps-in-toss/web-framework` and `@apps-in-toss/web-framework/*`) is\n * always handled by the SDK redirect plugin — callers may add more patterns\n * to be left as globals.\n */\n extraExternals?: string[];\n /**\n * Global name for the IIFE output object. Defaults to `__testBundle`.\n * The runtime entry uses this to call `__testBundle.runTestModule(__userFactory)`.\n */\n globalName?: string;\n}\n\n/**\n * The result of bundling a test file.\n * `code` is a self-contained IIFE string ready for `Runtime.evaluate`.\n */\nexport interface BundleResult {\n code: string;\n warnings: string[];\n}\n\n/** The SDK package name that mini-app test code imports from. */\nconst SDK_PACKAGE = '@apps-in-toss/web-framework';\n\n/**\n * Names the runtime installs as globals before invoking the user factory.\n * The `vitest` virtual module re-exports each as a lazy getter that reads from\n * `globalThis` at access time. Keep in sync with the globals installed in\n * `runtime.ts#runTestModule`.\n */\nconst VITEST_GLOBAL_NAMES = [\n 'describe',\n 'it',\n 'test',\n 'expect',\n 'beforeAll',\n 'afterAll',\n 'beforeEach',\n 'afterEach',\n 'vi',\n] as const;\n\n/**\n * Matches the bare SDK package and any sub-path import\n * (`@apps-in-toss/web-framework`, `@apps-in-toss/web-framework/foo`).\n * Built from {@link SDK_PACKAGE} so the package name has a single source.\n */\nconst SDK_IMPORT_FILTER = new RegExp(`^${SDK_PACKAGE.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}`);\n\n/**\n * esbuild plugin that intercepts SDK imports and redirects them to the\n * `window.__sdk` proxy that `src/in-app/auto.ts` installs at runtime.\n *\n * Strategy: for every import of `@apps-in-toss/web-framework` (or sub-paths),\n * esbuild resolves it to a virtual module that re-exports all named exports\n * via `window.__sdk[name]`. This avoids bundling the real SDK (which may not\n * be available in the test environment) while still making named imports work.\n *\n * If `window.__sdk` is absent (non-dog-food build), every access throws a\n * descriptive error rather than returning `undefined` silently.\n *\n * Bridge-stub interception (devtools#740, DT-2): the virtual module runs the\n * resolved `window.__sdk` object through `wrapSdkWithStub` before exporting\n * it. `wrapSdkWithStub` is a pass-through (returns the same object,\n * unwrapped) unless `isStubBlockingEnabled()` reads `true` off\n * `globalThis.__AIT_STUB_BLOCKING__` — an opt-in flag injected the same way\n * `__AIT_CELL__` is (`cell.ts#injectGlobals`, wired from the CLI's\n * `--stub-blocking` flag). Default off => zero behavior change: every existing\n * (non-stub) test run resolves the exact same `window.__sdk` reference it did\n * before this plugin learned about stubbing.\n *\n * Per-method pacing (devtools#769): BEFORE the stub wrap, `window.__sdk` is\n * run through `wrapWithMethodPacing`, which enforces a minimum interval\n * between calls to the SAME named SDK function (`getPaceMethodMs()` reads the\n * `__AIT_PACE_METHOD_MS__` page global — see `method-pace.ts`). Composition\n * order is pacing INSIDE the stub (`wrapSdkWithStub(wrapWithMethodPacing(sdk,\n * gap), enabled)`): a stubbed name resolves instantly from\n * `bridge-stub.ts`'s fixtures without ever reaching the paced wrapper, and\n * only calls that fall through to the real bridge — the ones that can\n * actually trigger `APP_BRIDGE_THROTTLED` — pay the pacing cost. `gapMs <= 0`\n * (default, no `--pace-method` / non-2.x cell) is a no-op fast path — see\n * `method-pace.ts#wrapWithMethodPacing`'s doc for the full contract.\n */\n/**\n * Builds the virtual CommonJS-style module contents the `sdk-redirect`\n * esbuild plugin loads for every `@apps-in-toss/web-framework` import.\n *\n * Pulled out to a pure, exported function (rather than inlined at the\n * `build.onLoad` call site) so unit tests can assert the exact composition\n * order (pacing wraps the raw SDK; the stub wraps the paced result) as a\n * string-level contract, independent of esbuild — esbuild cannot run inside\n * this repo's jsdom vitest environment (see `bundleTestFile`'s module doc's\n * lazy-import note), so a real bundling round-trip is out of unit-test reach\n * here; `wrapSdkWithStub`/`wrapWithMethodPacing`'s own composed-call behavior\n * is covered directly (see `bundle.test.ts`).\n *\n * Generates a virtual CommonJS-style module so that esbuild does NOT perform\n * strict named-export matching. When `format:'iife'` bundles a CJS module, it\n * wraps it with its own `__toCommonJS` helper and satisfies named imports via\n * property access on the `module.exports` object — which is our Proxy. This\n * means `import { getPlatformOS } from '...'` becomes\n * `__proxy.getPlatformOS` at runtime, which correctly reads from\n * `window.__sdk`.\n *\n * The bridge-stub and method-pace imports are STATIC imports of the real\n * `bridge-stub.ts`/`method-pace.ts` modules (not inlined JS) so esbuild\n * bundles each once and the fixture registry / pacing registry have a single\n * source of truth shared with their own unit tests.\n *\n * Exported for unit testing.\n */\nexport function buildSdkRedirectModuleContents(): string {\n return `\nimport { wrapSdkWithStub, isStubBlockingEnabled } from ${JSON.stringify(getBridgeStubPath())};\nimport { wrapWithMethodPacing, getPaceMethodMs } from ${JSON.stringify(getMethodPacePath())};\nvar __rawSdk = (typeof window !== 'undefined' && window.__sdk)\n ? window.__sdk\n : new Proxy({}, {\n get: function(_t, p) {\n throw new Error('window.__sdk is not installed — run in a dog-food build. Missing: ' + String(p));\n }\n });\nvar __pacedSdk = wrapWithMethodPacing(__rawSdk, getPaceMethodMs());\nvar __proxy = wrapSdkWithStub(__pacedSdk, isStubBlockingEnabled());\nmodule.exports = __proxy;\n`;\n}\n\nfunction sdkRedirectPlugin(): esbuild.Plugin {\n return {\n name: 'sdk-redirect',\n setup(build) {\n // Match the bare package and any sub-path imports\n build.onResolve({ filter: SDK_IMPORT_FILTER }, (args) => ({\n path: args.path,\n namespace: 'sdk-redirect',\n }));\n\n build.onLoad({ filter: /.*/, namespace: 'sdk-redirect' }, () => ({\n contents: buildSdkRedirectModuleContents(),\n loader: 'js',\n // resolveDir is required so esbuild can resolve the absolute\n // getBridgeStubPath()/getMethodPacePath() imports above from a\n // filesystem base — a virtual module has no implicit directory of\n // its own. process.cwd() is a safe base for an ABSOLUTE import\n // specifier (it is never used to resolve anything relative).\n resolveDir: process.cwd(),\n }));\n },\n };\n}\n\n/**\n * esbuild plugin that intercepts `import … from 'vitest'` and replaces it with\n * a virtual module that delegates every named import to `globalThis` at ACCESS\n * time (not at bundle-evaluation time).\n *\n * The runtime installs `describe/it/test/expect/beforeAll/afterAll/beforeEach/\n * afterEach/vi` as globals inside `runTestModule`, which runs AFTER the bundle\n * IIFE is evaluated. A value-copy redirect (`export var describe =\n * globalThis.describe`) would therefore capture `undefined` at evaluation time\n * and the user's `describe(...)` calls would be no-ops — registering zero tests.\n *\n * The fix defers the lookup to call time using per-name **getter** exports.\n * We emit a CommonJS module that:\n * 1. sets `__esModule = true` so esbuild's `__toESM` interop maps each named\n * import directly to a property access on the module (NOT wrapped under a\n * `default` shim — which is what happens for a bare Proxy whose own-keys\n * are empty, leaving every named import `undefined`);\n * 2. defines each global name as a getter that reads `globalThis[name]` on\n * every access. So `import { describe } from 'vitest'` compiles to\n * `import_vitest.describe`, whose getter returns the real `describe` only\n * when the factory calls it — after `runTestModule` installs the globals.\n *\n * A plain `module.exports = new Proxy(...)` does NOT work here: esbuild routes\n * the virtual module through `__toESM`, which enumerates own-keys (none on an\n * empty Proxy target) and therefore exposes zero named exports. Explicit getter\n * properties give `__toESM` real keys to map while keeping access lazy.\n */\nfunction vitestRedirectPlugin(): esbuild.Plugin {\n return {\n name: 'vitest-redirect',\n setup(build) {\n build.onResolve({ filter: /^vitest$/ }, () => ({\n path: 'vitest',\n namespace: 'vitest-redirect',\n }));\n\n build.onLoad({ filter: /^vitest$/, namespace: 'vitest-redirect' }, () => {\n const getters = VITEST_GLOBAL_NAMES.map(\n (name) =>\n `Object.defineProperty(exports, ${JSON.stringify(name)}, { enumerable: true, get: function() { return globalThis[${JSON.stringify(name)}]; } });`,\n ).join('\\n');\n // __esModule lets esbuild __toESM map named imports to these getters\n // directly. Each getter reads globalThis lazily so the value resolves at\n // call time — after runTestModule installs the globals.\n return {\n contents: `Object.defineProperty(exports, '__esModule', { value: true });\\n${getters}\\n`,\n loader: 'js',\n };\n });\n },\n };\n}\n\n/**\n * esbuild plugin that transforms the user test file into a module that exports\n * an async `__userFactory` function. The factory defers the user's top-level\n * test registration code (describe/it/test calls) so it only runs when\n * `runTestModule(__userFactory)` explicitly invokes it — AFTER the runtime has\n * installed describe/it/test/expect as globals.\n *\n * Algorithm:\n * - Import declarations and re-export statements are kept at module top-level\n * (the only valid ESM position for static `import`). A statement that spans\n * multiple lines — e.g. a named import with one member per line:\n * import {\n * appLogin,\n * getAnonymousKey,\n * } from '@apps-in-toss/web-framework';\n * is tracked as a single block: every line from the opening `import {` /\n * `export {` through the closing `from '…'` (or side-effect `'…'`) line is\n * kept together at top-level. This prevents the member lines and the\n * closing `} from '…'` line from leaking into the factory body, which would\n * leave an unterminated `import {` at module scope (the #678 env3 failure:\n * esbuild threw `Expected \"as\" but found \"{\"` on multi-line SDK imports).\n * - All other lines (describe/it/test calls, local declarations, etc.) are\n * moved into the body of the exported async factory function.\n *\n * This preserves SDK import resolution (the sdk-redirect plugin processes\n * top-level imports normally) while deferring test registration to the factory.\n */\nfunction userFactoryPlugin(absPath: string): esbuild.Plugin {\n const NAMESPACE = 'user-test-factory';\n return {\n name: 'user-test-factory',\n setup(build) {\n // Resolve the virtual \"user-test-factory\" specifier to our namespace.\n build.onResolve({ filter: /^user-test-factory$/ }, () => ({\n path: absPath,\n namespace: NAMESPACE,\n }));\n\n // Load the user file, split imports from body, wrap body in the factory.\n build.onLoad({ filter: /.*/, namespace: NAMESPACE }, async (args) => {\n const source = await fs.readFile(args.path, 'utf8');\n const lines = source.split('\\n');\n\n const topLevelLines: string[] = [];\n const bodyLines: string[] = [];\n\n // Matches `export` value declarations that cannot appear inside a\n // function body. We strip the `export` keyword so they become plain\n // declarations inside the factory.\n const EXPORT_DECLARATION_RE =\n /^(export\\s+)(default\\s+|async\\s+function\\s+|function\\s+|class\\s+|const\\s+|let\\s+|var\\s+)/;\n\n // True when `trimmed` begins a static `import` statement.\n const isImportStart = (trimmed: string): boolean =>\n trimmed.startsWith('import ') ||\n trimmed.startsWith('import{') ||\n trimmed.startsWith(\"import'\") ||\n trimmed.startsWith('import\"');\n\n // A module-scope `import`/`export … from` statement is \"complete\" on a\n // single line when it ends with a quoted module specifier (optionally\n // followed by `;`/whitespace), e.g. `… from '@x';` or side-effect\n // `import './x';`. A line ending in `{` or `,` (the common multi-line\n // named-import shape) is therefore NOT complete and must accumulate\n // further lines until the closing `from '…'` line.\n const endsStatement = (trimmed: string): boolean =>\n /['\"]\\s*;?\\s*$/.test(trimmed.replace(/\\/\\/.*$/, '').trimEnd());\n\n // When set, we are inside an unterminated multi-line import/re-export\n // block: every subsequent line stays at top level until the block ends.\n let inImportBlock = false;\n\n for (const line of lines) {\n const trimmed = line.trimStart();\n const indent = line.slice(0, line.length - trimmed.length);\n\n // Continuation of a multi-line import / re-export block — keep at\n // top level. The block ends on the line that terminates the\n // statement (closing `from '…'` / side-effect `'…'`).\n if (inImportBlock) {\n topLevelLines.push(line);\n if (endsStatement(trimmed)) {\n inImportBlock = false;\n }\n continue;\n }\n\n // Static import declarations must stay at module top level\n // (the ESM spec forbids `import` inside a function body). If the\n // statement does not terminate on this line, open an import block so\n // the member lines and closing `} from '…'` line stay top-level too.\n if (isImportStart(trimmed)) {\n topLevelLines.push(line);\n if (!endsStatement(trimmed)) {\n inImportBlock = true;\n }\n } else if (trimmed.startsWith('export ')) {\n // Determine whether this is a re-export (stays top-level) or a value\n // declaration (goes into the factory, export keyword stripped).\n const m = trimmed.match(EXPORT_DECLARATION_RE);\n if (m) {\n // Value declaration — strip `export ` and move into factory body.\n // e.g. `export function hello()` → `function hello()`\n // `export const x = 1` → `const x = 1`\n bodyLines.push(indent + trimmed.slice('export '.length));\n } else {\n // Re-export or `export type { … }` — stays at top level. A\n // multi-line `export { … } from '…'` opens an import block too.\n topLevelLines.push(line);\n if (/\\bfrom\\b/.test(trimmed) ? !endsStatement(trimmed) : trimmed.endsWith('{')) {\n inImportBlock = true;\n }\n }\n } else {\n bodyLines.push(line);\n }\n }\n\n const factoryContent = [\n ...topLevelLines,\n '',\n '// biome-ignore lint: generated factory wrapper',\n 'export default async function __userFactory(): Promise<void> {',\n ...bodyLines.map((l) => ` ${l}`),\n '}',\n ].join('\\n');\n\n return {\n contents: factoryContent,\n loader: 'ts',\n resolveDir: path.dirname(absPath),\n };\n });\n },\n };\n}\n\n/**\n * Returns the absolute filesystem path to a page-side leaf module shipped\n * alongside `bundle.ts` in dist (e.g. `runtime.js`, `bridge-stub.js`) — a\n * fully self-contained module with no further page-side deps of its own.\n *\n * Rolldown code-splitting duplicates this bundling logic into shared chunks\n * emitted at ARBITRARY dist depths: the `devtools-test` CLI pulls it from\n * dist/test-runner/bundle.js (dir = dist/test-runner/), while the `devtools-mcp`\n * daemon (dist/mcp/cli.js) pulls it through a ROOT chunk\n * (dist/debug-server-<hash>.js, dir = dist/). A fixed `..`-hop candidate list\n * is therefore wrong from at least one chunk — the live #697 regression.\n *\n * This resolves WITHOUT assuming chunk depth: from `import.meta.url`'s dir it\n * probes the co-located `<name>.js` and the nested `test-runner/<name>.js`,\n * then ascends one directory at a time (bounded) repeating both probes. The\n * nested probe catches dist/test-runner/<name>.js from the dist/ root level no\n * matter which depth the chunk was hoisted to (root, dist/mcp/, or a future\n * relocation). The build always emits dist/test-runner/<name>.js (tsdown entry\n * `'test-runner/<name>'`; guarded by scripts/check-test-runner-dist.sh for\n * `runtime`).\n *\n * An ABSOLUTE path is returned deliberately: esbuild loads it as a literal file\n * read, bypassing Node module resolution entirely, so this works identically in\n * the npx-daemon context (its own dist tree) and the consumer-CLI context\n * (the mini-app's installed @ait-co/devtools dist) — neither needs the package\n * to be node-resolvable from the caller.\n *\n * @param moduleName - The leaf module's basename without extension, e.g.\n * `'runtime'` or `'bridge-stub'`.\n */\nfunction getPageSideModulePath(moduleName: string): string {\n const startDir = path.dirname(fileURLToPath(import.meta.url));\n // .js first so a SHIPPED chunk never feeds esbuild raw TypeScript; the .ts\n // probe is last, for the source-tree (tsx) dev case where the module sits\n // beside bundle.ts and no dist exists.\n const RELATIVE_PROBES: string[][] = [\n [`${moduleName}.js`],\n ['test-runner', `${moduleName}.js`],\n [`${moduleName}.ts`],\n ['test-runner', `${moduleName}.ts`],\n ];\n // Bounded ascent: a package's dist is only a few levels deep. 12 is far more\n // than any real layout (root chunk → dist is 0 hops; dist/mcp → dist is 1)\n // and terminates well before the filesystem root in every case.\n let dir = startDir;\n for (let i = 0; i < 12; i++) {\n for (const segs of RELATIVE_PROBES) {\n const candidate = path.join(dir, ...segs);\n try {\n accessSync(candidate);\n return candidate;\n } catch {\n // try next probe\n }\n }\n const parent = path.dirname(dir);\n if (parent === dir) break; // reached filesystem root\n dir = parent;\n }\n // Nothing matched — return the co-located path so esbuild emits a clear\n // \"Could not resolve\" against a concrete path rather than failing cryptically.\n return path.join(startDir, `${moduleName}.js`);\n}\n\n/** Absolute path to the test-runner page-side runtime (describe/it/test/expect). */\nfunction getRuntimePath(): string {\n return getPageSideModulePath('runtime');\n}\n\n/**\n * Absolute path to the bridge-stub interceptor (devtools#740, DT-2) —\n * `wrapSdkWithStub`/`isStubBlockingEnabled`, statically imported by the\n * `sdk-redirect` virtual module.\n */\nfunction getBridgeStubPath(): string {\n return getPageSideModulePath('bridge-stub');\n}\n\n/**\n * Absolute path to the per-method pacing wrapper (devtools#769) —\n * `wrapWithMethodPacing`/`getPaceMethodMs`, statically imported by the\n * `sdk-redirect` virtual module.\n */\nfunction getMethodPacePath(): string {\n return getPageSideModulePath('method-pace');\n}\n\n/**\n * Bundles `absPath` into a single IIFE string suitable for `Runtime.evaluate`.\n *\n * The IIFE installs `window.__testBundle` (or the custom `globalName`) with:\n * - `runTestModule` — the runtime entry (from `runtime.ts`).\n * - `__userFactory` — an async function wrapping the user's test registration\n * code so it runs AFTER `runTestModule` installs the globals.\n *\n * Callers (rpc.ts) invoke:\n * `globalThis.__testBundle.runTestModule(globalThis.__testBundle.__userFactory)`\n *\n * @param absPath - Absolute path to the user test file.\n * @param opts - Optional bundling overrides.\n */\nexport async function bundleTestFile(absPath: string, opts?: BundleOptions): Promise<BundleResult> {\n const globalName = opts?.globalName ?? '__testBundle';\n const extraExternals = opts?.extraExternals ?? [];\n\n // Lazy load esbuild at call time (see the module-scope import note).\n const esbuild = await import('esbuild');\n const runtimePath = getRuntimePath();\n\n // Stdin wrapper: import the runtime and the user factory, re-export both.\n // esbuild follows the static imports to include runtime.ts and the user file\n // (via the userFactoryPlugin) in the single IIFE output.\n const wrapperContent = [\n `import { runTestModule } from ${JSON.stringify(runtimePath)};`,\n `import __userFactory from \"user-test-factory\";`,\n `export { runTestModule, __userFactory };`,\n ].join('\\n');\n\n const result = await esbuild.build({\n stdin: {\n contents: wrapperContent,\n loader: 'ts',\n // resolveDir is used for relative imports from the wrapper. Since the\n // wrapper only imports absolute paths (runtimePath) and the virtual\n // \"user-test-factory\" specifier (resolved by plugin), the directory\n // doesn't matter — but we still provide a sensible default.\n resolveDir: path.dirname(absPath),\n },\n bundle: true,\n format: 'iife',\n globalName,\n platform: 'browser',\n target: 'es2022',\n write: false,\n plugins: [userFactoryPlugin(absPath), vitestRedirectPlugin(), sdkRedirectPlugin()],\n external: extraExternals,\n treeShaking: true,\n // Ensure the IIFE result is always reachable via globalThis regardless of\n // the evaluation context. esbuild's `globalName` emits:\n // var __testBundle = (() => { ... })();\n // When `Runtime.evaluate` runs this bundle code inside an outer wrapper\n // (rpc.ts's async IIFE), `var` creates a local variable — NOT a global\n // property — so `globalThis.__testBundle` stays `undefined`. The footer\n // explicitly assigns the local variable to `globalThis` to close that gap.\n footer: {\n js: `globalThis[${JSON.stringify(globalName)}] = ${globalName};`,\n },\n });\n\n const warnings = result.warnings.map(\n (w) =>\n `${path.relative(process.cwd(), w.location?.file ?? '')}:${w.location?.line ?? '?'}: ${w.text}`,\n );\n\n const outputFile = result.outputFiles?.[0];\n if (!outputFile) {\n throw new Error('bundleTestFile: esbuild produced no output — check entryPoints');\n }\n\n return { code: outputFile.text, warnings };\n}\n"],"mappings":";;;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GAKR,YAAYA,OAAK,QAAQ,QAAQ;GAClC;EACD,QAAQ;EACR,QAAQ;EACR;EACA,UAAU;EACV,QAAQ;EACR,OAAO;EACP,SAAS;GAAC,kBAAkB,QAAQ;GAAE,sBAAsB;GAAE,mBAAmB;GAAC;EAClF,UAAU;EACV,aAAa;EAQb,QAAQ,EACN,IAAI,cAAc,KAAK,UAAU,WAAW,CAAC,MAAM,WAAW,IAC/D;EACF,CAAC;CAEF,MAAM,WAAW,OAAO,SAAS,KAC9B,MACC,GAAGA,OAAK,SAAS,QAAQ,KAAK,EAAE,EAAE,UAAU,QAAQ,GAAG,CAAC,GAAG,EAAE,UAAU,QAAQ,IAAI,IAAI,EAAE,OAC5F;CAED,MAAM,aAAa,OAAO,cAAc;AACxC,KAAI,CAAC,WACH,OAAM,IAAI,MAAM,iEAAiE;AAGnF,QAAO;EAAE,MAAM,WAAW;EAAM;EAAU"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region src/test-runner/capture.ts
|
|
2
|
-
/** The exact console-line prefix sdk-example's `flushCapture` emits. */
|
|
3
|
-
const CAPTURE_PREFIX = "__AIT_CAPTURE__ ";
|
|
4
|
-
/**
|
|
5
|
-
* Parses raw console line texts into {@link AitCaptureLine}s.
|
|
6
|
-
*
|
|
7
|
-
* Filtering rules (each independently drops a line — never throws):
|
|
8
|
-
* - the line text must `startsWith(CAPTURE_PREFIX)` exactly (allowlist);
|
|
9
|
-
* - there must be a non-empty category token (up to the next space);
|
|
10
|
-
* - the remaining payload must be valid JSON (`JSON.parse` succeeds).
|
|
11
|
-
*
|
|
12
|
-
* Lines that fail any rule (wss/scheme noise, truncated, broken JSON) are
|
|
13
|
-
* silently discarded — capture harvesting is best-effort and must never fail a
|
|
14
|
-
* run or leak a malformed/secret-bearing line.
|
|
15
|
-
*
|
|
16
|
-
* @param raw - Console line objects (only `.text` is read).
|
|
17
|
-
* @returns The captured lines, in input order.
|
|
18
|
-
*/
|
|
19
|
-
function parseCaptureLines(raw) {
|
|
20
|
-
const out = [];
|
|
21
|
-
for (const { text } of raw) {
|
|
22
|
-
if (!text.startsWith(CAPTURE_PREFIX)) continue;
|
|
23
|
-
const body = text.slice(16);
|
|
24
|
-
const spaceIdx = body.indexOf(" ");
|
|
25
|
-
if (spaceIdx === -1) continue;
|
|
26
|
-
const category = body.slice(0, spaceIdx);
|
|
27
|
-
const json = body.slice(spaceIdx + 1);
|
|
28
|
-
if (category === "" || json === "") continue;
|
|
29
|
-
try {
|
|
30
|
-
JSON.parse(json);
|
|
31
|
-
} catch {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
out.push({
|
|
35
|
-
category,
|
|
36
|
-
json
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { parseCaptureLines };
|
|
43
|
-
|
|
44
|
-
//# sourceMappingURL=capture.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capture.js","names":[],"sources":["../../src/test-runner/capture.ts"],"sourcesContent":["/**\n * `__AIT_CAPTURE__` console-line parser (devtools#696).\n *\n * env3 test runs inject sdk-example's `aitCapture.ts`, which — when running in a\n * WebView (no filesystem) — emits one `console.log` line per category in the\n * stable form:\n *\n * __AIT_CAPTURE__ <category> <json>\n *\n * The relay-worker harvests `Runtime.consoleAPICalled` events as plain text\n * lines (see `relay-worker.ts`) and hands them here. This module's only job is\n * to recognise the allowlisted prefix, split off the category, and keep the\n * remaining JSON string OPAQUE — devtools does NOT own or interpret the\n * `__AIT_CAPTURE__` record shape (that lives in sdk-example). We carry\n * `{ category, json }` through untouched so the 2.x↔3.0 line comparison stays a\n * downstream concern.\n *\n * Why a strict allowlist prefix (SECRET-HANDLING): the raw console stream may\n * also contain wss/scheme/relay noise lines. Only lines that EXACTLY start with\n * `'__AIT_CAPTURE__ '` pass; everything else is discarded, so a stray relay URL\n * can never be serialised into a capture artifact.\n *\n * react-free, dependency-free — safe to import from any test-runner entry\n * without dragging in the chii/cloudflared Node graph.\n */\n\n/**\n * One parsed capture line. `json` is the raw JSON string exactly as the page\n * emitted it (an array of sdk-example capture records). devtools treats it as\n * opaque — it is validated as parseable JSON but never inspected.\n */\nexport interface AitCaptureLine {\n /** The capture category (first whitespace-delimited token after the prefix). */\n category: string;\n /** The remaining JSON payload, verbatim. Opaque to devtools. */\n json: string;\n}\n\n/** The exact console-line prefix sdk-example's `flushCapture` emits. */\nconst CAPTURE_PREFIX = '__AIT_CAPTURE__ ';\n\n/**\n * Parses raw console line texts into {@link AitCaptureLine}s.\n *\n * Filtering rules (each independently drops a line — never throws):\n * - the line text must `startsWith(CAPTURE_PREFIX)` exactly (allowlist);\n * - there must be a non-empty category token (up to the next space);\n * - the remaining payload must be valid JSON (`JSON.parse` succeeds).\n *\n * Lines that fail any rule (wss/scheme noise, truncated, broken JSON) are\n * silently discarded — capture harvesting is best-effort and must never fail a\n * run or leak a malformed/secret-bearing line.\n *\n * @param raw - Console line objects (only `.text` is read).\n * @returns The captured lines, in input order.\n */\nexport function parseCaptureLines(raw: ReadonlyArray<{ text: string }>): AitCaptureLine[] {\n const out: AitCaptureLine[] = [];\n for (const { text } of raw) {\n // Allowlist: only the exact `__AIT_CAPTURE__ ` prefix passes. wss/scheme\n // noise lines are dropped here (SECRET-HANDLING).\n if (!text.startsWith(CAPTURE_PREFIX)) continue;\n\n const body = text.slice(CAPTURE_PREFIX.length);\n const spaceIdx = body.indexOf(' ');\n // No payload separator → malformed; drop.\n if (spaceIdx === -1) continue;\n\n const category = body.slice(0, spaceIdx);\n const json = body.slice(spaceIdx + 1);\n if (category === '' || json === '') continue;\n\n // Validate the payload is parseable JSON, but keep it as an OPAQUE string —\n // devtools does not own the record shape. Broken JSON is discarded (no throw).\n try {\n JSON.parse(json);\n } catch {\n continue;\n }\n\n out.push({ category, json });\n }\n return out;\n}\n"],"mappings":";;AAuCA,MAAM,iBAAiB;;;;;;;;;;;;;;;;AAiBvB,SAA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BAAA,CAAsB,UAAA,GAAa,mBAAA,GAAsB,eAAA;;AAAzE;;;;;UAciB,qBAAA;EAdwD;EAgBvE,IAAA,EAAM,UAAA,QAAkB,eAAA;EAhB8D;EAkBtF,OAAA;EAJoC;EAMpC,WAAA;AAAA;;UAIe,qBAAA,SAA8B,mBAAA;EARrB;;;;;AAQ1B;;EAQE,UAAA,EAAY,sBAAA;EARoD;;;;;;;EAgBhE,eAAA;AAAA;;;;;;;;;;;;;;;;iBAkBc,uBAAA,CAAwB,UAAA,EAAY,qBAAA,GAAwB,qBAAA"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
//#region src/test-runner/method-pace.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Per-method minimum-interval pacing for SDK calls (devtools#769).
|
|
4
|
-
*
|
|
5
|
-
* #767's `--pace` inserts delays BETWEEN test files / test-to-test — it has no
|
|
6
|
-
* effect on a burst of same-method calls WITHIN a single test body (e.g. a
|
|
7
|
-
* clipboard happy-path loop calling `setClipboardText`/`getClipboardText`
|
|
8
|
-
* eight times back to back). Real-device observation (sdk-example#293,
|
|
9
|
-
* 2.x×iOS) showed that burst alone is enough to saturate the native
|
|
10
|
-
* per-method bridge rate limit (`APP_BRIDGE_THROTTLED`, devtools#767/throttle.ts)
|
|
11
|
-
* even though `--pace`'s file/test spacing was already in effect — the
|
|
12
|
-
* limiter reacts to burst cadence within a method name, not just across test
|
|
13
|
-
* boundaries.
|
|
14
|
-
*
|
|
15
|
-
* This module wraps `window.__sdk` (the same bridge object `bundle.ts`'s
|
|
16
|
-
* `sdkRedirectPlugin` redirects SDK imports to) so that every call to the
|
|
17
|
-
* SAME named function waits out a minimum gap since that function's PREVIOUS
|
|
18
|
-
* invocation before the real call proceeds. Preflight (`cell.ts`) proved the
|
|
19
|
-
* inverse case empirically: a steady 250ms sequential cadence passes cleanly
|
|
20
|
-
* where an unpaced burst does not — sequential-with-spacing is the fix this
|
|
21
|
-
* module generalizes to every SDK call, not just the six permission probes.
|
|
22
|
-
*
|
|
23
|
-
* Runs entirely on the PAGE side (browser-compatible, no Node APIs) — bundled
|
|
24
|
-
* into the injected IIFE by `bundle.ts`'s `sdkRedirectPlugin`, the same way
|
|
25
|
-
* `bridge-stub.ts` and `runtime.ts` are. Imported ONLY from the test-runner
|
|
26
|
-
* (never from `sdk-example/src` — boilerplate cleanliness, umbrella §1.4).
|
|
27
|
-
*
|
|
28
|
-
* SECRET-HANDLING: this module carries no secrets — only method names and
|
|
29
|
-
* millisecond timestamps/durations.
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Reads the page-global `__AIT_PACE_METHOD_MS__` gap value (devtools#769),
|
|
33
|
-
* injected by `relay-factory.ts` the same way `__AIT_PACE_MS__`/`__AIT_CELL__`
|
|
34
|
-
* are (`cell.ts#injectGlobals`). Absent/non-positive resolves to `0` — the
|
|
35
|
-
* same "treat absence as zero" contract `runtime.ts`'s `__AIT_PACE_MS__` read
|
|
36
|
-
* uses.
|
|
37
|
-
*/
|
|
38
|
-
declare function getPaceMethodMs(): number;
|
|
39
|
-
/**
|
|
40
|
-
* Wraps an SDK-shaped bridge object (`window.__sdk`, or the already
|
|
41
|
-
* stub-wrapped result of `bridge-stub.ts#wrapSdkWithStub`) so that every
|
|
42
|
-
* function-valued export is paced to a minimum `gapMs` interval between
|
|
43
|
-
* calls to the SAME name (devtools#769). Non-function exports (constants,
|
|
44
|
-
* etc.) and classes (`PermissionError`, etc. — wrapping a class would break
|
|
45
|
-
* `new`, see `isClass`) pass through completely untouched.
|
|
46
|
-
*
|
|
47
|
-
* **Composition with bridge-stub (devtools#740)**: this wrapper is applied to
|
|
48
|
-
* the RAW `window.__sdk` object, and `wrapSdkWithStub` is applied on TOP of
|
|
49
|
-
* the paced result (`wrapSdkWithStub(wrapWithMethodPacing(rawSdk, gapMs),
|
|
50
|
-
* stubEnabled)` — see `bundle.ts`'s sdk-redirect virtual module). This means
|
|
51
|
-
* pacing sits BEHIND the stub interception: a stubbed name
|
|
52
|
-
* (`STUB_REGISTRY` — `openPermissionDialog`, `requestPermission`,
|
|
53
|
-
* `saveBase64Data`, `showFullScreenAd`) resolves instantly from the fixture
|
|
54
|
-
* with no added delay, because `wrapSdkWithStub`'s Proxy intercepts the
|
|
55
|
-
* property access before the paced function is ever reached. Only calls that
|
|
56
|
-
* fall through to the REAL bridge — the ones that actually risk
|
|
57
|
-
* `APP_BRIDGE_THROTTLED` — pay the pacing cost. Fixed by this ordering, not
|
|
58
|
-
* incidental: swapping it (pacing outside the stub) would pace fixture
|
|
59
|
-
* look-ups that can never hit the native rate limiter, for no benefit.
|
|
60
|
-
*
|
|
61
|
-
* `gapMs <= 0` (the default, no `--pace-method` / non-2.x cell) returns `sdk`
|
|
62
|
-
* itself, untouched — the exact object identity is preserved so the
|
|
63
|
-
* zero-diff-when-off contract holds under strict-equality checks, matching
|
|
64
|
-
* `wrapSdkWithStub`'s own `enabled === false` fast path.
|
|
65
|
-
*
|
|
66
|
-
* **Memoization**: wrapper functions are cached per name in a `Map` local to
|
|
67
|
-
* this call's `Proxy` (`wrapperCache` below), so repeated property access on
|
|
68
|
-
* the SAME `sdk` object within a single `wrapWithMethodPacing` call returns
|
|
69
|
-
* the SAME wrapper reference. This cache does NOT persist across separate
|
|
70
|
-
* `wrapWithMethodPacing` calls — each call (e.g. the sdk-redirect virtual
|
|
71
|
-
* module re-evaluated per test file bundle) gets its own fresh `Map` and
|
|
72
|
-
* therefore its own wrapper function instances, even for the same method
|
|
73
|
-
* name. That's fine for pacing correctness: the actual timing state lives in
|
|
74
|
-
* the page-global `getRegistry()` map (keyed by method name, not by wrapper
|
|
75
|
-
* identity), so cross-bundle pacing still works. But callers should NOT
|
|
76
|
-
* assume cross-call function identity — only "same wrapper within one call"
|
|
77
|
-
* is guaranteed.
|
|
78
|
-
*/
|
|
79
|
-
declare function wrapWithMethodPacing(sdk: Record<string, unknown>, gapMs: number): Record<string, unknown>;
|
|
80
|
-
//#endregion
|
|
81
|
-
export { getPaceMethodMs, wrapWithMethodPacing };
|
|
82
|
-
//# sourceMappingURL=method-pace.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"method-pace.d.ts","names":[],"sources":["../../src/test-runner/method-pace.ts"],"mappings":";;AAmFA;;;;;AA4EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA5EgB,eAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4EA,oBAAA,CACd,GAAA,EAAK,MAAA,mBACL,KAAA,WACC,MAAA"}
|