@reticlehq/engine 3.9.0 → 3.10.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/body-failures.js +16 -2
- package/dist/disagreement/contradiction-evidence.d.ts +119 -0
- package/dist/disagreement/contradiction-evidence.js +360 -48
- package/dist/disagreement/contradiction-types.d.ts +25 -0
- package/dist/disagreement/contradictions.d.ts +17 -1
- package/dist/disagreement/contradictions.js +146 -78
- package/dist/disagreement/echo-mismatch.js +205 -32
- package/dist/disagreement/stale-response.d.ts +10 -1
- package/dist/disagreement/stale-response.js +122 -47
- package/dist/evidence/already-true.d.ts +1 -1
- package/dist/evidence/already-true.js +13 -7
- package/dist/evidence/baseline.d.ts +1 -0
- package/dist/evidence/baseline.js +27 -16
- package/dist/evidence/blind-spots.d.ts +20 -3
- package/dist/evidence/blind-spots.js +127 -21
- package/dist/evidence/step-effect.d.ts +5 -0
- package/dist/evidence/step-effect.js +5 -2
- package/dist/evidence/verified.d.ts +23 -0
- package/dist/evidence/verified.js +53 -2
- package/dist/question/declared.d.ts +27 -0
- package/dist/question/declared.js +64 -13
- package/dist/question/predicate/net-blind-spots.d.ts +37 -1
- package/dist/question/predicate/net-blind-spots.js +72 -1
- package/dist/question/predicate/predicate-animation.d.ts +52 -0
- package/dist/question/predicate/predicate-animation.js +258 -0
- package/dist/question/predicate/predicate-element.d.ts +5 -2
- package/dist/question/predicate/predicate-element.js +103 -33
- package/dist/question/predicate/predicate-eval-kit.d.ts +2 -0
- package/dist/question/predicate/predicate-eval-kit.js +19 -0
- package/dist/question/predicate/predicate-eval.d.ts +1 -4
- package/dist/question/predicate/predicate-eval.js +38 -46
- package/dist/question/predicate/predicate-route.js +81 -27
- package/dist/question/predicate/predicate-schema.js +11 -2
- package/dist/question/predicate/predicate.js +79 -40
- package/dist/question/predicate/truncated-body-advice.d.ts +5 -0
- package/dist/question/predicate/truncated-body-advice.js +25 -0
- package/dist/state-bookkeeping.d.ts +24 -0
- package/dist/state-bookkeeping.js +31 -0
- package/dist/window/event-filters.d.ts +64 -0
- package/dist/window/event-filters.js +149 -20
- package/dist/window/network-detail-merge.d.ts +6 -0
- package/dist/window/network-detail-merge.js +43 -2
- package/package.json +2 -2
|
@@ -34,6 +34,8 @@ interface DeclaredExpectations {
|
|
|
34
34
|
netFailures: readonly DeclaredNetFailure[];
|
|
35
35
|
/** The caller required something to be ON SCREEN — an element or text, present rather than absent. */
|
|
36
36
|
rendersContent: boolean;
|
|
37
|
+
/** The caller required the page to be on a route. Read like `rendersContent`: top level and `allOf`. */
|
|
38
|
+
declaresRoute: boolean;
|
|
37
39
|
/**
|
|
38
40
|
* The `urlContains` of every net clause the predicate carries, failure or not.
|
|
39
41
|
*
|
|
@@ -50,7 +52,32 @@ interface DeclaredExpectations {
|
|
|
50
52
|
* `urlContains` is never here: the schema refuses it, and it would excuse every request.
|
|
51
53
|
*/
|
|
52
54
|
repeatableNetUrls: readonly DeclaredRead[];
|
|
55
|
+
/**
|
|
56
|
+
* The `path` of every state clause, and the `name` of every signal clause (#1531).
|
|
57
|
+
*
|
|
58
|
+
* A store change or a signal the caller named is the consequence they expected, so it ties that
|
|
59
|
+
* change to the action. `action-had-no-effect` reads it to tell the click's own effect from
|
|
60
|
+
* background churn in the same window.
|
|
61
|
+
*/
|
|
62
|
+
statePaths: readonly string[];
|
|
63
|
+
signalNames: readonly string[];
|
|
53
64
|
}
|
|
65
|
+
/** The store paths and signals `until` named, which tie their changes to the action (#1531). */
|
|
66
|
+
export declare function namedReactions(declared: DeclaredExpectations): {
|
|
67
|
+
namedStatePaths: readonly string[];
|
|
68
|
+
namedSignals: readonly string[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* What a held declaration proves, for the contradiction rules that infer from absence.
|
|
72
|
+
*
|
|
73
|
+
* `held` is the verdict passed AND the consequence was not already true before the action. A
|
|
74
|
+
* consequence that was already true proves nothing about the action. The act path and the assert
|
|
75
|
+
* path both call this, so the two cannot drift apart.
|
|
76
|
+
*/
|
|
77
|
+
export declare function provedConsequences(declared: DeclaredExpectations, held: boolean): {
|
|
78
|
+
renderProved: boolean;
|
|
79
|
+
routeProved: boolean;
|
|
80
|
+
};
|
|
54
81
|
export declare function declaredExpectations(predicate: Predicate | undefined): DeclaredExpectations;
|
|
55
82
|
/**
|
|
56
83
|
* Did the caller name a consequence that does not depend on the response body?
|
|
@@ -18,6 +18,23 @@
|
|
|
18
18
|
* something that never happened. Pure: a predicate in, a description out.
|
|
19
19
|
*/
|
|
20
20
|
import { PredicateKind, QueryBy, compareSourceClauses } from '@reticlehq/core';
|
|
21
|
+
/** The store paths and signals `until` named, which tie their changes to the action (#1531). */
|
|
22
|
+
export function namedReactions(declared) {
|
|
23
|
+
return { namedStatePaths: declared.statePaths, namedSignals: declared.signalNames };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a held declaration proves, for the contradiction rules that infer from absence.
|
|
27
|
+
*
|
|
28
|
+
* `held` is the verdict passed AND the consequence was not already true before the action. A
|
|
29
|
+
* consequence that was already true proves nothing about the action. The act path and the assert
|
|
30
|
+
* path both call this, so the two cannot drift apart.
|
|
31
|
+
*/
|
|
32
|
+
export function provedConsequences(declared, held) {
|
|
33
|
+
return {
|
|
34
|
+
renderProved: held && declared.rendersContent,
|
|
35
|
+
routeProved: held && declared.declaresRoute,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
21
38
|
/** Below this, a status is a success or a redirect: not a declared failure. */
|
|
22
39
|
const FAILURE_STATUS_MIN = 400;
|
|
23
40
|
/** Statuses that mean the caller was refused — the proof of an auth/authz denial, not a fault. */
|
|
@@ -49,14 +66,16 @@ function isDenialRole(role) {
|
|
|
49
66
|
return DENIAL_ROLES.has(role.toLowerCase());
|
|
50
67
|
}
|
|
51
68
|
function isDenialQuery(query) {
|
|
52
|
-
if (undefined !== query.role && isDenialRole(query.role))
|
|
69
|
+
if (undefined !== query.role && isDenialRole(query.role)) {
|
|
53
70
|
return true;
|
|
71
|
+
}
|
|
54
72
|
if (QueryBy.ROLE === query.by && undefined !== query.value && isDenialRole(query.value)) {
|
|
55
73
|
return true;
|
|
56
74
|
}
|
|
57
75
|
for (const field of [query.name, query.text, query.value, query.label]) {
|
|
58
|
-
if ('string' === typeof field && isDenialPhrase(field))
|
|
76
|
+
if ('string' === typeof field && isDenialPhrase(field)) {
|
|
59
77
|
return true;
|
|
78
|
+
}
|
|
60
79
|
}
|
|
61
80
|
return false;
|
|
62
81
|
}
|
|
@@ -69,16 +88,21 @@ export function declaredExpectations(predicate) {
|
|
|
69
88
|
const netFailures = [];
|
|
70
89
|
const netUrls = [];
|
|
71
90
|
const repeatableNetUrls = [];
|
|
91
|
+
const statePaths = [];
|
|
92
|
+
const signalNames = [];
|
|
72
93
|
let rendersContent = false;
|
|
94
|
+
let declaresRoute = false;
|
|
73
95
|
const walk = (p) => {
|
|
74
96
|
switch (p.kind) {
|
|
75
97
|
case PredicateKind.ALL_OF:
|
|
76
|
-
for (const child of p.predicates)
|
|
98
|
+
for (const child of p.predicates) {
|
|
77
99
|
walk(child);
|
|
100
|
+
}
|
|
78
101
|
return;
|
|
79
102
|
case PredicateKind.COMPARE:
|
|
80
|
-
for (const child of compareSourceClauses(p))
|
|
103
|
+
for (const child of compareSourceClauses(p)) {
|
|
81
104
|
walk(child);
|
|
105
|
+
}
|
|
82
106
|
return;
|
|
83
107
|
case PredicateKind.NET: {
|
|
84
108
|
netUrls.push(p.urlContains ?? '');
|
|
@@ -89,8 +113,9 @@ export function declaredExpectations(predicate) {
|
|
|
89
113
|
});
|
|
90
114
|
}
|
|
91
115
|
const declaredFailure = false === p.ok || (p.status !== undefined && p.status >= FAILURE_STATUS_MIN);
|
|
92
|
-
if (!declaredFailure)
|
|
116
|
+
if (!declaredFailure) {
|
|
93
117
|
return;
|
|
118
|
+
}
|
|
94
119
|
netFailures.push({
|
|
95
120
|
...(p.method === undefined ? {} : { method: p.method }),
|
|
96
121
|
...(p.urlContains === undefined ? {} : { urlContains: p.urlContains }),
|
|
@@ -101,8 +126,20 @@ export function declaredExpectations(predicate) {
|
|
|
101
126
|
case PredicateKind.ELEMENT:
|
|
102
127
|
if (true !== p.absent) {
|
|
103
128
|
rendersContent = true;
|
|
104
|
-
if (isDenialQuery(p.query))
|
|
129
|
+
if (isDenialQuery(p.query)) {
|
|
105
130
|
pushAuthDenialStatuses(netFailures);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
case PredicateKind.ROUTE:
|
|
135
|
+
declaresRoute = true;
|
|
136
|
+
return;
|
|
137
|
+
case PredicateKind.STATE:
|
|
138
|
+
statePaths.push(p.path);
|
|
139
|
+
return;
|
|
140
|
+
case PredicateKind.SIGNAL:
|
|
141
|
+
if (p.name !== undefined) {
|
|
142
|
+
signalNames.push(p.name);
|
|
106
143
|
}
|
|
107
144
|
return;
|
|
108
145
|
case PredicateKind.TEXT:
|
|
@@ -117,9 +154,18 @@ export function declaredExpectations(predicate) {
|
|
|
117
154
|
return;
|
|
118
155
|
}
|
|
119
156
|
};
|
|
120
|
-
if (predicate !== undefined)
|
|
157
|
+
if (predicate !== undefined) {
|
|
121
158
|
walk(predicate);
|
|
122
|
-
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
netFailures,
|
|
162
|
+
rendersContent,
|
|
163
|
+
declaresRoute,
|
|
164
|
+
netUrls,
|
|
165
|
+
repeatableNetUrls,
|
|
166
|
+
statePaths,
|
|
167
|
+
signalNames,
|
|
168
|
+
};
|
|
123
169
|
}
|
|
124
170
|
/**
|
|
125
171
|
* Did the caller name a consequence that does not depend on the response body?
|
|
@@ -137,8 +183,9 @@ export function declaredExpectations(predicate) {
|
|
|
137
183
|
* own.
|
|
138
184
|
*/
|
|
139
185
|
export function declaresBodyIndependentChannel(predicate) {
|
|
140
|
-
if (predicate === undefined)
|
|
186
|
+
if (predicate === undefined) {
|
|
141
187
|
return false;
|
|
188
|
+
}
|
|
142
189
|
const walk = (p) => {
|
|
143
190
|
switch (p.kind) {
|
|
144
191
|
case PredicateKind.ALL_OF:
|
|
@@ -177,13 +224,16 @@ export function declaresBodyIndependentChannel(predicate) {
|
|
|
177
224
|
*/
|
|
178
225
|
export function matchesDeclaredFailure(call, declared) {
|
|
179
226
|
return declared.some((d) => {
|
|
180
|
-
if (d.method !== undefined && d.method.toUpperCase() !== call.method.toUpperCase())
|
|
227
|
+
if (d.method !== undefined && d.method.toUpperCase() !== call.method.toUpperCase()) {
|
|
181
228
|
return false;
|
|
229
|
+
}
|
|
182
230
|
const haystack = call.matchUrl ?? call.url;
|
|
183
|
-
if (d.urlContains !== undefined && !haystack.includes(d.urlContains))
|
|
231
|
+
if (d.urlContains !== undefined && !haystack.includes(d.urlContains)) {
|
|
184
232
|
return false;
|
|
185
|
-
|
|
233
|
+
}
|
|
234
|
+
if (d.status !== undefined && d.status !== call.status) {
|
|
186
235
|
return false;
|
|
236
|
+
}
|
|
187
237
|
return true;
|
|
188
238
|
});
|
|
189
239
|
}
|
|
@@ -193,8 +243,9 @@ export function matchesDeclaredFailure(call, declared) {
|
|
|
193
243
|
* excuses a POST to the same endpoint (#1353).
|
|
194
244
|
*/
|
|
195
245
|
export function isDeclaredRead(call, reads) {
|
|
196
|
-
if (reads === undefined)
|
|
246
|
+
if (reads === undefined) {
|
|
197
247
|
return false;
|
|
248
|
+
}
|
|
198
249
|
const haystack = call.matchUrl ?? call.url;
|
|
199
250
|
return reads.some((r) => haystack.includes(r.urlContains) &&
|
|
200
251
|
(r.method === undefined || r.method.toUpperCase() === call.method.toUpperCase()));
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* zero-match `net` verdict says "not observable" or names its blind stretch, instead of "never
|
|
7
7
|
* happened". Split from `predicate-eval.ts`, which decides the verdict; this only knows the channel.
|
|
8
8
|
*
|
|
9
|
-
* Takes the filter's parts rather than the predicate, so it needs nothing from the contract.
|
|
9
|
+
* Takes the filter's parts rather than the predicate, so it needs nothing from the contract. The
|
|
10
|
+
* one exception is `unrecordedCallMiss`, which builds the whole `unknown` result for a net clause.
|
|
10
11
|
*/
|
|
12
|
+
import { unpatchedInWindow } from '../../window/event-filters.js';
|
|
13
|
+
import { describeNetFilter, type EvalResult } from './predicate-eval-kit.js';
|
|
11
14
|
/**
|
|
12
15
|
* Does this filter target a class of request the observer cannot see?
|
|
13
16
|
*
|
|
@@ -50,3 +53,36 @@ export declare function unobservedChannelReason(filter: string): string;
|
|
|
50
53
|
* that can settle it, because the state such a request produces IS observable after attach.
|
|
51
54
|
*/
|
|
52
55
|
export declare const PRE_ATTACH_CAVEAT: string;
|
|
56
|
+
/** `filter` is the net clause as applied — `describeNetFilter` of it. */
|
|
57
|
+
export declare function earlierMediaReason(filter: string): string;
|
|
58
|
+
/** The oracle that reports a miss over a request sent through an unpatched `fetch`. */
|
|
59
|
+
export declare const UNPATCHED_FETCH_ASSERTION = "net.unpatched-fetch";
|
|
60
|
+
/**
|
|
61
|
+
* Why a `net` miss is unknown when the browser recorded a matching request that no patched
|
|
62
|
+
* transport saw. `filter` is the net clause as applied — `describeNetFilter` of it.
|
|
63
|
+
*
|
|
64
|
+
* A client library can store `window.fetch` when its module loads, before Reticle patches it. A
|
|
65
|
+
* call through the stored function makes no `net.request`, so "no call matched" is false: the
|
|
66
|
+
* server got the request (#1660).
|
|
67
|
+
*/
|
|
68
|
+
export declare function unpatchedFetchReason(filter: string): string;
|
|
69
|
+
/** The oracle that reports a miss over a request whose page unloaded before its answer (#1944). */
|
|
70
|
+
export declare const PAGE_UNLOADED_ASSERTION = "net.page-unloaded";
|
|
71
|
+
/**
|
|
72
|
+
* Why a `net` miss is unknown when the page sent a matching request and then unloaded before the
|
|
73
|
+
* answer arrived. `filter` is the net clause as applied — `describeNetFilter` of it.
|
|
74
|
+
*
|
|
75
|
+
* A click can send a POST and then load a new document. Nobody records an answer that comes after
|
|
76
|
+
* the unload. The daemon carries the request into the new session marked `pageUnloaded`, so the
|
|
77
|
+
* record says the page sent it. "No call matched" would say it never did (#1944).
|
|
78
|
+
*/
|
|
79
|
+
export declare function pageUnloadedReason(filter: string): string;
|
|
80
|
+
/** The net clause a miss is judged against, as `describeNetFilter` takes it. */
|
|
81
|
+
type NetClause = Parameters<typeof describeNetFilter>[0];
|
|
82
|
+
/**
|
|
83
|
+
* `unknown` when a matching call happened and its record cannot answer: no patched transport saw it
|
|
84
|
+
* (#1660), or its page unloaded before the answer arrived (#1944). Else `undefined`. `observed` is
|
|
85
|
+
* read only when the miss is reported.
|
|
86
|
+
*/
|
|
87
|
+
export declare function unrecordedCallMiss(events: Parameters<typeof unpatchedInWindow>[0], p: NetClause, observed: () => string): EvalResult | undefined;
|
|
88
|
+
export {};
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* zero-match `net` verdict says "not observable" or names its blind stretch, instead of "never
|
|
7
7
|
* happened". Split from `predicate-eval.ts`, which decides the verdict; this only knows the channel.
|
|
8
8
|
*
|
|
9
|
-
* Takes the filter's parts rather than the predicate, so it needs nothing from the contract.
|
|
9
|
+
* Takes the filter's parts rather than the predicate, so it needs nothing from the contract. The
|
|
10
|
+
* one exception is `unrecordedCallMiss`, which builds the whole `unknown` result for a net clause.
|
|
10
11
|
*/
|
|
12
|
+
import { unloadedInWindow, unpatchedInWindow } from '../../window/event-filters.js';
|
|
13
|
+
import { describeNetFilter } from './predicate-eval-kit.js';
|
|
11
14
|
/**
|
|
12
15
|
* URL suffixes only the DOCUMENT fetches, which the network observer therefore never records.
|
|
13
16
|
*
|
|
@@ -189,3 +192,71 @@ export function unobservedChannelReason(filter) {
|
|
|
189
192
|
export const PRE_ATTACH_CAVEAT = ' — note that this window starts where the SDK attached, and requests made before that are never ' +
|
|
190
193
|
'captured, so a miss here cannot tell a call that was never made apart from one made before the ' +
|
|
191
194
|
'page connected; if the call is expected during startup, assert on the state it produces instead';
|
|
195
|
+
/** `filter` is the net clause as applied — `describeNetFilter` of it. */
|
|
196
|
+
export function earlierMediaReason(filter) {
|
|
197
|
+
return (`no fetch or XHR matched ${filter}, and the one media load that did match it was recorded ` +
|
|
198
|
+
`before this window opened. The network observer reports only the first resource timing ` +
|
|
199
|
+
`entry for a URL, and a media element load leaves no other record, so a repeat load inside ` +
|
|
200
|
+
`this window is not reported either: the empty window cannot show the file did not load in ` +
|
|
201
|
+
`it. Assert something that proves playback instead, for example an element check on the ` +
|
|
202
|
+
`<video> or <audio>`);
|
|
203
|
+
}
|
|
204
|
+
/** The oracle that reports a miss over a request sent through an unpatched `fetch`. */
|
|
205
|
+
export const UNPATCHED_FETCH_ASSERTION = 'net.unpatched-fetch';
|
|
206
|
+
/**
|
|
207
|
+
* Why a `net` miss is unknown when the browser recorded a matching request that no patched
|
|
208
|
+
* transport saw. `filter` is the net clause as applied — `describeNetFilter` of it.
|
|
209
|
+
*
|
|
210
|
+
* A client library can store `window.fetch` when its module loads, before Reticle patches it. A
|
|
211
|
+
* call through the stored function makes no `net.request`, so "no call matched" is false: the
|
|
212
|
+
* server got the request (#1660).
|
|
213
|
+
*/
|
|
214
|
+
export function unpatchedFetchReason(filter) {
|
|
215
|
+
return (`no recorded call matched ${filter}, but the browser recorded a request to a matching URL ` +
|
|
216
|
+
`that Reticle did not see. The request went through a fetch saved before Reticle connected ` +
|
|
217
|
+
`(a client library that stores window.fetch when it loads does this). Its method, status and ` +
|
|
218
|
+
`body are not known, so this clause cannot be judged. Connect Reticle earlier: add the build ` +
|
|
219
|
+
`plugin (@reticlehq/vite-plugin or @reticlehq/next), which runs connect() before the app code`);
|
|
220
|
+
}
|
|
221
|
+
/** The oracle that reports a miss over a request whose page unloaded before its answer (#1944). */
|
|
222
|
+
export const PAGE_UNLOADED_ASSERTION = 'net.page-unloaded';
|
|
223
|
+
/**
|
|
224
|
+
* Why a `net` miss is unknown when the page sent a matching request and then unloaded before the
|
|
225
|
+
* answer arrived. `filter` is the net clause as applied — `describeNetFilter` of it.
|
|
226
|
+
*
|
|
227
|
+
* A click can send a POST and then load a new document. Nobody records an answer that comes after
|
|
228
|
+
* the unload. The daemon carries the request into the new session marked `pageUnloaded`, so the
|
|
229
|
+
* record says the page sent it. "No call matched" would say it never did (#1944).
|
|
230
|
+
*/
|
|
231
|
+
export function pageUnloadedReason(filter) {
|
|
232
|
+
return (`the page sent a request matching ${filter}, and then its document unloaded before the answer ` +
|
|
233
|
+
'arrived. Nothing recorded the answer, so its status and body are unknown. This is not a ' +
|
|
234
|
+
'missing request. To prove the outcome, assert the state the request makes on the new page, ' +
|
|
235
|
+
'or make the request finish before the page navigates');
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* `unknown` when a matching call happened and its record cannot answer: no patched transport saw it
|
|
239
|
+
* (#1660), or its page unloaded before the answer arrived (#1944). Else `undefined`. `observed` is
|
|
240
|
+
* read only when the miss is reported.
|
|
241
|
+
*/
|
|
242
|
+
export function unrecordedCallMiss(events, p, observed) {
|
|
243
|
+
const since = p.since ?? 0;
|
|
244
|
+
const filter = describeNetFilter(p);
|
|
245
|
+
let reason = unpatchedFetchReason(filter);
|
|
246
|
+
let assertion = UNPATCHED_FETCH_ASSERTION;
|
|
247
|
+
if (!unpatchedInWindow(events, since, p.urlContains)) {
|
|
248
|
+
if (!unloadedInWindow(events, since, p.method, p.urlContains)) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
reason = pageUnloadedReason(filter);
|
|
252
|
+
assertion = PAGE_UNLOADED_ASSERTION;
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
pass: false,
|
|
256
|
+
failureReason: reason,
|
|
257
|
+
inconclusive: reason,
|
|
258
|
+
observed: observed(),
|
|
259
|
+
expected: `a recorded call matching ${filter}`,
|
|
260
|
+
assertion,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type EvalResult } from './predicate-eval-kit.js';
|
|
2
|
+
import type { PredicateSession } from './predicate-session.js';
|
|
3
|
+
export interface AnimationRuntime {
|
|
4
|
+
readonly startEventType: string;
|
|
5
|
+
readonly endEventType: string;
|
|
6
|
+
readonly animationsCommand: string;
|
|
7
|
+
readonly targetArg: string;
|
|
8
|
+
}
|
|
9
|
+
interface AnimationInputEvent {
|
|
10
|
+
type: string;
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
ref?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface AnimationEvent {
|
|
15
|
+
completed: boolean;
|
|
16
|
+
data: Record<string, unknown>;
|
|
17
|
+
ref?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AnimationPredicate {
|
|
20
|
+
name?: string;
|
|
21
|
+
target?: string;
|
|
22
|
+
completed?: boolean;
|
|
23
|
+
since?: number;
|
|
24
|
+
}
|
|
25
|
+
interface AnimationTargetDescriptor {
|
|
26
|
+
ref?: string;
|
|
27
|
+
role?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface AnimationObservation {
|
|
32
|
+
name?: string;
|
|
33
|
+
playState?: string;
|
|
34
|
+
target?: AnimationTargetDescriptor | null;
|
|
35
|
+
targetMatches?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface AnimationTargetResolution {
|
|
38
|
+
target?: string;
|
|
39
|
+
matched?: boolean;
|
|
40
|
+
refs?: readonly string[];
|
|
41
|
+
count?: number;
|
|
42
|
+
invalid?: boolean;
|
|
43
|
+
truncated?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface AnimationSnapshot {
|
|
46
|
+
animations: readonly AnimationObservation[];
|
|
47
|
+
target?: AnimationTargetResolution;
|
|
48
|
+
}
|
|
49
|
+
export declare function animationSnapshotFrom(value: unknown): AnimationSnapshot | undefined;
|
|
50
|
+
export declare function evalAnimation(events: readonly AnimationEvent[], p: AnimationPredicate, live?: AnimationSnapshot): EvalResult;
|
|
51
|
+
export declare function evalAnimationPredicate(session: PredicateSession, events: AnimationInputEvent[], predicate: AnimationPredicate, floor: number, runtime: AnimationRuntime): Promise<EvalResult>;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { isReticleVoice } from '../../state-bookkeeping.js';
|
|
2
|
+
import { str, num } from './predicate-eval-kit.js';
|
|
3
|
+
function record(value) {
|
|
4
|
+
return 'object' === typeof value && null !== value && !Array.isArray(value)
|
|
5
|
+
? value
|
|
6
|
+
: undefined;
|
|
7
|
+
}
|
|
8
|
+
function strings(value) {
|
|
9
|
+
if (!Array.isArray(value)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return value.filter((one) => 'string' === typeof one);
|
|
13
|
+
}
|
|
14
|
+
function animationTargetDescriptor(value) {
|
|
15
|
+
if (null === value) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const target = record(value);
|
|
19
|
+
if (target === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const ref = str(target['ref']);
|
|
23
|
+
const role = str(target['role']);
|
|
24
|
+
const name = str(target['name']);
|
|
25
|
+
const text = str(target['text']);
|
|
26
|
+
return {
|
|
27
|
+
...(ref === undefined ? {} : { ref }),
|
|
28
|
+
...(role === undefined ? {} : { role }),
|
|
29
|
+
...(name === undefined ? {} : { name }),
|
|
30
|
+
...(text === undefined ? {} : { text }),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function animationObservation(value) {
|
|
34
|
+
const row = record(value);
|
|
35
|
+
if (row === undefined) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const target = animationTargetDescriptor(row['target']);
|
|
39
|
+
const name = str(row['name']);
|
|
40
|
+
const playState = str(row['playState']);
|
|
41
|
+
return {
|
|
42
|
+
...(name === undefined ? {} : { name }),
|
|
43
|
+
...(playState === undefined ? {} : { playState }),
|
|
44
|
+
...(target === undefined ? {} : { target }),
|
|
45
|
+
...(true === row['targetMatches'] || false === row['targetMatches']
|
|
46
|
+
? { targetMatches: row['targetMatches'] }
|
|
47
|
+
: {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function animationTargetResolution(value) {
|
|
51
|
+
const target = record(value);
|
|
52
|
+
if (target === undefined) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const refs = strings(target['refs']);
|
|
56
|
+
const targetValue = str(target['target']);
|
|
57
|
+
const count = num(target['count']);
|
|
58
|
+
return {
|
|
59
|
+
...(targetValue === undefined ? {} : { target: targetValue }),
|
|
60
|
+
...(true === target['matched'] || false === target['matched']
|
|
61
|
+
? { matched: target['matched'] }
|
|
62
|
+
: {}),
|
|
63
|
+
...(refs === undefined ? {} : { refs }),
|
|
64
|
+
...(count === undefined ? {} : { count }),
|
|
65
|
+
...(true === target['invalid'] ? { invalid: true } : {}),
|
|
66
|
+
...(true === target['truncated'] ? { truncated: true } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function animationSnapshotFrom(value) {
|
|
70
|
+
const result = record(value);
|
|
71
|
+
if (result === undefined || !Array.isArray(result['animations'])) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const target = animationTargetResolution(result['target']);
|
|
75
|
+
return {
|
|
76
|
+
animations: result['animations']
|
|
77
|
+
.map(animationObservation)
|
|
78
|
+
.filter((row) => row !== undefined),
|
|
79
|
+
...(target === undefined ? {} : { target }),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function targetRef(target) {
|
|
83
|
+
return null === target ? undefined : target?.ref;
|
|
84
|
+
}
|
|
85
|
+
function eventMatchesTarget(event, p, live) {
|
|
86
|
+
if (p.target === undefined) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
const refs = live?.target?.refs;
|
|
90
|
+
if (refs !== undefined) {
|
|
91
|
+
return event.ref !== undefined && refs.includes(event.ref);
|
|
92
|
+
}
|
|
93
|
+
return event.ref === p.target;
|
|
94
|
+
}
|
|
95
|
+
function targetMatchesLive(animation, p, live) {
|
|
96
|
+
if (p.target === undefined) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (animation.targetMatches !== undefined) {
|
|
100
|
+
return animation.targetMatches;
|
|
101
|
+
}
|
|
102
|
+
const ref = targetRef(animation.target);
|
|
103
|
+
if (ref === undefined) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const refs = live?.target?.refs;
|
|
107
|
+
return refs === undefined ? ref === p.target : refs.includes(ref);
|
|
108
|
+
}
|
|
109
|
+
const PLAY_STATE_FINISHED = 'finished';
|
|
110
|
+
const PLAY_STATE_IDLE = 'idle';
|
|
111
|
+
function playStateMatches(animation, p) {
|
|
112
|
+
if (true === p.completed) {
|
|
113
|
+
return PLAY_STATE_FINISHED === animation.playState;
|
|
114
|
+
}
|
|
115
|
+
return (animation.playState !== undefined &&
|
|
116
|
+
![PLAY_STATE_FINISHED, PLAY_STATE_IDLE].includes(animation.playState));
|
|
117
|
+
}
|
|
118
|
+
function matchesLiveAnimation(animation, p, live) {
|
|
119
|
+
if (p.name === undefined ? isReticleVoice(animation.name ?? '') : animation.name !== p.name) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (!targetMatchesLive(animation, p, live)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return playStateMatches(animation, p);
|
|
126
|
+
}
|
|
127
|
+
function describeAnimationTarget(target) {
|
|
128
|
+
if (null === target) {
|
|
129
|
+
return 'no target';
|
|
130
|
+
}
|
|
131
|
+
if (target === undefined) {
|
|
132
|
+
return 'unknown target';
|
|
133
|
+
}
|
|
134
|
+
const label = target.name !== undefined && target.name.length > 0
|
|
135
|
+
? `${target.role ?? 'element'} ${JSON.stringify(target.name)}`
|
|
136
|
+
: (target.role ?? target.text ?? 'element');
|
|
137
|
+
return target.ref === undefined ? label : `${label} (${target.ref})`;
|
|
138
|
+
}
|
|
139
|
+
function describeAnimationObservation(animation) {
|
|
140
|
+
const name = animation.name ?? '(unnamed)';
|
|
141
|
+
const playState = animation.playState ?? 'unknown state';
|
|
142
|
+
return `${name} on ${describeAnimationTarget(animation.target)} (${playState})`;
|
|
143
|
+
}
|
|
144
|
+
function observedAnimations(events, live) {
|
|
145
|
+
const liveObserved = live?.animations.map(describeAnimationObservation) ?? [];
|
|
146
|
+
if (liveObserved.length > 0) {
|
|
147
|
+
return `current animations: ${liveObserved.join('; ')}`;
|
|
148
|
+
}
|
|
149
|
+
const eventObserved = events.map((event) => {
|
|
150
|
+
const name = str(event.data['name']) ?? '(unnamed)';
|
|
151
|
+
const kind = event.completed ? 'ended' : 'started';
|
|
152
|
+
return event.ref === undefined ? `${name} ${kind}` : `${name} ${kind} on ${event.ref}`;
|
|
153
|
+
});
|
|
154
|
+
if (eventObserved.length > 0) {
|
|
155
|
+
return `animation events in the window: ${eventObserved.join('; ')}`;
|
|
156
|
+
}
|
|
157
|
+
if (live === undefined) {
|
|
158
|
+
return 'no matching animation in the window';
|
|
159
|
+
}
|
|
160
|
+
return 'no matching animation in the window and none currently reported by the page';
|
|
161
|
+
}
|
|
162
|
+
function animationTargetMiss(p, target) {
|
|
163
|
+
if (p.target === undefined || target === undefined || true === target.matched) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
const quoted = JSON.stringify(p.target);
|
|
167
|
+
const reason = true === target.invalid
|
|
168
|
+
? `animation target selector ${quoted} is not a valid CSS selector`
|
|
169
|
+
: `animation target ${quoted} matched no element`;
|
|
170
|
+
return {
|
|
171
|
+
pass: false,
|
|
172
|
+
failureReason: reason,
|
|
173
|
+
observed: true === target.invalid
|
|
174
|
+
? 'the target selector could not be parsed'
|
|
175
|
+
: 'the target resolved to no element',
|
|
176
|
+
expected: 'a target selector that resolves to an element, or a live Reticle ref like e12',
|
|
177
|
+
assertion: 'animation.target',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function animationMiss(events, p, live) {
|
|
181
|
+
return {
|
|
182
|
+
pass: false,
|
|
183
|
+
failureReason: `no animation matched ${JSON.stringify(p)}`,
|
|
184
|
+
observed: observedAnimations(events, live),
|
|
185
|
+
expected: `an animation matching ${JSON.stringify(p)}`,
|
|
186
|
+
assertion: 'animation.present',
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export function evalAnimation(events, p, live) {
|
|
190
|
+
const wantCompleted = true === p.completed;
|
|
191
|
+
const hit = events.find((event) => {
|
|
192
|
+
if (event.completed !== wantCompleted) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const name = str(event.data['name']);
|
|
196
|
+
if (p.name === undefined ? isReticleVoice(name ?? '') : name !== p.name) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
if (!eventMatchesTarget(event, p, live)) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
});
|
|
204
|
+
if (hit !== undefined) {
|
|
205
|
+
return { pass: true, evidence: hit.data };
|
|
206
|
+
}
|
|
207
|
+
const targetMiss = animationTargetMiss(p, live?.target);
|
|
208
|
+
if (targetMiss !== undefined) {
|
|
209
|
+
return targetMiss;
|
|
210
|
+
}
|
|
211
|
+
const liveHit = p.since === undefined
|
|
212
|
+
? live?.animations.find((animation) => matchesLiveAnimation(animation, p, live))
|
|
213
|
+
: undefined;
|
|
214
|
+
return liveHit !== undefined ? { pass: true, evidence: liveHit } : animationMiss(events, p, live);
|
|
215
|
+
}
|
|
216
|
+
function animationEvents(events, runtime) {
|
|
217
|
+
return events.flatMap((event) => {
|
|
218
|
+
if (runtime.startEventType === event.type) {
|
|
219
|
+
return [
|
|
220
|
+
{
|
|
221
|
+
completed: false,
|
|
222
|
+
data: event.data,
|
|
223
|
+
...(event.ref === undefined ? {} : { ref: event.ref }),
|
|
224
|
+
},
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
if (runtime.endEventType === event.type) {
|
|
228
|
+
return [
|
|
229
|
+
{
|
|
230
|
+
completed: true,
|
|
231
|
+
data: event.data,
|
|
232
|
+
...(event.ref === undefined ? {} : { ref: event.ref }),
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
return [];
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
async function readAnimationSnapshot(session, predicate, runtime) {
|
|
240
|
+
const result = await session.command(runtime.animationsCommand, predicate.target === undefined ? {} : { [runtime.targetArg]: predicate.target });
|
|
241
|
+
return result.ok ? animationSnapshotFrom(result.result) : undefined;
|
|
242
|
+
}
|
|
243
|
+
export async function evalAnimationPredicate(session, events, predicate, floor, runtime) {
|
|
244
|
+
const useLiveAnimations = 0 === floor;
|
|
245
|
+
let snapshot = predicate.target !== undefined
|
|
246
|
+
? await readAnimationSnapshot(session, predicate, runtime)
|
|
247
|
+
: undefined;
|
|
248
|
+
const observed = animationEvents(events, runtime);
|
|
249
|
+
const eventSnapshot = useLiveAnimations || snapshot === undefined ? snapshot : { ...snapshot, animations: [] };
|
|
250
|
+
const eventResult = evalAnimation(observed, predicate, eventSnapshot);
|
|
251
|
+
if (eventResult.pass || !useLiveAnimations) {
|
|
252
|
+
return eventResult;
|
|
253
|
+
}
|
|
254
|
+
if (snapshot === undefined) {
|
|
255
|
+
snapshot = await readAnimationSnapshot(session, predicate, runtime);
|
|
256
|
+
}
|
|
257
|
+
return evalAnimation(observed, predicate, snapshot);
|
|
258
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* back (`residualQueryChecks`), the absent/present asymmetry, and the near-miss diagnostics that only
|
|
7
7
|
* ever enrich a failure. Nothing else in the predicate layer talks to `ReticleCommand.MATCH`.
|
|
8
8
|
*/
|
|
9
|
-
import { type ElementQuery, ElementState } from '@reticlehq/core';
|
|
9
|
+
import { type ElementQuery, ElementState, type MatchResult } from '@reticlehq/core';
|
|
10
10
|
import { type EvalResult } from './predicate-eval.js';
|
|
11
11
|
import type { PredicateSession } from './predicate-session.js';
|
|
12
12
|
import { type Baseline, type PropertyAssertion } from './property.js';
|
|
@@ -17,9 +17,12 @@ export declare const ARIA_HIDDEN_NOTE = "text is inside an aria-hidden subtree \
|
|
|
17
17
|
* so the hint can say exactly what to use instead.
|
|
18
18
|
*/
|
|
19
19
|
export declare const HTML_TAG_TO_ARIA_ROLE: Map<string, string>;
|
|
20
|
+
export declare function matchOnce(session: PredicateSession, query: ElementQuery, state: ElementState | undefined, diagnose?: boolean, fullText?: boolean): Promise<MatchResult>;
|
|
20
21
|
export declare function evalElement(session: PredicateSession, query: ElementQuery, state: ElementState | undefined, absent: boolean, diagnose: boolean,
|
|
21
22
|
/** Describe the matches with their full text, for a caller that will JUDGE it (see `withTextProperty`). */
|
|
22
|
-
fullText?: boolean
|
|
23
|
+
fullText?: boolean,
|
|
24
|
+
/** For an absence: only an element whose text satisfies this fails it. See `absentUnlessSatisfied`. */
|
|
25
|
+
unlessText?: PropertyAssertion): Promise<EvalResult>;
|
|
23
26
|
/** The text of every element a passing match described, joined — what a reader sees there. */
|
|
24
27
|
export declare function joinedText(evidence: unknown): string;
|
|
25
28
|
/**
|