@reticlehq/engine 3.7.0 → 3.8.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 (42) hide show
  1. package/dist/disagreement/contradiction-evidence.d.ts +70 -3
  2. package/dist/disagreement/contradiction-evidence.js +156 -7
  3. package/dist/disagreement/contradiction-types.d.ts +8 -0
  4. package/dist/disagreement/contradictions.js +21 -16
  5. package/dist/disagreement/stale-response.js +54 -15
  6. package/dist/evidence/baseline.js +1 -1
  7. package/dist/evidence/body-capture-remedy.d.ts +1 -15
  8. package/dist/evidence/body-capture-remedy.js +9 -2
  9. package/dist/evidence/step-effect.d.ts +20 -1
  10. package/dist/evidence/step-effect.js +30 -2
  11. package/dist/evidence/uncaptured-bodies.d.ts +18 -1
  12. package/dist/evidence/uncaptured-bodies.js +22 -1
  13. package/dist/evidence/unread-outcome.d.ts +7 -0
  14. package/dist/evidence/unread-outcome.js +22 -0
  15. package/dist/evidence/unsettled.js +25 -0
  16. package/dist/evidence/verified.d.ts +2 -0
  17. package/dist/evidence/verified.js +1 -1
  18. package/dist/exact-count.d.ts +19 -0
  19. package/dist/exact-count.js +25 -0
  20. package/dist/question/predicate/predicate-compare.js +7 -2
  21. package/dist/question/predicate/predicate-console.js +23 -10
  22. package/dist/question/predicate/predicate-element.d.ts +10 -1
  23. package/dist/question/predicate/predicate-element.js +138 -17
  24. package/dist/question/predicate/predicate-eval-kit.d.ts +3 -3
  25. package/dist/question/predicate/predicate-eval-kit.js +3 -7
  26. package/dist/question/predicate/predicate-eval.d.ts +10 -0
  27. package/dist/question/predicate/predicate-eval.js +169 -68
  28. package/dist/question/predicate/predicate-parse.d.ts +1 -1
  29. package/dist/question/predicate/predicate-parse.js +1 -1
  30. package/dist/question/predicate/predicate-request-body.d.ts +13 -0
  31. package/dist/question/predicate/predicate-request-body.js +23 -1
  32. package/dist/question/predicate/predicate-schema.d.ts +1 -1
  33. package/dist/question/predicate/predicate-schema.js +6 -5
  34. package/dist/question/predicate/predicate.js +54 -8
  35. package/dist/question/predicate/split-text-miss.d.ts +1 -0
  36. package/dist/question/predicate/split-text-miss.js +8 -1
  37. package/dist/state-bookkeeping.d.ts +2 -0
  38. package/dist/state-bookkeeping.js +4 -0
  39. package/dist/window/adversary.js +46 -40
  40. package/dist/window/network-detail-merge.d.ts +3 -4
  41. package/dist/window/network-detail-merge.js +43 -13
  42. package/package.json +3 -3
@@ -5,8 +5,8 @@
5
5
  * there rather than invented for the occasion. Everything here answers a question ABOUT NETWORK
6
6
  * EVIDENCE: what did this event mean, was it a write, did a retry rescue it, is it the toolchain's
7
7
  * own traffic rather than the app's, is this cadence a poll, what did a write carry, which page did
8
- * a list request ask for, and which `net` clause would name this call. Nothing here knows what a
9
- * contradiction is.
8
+ * a list request ask for, and which `net` clause would name this call — and whether a settled field
9
+ * reading shows the app wrote the screen forward. Nothing here knows what a contradiction is.
10
10
  *
11
11
  * The rules next door read this vocabulary and decide what disagrees. Keeping the two apart means a
12
12
  * new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
@@ -14,6 +14,8 @@
14
14
  */
15
15
  import { EventType, type ReticleEvent } from '@reticlehq/core';
16
16
  export interface NetCall {
17
+ /** When the call settled, on the session clock. */
18
+ t: number;
17
19
  method: string;
18
20
  url: string;
19
21
  /** Grader haystack — the raw request when redaction rewrote `url`. */
@@ -75,6 +77,27 @@ export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
75
77
  * stay under the blank-destination rule: an event that cannot show the path stayed put is not exempt.
76
78
  */
77
79
  export declare function isSamePathnameReplace(event: ReticleEvent): boolean;
80
+ /**
81
+ * Did this event show a field whose post-handler reading differs from its pre-action one?
82
+ *
83
+ * React writes `checked` and `value` as properties, so a controlled checkbox that re-renders
84
+ * produces no attribute mutation. The field change from the input event itself cannot fill that
85
+ * gap: it is emitted from the user's own event, before a controlled component restores the
86
+ * property, and counting it would treat a box React immediately reverted as rendered.
87
+ *
88
+ * A settled read carries the value from before the action beside the value after the handlers
89
+ * ran. The browser only sends one when the app itself wrote the property during the action, so an
90
+ * uncontrolled field the browser toggled on its own never counts. The screen moved only when the
91
+ * two readings differ.
92
+ */
93
+ export declare function settledFieldRendered(event: ReticleEvent): boolean;
94
+ /**
95
+ * Did this event show the screen moving, for the state-vs-render rule? A DOM node added, removed or
96
+ * changed, route movement (a navigation IS a render), or a field the app itself wrote to a new
97
+ * value (`settledFieldRendered`). The input event's own field change does not count: that is the
98
+ * keystroke or the browser's own toggle, true of a component that never re-rendered.
99
+ */
100
+ export declare function screenMoved(event: ReticleEvent): boolean;
78
101
  /**
79
102
  * Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
80
103
  *
@@ -186,9 +209,53 @@ export declare function declareFailureHint(calls: readonly {
186
209
  status: number | undefined;
187
210
  }[]): string;
188
211
  export declare function pageNumber(text: unknown): number | undefined;
189
- /** The endpoint and its page parameter, for a GET that carries one. */
212
+ /** The endpoint, page parameter and remaining query, for a GET that carries a page parameter. */
190
213
  export declare function pageRequest(event: ReticleEvent): {
191
214
  path: string;
192
215
  param: string;
193
216
  value: string;
217
+ query: string;
194
218
  } | undefined;
219
+ /**
220
+ * True when the app published no signal and no store change, in the window or before it.
221
+ *
222
+ * Undefined `prior` means the caller did not look before the window, so it cannot say: false. A
223
+ * zero-install page is the common case here. With no voice of its own, the app cannot say whether
224
+ * it handled a failure, so a finding that rests on that is weak rather than proof.
225
+ */
226
+ export declare function appIsSilent(events: readonly ReticleEvent[], prior: readonly ReticleEvent[] | undefined): boolean;
227
+ /**
228
+ * What became of the acted control's own change once its failed request settled.
229
+ *
230
+ * `ui-advanced-request-failed` asks whether the UI moved over a failed write. "Moved" was any DOM,
231
+ * store or route change in the window, and that reads a correct optimistic UI as a lie. Measured on
232
+ * a live incident feed with no SDK signals: acknowledging a row disables its button, POSTs, gets a
233
+ * 500, and enables the button again with a banner. The fixed build and the build that swallows the
234
+ * 500 both got the finding, twice each, because the feed appends a row every 800 ms on its own and
235
+ * the button was disabled while the request was in flight.
236
+ *
237
+ * What separates the two builds is the control's fate AFTER the failure:
238
+ *
239
+ * - REVERTED: every change the action made to the control before the failure is back at its value
240
+ * from before the action. The app handled the failure on the thing the user touched.
241
+ * - PENDING: the control still shows its in-flight value and nothing on it moved after the failure.
242
+ * The request was in flight; the app did not go on as if it succeeded.
243
+ * - PERSISTED: the control moved on after the failure. The app went on as if it succeeded.
244
+ *
245
+ * Undefined when this cannot be told: no ref was acted on, or the control did not change before the
246
+ * failure settled. The caller then keeps the old window-wide reading.
247
+ *
248
+ * Only the control's own changes count, so rows the action did not touch (a live feed, a clock)
249
+ * decide nothing.
250
+ *
251
+ * ponytail: the control alone decides. A control rolled back while an unrelated element keeps a
252
+ * change (an item added to a list as its button re-enables) reads as handled. Telling that apart
253
+ * needs the DOM ancestry of each event, which the wire does not carry.
254
+ */
255
+ export declare const TargetFate: {
256
+ readonly PERSISTED: "persisted";
257
+ readonly REVERTED: "reverted";
258
+ readonly PENDING: "pending";
259
+ };
260
+ export type TargetFate = (typeof TargetFate)[keyof typeof TargetFate];
261
+ export declare function targetFate(events: readonly ReticleEvent[], ref: string | undefined, failedAt: number): TargetFate | undefined;
@@ -5,17 +5,19 @@
5
5
  * there rather than invented for the occasion. Everything here answers a question ABOUT NETWORK
6
6
  * EVIDENCE: what did this event mean, was it a write, did a retry rescue it, is it the toolchain's
7
7
  * own traffic rather than the app's, is this cadence a poll, what did a write carry, which page did
8
- * a list request ask for, and which `net` clause would name this call. Nothing here knows what a
9
- * contradiction is.
8
+ * a list request ask for, and which `net` clause would name this call — and whether a settled field
9
+ * reading shows the app wrote the screen forward. Nothing here knows what a contradiction is.
10
10
  *
11
11
  * The rules next door read this vocabulary and decide what disagrees. Keeping the two apart means a
12
12
  * new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
13
13
  * rules end up disagreeing about the same window.
14
14
  */
15
- import { EventType, MUTATING_METHODS, NEXT_ACTION_FIELD, PredicateKind, REQUEST_SHAPE_FIELD, ROUTE_CHANGE_HOW_FIELD, RouteChangeHow, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
15
+ import { EventType, FieldChangeField, FieldChangeKind, MUTATING_METHODS, NEXT_ACTION_FIELD, PredicateKind, REQUEST_SHAPE_FIELD, ROUTE_CHANGE_HOW_FIELD, RouteChangeHow, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
16
+ import { isReticleVoice } from '../state-bookkeeping.js';
16
17
  export function netCall(e) {
17
18
  const status = asNumber(e.data['status']);
18
19
  return {
20
+ t: e.t,
19
21
  method: (asString(e.data['method']) ?? '').toUpperCase(),
20
22
  url: asString(e.data['url']) ?? '',
21
23
  matchUrl: urlForMatch(e.data),
@@ -137,6 +139,47 @@ export function isSamePathnameReplace(event) {
137
139
  return false;
138
140
  return true;
139
141
  }
142
+ /**
143
+ * Did this event show a field whose post-handler reading differs from its pre-action one?
144
+ *
145
+ * React writes `checked` and `value` as properties, so a controlled checkbox that re-renders
146
+ * produces no attribute mutation. The field change from the input event itself cannot fill that
147
+ * gap: it is emitted from the user's own event, before a controlled component restores the
148
+ * property, and counting it would treat a box React immediately reverted as rendered.
149
+ *
150
+ * A settled read carries the value from before the action beside the value after the handlers
151
+ * ran. The browser only sends one when the app itself wrote the property during the action, so an
152
+ * uncontrolled field the browser toggled on its own never counts. The screen moved only when the
153
+ * two readings differ.
154
+ */
155
+ export function settledFieldRendered(event) {
156
+ if (event.type !== EventType.FIELD_CHANGE)
157
+ return false;
158
+ if (event.data[FieldChangeField.KIND] !== FieldChangeKind.SETTLED)
159
+ return false;
160
+ const checked = event.data[FieldChangeField.CHECKED];
161
+ const previousChecked = event.data[FieldChangeField.PREVIOUS_CHECKED];
162
+ if ('boolean' === typeof checked && 'boolean' === typeof previousChecked) {
163
+ return checked !== previousChecked;
164
+ }
165
+ const value = event.data[FieldChangeField.VALUE];
166
+ const previous = event.data[FieldChangeField.PREVIOUS];
167
+ return 'string' === typeof value && 'string' === typeof previous && value !== previous;
168
+ }
169
+ /**
170
+ * Did this event show the screen moving, for the state-vs-render rule? A DOM node added, removed or
171
+ * changed, route movement (a navigation IS a render), or a field the app itself wrote to a new
172
+ * value (`settledFieldRendered`). The input event's own field change does not count: that is the
173
+ * keystroke or the browser's own toggle, true of a component that never re-rendered.
174
+ */
175
+ export function screenMoved(event) {
176
+ return (event.type === EventType.DOM_ADDED ||
177
+ event.type === EventType.DOM_REMOVED ||
178
+ event.type === EventType.DOM_ATTR ||
179
+ event.type === EventType.DOM_TEXT ||
180
+ event.type === EventType.ROUTE_CHANGE ||
181
+ settledFieldRendered(event));
182
+ }
140
183
  /**
141
184
  * Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
142
185
  *
@@ -308,15 +351,18 @@ function narrowPathOf(call) {
308
351
  /** Query parameters that say which page of a list is being asked for. */
309
352
  const PAGE_PARAMS = ['page', 'offset', 'cursor', 'after', 'start', 'skip', 'from'];
310
353
  /** "Page 2", "page 2 of 6", "2 / 6", "2 of 6". */
311
- const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+\b/i;
354
+ const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+(?:,\d{3})*\b/i;
355
+ const RECORD_RANGE_LABEL = /\b\d[\d,]*\s*(?:[-–—]|\bto\b)\s*\d[\d,]*\s+of\s+\d[\d,]*\b|\b\d[\d,]*\s+of\s+\d[\d,]*\s+(?:records|items|results)\b/i;
312
356
  export function pageNumber(text) {
313
357
  if ('string' !== typeof text)
314
358
  return undefined;
359
+ if (RECORD_RANGE_LABEL.test(text))
360
+ return undefined;
315
361
  const match = PAGE_LABEL.exec(text);
316
362
  const raw = match?.[1] ?? match?.[2];
317
363
  return raw === undefined ? undefined : Number(raw);
318
364
  }
319
- /** The endpoint and its page parameter, for a GET that carries one. */
365
+ /** The endpoint, page parameter and remaining query, for a GET that carries a page parameter. */
320
366
  export function pageRequest(event) {
321
367
  if (event.type !== EventType.NET_REQUEST)
322
368
  return undefined;
@@ -335,8 +381,111 @@ export function pageRequest(event) {
335
381
  }
336
382
  for (const param of PAGE_PARAMS) {
337
383
  const value = url.searchParams.get(param);
338
- if (value !== null)
339
- return { path: url.pathname, param, value };
384
+ if (value !== null) {
385
+ url.searchParams.delete(param);
386
+ // jQuery `cache: false` changes `_` on every otherwise identical GET.
387
+ url.searchParams.delete('_');
388
+ url.searchParams.sort();
389
+ return { path: url.pathname, param, value, query: url.searchParams.toString() };
390
+ }
340
391
  }
341
392
  return undefined;
342
393
  }
394
+ /**
395
+ * True when the app published no signal and no store change, in the window or before it.
396
+ *
397
+ * Undefined `prior` means the caller did not look before the window, so it cannot say: false. A
398
+ * zero-install page is the common case here. With no voice of its own, the app cannot say whether
399
+ * it handled a failure, so a finding that rests on that is weak rather than proof.
400
+ */
401
+ export function appIsSilent(events, prior) {
402
+ if (prior === undefined)
403
+ return false;
404
+ const speaks = (e) => {
405
+ if (e.type === EventType.SIGNAL)
406
+ return !isReticleVoice(asString(e.data['name']) ?? '');
407
+ if (e.type !== EventType.STATE_CHANGE)
408
+ return false;
409
+ return !isReticleVoice(asString(e.data['store']) ?? asString(e.data['name']) ?? '');
410
+ };
411
+ return !prior.some(speaks) && !events.some(speaks);
412
+ }
413
+ /**
414
+ * What became of the acted control's own change once its failed request settled.
415
+ *
416
+ * `ui-advanced-request-failed` asks whether the UI moved over a failed write. "Moved" was any DOM,
417
+ * store or route change in the window, and that reads a correct optimistic UI as a lie. Measured on
418
+ * a live incident feed with no SDK signals: acknowledging a row disables its button, POSTs, gets a
419
+ * 500, and enables the button again with a banner. The fixed build and the build that swallows the
420
+ * 500 both got the finding, twice each, because the feed appends a row every 800 ms on its own and
421
+ * the button was disabled while the request was in flight.
422
+ *
423
+ * What separates the two builds is the control's fate AFTER the failure:
424
+ *
425
+ * - REVERTED: every change the action made to the control before the failure is back at its value
426
+ * from before the action. The app handled the failure on the thing the user touched.
427
+ * - PENDING: the control still shows its in-flight value and nothing on it moved after the failure.
428
+ * The request was in flight; the app did not go on as if it succeeded.
429
+ * - PERSISTED: the control moved on after the failure. The app went on as if it succeeded.
430
+ *
431
+ * Undefined when this cannot be told: no ref was acted on, or the control did not change before the
432
+ * failure settled. The caller then keeps the old window-wide reading.
433
+ *
434
+ * Only the control's own changes count, so rows the action did not touch (a live feed, a clock)
435
+ * decide nothing.
436
+ *
437
+ * ponytail: the control alone decides. A control rolled back while an unrelated element keeps a
438
+ * change (an item added to a list as its button re-enables) reads as handled. Telling that apart
439
+ * needs the DOM ancestry of each event, which the wire does not carry.
440
+ */
441
+ export const TargetFate = {
442
+ PERSISTED: 'persisted',
443
+ REVERTED: 'reverted',
444
+ PENDING: 'pending',
445
+ };
446
+ /** A value the control did not have: an absent attribute, or no text. */
447
+ const ABSENT = '\u0000absent';
448
+ /** The attribute or text change this event made to `ref`, or undefined. No-op writes are skipped. */
449
+ function changeOf(event, ref) {
450
+ if (event.ref !== ref)
451
+ return undefined;
452
+ let key;
453
+ let now;
454
+ if (event.type === EventType.DOM_ATTR) {
455
+ key = `attr:${asString(event.data['attr']) ?? ''}`;
456
+ now = asString(event.data['value']) ?? ABSENT;
457
+ }
458
+ else if (event.type === EventType.DOM_TEXT) {
459
+ key = 'text';
460
+ now = asString(event.data['text']) ?? ABSENT;
461
+ }
462
+ else {
463
+ return undefined;
464
+ }
465
+ const old = asString(event.data['old']) ?? ABSENT;
466
+ return old === now ? undefined : { key, t: event.t, old, now };
467
+ }
468
+ export function targetFate(events, ref, failedAt) {
469
+ if (ref === undefined)
470
+ return undefined;
471
+ const before = new Map();
472
+ const atFailure = new Map();
473
+ const last = new Map();
474
+ for (const event of events) {
475
+ const change = changeOf(event, ref);
476
+ if (change === undefined)
477
+ continue;
478
+ if (!before.has(change.key))
479
+ before.set(change.key, change.old);
480
+ if (change.t <= failedAt)
481
+ atFailure.set(change.key, change.now);
482
+ last.set(change.key, change.now);
483
+ }
484
+ if (0 === atFailure.size)
485
+ return undefined;
486
+ const reverted = [...last].every(([key, value]) => before.get(key) === value);
487
+ if (reverted)
488
+ return TargetFate.REVERTED;
489
+ const movedAfter = [...last].some(([key, value]) => (atFailure.get(key) ?? before.get(key)) !== value);
490
+ return movedAfter ? TargetFate.PERSISTED : TargetFate.PENDING;
491
+ }
@@ -29,6 +29,14 @@ export interface ContradictionOptions {
29
29
  note?: NoteFn;
30
30
  /** The action that opened this window, when one did. Enables the no-effect check. */
31
31
  action?: string | undefined;
32
+ /**
33
+ * The ref of the control the action was dispatched on.
34
+ *
35
+ * Lets `ui-advanced-request-failed` read what became of that control after its request failed:
36
+ * rolled back, still pending, or moved on. Undefined keeps the window-wide reading. See
37
+ * `targetFate`.
38
+ */
39
+ ref?: string | undefined;
32
40
  /**
33
41
  * Was the page HIDDEN while this window was recorded? Stated by the caller, which knows.
34
42
  *
@@ -1,6 +1,6 @@
1
1
  import { ContradictionKind, EventType, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
2
2
  import { describeSuperseded } from '../question/predicate/observed-in-window.js';
3
- import { declareFailureHint, describe, groupByIdentity, identityOf, isMutating, isSameDocumentHashAnchor, isSamePathnameReplace, isSteadyCadence, netCall, pageNumber, pageRequest, recoveredByRetry, splitForeignTraffic, } from './contradiction-evidence.js';
3
+ import { declareFailureHint, describe, groupByIdentity, identityOf, isMutating, isSameDocumentHashAnchor, isSamePathnameReplace, isSteadyCadence, appIsSilent, netCall, TargetFate, targetFate, pageNumber, pageRequest, recoveredByRetry, screenMoved, splitForeignTraffic, } from './contradiction-evidence.js';
4
4
  import { findStaleResponses } from './stale-response.js';
5
5
  import { findBodyFailures } from './body-failures.js';
6
6
  import { findEchoMismatches } from './echo-mismatch.js';
@@ -421,12 +421,20 @@ function findWindowContradictions(allEvents, options) {
421
421
  true === advanced &&
422
422
  !misattributed &&
423
423
  !failureAcknowledged(events)) {
424
- found.push({
425
- kind: ContradictionKind.UI_ADVANCED_REQUEST_FAILED,
426
- claim: 'the UI moved forward (DOM/store/route changed)',
427
- counter: `${String(unexpectedWrites.length)} request(s) in the same window failed`,
428
- detail: `${unexpectedWrites.map(describe).join('; ')}${declareFailureHint(unexpectedWrites)}`,
429
- });
424
+ // The acted control's own fate after the failure decides when it can be read. See `targetFate`.
425
+ const failedAt = Math.max(...unexpectedWrites.map((c) => c.t));
426
+ const fate = targetFate(events, options.ref, failedAt);
427
+ if (fate === undefined || fate === TargetFate.PERSISTED) {
428
+ found.push({
429
+ // Undecided by the control, and the app says nothing about its own state: weak, not proof.
430
+ kind: fate === undefined && appIsSilent(events, options.prior)
431
+ ? ContradictionKind.UI_ADVANCED_UNSIGNALLED
432
+ : ContradictionKind.UI_ADVANCED_REQUEST_FAILED,
433
+ claim: 'the UI moved forward (DOM/store/route changed)',
434
+ counter: `${String(unexpectedWrites.length)} request(s) in the same window failed`,
435
+ detail: `${unexpectedWrites.map(describe).join('; ')}${declareFailureHint(unexpectedWrites)}`,
436
+ });
437
+ }
430
438
  }
431
439
  // ── A write succeeded and nothing on the client moved ───────────────────────────────────────
432
440
  // Writes only: a GET that changes nothing is a prefetch; a POST that changes nothing is a lost
@@ -465,7 +473,7 @@ function findWindowContradictions(allEvents, options) {
465
473
  // flight that the render could legitimately be waiting on.
466
474
  //
467
475
  // Route movement counts as the screen moving: a navigation IS a render, and a store change that
468
- // drives one has been corroborated.
476
+ // drives one has been corroborated, and so has a field the app wrote (`screenMoved`).
469
477
  //
470
478
  // And only when the window carries NO NETWORK AT ALL. A request means the app reached for
471
479
  // something, and whether it failed, was ignored or never settled already belongs to three other
@@ -475,16 +483,12 @@ function findWindowContradictions(allEvents, options) {
475
483
  if (options.actionSince !== undefined &&
476
484
  events.some(isMeaningfulStateChange) &&
477
485
  !events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING) &&
478
- !events.some((e) => e.type === EventType.DOM_ADDED ||
479
- e.type === EventType.DOM_REMOVED ||
480
- e.type === EventType.DOM_ATTR ||
481
- e.type === EventType.DOM_TEXT ||
482
- e.type === EventType.ROUTE_CHANGE)) {
486
+ !events.some(screenMoved)) {
483
487
  found.push({
484
488
  kind: ContradictionKind.STATE_VS_RENDER,
485
489
  claim: 'the store committed a change',
486
- counter: 'nothing rendered in the same window — no DOM node added, removed or changed, and no ' +
487
- 'route movement, with no request still in flight the render could be waiting on',
490
+ counter: 'nothing rendered in the same window: no DOM or app-written field change and no route ' +
491
+ 'movement, with no request still in flight the render could be waiting on',
488
492
  detail: 'a component that does not re-render on a committed change shows the OLD value while the ' +
489
493
  'app is internally consistent, which is why nothing else reports it',
490
494
  });
@@ -714,7 +718,8 @@ export function findStalledPagination(events, prior = []) {
714
718
  const previous = last.get(request.path);
715
719
  if (previous !== undefined &&
716
720
  previous.param === request.param &&
717
- previous.value === request.value)
721
+ previous.value === request.value &&
722
+ previous.query === request.query)
718
723
  return [
719
724
  {
720
725
  kind: ContradictionKind.PAGINATION_NOT_FETCHED,
@@ -17,21 +17,48 @@ function queryOf(url) {
17
17
  *
18
18
  * A filter race differs in a SELECTING parameter (`status`, `q`, a date range): the second request
19
19
  * makes the first obsolete, both answer into the same view, and the slower one wins.
20
+ *
21
+ * Held as normalised names (see `normalisedParam`), because one parameter has many spellings. The
22
+ * set once held `pageSize` and `per_page` verbatim, so `page_size` was a selecting parameter, and a
23
+ * page query (`page_size=25`) racing its own count query (`page_size=1`) was reported as stale (#1677).
24
+ * `last` stays out on purpose: `last=7d` is a window, and a window selects.
25
+ *
26
+ * The name alone does not decide it, because the same names carry filters: `first=John` against
27
+ * `first=Jane`, or a date range in `start` and `end`, read as paging while only names were compared.
28
+ * A count or a position pages with whole numbers, and a cursor pages with anything but a date.
20
29
  */
21
- const ENUMERATING_PARAMS = new Set([
30
+ const POSITION_PARAMS = new Set([
22
31
  'page',
32
+ 'pagenumber',
23
33
  'offset',
24
- 'cursor',
34
+ 'skip',
25
35
  'limit',
26
36
  'size',
27
- 'per_page',
28
- 'perPage',
29
- 'pageSize',
30
- 'after',
31
- 'before',
37
+ 'take',
38
+ 'top',
39
+ 'first',
40
+ 'perpage',
41
+ 'pagesize',
32
42
  'start',
33
43
  'end',
34
44
  ]);
45
+ /** Opaque tokens from the previous answer, so any value pages: except a date, which filters. */
46
+ const CURSOR_PARAMS = new Set(['cursor', 'after', 'before']);
47
+ const WHOLE_NUMBER = /^\d+$/;
48
+ /** `2026-01-01`, `2026-01-01T09:00:00Z`. */
49
+ const DATE = /^\d{4}-\d{2}-\d{2}/;
50
+ /** `page_size`, `page-size`, `PageSize`, `page[size]` and `$skip` as `pagesize` … `skip`. */
51
+ const normalisedParam = (key) => key.toLowerCase().replace(/[^a-z0-9]/g, '');
52
+ /** Whether `key` going from one value to the other moves through the collection, not within it. */
53
+ function enumerates(key, one, other) {
54
+ const name = normalisedParam(key);
55
+ if (POSITION_PARAMS.has(name)) {
56
+ return WHOLE_NUMBER.test(one ?? '') && WHOLE_NUMBER.test(other ?? '');
57
+ }
58
+ if (CURSOR_PARAMS.has(name))
59
+ return !DATE.test(one ?? '') && !DATE.test(other ?? '');
60
+ return false;
61
+ }
35
62
  /** Whether the two queries differ ONLY in how much of the same collection they ask for. */
36
63
  function differsOnlyByEnumeration(first, second) {
37
64
  const a = new URLSearchParams(first);
@@ -41,7 +68,7 @@ function differsOnlyByEnumeration(first, second) {
41
68
  for (const key of keys) {
42
69
  if (a.get(key) === b.get(key))
43
70
  continue;
44
- if (!ENUMERATING_PARAMS.has(key))
71
+ if (!enumerates(key, a.get(key), b.get(key)))
45
72
  return false;
46
73
  differed = true;
47
74
  }
@@ -156,23 +183,35 @@ const APPLY_SLACK_MS = 100;
156
183
  * detector that accuses correct code teaches people to ignore it, and it takes the true positives
157
184
  * down with it.
158
185
  */
159
- function appliedAfter(events, settledAt) {
186
+ function appliedAfter(events, loser, all) {
187
+ const { settledAt } = loser;
160
188
  return events.some((event) => {
161
189
  if (event.t < settledAt - APPLY_SLACK_MS || event.t > settledAt + APPLY_WINDOW_MS)
162
190
  return false;
163
- return (event.type === EventType.STATE_CHANGE ||
191
+ const reacts = event.type === EventType.STATE_CHANGE ||
164
192
  event.type === EventType.SIGNAL ||
165
193
  event.type === EventType.DOM_TEXT ||
166
194
  event.type === EventType.DOM_ADDED ||
167
195
  event.type === EventType.DOM_REMOVED ||
168
- event.type === EventType.DOM_ATTR);
196
+ event.type === EventType.DOM_ATTR;
197
+ // A reaction belongs to the completion nearest it. The slack lets a render stamped a moment
198
+ // early count, and so it also took in the NEWER response's own render landing just before the
199
+ // loser: a correct app that dropped the loser was accused (seen intermittently on a bench twin).
200
+ // It also belongs to a request being ISSUED nearer it: an action's own write ("loading", the
201
+ // requested value) lands with its request, and a fast burst of clicks puts the next one a few
202
+ // ms after a slow loser lands (seen 1 run in 2 on a correctly guarded quote desk).
203
+ const own = Math.abs(event.t - settledAt);
204
+ return (reacts &&
205
+ !all.some((f) => f.id !== loser.id &&
206
+ (Math.abs(event.t - f.settledAt) < own || Math.abs(event.t - f.issuedAt) < own)));
169
207
  });
170
208
  }
171
209
  export function findStaleResponses(events) {
172
210
  // Grouped by path first: two reads of DIFFERENT endpoints can never race, and comparing them was
173
211
  // the bulk of the work on any real page, which talks to many endpoints at once.
174
212
  const byPath = new Map();
175
- for (const flight of flights(events)) {
213
+ const all = flights(events);
214
+ for (const flight of all) {
176
215
  if (flight.method !== 'GET')
177
216
  continue;
178
217
  const path = pathOf(flight.url);
@@ -182,13 +221,13 @@ export function findStaleResponses(events) {
182
221
  }
183
222
  for (const group of byPath.values()) {
184
223
  const reads = group.slice(-MAX_FLIGHTS_PER_PATH);
185
- const found = raceIn(reads, events);
224
+ const found = raceIn(reads, events, all);
186
225
  if (found !== undefined)
187
226
  return [found];
188
227
  }
189
228
  return [];
190
229
  }
191
- function raceIn(reads, events) {
230
+ function raceIn(reads, events, all) {
192
231
  for (const first of reads) {
193
232
  for (const second of reads) {
194
233
  if (first.id === second.id)
@@ -207,7 +246,7 @@ function raceIn(reads, events) {
207
246
  continue;
208
247
  // The race happened. Whether it MATTERS is whether the app acted on the loser — an app that
209
248
  // drops superseded responses races just as visibly and is not broken.
210
- if (!appliedAfter(events, first.settledAt))
249
+ if (!appliedAfter(events, first, all))
211
250
  continue;
212
251
  return {
213
252
  kind: ContradictionKind.STALE_RESPONSE_APPLIED,
@@ -73,7 +73,7 @@ async function readStateValue(session, predicate) {
73
73
  return 'boolean' === typeof reply.found ? { taken: true, value: reply.value } : undefined;
74
74
  }
75
75
  async function readText(session, predicate) {
76
- const query = textPredicateQuery(predicate);
76
+ const query = textPredicateQuery(predicate, session.sdkVersion);
77
77
  const match = await session.command(ReticleCommand.MATCH, { query });
78
78
  if (!match.ok)
79
79
  return undefined;
@@ -1,17 +1,3 @@
1
- /**
2
- * What to tell a caller whose assertion needs response bodies, given what the connected SDK can do.
3
- *
4
- * The remedy used to be one fixed sentence naming `captureNetworkBodies`. Reported from the field:
5
- * six verdicts came back `unknown`/`outcome_unread` advising that setting against a pinned
6
- * `@reticlehq/react` from before it existed. The reporter set the env var, restarted, got the
7
- * identical message, and worked it out by elimination.
8
- *
9
- * The daemon is TOLD the page's SDK version at HELLO and threw it away after computing skew. Nothing
10
- * new has to be observed to say the true thing — it only has to be kept.
11
- *
12
- * Same class as the version-skew remedy that named a React package on Vue projects: remedy text that
13
- * does not check whether it applies. A wrong remedy is worse than none, because it is followed.
14
- */
15
1
  /** The earliest SDK release whose observer can capture network bodies at all. */
16
2
  export declare const BODY_CAPTURE_MIN_VERSION = "2.4.0";
17
3
  /**
@@ -21,7 +7,7 @@ export declare const BODY_CAPTURE_MIN_VERSION = "2.4.0";
21
7
  * old" there would hide a working fix from someone who could have used it; the opposite guess costs
22
8
  * one wasted read. The asymmetry decides it.
23
9
  */
24
- export declare function bodyCaptureRemedy(sdkVersion: string | undefined): string;
10
+ export declare function bodyCaptureRemedy(sdkVersion: string | undefined, skipReason?: unknown): string;
25
11
  /**
26
12
  * The invariant opening of the refusal below, named so the error envelope can recognise it.
27
13
  *
@@ -12,6 +12,8 @@
12
12
  * Same class as the version-skew remedy that named a React package on Vue projects: remedy text that
13
13
  * does not check whether it applies. A wrong remedy is worse than none, because it is followed.
14
14
  */
15
+ import { skippedBodyRemedy } from '../question/predicate/predicate-eval.js';
16
+ import { BODY_CAPTURE_DEFAULTS } from '../question/predicate/predicate-request-body.js';
15
17
  /** The earliest SDK release whose observer can capture network bodies at all. */
16
18
  export const BODY_CAPTURE_MIN_VERSION = '2.4.0';
17
19
  /**
@@ -38,7 +40,8 @@ function isAtLeast(version, minimum) {
38
40
  return true;
39
41
  }
40
42
  /** The sentence naming the setting — only ever produced for an SDK that HAS it. */
41
- const ENABLE_IT = 'Turn it on where your app calls connect(): `reticle.connect({ captureNetworkBodies: true })`, ' +
43
+ const ENABLE_IT = `${BODY_CAPTURE_DEFAULTS} ` +
44
+ 'Turn it on where your app calls connect(): `reticle.connect({ captureNetworkBodies: true })`, ' +
42
45
  'or for the Vite plugin `reticle({ captureNetworkBodies: true })` / VITE_RETICLE_CAPTURE_BODIES=1. ' +
43
46
  'Before bodies are kept, built-in rules redact keys such as `password`, `apiKey` and ' +
44
47
  '`authorization`, selected token keys, and known secret shapes. Other credential fields may ' +
@@ -51,7 +54,11 @@ const ENABLE_IT = 'Turn it on where your app calls connect(): `reticle.connect({
51
54
  * old" there would hide a working fix from someone who could have used it; the opposite guess costs
52
55
  * one wasted read. The asymmetry decides it.
53
56
  */
54
- export function bodyCaptureRemedy(sdkVersion) {
57
+ export function bodyCaptureRemedy(sdkVersion, skipReason) {
58
+ // Capture is ON and the SDK skipped this body on purpose: switching it on changes nothing (#1520).
59
+ const skipped = skippedBodyRemedy(skipReason);
60
+ if (skipped !== undefined)
61
+ return skipped;
55
62
  if (sdkVersion !== undefined && !isAtLeast(sdkVersion, BODY_CAPTURE_MIN_VERSION)) {
56
63
  return (`this page's SDK is ${sdkVersion}, and body capture needs ${BODY_CAPTURE_MIN_VERSION} or ` +
57
64
  'newer — the setting does not exist in your version, so there is nothing to switch on. ' +
@@ -11,6 +11,7 @@
11
11
  * live path and the replay path share it instead of agreeing by coincidence.
12
12
  */
13
13
  import type { Contradiction, ReactionDigest, ReticleEvent } from '@reticlehq/core';
14
+ import type { Predicate } from '../question/predicate/predicate-eval.js';
14
15
  /** The cursor pair an observer can re-read this step's evidence with. */
15
16
  export interface StepWindow {
16
17
  since: number;
@@ -38,4 +39,22 @@ export interface StepEffect {
38
39
  */
39
40
  contradictions?: Contradiction[];
40
41
  }
41
- export declare function stepEffect(events: readonly ReticleEvent[], window: StepWindow): StepEffect;
42
+ /** The page origin and declared background, omitted when the caller cannot say. Absence fails open. */
43
+ export declare function appScope(session: {
44
+ url?: string;
45
+ background?: readonly string[];
46
+ }): {
47
+ appOrigin?: string;
48
+ background?: readonly string[];
49
+ };
50
+ export declare function stepEffect(events: readonly ReticleEvent[], window: StepWindow,
51
+ /** The page under test, so a third-party write is not graded as the app ignoring a response. */
52
+ scope?: {
53
+ appOrigin?: string;
54
+ background?: readonly string[];
55
+ /**
56
+ * What the step said it would cause. A failure it declared is not a contradiction, the same
57
+ * rule `act_and_wait` applies to its `until`. Omitted when the step declared nothing.
58
+ */
59
+ declared?: readonly Predicate[];
60
+ }): StepEffect;