@specific.dev/spectest 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/aws-sigv4.d.ts +42 -0
  2. package/dist/aws-sigv4.js +166 -0
  3. package/dist/browser.d.ts +314 -0
  4. package/dist/browser.js +1320 -0
  5. package/dist/components/email.d.ts +135 -0
  6. package/dist/components/email.js +271 -0
  7. package/dist/components/expo.d.ts +69 -0
  8. package/dist/components/expo.js +125 -0
  9. package/dist/components/index.d.ts +8 -0
  10. package/dist/components/index.js +18 -0
  11. package/dist/components/k3s.d.ts +143 -0
  12. package/dist/components/k3s.js +1067 -0
  13. package/dist/components/postgres.d.ts +93 -0
  14. package/dist/components/postgres.js +58 -0
  15. package/dist/components/replayFake.d.ts +169 -0
  16. package/dist/components/replayFake.js +738 -0
  17. package/dist/components/s3.d.ts +99 -0
  18. package/dist/components/s3.js +81 -0
  19. package/dist/components/supabase.d.ts +197 -0
  20. package/dist/components/supabase.js +1003 -0
  21. package/dist/daemon.d.ts +1 -0
  22. package/dist/daemon.js +4223 -0
  23. package/dist/ids.d.ts +2 -0
  24. package/{src/ids.ts → dist/ids.js} +46 -50
  25. package/dist/index.d.ts +1183 -0
  26. package/dist/index.js +769 -0
  27. package/dist/ingress.d.ts +114 -0
  28. package/dist/ingress.js +210 -0
  29. package/dist/inspect.d.ts +228 -0
  30. package/dist/inspect.js +429 -0
  31. package/dist/locator.d.ts +260 -0
  32. package/dist/locator.js +293 -0
  33. package/dist/mobile.d.ts +71 -0
  34. package/dist/mobile.js +65 -0
  35. package/dist/record-secrets.d.ts +9 -0
  36. package/{src/record-secrets.ts → dist/record-secrets.js} +13 -15
  37. package/dist/recorder.d.ts +516 -0
  38. package/dist/recorder.js +219 -0
  39. package/dist/redis.d.ts +54 -0
  40. package/dist/redis.js +126 -0
  41. package/dist/replay-bundle.d.ts +38 -0
  42. package/{src/replay-bundle.ts → dist/replay-bundle.js} +29 -47
  43. package/dist/resolver.d.ts +1 -0
  44. package/dist/resolver.js +309 -0
  45. package/dist/s3.d.ts +89 -0
  46. package/dist/s3.js +198 -0
  47. package/dist/sql.d.ts +74 -0
  48. package/dist/sql.js +151 -0
  49. package/dist/terminal.d.ts +161 -0
  50. package/dist/terminal.js +538 -0
  51. package/package.json +24 -9
  52. package/src/browser.ts +0 -1819
  53. package/src/components/email.ts +0 -398
  54. package/src/components/expo.ts +0 -167
  55. package/src/components/index.ts +0 -63
  56. package/src/components/k3s.ts +0 -1312
  57. package/src/components/postgres.ts +0 -105
  58. package/src/components/replayFake.ts +0 -848
  59. package/src/components/s3.ts +0 -132
  60. package/src/components/supabase.ts +0 -1299
  61. package/src/daemon.ts +0 -4969
  62. package/src/index.ts +0 -2350
  63. package/src/ingress.ts +0 -288
  64. package/src/inspect.ts +0 -673
  65. package/src/locator.ts +0 -594
  66. package/src/mobile.ts +0 -133
  67. package/src/recorder.ts +0 -817
  68. package/src/redis.ts +0 -202
  69. package/src/resolver.ts +0 -351
  70. package/src/s3.ts +0 -333
  71. package/src/sql.ts +0 -243
  72. package/src/terminal.ts +0 -740
  73. package/src/vendor/rrweb-plugin-console-record.umd.js +0 -521
  74. package/src/vendor/rrweb-record.min.js +0 -5061
package/dist/mobile.js ADDED
@@ -0,0 +1,65 @@
1
+ // Mobile app handle for tests — drives an Expo/React-Native-Web app rendered
2
+ // in a phone-emulated headless Chromium and recorded as an rrweb session that
3
+ // the dashboard replays inside a phone bezel.
4
+ //
5
+ // `ctx.mobile(ctx.svc.app)` opens one of these already pointed at the app. The
6
+ // surface is the SAME Playwright-native one as `ctx.browser()` (the shared
7
+ // `Browser` session + `Locator`s from browser.ts/locator.ts) plus two mobile
8
+ // extensions: a `touchscreen` and `swipe`. There is no mobile-specific locator
9
+ // type — `getByTestId`/`getByRole`/`getByText`/… return the same `Locator`,
10
+ // and on a mobile session a locator's `tap()` dispatches a real CDP touch with
11
+ // the press dwell RN Pressables need (the `mobileStrategy` in locator.ts;
12
+ // desktop `tap()` throws and steers you to `click()`).
13
+ //
14
+ // This file is now just the `MobileApp` handle (`ctx.mobile` accepts it) and
15
+ // the `Mobile` public view of the shared backend. React Native Web renders
16
+ // `testID="x"` to `data-testid="x"` and `accessibilityLabel` to `aria-label`,
17
+ // so `getByTestId`/`getByLabel` map straight onto Playwright's built-ins.
18
+ import { acquirePersistentMobileBackend, openMobileBackend } from "./browser.js";
19
+ /** Branded handle a mobile-app component (e.g. `expo()`) exposes on
20
+ * `ctx.svc.<name>`. The brand is a `Symbol.for` key so `JSON.stringify`
21
+ * drops it (wire-invisible) while `ctx.mobile(...)` can still type-check
22
+ * against it. */
23
+ export const MOBILE_APP = Symbol.for("spectest.mobileApp");
24
+ /** True if `x` is a {@link MobileApp} handle. */
25
+ export function isMobileApp(x) {
26
+ return (typeof x === "object" &&
27
+ x !== null &&
28
+ x[MOBILE_APP] === true &&
29
+ typeof x.url === "string");
30
+ }
31
+ /** Build a {@link MobileApp} handle from a resolved URL (and an optional
32
+ * init script installed before the session's first navigation). */
33
+ export function mobileApp(url, initScript) {
34
+ return { [MOBILE_APP]: true, url, initScript };
35
+ }
36
+ /**
37
+ * Open an EPHEMERAL phone-emulated session pointed at `url` (`close()`
38
+ * destroys it). Library callers only — the daemon's `ctx.mobile(app)` goes
39
+ * through {@link openPersistentMobile} so sessions survive across tests.
40
+ */
41
+ export async function openMobile(opts) {
42
+ const backend = await openMobileBackend({
43
+ frame: "mobile",
44
+ url: opts.url,
45
+ recorder: opts.recorder,
46
+ });
47
+ // MobileBackend is a superset of Mobile (adds the low-level primitives).
48
+ return backend;
49
+ }
50
+ /**
51
+ * Acquire the persistent phone-emulated session for an app (one per app URL,
52
+ * created on first use). The daemon calls this from `ctx.mobile(app)` with a
53
+ * per-test rrweb recorder; the resulting record carries `frame: "mobile"` so
54
+ * the dashboard renders a phone bezel. `detach` is the test-end hook;
55
+ * `mobile.close()` destroys the session for real.
56
+ */
57
+ export async function openPersistentMobile(opts) {
58
+ const { browser, attached, detach } = await acquirePersistentMobileBackend(opts.url, opts.recorder, opts.initScript);
59
+ return {
60
+ mobile: browser,
61
+ attached,
62
+ detach,
63
+ safeAreaInsets: browser.safeAreaInsets,
64
+ };
65
+ }
@@ -0,0 +1,9 @@
1
+ /** Replace the eval-scoped secret set. Called by the daemon at the start
2
+ * of each `/eval` with the values the control plane resolved. */
3
+ export declare function setRecordSecrets(secrets: Record<string, string> | undefined): void;
4
+ /** Drop all secrets. Called from the eval's `finally` so nothing survives
5
+ * past the eval that supplied them. */
6
+ export declare function clearRecordSecrets(): void;
7
+ /** Resolve a secret by its platform `ref`. `undefined` if the control
8
+ * plane didn't supply it (ref not configured, or not on the eval path). */
9
+ export declare function getRecordSecret(ref: string): string | undefined;
@@ -15,27 +15,25 @@
15
15
  // eval means a secret never persists into anything a replay run can reach.
16
16
  // This module is shared (one instance per daemon process) so the daemon
17
17
  // writes and the component reads the same map.
18
-
19
- const SECRETS = new Map<string, string>();
20
-
18
+ const SECRETS = new Map();
21
19
  /** Replace the eval-scoped secret set. Called by the daemon at the start
22
20
  * of each `/eval` with the values the control plane resolved. */
23
- export function setRecordSecrets(secrets: Record<string, string> | undefined): void {
24
- SECRETS.clear();
25
- if (!secrets) return;
26
- for (const [ref, value] of Object.entries(secrets)) {
27
- if (typeof value === "string") SECRETS.set(ref, value);
28
- }
21
+ export function setRecordSecrets(secrets) {
22
+ SECRETS.clear();
23
+ if (!secrets)
24
+ return;
25
+ for (const [ref, value] of Object.entries(secrets)) {
26
+ if (typeof value === "string")
27
+ SECRETS.set(ref, value);
28
+ }
29
29
  }
30
-
31
30
  /** Drop all secrets. Called from the eval's `finally` so nothing survives
32
31
  * past the eval that supplied them. */
33
- export function clearRecordSecrets(): void {
34
- SECRETS.clear();
32
+ export function clearRecordSecrets() {
33
+ SECRETS.clear();
35
34
  }
36
-
37
35
  /** Resolve a secret by its platform `ref`. `undefined` if the control
38
36
  * plane didn't supply it (ref not configured, or not on the eval path). */
39
- export function getRecordSecret(ref: string): string | undefined {
40
- return SECRETS.get(ref);
37
+ export function getRecordSecret(ref) {
38
+ return SECRETS.get(ref);
41
39
  }
@@ -0,0 +1,516 @@
1
+ export type TestEvent = ExecEvent | AssertionEvent | HttpEvent | KubeEvent | BrowserEvent | DbEvent | RedisEvent | S3Event | TerminalEvent | TerminalStepEvent | WaitEvent | FakeEvent | EnvEvent | EmailEvent;
2
+ interface BaseEvent {
3
+ /** Order of *start* within the test. Reserved when an op begins (see
4
+ * `reserveEvent`), so an op whose nested children finish — and record —
5
+ * before it does still sorts ahead of them. Ops that don't reserve get
6
+ * their seq at record (= finish) time. */
7
+ seq: number;
8
+ /** Milliseconds since the recorder started, captured when the op began
9
+ * (reserved) or, absent a reservation, when it was recorded. */
10
+ tOffsetMs: number;
11
+ /**
12
+ * Optional grouping pointer. When set, this event was emitted inside
13
+ * a larger logical step (e.g. an HTTP call that fed the predicate of
14
+ * a `ctx.poll(...)`) and should render nested under the parent in
15
+ * timelines. The parent event is identified by its `seq`.
16
+ */
17
+ parentSeq?: number;
18
+ }
19
+ export interface ExecEvent extends BaseEvent {
20
+ kind: "exec";
21
+ service: string;
22
+ command: string;
23
+ /**
24
+ * Working directory the command ran from (`ctx.exec(svc, cmd, { cwd })`),
25
+ * if any. Kept off `command` so the sidebar shows just the command; the
26
+ * detail view surfaces it. Absent when the call used no `cwd`.
27
+ */
28
+ cwd?: string;
29
+ exitCode: number;
30
+ /** stdout truncated to OUTPUT_SNIPPET_BYTES. */
31
+ stdout: string;
32
+ stdoutTruncated: boolean;
33
+ stderr: string;
34
+ stderrTruncated: boolean;
35
+ durationMs: number;
36
+ /**
37
+ * Links this exec to the asciicast `TerminalSessionRecord` of its run
38
+ * (mirroring `TerminalEvent.sessionId`): one exec step covers one full
39
+ * CLI run, so the whole recording belongs to this event. Absent on
40
+ * events recorded before exec runs were captured.
41
+ */
42
+ sessionId?: string;
43
+ }
44
+ export interface AssertionEvent extends BaseEvent {
45
+ kind: "assertion";
46
+ /** Matcher name, e.g. "toBe", "toEqual". */
47
+ matcher: string;
48
+ /** Whether this was `expect(x).not.toBe(...)`. */
49
+ negated: boolean;
50
+ passed: boolean;
51
+ /** Best-effort JSON-safe serialization. */
52
+ actual: unknown;
53
+ expected?: unknown;
54
+ /** Failure message produced by the matcher (only when `passed` is false). */
55
+ error?: string;
56
+ /**
57
+ * Author-supplied label for the assertion. **Required** for a raw assertion
58
+ * (`expectRaw(value, message)`), where it renders as the summary
59
+ * ("ASSERT <message>") and serves as the diff-alignment key since a raw
60
+ * assertion has no provenance `path`. **Optional** for a provenance-linked
61
+ * `expect(value, message)`, where it leads the summary as a clarifying note
62
+ * alongside the rendered matcher/target. Absent when `expect(...)` was called
63
+ * without a message.
64
+ */
65
+ message?: string;
66
+ /**
67
+ * `seq` of the op (http / db / browser) whose return value this
68
+ * assertion drilled into. Set when `expect()` received a value wrapped
69
+ * by `inspect.wrap()`. The UI nests assertions with `sourceSeq` under
70
+ * the matching op; assertions without it render at top level.
71
+ */
72
+ sourceSeq?: number;
73
+ /** JSON-path of property accesses from the op return value down to
74
+ * the asserted value (e.g. `["body", "user", "name"]`). Empty for
75
+ * direct asserts on the op return itself. */
76
+ path?: string[];
77
+ }
78
+ export interface DbEvent extends BaseEvent {
79
+ kind: "db";
80
+ /** Service the query ran against (the key in `environment.services`). */
81
+ service: string;
82
+ /** SQL text. For tagged-template calls, values appear as `$1`, `$2`, … */
83
+ query: string;
84
+ /** Parameter values. Best-effort JSON-safe; large/binary values stringified. */
85
+ params?: unknown[];
86
+ /** Rows returned — or rows AFFECTED when `rowsAffected` is set. */
87
+ rowCount?: number;
88
+ /** Set when `rowCount` counts affected rows (a non-RETURNING
89
+ * INSERT/UPDATE/DELETE) rather than a result set — rendered as
90
+ * "N affected" so an `UPDATE → 0 rows` can't read as "nothing updated". */
91
+ rowsAffected?: boolean;
92
+ /** Captured rows for table rendering in the web UI. Capped at
93
+ * MAX_DB_ROWS; `rowsTruncated` is set when there were more. */
94
+ rows?: unknown[];
95
+ rowsTruncated?: boolean;
96
+ /** Column names in the order Bun.SQL returned them. Derived from the
97
+ * first captured row, so omitted when no rows. */
98
+ columns?: string[];
99
+ durationMs: number;
100
+ /** Set if the driver threw. */
101
+ error?: string;
102
+ }
103
+ /**
104
+ * One Redis/Valkey command issued through the instrumented {@link
105
+ * "../redis".RedisClient} (a drop-in for `Bun.RedisClient` / `Bun.redis`).
106
+ *
107
+ * The return value is `wrap()`ped against this event's seq, so a later
108
+ * `expect(...)` that drills into it nests under this step in the timeline
109
+ * (same mechanism as http/db).
110
+ */
111
+ export interface RedisEvent extends BaseEvent {
112
+ kind: "redis";
113
+ /** Label for the connection — the URL host (often the service name). */
114
+ service: string;
115
+ /** Command name, upper-cased (`GET`, `SET`, `HGETALL`, `PUBLISH`, …). */
116
+ command: string;
117
+ /** First argument — almost always the key the command targets. Surfaced
118
+ * separately so the UI can read `GET session:42` at a glance. */
119
+ key?: string;
120
+ /** Remaining arguments (best-effort JSON-safe; large/binary stringified).
121
+ * Omitted when there are none. */
122
+ args?: unknown[];
123
+ /** Reply, best-effort JSON-safe and capped. Omitted when the command threw
124
+ * or returned `null`/`undefined`. */
125
+ result?: unknown;
126
+ resultTruncated?: boolean;
127
+ durationMs: number;
128
+ /** Set if the command threw. */
129
+ error?: string;
130
+ }
131
+ /**
132
+ * One object-storage operation through the instrumented {@link
133
+ * "../s3".S3Client} (a drop-in for `Bun.S3Client` / `Bun.s3`), covering both
134
+ * client-level calls (`write`/`delete`/`exists`/`list`/`presign`/`stat`) and
135
+ * the `S3File` handle `.file(path)` returns (`text`/`json`/`write`/…).
136
+ *
137
+ * The return value is `wrap()`ped against this event's seq, so `expect(...)`
138
+ * drilling into it nests under this step (same mechanism as http/db).
139
+ */
140
+ export interface S3Event extends BaseEvent {
141
+ kind: "s3";
142
+ /** Operation: `write` | `read` | `delete` | `exists` | `list` |
143
+ * `presign` | `stat`. */
144
+ op: string;
145
+ /** Bucket, when the client/handle knows it. */
146
+ bucket?: string;
147
+ /** Object key (path) the op targeted. Omitted for bucket-wide `list`. */
148
+ key?: string;
149
+ /** Bytes written or read, when known. */
150
+ size?: number;
151
+ /** Content type, when known (read/write/stat). */
152
+ contentType?: string;
153
+ /** Small text preview of the body (read/write of text), capped. */
154
+ preview?: string;
155
+ previewTruncated?: boolean;
156
+ /** For `list`: number of keys returned. */
157
+ count?: number;
158
+ durationMs: number;
159
+ /** Set if the op threw. */
160
+ error?: string;
161
+ }
162
+ export interface HttpEvent extends BaseEvent {
163
+ kind: "http";
164
+ method: string;
165
+ url: string;
166
+ /** Truncated to OUTPUT_SNIPPET_BYTES. Only set for non-binary text bodies. */
167
+ requestBody?: string;
168
+ requestBodyTruncated?: boolean;
169
+ status?: number;
170
+ responseBody?: string;
171
+ responseBodyTruncated?: boolean;
172
+ durationMs: number;
173
+ /** Set if the request threw (network error, abort, etc.). */
174
+ error?: string;
175
+ }
176
+ /**
177
+ * A Kubernetes API call (from `ctx.svc.<k3s>.client.*` / `apply(...)`).
178
+ *
179
+ * The k3s component routes the kube client through `globalThis.fetch`, so
180
+ * the daemon's fetch wrapper first records it as a plain `http` event;
181
+ * the component then parses the request path and *reclassifies* that event
182
+ * into this richer shape via `recorderAnnotate`, so the UI can show
183
+ * `verb resource/name` (e.g. `list pods · default`) instead of an opaque
184
+ * `GET https://k8s.internal:6443/api/v1/...`. The underlying HTTP fields
185
+ * are retained so the request/response bodies (the actual K8s objects)
186
+ * still render in the detail view, and `expect(...)` on the returned
187
+ * object nests under this event exactly as it does for `http`.
188
+ */
189
+ export interface KubeEvent extends BaseEvent {
190
+ kind: "kube";
191
+ /** API verb derived from the HTTP method + path shape: `get` | `list` |
192
+ * `watch` | `create` | `update` | `patch` | `delete` |
193
+ * `deletecollection`. */
194
+ verb: string;
195
+ /** API group — `""` for the core group (`/api/v1`), else e.g. `"apps"`,
196
+ * `"networking.k8s.io"`. */
197
+ group?: string;
198
+ /** API version, e.g. `"v1"`. */
199
+ apiVersion?: string;
200
+ /** Resource plural, e.g. `"pods"`, `"deployments"`, `"ingresses"`. */
201
+ resource?: string;
202
+ /** Subresource, when addressed, e.g. `"status"`, `"scale"`, `"log"`. */
203
+ subresource?: string;
204
+ /** Object name, when the request targets a single object. */
205
+ name?: string;
206
+ /** Namespace, when namespaced. Absent for cluster-scoped requests. */
207
+ namespace?: string;
208
+ method: string;
209
+ url: string;
210
+ requestBody?: string;
211
+ requestBodyTruncated?: boolean;
212
+ status?: number;
213
+ responseBody?: string;
214
+ responseBodyTruncated?: boolean;
215
+ durationMs: number;
216
+ error?: string;
217
+ }
218
+ /**
219
+ * One call to a fake's helper function (`ctx.fakes.<name>.<fn>(...)`).
220
+ * Helpers are user-authored functions that read or mutate the fake's
221
+ * private state, so this is the only window into what a test asked the
222
+ * fake — distinct from the `http` events the *app under test* generates
223
+ * when it actually calls the fake's endpoints.
224
+ *
225
+ * The return value is `wrap()`ped against this event's seq, so a later
226
+ * `expect(...)` that drills into it nests under this step in the
227
+ * timeline (same mechanism as http/db/exec).
228
+ */
229
+ export interface FakeEvent extends BaseEvent {
230
+ kind: "fake";
231
+ /** Fake name — the key in `ctx.fakes`. */
232
+ fake: string;
233
+ /** Helper function called, e.g. `"lastCharge"`. */
234
+ member: string;
235
+ /** Call arguments (best-effort JSON-safe). */
236
+ args?: unknown[];
237
+ /** Return value (best-effort JSON-safe). Omitted when the helper threw
238
+ * or returned `undefined`. */
239
+ result?: unknown;
240
+ durationMs: number;
241
+ /** Set if the helper threw. */
242
+ error?: string;
243
+ }
244
+ /**
245
+ * One captured email, as embedded on an {@link EmailEvent}. The HTML and
246
+ * text bodies ride along (truncated to the output cap) so the dashboard
247
+ * can render the actual email a test asserted against.
248
+ */
249
+ export interface EmailEventMessage {
250
+ /** Sender address. */
251
+ from?: string;
252
+ /** Recipient addresses. */
253
+ to?: string[];
254
+ cc?: string[];
255
+ bcc?: string[];
256
+ subject?: string;
257
+ /** RFC date of the message, ISO-formatted. */
258
+ date?: string;
259
+ /** HTML body (truncated to the output cap). */
260
+ html?: string;
261
+ htmlTruncated?: boolean;
262
+ /** Plain-text body (truncated to the output cap). */
263
+ text?: string;
264
+ textTruncated?: boolean;
265
+ attachments?: {
266
+ filename: string;
267
+ contentType: string;
268
+ size: number;
269
+ }[];
270
+ }
271
+ /** One row of a mailbox listing embedded on an {@link EmailEvent}. */
272
+ export interface EmailEventSummary {
273
+ from?: string;
274
+ to?: string[];
275
+ subject?: string;
276
+ /** Plain-text preview of the body. */
277
+ snippet?: string;
278
+ date?: string;
279
+ }
280
+ /**
281
+ * One call to an email service's helpers (`ctx.svc.<name>.lastEmail(...)`
282
+ * etc.). Single-message ops embed the full captured message — including its
283
+ * HTML body — so timelines can render the email itself; listing ops embed
284
+ * compact summaries. The return value is `wrap()`ped against this event's
285
+ * seq, so `expect(...)` on it nests under this step (same mechanism as
286
+ * http/db/fake). Inside a `ctx.poll` predicate the event ride-alongs with
287
+ * the poll's iteration events: failed iterations get truncated, the winning
288
+ * one survives as a child of the `wait` event.
289
+ */
290
+ export interface EmailEvent extends BaseEvent {
291
+ kind: "email";
292
+ /** Service key of the mail server (`ctx.svc.<service>`). */
293
+ service: string;
294
+ /** Helper called, e.g. `"lastEmail"`. */
295
+ op: string;
296
+ /** Human-readable match criteria, e.g. `to alice@example.com`. */
297
+ query?: string;
298
+ /** Number of matching messages (listing ops / mailbox size on error). */
299
+ count?: number;
300
+ /** The captured message (single-message ops). */
301
+ message?: EmailEventMessage;
302
+ /** Message summaries (listing ops). */
303
+ messages?: EmailEventSummary[];
304
+ durationMs: number;
305
+ /** Set if the op threw (e.g. the mail server's query API failed). */
306
+ error?: string;
307
+ }
308
+ /**
309
+ * A runtime mutation of the environment — `ctx.startService` /
310
+ * `ctx.stopService` / `ctx.dnsName`, whether called from a test or from a
311
+ * fake handler reacting to the app under test. Distinct from the `http`
312
+ * event the app generates when it calls the fake: this is the
313
+ * infrastructure the fake (or test) created in response. No-op outside a
314
+ * running test (bootstrap / project-setup / eval), same as every record*.
315
+ */
316
+ export interface EnvEvent extends BaseEvent {
317
+ kind: "env";
318
+ /** Which environment primitive ran. */
319
+ op: "startService" | "stopService" | "dnsName";
320
+ /** Service name (startService / stopService). */
321
+ service?: string;
322
+ /** Image reference started (startService). */
323
+ image?: string;
324
+ /** Resolved IP — the new container's (startService) or the target's (dnsName). */
325
+ ip?: string;
326
+ /** Hostname registered (dnsName). */
327
+ hostname?: string;
328
+ durationMs: number;
329
+ /** Set if the op threw. */
330
+ error?: string;
331
+ }
332
+ export type BrowserAction = string;
333
+ export interface BrowserEvent extends BaseEvent {
334
+ kind: "browser";
335
+ action: BrowserAction;
336
+ /** Target URL (navigate). */
337
+ url?: string;
338
+ /** CSS selector (click, scrollTo). */
339
+ selector?: string;
340
+ /** Human-readable label for `evaluate` ops. */
341
+ description?: string;
342
+ /** Evaluated script, truncated. */
343
+ script?: string;
344
+ scriptTruncated?: boolean;
345
+ /** Typed text, truncated. */
346
+ text?: string;
347
+ textTruncated?: boolean;
348
+ /** Key name (press). */
349
+ key?: string;
350
+ /** Scroll/click coordinates. */
351
+ dx?: number;
352
+ dy?: number;
353
+ x?: number;
354
+ y?: number;
355
+ /** Screenshot image format. */
356
+ format?: string;
357
+ /** For `waitFor`: how many times the predicate was polled. */
358
+ attempts?: number;
359
+ durationMs: number;
360
+ error?: string;
361
+ /**
362
+ * Session this op belonged to. Set whenever the Browser was opened
363
+ * with a `BrowserSessionRecorder` attached (the daemon always does).
364
+ */
365
+ sessionId?: string;
366
+ /**
367
+ * Wall-clock `Date.now()` captured at the moment this op *finished*.
368
+ * Lives in the same time base as rrweb's `event.timestamp` fields,
369
+ * so the dashboard can seek the player by computing
370
+ * `event.timestamp - events[0].timestamp`. Using the post-op time
371
+ * (rather than op start) means clicking a "type 'foo'" step lands
372
+ * on the frame where the field already shows the text.
373
+ */
374
+ sessionTimestamp?: number;
375
+ }
376
+ /**
377
+ * Inline event for a single `ctx.terminal(...)` call. The heavy
378
+ * asciicast frames live separately on a `TerminalSessionRecord`
379
+ * (mirroring how `BrowserEvent` points at a `BrowserSessionRecord`).
380
+ * The UI shows this row in the step list and seeks the player to
381
+ * the session's start when clicked.
382
+ */
383
+ export interface TerminalEvent extends BaseEvent {
384
+ kind: "terminal";
385
+ service: string;
386
+ command: string;
387
+ exitCode: number;
388
+ durationMs: number;
389
+ /** Links this event to its TerminalSessionRecord. */
390
+ sessionId: string;
391
+ /** PTY size used for the run. */
392
+ cols: number;
393
+ rows: number;
394
+ /** First N bytes of decoded output, for tooltip/inline preview. */
395
+ outputPreview: string;
396
+ outputTruncated: boolean;
397
+ /** Set if spawning the PTY itself failed. */
398
+ error?: string;
399
+ }
400
+ /** Action taken on an open interactive terminal session. */
401
+ export type TerminalStepAction = "send" | "sendLine" | "press" | "waitFor" | "exit" | "close";
402
+ /**
403
+ * One operation on an open interactive terminal — analogous to
404
+ * `BrowserEvent`. The session's heavy asciicast frames live on the
405
+ * `TerminalSessionRecord`; this event just carries metadata so the
406
+ * step shows up in the timeline and the UI can seek the player.
407
+ */
408
+ export interface TerminalStepEvent extends BaseEvent {
409
+ kind: "terminal-step";
410
+ /** Links this event back to its TerminalSessionRecord. */
411
+ sessionId: string;
412
+ /** Service the terminal is attached to (mirrors TerminalEvent.service). */
413
+ service: string;
414
+ /** Which Terminal method produced this event. */
415
+ action: TerminalStepAction;
416
+ /** Bytes sent (send/sendLine), truncated. */
417
+ text?: string;
418
+ textTruncated?: boolean;
419
+ /** Key name passed to `press`. */
420
+ key?: string;
421
+ /** Human label passed to `waitFor`. */
422
+ description?: string;
423
+ /** How many polls `waitFor` made. */
424
+ attempts?: number;
425
+ /** Whether `waitFor` matched (false means it timed out). */
426
+ matched?: boolean;
427
+ /** Exit code observed on `close`. */
428
+ exitCode?: number;
429
+ /** Rendered screen at the moment of the op (post-action), truncated. */
430
+ screenPreview: string;
431
+ screenTruncated: boolean;
432
+ /**
433
+ * Player-relative offset, in seconds, captured against the *same*
434
+ * clock the asciicast frames use (the terminal factory's spawn
435
+ * time). The UI seeks the asciinema-player to this value when the
436
+ * step is clicked. Persisting it directly avoids ever subtracting
437
+ * `step.tOffsetMs - session.openedAtMs` on the front-end, which is
438
+ * fragile because the two timestamps live in slightly different
439
+ * Date.now() frames (recorder vs. spawn).
440
+ */
441
+ castTimeSec: number;
442
+ durationMs: number;
443
+ error?: string;
444
+ }
445
+ /** An ordering slot claimed at op *start* and handed back to the matching
446
+ * `record*` call at op finish. Lets a triggering op (an `exec`/`fetch` that
447
+ * reaches the app, which calls a fake, which calls `ctx.startService`) keep a
448
+ * lower seq than the nested events it sets off — even though those nested
449
+ * events finish, and record, first. */
450
+ export interface EventReservation {
451
+ seq: number;
452
+ tOffsetMs: number;
453
+ }
454
+ export declare function pauseRecording(): void;
455
+ export declare function resumeRecording(): void;
456
+ export declare function startRecording(): void;
457
+ export declare function stopRecording(): TestEvent[];
458
+ export declare function isRecording(): boolean;
459
+ /** Reserve an ordering slot at the start of an op so nested events it triggers
460
+ * (which finish — and record — first) still sort after it. Hand the returned
461
+ * reservation to the matching `record*` call at op finish. Returns `undefined`
462
+ * when nothing is recording, in which case `record*` falls back to allocating
463
+ * the seq at record time. */
464
+ export declare function reserveEvent(): EventReservation | undefined;
465
+ export declare function recordExec(ev: Omit<ExecEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
466
+ export declare function recordAssertion(ev: Omit<AssertionEvent, "seq" | "tOffsetMs" | "kind">): number | undefined;
467
+ export declare function recordHttp(ev: Omit<HttpEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
468
+ export declare function recordBrowser(ev: Omit<BrowserEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
469
+ export declare function recordDb(ev: Omit<DbEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
470
+ export declare function recordRedis(ev: Omit<RedisEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
471
+ export declare function recordS3(ev: Omit<S3Event, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
472
+ export declare function recordTerminal(ev: Omit<TerminalEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
473
+ export declare function recordTerminalStep(ev: Omit<TerminalStepEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
474
+ export declare function recordFake(ev: Omit<FakeEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
475
+ export declare function recordEnv(ev: Omit<EnvEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
476
+ export declare function recordEmail(ev: Omit<EmailEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
477
+ /**
478
+ * Recorded once per `ctx.poll(...)` call. Stands in for the suppressed
479
+ * intermediate iterations and gives downstream tagged values
480
+ * (`wrap(polledValue, waitSeq)`) a single, stable event to point at —
481
+ * assertions on those values then link to the wait, not to one of N
482
+ * dropped polls.
483
+ */
484
+ export interface WaitEvent extends BaseEvent {
485
+ kind: "wait";
486
+ description: string;
487
+ attempts: number;
488
+ durationMs: number;
489
+ passed: boolean;
490
+ /** Set when the predicate threw or the wait timed out. */
491
+ error?: string;
492
+ }
493
+ export declare function recordWait(ev: Omit<WaitEvent, "seq" | "tOffsetMs" | "kind">, reservation?: EventReservation): number | undefined;
494
+ /** Number of events the active recorder has accumulated. Returns 0
495
+ * when no recorder is active. */
496
+ export declare function recorderEventCount(): number;
497
+ /** Drop events with index >= `toLen` from the active recorder. */
498
+ export declare function recorderTruncate(toLen: number): void;
499
+ /** Stamp `parentSeq` onto every event from `startIdx` onward, so the
500
+ * UI groups them under the parent in the timeline. */
501
+ export declare function recorderMarkChildren(startIdx: number, parentSeq: number): void;
502
+ /** Shallow-merge `patch` into the active recorder's event with this
503
+ * `seq` (enrich/reclassify after the fact). No-op when nothing is
504
+ * recording or no event carries that seq. */
505
+ export declare function recorderAnnotate(seq: number, patch: Record<string, unknown>): void;
506
+ /** Retract the active recorder's event with this `seq` (an instrumentation
507
+ * site recorded it, then decided it's noise). No-op when nothing is
508
+ * recording or no event carries that seq. */
509
+ export declare function recorderRemove(seq: number): void;
510
+ /** Best-effort JSON-safe deep clone; falls back to `String(v)`. */
511
+ export declare function safeSerialize(v: unknown): unknown;
512
+ export declare function truncateUtf8(s: string): {
513
+ value: string;
514
+ truncated: boolean;
515
+ };
516
+ export {};