@reticlehq/engine 3.5.0 → 3.7.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 (57) hide show
  1. package/dist/disagreement/body-failures.js +2 -1
  2. package/dist/disagreement/contradiction-evidence.d.ts +73 -1
  3. package/dist/disagreement/contradiction-evidence.js +154 -6
  4. package/dist/disagreement/contradiction-types.d.ts +8 -1
  5. package/dist/disagreement/contradictions.d.ts +17 -1
  6. package/dist/disagreement/contradictions.js +111 -38
  7. package/dist/disagreement/echo-mismatch.js +42 -3
  8. package/dist/disagreement/reconcile.js +15 -0
  9. package/dist/disagreement/stale-response.js +37 -2
  10. package/dist/evidence/accepted-write.d.ts +26 -2
  11. package/dist/evidence/accepted-write.js +35 -18
  12. package/dist/evidence/already-true.d.ts +16 -0
  13. package/dist/evidence/already-true.js +48 -0
  14. package/dist/evidence/baseline.js +2 -6
  15. package/dist/evidence/blind-spots.d.ts +14 -3
  16. package/dist/evidence/blind-spots.js +48 -10
  17. package/dist/evidence/body-capture-remedy.d.ts +10 -0
  18. package/dist/evidence/body-capture-remedy.js +15 -2
  19. package/dist/evidence/instrumentation-gaps.js +3 -1
  20. package/dist/evidence/state-bookkeeping.d.ts +2 -0
  21. package/dist/evidence/state-bookkeeping.js +2 -0
  22. package/dist/evidence/superseded-checks.d.ts +29 -0
  23. package/dist/evidence/superseded-checks.js +30 -0
  24. package/dist/evidence/unsettled.js +4 -2
  25. package/dist/evidence/verified.d.ts +8 -1
  26. package/dist/evidence/verified.js +42 -4
  27. package/dist/question/declared.d.ts +24 -4
  28. package/dist/question/declared.js +26 -5
  29. package/dist/question/predicate/name-near-miss.d.ts +24 -0
  30. package/dist/question/predicate/name-near-miss.js +39 -0
  31. package/dist/question/predicate/net-blind-spots.d.ts +49 -0
  32. package/dist/question/predicate/net-blind-spots.js +153 -0
  33. package/dist/question/predicate/predicate-compare.js +13 -4
  34. package/dist/question/predicate/predicate-element.d.ts +15 -1
  35. package/dist/question/predicate/predicate-element.js +108 -7
  36. package/dist/question/predicate/predicate-eval-kit.d.ts +25 -0
  37. package/dist/question/predicate/predicate-eval-kit.js +31 -0
  38. package/dist/question/predicate/predicate-eval.d.ts +17 -2
  39. package/dist/question/predicate/predicate-eval.js +117 -180
  40. package/dist/question/predicate/predicate-parse.js +153 -13
  41. package/dist/question/predicate/predicate-request-body.d.ts +6 -1
  42. package/dist/question/predicate/predicate-request-body.js +7 -2
  43. package/dist/question/predicate/predicate-route.d.ts +2 -0
  44. package/dist/question/predicate/predicate-route.js +30 -0
  45. package/dist/question/predicate/predicate-schema.d.ts +11 -0
  46. package/dist/question/predicate/predicate-schema.js +110 -24
  47. package/dist/question/predicate/predicate-session.d.ts +10 -0
  48. package/dist/question/predicate/predicate-state.js +7 -0
  49. package/dist/question/predicate/predicate-to-links.js +1 -0
  50. package/dist/question/predicate/predicate.js +76 -25
  51. package/dist/question/predicate/split-text-miss.d.ts +6 -0
  52. package/dist/question/predicate/split-text-miss.js +10 -0
  53. package/dist/question/reaction.d.ts +1 -1
  54. package/dist/question/reaction.js +1 -1
  55. package/dist/state-bookkeeping.d.ts +25 -0
  56. package/dist/state-bookkeeping.js +70 -0
  57. package/package.json +2 -2
@@ -28,8 +28,10 @@ import { ContradictionKind, EventType, MUTATING_METHODS } from '@reticlehq/core'
28
28
  * that share a field name were never expected to match. Both used to fire on every healthy POST;
29
29
  * - only keys the request actually SENT are considered;
30
30
  * - only scalars, since deep structural diffing is where the false positives live;
31
- * - values are compared NORMALISED (trimmed, case-folded, numbers as numbers), so `FR` vs `fr` and
32
- * `1` vs `1.0` stay silent while `fr` vs `en` speaks;
31
+ * - values are compared NORMALISED (trimmed, case-folded, numbers as numbers, ISO-8601 instants
32
+ * as instants), so `FR` vs `fr`, `1` vs `1.0` and `.000Z` vs `Z` stay silent while `fr` vs `en`
33
+ * speaks;
34
+ * - server-stamped audit columns (`updated_at` and its spellings) are not compared;
33
35
  * - if the key appears anywhere in the response carrying the requested value, it is treated as
34
36
  * applied — an envelope that echoes both the old and the new value is not a dropped write;
35
37
  * - the response must look like a restatement of the request before any key is compared. Reported
@@ -64,10 +66,29 @@ function parse(raw) {
64
66
  return undefined;
65
67
  }
66
68
  }
69
+ /**
70
+ * An ISO-8601 date-time that names one instant: it carries a time AND a zone (`Z` or `±hh:mm`).
71
+ * A bare date or a zone-less local time is not an instant and is compared as text.
72
+ */
73
+ const ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/i;
74
+ /**
75
+ * Two spellings of one instant — `…:00.000Z`, `…:00Z`, `…+05:30` — are the same value. Servers
76
+ * re-serialise timestamps through their own date type, so precision and zone spelling are
77
+ * formatting, not a dropped write.
78
+ */
79
+ function normalizeString(value) {
80
+ const trimmed = value.trim();
81
+ if (ISO_INSTANT.test(trimmed)) {
82
+ const instant = Date.parse(trimmed);
83
+ if (Number.isFinite(instant))
84
+ return new Date(instant).toISOString().toLowerCase();
85
+ }
86
+ return trimmed.toLowerCase();
87
+ }
67
88
  /** Comparable form of a scalar. Non-scalars return undefined and are never compared. */
68
89
  function normalize(value) {
69
90
  if ('string' === typeof value)
70
- return value.trim().toLowerCase();
91
+ return normalizeString(value);
71
92
  if ('number' === typeof value)
72
93
  return Number.isFinite(value) ? String(value) : undefined;
73
94
  if ('boolean' === typeof value)
@@ -105,6 +126,22 @@ function isVersionKey(key) {
105
126
  'rev' === lower ||
106
127
  'revision' === lower);
107
128
  }
129
+ /**
130
+ * Audit columns the server stamps with its own clock on every write. A client that sends one back
131
+ * (a PATCH of the whole record it read) is not asking for that value to be kept, and the changed
132
+ * value in the response is the proof the write applied — the same reasoning as a version token.
133
+ */
134
+ const AUDIT_TIMESTAMP_KEYS = new Set([
135
+ 'updated_at',
136
+ 'updatedat',
137
+ 'modified_at',
138
+ 'modifiedat',
139
+ 'last_modified',
140
+ 'lastmodified',
141
+ ]);
142
+ function isAuditTimestampKey(key) {
143
+ return AUDIT_TIMESTAMP_KEYS.has(key.toLowerCase());
144
+ }
108
145
  /**
109
146
  * Every scalar value the response carries for each key, at any depth.
110
147
  *
@@ -289,6 +326,8 @@ export function findEchoMismatches(events, actionSince) {
289
326
  continue;
290
327
  if (isVersionKey(key))
291
328
  continue;
329
+ if (isAuditTimestampKey(key))
330
+ continue;
292
331
  const values = echoed.get(key);
293
332
  // Not echoed at all = no evidence either way. Only a key the server chose to report back can
294
333
  // contradict the request, and silence is not a contradiction.
@@ -129,6 +129,11 @@ function shows(text, value) {
129
129
  const haystack = text.toLowerCase();
130
130
  return renderedForms(value).some((form) => haystack.includes(form.toLowerCase()));
131
131
  }
132
+ /** Whether the page shows this record at all: its id appears in the page's text. */
133
+ function onPage(entity, pageText) {
134
+ const id = entity['id'];
135
+ return ('string' === typeof id || 'number' === typeof id) && pageText.includes(String(id));
136
+ }
132
137
  /**
133
138
  * Compare entities against the page's rendered text.
134
139
  *
@@ -142,8 +147,14 @@ export function reconcile(bodies, pageText) {
142
147
  // Every value each state field took across the response set — used to tell "this value is simply
143
148
  // not rendered anywhere" (uninteresting) from "a DIFFERENT value of this same field is rendered"
144
149
  // (a mapping bug). Without that distinction the check would flag any field a UI chooses not to show.
150
+ //
151
+ // Built only from records the page shows. From every response in the session it mixed record
152
+ // types and pages: on a disputes page, a payment's "captured" made each dispute's status look
153
+ // misrendered, and twenty bogus findings led the report.
145
154
  const vocabulary = new Map();
146
155
  for (const entity of entities) {
156
+ if (!onPage(entity, pageText))
157
+ continue;
147
158
  for (const [field, value] of Object.entries(entity)) {
148
159
  if (!STATE_FIELDS.has(field) || typeof value !== 'string')
149
160
  continue;
@@ -186,6 +197,10 @@ export function reconcile(bodies, pageText) {
186
197
  });
187
198
  }
188
199
  }
200
+ // A record the page does not show cannot be shown wrongly: a filtered list, or another page's
201
+ // data still in the session, is not a misrendering.
202
+ if (!onPage(entity, pageText))
203
+ continue;
189
204
  for (const [field, value] of Object.entries(entity)) {
190
205
  if (!STATE_FIELDS.has(field) || typeof value !== 'string')
191
206
  continue;
@@ -47,6 +47,40 @@ function differsOnlyByEnumeration(first, second) {
47
47
  }
48
48
  return differed;
49
49
  }
50
+ /**
51
+ * Parameters that NAME a resource. Two reads differing in one of these fetch two different things
52
+ * (a tile grid's `?id=1` and `?id=2`), and neither answer can overwrite the other's view.
53
+ */
54
+ const IDENTITY_PARAMS = new Set(['id', 'ids', 'uuid', 'slug', 'key']);
55
+ /** Different projections ask for differently shaped answers, both of which the app may need. */
56
+ const PROJECTION_PARAMS = new Set(['select', 'fields', 'columns', 'include', 'expand']);
57
+ /**
58
+ * Issued this close together, two requests came from one task (a `Promise.all`, two effects in one
59
+ * commit), so no later intent superseded the first: they are a fan-out, not a race (#1225).
60
+ * ponytail: a time bound stands in for "same task", which the event stream does not carry. A slow
61
+ * commit can space its effects wider than this; carry an issuing-task id if that shows up.
62
+ */
63
+ const SAME_TASK_MS = 2;
64
+ /**
65
+ * Whether the second read could have made the first obsolete. Not when they ask for differently
66
+ * shaped answers (different key sets or projections), not when they name different resources, and
67
+ * not when only enumeration changed.
68
+ */
69
+ function couldSupersede(first, second) {
70
+ const a = new URLSearchParams(first);
71
+ const b = new URLSearchParams(second);
72
+ const keysA = [...new Set(a.keys())].sort().join('&');
73
+ const keysB = [...new Set(b.keys())].sort().join('&');
74
+ if (keysA !== keysB)
75
+ return false;
76
+ for (const key of IDENTITY_PARAMS)
77
+ if (a.get(key) !== b.get(key))
78
+ return false;
79
+ for (const key of PROJECTION_PARAMS)
80
+ if (a.get(key) !== b.get(key))
81
+ return false;
82
+ return !differsOnlyByEnumeration(first, second);
83
+ }
50
84
  /** Pair NET_PENDING with its NET_REQUEST by the id both carry. Unpaired events are still in flight. */
51
85
  function flights(events) {
52
86
  const issued = new Map();
@@ -167,8 +201,9 @@ function raceIn(reads, events) {
167
201
  continue; // settled in order — no race
168
202
  if (queryOf(first.url) === queryOf(second.url))
169
203
  continue; // a retry, not a superseding query
170
- // Parallel pagination is not a race — see differsOnlyByEnumeration.
171
- if (differsOnlyByEnumeration(queryOf(first.url), queryOf(second.url)))
204
+ if (second.issuedAt - first.issuedAt < SAME_TASK_MS)
205
+ continue; // one task's fan-out
206
+ if (!couldSupersede(queryOf(first.url), queryOf(second.url)))
172
207
  continue;
173
208
  // The race happened. Whether it MATTERS is whether the app acted on the loser — an app that
174
209
  // drops superseded responses races just as visibly and is not broken.
@@ -1,4 +1,4 @@
1
- import { type ReticleEvent } from '@reticlehq/core';
1
+ import { type ExpectedLink, type ReticleEvent } from '@reticlehq/core';
2
2
  /**
3
3
  * Did a write in this window answer `202 Accepted`?
4
4
  *
@@ -14,6 +14,30 @@ import { type ReticleEvent } from '@reticlehq/core';
14
14
  * The DEV TOOLCHAIN's own traffic is excluded, on the same rule every other check applies: a verdict
15
15
  * about the app must not be decided by a request the app did not make.
16
16
  */
17
+ /**
18
+ * What the caller knows about the claim, which a bare window scan cannot (#1120).
19
+ *
20
+ * The rule is right for the write the claim depends on and wrong for everything else that answered
21
+ * 202 in the same window. An analytics beacon made every verdict in the app `unknown`, and a claim
22
+ * that deliberately asserted "the POST returned 202 and accepted: true" could not say so. The
23
+ * filter lives here, at the evidence boundary, so both callers inherit it.
24
+ *
25
+ * Every field is optional: a caller with no page URL, no declared background and no proven links
26
+ * gets exactly the behaviour this function had before, which the older unit tests pin.
27
+ */
28
+ export interface AcceptedWriteFilter {
29
+ /** The page under test. A 202 from another origin is not its outcome. */
30
+ readonly appUrl?: string | undefined;
31
+ /** Endpoints the project declared as background; their 202s are a heartbeat, not the action. */
32
+ readonly background?: readonly string[] | undefined;
33
+ /**
34
+ * The NET links the claim actually PROVED, from a green verdict only. A 202 a link names with
35
+ * `status: 202` is the claim's own acceptance: it held, and the global rule must not override it.
36
+ * On `anyOf` the proven list carries only the branch that won — a static scan of the predicate
37
+ * could exempt a 202 the verdict never rested on.
38
+ */
39
+ readonly asserted?: readonly ExpectedLink[] | undefined;
40
+ }
17
41
  /**
18
42
  * Which writes in this window answered `202 Accepted`, as "METHOD url".
19
43
  *
@@ -25,7 +49,7 @@ import { type ReticleEvent } from '@reticlehq/core';
25
49
  * Duplicates are folded, so a retried request names its endpoint once instead of filling the
26
50
  * sentence with the same line three times.
27
51
  */
28
- export declare function acceptedWriteLabels(events: readonly ReticleEvent[]): string[];
52
+ export declare function acceptedWriteLabels(events: readonly ReticleEvent[], filter?: AcceptedWriteFilter): string[];
29
53
  /**
30
54
  * Did a write in this window answer `202 Accepted`?
31
55
  *
@@ -1,20 +1,5 @@
1
- import { EventType, HTTP_ACCEPTED, isDevToolingUrl } from '@reticlehq/core';
1
+ import { ConsequenceKind, EventType, HTTP_ACCEPTED, MUTATING_METHODS, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
2
2
  import { asNumber, asString } from '@reticlehq/core';
3
- /**
4
- * Did a write in this window answer `202 Accepted`?
5
- *
6
- * `202` is the only status in HTTP whose meaning is "no outcome yet" — the server took the request
7
- * and has not finished with it. Folding it into the 2xx success band is how an asynchronous workflow
8
- * gets a green verdict at exactly the moment nothing has been decided.
9
- *
10
- * Measured on a logistics console with server-side reconciliation: a dispatch answered 202, the row
11
- * optimistically rendered "dispatched", the page settled, every channel agreed — and the server
12
- * REVERTED it to `held` 1.2 s later. The verdict was not wrong about what it observed. It was early,
13
- * and nothing in the response said so except the status code nobody was reading.
14
- *
15
- * The DEV TOOLCHAIN's own traffic is excluded, on the same rule every other check applies: a verdict
16
- * about the app must not be decided by a request the app did not make.
17
- */
18
3
  /**
19
4
  * Which writes in this window answered `202 Accepted`, as "METHOD url".
20
5
  *
@@ -26,23 +11,55 @@ import { asNumber, asString } from '@reticlehq/core';
26
11
  * Duplicates are folded, so a retried request names its endpoint once instead of filling the
27
12
  * sentence with the same line three times.
28
13
  */
29
- export function acceptedWriteLabels(events) {
14
+ export function acceptedWriteLabels(events, filter = {}) {
30
15
  const labels = [];
31
16
  for (const event of events) {
32
17
  if (event.type !== EventType.NET_REQUEST)
33
18
  continue;
34
19
  if (asNumber(event.data['status']) !== HTTP_ACCEPTED)
35
20
  continue;
21
+ const method = ('string' === typeof event.data['method'] ? event.data['method'] : '').toUpperCase();
22
+ // A read has no outcome to reconcile: a 202 on one is a poll or a prefetch.
23
+ if (!MUTATING_METHODS.includes(method))
24
+ continue;
36
25
  const url = asString(event.data['url']);
37
26
  if (isDevToolingUrl(url))
38
27
  continue;
39
- const method = ('string' === typeof event.data['method'] ? event.data['method'] : '').toUpperCase();
28
+ // The same split `splitForeignTraffic` makes for every other rule: somebody else's origin, or
29
+ // an endpoint the project itself declared as background, is not the app's work under test.
30
+ if (isForeignTraffic(url, filter.appUrl, filter.background ?? []))
31
+ continue;
32
+ if (isAssertedAcceptance(method, urlForMatch(event.data), filter.asserted))
33
+ continue;
40
34
  const label = `${method} ${url ?? ''}`.trim();
41
35
  if ('' !== label && !labels.includes(label))
42
36
  labels.push(label);
43
37
  }
44
38
  return labels;
45
39
  }
40
+ /**
41
+ * Did the claim's OWN proven evidence settle this exact request?
42
+ *
43
+ * For the request to be exempt, EVERY proven link that names it must assert `status: 202`. One link
44
+ * that names the same URL with another status — a 200 branch of an `anyOf` that also held, or a
45
+ * presence-only clause — means the verdict could have been green without this acceptance, and the
46
+ * accepted write's outcome is still owed. Method is matched when the link carries one, so a claim
47
+ * about `GET /save` cannot exempt the pending `POST /save`.
48
+ *
49
+ * `urlForMatch` and not `url`: a predicate matches the raw path, and redaction rewrites some public
50
+ * REST paths, so matching the displayed URL would drop the exemption for exactly the calls a
51
+ * predicate can still name.
52
+ */
53
+ function isAssertedAcceptance(method, url, asserted) {
54
+ if (asserted === undefined)
55
+ return false;
56
+ const naming = asserted.filter((link) => ConsequenceKind.NET === link.kind &&
57
+ link.urlContains !== undefined &&
58
+ url.includes(link.urlContains) &&
59
+ (link.method === undefined || link.method.toUpperCase() === method));
60
+ return (naming.length > 0 &&
61
+ naming.every((link) => ConsequenceKind.NET === link.kind && HTTP_ACCEPTED === link.status));
62
+ }
46
63
  /**
47
64
  * Did a write in this window answer `202 Accepted`?
48
65
  *
@@ -14,3 +14,19 @@ export declare function readsDomState(predicate: Predicate): boolean;
14
14
  * one visible match among several is a fair, ordinary read and is left alone.
15
15
  */
16
16
  export declare function alreadyTrueHiddenMatch(predicate: Predicate, evidence: unknown): boolean;
17
+ /** What a green resting on hidden matches says instead of `yes`. See `hiddenMatchNote`. */
18
+ export declare const HIDDEN_MATCH_NOTE: string;
19
+ /**
20
+ * The same, for an element check, which asks by `state` and refuses `visible` ("element accepts:
21
+ * query, state, absent") — every hidden-match answer used to advise the field it refuses.
22
+ */
23
+ export declare const HIDDEN_ELEMENT_MATCH_NOTE: string;
24
+ /**
25
+ * #1408: the post-action half of `alreadyTrueHiddenMatch`. A `text` clause beside a `net` clause is
26
+ * never already true, so a success template still hidden in the DOM passed with no caveat at all.
27
+ * Returns the note when any clause the green rests on matched only hidden elements.
28
+ *
29
+ * `evidence` is the passing result's: an `allOf` carries one entry per clause, in order, and an
30
+ * `anyOf` carries only the branch that held, which is why each branch is tried against it.
31
+ */
32
+ export declare function hiddenMatchNote(predicate: Predicate, evidence: unknown): string | undefined;
@@ -98,3 +98,51 @@ export function alreadyTrueHiddenMatch(predicate, evidence) {
98
98
  return false;
99
99
  return evidence.every((el) => !el.visible);
100
100
  }
101
+ /** What a green resting on hidden matches says instead of `yes`. See `hiddenMatchNote`. */
102
+ export const HIDDEN_MATCH_NOTE = 'the declared consequence held only on a hidden element: a text or element check matches DOM ' +
103
+ 'presence, not visibility, by default, so nothing here shows it is on screen. Add `visible: true` ' +
104
+ 'if you meant "this is showing", not merely "this exists"';
105
+ /**
106
+ * The same, for an element check, which asks by `state` and refuses `visible` ("element accepts:
107
+ * query, state, absent") — every hidden-match answer used to advise the field it refuses.
108
+ */
109
+ export const HIDDEN_ELEMENT_MATCH_NOTE = 'the declared consequence held only on a hidden element: an element check matches DOM presence, ' +
110
+ 'not visibility, by default, so nothing here shows it is on screen. Add `state: "visible"` if you ' +
111
+ 'meant "this is showing", not merely "this exists"';
112
+ /**
113
+ * #1408: the post-action half of `alreadyTrueHiddenMatch`. A `text` clause beside a `net` clause is
114
+ * never already true, so a success template still hidden in the DOM passed with no caveat at all.
115
+ * Returns the note when any clause the green rests on matched only hidden elements.
116
+ *
117
+ * `evidence` is the passing result's: an `allOf` carries one entry per clause, in order, and an
118
+ * `anyOf` carries only the branch that held, which is why each branch is tried against it.
119
+ */
120
+ export function hiddenMatchNote(predicate, evidence) {
121
+ const kind = hiddenMatchKind(predicate, evidence);
122
+ if (kind === undefined)
123
+ return undefined;
124
+ return PredicateKind.ELEMENT === kind ? HIDDEN_ELEMENT_MATCH_NOTE : HIDDEN_MATCH_NOTE;
125
+ }
126
+ /** The kind of the first clause the green rests on that matched only hidden elements. */
127
+ function hiddenMatchKind(predicate, evidence) {
128
+ if (PredicateKind.ALL_OF === predicate.kind) {
129
+ if (!Array.isArray(evidence))
130
+ return undefined;
131
+ const each = evidence;
132
+ for (const [i, clause] of predicate.predicates.entries()) {
133
+ const kind = hiddenMatchKind(clause, each[i]);
134
+ if (kind !== undefined)
135
+ return kind;
136
+ }
137
+ return undefined;
138
+ }
139
+ if (PredicateKind.ANY_OF === predicate.kind) {
140
+ for (const clause of predicate.predicates) {
141
+ const kind = hiddenMatchKind(clause, evidence);
142
+ if (kind !== undefined)
143
+ return kind;
144
+ }
145
+ return undefined;
146
+ }
147
+ return alreadyTrueHiddenMatch(predicate, evidence) ? predicate.kind : undefined;
148
+ }
@@ -14,6 +14,7 @@
14
14
  * and has no evidence behind it.
15
15
  */
16
16
  import { PredicateKind, ReticleCommand } from '@reticlehq/core';
17
+ import { textPredicateQuery } from '../question/predicate/predicate-element.js';
17
18
  /** The properties that mean nothing without a before-reading. Mirrors `RELATIVE` in property.ts. */
18
19
  const NEEDS_BASELINE = new Set([
19
20
  'changed',
@@ -72,12 +73,7 @@ async function readStateValue(session, predicate) {
72
73
  return 'boolean' === typeof reply.found ? { taken: true, value: reply.value } : undefined;
73
74
  }
74
75
  async function readText(session, predicate) {
75
- const query = {
76
- ...(predicate.contains === undefined ? {} : { text: predicate.contains }),
77
- ...(predicate.scope === undefined
78
- ? {}
79
- : { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
80
- };
76
+ const query = textPredicateQuery(predicate);
81
77
  const match = await session.command(ReticleCommand.MATCH, { query });
82
78
  if (!match.ok)
83
79
  return undefined;
@@ -47,8 +47,15 @@ interface CoverageStatement {
47
47
  * not depend on the evidence.
48
48
  */
49
49
  export declare function impeachesCapture(kind: BlindSpotKind): boolean;
50
- /** Compose the coverage statement. `full` (no note) when nothing was unobserved. */
51
- export declare function buildCoverageStatement(spots: readonly BlindSpot[]): CoverageStatement;
50
+ /**
51
+ * Compose the coverage statement. `full` (no note) when nothing was unobserved.
52
+ *
53
+ * `windowSpots`, when given, are the same spots counted over the judged window only. An impeaching
54
+ * kind is then labelled by what the WINDOW saw: its window count when it dropped events there, and
55
+ * as an earlier-in-the-session fact when it did not. Bounding kinds are standing facts of the page
56
+ * and keep their session-wide label.
57
+ */
58
+ export declare function buildCoverageStatement(spots: readonly BlindSpot[], windowSpots?: readonly BlindSpot[]): CoverageStatement;
52
59
  /**
53
60
  * Reduce a window's BLIND_SPOT events to one spot per kind — the LATEST reported count wins (the sensor
54
61
  * emits only on change, so the last value is the live count). This is how a result's coverage is derived
@@ -88,6 +95,9 @@ interface AbsencePredicate {
88
95
  absent?: boolean;
89
96
  query?: {
90
97
  scope?: unknown;
98
+ role?: string | undefined;
99
+ by?: string | undefined;
100
+ value?: string | undefined;
91
101
  };
92
102
  predicate?: AbsencePredicate;
93
103
  }
@@ -98,7 +108,8 @@ interface AbsencePredicate {
98
108
  *
99
109
  * Fires on three blind-spot kinds:
100
110
  * - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
101
- * - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element
111
+ * - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element (scoped:
112
+ * skipped when the queried role is structurally page-level, like dialog or a landmark)
102
113
  * - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
103
114
  */
104
115
  export declare function absenceBlindSpotNote(predicate: AbsencePredicate, spots: readonly BlindSpot[]): string | undefined;
@@ -7,7 +7,7 @@
7
7
  // The kind enum lives in core (it crosses the wire in a BLIND_SPOT event); re-exported here for the
8
8
  // honesty-side callers.
9
9
  export { BlindSpotKind } from '@reticlehq/core';
10
- import { BlindSpotKind, EventType, PredicateKind, ReticleEnv, TRANSPORT_LIMITS, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
10
+ import { BlindSpotKind, EventType, PredicateKind, QueryBy, ReticleEnv, TRANSPORT_LIMITS, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
11
11
  /**
12
12
  * Whether the observation window saw everything it was asked about.
13
13
  *
@@ -43,7 +43,7 @@ const LABEL = {
43
43
  // Not a tally — a fact about the app's wiring, phrased as what the EMPTY state channel means. An
44
44
  // agent reading `stateDiffs: []` otherwise reads "the app changed no state", which is a claim
45
45
  // nothing here can support. Names the one-line fix, because the reader is the one who can apply it.
46
- [BlindSpotKind.UNWATCHED_STATE]: () => 'no subscribable store is registered, so NO state change is observed — an empty stateDiffs here means unwatched, not unchanged (register the store itself in your reticle-dev module: registerStore(name, store), not a getter)',
46
+ [BlindSpotKind.UNWATCHED_STATE]: () => "no subscribable store is registered, so NO state change is observed — an empty stateDiffs here means unwatched, not unchanged (import { registerStore } from '@reticlehq/browser' and call registerStore(name, store) with a subscribable store; for component-local React state, import { useReticleStore } from '@reticlehq/react/store' and call useReticleStore(name, value), or inspect it with reticle_look { action: 'state', ref: '...' })",
47
47
  [BlindSpotKind.WRAPPED_NETWORK]: () => 'fetch was already wrapped before Reticle, so recorded requests may differ from what was sent',
48
48
  // A fact about the app's wiring, not a tally. Says what a network view WITHOUT ipc:// records
49
49
  // MEANS, because that state here is indistinguishable from "this app made no backend calls" —
@@ -72,8 +72,21 @@ const LABEL = {
72
72
  export function impeachesCapture(kind) {
73
73
  return kind === BlindSpotKind.RATE_LIMITED;
74
74
  }
75
- /** Compose the coverage statement. `full` (no note) when nothing was unobserved. */
76
- export function buildCoverageStatement(spots) {
75
+ /**
76
+ * Bridge sampling that happened in the session but not in the window being judged (#1414). The
77
+ * window's own label says "this window is SAMPLED" and asks for a re-run, which is false here: the
78
+ * verdict's capture is whole, and repeating the drive would only repeat a clean check.
79
+ */
80
+ const RATE_LIMITED_ELSEWHERE = (n) => `${String(n)} event${1 === n ? '' : 's'} dropped by the bridge rate cap earlier in this session, none in this window, so this result's capture is complete`;
81
+ /**
82
+ * Compose the coverage statement. `full` (no note) when nothing was unobserved.
83
+ *
84
+ * `windowSpots`, when given, are the same spots counted over the judged window only. An impeaching
85
+ * kind is then labelled by what the WINDOW saw: its window count when it dropped events there, and
86
+ * as an earlier-in-the-session fact when it did not. Bounding kinds are standing facts of the page
87
+ * and keep their session-wide label.
88
+ */
89
+ export function buildCoverageStatement(spots, windowSpots) {
77
90
  const present = spots.filter((s) => s.count > 0);
78
91
  if (0 === present.length)
79
92
  return { coverage: Coverage.FULL, spots: [] };
@@ -85,7 +98,15 @@ export function buildCoverageStatement(spots) {
85
98
  // daemon can report one, and `LABEL[kind](count)` threw a TypeError on the verdict path when it
86
99
  // did — turning "there is something I could not see" into a crashed assert, which is worse than
87
100
  // either the caveat or the silence. Unknown kinds degrade to their own name.
88
- const label = (s) => 'function' === typeof LABEL[s.kind] ? LABEL[s.kind](s.count) : `${s.kind} (${String(s.count)})`;
101
+ const known = (s) => 'function' === typeof LABEL[s.kind] ? LABEL[s.kind](s.count) : `${s.kind} (${String(s.count)})`;
102
+ const label = (s) => {
103
+ if (windowSpots === undefined || !impeachesCapture(s.kind))
104
+ return known(s);
105
+ const inWindow = windowSpots.find((w) => w.kind === s.kind)?.count ?? 0;
106
+ return 0 < inWindow
107
+ ? known({ kind: s.kind, count: inWindow })
108
+ : RATE_LIMITED_ELSEWHERE(s.count);
109
+ };
89
110
  const note = `${Coverage.PARTIAL} — ${present.map(label).join(', ')}`;
90
111
  return { coverage: Coverage.PARTIAL, note, spots: present };
91
112
  }
@@ -145,7 +166,8 @@ export function blindSpotsFromState(state, runtime) {
145
166
  return spotsForRuntime(spots, runtime);
146
167
  }
147
168
  /**
148
- * Events the BROWSER's own transport queue threw away inside this window, or 0.
169
+ * Events lost in transport inside this window, or 0: the BROWSER's own transport queue threw them
170
+ * away, or the daemon dropped a frame from a live session that it could not read (#1413).
149
171
  *
150
172
  * `RATE_LIMITED` — the BRIDGE sampling because events arrived faster than its per-second cap — is
151
173
  * already the one blind spot that `impeachesCapture`, on the reasoning that a green over a window
@@ -170,6 +192,18 @@ function droppedByTransport(events) {
170
192
  }
171
193
  return dropped;
172
194
  }
195
+ /**
196
+ * Roles that are structurally page-level and can never be a virtualized list row. A dialog is
197
+ * always a top-level overlay; a landmark is a page-structural element. Absence of one of these
198
+ * is not threatened by rows a virtualizer unmounted off-screen (#1236).
199
+ */
200
+ const NEVER_VIRTUALIZED_ROLES = new Set([
201
+ 'dialog',
202
+ 'alertdialog',
203
+ 'banner',
204
+ 'contentinfo',
205
+ 'main',
206
+ ]);
173
207
  /**
174
208
  * When an absence assertion targets a page with regions Reticle cannot observe, "the element is
175
209
  * absent" means only "it is absent in what I CAN see". Returns a note when that distinction
@@ -177,7 +211,8 @@ function droppedByTransport(events) {
177
211
  *
178
212
  * Fires on three blind-spot kinds:
179
213
  * - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
180
- * - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element
214
+ * - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element (scoped:
215
+ * skipped when the queried role is structurally page-level, like dialog or a landmark)
181
216
  * - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
182
217
  */
183
218
  export function absenceBlindSpotNote(predicate, spots) {
@@ -195,11 +230,14 @@ export function absenceBlindSpotNote(predicate, spots) {
195
230
  }
196
231
  if (PredicateKind.ELEMENT !== predicate.kind || true !== predicate.absent)
197
232
  return undefined;
233
+ const role = predicate.query?.role ??
234
+ (QueryBy.ROLE === predicate.query?.by ? predicate.query.value : undefined);
198
235
  const relevant = spots.filter((spot) => spot.count > 0 &&
199
236
  (spot.kind === BlindSpotKind.CROSS_ORIGIN_IFRAME
200
237
  ? undefined !== predicate.query?.scope
201
- : spot.kind === BlindSpotKind.VIRTUALIZED_UNMOUNTED ||
202
- spot.kind === BlindSpotKind.CLOSED_SHADOW_ROOT));
238
+ : spot.kind === BlindSpotKind.VIRTUALIZED_UNMOUNTED
239
+ ? undefined === role || !NEVER_VIRTUALIZED_ROLES.has(role)
240
+ : spot.kind === BlindSpotKind.CLOSED_SHADOW_ROOT));
203
241
  if (0 === relevant.length)
204
242
  return undefined;
205
243
  const statement = buildCoverageStatement(relevant);
@@ -210,7 +248,7 @@ export function transportGapNote(events) {
210
248
  const dropped = droppedByTransport(events);
211
249
  return 0 === dropped
212
250
  ? undefined
213
- : `the browser dropped ${String(dropped)} event(s) in this window (transport queue overflow), so events that would have contradicted this may never have arrived`;
251
+ : `${String(dropped)} event(s) in this window were lost in transport (a browser queue overflow, or a frame the daemon could not read), so events that would have contradicted this may never have arrived`;
214
252
  }
215
253
  /**
216
254
  * Is the state channel dark?
@@ -22,6 +22,16 @@ export declare const BODY_CAPTURE_MIN_VERSION = "2.4.0";
22
22
  * one wasted read. The asymmetry decides it.
23
23
  */
24
24
  export declare function bodyCaptureRemedy(sdkVersion: string | undefined): string;
25
+ /**
26
+ * The invariant opening of the refusal below, named so the error envelope can recognise it.
27
+ *
28
+ * The refusal's TAIL is the remedy, and there are two of those — switch the setting on, or upgrade
29
+ * an SDK too old to have it — so the opening is the only text both shapes share. The envelope's
30
+ * self-recovering table keys on phrasing, and a reword here with the phrasing retyped over there
31
+ * would silently unmap the refusal and put the "may be a defect in Reticle" ask back on a message
32
+ * that already names the fix.
33
+ */
34
+ export declare const BODY_CLAUSE_REFUSAL_OPENING = "this assertion reads a request/response BODY, and this session is not recording them";
25
35
  /**
26
36
  * Refuse a body clause the session cannot answer, BEFORE the action is spent.
27
37
  *
@@ -40,7 +40,10 @@ function isAtLeast(version, minimum) {
40
40
  /** The sentence naming the setting — only ever produced for an SDK that HAS it. */
41
41
  const ENABLE_IT = 'Turn it on where your app calls connect(): `reticle.connect({ captureNetworkBodies: true })`, ' +
42
42
  'or for the Vite plugin `reticle({ captureNetworkBodies: true })` / VITE_RETICLE_CAPTURE_BODIES=1. ' +
43
- 'Then re-run the action.';
43
+ 'Before bodies are kept, built-in rules redact keys such as `password`, `apiKey` and ' +
44
+ '`authorization`, selected token keys, and known secret shapes. Other credential fields may ' +
45
+ 'remain; add their names with `redact.keys` and use staging. See ' +
46
+ 'https://docs.reticle.sh/what-is-recorded for the limits. Then re-run the action.';
44
47
  /**
45
48
  * The remedy for this session, or the honest statement that there is none.
46
49
  *
@@ -77,6 +80,16 @@ function asksAboutBody(predicate) {
77
80
  return nested.some(asksAboutBody);
78
81
  return asksAboutBody(nested);
79
82
  }
83
+ /**
84
+ * The invariant opening of the refusal below, named so the error envelope can recognise it.
85
+ *
86
+ * The refusal's TAIL is the remedy, and there are two of those — switch the setting on, or upgrade
87
+ * an SDK too old to have it — so the opening is the only text both shapes share. The envelope's
88
+ * self-recovering table keys on phrasing, and a reword here with the phrasing retyped over there
89
+ * would silently unmap the refusal and put the "may be a defect in Reticle" ask back on a message
90
+ * that already names the fix.
91
+ */
92
+ export const BODY_CLAUSE_REFUSAL_OPENING = 'this assertion reads a request/response BODY, and this session is not recording them';
80
93
  /**
81
94
  * Refuse a body clause the session cannot answer, BEFORE the action is spent.
82
95
  *
@@ -96,6 +109,6 @@ export function bodyClauseRefusal(predicate, session) {
96
109
  return undefined;
97
110
  if (!asksAboutBody(predicate))
98
111
  return undefined;
99
- return ('this assertion reads a request/response BODY, and this session is not recording them — it ' +
112
+ return (`${BODY_CLAUSE_REFUSAL_OPENING} — it ` +
100
113
  `would fail whatever the app did. Nothing ran, so no action was spent. ${bodyCaptureRemedy(session.sdkVersion)}`);
101
114
  }
@@ -14,7 +14,9 @@ export function gapsForAction(facts) {
14
14
  const off = true === facts.sourceMappingDisabled;
15
15
  gaps.push(instrumentationGap(off ? InstrumentationGapKind.SOURCE_MAPPING_OFF : InstrumentationGapKind.NO_SOURCE_MAPPING, off
16
16
  ? 'source mapping is turned off for this build, so no element carries data-reticle-source'
17
- : 'the control that was driven carries no source mapping', 'this verdict can name the control but not the file and line that render it, so finding the code is a separate search', { ...(facts.ref === undefined ? {} : { ref: facts.ref }) }));
17
+ : facts.ref === undefined
18
+ ? 'nothing this verdict located carries a source mapping'
19
+ : 'the control that was driven carries no source mapping', 'this verdict can name the control but not the file and line that render it, so finding the code is a separate search', { ...(facts.ref === undefined ? {} : { ref: facts.ref }) }));
18
20
  }
19
21
  // Asked about state, and there is no state channel to answer from. Deliberately UNLOCATED: a store
20
22
  // is registered once at app setup, nowhere near the control that was driven, and nothing in this
@@ -0,0 +1,2 @@
1
+ /** Compatibility export for existing evidence consumers. */
2
+ export { CACHE_BOOKKEEPING_KEYS, isCacheBookkeepingDiff } from '../state-bookkeeping.js';
@@ -0,0 +1,2 @@
1
+ /** Compatibility export for existing evidence consumers. */
2
+ export { CACHE_BOOKKEEPING_KEYS, isCacheBookkeepingDiff } from '../state-bookkeeping.js';