@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.
- package/dist/disagreement/body-failures.js +16 -2
- package/dist/disagreement/contradiction-evidence.d.ts +119 -0
- package/dist/disagreement/contradiction-evidence.js +360 -48
- package/dist/disagreement/contradiction-types.d.ts +25 -0
- package/dist/disagreement/contradictions.d.ts +17 -1
- package/dist/disagreement/contradictions.js +146 -78
- package/dist/disagreement/echo-mismatch.js +205 -32
- package/dist/disagreement/stale-response.d.ts +10 -1
- package/dist/disagreement/stale-response.js +122 -47
- package/dist/evidence/already-true.d.ts +1 -1
- package/dist/evidence/already-true.js +13 -7
- package/dist/evidence/baseline.d.ts +1 -0
- package/dist/evidence/baseline.js +27 -16
- package/dist/evidence/blind-spots.d.ts +20 -3
- package/dist/evidence/blind-spots.js +127 -21
- package/dist/evidence/step-effect.d.ts +5 -0
- package/dist/evidence/step-effect.js +5 -2
- package/dist/evidence/verified.d.ts +23 -0
- package/dist/evidence/verified.js +53 -2
- package/dist/question/declared.d.ts +27 -0
- package/dist/question/declared.js +64 -13
- package/dist/question/predicate/net-blind-spots.d.ts +37 -1
- package/dist/question/predicate/net-blind-spots.js +72 -1
- package/dist/question/predicate/predicate-animation.d.ts +52 -0
- package/dist/question/predicate/predicate-animation.js +258 -0
- package/dist/question/predicate/predicate-element.d.ts +5 -2
- package/dist/question/predicate/predicate-element.js +103 -33
- package/dist/question/predicate/predicate-eval-kit.d.ts +2 -0
- package/dist/question/predicate/predicate-eval-kit.js +19 -0
- package/dist/question/predicate/predicate-eval.d.ts +1 -4
- package/dist/question/predicate/predicate-eval.js +38 -46
- package/dist/question/predicate/predicate-route.js +81 -27
- package/dist/question/predicate/predicate-schema.js +11 -2
- package/dist/question/predicate/predicate.js +79 -40
- package/dist/question/predicate/truncated-body-advice.d.ts +5 -0
- package/dist/question/predicate/truncated-body-advice.js +25 -0
- package/dist/state-bookkeeping.d.ts +24 -0
- package/dist/state-bookkeeping.js +31 -0
- package/dist/window/event-filters.d.ts +64 -0
- package/dist/window/event-filters.js +149 -20
- package/dist/window/network-detail-merge.d.ts +6 -0
- package/dist/window/network-detail-merge.js +43 -2
- package/package.json +2 -2
|
@@ -12,8 +12,9 @@
|
|
|
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, 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';
|
|
15
|
+
import { CanvasTrigger, DepartedNetField, 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, tiedReaction } from '../state-bookkeeping.js';
|
|
17
|
+
import { matchesDeclaredFailure } from '../question/declared.js';
|
|
17
18
|
export function netCall(e) {
|
|
18
19
|
const status = asNumber(e.data['status']);
|
|
19
20
|
return {
|
|
@@ -27,6 +28,7 @@ export function netCall(e) {
|
|
|
27
28
|
ok: e.data['ok'] === undefined && status === undefined
|
|
28
29
|
? undefined
|
|
29
30
|
: true === e.data['ok'] || (e.data['ok'] === undefined && (status ?? 0) < 400),
|
|
31
|
+
...(true === e.data[DepartedNetField.FROM_DEPARTED_DOCUMENT] ? { departed: true } : {}),
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -41,12 +43,14 @@ export function recoveredByRetry(settled) {
|
|
|
41
43
|
const out = new Set();
|
|
42
44
|
for (let i = 0; i < settled.length; i += 1) {
|
|
43
45
|
const call = settled[i];
|
|
44
|
-
if (call === undefined || false !== call.ok)
|
|
46
|
+
if (call === undefined || false !== call.ok) {
|
|
45
47
|
continue;
|
|
48
|
+
}
|
|
46
49
|
for (let j = i + 1; j < settled.length; j += 1) {
|
|
47
50
|
const later = settled[j];
|
|
48
|
-
if (later === undefined)
|
|
51
|
+
if (later === undefined) {
|
|
49
52
|
continue;
|
|
53
|
+
}
|
|
50
54
|
if (true === later.ok && later.method === call.method && later.matchUrl === call.matchUrl) {
|
|
51
55
|
out.add(call);
|
|
52
56
|
break;
|
|
@@ -83,14 +87,16 @@ export const NET_TYPES = new Set([
|
|
|
83
87
|
* does not (`#main-content`, `#`, empty). The blank-destination rule must still see the former.
|
|
84
88
|
*/
|
|
85
89
|
export function isInPageFragment(hash) {
|
|
86
|
-
if ('' === hash || '#' === hash)
|
|
90
|
+
if ('' === hash || '#' === hash) {
|
|
87
91
|
return true;
|
|
92
|
+
}
|
|
88
93
|
const body = hash.startsWith('#') ? hash.slice(1) : hash;
|
|
89
94
|
return !body.startsWith('/') && !body.startsWith('!');
|
|
90
95
|
}
|
|
91
96
|
export function hrefAsUrl(value) {
|
|
92
|
-
if (value === undefined || '' === value)
|
|
97
|
+
if (value === undefined || '' === value) {
|
|
93
98
|
return undefined;
|
|
99
|
+
}
|
|
94
100
|
try {
|
|
95
101
|
return new URL(value);
|
|
96
102
|
}
|
|
@@ -104,17 +110,20 @@ export function hrefAsUrl(value) {
|
|
|
104
110
|
* Returns false when `from`/`to` are missing, so older events without hrefs keep the existing rule.
|
|
105
111
|
*/
|
|
106
112
|
export function isSameDocumentHashAnchor(event) {
|
|
107
|
-
if (event.type !== EventType.ROUTE_CHANGE)
|
|
113
|
+
if (event.type !== EventType.ROUTE_CHANGE) {
|
|
108
114
|
return false;
|
|
115
|
+
}
|
|
109
116
|
const from = hrefAsUrl(asString(event.data['from']));
|
|
110
117
|
const to = hrefAsUrl(asString(event.data['to']));
|
|
111
|
-
if (from === undefined || to === undefined)
|
|
118
|
+
if (from === undefined || to === undefined) {
|
|
112
119
|
return false;
|
|
120
|
+
}
|
|
113
121
|
if (from.origin !== to.origin || from.pathname !== to.pathname || from.search !== to.search) {
|
|
114
122
|
return false;
|
|
115
123
|
}
|
|
116
|
-
if (from.hash === to.hash)
|
|
124
|
+
if (from.hash === to.hash) {
|
|
117
125
|
return false;
|
|
126
|
+
}
|
|
118
127
|
return isInPageFragment(to.hash);
|
|
119
128
|
}
|
|
120
129
|
/**
|
|
@@ -125,18 +134,23 @@ export function isSameDocumentHashAnchor(event) {
|
|
|
125
134
|
* stay under the blank-destination rule: an event that cannot show the path stayed put is not exempt.
|
|
126
135
|
*/
|
|
127
136
|
export function isSamePathnameReplace(event) {
|
|
128
|
-
if (event.type !== EventType.ROUTE_CHANGE)
|
|
137
|
+
if (event.type !== EventType.ROUTE_CHANGE) {
|
|
129
138
|
return false;
|
|
130
|
-
|
|
139
|
+
}
|
|
140
|
+
if (asString(event.data[ROUTE_CHANGE_HOW_FIELD]) !== RouteChangeHow.REPLACE) {
|
|
131
141
|
return false;
|
|
142
|
+
}
|
|
132
143
|
const from = hrefAsUrl(asString(event.data['from']));
|
|
133
144
|
const to = hrefAsUrl(asString(event.data['to']));
|
|
134
|
-
if (from === undefined || to === undefined)
|
|
145
|
+
if (from === undefined || to === undefined) {
|
|
135
146
|
return false;
|
|
136
|
-
|
|
147
|
+
}
|
|
148
|
+
if (from.origin !== to.origin || from.pathname !== to.pathname) {
|
|
137
149
|
return false;
|
|
138
|
-
|
|
150
|
+
}
|
|
151
|
+
if (from.hash !== to.hash && !isInPageFragment(to.hash)) {
|
|
139
152
|
return false;
|
|
153
|
+
}
|
|
140
154
|
return true;
|
|
141
155
|
}
|
|
142
156
|
/**
|
|
@@ -153,10 +167,12 @@ export function isSamePathnameReplace(event) {
|
|
|
153
167
|
* two readings differ.
|
|
154
168
|
*/
|
|
155
169
|
export function settledFieldRendered(event) {
|
|
156
|
-
if (event.type !== EventType.FIELD_CHANGE)
|
|
170
|
+
if (event.type !== EventType.FIELD_CHANGE) {
|
|
157
171
|
return false;
|
|
158
|
-
|
|
172
|
+
}
|
|
173
|
+
if (event.data[FieldChangeField.KIND] !== FieldChangeKind.SETTLED) {
|
|
159
174
|
return false;
|
|
175
|
+
}
|
|
160
176
|
const checked = event.data[FieldChangeField.CHECKED];
|
|
161
177
|
const previousChecked = event.data[FieldChangeField.PREVIOUS_CHECKED];
|
|
162
178
|
if ('boolean' === typeof checked && 'boolean' === typeof previousChecked) {
|
|
@@ -180,6 +196,84 @@ export function screenMoved(event) {
|
|
|
180
196
|
event.type === EventType.ROUTE_CHANGE ||
|
|
181
197
|
settledFieldRendered(event));
|
|
182
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* What the canvases on the page show about a window (#1525). A canvas renders as pixels, so a
|
|
201
|
+
* repaint makes no DOM mutation. The SDK sends a `CANVAS_DIGEST` for each canvas on its poll when the
|
|
202
|
+
* digest changed, and at the end of every act.
|
|
203
|
+
*/
|
|
204
|
+
export const CanvasPaint = {
|
|
205
|
+
/** No digest of a visible canvas in the window. */
|
|
206
|
+
NONE: 'none',
|
|
207
|
+
/** A visible canvas that was steady before the action showed something different: a render. */
|
|
208
|
+
PAINTED: 'painted',
|
|
209
|
+
/**
|
|
210
|
+
* A visible canvas was on screen and no change the action caused was seen. Not proof that it did
|
|
211
|
+
* not paint: the digest is a 16x16 sample, a canvas can paint after the act's own sample was taken,
|
|
212
|
+
* and a canvas that was already changing (a spinner, a live chart) cannot show what the action drew.
|
|
213
|
+
*/
|
|
214
|
+
UNOBSERVED: 'unobserved',
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* How long a canvas must have held its digest before the action for a change to count as the
|
|
218
|
+
* action's render: two of the SDK's 500 ms poll periods. The poll reports only a change, so a canvas
|
|
219
|
+
* that animates reports one every period, and its last change is always closer than this.
|
|
220
|
+
*/
|
|
221
|
+
export const CANVAS_STEADY_MS = 1_000;
|
|
222
|
+
/**
|
|
223
|
+
* How far back a canvas that changed on its own disqualifies it. A dashboard chart, a clock or a
|
|
224
|
+
* ticker refreshes on a timer slower than `CANVAS_STEADY_MS`, so its last change can be seconds old
|
|
225
|
+
* and its next tick can land in the window. A change the poll found, not just after an act, is
|
|
226
|
+
* such a tick. A timer slower than this can still read as the render.
|
|
227
|
+
*/
|
|
228
|
+
export const CANVAS_QUIET_MS = 10_000;
|
|
229
|
+
/**
|
|
230
|
+
* Did a canvas paint in this window, because of the action at `since`?
|
|
231
|
+
*
|
|
232
|
+
* A digest is a paint when it differs from the last digest of the same canvas (from `prior` or from
|
|
233
|
+
* earlier in the window), that canvas held its digest for `CANVAS_STEADY_MS` before the action, and
|
|
234
|
+
* it did not change on its own in the `CANVAS_QUIET_MS` before it. A change on its own is one the
|
|
235
|
+
* SDK's poll found more than `CANVAS_STEADY_MS` after the last act's digest: no act drew it. A
|
|
236
|
+
* canvas with no earlier digest is not a paint: nothing says what it showed before. A digest that
|
|
237
|
+
* says `visible: false` (no size, or outside the viewport) is never the paint, nor a canvas seen in
|
|
238
|
+
* the window: a hidden canvas cannot carry a render the user sees. It still counts as what the canvas
|
|
239
|
+
* showed before, since a click may scroll a canvas into view. An SDK older than the field sends no
|
|
240
|
+
* `visible`, and is read as visible.
|
|
241
|
+
*/
|
|
242
|
+
export function canvasPaint(events, prior, since) {
|
|
243
|
+
const last = new Map();
|
|
244
|
+
let actAt;
|
|
245
|
+
let seen = false;
|
|
246
|
+
for (const [event, inWindow] of [
|
|
247
|
+
...prior.map((e) => [e, false]),
|
|
248
|
+
...events.map((e) => [e, true]),
|
|
249
|
+
]) {
|
|
250
|
+
const digest = EventType.CANVAS_DIGEST === event.type ? asString(event.data['digest']) : undefined;
|
|
251
|
+
if (digest === undefined) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const polled = CanvasTrigger.POLL === event.data['trigger'];
|
|
255
|
+
// A sample taken off screen is still the canvas's last picture, so it is the baseline; only a
|
|
256
|
+
// sample on screen can be the render the user saw.
|
|
257
|
+
const shown = false !== event.data['visible'];
|
|
258
|
+
const key = event.ref ?? '';
|
|
259
|
+
const before = last.get(key);
|
|
260
|
+
const changed = before !== undefined && before.digest !== digest;
|
|
261
|
+
const steady = before?.changedAt === undefined || before.changedAt < since - CANVAS_STEADY_MS;
|
|
262
|
+
const quiet = before?.driftAt === undefined || before.driftAt < since - CANVAS_QUIET_MS;
|
|
263
|
+
if (inWindow && shown && changed && steady && quiet) {
|
|
264
|
+
return CanvasPaint.PAINTED;
|
|
265
|
+
}
|
|
266
|
+
seen ||= inWindow && shown;
|
|
267
|
+
const onItsOwn = changed && polled && (actAt === undefined || event.t > actAt + CANVAS_STEADY_MS);
|
|
268
|
+
last.set(key, {
|
|
269
|
+
digest,
|
|
270
|
+
changedAt: changed ? event.t : before?.changedAt,
|
|
271
|
+
driftAt: onItsOwn ? event.t : before?.driftAt,
|
|
272
|
+
});
|
|
273
|
+
actAt = polled ? actAt : event.t;
|
|
274
|
+
}
|
|
275
|
+
return seen ? CanvasPaint.UNOBSERVED : CanvasPaint.NONE;
|
|
276
|
+
}
|
|
183
277
|
/**
|
|
184
278
|
* Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
|
|
185
279
|
*
|
|
@@ -200,17 +294,20 @@ export function screenMoved(event) {
|
|
|
200
294
|
export function splitForeignTraffic(events, appOrigin, background = []) {
|
|
201
295
|
const ignored = [];
|
|
202
296
|
const app = events.filter((e) => {
|
|
203
|
-
if (!NET_TYPES.has(e.type))
|
|
297
|
+
if (!NET_TYPES.has(e.type)) {
|
|
204
298
|
return true;
|
|
299
|
+
}
|
|
205
300
|
const matchUrl = urlForMatch(e.data);
|
|
206
301
|
const shown = asString(e.data['url']);
|
|
207
302
|
// Somebody else's code, twice over: the toolchain's own channel, and any site that is not the
|
|
208
303
|
// app under test. Neither can answer the question every rule below asks.
|
|
209
304
|
const match = 0 === matchUrl.length ? undefined : matchUrl;
|
|
210
|
-
if (!isDevToolingUrl(match) && !isForeignTraffic(match, appOrigin, background))
|
|
305
|
+
if (!isDevToolingUrl(match) && !isForeignTraffic(match, appOrigin, background)) {
|
|
211
306
|
return true;
|
|
212
|
-
|
|
307
|
+
}
|
|
308
|
+
if (shown !== undefined && !ignored.includes(shown)) {
|
|
213
309
|
ignored.push(shown);
|
|
310
|
+
}
|
|
214
311
|
return false;
|
|
215
312
|
});
|
|
216
313
|
return { app, ignored };
|
|
@@ -255,27 +352,27 @@ export const POLL_JITTER_RATIO = 0.4;
|
|
|
255
352
|
* apart they are, which is the classic double submit and every case this rule was written for.
|
|
256
353
|
*/
|
|
257
354
|
export function isSteadyCadence(times) {
|
|
258
|
-
if (times.length < 3)
|
|
355
|
+
if (times.length < 3) {
|
|
259
356
|
return false;
|
|
357
|
+
}
|
|
260
358
|
const ordered = [...times].sort((a, b) => a - b);
|
|
261
359
|
const gaps = [];
|
|
262
|
-
for (let i = 1; i < ordered.length; i += 1)
|
|
360
|
+
for (let i = 1; i < ordered.length; i += 1) {
|
|
263
361
|
gaps.push((ordered[i] ?? 0) - (ordered[i - 1] ?? 0));
|
|
362
|
+
}
|
|
264
363
|
const sorted = [...gaps].sort((a, b) => a - b);
|
|
265
364
|
const median = sorted[Math.floor(sorted.length / 2)] ?? 0;
|
|
266
|
-
if (median < POLL_MIN_INTERVAL_MS)
|
|
365
|
+
if (median < POLL_MIN_INTERVAL_MS) {
|
|
267
366
|
return false;
|
|
367
|
+
}
|
|
268
368
|
return gaps.every((gap) => Math.abs(gap - median) <= median * POLL_JITTER_RATIO);
|
|
269
369
|
}
|
|
370
|
+
const nonEmpty = (text) => text === undefined || 0 === text.length ? undefined : text;
|
|
270
371
|
export function identityOf(event) {
|
|
271
372
|
const action = asString(event.data[NEXT_ACTION_FIELD]);
|
|
272
373
|
const shape = asString(event.data[REQUEST_SHAPE_FIELD]);
|
|
273
374
|
const body = asString(event.data['requestBody']);
|
|
274
|
-
const carried = shape
|
|
275
|
-
? shape
|
|
276
|
-
: body === undefined || 0 === body.length
|
|
277
|
-
? undefined
|
|
278
|
-
: body;
|
|
375
|
+
const carried = nonEmpty(shape) ?? nonEmpty(body);
|
|
279
376
|
if (action === undefined || 0 === action.length) {
|
|
280
377
|
return carried === undefined ? undefined : { key: carried, carried: true };
|
|
281
378
|
}
|
|
@@ -311,8 +408,9 @@ export function groupByIdentity(calls) {
|
|
|
311
408
|
export function declareFailureHint(calls) {
|
|
312
409
|
const clauses = calls.flatMap((c) => {
|
|
313
410
|
const urlContains = narrowPathOf(c);
|
|
314
|
-
if (urlContains === undefined)
|
|
411
|
+
if (urlContains === undefined) {
|
|
315
412
|
return [];
|
|
413
|
+
}
|
|
316
414
|
const clause = {
|
|
317
415
|
kind: PredicateKind.NET,
|
|
318
416
|
method: c.method.toUpperCase(),
|
|
@@ -321,8 +419,9 @@ export function declareFailureHint(calls) {
|
|
|
321
419
|
};
|
|
322
420
|
return [JSON.stringify(clause)];
|
|
323
421
|
});
|
|
324
|
-
if (0 === clauses.length)
|
|
422
|
+
if (0 === clauses.length) {
|
|
325
423
|
return '';
|
|
424
|
+
}
|
|
326
425
|
const subject = 1 === clauses.length ? 'this failure is' : 'these failures are';
|
|
327
426
|
return `. If ${subject} the outcome you expect, declare it in the predicate: ${clauses.join(', ')}`;
|
|
328
427
|
}
|
|
@@ -342,10 +441,12 @@ function narrowPathOf(call) {
|
|
|
342
441
|
catch {
|
|
343
442
|
return undefined;
|
|
344
443
|
}
|
|
345
|
-
if (0 === path.replace(/\/+$/, '').length)
|
|
444
|
+
if (0 === path.replace(/\/+$/, '').length) {
|
|
346
445
|
return undefined;
|
|
347
|
-
|
|
446
|
+
}
|
|
447
|
+
if (!call.url.includes(path) || !(call.matchUrl ?? call.url).includes(path)) {
|
|
348
448
|
return undefined;
|
|
449
|
+
}
|
|
349
450
|
return path;
|
|
350
451
|
}
|
|
351
452
|
/** Query parameters that say which page of a list is being asked for. */
|
|
@@ -353,25 +454,44 @@ const PAGE_PARAMS = ['page', 'offset', 'cursor', 'after', 'start', 'skip', 'from
|
|
|
353
454
|
/** "Page 2", "page 2 of 6", "2 / 6", "2 of 6". */
|
|
354
455
|
const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+(?:,\d{3})*\b/i;
|
|
355
456
|
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;
|
|
457
|
+
/**
|
|
458
|
+
* The page number a label shows, or undefined when the text is not a page label.
|
|
459
|
+
*
|
|
460
|
+
* A bare "N of M" with N = 0 is a count, not a page: no pager shows page 0, and a progress label
|
|
461
|
+
* such as "0 of 4 generated" does. Reading it as a page made a list that refetched its first page
|
|
462
|
+
* look like stalled pagination, and the verdict read `no` with no paging action at all.
|
|
463
|
+
*/
|
|
356
464
|
export function pageNumber(text) {
|
|
357
|
-
if ('string' !== typeof text)
|
|
465
|
+
if ('string' !== typeof text) {
|
|
358
466
|
return undefined;
|
|
359
|
-
|
|
467
|
+
}
|
|
468
|
+
if (RECORD_RANGE_LABEL.test(text)) {
|
|
360
469
|
return undefined;
|
|
470
|
+
}
|
|
361
471
|
const match = PAGE_LABEL.exec(text);
|
|
362
|
-
const
|
|
363
|
-
|
|
472
|
+
const explicit = match?.[1];
|
|
473
|
+
if (explicit !== undefined) {
|
|
474
|
+
return Number(explicit);
|
|
475
|
+
}
|
|
476
|
+
const bare = match?.[2];
|
|
477
|
+
if (bare === undefined || 0 === Number(bare)) {
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
480
|
+
return Number(bare);
|
|
364
481
|
}
|
|
365
482
|
/** The endpoint, page parameter and remaining query, for a GET that carries a page parameter. */
|
|
366
483
|
export function pageRequest(event) {
|
|
367
|
-
if (event.type !== EventType.NET_REQUEST)
|
|
484
|
+
if (event.type !== EventType.NET_REQUEST) {
|
|
368
485
|
return undefined;
|
|
486
|
+
}
|
|
369
487
|
const method = event.data['method'];
|
|
370
|
-
if ('string' !== typeof method || 'GET' !== method.toUpperCase())
|
|
488
|
+
if ('string' !== typeof method || 'GET' !== method.toUpperCase()) {
|
|
371
489
|
return undefined;
|
|
490
|
+
}
|
|
372
491
|
const raw = event.data['url'];
|
|
373
|
-
if ('string' !== typeof raw)
|
|
492
|
+
if ('string' !== typeof raw) {
|
|
374
493
|
return undefined;
|
|
494
|
+
}
|
|
375
495
|
let url;
|
|
376
496
|
try {
|
|
377
497
|
url = new URL(raw, 'http://app.invalid');
|
|
@@ -399,13 +519,16 @@ export function pageRequest(event) {
|
|
|
399
519
|
* it handled a failure, so a finding that rests on that is weak rather than proof.
|
|
400
520
|
*/
|
|
401
521
|
export function appIsSilent(events, prior) {
|
|
402
|
-
if (prior === undefined)
|
|
522
|
+
if (prior === undefined) {
|
|
403
523
|
return false;
|
|
524
|
+
}
|
|
404
525
|
const speaks = (e) => {
|
|
405
|
-
if (e.type === EventType.SIGNAL)
|
|
526
|
+
if (e.type === EventType.SIGNAL) {
|
|
406
527
|
return !isReticleVoice(asString(e.data['name']) ?? '');
|
|
407
|
-
|
|
528
|
+
}
|
|
529
|
+
if (e.type !== EventType.STATE_CHANGE) {
|
|
408
530
|
return false;
|
|
531
|
+
}
|
|
409
532
|
return !isReticleVoice(asString(e.data['store']) ?? asString(e.data['name']) ?? '');
|
|
410
533
|
};
|
|
411
534
|
return !prior.some(speaks) && !events.some(speaks);
|
|
@@ -447,8 +570,9 @@ export const TargetFate = {
|
|
|
447
570
|
const ABSENT = '\u0000absent';
|
|
448
571
|
/** The attribute or text change this event made to `ref`, or undefined. No-op writes are skipped. */
|
|
449
572
|
function changeOf(event, ref) {
|
|
450
|
-
if (event.ref !== ref)
|
|
573
|
+
if (event.ref !== ref) {
|
|
451
574
|
return undefined;
|
|
575
|
+
}
|
|
452
576
|
let key;
|
|
453
577
|
let now;
|
|
454
578
|
if (event.type === EventType.DOM_ATTR) {
|
|
@@ -466,26 +590,214 @@ function changeOf(event, ref) {
|
|
|
466
590
|
return old === now ? undefined : { key, t: event.t, old, now };
|
|
467
591
|
}
|
|
468
592
|
export function targetFate(events, ref, failedAt) {
|
|
469
|
-
if (ref === undefined)
|
|
593
|
+
if (ref === undefined) {
|
|
470
594
|
return undefined;
|
|
595
|
+
}
|
|
471
596
|
const before = new Map();
|
|
472
597
|
const atFailure = new Map();
|
|
473
598
|
const last = new Map();
|
|
474
599
|
for (const event of events) {
|
|
475
600
|
const change = changeOf(event, ref);
|
|
476
|
-
if (change === undefined)
|
|
601
|
+
if (change === undefined) {
|
|
477
602
|
continue;
|
|
478
|
-
|
|
603
|
+
}
|
|
604
|
+
if (!before.has(change.key)) {
|
|
479
605
|
before.set(change.key, change.old);
|
|
480
|
-
|
|
606
|
+
}
|
|
607
|
+
if (change.t <= failedAt) {
|
|
481
608
|
atFailure.set(change.key, change.now);
|
|
609
|
+
}
|
|
482
610
|
last.set(change.key, change.now);
|
|
483
611
|
}
|
|
484
|
-
if (0 === atFailure.size)
|
|
612
|
+
if (0 === atFailure.size) {
|
|
485
613
|
return undefined;
|
|
614
|
+
}
|
|
486
615
|
const reverted = [...last].every(([key, value]) => before.get(key) === value);
|
|
487
|
-
if (reverted)
|
|
616
|
+
if (reverted) {
|
|
488
617
|
return TargetFate.REVERTED;
|
|
618
|
+
}
|
|
489
619
|
const movedAfter = [...last].some(([key, value]) => (atFailure.get(key) ?? before.get(key)) !== value);
|
|
490
620
|
return movedAfter ? TargetFate.PERSISTED : TargetFate.PENDING;
|
|
491
621
|
}
|
|
622
|
+
// ── Success claims over a declared failure ────────────────────────────────────────────────────
|
|
623
|
+
/** The name a signal is reported under when the app gave it none. */
|
|
624
|
+
export const UNNAMED_SIGNAL = 'signal';
|
|
625
|
+
const nameOf = (e) => asString(e.data['name']) ?? UNNAMED_SIGNAL;
|
|
626
|
+
/** Whether `a` was emitted before `b`. The sequence number is exact; the clock can tie. */
|
|
627
|
+
function emittedBefore(a, b) {
|
|
628
|
+
return a.seq !== undefined && b.seq !== undefined ? a.seq < b.seq : a.t < b.t;
|
|
629
|
+
}
|
|
630
|
+
/** The event that recorded when this failed call was SENT, if the window holds it. */
|
|
631
|
+
function sendOf(events, call) {
|
|
632
|
+
const answer = events.find((e) => {
|
|
633
|
+
if (e.type !== EventType.NET_REQUEST || e.t !== call.t) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
const recorded = netCall(e);
|
|
637
|
+
return recorded.method === call.method && recorded.matchUrl === call.matchUrl;
|
|
638
|
+
});
|
|
639
|
+
const id = answer === undefined ? undefined : asString(answer.data['id']);
|
|
640
|
+
if (id === undefined) {
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
return events.find((e) => e.type === EventType.NET_PENDING && asString(e.data['id']) === id);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* The success signals that can claim the failed writes in this window landed.
|
|
647
|
+
*
|
|
648
|
+
* A caller that declared the failure (`net { status: 409 }`) tests the failure path. A signal that the
|
|
649
|
+
* app fired BEFORE it sent the failed write cannot report the outcome of that write, so it is not a
|
|
650
|
+
* claim about it (#2172). A `form:submit` on the click, or an analytics beacon, is that kind of signal.
|
|
651
|
+
*
|
|
652
|
+
* The limit is when the write was SENT, not when its answer was recorded. The browser observer reads
|
|
653
|
+
* a failed response's body before it records the answer, so the app's own handler can fire its
|
|
654
|
+
* signal first. A limit on the answer would then hide the false green this rule exists for.
|
|
655
|
+
*
|
|
656
|
+
* Every failed write must be declared, and the window must hold when each one was sent. Otherwise
|
|
657
|
+
* every success signal stays a claim, as before.
|
|
658
|
+
*/
|
|
659
|
+
export function successClaims(events, failedWrites, successSignals, declared = []) {
|
|
660
|
+
if (0 === failedWrites.length ||
|
|
661
|
+
!failedWrites.every((c) => matchesDeclaredFailure(c, declared))) {
|
|
662
|
+
return successSignals;
|
|
663
|
+
}
|
|
664
|
+
const sends = [];
|
|
665
|
+
for (const call of failedWrites) {
|
|
666
|
+
const send = sendOf(events, call);
|
|
667
|
+
if (send === undefined) {
|
|
668
|
+
return successSignals;
|
|
669
|
+
}
|
|
670
|
+
sends.push(send);
|
|
671
|
+
}
|
|
672
|
+
const claims = new Set(successSignals);
|
|
673
|
+
return events
|
|
674
|
+
.filter((e) => e.type === EventType.SIGNAL && sends.some((send) => !emittedBefore(e, send)))
|
|
675
|
+
.map(nameOf)
|
|
676
|
+
.filter((name) => claims.has(name));
|
|
677
|
+
}
|
|
678
|
+
const isPlainObject = (value) => 'object' === typeof value && value !== null && !Array.isArray(value);
|
|
679
|
+
/**
|
|
680
|
+
* The values one store write set: the value itself, or each key of an object that changed. The
|
|
681
|
+
* store observer diffs only the top level, so `invite: { status: 429 }` arrives as one object.
|
|
682
|
+
*/
|
|
683
|
+
function writtenValues(value, old) {
|
|
684
|
+
if (!isPlainObject(value)) {
|
|
685
|
+
return [value];
|
|
686
|
+
}
|
|
687
|
+
const before = isPlainObject(old) ? old : {};
|
|
688
|
+
return Object.entries(value).flatMap(([key, v]) => (Object.is(before[key], v) ? [] : [v]));
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Each call that failed in this window, with the event after which the app can react to it: the
|
|
692
|
+
* send, or the answer when the window does not hold the send. The limit is the send and not the
|
|
693
|
+
* answer for the reason `successClaims` gives: the browser observer records the answer after the
|
|
694
|
+
* app's own handler ran.
|
|
695
|
+
*/
|
|
696
|
+
function failedCalls(events) {
|
|
697
|
+
return events.flatMap((answer) => {
|
|
698
|
+
if (answer.type !== EventType.NET_REQUEST) {
|
|
699
|
+
return [];
|
|
700
|
+
}
|
|
701
|
+
const call = netCall(answer);
|
|
702
|
+
if (false !== call.ok) {
|
|
703
|
+
return [];
|
|
704
|
+
}
|
|
705
|
+
const id = asString(answer.data['id']);
|
|
706
|
+
const sent = events.find((e) => e.type === EventType.NET_PENDING && id !== undefined && asString(e.data['id']) === id);
|
|
707
|
+
return [{ call, after: sent ?? answer }];
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Did the store record the HTTP status of a call that failed in this window?
|
|
712
|
+
*
|
|
713
|
+
* A structural echo, like the echo of the error text: an app that keeps `status: 429` beside a
|
|
714
|
+
* retry button knows that the call failed. Strict, because a false acknowledgement hides a failed
|
|
715
|
+
* write. The value must be exactly that status (a number or its string), it must change in this
|
|
716
|
+
* write, and the write must come after the call was sent. The status of a call that succeeded is
|
|
717
|
+
* not one.
|
|
718
|
+
*/
|
|
719
|
+
export function storeEchoesFailedStatus(events) {
|
|
720
|
+
return failedCalls(events).some(({ call, after }) => {
|
|
721
|
+
if (call.status === undefined) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
const status = String(call.status);
|
|
725
|
+
return events.some((e) => e.type === EventType.STATE_CHANGE &&
|
|
726
|
+
emittedBefore(after, e) &&
|
|
727
|
+
writtenValues(e.data['value'], e.data['old']).some((v) => ('number' === typeof v || 'string' === typeof v) && String(v) === status));
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
/** Core's `LivePoliteness.ASSERTIVE`; not imported: coupling only shrinks. */
|
|
731
|
+
const LIVE_ASSERTIVE = 'assertive';
|
|
732
|
+
/**
|
|
733
|
+
* Did the app write text into an existing ASSERTIVE live region after a failed call was sent?
|
|
734
|
+
*
|
|
735
|
+
* The common way to show "Wrong email or password" is to write it into a `role="alert"` region that
|
|
736
|
+
* is already on the page, which a mount event does not record (#2173). The words do not decide, the
|
|
737
|
+
* level does. ARIA keeps the assertive level for errors and urgent warnings. A polite region
|
|
738
|
+
* (`role="status"`) is where an app writes "Saved", so text there is not an acknowledgement. The
|
|
739
|
+
* ceiling: an app that writes a success word into an alert region over a failed write is read as
|
|
740
|
+
* acknowledging it, as a mounted alert already is. Text written before the send cannot answer the
|
|
741
|
+
* call, and a cleared region says nothing.
|
|
742
|
+
*/
|
|
743
|
+
export function liveAlertAfterFailedSend(events) {
|
|
744
|
+
return failedCalls(events).some(({ after }) => events.some((e) => e.type === EventType.DOM_TEXT &&
|
|
745
|
+
LIVE_ASSERTIVE === e.data['live'] &&
|
|
746
|
+
(asString(e.data['text']) ?? '').length > 0 &&
|
|
747
|
+
emittedBefore(after, e)));
|
|
748
|
+
}
|
|
749
|
+
/** Reticle's own instrumentation's signals (core's `RETICLE_HYDRATION_SIGNAL`); not imported: coupling only shrinks. */
|
|
750
|
+
export const RETICLE_SIGNAL_NAMESPACE = 'reticle:';
|
|
751
|
+
/**
|
|
752
|
+
* Whether NOTHING in this window is attributable to the action.
|
|
753
|
+
*
|
|
754
|
+
* Ambient churn is deliberately not counted as evidence the action worked — a background event
|
|
755
|
+
* stream, a polling store, a perf sample and a scroll position all move on their own. What counts:
|
|
756
|
+
*
|
|
757
|
+
* - a mutation inside the target's own subtree (what the target itself did),
|
|
758
|
+
* - a request (the action asked the server for something),
|
|
759
|
+
* - a navigation, or a dialog/live region appearing — the two ways a real reaction legitimately
|
|
760
|
+
* lands OUTSIDE the target, e.g. a modal portalled to the body,
|
|
761
|
+
* - a store change or an app signal tied to the action (#1531): see
|
|
762
|
+
* `tiedReaction`.
|
|
763
|
+
*
|
|
764
|
+
* The last two clauses are what keep this from manufacturing noise: a button that opens a modal
|
|
765
|
+
* mutates nothing within itself, and a Pause button whose store updates on the media `pause` event
|
|
766
|
+
* renders its new label only later. Neither must be called dead.
|
|
767
|
+
*/
|
|
768
|
+
export function didNothing(events, requests, options) {
|
|
769
|
+
const mutatedWithin = options.mutatedWithin;
|
|
770
|
+
if (mutatedWithin === undefined) {
|
|
771
|
+
return 0 === events.length;
|
|
772
|
+
}
|
|
773
|
+
if (mutatedWithin > 0 || requests.length > 0) {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
const tied = tiedAppReaction(options);
|
|
777
|
+
return !events.some((e) => e.type === EventType.ROUTE_CHANGE || e.type === EventType.VISIBLE_SHOWN || tied(e));
|
|
778
|
+
}
|
|
779
|
+
const STATE_KEY_PREFIX = 'state:';
|
|
780
|
+
const SIGNAL_KEY_PREFIX = 'signal:';
|
|
781
|
+
/** Which store path or signal an event moved, keyed the same way in the window and in `prior`. */
|
|
782
|
+
function appReactionKey(e) {
|
|
783
|
+
if (e.type === EventType.STATE_CHANGE) {
|
|
784
|
+
return `${STATE_KEY_PREFIX}${asString(e.data['name']) ?? ''}:${asString(e.data['path']) ?? ''}`;
|
|
785
|
+
}
|
|
786
|
+
if (e.type !== EventType.SIGNAL) {
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
const name = asString(e.data['name']) ?? '';
|
|
790
|
+
// Reticle's own instrumentation is not the app reacting.
|
|
791
|
+
return name.startsWith(RETICLE_SIGNAL_NAMESPACE) ? undefined : `${SIGNAL_KEY_PREFIX}${name}`;
|
|
792
|
+
}
|
|
793
|
+
/** A store change or app signal tied to the action: see `tiedReaction` (#1531). */
|
|
794
|
+
function tiedAppReaction(options) {
|
|
795
|
+
const namedPaths = new Set(options.namedStatePaths ?? []);
|
|
796
|
+
const namedSignals = new Set(options.namedSignals ?? []);
|
|
797
|
+
return tiedReaction(options.prior ?? [], {
|
|
798
|
+
keyOf: appReactionKey,
|
|
799
|
+
isNamed: (e) => e.type === EventType.STATE_CHANGE
|
|
800
|
+
? namedPaths.has(asString(e.data['path']) ?? '')
|
|
801
|
+
: namedSignals.has(asString(e.data['name']) ?? ''),
|
|
802
|
+
});
|
|
803
|
+
}
|
|
@@ -57,6 +57,15 @@ export interface ContradictionOptions {
|
|
|
57
57
|
* contain. See `findUnitMismatches` for the measured case this exists for.
|
|
58
58
|
*/
|
|
59
59
|
prior?: readonly ReticleEvent[] | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Events from before the window that ONLY the read-server-fault rule reads, to tell a background
|
|
62
|
+
* read that already failed the same way from one this action caused.
|
|
63
|
+
*
|
|
64
|
+
* Flow replay passes this and not `prior`: `prior` also feeds the silent-app rule and the learning
|
|
65
|
+
* rules, and replay has no measurement for those. A poll that fails on every tick was reported
|
|
66
|
+
* inside every replayed step, and a working journey read `unverifiable`.
|
|
67
|
+
*/
|
|
68
|
+
failedReadsBefore?: readonly ReticleEvent[] | undefined;
|
|
60
69
|
/**
|
|
61
70
|
* Event time at which the action that opened this window was dispatched — the attribution floor.
|
|
62
71
|
*
|
|
@@ -116,6 +125,15 @@ export interface ContradictionOptions {
|
|
|
116
125
|
* with no view.
|
|
117
126
|
*/
|
|
118
127
|
renderProved?: boolean | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* The caller declared a route, it HELD in this window, and it was not true before the action.
|
|
130
|
+
*
|
|
131
|
+
* `action-had-no-effect` infers a dead control from an empty window. A full navigation that the
|
|
132
|
+
* SDK did not record leaves the window empty, and the passing route clause disproves the
|
|
133
|
+
* inference. Undefined/false leaves the rule as it was, which is the case that catches a click on
|
|
134
|
+
* an inert target.
|
|
135
|
+
*/
|
|
136
|
+
routeProved?: boolean | undefined;
|
|
119
137
|
/**
|
|
120
138
|
* The document currently under observation, as the session derived it from its own event stream.
|
|
121
139
|
*
|
|
@@ -175,6 +193,13 @@ export interface ContradictionOptions {
|
|
|
175
193
|
* declared, nothing is unrelated.
|
|
176
194
|
*/
|
|
177
195
|
namedNetUrls?: readonly string[] | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* The store paths and signal names the caller's predicate named (#1531). A change to one of them
|
|
198
|
+
* is the consequence the caller expected, so `action-had-no-effect` counts it as the action
|
|
199
|
+
* doing something. Undefined means nothing was declared.
|
|
200
|
+
*/
|
|
201
|
+
namedStatePaths?: readonly string[] | undefined;
|
|
202
|
+
namedSignals?: readonly string[] | undefined;
|
|
178
203
|
/**
|
|
179
204
|
* Endpoints the assertion declared as reads (`net { repeatable: true }`). Repeats on them are not
|
|
180
205
|
* a double submit, so `duplicate-request` skips them (#1353). A call matches when its URL contains
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { type ReticleEvent } from '@reticlehq/core';
|
|
2
2
|
import type { Contradiction, OwnContradiction, ContradictionOptions } from './contradiction-types.js';
|
|
3
3
|
export type { Contradiction, OwnContradiction, ContradictionOptions, } from './contradiction-types.js';
|
|
4
|
-
/**
|
|
4
|
+
/** What the state-vs-render rule makes of a window. See `readStateRender`. */
|
|
5
|
+
export declare const StateRender: {
|
|
6
|
+
readonly CLEAR: "clear";
|
|
7
|
+
readonly RAISE: "raise";
|
|
8
|
+
/** No DOM node moved, and a canvas on screen could hold the render in pixels not seen to change. */
|
|
9
|
+
readonly CANVAS_UNOBSERVED: "canvas-unobserved";
|
|
10
|
+
};
|
|
11
|
+
export type StateRender = (typeof StateRender)[keyof typeof StateRender];
|
|
12
|
+
/**
|
|
13
|
+
* The state-vs-render reading of a window, one function for the rule and for the coverage line that
|
|
14
|
+
* names its abstention, so the two cannot disagree. It fires on an ABSENCE, so it is scoped tightly:
|
|
15
|
+
* only for a window attributed to an ACTION, only when state moved, only when no DOM node, route or
|
|
16
|
+
* app-written field moved with it (`screenMoved`), and only when the window carries no network at
|
|
17
|
+
* all. A request belongs to the rules for failed, ignored and unsettled calls. A canvas that painted
|
|
18
|
+
* is the screen moving (#1525); a canvas whose paint was not seen makes the rule abstain.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readStateRender(events: readonly ReticleEvent[], options: Pick<ContradictionOptions, 'actionSince' | 'prior'>): StateRender;
|
|
5
21
|
export declare function findContradictions(allEvents: readonly ReticleEvent[], options?: ContradictionOptions): Contradiction[];
|
|
6
22
|
/**
|
|
7
23
|
* The page label moved and the request did not.
|