@reticlehq/engine 3.9.0 → 3.10.1

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,12 +1,13 @@
1
1
  /**
2
2
  * Which predicates can be satisfied by something that was already true before the action.
3
3
  *
4
- * Event-based kinds (net, signal, console, animation, settled) are evaluated against the
4
+ * Event-based kinds (net, signal, console, settled) are evaluated against the
5
5
  * event buffer floored at the act's own cursor, so a stale event cannot satisfy them — that floor is
6
6
  * why `act_and_wait` can trust them at all.
7
7
  *
8
- * `element` and `text` read the LIVE DOM, `route` can fall back to the current route, and `state` reads
9
- * live store memory via STATE_READ — where no event floor applies. A condition that held before the
8
+ * `element` and `text` read the LIVE DOM, `route` can fall back to the current route, `animation`
9
+ * can fall back to the page's current `getAnimations()` state, and `state` reads live store memory
10
+ * via STATE_READ — where no event floor applies. A condition that held before the
10
11
  * click holds after it and passes instantly, whatever the action did. A click asserted with
11
12
  * `{ kind: 'text', contains: 'Parallel Routes' }` returns `verified: "yes"` against
12
13
  * `routeChanges: 0` when the predicate matches a nav link that was already on screen, while the real
@@ -18,7 +19,10 @@
18
19
  */
19
20
  import { PredicateKind, compareSourceClauses } from '@reticlehq/core';
20
21
  import { asksForComparison } from './baseline.js';
21
- export function readsDomState(predicate) {
22
+ function predicateSince(predicate) {
23
+ return 'since' in predicate && 'number' === typeof predicate.since ? predicate.since : 0;
24
+ }
25
+ export function readsDomState(predicate, since = 0) {
22
26
  switch (predicate.kind) {
23
27
  // ROUTE is here, and it did not used to be. It was purely event-based — satisfiable only by a
24
28
  // navigation inside the act's window, and therefore unable to be answered by the past — so it
@@ -50,15 +54,17 @@ export function readsDomState(predicate) {
50
54
  case PredicateKind.ELEMENT:
51
55
  case PredicateKind.ROUTE:
52
56
  return true;
57
+ case PredicateKind.ANIMATION:
58
+ return 0 === Math.max(since, predicateSince(predicate));
53
59
  case PredicateKind.ALL_OF:
54
60
  case PredicateKind.ANY_OF:
55
- return predicate.predicates.some(readsDomState);
61
+ return predicate.predicates.some((p) => readsDomState(p, since));
56
62
  case PredicateKind.NOT:
57
- return readsDomState(predicate.predicate);
63
+ return readsDomState(predicate.predicate, since);
58
64
  // A comparison between two LIVE readings (text, a store) can already agree before the click, and
59
65
  // then it proves nothing about the click. A `net` or `signal` side is floored like any other.
60
66
  case PredicateKind.COMPARE:
61
- return compareSourceClauses(predicate).some(readsDomState);
67
+ return compareSourceClauses(predicate).some((p) => readsDomState(p, since));
62
68
  default:
63
69
  return false;
64
70
  }
@@ -1,5 +1,6 @@
1
1
  import type { Predicate } from '../question/predicate/predicate.js';
2
2
  import type { Baseline } from '../question/predicate/property.js';
3
+ export type { Baselines } from '../question/predicate/predicate.js';
3
4
  import type { PredicateSession } from '../question/predicate/predicate-session.js';
4
5
  /**
5
6
  * Does this leaf's claim compare two readings?
@@ -13,8 +13,8 @@
13
13
  * arbitrary named checkpoints. A `snapshot("cart")` / `compare("cart")` pair is a different feature
14
14
  * and has no evidence behind it.
15
15
  */
16
- import { MatchArg, PredicateKind, ReticleCommand } from '@reticlehq/core';
17
- import { textPredicateQuery } from '../question/predicate/predicate-element.js';
16
+ import { PredicateKind, ReticleCommand } from '@reticlehq/core';
17
+ import { matchOnce, textPredicateQuery } from '../question/predicate/predicate-element.js';
18
18
  /** The properties that mean nothing without a before-reading. Mirrors `RELATIVE` in property.ts. */
19
19
  const NEEDS_BASELINE = new Set([
20
20
  'changed',
@@ -41,21 +41,24 @@ function leavesNeedingBaseline(predicate, into) {
41
41
  switch (predicate.kind) {
42
42
  case PredicateKind.ALL_OF:
43
43
  case PredicateKind.ANY_OF:
44
- for (const part of predicate.predicates)
44
+ for (const part of predicate.predicates) {
45
45
  leavesNeedingBaseline(part, into);
46
+ }
46
47
  return;
47
48
  case PredicateKind.NOT:
48
49
  leavesNeedingBaseline(predicate.predicate, into);
49
50
  return;
50
51
  default:
51
- if (asksForComparison(predicate))
52
+ if (asksForComparison(predicate)) {
52
53
  into.push(predicate);
54
+ }
53
55
  }
54
56
  }
55
57
  /** Does the whole tree need a pre-action reading at all? One walk, so the caller pays nothing. */
56
58
  export function needsBaseline(predicate) {
57
- if (predicate === undefined)
59
+ if (predicate === undefined) {
58
60
  return false;
61
+ }
59
62
  const found = [];
60
63
  leavesNeedingBaseline(predicate, found);
61
64
  return found.length > 0;
@@ -65,8 +68,9 @@ async function readStateValue(session, predicate) {
65
68
  ? { path: predicate.path }
66
69
  : { store: predicate.store, path: predicate.path };
67
70
  const read = await session.command(ReticleCommand.STATE_READ, args);
68
- if (!read.ok)
71
+ if (!read.ok) {
69
72
  return undefined;
73
+ }
70
74
  const reply = (read.result ?? {});
71
75
  // `found: false` is a reading — the path held nothing — and it is NOT the same as "nobody
72
76
  // looked". Only an unreadable store returns undefined above.
@@ -76,19 +80,24 @@ async function readText(session, predicate) {
76
80
  const query = textPredicateQuery(predicate, session.sdkVersion);
77
81
  // Read the way the property will read it after the action: a before-reading of the display form
78
82
  // against an after-reading of the whole text would call every long text "changed".
79
- const match = await session.command(ReticleCommand.MATCH, {
80
- query,
81
- [MatchArg.FULL_TEXT]: true,
82
- });
83
- if (!match.ok)
83
+ // Through the verdict's own round-trip, so a page whose SDK refuses `matchCase` is asked again
84
+ // without it and gets a baseline too. A reply that cannot be read gives no baseline.
85
+ let match;
86
+ try {
87
+ match = await matchOnce(session, query, undefined, undefined, true);
88
+ }
89
+ catch {
84
90
  return undefined;
85
- const elements = (match.result ?? {}).elements;
86
- if (!Array.isArray(elements))
91
+ }
92
+ const elements = match.elements;
93
+ if (!Array.isArray(elements)) {
87
94
  return undefined;
95
+ }
88
96
  const text = elements
89
97
  .map((element) => {
90
- if ('object' !== typeof element || null === element)
98
+ if ('object' !== typeof element || null === element) {
91
99
  return '';
100
+ }
92
101
  const value = element.text;
93
102
  return 'string' === typeof value ? value : '';
94
103
  })
@@ -106,8 +115,9 @@ async function readText(session, predicate) {
106
115
  */
107
116
  export async function captureBaselines(session, predicate) {
108
117
  const captured = new Map();
109
- if (predicate === undefined)
118
+ if (predicate === undefined) {
110
119
  return captured;
120
+ }
111
121
  const leaves = [];
112
122
  leavesNeedingBaseline(predicate, leaves);
113
123
  for (const leaf of leaves) {
@@ -117,8 +127,9 @@ export async function captureBaselines(session, predicate) {
117
127
  : PredicateKind.TEXT === leaf.kind
118
128
  ? await readText(session, leaf)
119
129
  : undefined;
120
- if (reading !== undefined)
130
+ if (reading !== undefined) {
121
131
  captured.set(leaf, reading);
132
+ }
122
133
  }
123
134
  catch {
124
135
  // A reading that could not be taken leaves the leaf with no baseline, which the evaluator
@@ -5,7 +5,8 @@
5
5
  * Pure formatting over the counted blind spots the observers report.
6
6
  */
7
7
  export { BlindSpotKind } from '@reticlehq/core';
8
- import { BlindSpotKind, type ReticleEvent } from '@reticlehq/core';
8
+ import type { ContradictionOptions } from '../disagreement/contradiction-types.js';
9
+ import { BlindSpotKind, type Predicate, type ReticleEvent } from '@reticlehq/core';
9
10
  interface BlindSpot {
10
11
  kind: BlindSpotKind;
11
12
  count: number;
@@ -98,6 +99,8 @@ interface AbsencePredicate {
98
99
  role?: string | undefined;
99
100
  by?: string | undefined;
100
101
  value?: string | undefined;
102
+ testid?: string | undefined;
103
+ text?: string | undefined;
101
104
  };
102
105
  predicate?: AbsencePredicate;
103
106
  }
@@ -109,10 +112,11 @@ interface AbsencePredicate {
109
112
  * Fires on three blind-spot kinds:
110
113
  * - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
111
114
  * - 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)
115
+ * skipped when the queried role is structurally page-level, like dialog or a landmark, or when
116
+ * the window saw the target itself leave as a page-level node)
113
117
  * - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
114
118
  */
115
- export declare function absenceBlindSpotNote(predicate: AbsencePredicate, spots: readonly BlindSpot[]): string | undefined;
119
+ export declare function absenceBlindSpotNote(predicate: AbsencePredicate, spots: readonly BlindSpot[], windowEvents?: readonly ReticleEvent[]): string | undefined;
116
120
  /** The impeaching note for a transport gap, or undefined when the window was intact. */
117
121
  export declare function transportGapNote(events: readonly ReticleEvent[]): string | undefined;
118
122
  /**
@@ -142,3 +146,16 @@ export declare function restsOnCompleteWindow(predicate: {
142
146
  count?: number;
143
147
  predicate?: unknown;
144
148
  }): boolean;
149
+ /**
150
+ * For a failing assertion whose buffer lost events: does the failure rest on a clause that reads
151
+ * event history?
152
+ *
153
+ * An `allOf` that failed could have failed on ANY child. A child whose evidence IS present in
154
+ * the window passed; only a child whose evidence is ABSENT could have failed, and if that child
155
+ * reads event history the failure might be the buffer's fault. Checking the window events against
156
+ * each event-history child is what tells `allOf[{net /a}, {element Submit}]` apart from
157
+ * `allOf[{net /a}, {element Submit}]` where the request is present and only the button is missing.
158
+ */
159
+ export declare function failingClauseReadsLostChannel(predicate: Predicate, windowEvents: readonly ReticleEvent[]): boolean;
160
+ /** The coverage-line spot for a window where `readStateRender` abstained for a canvas, else none. */
161
+ export declare function canvasPaintSpots(events: readonly ReticleEvent[], options: Pick<ContradictionOptions, 'actionSince' | 'prior'>): BlindSpot[];
@@ -7,7 +7,8 @@
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, QueryBy, ReticleEnv, TRANSPORT_LIMITS, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
10
+ import { readStateRender, StateRender } from '../disagreement/contradictions.js';
11
+ import { BlindSpotKind, ChannelId, EventType, PredicateKind, QueryBy, ReticleEnv, TRANSPORT_LIMITS, asString, channelsReadBy, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
11
12
  /**
12
13
  * Whether the observation window saw everything it was asked about.
13
14
  *
@@ -50,6 +51,9 @@ const LABEL = {
50
51
  // and that reading is the false green: every IPC call went unseen and every `assert { net }` over
51
52
  // them is vacuous. Document-initiated loads ARE seen since subresource observation (#447), so
52
53
  // the note names the missing half instead of claiming the whole view is blind.
54
+ // A fact about one act window, phrased as what an absent render MEANS there: the store moved, no
55
+ // DOM node did, and a canvas could hold the render in pixels the digest did not see change.
56
+ [BlindSpotKind.CANVAS_PAINT_UNOBSERVED]: (n) => `canvas paint not observed: the store changed and no DOM node did, and ${String(n)} canvas${1 === n ? '' : 'es'} on screen showed no change the digest could see, so state-vs-render was not judged`,
53
57
  [BlindSpotKind.UNOBSERVED_IPC]: () => "this Electron renderer has no Reticle preload, so NO ipcRenderer.invoke is observed; document-initiated loads may still appear, so a view with no ipc:// records means unseen IPC, not none (add require('@reticlehq/electron/preload') to your preload)",
54
58
  };
55
59
  /**
@@ -88,8 +92,9 @@ const RATE_LIMITED_ELSEWHERE = (n) => `${String(n)} event${1 === n ? '' : 's'} d
88
92
  */
89
93
  export function buildCoverageStatement(spots, windowSpots) {
90
94
  const present = spots.filter((s) => s.count > 0);
91
- if (0 === present.length)
95
+ if (0 === present.length) {
92
96
  return { coverage: Coverage.FULL, spots: [] };
97
+ }
93
98
  // Each label carries its own ending. Appending a blanket " unobserved" here produced
94
99
  // "...may differ from what was sent unobserved" for the wrapped-network caveat, which is a
95
100
  // sentence rather than a count — and the same dangle appeared the moment a second prose-shaped
@@ -100,8 +105,9 @@ export function buildCoverageStatement(spots, windowSpots) {
100
105
  // either the caveat or the silence. Unknown kinds degrade to their own name.
101
106
  const known = (s) => 'function' === typeof LABEL[s.kind] ? LABEL[s.kind](s.count) : `${s.kind} (${String(s.count)})`;
102
107
  const label = (s) => {
103
- if (windowSpots === undefined || !impeachesCapture(s.kind))
108
+ if (windowSpots === undefined || !impeachesCapture(s.kind)) {
104
109
  return known(s);
110
+ }
105
111
  const inWindow = windowSpots.find((w) => w.kind === s.kind)?.count ?? 0;
106
112
  return 0 < inWindow
107
113
  ? known({ kind: s.kind, count: inWindow })
@@ -118,8 +124,9 @@ export function buildCoverageStatement(spots, windowSpots) {
118
124
  export function blindSpotsFromEvents(events) {
119
125
  const latest = new Map();
120
126
  for (const e of events) {
121
- if (e.type !== EventType.BLIND_SPOT)
127
+ if (e.type !== EventType.BLIND_SPOT) {
122
128
  continue;
129
+ }
123
130
  const kind = e.data['kind'];
124
131
  const count = e.data['count'];
125
132
  if ('string' === typeof kind && 'number' === typeof count) {
@@ -140,10 +147,12 @@ export function spotsForRuntime(spots, runtime) {
140
147
  // Unknown runtime keeps the rows, deliberately and separately from the table below: an older SDK
141
148
  // sends none, and dropping a real missing-preload warning is worse than showing one that does not
142
149
  // apply. The table answers "does this realm raise these", not "should silence be treated as no".
143
- if (runtime === undefined)
150
+ if (runtime === undefined) {
144
151
  return [...spots];
145
- if (realmOf(runtime).ownsCoverageKinds)
152
+ }
153
+ if (realmOf(runtime).ownsCoverageKinds) {
146
154
  return [...spots];
155
+ }
147
156
  return spots.filter((spot) => !isDesktopBlindSpot(spot.kind));
148
157
  }
149
158
  /**
@@ -185,8 +194,9 @@ export function blindSpotsFromState(state, runtime) {
185
194
  function droppedByTransport(events) {
186
195
  let dropped = 0;
187
196
  for (const e of events) {
188
- if (e.type !== EventType.TRANSPORT_OVERFLOW)
197
+ if (e.type !== EventType.TRANSPORT_OVERFLOW) {
189
198
  continue;
199
+ }
190
200
  const n = e.data['dropped'];
191
201
  dropped += 'number' === typeof n ? n : 0;
192
202
  }
@@ -204,6 +214,24 @@ const NEVER_VIRTUALIZED_ROLES = new Set([
204
214
  'contentinfo',
205
215
  'main',
206
216
  ]);
217
+ /**
218
+ * Did the window see the asserted element itself leave the page, as a page-level node?
219
+ *
220
+ * The virtualized blind spot says an unmounted row could hold the target. A `dom.removed` that
221
+ * names the target by its testid shows that the target was on the page and left (#2176). Only a
222
+ * page-level role counts: a virtualizer unmounts a ROW when it scrolls out of view, and that row's
223
+ * removal says nothing about the data. The blind-spot event carries a count and no container, so
224
+ * the engine cannot tell whether a target is outside every virtualized container.
225
+ */
226
+ function sawPageLevelTargetLeave(query, windowEvents) {
227
+ const testid = query?.testid ?? (QueryBy.TESTID === query?.by ? query.value : undefined);
228
+ if (undefined === testid) {
229
+ return false;
230
+ }
231
+ return windowEvents.some((e) => EventType.DOM_REMOVED === e.type &&
232
+ testid === asString(e.data['testid']) &&
233
+ NEVER_VIRTUALIZED_ROLES.has(asString(e.data['role']) ?? ''));
234
+ }
207
235
  /**
208
236
  * When an absence assertion targets a page with regions Reticle cannot observe, "the element is
209
237
  * absent" means only "it is absent in what I CAN see". Returns a note when that distinction
@@ -212,34 +240,46 @@ const NEVER_VIRTUALIZED_ROLES = new Set([
212
240
  * Fires on three blind-spot kinds:
213
241
  * - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
214
242
  * - 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)
243
+ * skipped when the queried role is structurally page-level, like dialog or a landmark, or when
244
+ * the window saw the target itself leave as a page-level node)
216
245
  * - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
217
246
  */
218
- export function absenceBlindSpotNote(predicate, spots) {
247
+ export function absenceBlindSpotNote(predicate, spots, windowEvents = []) {
219
248
  // `not(element)` is the third spelling of an absence assertion — the `not` wrapper IS the
220
249
  // negation, so the inner predicate will not carry `absent: true`. Unwrap and synthesize it.
221
250
  // `not(element { absent: true })` is a double negative — presence — and a positive match is
222
251
  // not threatened by an unobservable region.
223
252
  if (PredicateKind.NOT === predicate.kind && predicate.predicate !== undefined) {
224
253
  if (PredicateKind.ELEMENT === predicate.predicate.kind) {
225
- if (true === predicate.predicate.absent)
254
+ if (true === predicate.predicate.absent) {
226
255
  return undefined;
227
- return absenceBlindSpotNote({ ...predicate.predicate, absent: true }, spots);
256
+ }
257
+ return absenceBlindSpotNote({ ...predicate.predicate, absent: true }, spots, windowEvents);
228
258
  }
229
259
  return undefined;
230
260
  }
231
- if (PredicateKind.ELEMENT !== predicate.kind || true !== predicate.absent)
261
+ if (PredicateKind.ELEMENT !== predicate.kind || true !== predicate.absent) {
232
262
  return undefined;
263
+ }
233
264
  const role = predicate.query?.role ??
234
265
  (QueryBy.ROLE === predicate.query?.by ? predicate.query.value : undefined);
235
- const relevant = spots.filter((spot) => spot.count > 0 &&
236
- (spot.kind === BlindSpotKind.CROSS_ORIGIN_IFRAME
237
- ? undefined !== predicate.query?.scope
238
- : spot.kind === BlindSpotKind.VIRTUALIZED_UNMOUNTED
239
- ? undefined === role || !NEVER_VIRTUALIZED_ROLES.has(role)
240
- : spot.kind === BlindSpotKind.CLOSED_SHADOW_ROOT));
241
- if (0 === relevant.length)
266
+ const virtualizedApplies = (undefined === role || !NEVER_VIRTUALIZED_ROLES.has(role)) &&
267
+ !sawPageLevelTargetLeave(predicate.query, windowEvents);
268
+ const relevant = spots.filter((spot) => {
269
+ if (spot.count <= 0) {
270
+ return false;
271
+ }
272
+ if (spot.kind === BlindSpotKind.CROSS_ORIGIN_IFRAME) {
273
+ return undefined !== predicate.query?.scope;
274
+ }
275
+ if (spot.kind === BlindSpotKind.VIRTUALIZED_UNMOUNTED) {
276
+ return virtualizedApplies;
277
+ }
278
+ return spot.kind === BlindSpotKind.CLOSED_SHADOW_ROOT;
279
+ });
280
+ if (0 === relevant.length) {
242
281
  return undefined;
282
+ }
243
283
  const statement = buildCoverageStatement(relevant);
244
284
  return `the absence assertion targeted a region Reticle could not observe (${statement.note ?? 'partial coverage'}), so a passing DOM check cannot prove absence`;
245
285
  }
@@ -274,8 +314,12 @@ export function isStateUnwatched(spots) {
274
314
  * window would make `unknown` the answer to everything, which this repo has already paid for once.
275
315
  */
276
316
  export function restsOnCompleteWindow(predicate) {
277
- if (PredicateKind.NOT === predicate.kind)
317
+ if (PredicateKind.NOT === predicate.kind) {
318
+ return true;
319
+ }
320
+ if (PredicateKind.SETTLED === predicate.kind) {
278
321
  return true;
322
+ }
279
323
  // An exact cardinality of ZERO is the third spelling of an absence claim, and reading only
280
324
  // `absent` missed it: `{ kind: "net", urlContains: "/api/auth/sign-in", count: 0 }` says "this
281
325
  // request was never made", and the call the buffer evicted is precisely the disproof. It was
@@ -285,7 +329,69 @@ export function restsOnCompleteWindow(predicate) {
285
329
  // Only zero. `count: 2` asserts calls were MADE and found them; events aged out elsewhere in the
286
330
  // buffer do not unmake a positive finding, which is the same reason a plain presence assertion is
287
331
  // left alone here.
288
- if (0 === predicate.count)
332
+ if (0 === predicate.count) {
289
333
  return true;
334
+ }
290
335
  return true === predicate.absent;
291
336
  }
337
+ const EVENT_HISTORY_CHANNELS = new Set([
338
+ ChannelId.NET,
339
+ ChannelId.SIGNAL,
340
+ ChannelId.LOG,
341
+ ]);
342
+ /**
343
+ * For a failing assertion whose buffer lost events: does the failure rest on a clause that reads
344
+ * event history?
345
+ *
346
+ * An `allOf` that failed could have failed on ANY child. A child whose evidence IS present in
347
+ * the window passed; only a child whose evidence is ABSENT could have failed, and if that child
348
+ * reads event history the failure might be the buffer's fault. Checking the window events against
349
+ * each event-history child is what tells `allOf[{net /a}, {element Submit}]` apart from
350
+ * `allOf[{net /a}, {element Submit}]` where the request is present and only the button is missing.
351
+ */
352
+ export function failingClauseReadsLostChannel(predicate, windowEvents) {
353
+ if (PredicateKind.ALL_OF !== predicate.kind || 0 === predicate.predicates.length) {
354
+ return channelsReadBy(predicate).some((ch) => EVENT_HISTORY_CHANNELS.has(ch));
355
+ }
356
+ for (const child of predicate.predicates) {
357
+ if (!channelsReadBy(child).some((ch) => EVENT_HISTORY_CHANNELS.has(ch))) {
358
+ continue;
359
+ }
360
+ if (!childEvidencePresent(child, windowEvents)) {
361
+ return true;
362
+ }
363
+ }
364
+ return false;
365
+ }
366
+ function childEvidencePresent(child, events) {
367
+ if (PredicateKind.NET === child.kind) {
368
+ const url = child.urlContains;
369
+ if (url === undefined || 0 === url.length) {
370
+ return false;
371
+ }
372
+ return events.some((e) => EventType.NET_REQUEST === e.type &&
373
+ 'string' === typeof e.data['url'] &&
374
+ e.data['url'].includes(url));
375
+ }
376
+ if (PredicateKind.SIGNAL === child.kind) {
377
+ const name = child.name;
378
+ if (name === undefined) {
379
+ return false;
380
+ }
381
+ return events.some((e) => EventType.SIGNAL === e.type && asString(e.data['name']) === name);
382
+ }
383
+ if (PredicateKind.CONSOLE === child.kind) {
384
+ return events.some((e) => 'string' === typeof e.type && e.type.startsWith('console.'));
385
+ }
386
+ return false;
387
+ }
388
+ /** The coverage-line spot for a window where `readStateRender` abstained for a canvas, else none. */
389
+ export function canvasPaintSpots(events, options) {
390
+ if (StateRender.CANVAS_UNOBSERVED !== readStateRender(events, options)) {
391
+ return [];
392
+ }
393
+ const canvases = new Set(events
394
+ .filter((e) => EventType.CANVAS_DIGEST === e.type && false !== e.data['visible'])
395
+ .map((e) => e.ref ?? ''));
396
+ return [{ kind: BlindSpotKind.CANVAS_PAINT_UNOBSERVED, count: canvases.size }];
397
+ }
@@ -57,4 +57,9 @@ scope?: {
57
57
  * rule `act_and_wait` applies to its `until`. Omitted when the step declared nothing.
58
58
  */
59
59
  declared?: readonly Predicate[];
60
+ /**
61
+ * Events from before this step. Only the read-server-fault rule reads them, to leave alone a
62
+ * background read that already failed the same way. Omitted when the caller has none.
63
+ */
64
+ before?: readonly ReticleEvent[];
60
65
  }): StepEffect;
@@ -24,8 +24,9 @@ export function stepEffect(events, window,
24
24
  /** The page under test, so a third-party write is not graded as the app ignoring a response. */
25
25
  scope = {}) {
26
26
  const effect = {};
27
- if (window.until > window.since)
27
+ if (window.until > window.since) {
28
28
  effect.window = { since: window.since, until: window.until };
29
+ }
29
30
  effect.digest = summarizeReaction(buildReactionReport([...events], window.until - window.since));
30
31
  // `actionSince` is what tells the detectors which window belongs to THIS action. Without it the
31
32
  // headline rule cannot attribute a failed request to the click that moved the screen, and the
@@ -35,9 +36,11 @@ scope = {}) {
35
36
  ...(scope.appOrigin === undefined ? {} : { appOrigin: scope.appOrigin }),
36
37
  ...(scope.background === undefined ? {} : { background: scope.background }),
37
38
  ...declaredOptions(scope.declared),
39
+ ...(scope.before === undefined ? {} : { failedReadsBefore: scope.before }),
38
40
  });
39
- if (contradictions.length > 0)
41
+ if (contradictions.length > 0) {
40
42
  effect.contradictions = contradictions;
43
+ }
41
44
  return effect;
42
45
  }
43
46
  /** The contradiction options a step's own expectations give, merged over every one it declared. */
@@ -1,6 +1,8 @@
1
1
  import { ChannelId, Verified, VerifiedReason } from '@reticlehq/core';
2
2
  import { type HonestyBlock } from './honesty.js';
3
3
  import { type UnsettledWindow } from './unsettled.js';
4
+ import { type DeclinedDialog } from '../window/event-filters.js';
5
+ import type { ReticleEvent } from '@reticlehq/core';
4
6
  interface VerifiedInputs {
5
7
  /**
6
8
  * The page SDK and daemon wire mismatch, when the handshake found one. Absent means they agree.
@@ -64,6 +66,7 @@ interface VerifiedInputs {
64
66
  /** Cross-channel disagreements found in the action's window. */
65
67
  contradictions?: readonly {
66
68
  kind: string;
69
+ detail?: string;
67
70
  }[];
68
71
  /** Did a real frame flush before the wait gave up? */
69
72
  settled?: boolean;
@@ -93,6 +96,17 @@ interface VerifiedInputs {
93
96
  * ending is a statement about the clock, not about the network (#669).
94
97
  */
95
98
  namedRequestInFlight?: boolean;
99
+ /**
100
+ * The buffer evicted evidence a failing clause needed (#1231). Only set when a child that reads
101
+ * event history has no matching event left in the window, so the failure may be the buffer's
102
+ * fault rather than the app's.
103
+ */
104
+ bufferLostEvidence?: boolean;
105
+ /**
106
+ * A `confirm` or `prompt` that Reticle declined during this window (see `declinedDialogIn`). Only
107
+ * a failing verdict reads it: the app took the path for "no" because Reticle answered "no".
108
+ */
109
+ declinedDialog?: DeclinedDialog;
96
110
  /**
97
111
  * Writes in this window that answered `202 Accepted`, as "METHOD url" — the server took the
98
112
  * request and has NOT finished processing it.
@@ -170,5 +184,14 @@ interface VerifiedVerdict {
170
184
  * asserted nothing real — and the feedback invite has to tell it from "Reticle could not tell".
171
185
  */
172
186
  export declare const VACUOUS_BECAUSE = "nothing was asserted at a real grade, so passing proves nothing \u2014 assert a signal, request, or state path";
187
+ /**
188
+ * The sentence for an assertion that nobody could evaluate, with what was missing. Exported so a
189
+ * plan of steps names the missing evidence in the same words as one action (#2204).
190
+ */
191
+ export declare const couldNotEvaluate: (missing: string) => string;
192
+ /** The `declinedDialog` input for a window, or nothing. Shared so both verdict paths read it alike. */
193
+ export declare function withDeclinedDialog(events: readonly ReticleEvent[]): {
194
+ declinedDialog?: DeclinedDialog;
195
+ };
173
196
  export declare function decideVerified(inputs: VerifiedInputs): VerifiedVerdict;
174
197
  export {};
@@ -3,6 +3,8 @@ import { ChannelId, ContradictionKind, MUTATING_METHODS, Verified, VerifiedReaso
3
3
  import { HonestyGrade } from './honesty.js';
4
4
  import { unsettledBecause } from './unsettled.js';
5
5
  import { pageTornDownWhileOn } from './page-teardown.js';
6
+ import { declinedDialogIn } from '../window/event-filters.js';
7
+ import { clipBody } from '../question/predicate/predicate-eval-kit.js';
6
8
  /**
7
9
  * The decision rule: eight trust dimensions in, one answer out.
8
10
  *
@@ -24,8 +26,9 @@ import { pageTornDownWhileOn } from './page-teardown.js';
24
26
  */
25
27
  function undeclaredChannels(inputs) {
26
28
  const observable = inputs.channelsObservable;
27
- if (observable === undefined)
29
+ if (observable === undefined) {
28
30
  return [];
31
+ }
29
32
  const needed = inputs.channelsRead ?? [];
30
33
  return needed.filter((channel) => !observable.includes(channel));
31
34
  }
@@ -34,8 +37,18 @@ function undeclaredChannels(inputs) {
34
37
  * asserted nothing real — and the feedback invite has to tell it from "Reticle could not tell".
35
38
  */
36
39
  export const VACUOUS_BECAUSE = 'nothing was asserted at a real grade, so passing proves nothing — assert a signal, request, or state path';
40
+ /**
41
+ * The sentence for an assertion that nobody could evaluate, with what was missing. Exported so a
42
+ * plan of steps names the missing evidence in the same words as one action (#2204).
43
+ */
44
+ export const couldNotEvaluate = (missing) => `the assertion could not be evaluated: ${missing}`;
37
45
  /** A `"POST /api/x"` label: is it a write? */
38
46
  const isWriteLabel = (label) => MUTATING_METHODS.includes((label.split(' ')[0] ?? '').toUpperCase());
47
+ /** The `declinedDialog` input for a window, or nothing. Shared so both verdict paths read it alike. */
48
+ export function withDeclinedDialog(events) {
49
+ const declinedDialog = declinedDialogIn(events);
50
+ return declinedDialog === undefined ? {} : { declinedDialog };
51
+ }
39
52
  export function decideVerified(inputs) {
40
53
  const { pass, honesty, contradictions = [], settled, outcomePending, outcomeUnread } = inputs;
41
54
  // Ahead of everything, with `capability-absent` below it and for the same reason: a skewed wire
@@ -76,7 +89,7 @@ export function decideVerified(inputs) {
76
89
  return {
77
90
  verified: Verified.UNKNOWN,
78
91
  verifiedReason: VerifiedReason.INCONCLUSIVE,
79
- because: `the assertion could not be evaluated: ${inputs.inconclusive}`,
92
+ because: couldNotEvaluate(inputs.inconclusive),
80
93
  };
81
94
  }
82
95
  // ABOVE the failure clause, because a wait that ended when the tab vanished did not fail — it was
@@ -98,6 +111,21 @@ export function decideVerified(inputs) {
98
111
  'to repeat',
99
112
  };
100
113
  }
114
+ // ABOVE the failure clause. The app asked a question and Reticle answered "no" so that the tab
115
+ // cannot wedge. A consequence that needed "yes" then did not happen, and that is Reticle's choice,
116
+ // not an app defect. A pass is untouched: the app reached the consequence without the "yes".
117
+ const dialog = inputs.declinedDialog;
118
+ if (false === pass && dialog !== undefined) {
119
+ const asked = dialog.message === undefined ? '' : ` ("${clipBody(dialog.message)}")`;
120
+ return {
121
+ verified: Verified.UNKNOWN,
122
+ verifiedReason: VerifiedReason.DIALOG_DECLINED,
123
+ because: `the app opened a ${dialog.kind} dialog${asked} during this action, and Reticle declined ` +
124
+ 'it so that the tab cannot wedge. The app took the path for "no", so the clause that ' +
125
+ 'needed the answer "yes" was not judged. Assert what the app does on "no", or drive the ' +
126
+ 'accepted path another way',
127
+ };
128
+ }
101
129
  // ABOVE the failure clause, for the third time and the same reason: absence is not evidence.
102
130
  //
103
131
  // Omitting `until` waits for the page to SETTLE. Nobody declared a consequence, so a settle that
@@ -176,6 +204,17 @@ export function decideVerified(inputs) {
176
204
  'processing it — this window cannot contain the outcome; re-check that call once it reconciles',
177
205
  };
178
206
  }
207
+ // The buffer evicted evidence a failing clause needed. The failure may be the buffer's fault,
208
+ // not the app's, so the honest answer is unknown (#1231). Only fires when the caller proved
209
+ // that a specific event-history child has no evidence left in the window.
210
+ if (false === pass && true === inputs.bufferLostEvidence) {
211
+ return {
212
+ verified: Verified.UNKNOWN,
213
+ verifiedReason: VerifiedReason.UNCLEAN_CAPTURE,
214
+ because: 'the buffer evicted events this assertion needed, so the failure may be the ' +
215
+ "buffer's, not the app's — re-check once the window is complete",
216
+ };
217
+ }
179
218
  // A failed assertion is the most actionable fact there is; it leads — including over
180
219
  // `alreadyTrue`, because a condition that held before AND fails now is a real regression.
181
220
  if (false === pass) {
@@ -226,6 +265,18 @@ export function decideVerified(inputs) {
226
265
  // catch, and its outcome genuinely does not exist yet. A poll or a prefetch left hanging says
227
266
  // nothing about the action; an unfinished mutation says the answer is not in yet. Read off the
228
267
  // labels the window already carries — and when there are no labels to read, nothing is softened.
268
+ // A failed read gets its own sentence, and it names each request: the generic one below blames a
269
+ // window that closed early, and a 500 is not a timing fact. Ahead of the other absence clauses,
270
+ // because a server fault is the most actionable fact among them.
271
+ const failedReads = deciding.filter((c) => c.kind === ContradictionKind.READ_SERVER_FAULT);
272
+ if (failedReads.length > 0) {
273
+ return {
274
+ verified: Verified.UNKNOWN,
275
+ verifiedReason: VerifiedReason.EVIDENCE_INCOMPLETE,
276
+ because: `the assertion held, but a read of the app's own failed with a server error in this window (${failedReads.map((c) => c.detail ?? c.kind).join('; ')}), ` +
277
+ 'so the page can show stale or placeholder content that still matches. Read the response with reticle_observe, fix the server fault, then verify again',
278
+ };
279
+ }
229
280
  const openWrite = (inputs.unsettled?.stillInFlight ?? []).some(isWriteLabel);
230
281
  const settlementOnly = declaredHeld &&
231
282
  inputs.unsettled !== undefined &&