@reticlehq/engine 3.9.0 → 3.10.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 (43) hide show
  1. package/dist/disagreement/body-failures.js +16 -2
  2. package/dist/disagreement/contradiction-evidence.d.ts +119 -0
  3. package/dist/disagreement/contradiction-evidence.js +360 -48
  4. package/dist/disagreement/contradiction-types.d.ts +25 -0
  5. package/dist/disagreement/contradictions.d.ts +17 -1
  6. package/dist/disagreement/contradictions.js +146 -78
  7. package/dist/disagreement/echo-mismatch.js +205 -32
  8. package/dist/disagreement/stale-response.d.ts +10 -1
  9. package/dist/disagreement/stale-response.js +122 -47
  10. package/dist/evidence/already-true.d.ts +1 -1
  11. package/dist/evidence/already-true.js +13 -7
  12. package/dist/evidence/baseline.d.ts +1 -0
  13. package/dist/evidence/baseline.js +27 -16
  14. package/dist/evidence/blind-spots.d.ts +20 -3
  15. package/dist/evidence/blind-spots.js +127 -21
  16. package/dist/evidence/step-effect.d.ts +5 -0
  17. package/dist/evidence/step-effect.js +5 -2
  18. package/dist/evidence/verified.d.ts +23 -0
  19. package/dist/evidence/verified.js +53 -2
  20. package/dist/question/declared.d.ts +27 -0
  21. package/dist/question/declared.js +64 -13
  22. package/dist/question/predicate/net-blind-spots.d.ts +37 -1
  23. package/dist/question/predicate/net-blind-spots.js +72 -1
  24. package/dist/question/predicate/predicate-animation.d.ts +52 -0
  25. package/dist/question/predicate/predicate-animation.js +258 -0
  26. package/dist/question/predicate/predicate-element.d.ts +5 -2
  27. package/dist/question/predicate/predicate-element.js +103 -33
  28. package/dist/question/predicate/predicate-eval-kit.d.ts +2 -0
  29. package/dist/question/predicate/predicate-eval-kit.js +19 -0
  30. package/dist/question/predicate/predicate-eval.d.ts +1 -4
  31. package/dist/question/predicate/predicate-eval.js +38 -46
  32. package/dist/question/predicate/predicate-route.js +81 -27
  33. package/dist/question/predicate/predicate-schema.js +11 -2
  34. package/dist/question/predicate/predicate.js +79 -40
  35. package/dist/question/predicate/truncated-body-advice.d.ts +5 -0
  36. package/dist/question/predicate/truncated-body-advice.js +25 -0
  37. package/dist/state-bookkeeping.d.ts +24 -0
  38. package/dist/state-bookkeeping.js +31 -0
  39. package/dist/window/event-filters.d.ts +64 -0
  40. package/dist/window/event-filters.js +149 -20
  41. package/dist/window/network-detail-merge.d.ts +6 -0
  42. package/dist/window/network-detail-merge.js +43 -2
  43. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { EventType, URL_RAW, urlForMatch } from '@reticlehq/core';
1
+ import { DepartedNetField, EventType, NetInitiator, URL_RAW, urlForMatch, } from '@reticlehq/core';
2
2
  import { asNumber, asString } from '@reticlehq/core';
3
3
  import { mergeNetworkDetail } from './network-detail-merge.js';
4
4
  /**
@@ -37,8 +37,9 @@ export function eventMatchesFilters(e, filters) {
37
37
  // then `.includes` would throw — a crash on an odd-but-harmless agent input. Only an OWN key is a
38
38
  // real bucket; anything else falls through to the raw-type comparison.
39
39
  const bucket = Object.hasOwn(OBSERVE_FILTER_BUCKETS, f) ? OBSERVE_FILTER_BUCKETS[f] : undefined;
40
- if (bucket !== undefined ? bucket.includes(e.type) : e.type === f)
40
+ if (bucket !== undefined ? bucket.includes(e.type) : e.type === f) {
41
41
  return true;
42
+ }
42
43
  }
43
44
  return false;
44
45
  }
@@ -58,10 +59,12 @@ export function matchNet(e, method, urlContains, status, ok) {
58
59
  if (urlContains !== undefined && !urlForMatch(d).includes(urlContains)) {
59
60
  return false;
60
61
  }
61
- if (status !== undefined && asNumber(d['status']) !== status)
62
+ if (status !== undefined && asNumber(d['status']) !== status) {
62
63
  return false;
63
- if (ok !== undefined && d['ok'] !== ok)
64
+ }
65
+ if (ok !== undefined && d['ok'] !== ok) {
64
66
  return false;
67
+ }
65
68
  return true;
66
69
  }
67
70
  /**
@@ -78,8 +81,9 @@ export function reconcileNet(events) {
78
81
  const doneIds = new Set(completed.map((e) => asString(e.data['id'])).filter((id) => id !== undefined));
79
82
  const unresolved = events
80
83
  .filter((e) => {
81
- if (e.type !== EventType.NET_PENDING)
84
+ if (e.type !== EventType.NET_PENDING) {
82
85
  return false;
86
+ }
83
87
  const id = asString(e.data['id']);
84
88
  return id === undefined || !doneIds.has(id);
85
89
  })
@@ -94,12 +98,14 @@ export function reconcileNet(events) {
94
98
  * or a network listing.
95
99
  */
96
100
  export function withoutUrlRaw(event) {
97
- if (typeof event !== 'object' || null === event)
101
+ if (typeof event !== 'object' || null === event) {
98
102
  return event;
103
+ }
99
104
  const rec = event;
100
105
  const data = rec['data'];
101
- if (typeof data !== 'object' || null === data || !(URL_RAW in data))
106
+ if (typeof data !== 'object' || null === data || !(URL_RAW in data)) {
102
107
  return event;
108
+ }
103
109
  const { [URL_RAW]: _raw, ...rest } = data;
104
110
  return { ...rec, data: rest };
105
111
  }
@@ -115,28 +121,42 @@ export function projectNetCall(e, includeBodies = true) {
115
121
  method: asString(e.data['method']) ?? '',
116
122
  url: asString(e.data['url']) ?? '',
117
123
  };
118
- if ('number' === typeof status || 'string' === typeof status)
124
+ if ('number' === typeof status || 'string' === typeof status) {
119
125
  view.status = status;
120
- if (statusText !== undefined)
126
+ }
127
+ if (statusText !== undefined) {
121
128
  view.statusText = statusText;
122
- if (contentType !== undefined)
129
+ }
130
+ if (contentType !== undefined) {
123
131
  view.contentType = contentType;
124
- if (responseSize !== undefined)
132
+ }
133
+ if (responseSize !== undefined) {
125
134
  view.responseSize = responseSize;
135
+ }
126
136
  // Bodies dominate the payload of the most-called read tool, and are only occasionally the part
127
137
  // anyone wanted — `bodies: false` on reticle_network drops them for a body-free listing (#401).
128
- if (includeBodies && requestBody !== undefined)
138
+ if (includeBodies && requestBody !== undefined) {
129
139
  view.requestBody = requestBody;
130
- if (includeBodies && responseBody !== undefined)
140
+ }
141
+ if (includeBodies && responseBody !== undefined) {
131
142
  view.responseBody = responseBody;
143
+ }
132
144
  if (includeBodies &&
133
145
  (true === e.data['requestBodyTruncated'] || true === e.data['responseBodyTruncated'])) {
134
146
  view.bodyTruncated = true;
135
147
  }
136
- if (ms !== undefined)
148
+ if (ms !== undefined) {
137
149
  view.ms = ms;
138
- if (true === e.data['oneWay'])
150
+ }
151
+ if (true === e.data['oneWay']) {
139
152
  view.oneWay = true;
153
+ }
154
+ if (true === e.data[DepartedNetField.FROM_DEPARTED_DOCUMENT]) {
155
+ view.fromDepartedDocument = true;
156
+ }
157
+ if (true === e.data[DepartedNetField.PAGE_UNLOADED]) {
158
+ view.pageUnloaded = true;
159
+ }
140
160
  const headers = e.data['headers'];
141
161
  if (headers !== null && 'object' === typeof headers) {
142
162
  view.headers = headers;
@@ -159,8 +179,9 @@ export function projectConsoleLog(e) {
159
179
  const level = e.type === EventType.ERROR_UNCAUGHT ? 'error' : e.type.replace('console.', '');
160
180
  const view = { level, text: asString(e.data['message']) ?? '' };
161
181
  const stack = asString(e.data['stack']);
162
- if (stack !== undefined && stack.length > 0)
182
+ if (stack !== undefined && stack.length > 0) {
163
183
  view.stack = topFrames(stack);
184
+ }
164
185
  // An uncaught error reports its origin as discrete fields rather than in a stack; render them in
165
186
  // the same file:line form the element descriptors use so the agent reads one shape everywhere.
166
187
  const source = asString(e.data['source']);
@@ -181,10 +202,12 @@ export function isConsoleEvent(e) {
181
202
  }
182
203
  /** Match a console/error event against an optional level filter (reticle_console). */
183
204
  export function matchConsole(e, level) {
184
- if (!isConsoleEvent(e))
205
+ if (!isConsoleEvent(e)) {
185
206
  return false;
186
- if (level === undefined)
207
+ }
208
+ if (level === undefined) {
187
209
  return true;
210
+ }
188
211
  return (e.type === `console.${level}` || ('error' === level && e.type === EventType.ERROR_UNCAUGHT));
189
212
  }
190
213
  /** How many present calls/levels a zero-match hint samples before truncating. */
@@ -203,13 +226,119 @@ export function netEmptyHint(allNet) {
203
226
  export function consoleEmptyHint(allConsole) {
204
227
  const byLevel = { log: 0, warn: 0, error: 0 };
205
228
  for (const e of allConsole) {
206
- if (e.type === EventType.CONSOLE_LOG)
229
+ if (e.type === EventType.CONSOLE_LOG) {
207
230
  byLevel.log += 1;
208
- else if (e.type === EventType.CONSOLE_WARN)
231
+ }
232
+ else if (e.type === EventType.CONSOLE_WARN) {
209
233
  byLevel.warn += 1;
234
+ }
210
235
  else if (e.type === EventType.CONSOLE_ERROR || e.type === EventType.ERROR_UNCAUGHT) {
211
236
  byLevel.error += 1;
212
237
  }
213
238
  }
214
239
  return { totalInWindow: allConsole.length, byLevel };
215
240
  }
241
+ /**
242
+ * Did the browser leave for a URL this filter names, inside the window (#1936)?
243
+ *
244
+ * A click on `<a download>`, or on a link that the server answers as an attachment, is recorded as a
245
+ * navigation `NET_PENDING`. The response goes to the download manager. The page never sees its
246
+ * status, and no `NET_REQUEST` can close the record. A miss over this window is unobservable, not a
247
+ * failure: the file can be on disk while the net channel shows only the pending record.
248
+ *
249
+ * An ordinary link records the same navigation `NET_PENDING`, and there the page DID leave, so a
250
+ * miss stays a real `no`. A record counts only when it is a download (`download: true`), or when no
251
+ * later event comes from a different document. A later event with another `documentId` proves that
252
+ * a new document loaded, so the old page's request did not go to a download.
253
+ */
254
+ export function departedInWindow(events, since, method, urlContains) {
255
+ return events.some((e) => e.type === EventType.NET_PENDING &&
256
+ e.t >= since &&
257
+ e.data['initiator'] === NetInitiator.NAVIGATION &&
258
+ (method === undefined ||
259
+ asString(e.data['method'])?.toUpperCase() === method.toUpperCase()) &&
260
+ (urlContains === undefined || urlForMatch(e.data).includes(urlContains)) &&
261
+ (true === e.data['download'] || !newDocumentAfter(events, e)));
262
+ }
263
+ /**
264
+ * Did a request to this URL leave through a `fetch` that Reticle did not patch, in the window?
265
+ *
266
+ * The SDK reports such a call as `net.unpatched`: the browser recorded it in resource timing, and no
267
+ * patched transport saw it. It has no method, so only the URL filter can match it.
268
+ */
269
+ export function unpatchedInWindow(events, since, urlContains) {
270
+ return events.some((e) => e.type === EventType.NET_UNPATCHED &&
271
+ e.t >= since &&
272
+ (urlContains === undefined || urlForMatch(e.data).includes(urlContains)));
273
+ }
274
+ /**
275
+ * Did the page send a request this filter names, inside the window, and unload before its answer
276
+ * arrived (#1944)? The daemon marks such a carried `NET_PENDING` `pageUnloaded`. Its outcome is
277
+ * unknown, so a miss over it is unobservable, not a failure.
278
+ */
279
+ export function unloadedInWindow(events, since, method, urlContains) {
280
+ return events.some((e) => e.type === EventType.NET_PENDING &&
281
+ e.t >= since &&
282
+ true === e.data[DepartedNetField.PAGE_UNLOADED] &&
283
+ (method === undefined ||
284
+ asString(e.data['method'])?.toUpperCase() === method.toUpperCase()) &&
285
+ (urlContains === undefined || urlForMatch(e.data).includes(urlContains)));
286
+ }
287
+ /** Is there an event after `record` from a document other than the one that emitted it? */
288
+ function newDocumentAfter(events, record) {
289
+ const from = record.documentId;
290
+ if (from === undefined) {
291
+ return false;
292
+ }
293
+ return events.some((e) => e.t >= record.t && e.documentId !== undefined && e.documentId !== from);
294
+ }
295
+ /**
296
+ * Initiator types a media element load carries on its resource timing record.
297
+ *
298
+ * A `<video>`, `<audio>` or `<track>` load goes through neither `fetch` nor `XMLHttpRequest`, so
299
+ * the record the resource timing observer emits is the only one it ever leaves.
300
+ */
301
+ const MEDIA_INITIATORS = new Set(['video', 'audio', 'track']);
302
+ /**
303
+ * The media entry that matches this filter and was recorded BEFORE the window opened, if any.
304
+ *
305
+ * The browser observer reports only the first resource timing entry for a URL: its seen-set
306
+ * (`reportedNetUrls` in adapters/realm/browser/src/observers/network.ts) drops every later entry
307
+ * for a URL it has already reported. For a media element load that first entry is also the only
308
+ * kind of record there is, so once it lands before `since`, a repeat load inside the window
309
+ * leaves no record at all and the window reads empty. The empty window is then not evidence the
310
+ * file did not load in it — a missing entry is not evidence there (#2069).
311
+ *
312
+ * A `fetch` or XHR record before the window impeaches nothing and is not returned here: the
313
+ * patched transports report every call, so a repeat would have been seen. Only the clauses that
314
+ * identify the request are read — `urlContains` and `method`. A status clause is not read: the
315
+ * entry's status is the unreadable thing this blind spot is about. Resource timing carries no
316
+ * method; the observer stamps `GET` for exactly that reason, so a record with no method counts
317
+ * as the `GET` a media element only ever issues.
318
+ */
319
+ export function mediaEntryBeforeWindow(events, since, method, urlContains) {
320
+ return events.find((e) => e.type === EventType.NET_REQUEST &&
321
+ e.t < since &&
322
+ MEDIA_INITIATORS.has(asString(e.data['initiator']) ?? '') &&
323
+ (method === undefined ||
324
+ (asString(e.data['method']) ?? 'GET').toUpperCase() === method.toUpperCase()) &&
325
+ (urlContains === undefined || urlForMatch(e.data).includes(urlContains)));
326
+ }
327
+ /**
328
+ * The first dialog in the window that Reticle answered on the app's behalf, or undefined.
329
+ *
330
+ * Only a dialog that carries `answered` counts. An `alert` has no answer, so it cannot change which
331
+ * path the app took. The SDK and the leased-tab pool both record the answer in this one event.
332
+ */
333
+ export function declinedDialogIn(events) {
334
+ const dialog = events.find((e) => e.type === EventType.DIALOG_OPENED && Object.hasOwn(e.data, 'answered'));
335
+ if (dialog === undefined) {
336
+ return undefined;
337
+ }
338
+ const message = asString(dialog.data['message']);
339
+ return {
340
+ // The schema requires `kind`, so this is never empty on a valid event.
341
+ kind: String(dialog.data['kind']),
342
+ ...(message === undefined ? {} : { message }),
343
+ };
344
+ }
@@ -1,4 +1,10 @@
1
1
  import { type ReticleEvent } from '@reticlehq/core';
2
+ /**
3
+ * Record every server-sent download the driven browser saw, and that the page never recorded, as a
4
+ * request — and change nothing else. A `net` check with no body clause runs on events that the full
5
+ * merge below never touches, so without this a plain status check on a working export missed.
6
+ */
7
+ export declare function withDownloadRequests(events: readonly ReticleEvent[]): ReticleEvent[];
2
8
  /**
3
9
  * Fold wire details by method+url, and SDK response bodies by request id plus method+url.
4
10
  * SDK body details finish background capture without adding another request to counts or settle.
@@ -1,4 +1,4 @@
1
- import { EventType, urlForMatch } from '@reticlehq/core';
1
+ import { EventType, NetInitiator, urlForMatch } from '@reticlehq/core';
2
2
  /**
3
3
  * Folding the browser's own view of a network request together with the daemon's.
4
4
  *
@@ -27,6 +27,44 @@ function keyOf(data) {
27
27
  const m = 'string' === typeof method ? method.toUpperCase() : '';
28
28
  return `${m} ${urlForMatch(data)}`;
29
29
  }
30
+ /** True when a response is a file the server sent to be saved, not shown. */
31
+ function isAttachment(headers) {
32
+ if ('object' !== typeof headers || null === headers) {
33
+ return false;
34
+ }
35
+ const disposition = headers['content-disposition'];
36
+ return 'string' === typeof disposition && /^\s*attachment\b/i.test(disposition);
37
+ }
38
+ /**
39
+ * A wire detail for a server-sent download, as the request it was; undefined for any other detail.
40
+ * Its duration was not measured (the page never timed it), so it carries 0.
41
+ */
42
+ function downloadRequest(e) {
43
+ if (!isAttachment(e.data['headers'])) {
44
+ return undefined;
45
+ }
46
+ const status = 'number' === typeof e.data['status'] ? e.data['status'] : 0;
47
+ return {
48
+ ...e,
49
+ type: EventType.NET_REQUEST,
50
+ data: {
51
+ ...e.data,
52
+ id: `download:${String(e.t)}:${urlForMatch(e.data)}`,
53
+ ok: 200 <= status && status < 400,
54
+ durationMs: 0,
55
+ initiator: NetInitiator.DOWNLOAD,
56
+ },
57
+ };
58
+ }
59
+ /**
60
+ * Record every server-sent download the driven browser saw, and that the page never recorded, as a
61
+ * request — and change nothing else. A `net` check with no body clause runs on events that the full
62
+ * merge below never touches, so without this a plain status check on a working export missed.
63
+ */
64
+ export function withDownloadRequests(events) {
65
+ const recorded = new Set(events.filter((e) => e.type === EventType.NET_REQUEST).map((e) => keyOf(e.data)));
66
+ return events.map((e) => e.type === EventType.NET_DETAIL && !recorded.has(keyOf(e.data)) ? (downloadRequest(e) ?? e) : e);
67
+ }
30
68
  /**
31
69
  * Fold wire details by method+url, and SDK response bodies by request id plus method+url.
32
70
  * SDK body details finish background capture without adding another request to counts or settle.
@@ -62,7 +100,10 @@ export function mergeNetworkDetail(events) {
62
100
  match = requestByKey.get(keyOf(e.data));
63
101
  }
64
102
  if (match === undefined || keyOf(match.data) !== keyOf(e.data)) {
65
- out.push(e); // unmatched detail survives on its own
103
+ // A server-sent download has no in-page request to merge onto: it left the page as a
104
+ // navigation. The driven browser saw it, so it is recorded as the request it was. Any other
105
+ // unmatched detail survives on its own, as before.
106
+ out.push(sdkBody ? e : (downloadRequest(e) ?? e));
66
107
  continue;
67
108
  }
68
109
  const base = enriched.get(match) ?? match;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/engine",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "description": "The rules that decide a verdict: read what happened in a running app and say whether the declared consequence held. No browser, no daemon, no command line - an implementation of the OpenVerification specification you can use on its own.",
5
5
  "keywords": [
6
6
  "verification",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "zod": "^4.6.6",
60
- "@reticlehq/core": "3.9.0",
60
+ "@reticlehq/core": "3.10.0",
61
61
  "open-verification": "1.1.0"
62
62
  },
63
63
  "scripts": {