@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
|
@@ -19,6 +19,8 @@ interface RequestBodyPredicate {
|
|
|
19
19
|
interface RequestBodyState {
|
|
20
20
|
/** A call matched everything else but carried no recorded request body. */
|
|
21
21
|
unrecorded: boolean;
|
|
22
|
+
/** The body type the SDK named for an unrecorded request body, which it does only with capture on. */
|
|
23
|
+
unrecordedType?: unknown;
|
|
22
24
|
/** The request body a clause was checked against and did not match. */
|
|
23
25
|
mismatch?: string;
|
|
24
26
|
/** The prefix of a TRUNCATED request body the clause did not hold over — undecidable, not absent. */
|
|
@@ -33,6 +35,13 @@ interface RequestBodyState {
|
|
|
33
35
|
*/
|
|
34
36
|
redactedField?: string;
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The remedy for a request body the SDK did not record although capture is on, or `undefined`.
|
|
40
|
+
*
|
|
41
|
+
* With capture on, the SDK names the type of a body it cannot stringify (`requestBodyType`: a
|
|
42
|
+
* `Blob`, a `FormData`, a stream). "Enable captureNetworkBodies" is then wrong advice (#1520).
|
|
43
|
+
*/
|
|
44
|
+
export declare function requestBodySkipRemedy(bodyType: unknown): string | undefined;
|
|
36
45
|
export declare function newRequestBodyState(): RequestBodyState;
|
|
37
46
|
/**
|
|
38
47
|
* Does this event satisfy the predicate's request-body clauses? Records why not in `state`.
|
|
@@ -45,6 +54,11 @@ export declare function checkRequestBody(data: Record<string, unknown>, predicat
|
|
|
45
54
|
*
|
|
46
55
|
* Ranked the way the response side ranks its own: the two nobody could have answered (redacted,
|
|
47
56
|
* unrecorded, truncated) come before the one that WAS answered and came out false.
|
|
57
|
+
*
|
|
58
|
+
* `responseMismatch` is the response body of a call whose request DID satisfy the clause and whose
|
|
59
|
+
* response did not. When it is set, a definite request mismatch on some OTHER call is not the
|
|
60
|
+
* explanation and yields to it; the unknowns above still win, because the call they describe may
|
|
61
|
+
* be the one that would have satisfied the whole predicate.
|
|
48
62
|
*/
|
|
49
|
-
export declare function requestBodyVerdict(state: RequestBodyState, predicate: NetPredicate, matchCount: number): EvalResult | undefined;
|
|
63
|
+
export declare function requestBodyVerdict(state: RequestBodyState, predicate: NetPredicate, matchCount: number, responseMismatch?: string): EvalResult | undefined;
|
|
50
64
|
export {};
|
|
@@ -15,6 +15,17 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { REDACTED_VALUE } from '@reticlehq/core';
|
|
17
17
|
import { clipBody, describeBodyFieldMiss, describeNetFilter, matchJsonBody, str, } from './predicate-eval-kit.js';
|
|
18
|
+
/**
|
|
19
|
+
* The remedy for a request body the SDK did not record although capture is on, or `undefined`.
|
|
20
|
+
*
|
|
21
|
+
* With capture on, the SDK names the type of a body it cannot stringify (`requestBodyType`: a
|
|
22
|
+
* `Blob`, a `FormData`, a stream). "Enable captureNetworkBodies" is then wrong advice (#1520).
|
|
23
|
+
*/
|
|
24
|
+
export function requestBodySkipRemedy(bodyType) {
|
|
25
|
+
if ('string' !== typeof bodyType || 0 === bodyType.length)
|
|
26
|
+
return undefined;
|
|
27
|
+
return `the request body was a ${bodyType}, which the SDK does not record as text, and capture is already on. Assert on the response or on the effect the request had instead`;
|
|
28
|
+
}
|
|
18
29
|
export function newRequestBodyState() {
|
|
19
30
|
return { unrecorded: false };
|
|
20
31
|
}
|
|
@@ -30,6 +41,7 @@ export function checkRequestBody(data, predicate, state) {
|
|
|
30
41
|
const sent = str(data['requestBody']);
|
|
31
42
|
if (sent === undefined) {
|
|
32
43
|
state.unrecorded = true;
|
|
44
|
+
state.unrecordedType ??= data['requestBodyType'];
|
|
33
45
|
return false;
|
|
34
46
|
}
|
|
35
47
|
const wasTruncated = true === data['requestBodyTruncated'];
|
|
@@ -62,8 +74,13 @@ export function checkRequestBody(data, predicate, state) {
|
|
|
62
74
|
*
|
|
63
75
|
* Ranked the way the response side ranks its own: the two nobody could have answered (redacted,
|
|
64
76
|
* unrecorded, truncated) come before the one that WAS answered and came out false.
|
|
77
|
+
*
|
|
78
|
+
* `responseMismatch` is the response body of a call whose request DID satisfy the clause and whose
|
|
79
|
+
* response did not. When it is set, a definite request mismatch on some OTHER call is not the
|
|
80
|
+
* explanation and yields to it; the unknowns above still win, because the call they describe may
|
|
81
|
+
* be the one that would have satisfied the whole predicate.
|
|
65
82
|
*/
|
|
66
|
-
export function requestBodyVerdict(state, predicate, matchCount) {
|
|
83
|
+
export function requestBodyVerdict(state, predicate, matchCount, responseMismatch) {
|
|
67
84
|
if (matchCount > 0)
|
|
68
85
|
return undefined;
|
|
69
86
|
const wanted = JSON.stringify(predicate.requestBodyContains ?? predicate.requestBodyMatches);
|
|
@@ -78,9 +95,12 @@ export function requestBodyVerdict(state, predicate, matchCount) {
|
|
|
78
95
|
};
|
|
79
96
|
}
|
|
80
97
|
if (state.unrecorded) {
|
|
98
|
+
// Unknown, not different: nothing was read, so nothing says the body did not match (#1520).
|
|
99
|
+
const reason = `a call matched but its REQUEST body was not recorded, so the request-body clause could not be checked — ${requestBodySkipRemedy(state.unrecordedType) ?? 'enable it where the app calls connect(): reticle({ captureNetworkBodies: true })'}`;
|
|
81
100
|
return {
|
|
82
101
|
pass: false,
|
|
83
|
-
failureReason:
|
|
102
|
+
failureReason: reason,
|
|
103
|
+
inconclusive: reason,
|
|
84
104
|
observed: 'a matching call with no recorded request body',
|
|
85
105
|
expected: `a request body matching ${wanted}`,
|
|
86
106
|
assertion: 'net.requestBody',
|
|
@@ -95,7 +115,7 @@ export function requestBodyVerdict(state, predicate, matchCount) {
|
|
|
95
115
|
assertion: 'net.requestBody',
|
|
96
116
|
};
|
|
97
117
|
}
|
|
98
|
-
if (state.mismatch !== undefined) {
|
|
118
|
+
if (state.mismatch !== undefined && responseMismatch === undefined) {
|
|
99
119
|
// Named separately from "no call matched", for the reason the response side already learned: the
|
|
100
120
|
// request DID fire, and reporting zero matches sends the caller to check the url and the method,
|
|
101
121
|
// which are both fine, instead of to the value the UI actually sent.
|
|
@@ -47,6 +47,8 @@ interface RouteParts {
|
|
|
47
47
|
}
|
|
48
48
|
/** A `ROUTE_CHANGE` event, or its `data` — one reading, so the sixth copy cannot drift. */
|
|
49
49
|
export declare function routeOfEvent(eventOrData: ReticleEvent | Record<string, unknown>): RouteParts | undefined;
|
|
50
|
+
/** A route as a navigable path, pathname + app query + hash, with Reticle's own params dropped. */
|
|
51
|
+
export declare function navigablePath(parts: Pick<RouteParts, 'docPath' | 'search' | 'hash'>): string;
|
|
50
52
|
/** Same shape from a session URL (the fallback when the tab hard-loaded and emitted no route event). */
|
|
51
53
|
export declare function routeOfUrl(url: string): RouteParts | undefined;
|
|
52
54
|
export declare function evalRoute(events: ReticleEvent[], p: Extract<Predicate, {
|
|
@@ -100,6 +100,36 @@ function withoutIdentityParams(value) {
|
|
|
100
100
|
parsed.searchParams.delete(name);
|
|
101
101
|
return parsed.toString();
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* A `?query` with Reticle's own params removed and the app's pairs left exactly as written. A recording keeps the app's query in `startPath` and replay compares against it,
|
|
105
|
+
* so a leased tab's `__reticle_*` params must be dropped on both sides or a tab already on the page
|
|
106
|
+
* reads as somewhere else (#1411).
|
|
107
|
+
*/
|
|
108
|
+
function searchWithoutIdentityParams(search) {
|
|
109
|
+
const query = search.startsWith('?') ? search.slice(1) : search;
|
|
110
|
+
if ('' === query)
|
|
111
|
+
return '';
|
|
112
|
+
// Pair by pair, not through URLSearchParams: its round trip re-encodes what it keeps (`%20` comes
|
|
113
|
+
// back as `+`), so a hand-written startPath `/search?q=red%20shirt` would stop matching a tab on
|
|
114
|
+
// exactly that URL. Only Reticle's own pairs are removed; the rest keep their spelling.
|
|
115
|
+
const ours = new Set(Object.values(RETICLE_URL_PARAM));
|
|
116
|
+
const kept = query.split('&').filter((pair) => !ours.has(paramNameOf(pair)));
|
|
117
|
+
return 0 === kept.length ? '' : `?${kept.join('&')}`;
|
|
118
|
+
}
|
|
119
|
+
/** The decoded name of one `name=value` query pair, or the raw text when it does not decode. */
|
|
120
|
+
function paramNameOf(pair) {
|
|
121
|
+
const raw = pair.split('=', 1)[0] ?? '';
|
|
122
|
+
try {
|
|
123
|
+
return decodeURIComponent(raw.replaceAll('+', ' '));
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return raw;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** A route as a navigable path, pathname + app query + hash, with Reticle's own params dropped. */
|
|
130
|
+
export function navigablePath(parts) {
|
|
131
|
+
return `${parts.docPath}${searchWithoutIdentityParams(parts.search)}${parts.hash}`;
|
|
132
|
+
}
|
|
103
133
|
/** The event payload as evidence: every URL-ish field scrubbed of our own params. */
|
|
104
134
|
function routeEvidence(data) {
|
|
105
135
|
return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, withoutIdentityParams(value)]));
|
|
@@ -11,6 +11,17 @@ import { z } from 'zod';
|
|
|
11
11
|
import { type ElementDescriptor, type ElementQuery } from '@reticlehq/core';
|
|
12
12
|
export { PredicateSchema } from '@reticlehq/core';
|
|
13
13
|
export type { Predicate, PropertyAssertion } from '@reticlehq/core';
|
|
14
|
+
/** The query to send, asking the browser to project `alt` when this side has to check it. */
|
|
15
|
+
export declare function withAltProjected(query: ElementQuery, checks: readonly [string, string][]): ElementQuery;
|
|
16
|
+
/**
|
|
17
|
+
* Why `alt` cannot be checked, when none of the matched elements is an image — or `undefined` when
|
|
18
|
+
* it can. A button has no alt, so grading it "no" would read as "the alt is wrong" when the truth is
|
|
19
|
+
* "this is not an image": a refusal that says what to use instead costs one turn.
|
|
20
|
+
*
|
|
21
|
+
* Only the case where NO match is an image is refused. With an image among them, the others simply do
|
|
22
|
+
* not satisfy `alt`, and the verdict is about the images.
|
|
23
|
+
*/
|
|
24
|
+
export declare function describeAltOnNonImage(checks: readonly [string, string][], elements: readonly ElementDescriptor[]): string | undefined;
|
|
14
25
|
interface ResidualQueryChecks {
|
|
15
26
|
/** Dropped fields this side CAN check, as [field, wanted value] pairs. */
|
|
16
27
|
checks: [string, string][];
|
|
@@ -54,6 +54,10 @@ function usedQueryFields(query) {
|
|
|
54
54
|
used.add('attrs');
|
|
55
55
|
if (query.self !== undefined)
|
|
56
56
|
used.add('self');
|
|
57
|
+
// A modifier of the text rule, not a locator: the browser honours it wherever it reads `text`, and
|
|
58
|
+
// the residual text check below is already case-exact.
|
|
59
|
+
if (query.matchCase !== undefined)
|
|
60
|
+
used.add('matchCase');
|
|
57
61
|
// The browser's `self` branch checks subtree text when supplied, but skips every other locator.
|
|
58
62
|
// Mark only text as consumed so role/name/etc. remain residual checks on the returned descriptor.
|
|
59
63
|
if (true === query.self)
|
|
@@ -86,6 +90,20 @@ function usedQueryFields(query) {
|
|
|
86
90
|
}
|
|
87
91
|
return used;
|
|
88
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The role the browser reports for an `<img>`. It stands in for "an image" because the descriptor
|
|
95
|
+
* carries no tag name, so anything else with this role — an `<svg role="img">` — counts as one too.
|
|
96
|
+
*/
|
|
97
|
+
const IMAGE_ROLE = 'img';
|
|
98
|
+
const ALT_FIELD = 'alt';
|
|
99
|
+
/** How a failure reports an image that carries no `alt` attribute at all. */
|
|
100
|
+
const NO_ALT_ATTRIBUTE = '(no alt attribute)';
|
|
101
|
+
/** What the refusal says about `alt` on something that is not an image, and what to assert instead. */
|
|
102
|
+
const ALT_IMAGE_ONLY = '`alt` can only be checked on an image';
|
|
103
|
+
const ALT_USE_NAME = 'For an element that is not an image, assert its accessible name with `name` instead.';
|
|
104
|
+
function isImage(element) {
|
|
105
|
+
return IMAGE_ROLE === element.role;
|
|
106
|
+
}
|
|
89
107
|
/**
|
|
90
108
|
* How a dropped field is checked back on the server, against the descriptor the match returned.
|
|
91
109
|
*
|
|
@@ -100,6 +118,11 @@ function usedQueryFields(query) {
|
|
|
100
118
|
* copies out of a query result are the words that match here. `text` is a substring match, matching
|
|
101
119
|
* Testing Library's `exact: false`, and falls back to the name because describe() omits `text` when it
|
|
102
120
|
* equals the accessible name.
|
|
121
|
+
*
|
|
122
|
+
* `alt` is read from the image's `alt` ATTRIBUTE, projected onto the match by `withAltProjected` —
|
|
123
|
+
* not from its accessible name. Both a decorative `alt=""` and a missing alt give an empty name, and
|
|
124
|
+
* only the attribute tells them apart: a missing alt is the defect `alt: ""` exists to rule out. On
|
|
125
|
+
* anything but an image it is false, and `describeAltOnNonImage` turns that into a refusal.
|
|
103
126
|
*/
|
|
104
127
|
/**
|
|
105
128
|
* Does an element whose computed role is `actual` satisfy a query for `queried`?
|
|
@@ -120,7 +143,33 @@ const RESIDUAL_CHECKS = {
|
|
|
120
143
|
role: (element, want) => matchesRole(element.role, want),
|
|
121
144
|
name: (element, want) => element.name.trim() === want.trim(),
|
|
122
145
|
text: (element, want) => (element.text ?? element.name).includes(want),
|
|
146
|
+
[ALT_FIELD]: (element, want) => {
|
|
147
|
+
const alt = element.attrs?.[ALT_FIELD];
|
|
148
|
+
return isImage(element) && alt !== undefined && alt.trim() === want.trim();
|
|
149
|
+
},
|
|
123
150
|
};
|
|
151
|
+
/** The query to send, asking the browser to project `alt` when this side has to check it. */
|
|
152
|
+
export function withAltProjected(query, checks) {
|
|
153
|
+
const attrs = query.attrs ?? [];
|
|
154
|
+
if (!checks.some(([field]) => ALT_FIELD === field) || attrs.includes(ALT_FIELD))
|
|
155
|
+
return query;
|
|
156
|
+
return { ...query, attrs: [...attrs, ALT_FIELD] };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Why `alt` cannot be checked, when none of the matched elements is an image — or `undefined` when
|
|
160
|
+
* it can. A button has no alt, so grading it "no" would read as "the alt is wrong" when the truth is
|
|
161
|
+
* "this is not an image": a refusal that says what to use instead costs one turn.
|
|
162
|
+
*
|
|
163
|
+
* Only the case where NO match is an image is refused. With an image among them, the others simply do
|
|
164
|
+
* not satisfy `alt`, and the verdict is about the images.
|
|
165
|
+
*/
|
|
166
|
+
export function describeAltOnNonImage(checks, elements) {
|
|
167
|
+
const wantsAlt = checks.some(([field]) => ALT_FIELD === field);
|
|
168
|
+
if (!wantsAlt || 0 === elements.length || elements.some(isImage))
|
|
169
|
+
return undefined;
|
|
170
|
+
const roles = [...new Set(elements.map((element) => element.role))].join(', ');
|
|
171
|
+
return `${ALT_IMAGE_ONLY}, and the element matched is ${roles}, not ${IMAGE_ROLE}. ${ALT_USE_NAME}`;
|
|
172
|
+
}
|
|
124
173
|
/**
|
|
125
174
|
* Split a query's dropped fields into the ones the server can still enforce and the ones it cannot.
|
|
126
175
|
*
|
|
@@ -171,7 +220,9 @@ export function describeResidual(element, field) {
|
|
|
171
220
|
? (element.text ?? element.name)
|
|
172
221
|
: 'role' === field
|
|
173
222
|
? element.role
|
|
174
|
-
:
|
|
223
|
+
: ALT_FIELD === field
|
|
224
|
+
? (element.attrs?.[ALT_FIELD] ?? NO_ALT_ATTRIBUTE)
|
|
225
|
+
: element.name;
|
|
175
226
|
return `${element.role} "${element.name}" ${field}=${JSON.stringify(reading)}`;
|
|
176
227
|
}
|
|
177
228
|
/**
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { PredicateKind, ReticleCommand, capDepth, selectPath } from '@reticlehq/core';
|
|
10
10
|
import { matchValue } from './predicate-eval.js';
|
|
11
|
+
import { isStringifiedPrimitiveMismatch, stringifiedPrimitiveResult, } from './predicate-eval-kit.js';
|
|
11
12
|
import { satisfiesProperty } from './property.js';
|
|
12
13
|
/** One name, or none — two candidates is a question, not an answer. */
|
|
13
14
|
function oneOf(names) {
|
|
@@ -159,6 +160,9 @@ async function evalStateNamed(session, p, storeName, baseline) {
|
|
|
159
160
|
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
160
161
|
};
|
|
161
162
|
}
|
|
163
|
+
if (isStringifiedPrimitiveMismatch(selection.value, want)) {
|
|
164
|
+
return stringifiedPrimitiveResult(storeName, p.path, selection.value, want, capDepth);
|
|
165
|
+
}
|
|
162
166
|
return {
|
|
163
167
|
pass: false,
|
|
164
168
|
failureReason: `state '${p.path}' is ${JSON.stringify(capDepth(selection.value, 0))}, expected ${JSON.stringify(want)}`,
|
|
@@ -306,6 +310,9 @@ export async function evalState(session, p, baseline) {
|
|
|
306
310
|
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
307
311
|
};
|
|
308
312
|
}
|
|
313
|
+
if (isStringifiedPrimitiveMismatch(selection.value, want)) {
|
|
314
|
+
return stringifiedPrimitiveResult(storeName, p.path, selection.value, want, capDepth);
|
|
315
|
+
}
|
|
309
316
|
return {
|
|
310
317
|
pass: false,
|
|
311
318
|
failureReason: `state '${p.path}' is ${JSON.stringify(capDepth(selection.value, 0))}, expected ${JSON.stringify(want)}`,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ElementState, PredicateKind, THROTTLED_STARVED_NOTE, isSameDocument, } from '@reticlehq/core';
|
|
1
|
+
import { ElementState, EventType, MUTATING_METHODS, PredicateKind, THROTTLED_STARVED_NOTE, isSameDocument, } from '@reticlehq/core';
|
|
2
2
|
import { predicateToExpectedLinks } from './predicate-to-links.js';
|
|
3
3
|
import { isAmbient, ambientKeyOf } from '../../window/ambient.js';
|
|
4
4
|
import { evalRoute } from './predicate-route.js';
|
|
5
5
|
import { describeSuperseded } from './observed-in-window.js';
|
|
6
|
-
import { evalElement, withTextProperty } from './predicate-element.js';
|
|
6
|
+
import { evalElement, textPredicateQuery, withTextProperty } from './predicate-element.js';
|
|
7
7
|
import { evalState } from './predicate-state.js';
|
|
8
8
|
import { evalCompare } from './predicate-compare.js';
|
|
9
9
|
import { PredicateSchema, evalNet, evalConsole, evalAnimation, evalSignal, evalSettled, } from './predicate-eval.js';
|
|
@@ -38,6 +38,25 @@ const WINDOW_ONLY_KINDS = new Set([
|
|
|
38
38
|
]);
|
|
39
39
|
/** Names the oracle that answered, in the same shape every other `assertion` here uses. */
|
|
40
40
|
const SUPERSEDED_ASSERTION = 'window.evidence-superseded';
|
|
41
|
+
/**
|
|
42
|
+
* A WRITE the server answered: a mutating NET_REQUEST carrying a status or an `ok`.
|
|
43
|
+
*
|
|
44
|
+
* The answer to a write is a fact about the server, not page state, so it stays true after the
|
|
45
|
+
* page that sent it is replaced (#1529). The answer to a read is not: a GET from the old page says
|
|
46
|
+
* nothing about whether the page now on screen loaded its data, and keeping it would let a stale
|
|
47
|
+
* 200 pass `net GET 200` while the current page's own request failed. A request nobody answered,
|
|
48
|
+
* or a subresource whose answer could not be read, carries neither field and is never kept.
|
|
49
|
+
*/
|
|
50
|
+
function isServerAnswer(e) {
|
|
51
|
+
const method = e.data['method'];
|
|
52
|
+
return (EventType.NET_REQUEST === e.type &&
|
|
53
|
+
'string' === typeof method &&
|
|
54
|
+
MUTATING_METHODS.includes(method.toUpperCase()) &&
|
|
55
|
+
('number' === typeof e.data['status'] || 'boolean' === typeof e.data['ok']));
|
|
56
|
+
}
|
|
57
|
+
/** Why a `net` miss is unknown when only a replaced page's answer would have matched (#1529). */
|
|
58
|
+
const ANSWERED_BEFORE_NAVIGATION = 'a matching request was answered under the page before the navigation, and this window has no ' +
|
|
59
|
+
'`since` floor to count it in. Pass the cursor from before the action as `since`.';
|
|
41
60
|
/** The predicate's own event-time floor, if its kind carries one. */
|
|
42
61
|
function predicateSince(predicate) {
|
|
43
62
|
return 'since' in predicate && 'number' === typeof predicate.since ? predicate.since : 0;
|
|
@@ -83,6 +102,7 @@ function annotateThrottledMiss(session, predicate, result) {
|
|
|
83
102
|
*
|
|
84
103
|
* - `splitText`: the browser found the requested string in the rendered page, split across
|
|
85
104
|
* children. Target-specific — the text IS the thing that was asked for.
|
|
105
|
+
* - `caseMiss`: the browser found it in another case, for a case-exact check.
|
|
86
106
|
* - `nearMiss` from `element.state`: the target element exists but in the wrong state. The DOM
|
|
87
107
|
* painted the element itself, so starvation is not the explanation.
|
|
88
108
|
*
|
|
@@ -96,7 +116,7 @@ function evidenceProvesPageRendered(result) {
|
|
|
96
116
|
const evidence = result.evidence;
|
|
97
117
|
if ('object' !== typeof evidence || null === evidence)
|
|
98
118
|
return false;
|
|
99
|
-
if ('splitText' in evidence)
|
|
119
|
+
if ('splitText' in evidence || 'caseMiss' in evidence)
|
|
100
120
|
return true;
|
|
101
121
|
if ('nearMiss' in evidence && 'element.state' === result.assertion)
|
|
102
122
|
return true;
|
|
@@ -225,11 +245,19 @@ diagnose = true, baselines) {
|
|
|
225
245
|
// `since` from the act it just performed is scoping the assertion to that action's aftermath. It is
|
|
226
246
|
// applied here, once, rather than in each eval: the floor means the same thing for every kind that
|
|
227
247
|
// reads the event stream, and net/console re-applying it is a no-op.
|
|
228
|
-
const
|
|
248
|
+
const floor = Math.max(since, predicateSince(predicate));
|
|
249
|
+
const raw = session.eventsSince(floor);
|
|
250
|
+
const onScreen = (e) => isSameDocument(e.documentId, session.currentDocumentId);
|
|
229
251
|
// Scoped ONCE, here, for the same reason the contradiction pass scopes at its own choke point:
|
|
230
252
|
// reasoning about a dead page's evidence is a defect in every oracle below rather than in whichever
|
|
231
253
|
// one happened to read it, and this is the single place they all take their window from.
|
|
232
|
-
|
|
254
|
+
//
|
|
255
|
+
// One exception (#1529). A `net` predicate inside an explicit `since` window also keeps the server's
|
|
256
|
+
// answers to the page that was just replaced: a write that navigates (delete, then redirect home)
|
|
257
|
+
// is proven by its response, and dropping it read a 204 as "never happened". The floor is what
|
|
258
|
+
// ties the request to the action; without one it could come from any earlier page.
|
|
259
|
+
const keepsAnswers = PredicateKind.NET === predicate.kind && 0 < floor;
|
|
260
|
+
const events = raw.filter((e) => onScreen(e) || (keepsAnswers && isServerAnswer(e)));
|
|
233
261
|
const superseded = raw.length - events.length;
|
|
234
262
|
// An empty window was always allowed to mean "it did not happen"; that reading is only unsafe once
|
|
235
263
|
// supersession is what emptied it. Without this, dropping stale evidence would trade a wrong pass
|
|
@@ -252,22 +280,29 @@ diagnose = true, baselines) {
|
|
|
252
280
|
return evalElement(session, predicate.query, predicate.state, predicate.absent ?? false, diagnose);
|
|
253
281
|
case PredicateKind.TEXT: {
|
|
254
282
|
// `scope` passes straight through: the text predicate has always been an element query with
|
|
255
|
-
// only `text` filled in, so scoping it needs the field, not a second code path.
|
|
256
|
-
|
|
257
|
-
// query as `text: undefined` — that is a locator asking for the empty string.
|
|
258
|
-
const query = {
|
|
259
|
-
...(undefined === predicate.contains ? {} : { text: predicate.contains }),
|
|
260
|
-
...(undefined === predicate.scope
|
|
261
|
-
? {}
|
|
262
|
-
: { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
|
|
263
|
-
};
|
|
283
|
+
// only `text` filled in, so scoping it needs the field, not a second code path.
|
|
284
|
+
const query = textPredicateQuery(predicate, session.sdkVersion);
|
|
264
285
|
const found = await evalElement(session, query, true === predicate.visible ? ElementState.VISIBLE : undefined, predicate.absent ?? false, diagnose);
|
|
265
286
|
if (undefined === predicate.satisfies)
|
|
266
287
|
return found;
|
|
267
288
|
return withTextProperty(found, predicate.satisfies, JSON.stringify(query), baselines?.get(predicate));
|
|
268
289
|
}
|
|
269
|
-
case PredicateKind.NET:
|
|
270
|
-
|
|
290
|
+
case PredicateKind.NET: {
|
|
291
|
+
const result = evalNet(events, predicate);
|
|
292
|
+
if (result.pass || keepsAnswers || result.inconclusive !== undefined)
|
|
293
|
+
return result;
|
|
294
|
+
// No floor, so a replaced page's answers were left out. If one would have satisfied the
|
|
295
|
+
// predicate, nothing here can say whether it was this action's: unknown, never a plain no.
|
|
296
|
+
const withAnswers = raw.filter((e) => onScreen(e) || isServerAnswer(e));
|
|
297
|
+
if (withAnswers.length === events.length || !evalNet(withAnswers, predicate).pass) {
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
...result,
|
|
302
|
+
failureReason: ANSWERED_BEFORE_NAVIGATION,
|
|
303
|
+
inconclusive: ANSWERED_BEFORE_NAVIGATION,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
271
306
|
case PredicateKind.ROUTE:
|
|
272
307
|
// `since` so an unanswered request already in flight before this window is not counted
|
|
273
308
|
// against the app — see unansweredIn.
|
|
@@ -424,7 +459,7 @@ function assertsExactCount(predicate) {
|
|
|
424
459
|
predicate.count !== undefined);
|
|
425
460
|
}
|
|
426
461
|
/**
|
|
427
|
-
* Does this predicate claim that something did NOT happen: an `absent` check, or a `not`?
|
|
462
|
+
* Does this predicate claim that something did NOT happen: an `absent` check, a `count: 0`, or a `not`?
|
|
428
463
|
*
|
|
429
464
|
* Such a claim is about the END of a window for the same reason an exact count is, and reads true
|
|
430
465
|
* at the start of every window by construction. Settled on its first reading, a clean-console check
|
|
@@ -437,7 +472,12 @@ function claimsAbsence(predicate) {
|
|
|
437
472
|
if (PredicateKind.ALL_OF === predicate.kind || PredicateKind.ANY_OF === predicate.kind) {
|
|
438
473
|
return predicate.predicates.some(claimsAbsence);
|
|
439
474
|
}
|
|
440
|
-
|
|
475
|
+
if ('absent' in predicate && true === predicate.absent) {
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
// `count: 0` is absence written as arithmetic. Held only for COUNT_CONFIRM_MS, a request sent
|
|
479
|
+
// 500 ms after the action passed a "no request" check.
|
|
480
|
+
return 'count' in predicate && 0 === predicate.count;
|
|
441
481
|
}
|
|
442
482
|
/**
|
|
443
483
|
* Evaluate now, else wait for it to become true (on each event + a poll) until timeout. `since` is
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
/** The container descriptor the browser attaches to a missed text query. */
|
|
20
20
|
interface SplitTextOwner {
|
|
21
21
|
ref?: string;
|
|
22
|
+
selector?: string;
|
|
22
23
|
role?: string;
|
|
23
24
|
name?: string;
|
|
24
25
|
}
|
|
@@ -29,4 +30,10 @@ interface SplitTextOwner {
|
|
|
29
30
|
* short message it already had. A clause that fires on every failure stops carrying information.
|
|
30
31
|
*/
|
|
31
32
|
export declare function describeSplitTextMiss(owner: SplitTextOwner | undefined, searchedText?: string): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The clause for a case-exact check that missed only on case: what the page shows, and the one
|
|
35
|
+
* change that matches it. It used to read "split across the children" with the same check as the
|
|
36
|
+
* recovery, which fails again.
|
|
37
|
+
*/
|
|
38
|
+
export declare function describeCaseMiss(shown: string | undefined): string | undefined;
|
|
32
39
|
export {};
|
|
@@ -38,7 +38,14 @@ export function describeSplitTextMiss(owner, searchedText) {
|
|
|
38
38
|
if (owner === undefined)
|
|
39
39
|
return undefined;
|
|
40
40
|
const where = nameOf(owner);
|
|
41
|
-
|
|
41
|
+
// A selector wins over the ref: it can be written into an `until` before the action runs,
|
|
42
|
+
// which is when the recovery has to exist. A ref is minted by a snapshot the agent may not
|
|
43
|
+
// have taken yet (#1147).
|
|
44
|
+
const scope = owner.selector !== undefined && owner.selector.length > 0
|
|
45
|
+
? owner.selector
|
|
46
|
+
: owner.ref !== undefined && owner.ref.length > 0
|
|
47
|
+
? owner.ref
|
|
48
|
+
: undefined;
|
|
42
49
|
const recovery = scope === undefined || searchedText === undefined
|
|
43
50
|
? 'scope to that container and match it as a whole'
|
|
44
51
|
: `retry as ${JSON.stringify({
|
|
@@ -49,3 +56,13 @@ export function describeSplitTextMiss(owner, searchedText) {
|
|
|
49
56
|
})}`;
|
|
50
57
|
return `that text IS on the page, split across the children of ${where} — no single element's own text carries it, so no text query can match it; ${recovery}`;
|
|
51
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The clause for a case-exact check that missed only on case: what the page shows, and the one
|
|
61
|
+
* change that matches it. It used to read "split across the children" with the same check as the
|
|
62
|
+
* recovery, which fails again.
|
|
63
|
+
*/
|
|
64
|
+
export function describeCaseMiss(shown) {
|
|
65
|
+
if (shown === undefined || 0 === shown.length)
|
|
66
|
+
return undefined;
|
|
67
|
+
return `the page shows "${truncate(shown)}", which differs only by case — this check is case-exact; retry with ignoreCase: true if the case does not matter`;
|
|
68
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReticleEvent } from '@reticlehq/core';
|
|
2
|
+
/**
|
|
3
|
+
* Meaningful state vs cache bookkeeping.
|
|
4
|
+
*
|
|
5
|
+
* A query cache (TanStack Query, SWR-shaped stores) re-emits every entry as it moves through
|
|
6
|
+
* pending → fetching → idle, stamping `fetchStatus`, `isStale` and `dataUpdatedAt` on the way. Those
|
|
7
|
+
* transitions are real, and they are not what an action CHANGED: one click on a cache-backed page
|
|
8
|
+
* reported a dozen `stateDiffs` whose only difference was the cache's own clock, and the one diff
|
|
9
|
+
* that mattered was the thirteenth.
|
|
10
|
+
*
|
|
11
|
+
* This rule classifies ONE before→after pair. It is deliberately narrow: a diff is bookkeeping only
|
|
12
|
+
* when both sides are plain objects AND every key that differs is a bookkeeping key. A change to
|
|
13
|
+
* `data`, `error`, or any key this list does not name is meaningful — so a value nobody anticipated
|
|
14
|
+
* is always reported, never silently classed as noise. `status` is included because on its own
|
|
15
|
+
* (no `data`/`error` move) it is the cache narrating its fetch, not the app changing.
|
|
16
|
+
*
|
|
17
|
+
* Predicates never read this: they evaluate the event window directly, so a `state` assertion on
|
|
18
|
+
* `isStale` still sees every transition. One verdict does: `state-vs-render` ignores a change this
|
|
19
|
+
* classes as bookkeeping, so a cache's own clock cannot stand in for an app change nobody rendered.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CACHE_BOOKKEEPING_KEYS: ReadonlySet<string>;
|
|
22
|
+
/** TRUE when this before→after differs only in cache-bookkeeping keys, and differs at all. */
|
|
23
|
+
export declare function isCacheBookkeepingDiff(from: unknown, to: unknown): boolean;
|
|
24
|
+
/** Whether a state event carries movement that can support state-vs-render. */
|
|
25
|
+
export declare function isMeaningfulStateChange(event: ReticleEvent): boolean;
|
|
26
|
+
/** True for a signal or store that Reticle sends about itself. It says nothing about the app. */
|
|
27
|
+
export declare const isReticleVoice: (name: string) => boolean;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EventType } from '@reticlehq/core';
|
|
2
|
+
/**
|
|
3
|
+
* Meaningful state vs cache bookkeeping.
|
|
4
|
+
*
|
|
5
|
+
* A query cache (TanStack Query, SWR-shaped stores) re-emits every entry as it moves through
|
|
6
|
+
* pending → fetching → idle, stamping `fetchStatus`, `isStale` and `dataUpdatedAt` on the way. Those
|
|
7
|
+
* transitions are real, and they are not what an action CHANGED: one click on a cache-backed page
|
|
8
|
+
* reported a dozen `stateDiffs` whose only difference was the cache's own clock, and the one diff
|
|
9
|
+
* that mattered was the thirteenth.
|
|
10
|
+
*
|
|
11
|
+
* This rule classifies ONE before→after pair. It is deliberately narrow: a diff is bookkeeping only
|
|
12
|
+
* when both sides are plain objects AND every key that differs is a bookkeeping key. A change to
|
|
13
|
+
* `data`, `error`, or any key this list does not name is meaningful — so a value nobody anticipated
|
|
14
|
+
* is always reported, never silently classed as noise. `status` is included because on its own
|
|
15
|
+
* (no `data`/`error` move) it is the cache narrating its fetch, not the app changing.
|
|
16
|
+
*
|
|
17
|
+
* Predicates never read this: they evaluate the event window directly, so a `state` assertion on
|
|
18
|
+
* `isStale` still sees every transition. One verdict does: `state-vs-render` ignores a change this
|
|
19
|
+
* classes as bookkeeping, so a cache's own clock cannot stand in for an app change nobody rendered.
|
|
20
|
+
*/
|
|
21
|
+
export const CACHE_BOOKKEEPING_KEYS = new Set([
|
|
22
|
+
'status',
|
|
23
|
+
'fetchStatus',
|
|
24
|
+
'isStale',
|
|
25
|
+
'dataUpdatedAt',
|
|
26
|
+
'errorUpdatedAt',
|
|
27
|
+
'isFetching',
|
|
28
|
+
'isInvalidated',
|
|
29
|
+
'fetchFailureCount',
|
|
30
|
+
]);
|
|
31
|
+
function plainObject(value) {
|
|
32
|
+
return 'object' === typeof value && null !== value && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function same(a, b) {
|
|
35
|
+
if (Object.is(a, b))
|
|
36
|
+
return true;
|
|
37
|
+
try {
|
|
38
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Not comparable is not "equal": a pair we cannot read is reported, never classed as noise.
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** TRUE when this before→after differs only in cache-bookkeeping keys, and differs at all. */
|
|
46
|
+
export function isCacheBookkeepingDiff(from, to) {
|
|
47
|
+
if (!plainObject(from) || !plainObject(to))
|
|
48
|
+
return false;
|
|
49
|
+
let differed = false;
|
|
50
|
+
for (const key of new Set([...Object.keys(from), ...Object.keys(to)])) {
|
|
51
|
+
if (same(from[key], to[key]))
|
|
52
|
+
continue;
|
|
53
|
+
if (!CACHE_BOOKKEEPING_KEYS.has(key))
|
|
54
|
+
return false;
|
|
55
|
+
differed = true;
|
|
56
|
+
}
|
|
57
|
+
return differed;
|
|
58
|
+
}
|
|
59
|
+
/** Whether a state event carries movement that can support state-vs-render. */
|
|
60
|
+
export function isMeaningfulStateChange(event) {
|
|
61
|
+
if (event.type !== EventType.STATE_CHANGE)
|
|
62
|
+
return false;
|
|
63
|
+
if (!('old' in event.data))
|
|
64
|
+
return true;
|
|
65
|
+
const hasAfter = 'value' in event.data || 'new' in event.data;
|
|
66
|
+
if (!hasAfter)
|
|
67
|
+
return true;
|
|
68
|
+
const after = 'value' in event.data ? event.data['value'] : event.data['new'];
|
|
69
|
+
return !isCacheBookkeepingDiff(event.data['old'], after);
|
|
70
|
+
}
|
|
71
|
+
/** The name prefixes of Reticle's own signals and stores (`reticle:busy`, `__reticle…`). */
|
|
72
|
+
const RETICLE_VOICE = /^(?:reticle:|__reticle)/;
|
|
73
|
+
/** True for a signal or store that Reticle sends about itself. It says nothing about the app. */
|
|
74
|
+
export const isReticleVoice = (name) => RETICLE_VOICE.test(name);
|
package/dist/window/adversary.js
CHANGED
|
@@ -45,6 +45,9 @@ function barestValue(schema) {
|
|
|
45
45
|
return false;
|
|
46
46
|
case 'ZodArray':
|
|
47
47
|
return [];
|
|
48
|
+
// A tuple has a fixed length, so the barest one still has every item.
|
|
49
|
+
case 'ZodTuple':
|
|
50
|
+
return (def.items ?? []).map((item) => barestValue(item));
|
|
48
51
|
case 'ZodLiteral':
|
|
49
52
|
return def.value;
|
|
50
53
|
case 'ZodEnum':
|
|
@@ -67,8 +70,9 @@ function barestObject(schema) {
|
|
|
67
70
|
const out = {};
|
|
68
71
|
for (const [key, field] of Object.entries(schema.shape)) {
|
|
69
72
|
const value = barestValue(field);
|
|
70
|
-
if (value !== undefined)
|
|
73
|
+
if (value !== undefined) {
|
|
71
74
|
out[key] = value;
|
|
75
|
+
}
|
|
72
76
|
}
|
|
73
77
|
return out;
|
|
74
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reticlehq/engine",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "The rules that decide a verdict: read what happened in a running app and say whether the declared consequence held. No browser, no daemon, no command line - an implementation of the OpenVerification specification you can use on its own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"verification",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"zod": "^3.24.1",
|
|
60
|
-
"@reticlehq/core": "3.
|
|
60
|
+
"@reticlehq/core": "3.8.0",
|
|
61
61
|
"open-verification": "1.0.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|