@reticlehq/engine 3.6.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/disagreement/contradiction-evidence.d.ts +134 -2
- package/dist/disagreement/contradiction-evidence.js +291 -3
- package/dist/disagreement/contradiction-types.d.ts +16 -1
- package/dist/disagreement/contradictions.d.ts +12 -0
- package/dist/disagreement/contradictions.js +56 -84
- package/dist/disagreement/stale-response.js +56 -17
- package/dist/evidence/already-true.d.ts +5 -0
- package/dist/evidence/already-true.js +27 -6
- package/dist/evidence/baseline.js +2 -6
- package/dist/evidence/blind-spots.d.ts +14 -3
- package/dist/evidence/blind-spots.js +48 -10
- package/dist/evidence/body-capture-remedy.d.ts +1 -15
- package/dist/evidence/body-capture-remedy.js +6 -1
- package/dist/evidence/instrumentation-gaps.js +3 -1
- package/dist/evidence/state-bookkeeping.d.ts +2 -0
- package/dist/evidence/state-bookkeeping.js +2 -0
- package/dist/evidence/step-effect.d.ts +20 -1
- package/dist/evidence/step-effect.js +30 -2
- package/dist/evidence/superseded-checks.d.ts +29 -0
- package/dist/evidence/superseded-checks.js +30 -0
- package/dist/evidence/uncaptured-bodies.d.ts +18 -1
- package/dist/evidence/uncaptured-bodies.js +22 -1
- package/dist/evidence/unread-outcome.d.ts +7 -0
- package/dist/evidence/unread-outcome.js +22 -0
- package/dist/evidence/unsettled.js +29 -2
- package/dist/evidence/verified.d.ts +8 -1
- package/dist/evidence/verified.js +33 -5
- package/dist/question/declared.d.ts +20 -0
- package/dist/question/declared.js +20 -1
- package/dist/question/predicate/net-blind-spots.d.ts +49 -0
- package/dist/question/predicate/net-blind-spots.js +153 -0
- package/dist/question/predicate/predicate-compare.js +7 -1
- package/dist/question/predicate/predicate-console.js +23 -10
- package/dist/question/predicate/predicate-element.d.ts +23 -0
- package/dist/question/predicate/predicate-element.js +208 -16
- package/dist/question/predicate/predicate-eval-kit.d.ts +28 -3
- package/dist/question/predicate/predicate-eval-kit.js +34 -7
- package/dist/question/predicate/predicate-eval.d.ts +11 -1
- package/dist/question/predicate/predicate-eval.js +138 -177
- package/dist/question/predicate/predicate-parse.js +34 -0
- package/dist/question/predicate/predicate-request-body.d.ts +15 -1
- package/dist/question/predicate/predicate-request-body.js +23 -3
- package/dist/question/predicate/predicate-route.d.ts +2 -0
- package/dist/question/predicate/predicate-route.js +30 -0
- package/dist/question/predicate/predicate-schema.d.ts +11 -0
- package/dist/question/predicate/predicate-schema.js +52 -1
- package/dist/question/predicate/predicate-state.js +7 -0
- package/dist/question/predicate/predicate.js +58 -18
- package/dist/question/predicate/split-text-miss.d.ts +7 -0
- package/dist/question/predicate/split-text-miss.js +18 -1
- package/dist/state-bookkeeping.d.ts +27 -0
- package/dist/state-bookkeeping.js +74 -0
- package/dist/window/adversary.js +5 -1
- package/package.json +2 -2
|
@@ -1,39 +1,25 @@
|
|
|
1
|
-
import { ContradictionKind, EventType,
|
|
1
|
+
import { ContradictionKind, EventType, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
|
|
2
2
|
import { describeSuperseded } from '../question/predicate/observed-in-window.js';
|
|
3
|
-
import { describe, isMutating, isSameDocumentHashAnchor, isSteadyCadence, netCall, 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';
|
|
7
7
|
import { findUnitMismatches } from './unit-mismatch.js';
|
|
8
8
|
import { asString } from '@reticlehq/core';
|
|
9
|
-
import { matchesDeclaredFailure } from '../question/declared.js';
|
|
9
|
+
import { isDeclaredRead, matchesDeclaredFailure } from '../question/declared.js';
|
|
10
10
|
import { runRegisteredFolds } from './contradiction-folds.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return carried === undefined
|
|
24
|
-
? { key: action, carried: false }
|
|
25
|
-
: { key: `${action}:${carried}`, carried: true };
|
|
26
|
-
}
|
|
27
|
-
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
28
|
-
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
29
|
-
function groupByIdentity(calls) {
|
|
30
|
-
const byIdentity = new Map();
|
|
31
|
-
for (const call of calls) {
|
|
32
|
-
const key = call.identity?.key ?? '';
|
|
33
|
-
byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
|
|
34
|
-
}
|
|
35
|
-
return [...byIdentity.values()];
|
|
36
|
-
}
|
|
11
|
+
import { isMeaningfulStateChange } from '../state-bookkeeping.js';
|
|
12
|
+
/**
|
|
13
|
+
* The contradiction hunter.
|
|
14
|
+
*
|
|
15
|
+
* Every other check reads ONE channel and asks "did something bad happen there?". This asks what a
|
|
16
|
+
* person watching the screen structurally cannot: do the channels DISAGREE? The DOM, the store, the
|
|
17
|
+
* app's own signals, the console and the network arrive in one causally ordered window, so the case
|
|
18
|
+
* where the screen says one thing and the network says the opposite is visible — and that gap is
|
|
19
|
+
* where false greens live, because a screenshot, a DOM assertion and a human all agree there.
|
|
20
|
+
*
|
|
21
|
+
* Pure: a window of events in, findings out. No session, no IO, no clock.
|
|
22
|
+
*/
|
|
37
23
|
function uiAdvanced(events) {
|
|
38
24
|
return events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
39
25
|
e.type === EventType.DOM_REMOVED ||
|
|
@@ -49,6 +35,10 @@ function uiAdvanced(events) {
|
|
|
49
35
|
* the structural check below cannot decide, not the primary signal.
|
|
50
36
|
*/
|
|
51
37
|
const ACKNOWLEDGED = /error|fail|invalid|reject|denied|unable|could not|couldn't/i;
|
|
38
|
+
// Refusal wording belongs to explicit signals; "checkout.blocking" can be an ordinary loading flag.
|
|
39
|
+
// Token boundaries keep "unblocked" and "blockchain" as success claims.
|
|
40
|
+
const REFUSAL_SIGNAL = /(?:^|[^a-z])(?:refus(?:e[ds]?|al|ing)|forbid(?:den|ding|s)?|blocked|not[ _-]+allowed)(?:$|[^a-z])/i;
|
|
41
|
+
const signalAcknowledgesFailure = (name) => ACKNOWLEDGED.test(name) || REFUSAL_SIGNAL.test(name);
|
|
52
42
|
/**
|
|
53
43
|
* Below this length an error string is too generic to be evidence — "no", "err", a bare code — and
|
|
54
44
|
* could coincide with unrelated state text.
|
|
@@ -114,7 +104,7 @@ function failureAcknowledged(events) {
|
|
|
114
104
|
// A failure-shaped SIGNAL is an acknowledgement too. An app that fires `auth:denied` has plainly
|
|
115
105
|
// not proceeded as if it succeeded, whatever its state paths happen to be named.
|
|
116
106
|
if (e.type === EventType.SIGNAL)
|
|
117
|
-
return
|
|
107
|
+
return signalAcknowledgesFailure(asString(e.data['name']) ?? '');
|
|
118
108
|
if (e.type !== EventType.STATE_CHANGE)
|
|
119
109
|
return false;
|
|
120
110
|
const path = asString(e.data['path']) ?? '';
|
|
@@ -123,6 +113,8 @@ function failureAcknowledged(events) {
|
|
|
123
113
|
});
|
|
124
114
|
}
|
|
125
115
|
const ALERT_ROLE = 'alert';
|
|
116
|
+
/** Reticle's own instrumentation's signals (core's `RETICLE_HYDRATION_SIGNAL`); not imported: coupling only shrinks. */
|
|
117
|
+
const RETICLE_SIGNAL_NAMESPACE = 'reticle:';
|
|
126
118
|
const ARIA_INVALID = 'aria-invalid';
|
|
127
119
|
const MUST_DO_SOMETHING = new Set(['click', 'dblclick', 'submit']);
|
|
128
120
|
/**
|
|
@@ -307,7 +299,12 @@ function findWindowContradictions(allEvents, options) {
|
|
|
307
299
|
// consequences are location.hash, focus, and scroll — not a DOM mutation. Treating it as a
|
|
308
300
|
// blank destination made "did my skip link work" unanswerable. Hash-router paths (`#/invoices`)
|
|
309
301
|
// still go through the rule: those ARE a new view.
|
|
310
|
-
|
|
302
|
+
//
|
|
303
|
+
// A `replaceState` that keeps the pathname is the same kind of non-navigation: the URL recorded
|
|
304
|
+
// state (a zoom, a filter, a selected tab) and the view did not change. A replace onto a new
|
|
305
|
+
// pathname, or a push onto one, is still a navigation.
|
|
306
|
+
const notANavigation = routed &&
|
|
307
|
+
routeEvents.every((event) => isSameDocumentHashAnchor(event) || isSamePathnameReplace(event));
|
|
311
308
|
// `dom.text` counts as rendered, and it has to: React reconciles a destination IN PLACE far more
|
|
312
309
|
// often than it adds nodes. Measured on three ordinary sidebar navigations of the bench app — every
|
|
313
310
|
// one emitted { dom.attr:2, dom.text:2, render.commit, state.change } and ZERO dom.added/removed,
|
|
@@ -322,7 +319,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
322
319
|
e.type === EventType.DOM_REMOVED ||
|
|
323
320
|
e.type === EventType.DOM_TEXT);
|
|
324
321
|
const fetched = events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING);
|
|
325
|
-
if (routed && !
|
|
322
|
+
if (routed && !notANavigation && !rendered && !fetched && true !== options.renderProved) {
|
|
326
323
|
// A console error in the SAME window turns "nothing rendered" from an absence into a positive
|
|
327
324
|
// claim: the destination did not merely fail to produce content, it crashed while trying to.
|
|
328
325
|
// Reported once as `unknown` when this held — a React hooks error and an empty destination were
|
|
@@ -378,7 +375,9 @@ function findWindowContradictions(allEvents, options) {
|
|
|
378
375
|
// A failure-shaped signal is not a success claim, so it must not be read as one: saying "the app
|
|
379
376
|
// claimed success" about an app that plainly reported a failure is true in outline and wrong in
|
|
380
377
|
// its reasoning, which is how a checker stops being believed.
|
|
381
|
-
|
|
378
|
+
// Nor is a signal Reticle's instrumentation fires: a revoked member's tab sent to /login by the
|
|
379
|
+
// intended 401 hydrated, and that read as a success claim graded the working revocation `no`.
|
|
380
|
+
const successSignals = signals.filter((name) => !name.startsWith(RETICLE_SIGNAL_NAMESPACE) && !signalAcknowledgesFailure(name));
|
|
382
381
|
// An app that RETRACTED has not claimed success, whenever it fired the optimistic signal.
|
|
383
382
|
//
|
|
384
383
|
// The weaker UI rule below already consulted this and the sharper signal rule did not, so an app
|
|
@@ -422,12 +421,20 @@ function findWindowContradictions(allEvents, options) {
|
|
|
422
421
|
true === advanced &&
|
|
423
422
|
!misattributed &&
|
|
424
423
|
!failureAcknowledged(events)) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
+
}
|
|
431
438
|
}
|
|
432
439
|
// ── A write succeeded and nothing on the client moved ───────────────────────────────────────
|
|
433
440
|
// Writes only: a GET that changes nothing is a prefetch; a POST that changes nothing is a lost
|
|
@@ -466,7 +473,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
466
473
|
// flight that the render could legitimately be waiting on.
|
|
467
474
|
//
|
|
468
475
|
// Route movement counts as the screen moving: a navigation IS a render, and a store change that
|
|
469
|
-
// drives one has been corroborated.
|
|
476
|
+
// drives one has been corroborated, and so has a field the app wrote (`screenMoved`).
|
|
470
477
|
//
|
|
471
478
|
// And only when the window carries NO NETWORK AT ALL. A request means the app reached for
|
|
472
479
|
// something, and whether it failed, was ignored or never settled already belongs to three other
|
|
@@ -474,18 +481,14 @@ function findWindowContradictions(allEvents, options) {
|
|
|
474
481
|
// signal rule below had to earn. Two existing tests proved it: both describe a window with a
|
|
475
482
|
// failed call in it, and both were already answered by the rule that owns that fact.
|
|
476
483
|
if (options.actionSince !== undefined &&
|
|
477
|
-
events.some(
|
|
484
|
+
events.some(isMeaningfulStateChange) &&
|
|
478
485
|
!events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING) &&
|
|
479
|
-
!events.some(
|
|
480
|
-
e.type === EventType.DOM_REMOVED ||
|
|
481
|
-
e.type === EventType.DOM_ATTR ||
|
|
482
|
-
e.type === EventType.DOM_TEXT ||
|
|
483
|
-
e.type === EventType.ROUTE_CHANGE)) {
|
|
486
|
+
!events.some(screenMoved)) {
|
|
484
487
|
found.push({
|
|
485
488
|
kind: ContradictionKind.STATE_VS_RENDER,
|
|
486
489
|
claim: 'the store committed a change',
|
|
487
|
-
counter: 'nothing rendered in the same window
|
|
488
|
-
'
|
|
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',
|
|
489
492
|
detail: 'a component that does not re-render on a committed change shows the OLD value while the ' +
|
|
490
493
|
'app is internally consistent, which is why nothing else reports it',
|
|
491
494
|
});
|
|
@@ -567,6 +570,9 @@ function findWindowContradictions(allEvents, options) {
|
|
|
567
570
|
const call = netCall(event);
|
|
568
571
|
if (!isMutating(call))
|
|
569
572
|
continue;
|
|
573
|
+
// Declared a read by the assertion itself (#1353): a repeat is the app reading twice.
|
|
574
|
+
if (isDeclaredRead(call, options.repeatableNetUrls))
|
|
575
|
+
continue;
|
|
570
576
|
const label = `${call.method} ${call.url}`;
|
|
571
577
|
const calls = writes.get(label) ?? [];
|
|
572
578
|
// `landed` is tracked per call rather than counted here, because the claim is about what
|
|
@@ -685,41 +691,6 @@ function findWindowContradictions(allEvents, options) {
|
|
|
685
691
|
* changing AND a GET to the same endpoint carrying the same page parameter the last one carried.
|
|
686
692
|
* Client-side paging that fetches nothing is legitimate and stays silent.
|
|
687
693
|
*/
|
|
688
|
-
/** Query parameters that say which page of a list is being asked for. */
|
|
689
|
-
const PAGE_PARAMS = ['page', 'offset', 'cursor', 'after', 'start', 'skip', 'from'];
|
|
690
|
-
/** "Page 2", "page 2 of 6", "2 / 6", "2 of 6". */
|
|
691
|
-
const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+\b/i;
|
|
692
|
-
function pageNumber(text) {
|
|
693
|
-
if ('string' !== typeof text)
|
|
694
|
-
return undefined;
|
|
695
|
-
const match = PAGE_LABEL.exec(text);
|
|
696
|
-
const raw = match?.[1] ?? match?.[2];
|
|
697
|
-
return raw === undefined ? undefined : Number(raw);
|
|
698
|
-
}
|
|
699
|
-
/** The endpoint and its page parameter, for a GET that carries one. */
|
|
700
|
-
function pageRequest(event) {
|
|
701
|
-
if (event.type !== EventType.NET_REQUEST)
|
|
702
|
-
return undefined;
|
|
703
|
-
const method = event.data['method'];
|
|
704
|
-
if ('string' !== typeof method || 'GET' !== method.toUpperCase())
|
|
705
|
-
return undefined;
|
|
706
|
-
const raw = event.data['url'];
|
|
707
|
-
if ('string' !== typeof raw)
|
|
708
|
-
return undefined;
|
|
709
|
-
let url;
|
|
710
|
-
try {
|
|
711
|
-
url = new URL(raw, 'http://app.invalid');
|
|
712
|
-
}
|
|
713
|
-
catch {
|
|
714
|
-
return undefined;
|
|
715
|
-
}
|
|
716
|
-
for (const param of PAGE_PARAMS) {
|
|
717
|
-
const value = url.searchParams.get(param);
|
|
718
|
-
if (value !== null)
|
|
719
|
-
return { path: url.pathname, param, value };
|
|
720
|
-
}
|
|
721
|
-
return undefined;
|
|
722
|
-
}
|
|
723
694
|
/**
|
|
724
695
|
* @param prior events before the window: where the last page request to each endpoint is learned.
|
|
725
696
|
*/
|
|
@@ -747,7 +718,8 @@ export function findStalledPagination(events, prior = []) {
|
|
|
747
718
|
const previous = last.get(request.path);
|
|
748
719
|
if (previous !== undefined &&
|
|
749
720
|
previous.param === request.param &&
|
|
750
|
-
previous.value === request.value
|
|
721
|
+
previous.value === request.value &&
|
|
722
|
+
previous.query === request.query)
|
|
751
723
|
return [
|
|
752
724
|
{
|
|
753
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
|
|
30
|
+
const POSITION_PARAMS = new Set([
|
|
22
31
|
'page',
|
|
32
|
+
'pagenumber',
|
|
23
33
|
'offset',
|
|
24
|
-
'
|
|
34
|
+
'skip',
|
|
25
35
|
'limit',
|
|
26
36
|
'size',
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
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 (!
|
|
71
|
+
if (!enumerates(key, a.get(key), b.get(key)))
|
|
45
72
|
return false;
|
|
46
73
|
differed = true;
|
|
47
74
|
}
|
|
@@ -52,6 +79,8 @@ function differsOnlyByEnumeration(first, second) {
|
|
|
52
79
|
* (a tile grid's `?id=1` and `?id=2`), and neither answer can overwrite the other's view.
|
|
53
80
|
*/
|
|
54
81
|
const IDENTITY_PARAMS = new Set(['id', 'ids', 'uuid', 'slug', 'key']);
|
|
82
|
+
/** Different projections ask for differently shaped answers, both of which the app may need. */
|
|
83
|
+
const PROJECTION_PARAMS = new Set(['select', 'fields', 'columns', 'include', 'expand']);
|
|
55
84
|
/**
|
|
56
85
|
* Issued this close together, two requests came from one task (a `Promise.all`, two effects in one
|
|
57
86
|
* commit), so no later intent superseded the first: they are a fan-out, not a race (#1225).
|
|
@@ -61,8 +90,8 @@ const IDENTITY_PARAMS = new Set(['id', 'ids', 'uuid', 'slug', 'key']);
|
|
|
61
90
|
const SAME_TASK_MS = 2;
|
|
62
91
|
/**
|
|
63
92
|
* Whether the second read could have made the first obsolete. Not when they ask for differently
|
|
64
|
-
* shaped answers (
|
|
65
|
-
*
|
|
93
|
+
* shaped answers (different key sets or projections), not when they name different resources, and
|
|
94
|
+
* not when only enumeration changed.
|
|
66
95
|
*/
|
|
67
96
|
function couldSupersede(first, second) {
|
|
68
97
|
const a = new URLSearchParams(first);
|
|
@@ -74,6 +103,9 @@ function couldSupersede(first, second) {
|
|
|
74
103
|
for (const key of IDENTITY_PARAMS)
|
|
75
104
|
if (a.get(key) !== b.get(key))
|
|
76
105
|
return false;
|
|
106
|
+
for (const key of PROJECTION_PARAMS)
|
|
107
|
+
if (a.get(key) !== b.get(key))
|
|
108
|
+
return false;
|
|
77
109
|
return !differsOnlyByEnumeration(first, second);
|
|
78
110
|
}
|
|
79
111
|
/** Pair NET_PENDING with its NET_REQUEST by the id both carry. Unpaired events are still in flight. */
|
|
@@ -151,23 +183,30 @@ const APPLY_SLACK_MS = 100;
|
|
|
151
183
|
* detector that accuses correct code teaches people to ignore it, and it takes the true positives
|
|
152
184
|
* down with it.
|
|
153
185
|
*/
|
|
154
|
-
function appliedAfter(events,
|
|
186
|
+
function appliedAfter(events, loser, all) {
|
|
187
|
+
const { settledAt } = loser;
|
|
155
188
|
return events.some((event) => {
|
|
156
189
|
if (event.t < settledAt - APPLY_SLACK_MS || event.t > settledAt + APPLY_WINDOW_MS)
|
|
157
190
|
return false;
|
|
158
|
-
|
|
191
|
+
const reacts = event.type === EventType.STATE_CHANGE ||
|
|
159
192
|
event.type === EventType.SIGNAL ||
|
|
160
193
|
event.type === EventType.DOM_TEXT ||
|
|
161
194
|
event.type === EventType.DOM_ADDED ||
|
|
162
195
|
event.type === EventType.DOM_REMOVED ||
|
|
163
|
-
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
|
+
const own = Math.abs(event.t - settledAt);
|
|
201
|
+
return reacts && !all.some((f) => f.id !== loser.id && Math.abs(event.t - f.settledAt) < own);
|
|
164
202
|
});
|
|
165
203
|
}
|
|
166
204
|
export function findStaleResponses(events) {
|
|
167
205
|
// Grouped by path first: two reads of DIFFERENT endpoints can never race, and comparing them was
|
|
168
206
|
// the bulk of the work on any real page, which talks to many endpoints at once.
|
|
169
207
|
const byPath = new Map();
|
|
170
|
-
|
|
208
|
+
const all = flights(events);
|
|
209
|
+
for (const flight of all) {
|
|
171
210
|
if (flight.method !== 'GET')
|
|
172
211
|
continue;
|
|
173
212
|
const path = pathOf(flight.url);
|
|
@@ -177,13 +216,13 @@ export function findStaleResponses(events) {
|
|
|
177
216
|
}
|
|
178
217
|
for (const group of byPath.values()) {
|
|
179
218
|
const reads = group.slice(-MAX_FLIGHTS_PER_PATH);
|
|
180
|
-
const found = raceIn(reads, events);
|
|
219
|
+
const found = raceIn(reads, events, all);
|
|
181
220
|
if (found !== undefined)
|
|
182
221
|
return [found];
|
|
183
222
|
}
|
|
184
223
|
return [];
|
|
185
224
|
}
|
|
186
|
-
function raceIn(reads, events) {
|
|
225
|
+
function raceIn(reads, events, all) {
|
|
187
226
|
for (const first of reads) {
|
|
188
227
|
for (const second of reads) {
|
|
189
228
|
if (first.id === second.id)
|
|
@@ -202,7 +241,7 @@ function raceIn(reads, events) {
|
|
|
202
241
|
continue;
|
|
203
242
|
// The race happened. Whether it MATTERS is whether the app acted on the loser — an app that
|
|
204
243
|
// drops superseded responses races just as visibly and is not broken.
|
|
205
|
-
if (!appliedAfter(events, first
|
|
244
|
+
if (!appliedAfter(events, first, all))
|
|
206
245
|
continue;
|
|
207
246
|
return {
|
|
208
247
|
kind: ContradictionKind.STALE_RESPONSE_APPLIED,
|
|
@@ -16,6 +16,11 @@ export declare function readsDomState(predicate: Predicate): boolean;
|
|
|
16
16
|
export declare function alreadyTrueHiddenMatch(predicate: Predicate, evidence: unknown): boolean;
|
|
17
17
|
/** What a green resting on hidden matches says instead of `yes`. See `hiddenMatchNote`. */
|
|
18
18
|
export declare const HIDDEN_MATCH_NOTE: string;
|
|
19
|
+
/**
|
|
20
|
+
* The same, for an element check, which asks by `state` and refuses `visible` ("element accepts:
|
|
21
|
+
* query, state, absent") — every hidden-match answer used to advise the field it refuses.
|
|
22
|
+
*/
|
|
23
|
+
export declare const HIDDEN_ELEMENT_MATCH_NOTE: string;
|
|
19
24
|
/**
|
|
20
25
|
* #1408: the post-action half of `alreadyTrueHiddenMatch`. A `text` clause beside a `net` clause is
|
|
21
26
|
* never already true, so a success template still hidden in the DOM passed with no caveat at all.
|
|
@@ -102,6 +102,13 @@ export function alreadyTrueHiddenMatch(predicate, evidence) {
|
|
|
102
102
|
export const HIDDEN_MATCH_NOTE = 'the declared consequence held only on a hidden element: a text or element check matches DOM ' +
|
|
103
103
|
'presence, not visibility, by default, so nothing here shows it is on screen. Add `visible: true` ' +
|
|
104
104
|
'if you meant "this is showing", not merely "this exists"';
|
|
105
|
+
/**
|
|
106
|
+
* The same, for an element check, which asks by `state` and refuses `visible` ("element accepts:
|
|
107
|
+
* query, state, absent") — every hidden-match answer used to advise the field it refuses.
|
|
108
|
+
*/
|
|
109
|
+
export const HIDDEN_ELEMENT_MATCH_NOTE = 'the declared consequence held only on a hidden element: an element check matches DOM presence, ' +
|
|
110
|
+
'not visibility, by default, so nothing here shows it is on screen. Add `state: "visible"` if you ' +
|
|
111
|
+
'meant "this is showing", not merely "this exists"';
|
|
105
112
|
/**
|
|
106
113
|
* #1408: the post-action half of `alreadyTrueHiddenMatch`. A `text` clause beside a `net` clause is
|
|
107
114
|
* never already true, so a success template still hidden in the DOM passed with no caveat at all.
|
|
@@ -111,17 +118,31 @@ export const HIDDEN_MATCH_NOTE = 'the declared consequence held only on a hidden
|
|
|
111
118
|
* `anyOf` carries only the branch that held, which is why each branch is tried against it.
|
|
112
119
|
*/
|
|
113
120
|
export function hiddenMatchNote(predicate, evidence) {
|
|
114
|
-
|
|
121
|
+
const kind = hiddenMatchKind(predicate, evidence);
|
|
122
|
+
if (kind === undefined)
|
|
123
|
+
return undefined;
|
|
124
|
+
return PredicateKind.ELEMENT === kind ? HIDDEN_ELEMENT_MATCH_NOTE : HIDDEN_MATCH_NOTE;
|
|
115
125
|
}
|
|
116
|
-
|
|
126
|
+
/** The kind of the first clause the green rests on that matched only hidden elements. */
|
|
127
|
+
function hiddenMatchKind(predicate, evidence) {
|
|
117
128
|
if (PredicateKind.ALL_OF === predicate.kind) {
|
|
118
129
|
if (!Array.isArray(evidence))
|
|
119
|
-
return
|
|
130
|
+
return undefined;
|
|
120
131
|
const each = evidence;
|
|
121
|
-
|
|
132
|
+
for (const [i, clause] of predicate.predicates.entries()) {
|
|
133
|
+
const kind = hiddenMatchKind(clause, each[i]);
|
|
134
|
+
if (kind !== undefined)
|
|
135
|
+
return kind;
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
122
138
|
}
|
|
123
139
|
if (PredicateKind.ANY_OF === predicate.kind) {
|
|
124
|
-
|
|
140
|
+
for (const clause of predicate.predicates) {
|
|
141
|
+
const kind = hiddenMatchKind(clause, evidence);
|
|
142
|
+
if (kind !== undefined)
|
|
143
|
+
return kind;
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
125
146
|
}
|
|
126
|
-
return alreadyTrueHiddenMatch(predicate, evidence);
|
|
147
|
+
return alreadyTrueHiddenMatch(predicate, evidence) ? predicate.kind : undefined;
|
|
127
148
|
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* and has no evidence behind it.
|
|
15
15
|
*/
|
|
16
16
|
import { PredicateKind, ReticleCommand } from '@reticlehq/core';
|
|
17
|
+
import { textPredicateQuery } from '../question/predicate/predicate-element.js';
|
|
17
18
|
/** The properties that mean nothing without a before-reading. Mirrors `RELATIVE` in property.ts. */
|
|
18
19
|
const NEEDS_BASELINE = new Set([
|
|
19
20
|
'changed',
|
|
@@ -72,12 +73,7 @@ async function readStateValue(session, predicate) {
|
|
|
72
73
|
return 'boolean' === typeof reply.found ? { taken: true, value: reply.value } : undefined;
|
|
73
74
|
}
|
|
74
75
|
async function readText(session, predicate) {
|
|
75
|
-
const query =
|
|
76
|
-
...(predicate.contains === undefined ? {} : { text: predicate.contains }),
|
|
77
|
-
...(predicate.scope === undefined
|
|
78
|
-
? {}
|
|
79
|
-
: { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
|
|
80
|
-
};
|
|
76
|
+
const query = textPredicateQuery(predicate, session.sdkVersion);
|
|
81
77
|
const match = await session.command(ReticleCommand.MATCH, { query });
|
|
82
78
|
if (!match.ok)
|
|
83
79
|
return undefined;
|
|
@@ -47,8 +47,15 @@ interface CoverageStatement {
|
|
|
47
47
|
* not depend on the evidence.
|
|
48
48
|
*/
|
|
49
49
|
export declare function impeachesCapture(kind: BlindSpotKind): boolean;
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Compose the coverage statement. `full` (no note) when nothing was unobserved.
|
|
52
|
+
*
|
|
53
|
+
* `windowSpots`, when given, are the same spots counted over the judged window only. An impeaching
|
|
54
|
+
* kind is then labelled by what the WINDOW saw: its window count when it dropped events there, and
|
|
55
|
+
* as an earlier-in-the-session fact when it did not. Bounding kinds are standing facts of the page
|
|
56
|
+
* and keep their session-wide label.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildCoverageStatement(spots: readonly BlindSpot[], windowSpots?: readonly BlindSpot[]): CoverageStatement;
|
|
52
59
|
/**
|
|
53
60
|
* Reduce a window's BLIND_SPOT events to one spot per kind — the LATEST reported count wins (the sensor
|
|
54
61
|
* emits only on change, so the last value is the live count). This is how a result's coverage is derived
|
|
@@ -88,6 +95,9 @@ interface AbsencePredicate {
|
|
|
88
95
|
absent?: boolean;
|
|
89
96
|
query?: {
|
|
90
97
|
scope?: unknown;
|
|
98
|
+
role?: string | undefined;
|
|
99
|
+
by?: string | undefined;
|
|
100
|
+
value?: string | undefined;
|
|
91
101
|
};
|
|
92
102
|
predicate?: AbsencePredicate;
|
|
93
103
|
}
|
|
@@ -98,7 +108,8 @@ interface AbsencePredicate {
|
|
|
98
108
|
*
|
|
99
109
|
* Fires on three blind-spot kinds:
|
|
100
110
|
* - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
|
|
101
|
-
* - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element
|
|
111
|
+
* - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element (scoped:
|
|
112
|
+
* skipped when the queried role is structurally page-level, like dialog or a landmark)
|
|
102
113
|
* - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
|
|
103
114
|
*/
|
|
104
115
|
export declare function absenceBlindSpotNote(predicate: AbsencePredicate, spots: readonly BlindSpot[]): string | undefined;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// The kind enum lives in core (it crosses the wire in a BLIND_SPOT event); re-exported here for the
|
|
8
8
|
// honesty-side callers.
|
|
9
9
|
export { BlindSpotKind } from '@reticlehq/core';
|
|
10
|
-
import { BlindSpotKind, EventType, PredicateKind, ReticleEnv, TRANSPORT_LIMITS, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
|
|
10
|
+
import { BlindSpotKind, EventType, PredicateKind, QueryBy, ReticleEnv, TRANSPORT_LIMITS, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
|
|
11
11
|
/**
|
|
12
12
|
* Whether the observation window saw everything it was asked about.
|
|
13
13
|
*
|
|
@@ -43,7 +43,7 @@ const LABEL = {
|
|
|
43
43
|
// Not a tally — a fact about the app's wiring, phrased as what the EMPTY state channel means. An
|
|
44
44
|
// agent reading `stateDiffs: []` otherwise reads "the app changed no state", which is a claim
|
|
45
45
|
// nothing here can support. Names the one-line fix, because the reader is the one who can apply it.
|
|
46
|
-
[BlindSpotKind.UNWATCHED_STATE]: () =>
|
|
46
|
+
[BlindSpotKind.UNWATCHED_STATE]: () => "no subscribable store is registered, so NO state change is observed — an empty stateDiffs here means unwatched, not unchanged (import { registerStore } from '@reticlehq/browser' and call registerStore(name, store) with a subscribable store; for component-local React state, import { useReticleStore } from '@reticlehq/react/store' and call useReticleStore(name, value), or inspect it with reticle_look { action: 'state', ref: '...' })",
|
|
47
47
|
[BlindSpotKind.WRAPPED_NETWORK]: () => 'fetch was already wrapped before Reticle, so recorded requests may differ from what was sent',
|
|
48
48
|
// A fact about the app's wiring, not a tally. Says what a network view WITHOUT ipc:// records
|
|
49
49
|
// MEANS, because that state here is indistinguishable from "this app made no backend calls" —
|
|
@@ -72,8 +72,21 @@ const LABEL = {
|
|
|
72
72
|
export function impeachesCapture(kind) {
|
|
73
73
|
return kind === BlindSpotKind.RATE_LIMITED;
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Bridge sampling that happened in the session but not in the window being judged (#1414). The
|
|
77
|
+
* window's own label says "this window is SAMPLED" and asks for a re-run, which is false here: the
|
|
78
|
+
* verdict's capture is whole, and repeating the drive would only repeat a clean check.
|
|
79
|
+
*/
|
|
80
|
+
const RATE_LIMITED_ELSEWHERE = (n) => `${String(n)} event${1 === n ? '' : 's'} dropped by the bridge rate cap earlier in this session, none in this window, so this result's capture is complete`;
|
|
81
|
+
/**
|
|
82
|
+
* Compose the coverage statement. `full` (no note) when nothing was unobserved.
|
|
83
|
+
*
|
|
84
|
+
* `windowSpots`, when given, are the same spots counted over the judged window only. An impeaching
|
|
85
|
+
* kind is then labelled by what the WINDOW saw: its window count when it dropped events there, and
|
|
86
|
+
* as an earlier-in-the-session fact when it did not. Bounding kinds are standing facts of the page
|
|
87
|
+
* and keep their session-wide label.
|
|
88
|
+
*/
|
|
89
|
+
export function buildCoverageStatement(spots, windowSpots) {
|
|
77
90
|
const present = spots.filter((s) => s.count > 0);
|
|
78
91
|
if (0 === present.length)
|
|
79
92
|
return { coverage: Coverage.FULL, spots: [] };
|
|
@@ -85,7 +98,15 @@ export function buildCoverageStatement(spots) {
|
|
|
85
98
|
// daemon can report one, and `LABEL[kind](count)` threw a TypeError on the verdict path when it
|
|
86
99
|
// did — turning "there is something I could not see" into a crashed assert, which is worse than
|
|
87
100
|
// either the caveat or the silence. Unknown kinds degrade to their own name.
|
|
88
|
-
const
|
|
101
|
+
const known = (s) => 'function' === typeof LABEL[s.kind] ? LABEL[s.kind](s.count) : `${s.kind} (${String(s.count)})`;
|
|
102
|
+
const label = (s) => {
|
|
103
|
+
if (windowSpots === undefined || !impeachesCapture(s.kind))
|
|
104
|
+
return known(s);
|
|
105
|
+
const inWindow = windowSpots.find((w) => w.kind === s.kind)?.count ?? 0;
|
|
106
|
+
return 0 < inWindow
|
|
107
|
+
? known({ kind: s.kind, count: inWindow })
|
|
108
|
+
: RATE_LIMITED_ELSEWHERE(s.count);
|
|
109
|
+
};
|
|
89
110
|
const note = `${Coverage.PARTIAL} — ${present.map(label).join(', ')}`;
|
|
90
111
|
return { coverage: Coverage.PARTIAL, note, spots: present };
|
|
91
112
|
}
|
|
@@ -145,7 +166,8 @@ export function blindSpotsFromState(state, runtime) {
|
|
|
145
166
|
return spotsForRuntime(spots, runtime);
|
|
146
167
|
}
|
|
147
168
|
/**
|
|
148
|
-
* Events the BROWSER's own transport queue threw
|
|
169
|
+
* Events lost in transport inside this window, or 0: the BROWSER's own transport queue threw them
|
|
170
|
+
* away, or the daemon dropped a frame from a live session that it could not read (#1413).
|
|
149
171
|
*
|
|
150
172
|
* `RATE_LIMITED` — the BRIDGE sampling because events arrived faster than its per-second cap — is
|
|
151
173
|
* already the one blind spot that `impeachesCapture`, on the reasoning that a green over a window
|
|
@@ -170,6 +192,18 @@ function droppedByTransport(events) {
|
|
|
170
192
|
}
|
|
171
193
|
return dropped;
|
|
172
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Roles that are structurally page-level and can never be a virtualized list row. A dialog is
|
|
197
|
+
* always a top-level overlay; a landmark is a page-structural element. Absence of one of these
|
|
198
|
+
* is not threatened by rows a virtualizer unmounted off-screen (#1236).
|
|
199
|
+
*/
|
|
200
|
+
const NEVER_VIRTUALIZED_ROLES = new Set([
|
|
201
|
+
'dialog',
|
|
202
|
+
'alertdialog',
|
|
203
|
+
'banner',
|
|
204
|
+
'contentinfo',
|
|
205
|
+
'main',
|
|
206
|
+
]);
|
|
173
207
|
/**
|
|
174
208
|
* When an absence assertion targets a page with regions Reticle cannot observe, "the element is
|
|
175
209
|
* absent" means only "it is absent in what I CAN see". Returns a note when that distinction
|
|
@@ -177,7 +211,8 @@ function droppedByTransport(events) {
|
|
|
177
211
|
*
|
|
178
212
|
* Fires on three blind-spot kinds:
|
|
179
213
|
* - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
|
|
180
|
-
* - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element
|
|
214
|
+
* - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element (scoped:
|
|
215
|
+
* skipped when the queried role is structurally page-level, like dialog or a landmark)
|
|
181
216
|
* - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
|
|
182
217
|
*/
|
|
183
218
|
export function absenceBlindSpotNote(predicate, spots) {
|
|
@@ -195,11 +230,14 @@ export function absenceBlindSpotNote(predicate, spots) {
|
|
|
195
230
|
}
|
|
196
231
|
if (PredicateKind.ELEMENT !== predicate.kind || true !== predicate.absent)
|
|
197
232
|
return undefined;
|
|
233
|
+
const role = predicate.query?.role ??
|
|
234
|
+
(QueryBy.ROLE === predicate.query?.by ? predicate.query.value : undefined);
|
|
198
235
|
const relevant = spots.filter((spot) => spot.count > 0 &&
|
|
199
236
|
(spot.kind === BlindSpotKind.CROSS_ORIGIN_IFRAME
|
|
200
237
|
? undefined !== predicate.query?.scope
|
|
201
|
-
: spot.kind === BlindSpotKind.VIRTUALIZED_UNMOUNTED
|
|
202
|
-
|
|
238
|
+
: spot.kind === BlindSpotKind.VIRTUALIZED_UNMOUNTED
|
|
239
|
+
? undefined === role || !NEVER_VIRTUALIZED_ROLES.has(role)
|
|
240
|
+
: spot.kind === BlindSpotKind.CLOSED_SHADOW_ROOT));
|
|
203
241
|
if (0 === relevant.length)
|
|
204
242
|
return undefined;
|
|
205
243
|
const statement = buildCoverageStatement(relevant);
|
|
@@ -210,7 +248,7 @@ export function transportGapNote(events) {
|
|
|
210
248
|
const dropped = droppedByTransport(events);
|
|
211
249
|
return 0 === dropped
|
|
212
250
|
? undefined
|
|
213
|
-
:
|
|
251
|
+
: `${String(dropped)} event(s) in this window were lost in transport (a browser queue overflow, or a frame the daemon could not read), so events that would have contradicted this may never have arrived`;
|
|
214
252
|
}
|
|
215
253
|
/**
|
|
216
254
|
* Is the state channel dark?
|