@reticlehq/engine 3.1.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/LICENSE +202 -0
- package/README.md +36 -0
- package/dist/disagreement/body-failures.d.ts +4 -0
- package/dist/disagreement/body-failures.js +113 -0
- package/dist/disagreement/contradiction-evidence.d.ts +122 -0
- package/dist/disagreement/contradiction-evidence.js +194 -0
- package/dist/disagreement/contradiction-folds.d.ts +61 -0
- package/dist/disagreement/contradiction-folds.js +71 -0
- package/dist/disagreement/contradiction-types.d.ts +164 -0
- package/dist/disagreement/contradiction-types.js +1 -0
- package/dist/disagreement/contradictions.d.ts +5 -0
- package/dist/disagreement/contradictions.js +613 -0
- package/dist/disagreement/echo-mismatch.d.ts +10 -0
- package/dist/disagreement/echo-mismatch.js +299 -0
- package/dist/disagreement/reconcile.d.ts +39 -0
- package/dist/disagreement/reconcile.js +211 -0
- package/dist/disagreement/stale-response.d.ts +3 -0
- package/dist/disagreement/stale-response.js +186 -0
- package/dist/disagreement/unit-mismatch.d.ts +16 -0
- package/dist/disagreement/unit-mismatch.js +167 -0
- package/dist/disagreement/witness-disagreement.d.ts +42 -0
- package/dist/disagreement/witness-disagreement.js +43 -0
- package/dist/evidence/accepted-write.d.ts +35 -0
- package/dist/evidence/accepted-write.js +54 -0
- package/dist/evidence/already-true.d.ts +16 -0
- package/dist/evidence/already-true.js +89 -0
- package/dist/evidence/blind-spots.d.ts +133 -0
- package/dist/evidence/blind-spots.js +253 -0
- package/dist/evidence/body-capture-remedy.d.ts +42 -0
- package/dist/evidence/body-capture-remedy.js +96 -0
- package/dist/evidence/gap-ledger.d.ts +52 -0
- package/dist/evidence/gap-ledger.js +63 -0
- package/dist/evidence/honesty.d.ts +113 -0
- package/dist/evidence/honesty.js +105 -0
- package/dist/evidence/instrumentation-gaps.d.ts +91 -0
- package/dist/evidence/instrumentation-gaps.js +102 -0
- package/dist/evidence/learned-guards.d.ts +75 -0
- package/dist/evidence/learned-guards.js +78 -0
- package/dist/evidence/observability.d.ts +38 -0
- package/dist/evidence/observability.js +40 -0
- package/dist/evidence/page-teardown.d.ts +15 -0
- package/dist/evidence/page-teardown.js +17 -0
- package/dist/evidence/step-effect.d.ts +41 -0
- package/dist/evidence/step-effect.js +27 -0
- package/dist/evidence/uncaptured-bodies.d.ts +23 -0
- package/dist/evidence/uncaptured-bodies.js +41 -0
- package/dist/evidence/undeclared-change.d.ts +51 -0
- package/dist/evidence/undeclared-change.js +56 -0
- package/dist/evidence/unread-outcome.d.ts +10 -0
- package/dist/evidence/unread-outcome.js +77 -0
- package/dist/evidence/unsettled.d.ts +58 -0
- package/dist/evidence/unsettled.js +127 -0
- package/dist/evidence/verdict-intent-gap.d.ts +30 -0
- package/dist/evidence/verdict-intent-gap.js +35 -0
- package/dist/evidence/verified.d.ts +158 -0
- package/dist/evidence/verified.js +378 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +25 -0
- package/dist/question/declared.d.ts +74 -0
- package/dist/question/declared.js +171 -0
- package/dist/question/lineage.d.ts +52 -0
- package/dist/question/lineage.js +122 -0
- package/dist/question/predicate/net-evidence.d.ts +21 -0
- package/dist/question/predicate/net-evidence.js +81 -0
- package/dist/question/predicate/observed-in-window.d.ts +24 -0
- package/dist/question/predicate/observed-in-window.js +38 -0
- package/dist/question/predicate/predicate-asks.d.ts +28 -0
- package/dist/question/predicate/predicate-asks.js +46 -0
- package/dist/question/predicate/predicate-console.d.ts +13 -0
- package/dist/question/predicate/predicate-console.js +138 -0
- package/dist/question/predicate/predicate-element.d.ts +13 -0
- package/dist/question/predicate/predicate-element.js +214 -0
- package/dist/question/predicate/predicate-eval-kit.d.ts +90 -0
- package/dist/question/predicate/predicate-eval-kit.js +126 -0
- package/dist/question/predicate/predicate-eval.d.ts +24 -0
- package/dist/question/predicate/predicate-eval.js +710 -0
- package/dist/question/predicate/predicate-parse.d.ts +15 -0
- package/dist/question/predicate/predicate-parse.js +173 -0
- package/dist/question/predicate/predicate-precheck.d.ts +8 -0
- package/dist/question/predicate/predicate-precheck.js +41 -0
- package/dist/question/predicate/predicate-request-body.d.ts +50 -0
- package/dist/question/predicate/predicate-request-body.js +120 -0
- package/dist/question/predicate/predicate-route.d.ts +66 -0
- package/dist/question/predicate/predicate-route.js +293 -0
- package/dist/question/predicate/predicate-schema.d.ts +170 -0
- package/dist/question/predicate/predicate-schema.js +509 -0
- package/dist/question/predicate/predicate-session.d.ts +72 -0
- package/dist/question/predicate/predicate-session.js +1 -0
- package/dist/question/predicate/predicate-to-links.d.ts +13 -0
- package/dist/question/predicate/predicate-to-links.js +38 -0
- package/dist/question/predicate/predicate.d.ts +26 -0
- package/dist/question/predicate/predicate.js +785 -0
- package/dist/question/predicate/property.d.ts +102 -0
- package/dist/question/predicate/property.js +135 -0
- package/dist/question/predicate/split-text-miss.d.ts +32 -0
- package/dist/question/predicate/split-text-miss.js +51 -0
- package/dist/question/predicate/testid-near-miss.d.ts +22 -0
- package/dist/question/predicate/testid-near-miss.js +33 -0
- package/dist/question/reaction.d.ts +17 -0
- package/dist/question/reaction.js +67 -0
- package/dist/window/adversary.d.ts +28 -0
- package/dist/window/adversary.js +90 -0
- package/dist/window/ambient.d.ts +63 -0
- package/dist/window/ambient.js +76 -0
- package/dist/window/appearance-budget.d.ts +41 -0
- package/dist/window/appearance-budget.js +47 -0
- package/dist/window/asset-noise.d.ts +42 -0
- package/dist/window/asset-noise.js +35 -0
- package/dist/window/body-relevance.d.ts +54 -0
- package/dist/window/body-relevance.js +78 -0
- package/dist/window/byte-size.d.ts +1 -0
- package/dist/window/byte-size.js +16 -0
- package/dist/window/engine-host.d.ts +35 -0
- package/dist/window/engine-host.js +20 -0
- package/dist/window/event-filters.d.ts +121 -0
- package/dist/window/event-filters.js +215 -0
- package/dist/window/json-salvage.d.ts +33 -0
- package/dist/window/json-salvage.js +96 -0
- package/dist/window/network-detail-merge.d.ts +8 -0
- package/dist/window/network-detail-merge.js +89 -0
- package/dist/window/ring-buffer.d.ts +41 -0
- package/dist/window/ring-buffer.js +152 -0
- package/package.json +71 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { ContradictionKind, EventType } from '@reticlehq/core';
|
|
2
|
+
function pathOf(url) {
|
|
3
|
+
const q = url.indexOf('?');
|
|
4
|
+
return -1 === q ? url : url.slice(0, q);
|
|
5
|
+
}
|
|
6
|
+
function queryOf(url) {
|
|
7
|
+
const q = url.indexOf('?');
|
|
8
|
+
return -1 === q ? '' : url.slice(q + 1);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parameters that ENUMERATE a collection rather than select within it.
|
|
12
|
+
*
|
|
13
|
+
* Two overlapping reads that differ only in these are a fan-out, not a race: an app fetching page 0
|
|
14
|
+
* and page 5 in parallel wants both, and whichever lands last is not overwriting the other. Measured
|
|
15
|
+
* against a synthetic dashboard doing parallel pagination — every run reported a race, because the
|
|
16
|
+
* requests do overlap and do settle out of order, and the original rule looked no further than that.
|
|
17
|
+
*
|
|
18
|
+
* A filter race differs in a SELECTING parameter (`status`, `q`, a date range): the second request
|
|
19
|
+
* makes the first obsolete, both answer into the same view, and the slower one wins.
|
|
20
|
+
*/
|
|
21
|
+
const ENUMERATING_PARAMS = new Set([
|
|
22
|
+
'page',
|
|
23
|
+
'offset',
|
|
24
|
+
'cursor',
|
|
25
|
+
'limit',
|
|
26
|
+
'size',
|
|
27
|
+
'per_page',
|
|
28
|
+
'perPage',
|
|
29
|
+
'pageSize',
|
|
30
|
+
'after',
|
|
31
|
+
'before',
|
|
32
|
+
'start',
|
|
33
|
+
'end',
|
|
34
|
+
]);
|
|
35
|
+
/** Whether the two queries differ ONLY in how much of the same collection they ask for. */
|
|
36
|
+
function differsOnlyByEnumeration(first, second) {
|
|
37
|
+
const a = new URLSearchParams(first);
|
|
38
|
+
const b = new URLSearchParams(second);
|
|
39
|
+
const keys = new Set([...a.keys(), ...b.keys()]);
|
|
40
|
+
let differed = false;
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
if (a.get(key) === b.get(key))
|
|
43
|
+
continue;
|
|
44
|
+
if (!ENUMERATING_PARAMS.has(key))
|
|
45
|
+
return false;
|
|
46
|
+
differed = true;
|
|
47
|
+
}
|
|
48
|
+
return differed;
|
|
49
|
+
}
|
|
50
|
+
/** Pair NET_PENDING with its NET_REQUEST by the id both carry. Unpaired events are still in flight. */
|
|
51
|
+
function flights(events) {
|
|
52
|
+
const issued = new Map();
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const event of events) {
|
|
55
|
+
const id = 'string' === typeof event.data['id'] ? event.data['id'] : undefined;
|
|
56
|
+
if (id === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
const at = 'number' === typeof event.t ? event.t : 0;
|
|
59
|
+
if (event.type === EventType.NET_PENDING) {
|
|
60
|
+
const url = 'string' === typeof event.data['url'] ? event.data['url'] : '';
|
|
61
|
+
const method = 'string' === typeof event.data['method'] ? event.data['method'] : 'GET';
|
|
62
|
+
issued.set(id, { url, method, at });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
66
|
+
continue;
|
|
67
|
+
const start = issued.get(id);
|
|
68
|
+
if (start === undefined)
|
|
69
|
+
continue; // started before this window — its ordering is unknowable
|
|
70
|
+
out.push({
|
|
71
|
+
id,
|
|
72
|
+
url: start.url,
|
|
73
|
+
method: start.method.toUpperCase(),
|
|
74
|
+
issuedAt: start.at,
|
|
75
|
+
settledAt: at,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Most recent flights compared per endpoint.
|
|
82
|
+
*
|
|
83
|
+
* The comparison is pairwise, so an unbounded window is quadratic: measured at 548ms for 2000
|
|
84
|
+
* concurrent reads of one endpoint, paid on EVERY verdict. A verdict that costs half a second is a
|
|
85
|
+
* verdict agents stop asking for. Racing requests are adjacent in time by definition, so the most
|
|
86
|
+
* recent flights are where a race can be; older ones cannot overlap them anyway.
|
|
87
|
+
*
|
|
88
|
+
* Bounded rather than silent: this is a detection ceiling, not a truncation of reported data — a race
|
|
89
|
+
* among more than this many simultaneous reads of ONE endpoint goes unreported, and that is a
|
|
90
|
+
* deliberate trade for a hot path that runs on every assert.
|
|
91
|
+
*/
|
|
92
|
+
const MAX_FLIGHTS_PER_PATH = 60;
|
|
93
|
+
/** The one contradiction, or none. Reported once per window — a race is a fact about the window. */
|
|
94
|
+
/**
|
|
95
|
+
* How long after a superseded response lands we look for the app reacting to it.
|
|
96
|
+
*
|
|
97
|
+
* A handler runs on the microtask that resolves the fetch; the render follows within a frame or two.
|
|
98
|
+
* Beyond this the connection between the response and any change is speculation.
|
|
99
|
+
*/
|
|
100
|
+
const APPLY_WINDOW_MS = 500;
|
|
101
|
+
/**
|
|
102
|
+
* How far BEFORE the completion stamp a reaction still counts as reacting to it.
|
|
103
|
+
*
|
|
104
|
+
* Not a fudge factor — a correction for which of the two is stamped first. `NET_REQUEST` is emitted
|
|
105
|
+
* when the observer's wrapper sees the fetch settle, and the app's own handler runs on the same
|
|
106
|
+
* microtask; in practice the app's state write, signal and DOM text land at or a millisecond BEFORE
|
|
107
|
+
* the completion event that caused them.
|
|
108
|
+
*
|
|
109
|
+
* So a strictly-forward window could not see the application at all, and the rule could never fire on
|
|
110
|
+
* real traffic however plainly the app misbehaved. Sixteen passing unit tests did not catch that,
|
|
111
|
+
* because synthetic events are written with the reaction placed after the cause.
|
|
112
|
+
*/
|
|
113
|
+
const APPLY_SLACK_MS = 100;
|
|
114
|
+
/**
|
|
115
|
+
* Did the app REACT to this response — did anything user-visible move after it landed?
|
|
116
|
+
*
|
|
117
|
+
* The question the rule could not previously ask, and the difference between a defect and a
|
|
118
|
+
* correctly-handled race. An app that guards against superseded responses still RACES: two requests
|
|
119
|
+
* overlap and settle out of order exactly as before. What it does not do is act on the loser.
|
|
120
|
+
*
|
|
121
|
+
* Without this check the rule fires identically on both, which is worse than not having it: a
|
|
122
|
+
* detector that accuses correct code teaches people to ignore it, and it takes the true positives
|
|
123
|
+
* down with it.
|
|
124
|
+
*/
|
|
125
|
+
function appliedAfter(events, settledAt) {
|
|
126
|
+
return events.some((event) => {
|
|
127
|
+
if (event.t < settledAt - APPLY_SLACK_MS || event.t > settledAt + APPLY_WINDOW_MS)
|
|
128
|
+
return false;
|
|
129
|
+
return (event.type === EventType.STATE_CHANGE ||
|
|
130
|
+
event.type === EventType.SIGNAL ||
|
|
131
|
+
event.type === EventType.DOM_TEXT ||
|
|
132
|
+
event.type === EventType.DOM_ADDED ||
|
|
133
|
+
event.type === EventType.DOM_REMOVED ||
|
|
134
|
+
event.type === EventType.DOM_ATTR);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export function findStaleResponses(events) {
|
|
138
|
+
// Grouped by path first: two reads of DIFFERENT endpoints can never race, and comparing them was
|
|
139
|
+
// the bulk of the work on any real page, which talks to many endpoints at once.
|
|
140
|
+
const byPath = new Map();
|
|
141
|
+
for (const flight of flights(events)) {
|
|
142
|
+
if (flight.method !== 'GET')
|
|
143
|
+
continue;
|
|
144
|
+
const path = pathOf(flight.url);
|
|
145
|
+
const group = byPath.get(path) ?? [];
|
|
146
|
+
group.push(flight);
|
|
147
|
+
byPath.set(path, group);
|
|
148
|
+
}
|
|
149
|
+
for (const group of byPath.values()) {
|
|
150
|
+
const reads = group.slice(-MAX_FLIGHTS_PER_PATH);
|
|
151
|
+
const found = raceIn(reads, events);
|
|
152
|
+
if (found !== undefined)
|
|
153
|
+
return [found];
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
function raceIn(reads, events) {
|
|
158
|
+
for (const first of reads) {
|
|
159
|
+
for (const second of reads) {
|
|
160
|
+
if (first.id === second.id)
|
|
161
|
+
continue;
|
|
162
|
+
if (second.issuedAt <= first.issuedAt)
|
|
163
|
+
continue; // `first` must be the earlier request
|
|
164
|
+
if (second.issuedAt >= first.settledAt)
|
|
165
|
+
continue; // sequential, not overlapping
|
|
166
|
+
if (second.settledAt >= first.settledAt)
|
|
167
|
+
continue; // settled in order — no race
|
|
168
|
+
if (queryOf(first.url) === queryOf(second.url))
|
|
169
|
+
continue; // a retry, not a superseding query
|
|
170
|
+
// Parallel pagination is not a race — see differsOnlyByEnumeration.
|
|
171
|
+
if (differsOnlyByEnumeration(queryOf(first.url), queryOf(second.url)))
|
|
172
|
+
continue;
|
|
173
|
+
// The race happened. Whether it MATTERS is whether the app acted on the loser — an app that
|
|
174
|
+
// drops superseded responses races just as visibly and is not broken.
|
|
175
|
+
if (!appliedAfter(events, first.settledAt))
|
|
176
|
+
continue;
|
|
177
|
+
return {
|
|
178
|
+
kind: ContradictionKind.STALE_RESPONSE_APPLIED,
|
|
179
|
+
claim: `both reads of ${pathOf(first.url)} returned successfully and the page settled`,
|
|
180
|
+
counter: `the SUPERSEDED request (${queryOf(first.url)}) settled ${String(Math.max(0, first.settledAt - second.settledAt))}ms AFTER the one that replaced it (${queryOf(second.url)}), so the screen is showing the older query's data`,
|
|
181
|
+
detail: 'a filter/search race: the newer request was issued while the older was still in flight, and the older answered last, so whichever query the server happens to be slower at wins — unless the app cancels superseded requests or drops responses that no longer match current state',
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ReticleEvent } from '@reticlehq/core';
|
|
2
|
+
import type { OwnContradiction } from './contradiction-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* @param prior events from BEFORE the window, used only to learn what the API has stated.
|
|
5
|
+
*
|
|
6
|
+
* The scale error is a disagreement with a value the API gave EARLIER — by definition before the
|
|
7
|
+
* action that sends it back. `reticle_assert` scopes its window to the last act's cursor, so the
|
|
8
|
+
* stating response falls outside it and `known` is empty exactly when it matters. Measured live on
|
|
9
|
+
* the payments panel: `reticle_observe` over a wide window reported the mismatch while `assert` on
|
|
10
|
+
* the same session reported none — the verdict tool, the one an agent gates on, was the blind one.
|
|
11
|
+
*
|
|
12
|
+
* Prior events TEACH, they are never themselves findings: widening the window instead would make
|
|
13
|
+
* every other rule blame this action for events it did not cause, and would re-report every earlier
|
|
14
|
+
* mistake on every assert.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findUnitMismatches(events: readonly ReticleEvent[], prior?: readonly ReticleEvent[]): OwnContradiction[];
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { ContradictionKind, EventType } from '@reticlehq/core';
|
|
2
|
+
/**
|
|
3
|
+
* The app sent a money value back in a DIFFERENT unit than the API gave it.
|
|
4
|
+
*
|
|
5
|
+
* Payment APIs overwhelmingly speak minor units — Stripe, Razorpay, Adyen, PayPal all state amounts
|
|
6
|
+
* in paise/cents as integers. A UI renders that as a major-unit string, and the bug is writing the
|
|
7
|
+
* rendered number back into the field the integer came from.
|
|
8
|
+
*
|
|
9
|
+
* Measured on a real payments dashboard: `GET /payments` returns `amount: 118701` for a payment, the
|
|
10
|
+
* row renders "₹1,187.01", and the refund posts `{"amount": 1187.01}` into the same field. The server
|
|
11
|
+
* takes 1187 paise and answers `200 {"status": "processed"}`. That is a 100x UNDER-REFUND, and every
|
|
12
|
+
* channel agrees it worked: the status is 200, the payload says processed, the UI advances, the page
|
|
13
|
+
* settles, and the number in the request is exactly the number on the screen. Nothing disagrees,
|
|
14
|
+
* because the disagreement is with a value the API returned EARLIER in the session.
|
|
15
|
+
*
|
|
16
|
+
* Which is the point: this is only visible to something holding the whole request timeline with
|
|
17
|
+
* bodies. A snapshot cannot see it, a status column cannot see it, and a human reading the request
|
|
18
|
+
* sees the amount they expected.
|
|
19
|
+
*
|
|
20
|
+
* Not a heuristic about decimals. Firing on "an amount had a fractional part" would accuse every API
|
|
21
|
+
* that legitimately uses major units. This fires only when the SAME field of the SAME entity was
|
|
22
|
+
* observed at a different scale — a comparison, not a guess.
|
|
23
|
+
*/
|
|
24
|
+
/** Fields worth comparing. Deliberately short: money, not every number an app sends. */
|
|
25
|
+
const MONEY_FIELDS = new Set(['amount', 'value', 'price', 'total', 'fee', 'cost', 'balance']);
|
|
26
|
+
/**
|
|
27
|
+
* Scales that indicate a minor/major confusion. 100 covers two-decimal currencies; 1000 covers the
|
|
28
|
+
* three-decimal ones (KWD, BHD, JOD, TND).
|
|
29
|
+
*/
|
|
30
|
+
const SCALES = [100, 1000];
|
|
31
|
+
/**
|
|
32
|
+
* Prefixed ids (`pay_NkT10001`) and uuids, matched anywhere in a URL or a string field.
|
|
33
|
+
*
|
|
34
|
+
* Numeric ids are handled separately by path segment: `/api/orders/9/capture` is at least as common
|
|
35
|
+
* as a prefixed id, and a bare `9` cannot be pattern-matched out of arbitrary text without matching
|
|
36
|
+
* every other number too.
|
|
37
|
+
*/
|
|
38
|
+
const ID_PATTERN = /[A-Za-z]{2,}_[A-Za-z0-9]{2,}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}/g;
|
|
39
|
+
function parse(raw) {
|
|
40
|
+
if (typeof raw !== 'string' || 0 === raw.length)
|
|
41
|
+
return undefined;
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(raw);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Every (id, field, value) triple in a payload, from objects that carry an id of their own. */
|
|
50
|
+
function moneyByEntity(node, into) {
|
|
51
|
+
if (Array.isArray(node)) {
|
|
52
|
+
for (const item of node)
|
|
53
|
+
moneyByEntity(item, into);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (typeof node !== 'object' || null === node)
|
|
57
|
+
return;
|
|
58
|
+
const record = node;
|
|
59
|
+
// An id may arrive as a number (`{"id": 9}`) — normalised so a numeric path segment matches it.
|
|
60
|
+
const raw = record['id'];
|
|
61
|
+
const id = 'string' === typeof raw ? raw : 'number' === typeof raw ? String(raw) : undefined;
|
|
62
|
+
if (id !== undefined) {
|
|
63
|
+
for (const [key, value] of Object.entries(record)) {
|
|
64
|
+
if (!MONEY_FIELDS.has(key) || typeof value !== 'number')
|
|
65
|
+
continue;
|
|
66
|
+
const fields = into.get(id) ?? new Map();
|
|
67
|
+
fields.set(key, value);
|
|
68
|
+
into.set(id, fields);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const value of Object.values(record))
|
|
72
|
+
moneyByEntity(value, into);
|
|
73
|
+
}
|
|
74
|
+
/** Ids named anywhere in a URL or a request payload — how a write says which entity it targets. */
|
|
75
|
+
function idsIn(url, body) {
|
|
76
|
+
const found = new Set(url.match(ID_PATTERN) ?? []);
|
|
77
|
+
// Numeric path segments: `/api/orders/9/capture` names entity 9.
|
|
78
|
+
for (const segment of url.split('?')[0]?.split('/') ?? []) {
|
|
79
|
+
if (segment.length > 0 && /^\d+$/.test(segment))
|
|
80
|
+
found.add(segment);
|
|
81
|
+
}
|
|
82
|
+
if ('object' === typeof body && body !== null) {
|
|
83
|
+
for (const value of Object.values(body)) {
|
|
84
|
+
if ('string' === typeof value)
|
|
85
|
+
for (const id of value.match(ID_PATTERN) ?? [])
|
|
86
|
+
found.add(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return Array.from(found);
|
|
90
|
+
}
|
|
91
|
+
/** The scale between a known value and a sent one, or undefined when they are consistent. */
|
|
92
|
+
function scaleBetween(known, sent) {
|
|
93
|
+
if (0 === sent || 0 === known)
|
|
94
|
+
return undefined;
|
|
95
|
+
for (const scale of SCALES) {
|
|
96
|
+
// A tolerance, because the major-unit form is a rounded render of the minor one.
|
|
97
|
+
if (Math.abs(known - sent * scale) <= scale / 2)
|
|
98
|
+
return scale;
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @param prior events from BEFORE the window, used only to learn what the API has stated.
|
|
104
|
+
*
|
|
105
|
+
* The scale error is a disagreement with a value the API gave EARLIER — by definition before the
|
|
106
|
+
* action that sends it back. `reticle_assert` scopes its window to the last act's cursor, so the
|
|
107
|
+
* stating response falls outside it and `known` is empty exactly when it matters. Measured live on
|
|
108
|
+
* the payments panel: `reticle_observe` over a wide window reported the mismatch while `assert` on
|
|
109
|
+
* the same session reported none — the verdict tool, the one an agent gates on, was the blind one.
|
|
110
|
+
*
|
|
111
|
+
* Prior events TEACH, they are never themselves findings: widening the window instead would make
|
|
112
|
+
* every other rule blame this action for events it did not cause, and would re-report every earlier
|
|
113
|
+
* mistake on every assert.
|
|
114
|
+
*/
|
|
115
|
+
export function findUnitMismatches(events, prior = []) {
|
|
116
|
+
// What the API has told us about each entity so far, in the API's own units.
|
|
117
|
+
const known = new Map();
|
|
118
|
+
for (const event of prior) {
|
|
119
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
120
|
+
continue;
|
|
121
|
+
const body = parse(event.data['responseBody']);
|
|
122
|
+
if (body !== undefined)
|
|
123
|
+
moneyByEntity(body, known);
|
|
124
|
+
}
|
|
125
|
+
const found = [];
|
|
126
|
+
const seen = new Set();
|
|
127
|
+
for (const event of events) {
|
|
128
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
129
|
+
continue;
|
|
130
|
+
const url = 'string' === typeof event.data['url'] ? event.data['url'] : '';
|
|
131
|
+
const requestBody = parse(event.data['requestBody']);
|
|
132
|
+
// Compare BEFORE recording this call's own response, or a request that echoes its own reply
|
|
133
|
+
// would compare against itself.
|
|
134
|
+
if ('object' === typeof requestBody && requestBody !== null) {
|
|
135
|
+
const sentFields = requestBody;
|
|
136
|
+
for (const id of idsIn(url, requestBody)) {
|
|
137
|
+
const fields = known.get(id);
|
|
138
|
+
if (fields === undefined)
|
|
139
|
+
continue;
|
|
140
|
+
for (const [key, sent] of Object.entries(sentFields)) {
|
|
141
|
+
if (!MONEY_FIELDS.has(key) || typeof sent !== 'number')
|
|
142
|
+
continue;
|
|
143
|
+
const priorValue = fields.get(key);
|
|
144
|
+
if (priorValue === undefined)
|
|
145
|
+
continue;
|
|
146
|
+
const scale = scaleBetween(priorValue, sent);
|
|
147
|
+
if (scale === undefined)
|
|
148
|
+
continue;
|
|
149
|
+
const key2 = `${id}:${key}`;
|
|
150
|
+
if (seen.has(key2))
|
|
151
|
+
continue;
|
|
152
|
+
seen.add(key2);
|
|
153
|
+
found.push({
|
|
154
|
+
kind: ContradictionKind.UNIT_MISMATCH,
|
|
155
|
+
claim: `the request sent ${key}=${String(sent)} and the server accepted it`,
|
|
156
|
+
counter: `the API reports ${key}=${String(priorValue)} for ${id} — the value sent is ${String(scale)}x SMALLER, i.e. a major-unit number written into a minor-unit field`,
|
|
157
|
+
detail: `${url} — at this scale the operation moves ${String(sent)} minor units instead of ${String(priorValue)}; nothing else can see this, because the number sent is exactly the number rendered on screen`,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const responseBody = parse(event.data['responseBody']);
|
|
163
|
+
if (responseBody !== undefined)
|
|
164
|
+
moneyByEntity(responseBody, known);
|
|
165
|
+
}
|
|
166
|
+
return found;
|
|
167
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two independent observers, and what it means when they disagree.
|
|
3
|
+
*
|
|
4
|
+
* Every channel a realm declares is, in the end, the subject describing itself. The DOM says the
|
|
5
|
+
* order saved because the app wrote that on the screen; the network says so because the app made
|
|
6
|
+
* the call. When an app lies to itself — an optimistic update never committed, a write that
|
|
7
|
+
* returned 200 and rolled back — every channel inside it repeats the lie consistently, and no
|
|
8
|
+
* amount of evidence from in there ever settles it. The database is not in there.
|
|
9
|
+
*
|
|
10
|
+
* So this is not an inference and it is not a heuristic: it is two observers that cannot have
|
|
11
|
+
* caused each other's reading, disagreeing. Nothing else this engine produces carries that weight,
|
|
12
|
+
* which is why the `Witness` SPI omits every method that could act — an implementer who CAN act
|
|
13
|
+
* through the same object eventually will, and its evidence is worthless the moment it might have
|
|
14
|
+
* caused what it reports.
|
|
15
|
+
*
|
|
16
|
+
* The asymmetry here is the entire safety property. A witness that could not be reached proves
|
|
17
|
+
* NOTHING and must never read as agreement: "I could not check" and "I checked and it was fine" are
|
|
18
|
+
* opposite answers, and collapsing them is precisely how a verification that never happened gets
|
|
19
|
+
* reported as one that did.
|
|
20
|
+
*/
|
|
21
|
+
export declare const WitnessOutcome: {
|
|
22
|
+
/** The app and an observer outside it do not agree about whether the effect happened. */
|
|
23
|
+
readonly DISAGREES: "witness-disagrees";
|
|
24
|
+
/** The outside observer could not be consulted, so nothing was settled either way. */
|
|
25
|
+
readonly UNREACHABLE: "witness-unreachable";
|
|
26
|
+
};
|
|
27
|
+
export type WitnessOutcome = (typeof WitnessOutcome)[keyof typeof WitnessOutcome];
|
|
28
|
+
export interface WitnessReading {
|
|
29
|
+
/** Did the app assert the effect happened — a success signal, a 2xx, a rendered confirmation. */
|
|
30
|
+
readonly appClaims: boolean;
|
|
31
|
+
/** What the outside observer saw. `undefined` means it was not consulted successfully. */
|
|
32
|
+
readonly witnessSaw: boolean | undefined;
|
|
33
|
+
/** Why the witness could not be consulted, when it could not be. */
|
|
34
|
+
readonly unreachable?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface WitnessFinding {
|
|
37
|
+
readonly kind: WitnessOutcome;
|
|
38
|
+
readonly because: string;
|
|
39
|
+
/** True when nothing was settled. An inconclusive finding is never a pass and never a failure. */
|
|
40
|
+
readonly inconclusive?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function witnessDisagreement(reading: WitnessReading): WitnessFinding | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two independent observers, and what it means when they disagree.
|
|
3
|
+
*
|
|
4
|
+
* Every channel a realm declares is, in the end, the subject describing itself. The DOM says the
|
|
5
|
+
* order saved because the app wrote that on the screen; the network says so because the app made
|
|
6
|
+
* the call. When an app lies to itself — an optimistic update never committed, a write that
|
|
7
|
+
* returned 200 and rolled back — every channel inside it repeats the lie consistently, and no
|
|
8
|
+
* amount of evidence from in there ever settles it. The database is not in there.
|
|
9
|
+
*
|
|
10
|
+
* So this is not an inference and it is not a heuristic: it is two observers that cannot have
|
|
11
|
+
* caused each other's reading, disagreeing. Nothing else this engine produces carries that weight,
|
|
12
|
+
* which is why the `Witness` SPI omits every method that could act — an implementer who CAN act
|
|
13
|
+
* through the same object eventually will, and its evidence is worthless the moment it might have
|
|
14
|
+
* caused what it reports.
|
|
15
|
+
*
|
|
16
|
+
* The asymmetry here is the entire safety property. A witness that could not be reached proves
|
|
17
|
+
* NOTHING and must never read as agreement: "I could not check" and "I checked and it was fine" are
|
|
18
|
+
* opposite answers, and collapsing them is precisely how a verification that never happened gets
|
|
19
|
+
* reported as one that did.
|
|
20
|
+
*/
|
|
21
|
+
export const WitnessOutcome = {
|
|
22
|
+
/** The app and an observer outside it do not agree about whether the effect happened. */
|
|
23
|
+
DISAGREES: 'witness-disagrees',
|
|
24
|
+
/** The outside observer could not be consulted, so nothing was settled either way. */
|
|
25
|
+
UNREACHABLE: 'witness-unreachable',
|
|
26
|
+
};
|
|
27
|
+
export function witnessDisagreement(reading) {
|
|
28
|
+
if (reading.witnessSaw === undefined) {
|
|
29
|
+
return {
|
|
30
|
+
kind: WitnessOutcome.UNREACHABLE,
|
|
31
|
+
because: `the outside observer could not be consulted (${reading.unreachable ?? 'no reason given'}), so nothing here is settled — this is not agreement, and it is not a failure of the app`,
|
|
32
|
+
inconclusive: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (reading.appClaims === reading.witnessSaw)
|
|
36
|
+
return undefined;
|
|
37
|
+
return {
|
|
38
|
+
kind: WitnessOutcome.DISAGREES,
|
|
39
|
+
because: reading.appClaims
|
|
40
|
+
? 'the app reported success and an observer outside it did not see the effect — the app is the only thing claiming this happened'
|
|
41
|
+
: 'an observer outside the app saw the effect while the app claimed nothing — a side effect the interface is hiding, or one it never meant to cause',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ReticleEvent } from '@reticlehq/core';
|
|
2
|
+
/**
|
|
3
|
+
* Did a write in this window answer `202 Accepted`?
|
|
4
|
+
*
|
|
5
|
+
* `202` is the only status in HTTP whose meaning is "no outcome yet" — the server took the request
|
|
6
|
+
* and has not finished with it. Folding it into the 2xx success band is how an asynchronous workflow
|
|
7
|
+
* gets a green verdict at exactly the moment nothing has been decided.
|
|
8
|
+
*
|
|
9
|
+
* Measured on a logistics console with server-side reconciliation: a dispatch answered 202, the row
|
|
10
|
+
* optimistically rendered "dispatched", the page settled, every channel agreed — and the server
|
|
11
|
+
* REVERTED it to `held` 1.2 s later. The verdict was not wrong about what it observed. It was early,
|
|
12
|
+
* and nothing in the response said so except the status code nobody was reading.
|
|
13
|
+
*
|
|
14
|
+
* The DEV TOOLCHAIN's own traffic is excluded, on the same rule every other check applies: a verdict
|
|
15
|
+
* about the app must not be decided by a request the app did not make.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Which writes in this window answered `202 Accepted`, as "METHOD url".
|
|
19
|
+
*
|
|
20
|
+
* The verdict tells the agent to re-check once the server reconciles. That instruction is only
|
|
21
|
+
* usable if the agent knows WHAT to re-check: a window with three requests and a verdict saying
|
|
22
|
+
* "a write returned 202" leaves it guessing which one, and guessing wrong means watching a request
|
|
23
|
+
* that already finished while the real one is still pending.
|
|
24
|
+
*
|
|
25
|
+
* Duplicates are folded, so a retried request names its endpoint once instead of filling the
|
|
26
|
+
* sentence with the same line three times.
|
|
27
|
+
*/
|
|
28
|
+
export declare function acceptedWriteLabels(events: readonly ReticleEvent[]): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Did a write in this window answer `202 Accepted`?
|
|
31
|
+
*
|
|
32
|
+
* Derived from the labels above rather than repeating the filter, so the question and the list can
|
|
33
|
+
* never disagree about which requests count.
|
|
34
|
+
*/
|
|
35
|
+
export declare function hasAcceptedWrite(events: readonly ReticleEvent[]): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EventType, HTTP_ACCEPTED, isDevToolingUrl } from '@reticlehq/core';
|
|
2
|
+
import { asNumber, asString } from '@reticlehq/core';
|
|
3
|
+
/**
|
|
4
|
+
* Did a write in this window answer `202 Accepted`?
|
|
5
|
+
*
|
|
6
|
+
* `202` is the only status in HTTP whose meaning is "no outcome yet" — the server took the request
|
|
7
|
+
* and has not finished with it. Folding it into the 2xx success band is how an asynchronous workflow
|
|
8
|
+
* gets a green verdict at exactly the moment nothing has been decided.
|
|
9
|
+
*
|
|
10
|
+
* Measured on a logistics console with server-side reconciliation: a dispatch answered 202, the row
|
|
11
|
+
* optimistically rendered "dispatched", the page settled, every channel agreed — and the server
|
|
12
|
+
* REVERTED it to `held` 1.2 s later. The verdict was not wrong about what it observed. It was early,
|
|
13
|
+
* and nothing in the response said so except the status code nobody was reading.
|
|
14
|
+
*
|
|
15
|
+
* The DEV TOOLCHAIN's own traffic is excluded, on the same rule every other check applies: a verdict
|
|
16
|
+
* about the app must not be decided by a request the app did not make.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Which writes in this window answered `202 Accepted`, as "METHOD url".
|
|
20
|
+
*
|
|
21
|
+
* The verdict tells the agent to re-check once the server reconciles. That instruction is only
|
|
22
|
+
* usable if the agent knows WHAT to re-check: a window with three requests and a verdict saying
|
|
23
|
+
* "a write returned 202" leaves it guessing which one, and guessing wrong means watching a request
|
|
24
|
+
* that already finished while the real one is still pending.
|
|
25
|
+
*
|
|
26
|
+
* Duplicates are folded, so a retried request names its endpoint once instead of filling the
|
|
27
|
+
* sentence with the same line three times.
|
|
28
|
+
*/
|
|
29
|
+
export function acceptedWriteLabels(events) {
|
|
30
|
+
const labels = [];
|
|
31
|
+
for (const event of events) {
|
|
32
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
33
|
+
continue;
|
|
34
|
+
if (asNumber(event.data['status']) !== HTTP_ACCEPTED)
|
|
35
|
+
continue;
|
|
36
|
+
const url = asString(event.data['url']);
|
|
37
|
+
if (isDevToolingUrl(url))
|
|
38
|
+
continue;
|
|
39
|
+
const method = ('string' === typeof event.data['method'] ? event.data['method'] : '').toUpperCase();
|
|
40
|
+
const label = `${method} ${url ?? ''}`.trim();
|
|
41
|
+
if ('' !== label && !labels.includes(label))
|
|
42
|
+
labels.push(label);
|
|
43
|
+
}
|
|
44
|
+
return labels;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Did a write in this window answer `202 Accepted`?
|
|
48
|
+
*
|
|
49
|
+
* Derived from the labels above rather than repeating the filter, so the question and the list can
|
|
50
|
+
* never disagree about which requests count.
|
|
51
|
+
*/
|
|
52
|
+
export function hasAcceptedWrite(events) {
|
|
53
|
+
return acceptedWriteLabels(events).length > 0;
|
|
54
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Predicate } from '../question/predicate/predicate.js';
|
|
2
|
+
export declare function readsDomState(predicate: Predicate): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* #889: an `already_true` verdict says the declared consequence held before the action, so nothing
|
|
5
|
+
* was proven — but a `text`/`element` predicate matches DOM presence by default, not visibility (a
|
|
6
|
+
* caller has to pass `visible: true` to ask for that). A dialog's content mounted-but-hidden before
|
|
7
|
+
* the click therefore reads as "already true", identically to genuinely-visible content that was
|
|
8
|
+
* already on screen — and the `already_true` message named neither which node it matched nor that
|
|
9
|
+
* the match was invisible, which is what made it read as proof of nothing rather than as the
|
|
10
|
+
* mid-load/hidden-mount trap it actually was.
|
|
11
|
+
*
|
|
12
|
+
* True only when the predicate itself did not ask for a state (an explicit `visible`/other state
|
|
13
|
+
* constraint already means the caller saw and handled this) AND every matched element is hidden —
|
|
14
|
+
* one visible match among several is a fair, ordinary read and is left alone.
|
|
15
|
+
*/
|
|
16
|
+
export declare function alreadyTrueHiddenMatch(predicate: Predicate, evidence: unknown): boolean;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which predicates can be satisfied by something that was already true before the action.
|
|
3
|
+
*
|
|
4
|
+
* Event-based kinds (net, signal, console, animation, settled) are evaluated against the
|
|
5
|
+
* event buffer floored at the act's own cursor, so a stale event cannot satisfy them — that floor is
|
|
6
|
+
* why `act_and_wait` can trust them at all.
|
|
7
|
+
*
|
|
8
|
+
* `element` and `text` read the LIVE DOM, `route` can fall back to the current route, and `state` reads
|
|
9
|
+
* live store memory via STATE_READ — where no event floor applies. A condition that held before the
|
|
10
|
+
* click holds after it and passes instantly, whatever the action did. A click asserted with
|
|
11
|
+
* `{ kind: 'text', contains: 'Parallel Routes' }` returns `verified: "yes"` against
|
|
12
|
+
* `routeChanges: 0` when the predicate matches a nav link that was already on screen, while the real
|
|
13
|
+
* navigation lands seconds later. Likewise a pre-existing store value (e.g. `cart.count == 3`)
|
|
14
|
+
* satisfies an inert action if it is not checked before dispatch.
|
|
15
|
+
*
|
|
16
|
+
* So these are the kinds worth evaluating BEFORE the act, to find out whether the green means
|
|
17
|
+
* anything.
|
|
18
|
+
*/
|
|
19
|
+
import { PredicateKind } from '@reticlehq/core';
|
|
20
|
+
export function readsDomState(predicate) {
|
|
21
|
+
switch (predicate.kind) {
|
|
22
|
+
// ROUTE is here, and it did not used to be. It was purely event-based — satisfiable only by a
|
|
23
|
+
// navigation inside the act's window, and therefore unable to be answered by the past — so it
|
|
24
|
+
// sat with the floored kinds below.
|
|
25
|
+
//
|
|
26
|
+
// It gained a fallback to the CURRENT route for the case where the window holds no route change,
|
|
27
|
+
// which is what makes "did the session survive a reload?" answerable at all. Without a
|
|
28
|
+
// before-check that fallback is a guaranteed green: the app is already on /login, the click's
|
|
29
|
+
// handler is broken, nothing navigates, and an assertion that the action reached /login passes
|
|
30
|
+
// on the strength of it having been there all along. A bare `{ kind: 'route' }` becomes
|
|
31
|
+
// unconditionally true, because there is always a current route.
|
|
32
|
+
//
|
|
33
|
+
// One extra query on the act path buys `already_true`, reported as UNKNOWN with the reason
|
|
34
|
+
// rather than as a pass. The fallback removed a false red; this is what stops it becoming a
|
|
35
|
+
// false green, and that is the trade this codebase never makes.
|
|
36
|
+
//
|
|
37
|
+
// STATE is here for the same reason: it is evaluated via STATE_READ against live in-memory stores
|
|
38
|
+
// rather than through the floored event buffer. If the store already holds the expected value
|
|
39
|
+
// before dispatch, an inert click would immediately pass post-dispatch on the pre-existing state.
|
|
40
|
+
// Evaluating before dispatch routes that pre-existing condition into already_true.
|
|
41
|
+
case PredicateKind.ELEMENT:
|
|
42
|
+
case PredicateKind.TEXT:
|
|
43
|
+
case PredicateKind.ROUTE:
|
|
44
|
+
case PredicateKind.STATE:
|
|
45
|
+
return true;
|
|
46
|
+
case PredicateKind.ALL_OF:
|
|
47
|
+
case PredicateKind.ANY_OF:
|
|
48
|
+
return predicate.predicates.some(readsDomState);
|
|
49
|
+
case PredicateKind.NOT:
|
|
50
|
+
return readsDomState(predicate.predicate);
|
|
51
|
+
default:
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** True when `value` looks like an element/text predicate's passing evidence — an array of descriptors. */
|
|
56
|
+
function isDescriptorArray(value) {
|
|
57
|
+
if (!Array.isArray(value))
|
|
58
|
+
return false;
|
|
59
|
+
return value.every((v) => {
|
|
60
|
+
if ('object' !== typeof v || null === v)
|
|
61
|
+
return false;
|
|
62
|
+
return 'boolean' === typeof v['visible'];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* #889: an `already_true` verdict says the declared consequence held before the action, so nothing
|
|
67
|
+
* was proven — but a `text`/`element` predicate matches DOM presence by default, not visibility (a
|
|
68
|
+
* caller has to pass `visible: true` to ask for that). A dialog's content mounted-but-hidden before
|
|
69
|
+
* the click therefore reads as "already true", identically to genuinely-visible content that was
|
|
70
|
+
* already on screen — and the `already_true` message named neither which node it matched nor that
|
|
71
|
+
* the match was invisible, which is what made it read as proof of nothing rather than as the
|
|
72
|
+
* mid-load/hidden-mount trap it actually was.
|
|
73
|
+
*
|
|
74
|
+
* True only when the predicate itself did not ask for a state (an explicit `visible`/other state
|
|
75
|
+
* constraint already means the caller saw and handled this) AND every matched element is hidden —
|
|
76
|
+
* one visible match among several is a fair, ordinary read and is left alone.
|
|
77
|
+
*/
|
|
78
|
+
export function alreadyTrueHiddenMatch(predicate, evidence) {
|
|
79
|
+
if (predicate.kind !== PredicateKind.ELEMENT && predicate.kind !== PredicateKind.TEXT) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (predicate.kind === PredicateKind.ELEMENT && predicate.state !== undefined)
|
|
83
|
+
return false;
|
|
84
|
+
if (predicate.kind === PredicateKind.TEXT && true === predicate.visible)
|
|
85
|
+
return false;
|
|
86
|
+
if (!isDescriptorArray(evidence) || 0 === evidence.length)
|
|
87
|
+
return false;
|
|
88
|
+
return evidence.every((el) => !el.visible);
|
|
89
|
+
}
|