@ricsam/isolate 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +15 -0
  2. package/dist/cjs/bridge/runtime-bindings.cjs +11 -10
  3. package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
  4. package/dist/cjs/bridge/sandbox-isolate.cjs +58 -2
  5. package/dist/cjs/bridge/sandbox-isolate.cjs.map +3 -3
  6. package/dist/cjs/host/create-isolate-host.cjs +7 -2
  7. package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
  8. package/dist/cjs/host/nested-host-controller.cjs +36 -4
  9. package/dist/cjs/host/nested-host-controller.cjs.map +3 -3
  10. package/dist/cjs/internal/client/connection.cjs +9 -9
  11. package/dist/cjs/internal/client/connection.cjs.map +3 -3
  12. package/dist/cjs/internal/runtime/index.cjs +5 -2
  13. package/dist/cjs/internal/runtime/index.cjs.map +3 -3
  14. package/dist/cjs/internal/typecheck/isolate-types.cjs +50 -1
  15. package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
  16. package/dist/cjs/package.json +1 -1
  17. package/dist/cjs/runtime/namespaced-runtime.cjs +4 -1
  18. package/dist/cjs/runtime/namespaced-runtime.cjs.map +3 -3
  19. package/dist/cjs/runtime/test-event-subscriptions.cjs +76 -0
  20. package/dist/cjs/runtime/test-event-subscriptions.cjs.map +10 -0
  21. package/dist/cjs/runtime/test-runtime.cjs +26 -3
  22. package/dist/cjs/runtime/test-runtime.cjs.map +3 -3
  23. package/dist/mjs/bridge/runtime-bindings.mjs +11 -10
  24. package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
  25. package/dist/mjs/bridge/sandbox-isolate.mjs +58 -2
  26. package/dist/mjs/bridge/sandbox-isolate.mjs.map +3 -3
  27. package/dist/mjs/host/create-isolate-host.mjs +7 -2
  28. package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
  29. package/dist/mjs/host/nested-host-controller.mjs +36 -4
  30. package/dist/mjs/host/nested-host-controller.mjs.map +3 -3
  31. package/dist/mjs/internal/client/connection.mjs +9 -9
  32. package/dist/mjs/internal/client/connection.mjs.map +3 -3
  33. package/dist/mjs/internal/runtime/index.mjs +5 -2
  34. package/dist/mjs/internal/runtime/index.mjs.map +3 -3
  35. package/dist/mjs/internal/typecheck/isolate-types.mjs +50 -1
  36. package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
  37. package/dist/mjs/package.json +1 -1
  38. package/dist/mjs/runtime/namespaced-runtime.mjs +4 -1
  39. package/dist/mjs/runtime/namespaced-runtime.mjs.map +3 -3
  40. package/dist/mjs/runtime/test-event-subscriptions.mjs +36 -0
  41. package/dist/mjs/runtime/test-event-subscriptions.mjs.map +10 -0
  42. package/dist/mjs/runtime/test-runtime.mjs +26 -3
  43. package/dist/mjs/runtime/test-runtime.mjs.map +3 -3
  44. package/dist/types/internal/typecheck/isolate-types.d.ts +2 -2
  45. package/dist/types/runtime/namespaced-runtime.d.ts +3 -1
  46. package/dist/types/runtime/test-event-subscriptions.d.ts +12 -0
  47. package/dist/types/types.d.ts +6 -0
  48. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/isolate",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "type": "module"
5
5
  }
@@ -28,6 +28,7 @@ function createNamespacedRuntimeAdapter(runtime, diagnostics, options) {
28
28
  unsubscribe();
29
29
  }
30
30
  subscriptions.clear();
31
+ options?.testEvents.clear();
31
32
  options?.onRelease?.();
32
33
  };
33
34
  const ensureActive = () => {
@@ -35,6 +36,7 @@ function createNamespacedRuntimeAdapter(runtime, diagnostics, options) {
35
36
  throw createStateError(state, invalidationReason);
36
37
  }
37
38
  };
39
+ options.testEvents.setEnsureUsable(ensureActive);
38
40
  return {
39
41
  async eval(code, evalOptions) {
40
42
  ensureActive();
@@ -118,6 +120,7 @@ function createNamespacedRuntimeAdapter(runtime, diagnostics, options) {
118
120
  options?.abortBindings?.(reason);
119
121
  release();
120
122
  },
123
+ test: options.testEvents.api,
121
124
  events: {
122
125
  on: (event, handler) => {
123
126
  ensureActive();
@@ -140,4 +143,4 @@ export {
140
143
  createNamespacedRuntimeAdapter
141
144
  };
142
145
 
143
- //# debugId=92EF09126B0797AF64756E2164756E21
146
+ //# debugId=C0372FF17D33A9F464756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/runtime/namespaced-runtime.ts"],
4
4
  "sourcesContent": [
5
- "import {\n createBrowserDiagnostics,\n type MutableRuntimeDiagnostics,\n} from \"../bridge/diagnostics.mjs\";\nimport { isBenignDisposeError, type RemoteRuntime } from \"../internal/client/index.mjs\";\nimport type {\n NamespacedRuntime,\n RunResults,\n TestRuntimeDiagnostics,\n} from \"../types.mjs\";\n\ntype RuntimeState = \"active\" | \"disposed\" | \"invalidated\";\n\nexport interface NamespacedRuntimeAdapter extends NamespacedRuntime {\n invalidate(reason?: string): void;\n}\n\nfunction createStateError(state: RuntimeState, reason?: string): Error {\n if (state === \"invalidated\") {\n const error = new Error(\n reason && reason.length > 0\n ? `Namespaced runtime is no longer available: ${reason}`\n : \"Namespaced runtime is no longer available.\",\n );\n error.name = \"NamespacedRuntimeInvalidatedError\";\n return error;\n }\n\n const error = new Error(\"Namespaced runtime has already been disposed.\");\n error.name = \"NamespacedRuntimeDisposedError\";\n return error;\n}\n\nexport function createNamespacedRuntimeAdapter(\n runtime: RemoteRuntime,\n diagnostics: MutableRuntimeDiagnostics,\n options?: {\n hasBrowser?: boolean;\n abortBindings?: (reason?: string) => void;\n onRelease?: () => void;\n },\n): NamespacedRuntimeAdapter {\n let state: RuntimeState = \"active\";\n let lastRun: RunResults | undefined;\n let invalidationReason: string | undefined;\n let released = false;\n const subscriptions = new Set<() => void>();\n\n const release = () => {\n if (released) {\n return;\n }\n released = true;\n for (const unsubscribe of subscriptions) {\n unsubscribe();\n }\n subscriptions.clear();\n options?.onRelease?.();\n };\n\n const ensureActive = (): void => {\n if (state !== \"active\") {\n throw createStateError(state, invalidationReason);\n }\n };\n\n return {\n async eval(code, evalOptions) {\n ensureActive();\n diagnostics.lifecycleState = \"active\";\n try {\n await runtime.eval(code, {\n filename: evalOptions?.filename,\n executionTimeout: evalOptions?.executionTimeout,\n });\n } catch (error) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n async runTests(code, runOptions) {\n ensureActive();\n diagnostics.lifecycleState = \"active\";\n try {\n await runtime.testEnvironment.reset();\n await runtime.eval(code, {\n filename: runOptions?.filename,\n executionTimeout: runOptions?.timeoutMs,\n });\n lastRun = await runtime.testEnvironment.runTests(runOptions?.timeoutMs);\n return lastRun;\n } catch (error) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n async diagnostics(): Promise<TestRuntimeDiagnostics> {\n ensureActive();\n const runtimeDiagnostics = {\n ...diagnostics,\n reused: runtime.reused,\n };\n const collectedData = options?.hasBrowser\n ? runtime.playwright.getCollectedData()\n : undefined;\n const trackedResources = options?.hasBrowser\n ? runtime.playwright.getTrackedResources()\n : undefined;\n\n return {\n runtime: runtimeDiagnostics,\n browser: collectedData\n ? createBrowserDiagnostics(collectedData, trackedResources)\n : undefined,\n test: {\n enabled: true as const,\n registeredTests: await runtime.testEnvironment.getTestCount(),\n lastRun,\n },\n };\n },\n async dispose(disposeOptions) {\n if (state === \"invalidated\" || state === \"disposed\") {\n release();\n return;\n }\n\n state = \"disposed\";\n diagnostics.lifecycleState = \"disposing\";\n try {\n options?.abortBindings?.(disposeOptions?.reason);\n await runtime.dispose(disposeOptions);\n } catch (error) {\n if (!isBenignDisposeError(error)) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n }\n } finally {\n diagnostics.lifecycleState = \"idle\";\n release();\n }\n },\n invalidate(reason) {\n if (state === \"disposed\" || state === \"invalidated\") {\n release();\n return;\n }\n state = \"invalidated\";\n invalidationReason = reason;\n diagnostics.lifecycleState = \"idle\";\n options?.abortBindings?.(reason);\n release();\n },\n events: {\n on: (event, handler) => {\n ensureActive();\n const unsubscribe = runtime.on(event, handler);\n subscriptions.add(unsubscribe);\n return () => {\n if (subscriptions.delete(unsubscribe)) {\n unsubscribe();\n }\n };\n },\n emit: async (event, payload) => {\n ensureActive();\n runtime.emit(event, payload);\n },\n },\n };\n}\n"
5
+ "import {\n createBrowserDiagnostics,\n type MutableRuntimeDiagnostics,\n} from \"../bridge/diagnostics.mjs\";\nimport { isBenignDisposeError, type RemoteRuntime } from \"../internal/client/index.mjs\";\nimport type { TestEventSubscriptions } from \"./test-event-subscriptions.mjs\";\nimport type {\n NamespacedRuntime,\n RunResults,\n TestRuntimeDiagnostics,\n} from \"../types.mjs\";\n\ntype RuntimeState = \"active\" | \"disposed\" | \"invalidated\";\n\nexport interface NamespacedRuntimeAdapter extends NamespacedRuntime {\n invalidate(reason?: string): void;\n}\n\nfunction createStateError(state: RuntimeState, reason?: string): Error {\n if (state === \"invalidated\") {\n const error = new Error(\n reason && reason.length > 0\n ? `Namespaced runtime is no longer available: ${reason}`\n : \"Namespaced runtime is no longer available.\",\n );\n error.name = \"NamespacedRuntimeInvalidatedError\";\n return error;\n }\n\n const error = new Error(\"Namespaced runtime has already been disposed.\");\n error.name = \"NamespacedRuntimeDisposedError\";\n return error;\n}\n\nexport function createNamespacedRuntimeAdapter(\n runtime: RemoteRuntime,\n diagnostics: MutableRuntimeDiagnostics,\n options: {\n hasBrowser?: boolean;\n abortBindings?: (reason?: string) => void;\n onRelease?: () => void;\n testEvents: TestEventSubscriptions;\n },\n): NamespacedRuntimeAdapter {\n let state: RuntimeState = \"active\";\n let lastRun: RunResults | undefined;\n let invalidationReason: string | undefined;\n let released = false;\n const subscriptions = new Set<() => void>();\n\n const release = () => {\n if (released) {\n return;\n }\n released = true;\n for (const unsubscribe of subscriptions) {\n unsubscribe();\n }\n subscriptions.clear();\n options?.testEvents.clear();\n options?.onRelease?.();\n };\n\n const ensureActive = (): void => {\n if (state !== \"active\") {\n throw createStateError(state, invalidationReason);\n }\n };\n options.testEvents.setEnsureUsable(ensureActive);\n\n return {\n async eval(code, evalOptions) {\n ensureActive();\n diagnostics.lifecycleState = \"active\";\n try {\n await runtime.eval(code, {\n filename: evalOptions?.filename,\n executionTimeout: evalOptions?.executionTimeout,\n });\n } catch (error) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n async runTests(code, runOptions) {\n ensureActive();\n diagnostics.lifecycleState = \"active\";\n try {\n await runtime.testEnvironment.reset();\n await runtime.eval(code, {\n filename: runOptions?.filename,\n executionTimeout: runOptions?.timeoutMs,\n });\n lastRun = await runtime.testEnvironment.runTests(runOptions?.timeoutMs);\n return lastRun;\n } catch (error) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n async diagnostics(): Promise<TestRuntimeDiagnostics> {\n ensureActive();\n const runtimeDiagnostics = {\n ...diagnostics,\n reused: runtime.reused,\n };\n const collectedData = options?.hasBrowser\n ? runtime.playwright.getCollectedData()\n : undefined;\n const trackedResources = options?.hasBrowser\n ? runtime.playwright.getTrackedResources()\n : undefined;\n\n return {\n runtime: runtimeDiagnostics,\n browser: collectedData\n ? createBrowserDiagnostics(collectedData, trackedResources)\n : undefined,\n test: {\n enabled: true as const,\n registeredTests: await runtime.testEnvironment.getTestCount(),\n lastRun,\n },\n };\n },\n async dispose(disposeOptions) {\n if (state === \"invalidated\" || state === \"disposed\") {\n release();\n return;\n }\n\n state = \"disposed\";\n diagnostics.lifecycleState = \"disposing\";\n try {\n options?.abortBindings?.(disposeOptions?.reason);\n await runtime.dispose(disposeOptions);\n } catch (error) {\n if (!isBenignDisposeError(error)) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n }\n } finally {\n diagnostics.lifecycleState = \"idle\";\n release();\n }\n },\n invalidate(reason) {\n if (state === \"disposed\" || state === \"invalidated\") {\n release();\n return;\n }\n state = \"invalidated\";\n invalidationReason = reason;\n diagnostics.lifecycleState = \"idle\";\n options?.abortBindings?.(reason);\n release();\n },\n test: options.testEvents.api,\n events: {\n on: (event, handler) => {\n ensureActive();\n const unsubscribe = runtime.on(event, handler);\n subscriptions.add(unsubscribe);\n return () => {\n if (subscriptions.delete(unsubscribe)) {\n unsubscribe();\n }\n };\n },\n emit: async (event, payload) => {\n ensureActive();\n runtime.emit(event, payload);\n },\n },\n };\n}\n"
6
6
  ],
7
- "mappings": ";AAAA;AAAA;AAAA;AAIA;AAaA,SAAS,gBAAgB,CAAC,OAAqB,QAAwB;AAAA,EACrE,IAAI,UAAU,eAAe;AAAA,IAC3B,MAAM,SAAQ,IAAI,MAChB,UAAU,OAAO,SAAS,IACtB,8CAA8C,WAC9C,4CACN;AAAA,IACA,OAAM,OAAO;AAAA,IACb,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAQ,IAAI,MAAM,+CAA+C;AAAA,EACvE,MAAM,OAAO;AAAA,EACb,OAAO;AAAA;AAGF,SAAS,8BAA8B,CAC5C,SACA,aACA,SAK0B;AAAA,EAC1B,IAAI,QAAsB;AAAA,EAC1B,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI,WAAW;AAAA,EACf,MAAM,gBAAgB,IAAI;AAAA,EAE1B,MAAM,UAAU,MAAM;AAAA,IACpB,IAAI,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,WAAW;AAAA,IACX,WAAW,eAAe,eAAe;AAAA,MACvC,YAAY;AAAA,IACd;AAAA,IACA,cAAc,MAAM;AAAA,IACpB,SAAS,YAAY;AAAA;AAAA,EAGvB,MAAM,eAAe,MAAY;AAAA,IAC/B,IAAI,UAAU,UAAU;AAAA,MACtB,MAAM,iBAAiB,OAAO,kBAAkB;AAAA,I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C/C,MAAM,QAAQ,QAAQ,cAAc;AAAA,QACpC,OAAO,OAAO;AAAA,QACd,IAAI,CAAC,qBAAqB,KAAK,GAAG;AAAA,UAChC,YAAY,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAC7E,MAAM;AAAA,QACR;AAAA,gBACA;AAAA,QACA,YAAY,iBAAiB;AAAA,QAC7B,QAAQ;AAAA;AAAA;AAAA,IAGZ,UAAU,CAAC,QAAQ;AAAA,MACjB,IAAI,UAAU,cAAc,UAAU,eAAe;AAAA,QACnD,QAAQ;AAAA,QACR;AAAA,MACF;AAAA,MACA,QAAQ;AAAA,MACR,qBAAqB;AAAA,MACrB,YAAY,iBAAiB;AAAA,MAC7B,SAAS,gBAAgB,MAAM;AAAA,MAC/B,QAAQ;AAAA;AAAA,IAEV,MAAM,QAAQ,WAAW;AAAA,IACzB,QAAQ;AAAA,MACN,IAAI,CAAC,OAAO,YAAY;AAAA,QACtB,aAAa;AAAA,QACb,MAAM,cAAc,QAAQ,GAAG,OAAO,OAAO;AAAA,QAC7C,cAAc,IAAI,WAAW;AAAA,QAC7B,OAAO,MAAM;AAAA,UACX,IAAI,cAAc,OAAO,WAAW,GAAG;AAAA,YACrC,YAAY;AAAA,UACd;AAAA;AAAA;AAAA,MAGJ,MAAM,OAAO,OAAO,YAAY;AAAA,QAC9B,aAAa;AAAA,QACb,QAAQ,KAAK,OAAO,OAAO;AAAA;AAAA,IAE/B;AAAA,EACF;AAAA;",
8
+ "debugId": "C0372FF17D33A9F464756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -0,0 +1,36 @@
1
+ // src/runtime/test-event-subscriptions.ts
2
+ function createTestEventSubscriptions(ensureUsable) {
3
+ let currentEnsureUsable = ensureUsable;
4
+ const handlers = new Set;
5
+ return {
6
+ api: {
7
+ onEvent(handler) {
8
+ currentEnsureUsable?.();
9
+ handlers.add(handler);
10
+ return () => {
11
+ handlers.delete(handler);
12
+ };
13
+ }
14
+ },
15
+ emit(event) {
16
+ for (const handler of handlers) {
17
+ try {
18
+ handler(event);
19
+ } catch (error) {
20
+ console.error("[isolate-test] Test event handler failed.", error);
21
+ }
22
+ }
23
+ },
24
+ clear() {
25
+ handlers.clear();
26
+ },
27
+ setEnsureUsable(nextEnsureUsable) {
28
+ currentEnsureUsable = nextEnsureUsable;
29
+ }
30
+ };
31
+ }
32
+ export {
33
+ createTestEventSubscriptions
34
+ };
35
+
36
+ //# debugId=CDA8BA839DF4D2D464756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/runtime/test-event-subscriptions.ts"],
4
+ "sourcesContent": [
5
+ "import type { TestEvent } from \"../types.mjs\";\n\ninterface TestEventApi {\n onEvent(handler: (event: TestEvent) => void): () => void;\n}\n\nexport interface TestEventSubscriptions {\n readonly api: TestEventApi;\n emit(event: TestEvent): void;\n clear(): void;\n setEnsureUsable(ensureUsable?: () => void): void;\n}\n\nexport function createTestEventSubscriptions(\n ensureUsable?: () => void,\n): TestEventSubscriptions {\n let currentEnsureUsable = ensureUsable;\n const handlers = new Set<(event: TestEvent) => void>();\n\n return {\n api: {\n onEvent(handler) {\n currentEnsureUsable?.();\n handlers.add(handler);\n return () => {\n handlers.delete(handler);\n };\n },\n },\n emit(event) {\n for (const handler of handlers) {\n try {\n handler(event);\n } catch (error) {\n console.error(\"[isolate-test] Test event handler failed.\", error);\n }\n }\n },\n clear() {\n handlers.clear();\n },\n setEnsureUsable(nextEnsureUsable) {\n currentEnsureUsable = nextEnsureUsable;\n },\n };\n}\n"
6
+ ],
7
+ "mappings": ";AAaO,SAAS,4BAA4B,CAC1C,cACwB;AAAA,EACxB,IAAI,sBAAsB;AAAA,EAC1B,MAAM,WAAW,IAAI;AAAA,EAErB,OAAO;AAAA,IACL,KAAK;AAAA,MACH,OAAO,CAAC,SAAS;AAAA,QACf,sBAAsB;AAAA,QACtB,SAAS,IAAI,OAAO;AAAA,QACpB,OAAO,MAAM;AAAA,UACX,SAAS,OAAO,OAAO;AAAA;AAAA;AAAA,IAG7B;AAAA,IACA,IAAI,CAAC,OAAO;AAAA,MACV,WAAW,WAAW,UAAU;AAAA,QAC9B,IAAI;AAAA,UACF,QAAQ,KAAK;AAAA,UACb,OAAO,OAAO;AAAA,UACd,QAAQ,MAAM,6CAA6C,KAAK;AAAA;AAAA,MAEpE;AAAA;AAAA,IAEF,KAAK,GAAG;AAAA,MACN,SAAS,MAAM;AAAA;AAAA,IAEjB,eAAe,CAAC,kBAAkB;AAAA,MAChC,sBAAsB;AAAA;AAAA,EAE1B;AAAA;",
8
+ "debugId": "CDA8BA839DF4D2D464756E2164756E21",
9
+ "names": []
10
+ }
@@ -7,21 +7,36 @@ import {
7
7
  createRuntimeBindingsAdapter
8
8
  } from "../bridge/runtime-bindings.mjs";
9
9
  import { isBenignDisposeError } from "../internal/client/index.mjs";
10
+ import { createTestEventSubscriptions } from "./test-event-subscriptions.mjs";
11
+ function createDisposedTestRuntimeError() {
12
+ return new Error("Test runtime has already been disposed.");
13
+ }
10
14
  async function createTestRuntimeAdapter(createRuntime, options, adapterOptions) {
11
15
  const diagnostics = createRuntimeDiagnostics();
16
+ const testEvents = createTestEventSubscriptions();
12
17
  let runtimeId = options.key ?? "test-runtime";
18
+ let isDisposed = false;
13
19
  const bindingsAdapter = createRuntimeBindingsAdapter(options.bindings, () => runtimeId, diagnostics, adapterOptions);
14
20
  const runtime = await createRuntime({
15
21
  ...bindingsAdapter.runtimeOptions,
16
22
  cwd: options.cwd,
17
23
  memoryLimitMB: options.memoryLimitMB,
18
24
  executionTimeout: options.executionTimeout,
19
- testEnvironment: true
25
+ testEnvironment: {
26
+ onEvent: (event) => testEvents.emit(event)
27
+ }
20
28
  });
21
29
  runtimeId = runtime.id;
22
30
  let lastRun;
31
+ const ensureActive = () => {
32
+ if (isDisposed) {
33
+ throw createDisposedTestRuntimeError();
34
+ }
35
+ };
36
+ testEvents.setEnsureUsable(ensureActive);
23
37
  return {
24
38
  async run(code, runOptions) {
39
+ ensureActive();
25
40
  diagnostics.lifecycleState = "active";
26
41
  try {
27
42
  await runtime.testEnvironment.reset();
@@ -39,6 +54,7 @@ async function createTestRuntimeAdapter(createRuntime, options, adapterOptions)
39
54
  }
40
55
  },
41
56
  async diagnostics() {
57
+ ensureActive();
42
58
  const runtimeDiagnostics = {
43
59
  ...diagnostics,
44
60
  reused: runtime.reused
@@ -56,6 +72,11 @@ async function createTestRuntimeAdapter(createRuntime, options, adapterOptions)
56
72
  };
57
73
  },
58
74
  async dispose(disposeOptions) {
75
+ if (isDisposed) {
76
+ testEvents.clear();
77
+ return;
78
+ }
79
+ isDisposed = true;
59
80
  diagnostics.lifecycleState = "disposing";
60
81
  try {
61
82
  bindingsAdapter.abort(disposeOptions?.reason);
@@ -67,12 +88,14 @@ async function createTestRuntimeAdapter(createRuntime, options, adapterOptions)
67
88
  }
68
89
  } finally {
69
90
  diagnostics.lifecycleState = "idle";
91
+ testEvents.clear();
70
92
  }
71
- }
93
+ },
94
+ test: testEvents.api
72
95
  };
73
96
  }
74
97
  export {
75
98
  createTestRuntimeAdapter
76
99
  };
77
100
 
78
- //# debugId=5E07E630DF3B621F64756E2164756E21
101
+ //# debugId=8447E64FE68142EE64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/runtime/test-runtime.ts"],
4
4
  "sourcesContent": [
5
- "import {\n createBrowserDiagnostics,\n createRuntimeDiagnostics,\n} from \"../bridge/diagnostics.mjs\";\nimport {\n createRuntimeBindingsAdapter,\n type RuntimeBindingsAdapterOptions,\n} from \"../bridge/runtime-bindings.mjs\";\nimport type { RemoteRuntime, RuntimeOptions } from \"../internal/client/index.mjs\";\nimport { isBenignDisposeError } from \"../internal/client/index.mjs\";\nimport type {\n CreateTestRuntimeOptions,\n RunResults,\n TestRuntime,\n} from \"../types.mjs\";\n\nexport async function createTestRuntimeAdapter(\n createRuntime: (options: RuntimeOptions) => Promise<RemoteRuntime>,\n options: CreateTestRuntimeOptions,\n adapterOptions?: RuntimeBindingsAdapterOptions,\n): Promise<TestRuntime> {\n const diagnostics = createRuntimeDiagnostics();\n let runtimeId = options.key ?? \"test-runtime\";\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n adapterOptions,\n );\n const runtime = await createRuntime({\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n testEnvironment: true,\n });\n runtimeId = runtime.id;\n\n let lastRun: RunResults | undefined;\n\n return {\n async run(code, runOptions) {\n diagnostics.lifecycleState = \"active\";\n try {\n await runtime.testEnvironment.reset();\n await runtime.eval(code, {\n filename: runOptions?.filename,\n executionTimeout: runOptions?.timeoutMs,\n });\n lastRun = await runtime.testEnvironment.runTests(runOptions?.timeoutMs);\n return lastRun;\n } catch (error) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n async diagnostics() {\n const runtimeDiagnostics = {\n ...diagnostics,\n reused: runtime.reused,\n };\n const collectedData = options.bindings.browser\n ? runtime.playwright.getCollectedData()\n : undefined;\n const trackedResources = options.bindings.browser\n ? runtime.playwright.getTrackedResources()\n : undefined;\n return {\n runtime: runtimeDiagnostics,\n browser: collectedData\n ? createBrowserDiagnostics(collectedData, trackedResources)\n : undefined,\n test: {\n enabled: true as const,\n registeredTests: await runtime.testEnvironment.getTestCount(),\n lastRun,\n },\n };\n },\n async dispose(disposeOptions) {\n diagnostics.lifecycleState = \"disposing\";\n try {\n bindingsAdapter.abort(disposeOptions?.reason);\n await runtime.dispose(disposeOptions);\n } catch (error) {\n if (!isBenignDisposeError(error)) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n }\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n };\n}\n"
5
+ "import {\n createBrowserDiagnostics,\n createRuntimeDiagnostics,\n} from \"../bridge/diagnostics.mjs\";\nimport {\n createRuntimeBindingsAdapter,\n type RuntimeBindingsAdapterOptions,\n} from \"../bridge/runtime-bindings.mjs\";\nimport type { RemoteRuntime, RuntimeOptions } from \"../internal/client/index.mjs\";\nimport { isBenignDisposeError } from \"../internal/client/index.mjs\";\nimport { createTestEventSubscriptions } from \"./test-event-subscriptions.mjs\";\nimport type {\n CreateTestRuntimeOptions,\n RunResults,\n TestRuntime,\n} from \"../types.mjs\";\n\nfunction createDisposedTestRuntimeError(): Error {\n return new Error(\"Test runtime has already been disposed.\");\n}\n\nexport async function createTestRuntimeAdapter(\n createRuntime: (options: RuntimeOptions) => Promise<RemoteRuntime>,\n options: CreateTestRuntimeOptions,\n adapterOptions?: RuntimeBindingsAdapterOptions,\n): Promise<TestRuntime> {\n const diagnostics = createRuntimeDiagnostics();\n const testEvents = createTestEventSubscriptions();\n let runtimeId = options.key ?? \"test-runtime\";\n let isDisposed = false;\n const bindingsAdapter = createRuntimeBindingsAdapter(\n options.bindings,\n () => runtimeId,\n diagnostics,\n adapterOptions,\n );\n const runtime = await createRuntime({\n ...bindingsAdapter.runtimeOptions,\n cwd: options.cwd,\n memoryLimitMB: options.memoryLimitMB,\n executionTimeout: options.executionTimeout,\n testEnvironment: {\n onEvent: (event) => testEvents.emit(event),\n },\n });\n runtimeId = runtime.id;\n\n let lastRun: RunResults | undefined;\n const ensureActive = (): void => {\n if (isDisposed) {\n throw createDisposedTestRuntimeError();\n }\n };\n testEvents.setEnsureUsable(ensureActive);\n\n return {\n async run(code, runOptions) {\n ensureActive();\n diagnostics.lifecycleState = \"active\";\n try {\n await runtime.testEnvironment.reset();\n await runtime.eval(code, {\n filename: runOptions?.filename,\n executionTimeout: runOptions?.timeoutMs,\n });\n lastRun = await runtime.testEnvironment.runTests(runOptions?.timeoutMs);\n return lastRun;\n } catch (error) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n } finally {\n diagnostics.lifecycleState = \"idle\";\n }\n },\n async diagnostics() {\n ensureActive();\n const runtimeDiagnostics = {\n ...diagnostics,\n reused: runtime.reused,\n };\n const collectedData = options.bindings.browser\n ? runtime.playwright.getCollectedData()\n : undefined;\n const trackedResources = options.bindings.browser\n ? runtime.playwright.getTrackedResources()\n : undefined;\n return {\n runtime: runtimeDiagnostics,\n browser: collectedData\n ? createBrowserDiagnostics(collectedData, trackedResources)\n : undefined,\n test: {\n enabled: true as const,\n registeredTests: await runtime.testEnvironment.getTestCount(),\n lastRun,\n },\n };\n },\n async dispose(disposeOptions) {\n if (isDisposed) {\n testEvents.clear();\n return;\n }\n\n isDisposed = true;\n diagnostics.lifecycleState = \"disposing\";\n try {\n bindingsAdapter.abort(disposeOptions?.reason);\n await runtime.dispose(disposeOptions);\n } catch (error) {\n if (!isBenignDisposeError(error)) {\n diagnostics.lastError = error instanceof Error ? error.message : String(error);\n throw error;\n }\n } finally {\n diagnostics.lifecycleState = \"idle\";\n testEvents.clear();\n }\n },\n test: testEvents.api,\n };\n}\n"
6
6
  ],
7
- "mappings": ";AAAA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAKA;AAOA,eAAsB,wBAAwB,CAC5C,eACA,SACA,gBACsB;AAAA,EACtB,MAAM,cAAc,yBAAyB;AAAA,EAC7C,IAAI,YAAY,QAAQ,OAAO;AAAA,EAC/B,MAAM,kBAAkB,6BACtB,QAAQ,UACR,MAAM,WACN,aACA,cACF;AAAA,EACA,MAAM,UAAU,MAAM,cAAc;AAAA,OAC/B,gBAAgB;AAAA,IACnB,KAAK,QAAQ;AAAA,IACb,eAAe,QAAQ;AAAA,IACvB,kBAAkB,QAAQ;AAAA,IAC1B,iBAAiB;AAAA,EACnB,CAAC;AAAA,EACD,YAAY,QAAQ;AAAA,EAEpB,IAAI;AAAA,EAEJ,OAAO;AAAA,SACC,IAAG,CAAC,MAAM,YAAY;AAAA,MAC1B,YAAY,iBAAiB;AAAA,MAC7B,IAAI;AAAA,QACF,MAAM,QAAQ,gBAAgB,MAAM;AAAA,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YAAY,iBAAiB;AAAA;AAAA;AAAA,SAG3B,YAAW,GAAG;AAAA,MAClB,aAAa;AAAA,MACb,MAAM,qBAAqB;AAAA,WACtB;AAAA,QACH,QAAQ,QAAQ;AAAA,MAClB;AAAA,MACA,MAAM,gBAAgB,QAAQ,SAAS,UACnC,QAAQ,WAAW,iBAAiB,IACpC;AAAA,MACJ,MAAM,mBAAmB,QAAQ,SAAS,UACtC,QAAQ,WAAW,oBAAoB,IACvC;AAAA,MACJ,OAAO;AAAA,QACL,SAAS;AAAA,QACT,SAAS,gBACL,yBAAyB,eAAe,gBAAgB,IACxD;AAAA,QACJ,MAAM;AAAA,UACJ,SAAS;AAAA,UACT,iBAAiB,MAAM,QAAQ,gBAAgB,aAAa;AAAA,UAC5D;AAAA,QACF;AAAA,MACF;AAAA;AAAA,SAEI,QAAO,CAAC,gBAAgB;AAAA,MAC5B,IAAI,YAAY;AAAA,QACd,WAAW,MAAM;AAAA,QACjB;AAAA,MACF;AAAA,MAEA,aAAa;AAAA,MACb,YAAY,iBAAiB;AAAA,MAC7B,IAAI;AAAA,QACF,gBAAgB,MAAM,gBAAgB,MAAM;AAAA,QAC5C,MAAM,QAAQ,QAAQ,cAAc;AAAA,QACpC,OAAO,OAAO;AAAA,QACd,IAAI,CAAC,qBAAqB,KAAK,GAAG;AAAA,UAChC,YAAY,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAC7E,MAAM;AAAA,QACR;AAAA,gBACA;AAAA,QACA,YAAY,iBAAiB;AAAA,QAC7B,WAAW,MAAM;AAAA;AAAA;AAAA,IAGrB,MAAM,WAAW;AAAA,EACnB;AAAA;",
8
+ "debugId": "8447E64FE68142EE64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -73,13 +73,13 @@ export declare const TIMERS_TYPES = "/**\n * Global Type Definitions for ../time
73
73
  * setupPlaywright() into an isolated-vm context.
74
74
  */
75
75
  export declare const PLAYWRIGHT_TYPES = "\n/**\n * Locator represents an element or group of elements in the page.\n */\ndeclare class Locator {\n /** Click the element */\n click(): Promise<void>;\n /** Double-click the element */\n dblclick(): Promise<void>;\n /** Fill an input element with text */\n fill(text: string): Promise<void>;\n /** Type text into an element (key by key) */\n type(text: string): Promise<void>;\n /** Check a checkbox or radio */\n check(): Promise<void>;\n /** Uncheck a checkbox */\n uncheck(): Promise<void>;\n /** Select an option in a dropdown */\n selectOption(value: string | string[]): Promise<void>;\n /** Clear an input element */\n clear(): Promise<void>;\n /** Press a key */\n press(key: string): Promise<void>;\n /** Hover over the element */\n hover(): Promise<void>;\n /** Focus the element */\n focus(): Promise<void>;\n /** Get text content of the element */\n textContent(): Promise<string | null>;\n /** Get the value of an input element */\n inputValue(): Promise<string>;\n /** Check if the element is visible */\n isVisible(): Promise<boolean>;\n /** Check if the element is enabled */\n isEnabled(): Promise<boolean>;\n /** Check if the element is checked */\n isChecked(): Promise<boolean>;\n /** Check if the element is disabled */\n isDisabled(): Promise<boolean>;\n /** Check if the element is hidden */\n isHidden(): Promise<boolean>;\n /** Get the count of matching elements */\n count(): Promise<number>;\n /** Get an attribute value */\n getAttribute(name: string): Promise<string | null>;\n /** Get innerHTML */\n innerHTML(): Promise<string>;\n /** Get innerText */\n innerText(): Promise<string>;\n /** Get all text contents */\n allTextContents(): Promise<string[]>;\n /** Get all inner texts */\n allInnerTexts(): Promise<string[]>;\n /** Wait for the element to match a state */\n waitFor(options?: { state?: \"attached\" | \"detached\" | \"visible\" | \"hidden\"; timeout?: number }): Promise<void>;\n /** Get bounding box */\n boundingBox(): Promise<{ x: number; y: number; width: number; height: number } | null>;\n /** Set input files for a file input */\n setInputFiles(files: string | string[] | { name: string; mimeType: string; buffer: ArrayBuffer | Uint8Array | string }[]): Promise<void>;\n /** Take a screenshot of the element */\n screenshot(options?: { path?: string; type?: \"png\" | \"jpeg\"; quality?: number }): Promise<void>;\n /** Drag to another element */\n dragTo(target: Locator): Promise<void>;\n /** Scroll element into view */\n scrollIntoViewIfNeeded(): Promise<void>;\n /** Highlight the element for debugging */\n highlight(): Promise<void>;\n /** Evaluate a function in the context of the element */\n evaluate<R>(fn: (el: Element, arg?: unknown) => R, arg?: unknown): Promise<R>;\n /** Evaluate a function for all matching elements */\n evaluateAll<R>(fn: (els: Element[], arg?: unknown) => R, arg?: unknown): Promise<R>;\n\n // Chaining methods\n /** Chain with another CSS selector */\n locator(selector: string): Locator;\n /** Chain with getByRole */\n getByRole(role: string, options?: { name?: string | RegExp; exact?: boolean }): Locator;\n /** Chain with getByText */\n getByText(text: string | RegExp): Locator;\n /** Chain with getByLabel */\n getByLabel(label: string | RegExp): Locator;\n /** Chain with getByPlaceholder */\n getByPlaceholder(placeholder: string | RegExp): Locator;\n /** Chain with getByTestId */\n getByTestId(testId: string): Locator;\n /** Chain with getByAltText */\n getByAltText(alt: string | RegExp): Locator;\n /** Chain with getByTitle */\n getByTitle(title: string | RegExp): Locator;\n\n // Subset selection\n /** Get all matching locators as an array */\n all(): Promise<Locator[]>;\n /** Get the nth matching element */\n nth(index: number): Locator;\n /** Get the first matching element */\n first(): Locator;\n /** Get the last matching element */\n last(): Locator;\n\n // Filtering\n /** Filter locators by additional criteria */\n filter(options: { hasText?: string | RegExp; hasNotText?: string | RegExp; has?: Locator; hasNot?: Locator }): Locator;\n /** Create a locator matching either this or the other locator */\n or(other: Locator): Locator;\n /** Create a locator matching both this and the other locator */\n and(other: Locator): Locator;\n}\n\n/**\n * FrameLocator for interacting with elements inside iframes.\n */\ninterface FrameLocator {\n locator(selector: string): Locator;\n getByRole(role: string, options?: { name?: string | RegExp; exact?: boolean }): Locator;\n getByText(text: string | RegExp): Locator;\n getByLabel(label: string | RegExp): Locator;\n getByPlaceholder(placeholder: string | RegExp): Locator;\n getByTestId(testId: string): Locator;\n getByAltText(alt: string | RegExp): Locator;\n getByTitle(title: string | RegExp): Locator;\n}\n\n/**\n * Keyboard API for simulating keyboard input.\n */\ninterface Keyboard {\n type(text: string, options?: { delay?: number }): Promise<void>;\n press(key: string, options?: { delay?: number }): Promise<void>;\n down(key: string): Promise<void>;\n up(key: string): Promise<void>;\n insertText(text: string): Promise<void>;\n}\n\n/**\n * Mouse API for simulating mouse input.\n */\ninterface Mouse {\n move(x: number, y: number, options?: { steps?: number }): Promise<void>;\n click(x: number, y: number, options?: { button?: \"left\" | \"right\" | \"middle\"; clickCount?: number; delay?: number }): Promise<void>;\n down(options?: { button?: \"left\" | \"right\" | \"middle\"; clickCount?: number }): Promise<void>;\n up(options?: { button?: \"left\" | \"right\" | \"middle\"; clickCount?: number }): Promise<void>;\n wheel(deltaX: number, deltaY: number): Promise<void>;\n}\n\n/**\n * API Response from page.request methods.\n */\ninterface APIResponse {\n status(): number;\n ok(): boolean;\n headers(): Record<string, string>;\n json(): Promise<unknown>;\n text(): Promise<string>;\n body(): Promise<ArrayBuffer>;\n}\n\n/**\n * Request API for making HTTP requests with page cookies.\n */\ninterface APIRequestContext {\n fetch(url: string, options?: { method?: string; data?: unknown; headers?: Record<string, string> }): Promise<APIResponse>;\n get(url: string, options?: { headers?: Record<string, string> }): Promise<APIResponse>;\n post(url: string, options?: { data?: unknown; headers?: Record<string, string> }): Promise<APIResponse>;\n put(url: string, options?: { data?: unknown; headers?: Record<string, string> }): Promise<APIResponse>;\n delete(url: string, options?: { headers?: Record<string, string> }): Promise<APIResponse>;\n}\n\n/**\n * Frame information.\n */\ninterface FrameInfo {\n name: string;\n url: string;\n}\n\n/**\n * Cookie data.\n */\ninterface Cookie {\n name: string;\n value: string;\n domain?: string;\n path?: string;\n expires?: number;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n}\n\n/**\n * IsolatePage - represents a browser page in the isolate.\n */\ndeclare class IsolatePage {\n /** Navigate to a URL */\n goto(url: string, options?: { waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle\" }): Promise<void>;\n /** Reload the page */\n reload(): Promise<void>;\n /** Get the current URL */\n url(): Promise<string>;\n /** Get the page title */\n title(): Promise<string>;\n /** Get the page HTML content */\n content(): Promise<string>;\n /** Wait for a selector to appear */\n waitForSelector(selector: string, options?: { state?: \"attached\" | \"detached\" | \"visible\" | \"hidden\"; timeout?: number }): Promise<void>;\n /** Wait for a specified time */\n waitForTimeout(ms: number): Promise<void>;\n /** Wait for a load state */\n waitForLoadState(state?: \"load\" | \"domcontentloaded\" | \"networkidle\"): Promise<void>;\n /** Wait for the URL to match */\n waitForURL(url: string | RegExp, options?: { timeout?: number; waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle\" }): Promise<void>;\n /** Evaluate JavaScript in the browser context */\n evaluate<R>(script: string | (() => R) | ((arg: unknown) => R), arg?: unknown): Promise<R>;\n /** Create a locator by CSS selector */\n locator(selector: string): Locator;\n /** Create a locator by ARIA role */\n getByRole(role: string, options?: { name?: string | RegExp; exact?: boolean }): Locator;\n /** Create a locator by text content */\n getByText(text: string | RegExp): Locator;\n /** Create a locator by label */\n getByLabel(label: string | RegExp): Locator;\n /** Create a locator by placeholder */\n getByPlaceholder(placeholder: string | RegExp): Locator;\n /** Create a locator by test ID */\n getByTestId(testId: string): Locator;\n /** Create a locator by alt text */\n getByAltText(alt: string | RegExp): Locator;\n /** Create a locator by title */\n getByTitle(title: string | RegExp): Locator;\n /** Create a frame locator */\n frameLocator(selector: string): FrameLocator;\n /** Navigate back */\n goBack(options?: { waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle\" }): Promise<void>;\n /** Navigate forward */\n goForward(options?: { waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle\" }): Promise<void>;\n /** Click an element (shorthand) */\n click(selector: string): Promise<void>;\n /** Fill an input (shorthand) */\n fill(selector: string, value: string): Promise<void>;\n /** Take a screenshot */\n screenshot(options?: { path?: string; fullPage?: boolean; type?: \"png\" | \"jpeg\"; quality?: number }): Promise<void>;\n /** Generate a PDF (Chromium only) */\n pdf(options?: { path?: string; format?: string; landscape?: boolean; margin?: { top?: string; bottom?: string; left?: string; right?: string } }): Promise<string>;\n /** Set the viewport size */\n setViewportSize(size: { width: number; height: number }): Promise<void>;\n /** Get the viewport size */\n viewportSize(): Promise<{ width: number; height: number } | null>;\n /** Emulate media type or color scheme */\n emulateMedia(options: { media?: \"screen\" | \"print\" | null; colorScheme?: \"light\" | \"dark\" | \"no-preference\" | null }): Promise<void>;\n /** Set extra HTTP headers */\n setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;\n /** Bring the page to front */\n bringToFront(): Promise<void>;\n /** Close the page */\n close(): Promise<void>;\n /** Check if the page is closed */\n isClosed(): Promise<boolean>;\n /** Pause execution (for debugging) */\n pause(): Promise<void>;\n /** Get all frames */\n frames(): Promise<FrameInfo[]>;\n /** Get the main frame */\n mainFrame(): Promise<FrameInfo>;\n /** Get the browser context for this page */\n context(): IsolateContext;\n /** Keyboard API */\n readonly keyboard: Keyboard;\n /** Mouse API */\n readonly mouse: Mouse;\n /** Request API for making HTTP requests */\n readonly request: APIRequestContext;\n}\n\n/**\n * IsolateContext - represents a browser context in the isolate.\n */\ndeclare class IsolateContext {\n /** Create a new page in this context (requires createPage callback) */\n newPage(): Promise<IsolatePage>;\n /** Get tracked pages for this context */\n pages(): Promise<IsolatePage[]>;\n /** Close this context and all its pages */\n close(): Promise<void>;\n /** Clear all cookies */\n clearCookies(): Promise<void>;\n /** Add cookies */\n addCookies(cookies: Cookie[]): Promise<void>;\n /** Get cookies */\n cookies(urls?: string | string[]): Promise<Cookie[]>;\n}\n\n/**\n * Browser object for creating new contexts.\n */\ninterface IsolateBrowser {\n /** Create a new browser context (requires createContext callback) */\n newContext(options?: {\n viewport?: { width: number; height: number } | null;\n userAgent?: string;\n locale?: string;\n timezoneId?: string;\n geolocation?: { latitude: number; longitude: number; accuracy?: number };\n permissions?: string[];\n colorScheme?: \"light\" | \"dark\" | \"no-preference\";\n }): Promise<IsolateContext>;\n /** Get tracked browser contexts */\n contexts(): Promise<IsolateContext[]>;\n}\n\n/**\n * Browser object for creating new contexts.\n */\ndeclare const browser: IsolateBrowser;\n\n// ============================================================================\n// Playwright Expect Matchers (extends test-environment expect)\n// ============================================================================\n\n/**\n * Options for locator assertion timeouts.\n */\ninterface LocatorAssertionOptions {\n timeout?: number;\n}\n\n/**\n * Locator-specific assertion matchers (added to expect when using Playwright).\n * These are available when calling expect(locator).\n */\ninterface PlaywrightLocatorMatchers {\n /** Assert element is visible */\n toBeVisible(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is hidden */\n toBeHidden(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is enabled */\n toBeEnabled(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is disabled */\n toBeDisabled(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is checked */\n toBeChecked(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is focused */\n toBeFocused(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is empty */\n toBeEmpty(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is attached to DOM */\n toBeAttached(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is editable */\n toBeEditable(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element is in viewport */\n toBeInViewport(options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element contains text */\n toContainText(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has exact text */\n toHaveText(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has value (for inputs) */\n toHaveValue(expected: string, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has attribute */\n toHaveAttribute(name: string, value?: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element count */\n toHaveCount(count: number, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has class */\n toHaveClass(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element contains class */\n toContainClass(expected: string, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has id */\n toHaveId(expected: string, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has CSS property */\n toHaveCSS(name: string, value: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has JavaScript property */\n toHaveJSProperty(name: string, value: unknown, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has accessible name */\n toHaveAccessibleName(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has accessible description */\n toHaveAccessibleDescription(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert element has ARIA role */\n toHaveRole(expected: string, options?: LocatorAssertionOptions): Promise<void>;\n /** Negated matchers */\n not: PlaywrightLocatorMatchers;\n}\n\n/**\n * Page-specific assertion matchers (added to expect when using Playwright).\n * These are available when calling expect(page).\n */\ninterface PlaywrightPageMatchers {\n /** Assert page has URL */\n toHaveURL(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Assert page has title */\n toHaveTitle(expected: string | RegExp, options?: LocatorAssertionOptions): Promise<void>;\n /** Negated matchers */\n not: PlaywrightPageMatchers;\n}\n";
76
- export declare const SANDBOX_ISOLATE_TYPES = "\ndeclare module \"@ricsam/isolate\" {\n export interface NestedModuleImporter {\n path: string;\n resolveDir: string;\n }\n\n export interface NestedModuleSource {\n code: string;\n filename: string;\n resolveDir: string;\n static?: boolean;\n }\n\n export type NestedModuleResolveResult =\n | string\n | NestedModuleSource\n | null\n | undefined\n | Promise<string | NestedModuleSource | null | undefined>;\n\n export interface NestedFileBindings {\n readFile?: (path: string) => Promise<ArrayBuffer>;\n writeFile?: (path: string, data: ArrayBuffer) => Promise<void>;\n unlink?: (path: string) => Promise<void>;\n readdir?: (path: string) => Promise<string[]>;\n mkdir?: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n rmdir?: (path: string) => Promise<void>;\n stat?: (\n path: string,\n ) => Promise<{ isFile: boolean; isDirectory: boolean; size: number }>;\n rename?: (from: string, to: string) => Promise<void>;\n }\n\n export interface NestedBrowserBindings {\n createContext?: (options: unknown) => Promise<unknown> | unknown;\n createPage?: (contextHandle: unknown) => Promise<unknown> | unknown;\n }\n\n export interface NestedHostBindings {\n console?: {\n onEntry?: (entry: unknown) => void;\n };\n fetch?: (request: Request) => Response | Promise<Response>;\n files?: NestedFileBindings;\n modules?: {\n resolve(\n specifier: string,\n importer: NestedModuleImporter,\n ): NestedModuleResolveResult;\n };\n tools?: Record<string, (...args: any[]) => unknown>;\n browser?: unknown;\n }\n\n export interface NestedRuntimeDiagnostics {\n activeRequests: number;\n activeResources: number;\n pendingFiles: number;\n pendingFetches: number;\n pendingModules: number;\n pendingTools: number;\n streamCount: number;\n lastError?: string;\n reused?: boolean;\n lifecycleState: \"idle\" | \"active\" | \"reloading\" | \"disposing\";\n }\n\n export interface NestedBrowserDiagnostics {\n contexts: number;\n pages: number;\n browserConsoleLogs: number;\n networkRequests: number;\n networkResponses: number;\n pageErrors: number;\n requestFailures: number;\n collectedData: {\n browserConsoleLogs: unknown[];\n pageErrors: unknown[];\n networkRequests: unknown[];\n networkResponses: unknown[];\n requestFailures: unknown[];\n };\n }\n\n export interface NestedRuntimeResourceDiagnostics {\n runtime: NestedRuntimeDiagnostics;\n browser?: NestedBrowserDiagnostics;\n }\n\n export interface NestedTestDiagnostics {\n enabled: true;\n registeredTests: number;\n lastRun?: unknown;\n }\n\n export interface NestedTestRuntimeDiagnostics extends NestedRuntimeResourceDiagnostics {\n test: NestedTestDiagnostics;\n }\n\n export interface NestedHostDiagnostics {\n runtimes: number;\n servers: number;\n connected: boolean;\n }\n\n export type NestedRequestResult =\n | { type: \"response\"; response: Response }\n | { type: \"websocket\"; upgradeData: Record<string, unknown> };\n\n export interface NestedScriptRuntime {\n eval(\n code: string,\n options?: string | { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedAppServer {\n handle(\n request: Request | string,\n options?: { requestId?: string; metadata?: Record<string, string> },\n ): Promise<NestedRequestResult>;\n ws: {\n open(connectionId: string): Promise<void>;\n message(connectionId: string, data: string | ArrayBuffer): Promise<void>;\n close(connectionId: string, code: number, reason: string): Promise<void>;\n error(connectionId: string, error: Error): Promise<void>;\n };\n reload(reason?: string): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n }\n\n export interface NestedTestRuntime {\n run(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n }\n\n export interface NestedNamespacedRuntime {\n eval(\n code: string,\n options?: { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n runTests(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedCreateRuntimeOptions {\n key?: string;\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateNamespacedRuntimeOptions {\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateTestRuntimeOptions extends NestedCreateRuntimeOptions {}\n\n export interface NestedCreateAppServerOptions extends NestedCreateRuntimeOptions {\n key: string;\n entry: string;\n entryFilename?: string;\n }\n\n export interface NestedIsolateHost {\n createRuntime(options?: NestedCreateRuntimeOptions): Promise<NestedScriptRuntime>;\n createAppServer(options: NestedCreateAppServerOptions): Promise<NestedAppServer>;\n createTestRuntime(\n options?: NestedCreateTestRuntimeOptions,\n ): Promise<NestedTestRuntime>;\n getNamespacedRuntime(\n key: string,\n options?: NestedCreateNamespacedRuntimeOptions,\n ): Promise<NestedNamespacedRuntime>;\n disposeNamespace(\n key: string,\n options?: { reason?: string },\n ): Promise<void>;\n diagnostics(): Promise<NestedHostDiagnostics>;\n close(): Promise<void>;\n }\n\n export function createIsolateHost(): NestedIsolateHost;\n}\n";
76
+ export declare const SANDBOX_ISOLATE_TYPES = "\ndeclare module \"@ricsam/isolate\" {\n export interface NestedModuleImporter {\n path: string;\n resolveDir: string;\n }\n\n export interface NestedModuleSource {\n code: string;\n filename: string;\n resolveDir: string;\n static?: boolean;\n }\n\n export type NestedModuleResolveResult =\n | string\n | NestedModuleSource\n | null\n | undefined\n | Promise<string | NestedModuleSource | null | undefined>;\n\n export interface NestedFileBindings {\n readFile?: (path: string) => Promise<ArrayBuffer>;\n writeFile?: (path: string, data: ArrayBuffer) => Promise<void>;\n unlink?: (path: string) => Promise<void>;\n readdir?: (path: string) => Promise<string[]>;\n mkdir?: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n rmdir?: (path: string) => Promise<void>;\n stat?: (\n path: string,\n ) => Promise<{ isFile: boolean; isDirectory: boolean; size: number }>;\n rename?: (from: string, to: string) => Promise<void>;\n }\n\n export interface NestedBrowserBindings {\n createContext?: (options: unknown) => Promise<unknown> | unknown;\n createPage?: (contextHandle: unknown) => Promise<unknown> | unknown;\n }\n\n export interface NestedHostBindings {\n console?: {\n onEntry?: (entry: unknown) => void;\n };\n fetch?: (request: Request) => Response | Promise<Response>;\n files?: NestedFileBindings;\n modules?: {\n resolve(\n specifier: string,\n importer: NestedModuleImporter,\n ): NestedModuleResolveResult;\n };\n tools?: Record<string, (...args: any[]) => unknown>;\n browser?: unknown;\n }\n\n export interface NestedRuntimeDiagnostics {\n activeRequests: number;\n activeResources: number;\n pendingFiles: number;\n pendingFetches: number;\n pendingModules: number;\n pendingTools: number;\n streamCount: number;\n lastError?: string;\n reused?: boolean;\n lifecycleState: \"idle\" | \"active\" | \"reloading\" | \"disposing\";\n }\n\n export interface NestedBrowserDiagnostics {\n contexts: number;\n pages: number;\n browserConsoleLogs: number;\n networkRequests: number;\n networkResponses: number;\n pageErrors: number;\n requestFailures: number;\n collectedData: {\n browserConsoleLogs: unknown[];\n pageErrors: unknown[];\n networkRequests: unknown[];\n networkResponses: unknown[];\n requestFailures: unknown[];\n };\n }\n\n export interface NestedRuntimeResourceDiagnostics {\n runtime: NestedRuntimeDiagnostics;\n browser?: NestedBrowserDiagnostics;\n }\n\n export interface NestedTestDiagnostics {\n enabled: true;\n registeredTests: number;\n lastRun?: unknown;\n }\n\n export interface NestedSuiteInfo {\n name: string;\n path: string[];\n fullName: string;\n depth: number;\n }\n\n export interface NestedSuiteResult extends NestedSuiteInfo {\n passed: number;\n failed: number;\n skipped: number;\n todo: number;\n duration: number;\n }\n\n export interface NestedTestInfo {\n name: string;\n suitePath: string[];\n fullName: string;\n }\n\n export interface NestedTestError {\n message: string;\n stack?: string;\n expected?: unknown;\n actual?: unknown;\n matcherName?: string;\n }\n\n export interface NestedTestResult extends NestedTestInfo {\n status: \"pass\" | \"fail\" | \"skip\" | \"todo\";\n duration: number;\n error?: NestedTestError;\n }\n\n export type NestedTestEvent =\n | { type: \"runStart\"; testCount: number; suiteCount: number }\n | { type: \"suiteStart\"; suite: NestedSuiteInfo }\n | { type: \"suiteEnd\"; suite: NestedSuiteResult }\n | { type: \"testStart\"; test: NestedTestInfo }\n | { type: \"testEnd\"; test: NestedTestResult }\n | { type: \"runEnd\"; results: unknown };\n\n export interface NestedTestRuntimeDiagnostics extends NestedRuntimeResourceDiagnostics {\n test: NestedTestDiagnostics;\n }\n\n export interface NestedHostDiagnostics {\n runtimes: number;\n servers: number;\n connected: boolean;\n }\n\n export type NestedRequestResult =\n | { type: \"response\"; response: Response }\n | { type: \"websocket\"; upgradeData: Record<string, unknown> };\n\n export interface NestedScriptRuntime {\n eval(\n code: string,\n options?: string | { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedAppServer {\n handle(\n request: Request | string,\n options?: { requestId?: string; metadata?: Record<string, string> },\n ): Promise<NestedRequestResult>;\n ws: {\n open(connectionId: string): Promise<void>;\n message(connectionId: string, data: string | ArrayBuffer): Promise<void>;\n close(connectionId: string, code: number, reason: string): Promise<void>;\n error(connectionId: string, error: Error): Promise<void>;\n };\n reload(reason?: string): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n }\n\n export interface NestedTestRuntime {\n run(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n test: {\n onEvent(handler: (event: NestedTestEvent) => void): () => void;\n };\n }\n\n export interface NestedNamespacedRuntime {\n eval(\n code: string,\n options?: { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n runTests(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n test: {\n onEvent(handler: (event: NestedTestEvent) => void): () => void;\n };\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedCreateRuntimeOptions {\n key?: string;\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateNamespacedRuntimeOptions {\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateTestRuntimeOptions extends NestedCreateRuntimeOptions {}\n\n export interface NestedCreateAppServerOptions extends NestedCreateRuntimeOptions {\n key: string;\n entry: string;\n entryFilename?: string;\n }\n\n export interface NestedIsolateHost {\n createRuntime(options?: NestedCreateRuntimeOptions): Promise<NestedScriptRuntime>;\n createAppServer(options: NestedCreateAppServerOptions): Promise<NestedAppServer>;\n createTestRuntime(\n options?: NestedCreateTestRuntimeOptions,\n ): Promise<NestedTestRuntime>;\n getNamespacedRuntime(\n key: string,\n options?: NestedCreateNamespacedRuntimeOptions,\n ): Promise<NestedNamespacedRuntime>;\n disposeNamespace(\n key: string,\n options?: { reason?: string },\n ): Promise<void>;\n diagnostics(): Promise<NestedHostDiagnostics>;\n close(): Promise<void>;\n }\n\n export function createIsolateHost(): NestedIsolateHost;\n}\n";
77
77
  /**
78
78
  * Map of package names to their type definitions.
79
79
  */
80
80
  export declare const TYPE_DEFINITIONS: {
81
81
  readonly core: "/**\n * Global Type Definitions for ../core/index.ts\n *\n * These types define the globals injected by setupCore() into an isolated-vm context.\n * Use these types to typecheck user code that will run inside the V8 isolate.\n *\n * @example\n * // In your tsconfig.isolate.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Async Context\n // ============================================\n\n interface AsyncContextVariableOptions<T = unknown> {\n defaultValue?: T;\n name?: string;\n }\n\n interface AsyncContextVariable<T = unknown> {\n readonly name: string;\n run<R, A extends unknown[]>(value: T, fn: (...args: A) => R, ...args: A): R;\n get(): T;\n }\n\n interface AsyncContextVariableConstructor {\n new <T = unknown>(options?: AsyncContextVariableOptions<T>): AsyncContextVariable<T>;\n readonly prototype: AsyncContextVariable<unknown>;\n }\n\n interface AsyncContextSnapshot {\n run<R, A extends unknown[]>(fn: (...args: A) => R, ...args: A): R;\n }\n\n interface AsyncContextSnapshotConstructor {\n new (): AsyncContextSnapshot;\n wrap<T extends (...args: any[]) => any>(fn: T): T;\n readonly prototype: AsyncContextSnapshot;\n }\n\n const AsyncContext: {\n Variable: AsyncContextVariableConstructor;\n Snapshot: AsyncContextSnapshotConstructor;\n };\n\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // DOM Parsing and Constructors\n // ============================================\n\n /**\n * Parses HTML/XML strings into Document objects.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser\n */\n const DOMParser: typeof globalThis.DOMParser;\n\n /**\n * Base DOM node constructor.\n */\n const Node: typeof globalThis.Node;\n\n /**\n * DOM document constructor.\n */\n const Document: typeof globalThis.Document;\n\n /**\n * DOM document fragment constructor.\n */\n const DocumentFragment: typeof globalThis.DocumentFragment;\n\n /**\n * DOM document type constructor.\n */\n const DocumentType: typeof globalThis.DocumentType;\n\n /**\n * DOM element constructor.\n */\n const Element: typeof globalThis.Element;\n\n /**\n * DOM attribute constructor.\n */\n const Attr: typeof globalThis.Attr;\n\n /**\n * DOM text node constructor.\n */\n const Text: typeof globalThis.Text;\n\n /**\n * DOM comment node constructor.\n */\n const Comment: typeof globalThis.Comment;\n\n /**\n * DOM event constructor.\n */\n const Event: typeof globalThis.Event;\n\n /**\n * Base event target constructor.\n */\n const EventTarget: typeof globalThis.EventTarget;\n\n /**\n * Custom event constructor.\n */\n const CustomEvent: typeof globalThis.CustomEvent;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n";
82
- readonly sandboxIsolate: "\ndeclare module \"@ricsam/isolate\" {\n export interface NestedModuleImporter {\n path: string;\n resolveDir: string;\n }\n\n export interface NestedModuleSource {\n code: string;\n filename: string;\n resolveDir: string;\n static?: boolean;\n }\n\n export type NestedModuleResolveResult =\n | string\n | NestedModuleSource\n | null\n | undefined\n | Promise<string | NestedModuleSource | null | undefined>;\n\n export interface NestedFileBindings {\n readFile?: (path: string) => Promise<ArrayBuffer>;\n writeFile?: (path: string, data: ArrayBuffer) => Promise<void>;\n unlink?: (path: string) => Promise<void>;\n readdir?: (path: string) => Promise<string[]>;\n mkdir?: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n rmdir?: (path: string) => Promise<void>;\n stat?: (\n path: string,\n ) => Promise<{ isFile: boolean; isDirectory: boolean; size: number }>;\n rename?: (from: string, to: string) => Promise<void>;\n }\n\n export interface NestedBrowserBindings {\n createContext?: (options: unknown) => Promise<unknown> | unknown;\n createPage?: (contextHandle: unknown) => Promise<unknown> | unknown;\n }\n\n export interface NestedHostBindings {\n console?: {\n onEntry?: (entry: unknown) => void;\n };\n fetch?: (request: Request) => Response | Promise<Response>;\n files?: NestedFileBindings;\n modules?: {\n resolve(\n specifier: string,\n importer: NestedModuleImporter,\n ): NestedModuleResolveResult;\n };\n tools?: Record<string, (...args: any[]) => unknown>;\n browser?: unknown;\n }\n\n export interface NestedRuntimeDiagnostics {\n activeRequests: number;\n activeResources: number;\n pendingFiles: number;\n pendingFetches: number;\n pendingModules: number;\n pendingTools: number;\n streamCount: number;\n lastError?: string;\n reused?: boolean;\n lifecycleState: \"idle\" | \"active\" | \"reloading\" | \"disposing\";\n }\n\n export interface NestedBrowserDiagnostics {\n contexts: number;\n pages: number;\n browserConsoleLogs: number;\n networkRequests: number;\n networkResponses: number;\n pageErrors: number;\n requestFailures: number;\n collectedData: {\n browserConsoleLogs: unknown[];\n pageErrors: unknown[];\n networkRequests: unknown[];\n networkResponses: unknown[];\n requestFailures: unknown[];\n };\n }\n\n export interface NestedRuntimeResourceDiagnostics {\n runtime: NestedRuntimeDiagnostics;\n browser?: NestedBrowserDiagnostics;\n }\n\n export interface NestedTestDiagnostics {\n enabled: true;\n registeredTests: number;\n lastRun?: unknown;\n }\n\n export interface NestedTestRuntimeDiagnostics extends NestedRuntimeResourceDiagnostics {\n test: NestedTestDiagnostics;\n }\n\n export interface NestedHostDiagnostics {\n runtimes: number;\n servers: number;\n connected: boolean;\n }\n\n export type NestedRequestResult =\n | { type: \"response\"; response: Response }\n | { type: \"websocket\"; upgradeData: Record<string, unknown> };\n\n export interface NestedScriptRuntime {\n eval(\n code: string,\n options?: string | { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedAppServer {\n handle(\n request: Request | string,\n options?: { requestId?: string; metadata?: Record<string, string> },\n ): Promise<NestedRequestResult>;\n ws: {\n open(connectionId: string): Promise<void>;\n message(connectionId: string, data: string | ArrayBuffer): Promise<void>;\n close(connectionId: string, code: number, reason: string): Promise<void>;\n error(connectionId: string, error: Error): Promise<void>;\n };\n reload(reason?: string): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n }\n\n export interface NestedTestRuntime {\n run(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n }\n\n export interface NestedNamespacedRuntime {\n eval(\n code: string,\n options?: { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n runTests(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedCreateRuntimeOptions {\n key?: string;\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateNamespacedRuntimeOptions {\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateTestRuntimeOptions extends NestedCreateRuntimeOptions {}\n\n export interface NestedCreateAppServerOptions extends NestedCreateRuntimeOptions {\n key: string;\n entry: string;\n entryFilename?: string;\n }\n\n export interface NestedIsolateHost {\n createRuntime(options?: NestedCreateRuntimeOptions): Promise<NestedScriptRuntime>;\n createAppServer(options: NestedCreateAppServerOptions): Promise<NestedAppServer>;\n createTestRuntime(\n options?: NestedCreateTestRuntimeOptions,\n ): Promise<NestedTestRuntime>;\n getNamespacedRuntime(\n key: string,\n options?: NestedCreateNamespacedRuntimeOptions,\n ): Promise<NestedNamespacedRuntime>;\n disposeNamespace(\n key: string,\n options?: { reason?: string },\n ): Promise<void>;\n diagnostics(): Promise<NestedHostDiagnostics>;\n close(): Promise<void>;\n }\n\n export function createIsolateHost(): NestedIsolateHost;\n}\n";
82
+ readonly sandboxIsolate: "\ndeclare module \"@ricsam/isolate\" {\n export interface NestedModuleImporter {\n path: string;\n resolveDir: string;\n }\n\n export interface NestedModuleSource {\n code: string;\n filename: string;\n resolveDir: string;\n static?: boolean;\n }\n\n export type NestedModuleResolveResult =\n | string\n | NestedModuleSource\n | null\n | undefined\n | Promise<string | NestedModuleSource | null | undefined>;\n\n export interface NestedFileBindings {\n readFile?: (path: string) => Promise<ArrayBuffer>;\n writeFile?: (path: string, data: ArrayBuffer) => Promise<void>;\n unlink?: (path: string) => Promise<void>;\n readdir?: (path: string) => Promise<string[]>;\n mkdir?: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n rmdir?: (path: string) => Promise<void>;\n stat?: (\n path: string,\n ) => Promise<{ isFile: boolean; isDirectory: boolean; size: number }>;\n rename?: (from: string, to: string) => Promise<void>;\n }\n\n export interface NestedBrowserBindings {\n createContext?: (options: unknown) => Promise<unknown> | unknown;\n createPage?: (contextHandle: unknown) => Promise<unknown> | unknown;\n }\n\n export interface NestedHostBindings {\n console?: {\n onEntry?: (entry: unknown) => void;\n };\n fetch?: (request: Request) => Response | Promise<Response>;\n files?: NestedFileBindings;\n modules?: {\n resolve(\n specifier: string,\n importer: NestedModuleImporter,\n ): NestedModuleResolveResult;\n };\n tools?: Record<string, (...args: any[]) => unknown>;\n browser?: unknown;\n }\n\n export interface NestedRuntimeDiagnostics {\n activeRequests: number;\n activeResources: number;\n pendingFiles: number;\n pendingFetches: number;\n pendingModules: number;\n pendingTools: number;\n streamCount: number;\n lastError?: string;\n reused?: boolean;\n lifecycleState: \"idle\" | \"active\" | \"reloading\" | \"disposing\";\n }\n\n export interface NestedBrowserDiagnostics {\n contexts: number;\n pages: number;\n browserConsoleLogs: number;\n networkRequests: number;\n networkResponses: number;\n pageErrors: number;\n requestFailures: number;\n collectedData: {\n browserConsoleLogs: unknown[];\n pageErrors: unknown[];\n networkRequests: unknown[];\n networkResponses: unknown[];\n requestFailures: unknown[];\n };\n }\n\n export interface NestedRuntimeResourceDiagnostics {\n runtime: NestedRuntimeDiagnostics;\n browser?: NestedBrowserDiagnostics;\n }\n\n export interface NestedTestDiagnostics {\n enabled: true;\n registeredTests: number;\n lastRun?: unknown;\n }\n\n export interface NestedSuiteInfo {\n name: string;\n path: string[];\n fullName: string;\n depth: number;\n }\n\n export interface NestedSuiteResult extends NestedSuiteInfo {\n passed: number;\n failed: number;\n skipped: number;\n todo: number;\n duration: number;\n }\n\n export interface NestedTestInfo {\n name: string;\n suitePath: string[];\n fullName: string;\n }\n\n export interface NestedTestError {\n message: string;\n stack?: string;\n expected?: unknown;\n actual?: unknown;\n matcherName?: string;\n }\n\n export interface NestedTestResult extends NestedTestInfo {\n status: \"pass\" | \"fail\" | \"skip\" | \"todo\";\n duration: number;\n error?: NestedTestError;\n }\n\n export type NestedTestEvent =\n | { type: \"runStart\"; testCount: number; suiteCount: number }\n | { type: \"suiteStart\"; suite: NestedSuiteInfo }\n | { type: \"suiteEnd\"; suite: NestedSuiteResult }\n | { type: \"testStart\"; test: NestedTestInfo }\n | { type: \"testEnd\"; test: NestedTestResult }\n | { type: \"runEnd\"; results: unknown };\n\n export interface NestedTestRuntimeDiagnostics extends NestedRuntimeResourceDiagnostics {\n test: NestedTestDiagnostics;\n }\n\n export interface NestedHostDiagnostics {\n runtimes: number;\n servers: number;\n connected: boolean;\n }\n\n export type NestedRequestResult =\n | { type: \"response\"; response: Response }\n | { type: \"websocket\"; upgradeData: Record<string, unknown> };\n\n export interface NestedScriptRuntime {\n eval(\n code: string,\n options?: string | { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedAppServer {\n handle(\n request: Request | string,\n options?: { requestId?: string; metadata?: Record<string, string> },\n ): Promise<NestedRequestResult>;\n ws: {\n open(connectionId: string): Promise<void>;\n message(connectionId: string, data: string | ArrayBuffer): Promise<void>;\n close(connectionId: string, code: number, reason: string): Promise<void>;\n error(connectionId: string, error: Error): Promise<void>;\n };\n reload(reason?: string): Promise<void>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n diagnostics(): Promise<NestedRuntimeResourceDiagnostics>;\n }\n\n export interface NestedTestRuntime {\n run(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n test: {\n onEvent(handler: (event: NestedTestEvent) => void): () => void;\n };\n }\n\n export interface NestedNamespacedRuntime {\n eval(\n code: string,\n options?: { filename?: string; executionTimeout?: number },\n ): Promise<void>;\n runTests(\n code: string,\n options?: { filename?: string; timeoutMs?: number },\n ): Promise<unknown>;\n diagnostics(): Promise<NestedTestRuntimeDiagnostics>;\n dispose(options?: { hard?: boolean; reason?: string }): Promise<void>;\n test: {\n onEvent(handler: (event: NestedTestEvent) => void): () => void;\n };\n events: {\n on(event: string, handler: (payload: unknown) => void): () => void;\n emit(event: string, payload: unknown): Promise<void>;\n };\n }\n\n export interface NestedCreateRuntimeOptions {\n key?: string;\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateNamespacedRuntimeOptions {\n bindings?: NestedHostBindings;\n cwd?: string;\n executionTimeout?: number;\n memoryLimitMB?: number;\n }\n\n export interface NestedCreateTestRuntimeOptions extends NestedCreateRuntimeOptions {}\n\n export interface NestedCreateAppServerOptions extends NestedCreateRuntimeOptions {\n key: string;\n entry: string;\n entryFilename?: string;\n }\n\n export interface NestedIsolateHost {\n createRuntime(options?: NestedCreateRuntimeOptions): Promise<NestedScriptRuntime>;\n createAppServer(options: NestedCreateAppServerOptions): Promise<NestedAppServer>;\n createTestRuntime(\n options?: NestedCreateTestRuntimeOptions,\n ): Promise<NestedTestRuntime>;\n getNamespacedRuntime(\n key: string,\n options?: NestedCreateNamespacedRuntimeOptions,\n ): Promise<NestedNamespacedRuntime>;\n disposeNamespace(\n key: string,\n options?: { reason?: string },\n ): Promise<void>;\n diagnostics(): Promise<NestedHostDiagnostics>;\n close(): Promise<void>;\n }\n\n export function createIsolateHost(): NestedIsolateHost;\n}\n";
83
83
  readonly console: "/**\n * Global Type Definitions for ../console/index.ts\n *\n * These types define the globals injected by setupConsole() into an isolated-vm context.\n * Use these types to typecheck user code that will run inside the V8 isolate.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Console interface for logging and debugging.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Console\n */\n interface Console {\n /**\n * Log a message to the console.\n * @param data - Values to log\n */\n log(...data: unknown[]): void;\n\n /**\n * Log a warning message.\n * @param data - Values to log\n */\n warn(...data: unknown[]): void;\n\n /**\n * Log an error message.\n * @param data - Values to log\n */\n error(...data: unknown[]): void;\n\n /**\n * Log a debug message.\n * @param data - Values to log\n */\n debug(...data: unknown[]): void;\n\n /**\n * Log an info message.\n * @param data - Values to log\n */\n info(...data: unknown[]): void;\n\n /**\n * Log a stack trace.\n * @param data - Values to log with the trace\n */\n trace(...data: unknown[]): void;\n\n /**\n * Display an object in a formatted way.\n * @param item - Object to display\n * @param options - Display options\n */\n dir(item: unknown, options?: object): void;\n\n /**\n * Display tabular data.\n * @param tabularData - Data to display as a table\n * @param properties - Optional array of property names to include\n */\n table(tabularData: unknown, properties?: string[]): void;\n\n /**\n * Start a timer.\n * @param label - Timer label (default: \"default\")\n */\n time(label?: string): void;\n\n /**\n * End a timer and log the elapsed time.\n * @param label - Timer label (default: \"default\")\n */\n timeEnd(label?: string): void;\n\n /**\n * Log the elapsed time of a timer without ending it.\n * @param label - Timer label (default: \"default\")\n * @param data - Additional values to log\n */\n timeLog(label?: string, ...data: unknown[]): void;\n\n /**\n * Log an error if the assertion is false.\n * @param condition - Condition to test\n * @param data - Values to log if assertion fails\n */\n assert(condition?: boolean, ...data: unknown[]): void;\n\n /**\n * Increment and log a counter.\n * @param label - Counter label (default: \"default\")\n */\n count(label?: string): void;\n\n /**\n * Reset a counter.\n * @param label - Counter label (default: \"default\")\n */\n countReset(label?: string): void;\n\n /**\n * Clear the console.\n */\n clear(): void;\n\n /**\n * Start an inline group.\n * @param data - Group label\n */\n group(...data: unknown[]): void;\n\n /**\n * Start a collapsed inline group.\n * @param data - Group label\n */\n groupCollapsed(...data: unknown[]): void;\n\n /**\n * End the current inline group.\n */\n groupEnd(): void;\n }\n\n /**\n * Console object for logging and debugging.\n */\n const console: Console;\n}\n";
84
84
  readonly crypto: "/**\n * Global Type Definitions for ../crypto/index.ts\n *\n * These types define the globals injected by setupCrypto() into an isolated-vm context.\n * Use these types to typecheck user code that will run inside the V8 isolate.\n *\n * @example\n * // Generate random bytes\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n *\n * // Generate UUID\n * const uuid = crypto.randomUUID();\n *\n * // Use SubtleCrypto\n * const key = await crypto.subtle.generateKey(\n * { name: \"AES-GCM\", length: 256 },\n * true,\n * [\"encrypt\", \"decrypt\"]\n * );\n */\n\nexport {};\n\ndeclare global {\n /**\n * CryptoKey represents a cryptographic key.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey\n */\n interface CryptoKey {\n /**\n * The type of key: \"public\", \"private\", or \"secret\".\n */\n readonly type: \"public\" | \"private\" | \"secret\";\n\n /**\n * Whether the key can be exported.\n */\n readonly extractable: boolean;\n\n /**\n * The algorithm used by this key.\n */\n readonly algorithm: KeyAlgorithm;\n\n /**\n * The usages allowed for this key.\n */\n readonly usages: ReadonlyArray<KeyUsage>;\n }\n\n /**\n * CryptoKey constructor (keys cannot be constructed directly).\n */\n const CryptoKey: {\n prototype: CryptoKey;\n };\n\n /**\n * SubtleCrypto interface for cryptographic operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto\n */\n interface SubtleCrypto {\n /**\n * Generate a digest (hash) of the given data.\n *\n * @param algorithm - Hash algorithm (e.g., \"SHA-256\", \"SHA-384\", \"SHA-512\")\n * @param data - Data to hash\n * @returns Promise resolving to the hash as ArrayBuffer\n */\n digest(\n algorithm: AlgorithmIdentifier,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Generate a new cryptographic key or key pair.\n *\n * @param algorithm - Key generation algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey or CryptoKeyPair\n */\n generateKey(\n algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey | CryptoKeyPair>;\n\n /**\n * Sign data using a private key.\n *\n * @param algorithm - Signing algorithm\n * @param key - Private key to sign with\n * @param data - Data to sign\n * @returns Promise resolving to the signature as ArrayBuffer\n */\n sign(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Verify a signature.\n *\n * @param algorithm - Signing algorithm\n * @param key - Public key to verify with\n * @param signature - Signature to verify\n * @param data - Data that was signed\n * @returns Promise resolving to true if valid, false otherwise\n */\n verify(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n signature: BufferSource,\n data: BufferSource\n ): Promise<boolean>;\n\n /**\n * Encrypt data.\n *\n * @param algorithm - Encryption algorithm\n * @param key - Encryption key\n * @param data - Data to encrypt\n * @returns Promise resolving to encrypted data as ArrayBuffer\n */\n encrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Decrypt data.\n *\n * @param algorithm - Decryption algorithm\n * @param key - Decryption key\n * @param data - Data to decrypt\n * @returns Promise resolving to decrypted data as ArrayBuffer\n */\n decrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Import a key from external data.\n *\n * @param format - Key format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param keyData - Key data\n * @param algorithm - Key algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey\n */\n importKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n keyData: BufferSource | JsonWebKey,\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Export a key.\n *\n * @param format - Export format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param key - Key to export\n * @returns Promise resolving to ArrayBuffer or JsonWebKey\n */\n exportKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey\n ): Promise<ArrayBuffer | JsonWebKey>;\n\n /**\n * Derive bits from a key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param length - Number of bits to derive\n * @returns Promise resolving to derived bits as ArrayBuffer\n */\n deriveBits(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n length: number\n ): Promise<ArrayBuffer>;\n\n /**\n * Derive a new key from a base key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param derivedKeyType - Type of key to derive\n * @param extractable - Whether the derived key can be exported\n * @param keyUsages - Allowed usages for derived key\n * @returns Promise resolving to a CryptoKey\n */\n deriveKey(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n derivedKeyType: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Wrap a key for secure export.\n *\n * @param format - Key format\n * @param key - Key to wrap\n * @param wrappingKey - Key to wrap with\n * @param wrapAlgorithm - Wrapping algorithm\n * @returns Promise resolving to wrapped key as ArrayBuffer\n */\n wrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey,\n wrappingKey: CryptoKey,\n wrapAlgorithm: AlgorithmIdentifier\n ): Promise<ArrayBuffer>;\n\n /**\n * Unwrap a wrapped key.\n *\n * @param format - Key format\n * @param wrappedKey - Wrapped key data\n * @param unwrappingKey - Key to unwrap with\n * @param unwrapAlgorithm - Unwrapping algorithm\n * @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key\n * @param extractable - Whether the unwrapped key can be exported\n * @param keyUsages - Allowed usages for unwrapped key\n * @returns Promise resolving to a CryptoKey\n */\n unwrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n wrappedKey: BufferSource,\n unwrappingKey: CryptoKey,\n unwrapAlgorithm: AlgorithmIdentifier,\n unwrappedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n }\n\n /**\n * Crypto interface providing cryptographic functionality.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto\n */\n interface Crypto {\n /**\n * SubtleCrypto interface for cryptographic operations.\n */\n readonly subtle: SubtleCrypto;\n\n /**\n * Fill a TypedArray with cryptographically random values.\n *\n * @param array - TypedArray to fill (max 65536 bytes)\n * @returns The same array, filled with random values\n *\n * @example\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n */\n getRandomValues<T extends ArrayBufferView | null>(array: T): T;\n\n /**\n * Generate a random UUID v4.\n *\n * @returns A random UUID string\n *\n * @example\n * const uuid = crypto.randomUUID();\n * // \"550e8400-e29b-41d4-a716-446655440000\"\n */\n randomUUID(): string;\n }\n\n /**\n * Crypto object providing cryptographic functionality.\n */\n const crypto: Crypto;\n}\n";
85
85
  readonly encoding: "/**\n * Global Type Definitions for ../encoding/index.ts\n *\n * These types define the globals injected by setupEncoding() into an isolated-vm context.\n * Use these types to typecheck user code that will run inside the V8 isolate.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n\n // ============================================\n // Buffer\n // ============================================\n\n /**\n * Buffer encoding types supported by the isolate Buffer implementation.\n */\n type BufferEncoding = \"utf8\" | \"utf-8\" | \"base64\" | \"hex\";\n\n /**\n * Buffer class for working with binary data.\n * Extends Uint8Array for compatibility.\n * @see https://nodejs.org/api/buffer.html\n */\n interface Buffer extends Uint8Array {\n /**\n * Convert the buffer to a string.\n *\n * @param encoding - The encoding to use (default: \"utf8\")\n * @returns The string representation\n *\n * @example\n * const buf = Buffer.from(\"hello\");\n * buf.toString(); // \"hello\"\n * buf.toString(\"hex\"); // \"68656c6c6f\"\n * buf.toString(\"base64\"); // \"aGVsbG8=\"\n */\n toString(encoding?: BufferEncoding): string;\n\n /**\n * Returns a new Buffer that references the same memory as the original,\n * but offset and cropped by the start and end indices.\n *\n * @param start - Start index (default: 0)\n * @param end - End index (default: buffer.length)\n * @returns A new Buffer instance\n *\n * @example\n * const buf = Buffer.from(\"hello\");\n * buf.slice(1, 4).toString(); // \"ell\"\n */\n slice(start?: number, end?: number): Buffer;\n\n /**\n * Returns a new Buffer that references the same memory as the original,\n * but offset and cropped by the start and end indices.\n *\n * @param start - Start index (default: 0)\n * @param end - End index (default: buffer.length)\n * @returns A new Buffer instance\n */\n subarray(start?: number, end?: number): Buffer;\n }\n\n /**\n * Buffer constructor interface.\n */\n interface BufferConstructor {\n /**\n * Creates a new Buffer from a string, array, ArrayBuffer, or another Buffer.\n *\n * @param value - The value to create a buffer from\n * @param encodingOrOffset - Encoding for strings, or byte offset for ArrayBuffer\n * @param length - Length for ArrayBuffer (when offset is provided)\n * @returns A new Buffer instance\n *\n * @example\n * Buffer.from(\"hello\"); // UTF-8 encoded\n * Buffer.from(\"aGVsbG8=\", \"base64\"); // base64 decoded\n * Buffer.from(\"68656c6c6f\", \"hex\"); // hex decoded\n * Buffer.from([104, 101, 108, 108, 111]); // from array\n */\n from(value: string, encoding?: BufferEncoding): Buffer;\n from(value: ArrayBuffer, byteOffset?: number, length?: number): Buffer;\n from(value: Uint8Array | ReadonlyArray<number>): Buffer;\n from(value: Iterable<number>): Buffer;\n\n /**\n * Allocates a new Buffer of the specified size, filled with zeros or the specified fill value.\n *\n * @param size - The size of the buffer in bytes\n * @param fill - Value to fill the buffer with (default: 0)\n * @param encoding - Encoding for string fill values\n * @returns A new Buffer instance\n *\n * @example\n * Buffer.alloc(5); // <Buffer 00 00 00 00 00>\n * Buffer.alloc(5, 1); // <Buffer 01 01 01 01 01>\n * Buffer.alloc(5, \"ab\"); // <Buffer 61 62 61 62 61>\n */\n alloc(size: number, fill?: number | string | Buffer, encoding?: BufferEncoding): Buffer;\n\n /**\n * Allocates a new Buffer of the specified size without initializing the memory.\n * The contents are unknown and may contain sensitive data.\n *\n * @param size - The size of the buffer in bytes\n * @returns A new Buffer instance\n */\n allocUnsafe(size: number): Buffer;\n\n /**\n * Concatenates a list of Buffers.\n *\n * @param list - Array of Buffer instances to concatenate\n * @param totalLength - Total length of the buffers (optional)\n * @returns A new Buffer instance\n *\n * @example\n * const buf1 = Buffer.from(\"hel\");\n * const buf2 = Buffer.from(\"lo\");\n * Buffer.concat([buf1, buf2]).toString(); // \"hello\"\n */\n concat(list: ReadonlyArray<Uint8Array>, totalLength?: number): Buffer;\n\n /**\n * Returns true if the given object is a Buffer.\n *\n * @param obj - Object to test\n * @returns true if obj is a Buffer\n *\n * @example\n * Buffer.isBuffer(Buffer.from(\"test\")); // true\n * Buffer.isBuffer(new Uint8Array(5)); // false\n */\n isBuffer(obj: unknown): obj is Buffer;\n\n /**\n * Returns the byte length of a string when encoded.\n *\n * @param string - The string to measure\n * @param encoding - The encoding (default: \"utf8\")\n * @returns The byte length\n *\n * @example\n * Buffer.byteLength(\"hello\"); // 5\n * Buffer.byteLength(\"aGVsbG8=\", \"base64\"); // 5 (decoded length)\n */\n byteLength(string: string, encoding?: BufferEncoding): number;\n byteLength(buffer: ArrayBufferView | ArrayBuffer): number;\n\n /**\n * Returns true if the encoding is a valid buffer encoding.\n *\n * @param encoding - The encoding to check\n * @returns true if the encoding is supported\n */\n isEncoding(encoding: string): encoding is BufferEncoding;\n\n readonly prototype: Buffer;\n }\n\n /**\n * Buffer class for working with binary data.\n * @see https://nodejs.org/api/buffer.html\n */\n const Buffer: BufferConstructor;\n}\n";
@@ -1,11 +1,13 @@
1
1
  import { type MutableRuntimeDiagnostics } from "../bridge/diagnostics.ts";
2
2
  import { type RemoteRuntime } from "../internal/client/index.ts";
3
+ import type { TestEventSubscriptions } from "./test-event-subscriptions.ts";
3
4
  import type { NamespacedRuntime } from "../types.ts";
4
5
  export interface NamespacedRuntimeAdapter extends NamespacedRuntime {
5
6
  invalidate(reason?: string): void;
6
7
  }
7
- export declare function createNamespacedRuntimeAdapter(runtime: RemoteRuntime, diagnostics: MutableRuntimeDiagnostics, options?: {
8
+ export declare function createNamespacedRuntimeAdapter(runtime: RemoteRuntime, diagnostics: MutableRuntimeDiagnostics, options: {
8
9
  hasBrowser?: boolean;
9
10
  abortBindings?: (reason?: string) => void;
10
11
  onRelease?: () => void;
12
+ testEvents: TestEventSubscriptions;
11
13
  }): NamespacedRuntimeAdapter;
@@ -0,0 +1,12 @@
1
+ import type { TestEvent } from "../types.ts";
2
+ interface TestEventApi {
3
+ onEvent(handler: (event: TestEvent) => void): () => void;
4
+ }
5
+ export interface TestEventSubscriptions {
6
+ readonly api: TestEventApi;
7
+ emit(event: TestEvent): void;
8
+ clear(): void;
9
+ setEnsureUsable(ensureUsable?: () => void): void;
10
+ }
11
+ export declare function createTestEventSubscriptions(ensureUsable?: () => void): TestEventSubscriptions;
12
+ export {};
@@ -175,6 +175,9 @@ export interface TestRuntime {
175
175
  hard?: boolean;
176
176
  reason?: string;
177
177
  }): Promise<void>;
178
+ test: {
179
+ onEvent(handler: (event: TestEvent) => void): () => void;
180
+ };
178
181
  }
179
182
  export interface NamespacedRuntime {
180
183
  eval(code: string, options?: {
@@ -190,6 +193,9 @@ export interface NamespacedRuntime {
190
193
  hard?: boolean;
191
194
  reason?: string;
192
195
  }): Promise<void>;
196
+ test: {
197
+ onEvent(handler: (event: TestEvent) => void): () => void;
198
+ };
193
199
  events: {
194
200
  on(event: string, handler: (payload: unknown) => void): () => void;
195
201
  emit(event: string, payload: unknown): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/isolate",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "description": "Unified runtime host for app servers, script runtimes, browser runtimes, module resolution, file bindings, and typechecking",
6
6
  "author": "ricsam <oss@ricsam.dev>",