@reticlehq/engine 3.9.0 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/disagreement/body-failures.js +16 -2
- package/dist/disagreement/contradiction-evidence.d.ts +119 -0
- package/dist/disagreement/contradiction-evidence.js +360 -48
- package/dist/disagreement/contradiction-types.d.ts +25 -0
- package/dist/disagreement/contradictions.d.ts +17 -1
- package/dist/disagreement/contradictions.js +146 -78
- package/dist/disagreement/echo-mismatch.js +205 -32
- package/dist/disagreement/stale-response.d.ts +10 -1
- package/dist/disagreement/stale-response.js +122 -47
- package/dist/evidence/already-true.d.ts +1 -1
- package/dist/evidence/already-true.js +13 -7
- package/dist/evidence/baseline.d.ts +1 -0
- package/dist/evidence/baseline.js +27 -16
- package/dist/evidence/blind-spots.d.ts +20 -3
- package/dist/evidence/blind-spots.js +127 -21
- package/dist/evidence/step-effect.d.ts +5 -0
- package/dist/evidence/step-effect.js +5 -2
- package/dist/evidence/verified.d.ts +23 -0
- package/dist/evidence/verified.js +53 -2
- package/dist/question/declared.d.ts +27 -0
- package/dist/question/declared.js +64 -13
- package/dist/question/predicate/net-blind-spots.d.ts +37 -1
- package/dist/question/predicate/net-blind-spots.js +72 -1
- package/dist/question/predicate/predicate-animation.d.ts +52 -0
- package/dist/question/predicate/predicate-animation.js +258 -0
- package/dist/question/predicate/predicate-element.d.ts +5 -2
- package/dist/question/predicate/predicate-element.js +103 -33
- package/dist/question/predicate/predicate-eval-kit.d.ts +2 -0
- package/dist/question/predicate/predicate-eval-kit.js +19 -0
- package/dist/question/predicate/predicate-eval.d.ts +1 -4
- package/dist/question/predicate/predicate-eval.js +38 -46
- package/dist/question/predicate/predicate-route.js +81 -27
- package/dist/question/predicate/predicate-schema.js +11 -2
- package/dist/question/predicate/predicate.js +79 -40
- package/dist/question/predicate/truncated-body-advice.d.ts +5 -0
- package/dist/question/predicate/truncated-body-advice.js +25 -0
- package/dist/state-bookkeeping.d.ts +24 -0
- package/dist/state-bookkeeping.js +31 -0
- package/dist/window/event-filters.d.ts +64 -0
- package/dist/window/event-filters.js +149 -20
- package/dist/window/network-detail-merge.d.ts +6 -0
- package/dist/window/network-detail-merge.js +43 -2
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { MatchArg, QueryBy, ReticleCommand, TRANSPORT_LIMITS, ElementState, } from '@reticlehq/core';
|
|
10
10
|
import { describeAltOnNonImage, describeUnusableElementQuery, residualQueryChecks, withAltProjected, satisfiesResiduals, describeResidual, } from './predicate-eval.js';
|
|
11
|
-
import { clipBody } from './predicate-eval-kit.js';
|
|
11
|
+
import { clipBody, sdkPredates } from './predicate-eval-kit.js';
|
|
12
12
|
import { describeTestidMiss } from './testid-near-miss.js';
|
|
13
13
|
import { describeCaseMiss, describeSplitTextMiss } from './split-text-miss.js';
|
|
14
14
|
import { satisfiesProperty } from './property.js';
|
|
@@ -94,6 +94,20 @@ function describePresentTestidsCut(shown, total) {
|
|
|
94
94
|
}
|
|
95
95
|
return ` (the present-testid list shows the first ${String(shown)} of ${String(total)} in document order — absence from it proves nothing)`;
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* How many elements a CSS scope matched, when it matched more than one, or nothing. The search covers
|
|
99
|
+
* all of them, and without the count a miss across a list of items read like a miss in one (#1663).
|
|
100
|
+
*/
|
|
101
|
+
function describeScopeMatches(scopeMatches) {
|
|
102
|
+
if (scopeMatches === undefined || scopeMatches <= 1) {
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
return ` (searched all ${String(scopeMatches)} elements the scope matched)`;
|
|
106
|
+
}
|
|
107
|
+
/** ` (ref e3)` for a described element, or '' when there is none or it has no ref. */
|
|
108
|
+
function describeRef(element) {
|
|
109
|
+
return element === undefined || '' === element.ref ? '' : ` (ref ${element.ref})`;
|
|
110
|
+
}
|
|
97
111
|
/**
|
|
98
112
|
* Why an `absent` check failed. `absent` means removed from the DOM, so an element the app hid but
|
|
99
113
|
* kept mounted still fails it, correctly. But "found 1" beside `visible: false` evidence reads as a
|
|
@@ -103,8 +117,8 @@ function describePresentTestidsCut(shown, total) {
|
|
|
103
117
|
* check names no state: with `state: "hidden"` the advice would repeat the check itself, and with any
|
|
104
118
|
* other state it would ask the caller to drop the condition they actually wrote.
|
|
105
119
|
*/
|
|
106
|
-
function describeAbsentMiss(match, state) {
|
|
107
|
-
const found = `expected element
|
|
120
|
+
function describeAbsentMiss(match, state, subject) {
|
|
121
|
+
const found = `expected no element matching ${subject} but found ${String(match.count)}`;
|
|
108
122
|
const allDescribedHidden = undefined === state &&
|
|
109
123
|
match.elements.length > 0 &&
|
|
110
124
|
match.elements.length === match.count &&
|
|
@@ -142,7 +156,7 @@ function matchNotServedMessage(sdkVersion, declared) {
|
|
|
142
156
|
"connected and this is not one of them. Update the page's @reticlehq packages: " +
|
|
143
157
|
'`reticle update` in the app.');
|
|
144
158
|
}
|
|
145
|
-
async function matchOnce(session, query, state, diagnose, fullText = false) {
|
|
159
|
+
export async function matchOnce(session, query, state, diagnose, fullText = false) {
|
|
146
160
|
// A page that declared its commands and left match out can never answer (#1990): the session
|
|
147
161
|
// refuses the send, and that refusal used to be read as "zero matches". Refuse before the trip.
|
|
148
162
|
if (session.commands !== undefined && !session.commands.includes(ReticleCommand.MATCH)) {
|
|
@@ -154,10 +168,49 @@ async function matchOnce(session, query, state, diagnose, fullText = false) {
|
|
|
154
168
|
...(true === diagnose ? { diagnose: true } : {}),
|
|
155
169
|
...(fullText ? { [MatchArg.FULL_TEXT]: true } : {}),
|
|
156
170
|
});
|
|
171
|
+
// A reply with an error never looked at the page. Read as zero matches, a query the page's schema
|
|
172
|
+
// refused or a matcher that threw became a false `no`. Thrown, the verdict reads it as unknown.
|
|
157
173
|
if (!res.ok) {
|
|
158
|
-
|
|
174
|
+
const error = res.error ?? 'no error given';
|
|
175
|
+
// An SDK older than MATCH_CASE_SINCE refuses the whole query for this one key, and a page that
|
|
176
|
+
// reports no version is still sent it. Ask once more without it and check the case here.
|
|
177
|
+
if (true === query.matchCase && error.includes(MATCH_CASE_FIELD)) {
|
|
178
|
+
return matchCaseOnThisSide(session, query, state, diagnose, fullText);
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`the page could not answer 'match': ${error}`);
|
|
159
181
|
}
|
|
160
|
-
|
|
182
|
+
// An ok reply with no result said nothing about the page either. Defaulting it to zero matches
|
|
183
|
+
// was the same false `no`.
|
|
184
|
+
if (undefined === res.result || null === res.result) {
|
|
185
|
+
throw new Error(`the page could not answer 'match': the reply carried no result`);
|
|
186
|
+
}
|
|
187
|
+
return res.result;
|
|
188
|
+
}
|
|
189
|
+
/** The query key an SDK older than MATCH_CASE_SINCE does not know. Its refusal names the key. */
|
|
190
|
+
const MATCH_CASE_FIELD = 'matchCase';
|
|
191
|
+
/**
|
|
192
|
+
* Match without `matchCase`, then keep only the elements whose text holds the exact case.
|
|
193
|
+
*
|
|
194
|
+
* The case is checked on the text the page describes. When that text cannot show the match (a
|
|
195
|
+
* truncated description, or more matches than the page described), the result is not decided: the
|
|
196
|
+
* error makes the verdict unknown, never a false `no`.
|
|
197
|
+
*/
|
|
198
|
+
async function matchCaseOnThisSide(session, query, state, diagnose, fullText) {
|
|
199
|
+
const caseBlind = { ...query };
|
|
200
|
+
delete caseBlind.matchCase;
|
|
201
|
+
const match = await matchOnce(session, caseBlind, state, diagnose, fullText);
|
|
202
|
+
const want = query.text;
|
|
203
|
+
if (undefined === want) {
|
|
204
|
+
return match;
|
|
205
|
+
}
|
|
206
|
+
const undecided = match.count > match.elements.length ||
|
|
207
|
+
match.elements.some((element) => !(element.text ?? element.name).toLowerCase().includes(want.toLowerCase()));
|
|
208
|
+
if (undecided) {
|
|
209
|
+
throw new Error(`the page's SDK cannot match case, and its description of the matches does not show ` +
|
|
210
|
+
`${JSON.stringify(want)}, so the case was not checked. Update the page's @reticlehq packages`);
|
|
211
|
+
}
|
|
212
|
+
const kept = match.elements.filter((element) => satisfiesResiduals(element, [['text', want]]));
|
|
213
|
+
return { ...match, matched: kept.length > 0, count: kept.length, elements: kept };
|
|
161
214
|
}
|
|
162
215
|
/**
|
|
163
216
|
* Roles that exist to ANNOUNCE something. An empty one is the container, not the message.
|
|
@@ -206,26 +259,8 @@ function substantiveMatches(query, elements) {
|
|
|
206
259
|
const ELEMENT_STATE_SINCE = {
|
|
207
260
|
// The key is checked against ElementState by the Record type, so a misspelt state cannot compile.
|
|
208
261
|
pressed: '3.4.0',
|
|
262
|
+
receivesPointer: '3.10.0',
|
|
209
263
|
};
|
|
210
|
-
/** Leading `major.minor.patch` as numbers; a pre-release of a version counts as that version. */
|
|
211
|
-
function versionParts(version) {
|
|
212
|
-
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
213
|
-
return null === m ? undefined : [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
214
|
-
}
|
|
215
|
-
/** Whether the page's SDK is older than `since`. An unknown or unreadable version is not. */
|
|
216
|
-
function sdkPredates(sdk, since) {
|
|
217
|
-
const have = sdk === undefined ? undefined : versionParts(sdk);
|
|
218
|
-
const need = versionParts(since);
|
|
219
|
-
if (have === undefined || need === undefined) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
for (let i = 0; i < 3; i += 1) {
|
|
223
|
-
if (have[i] !== need[i]) {
|
|
224
|
-
return (have[i] ?? 0) < (need[i] ?? 0);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
264
|
/** The state, when the page's SDK is older than the first release that answers it. */
|
|
230
265
|
function stateTheSdkPredates(sdk, state) {
|
|
231
266
|
const since = state === undefined ? undefined : ELEMENT_STATE_SINCE[state];
|
|
@@ -238,7 +273,9 @@ function stateTheSdkPredates(sdk, state) {
|
|
|
238
273
|
const MATCH_CASE_SINCE = '3.7.0';
|
|
239
274
|
export async function evalElement(session, query, state, absent, diagnose,
|
|
240
275
|
/** Describe the matches with their full text, for a caller that will JUDGE it (see `withTextProperty`). */
|
|
241
|
-
fullText = false
|
|
276
|
+
fullText = false,
|
|
277
|
+
/** For an absence: only an element whose text satisfies this fails it. See `absentUnlessSatisfied`. */
|
|
278
|
+
unlessText) {
|
|
242
279
|
const tooOld = stateTheSdkPredates(session.sdkVersion, state);
|
|
243
280
|
if (tooOld !== undefined) {
|
|
244
281
|
const reason = `the page's SDK is ${tooOld.sdk}, and the '${tooOld.state}' state needs ${tooOld.since} or ` +
|
|
@@ -261,7 +298,10 @@ fullText = false) {
|
|
|
261
298
|
const reason = describeUnusableElementQuery(query, residual.unusable);
|
|
262
299
|
return { pass: false, failureReason: reason, inconclusive: reason };
|
|
263
300
|
}
|
|
264
|
-
|
|
301
|
+
// A `text` checked on this side is checked against the element's text, which is the 80-character
|
|
302
|
+
// display form unless the full text is asked for: words past the cut read as absent.
|
|
303
|
+
const textOnThisSide = residual.checks.some(([field]) => 'text' === field);
|
|
304
|
+
let match = await matchOnce(session, withAltProjected(query, residual.checks), state, diagnose, fullText || textOnThisSide);
|
|
265
305
|
const subject = JSON.stringify(query);
|
|
266
306
|
// Full text was asked for to JUDGE it, so a reading that is not the full text is not graded.
|
|
267
307
|
if (fullText && !absent && match.matched) {
|
|
@@ -324,10 +364,13 @@ fullText = false) {
|
|
|
324
364
|
if (true === match.scopeMissing) {
|
|
325
365
|
return { pass: true, evidence: { absent: true, scopeMissing: true } };
|
|
326
366
|
}
|
|
367
|
+
if (match.matched && unlessText !== undefined) {
|
|
368
|
+
return absentUnlessSatisfied(match, unlessText, subject);
|
|
369
|
+
}
|
|
327
370
|
return match.matched
|
|
328
371
|
? {
|
|
329
372
|
pass: false,
|
|
330
|
-
failureReason: describeAbsentMiss(match, state),
|
|
373
|
+
failureReason: describeAbsentMiss(match, state, subject),
|
|
331
374
|
observed: `${String(match.count)} element(s) matching ${subject}`,
|
|
332
375
|
expected: `no element matching ${subject}`,
|
|
333
376
|
assertion: 'element.absent',
|
|
@@ -396,7 +439,7 @@ fullText = false) {
|
|
|
396
439
|
if (!diagnose) {
|
|
397
440
|
return {
|
|
398
441
|
pass: false,
|
|
399
|
-
failureReason: `no element matched ${subject}${state === undefined ? '' : ` in state '${state}'`}`,
|
|
442
|
+
failureReason: `no element matched ${subject}${state === undefined ? '' : ` in state '${state}'`}${describeScopeMatches(match.scopeMatches)}`,
|
|
400
443
|
observed: 'no matching element on the page',
|
|
401
444
|
expected: `an element matching ${subject}${state === undefined ? '' : ` in state '${state}'`}`,
|
|
402
445
|
assertion: 'element.present',
|
|
@@ -408,7 +451,7 @@ fullText = false) {
|
|
|
408
451
|
if (relaxed.matched) {
|
|
409
452
|
return {
|
|
410
453
|
pass: false,
|
|
411
|
-
failureReason: `element exists but not in state '${state}'`,
|
|
454
|
+
failureReason: `element matching ${subject} exists${describeRef(relaxed.elements[0])} but not in state '${state}'`,
|
|
412
455
|
observed: `element matching ${subject} is present, states: ${relaxed.elements[0]?.states.join(', ') ?? 'unknown'}`,
|
|
413
456
|
expected: `element matching ${subject} in state '${state}'`,
|
|
414
457
|
assertion: 'element.state',
|
|
@@ -421,7 +464,7 @@ fullText = false) {
|
|
|
421
464
|
if (roleOnly.matched) {
|
|
422
465
|
return {
|
|
423
466
|
pass: false,
|
|
424
|
-
failureReason: `no '${query.role}' named '${query.name}'; saw: ${roleOnly.elements
|
|
467
|
+
failureReason: `no '${query.role}' named '${query.name}' (query ${subject}); saw: ${roleOnly.elements
|
|
425
468
|
.map((e) => e.name)
|
|
426
469
|
.filter((n) => n.length > 0)
|
|
427
470
|
.join(', ')}`,
|
|
@@ -443,7 +486,7 @@ fullText = false) {
|
|
|
443
486
|
const seen = byName.map((e) => `${'' === e.role ? 'no role' : e.role} "${'' === e.name ? (e.text ?? '') : e.name}" (${e.ref})`);
|
|
444
487
|
return {
|
|
445
488
|
pass: false,
|
|
446
|
-
failureReason: `no '${query.role}' named '${query.name}'; that name is on: ${seen.join(', ')}`,
|
|
489
|
+
failureReason: `no '${query.role}' named '${query.name}' (query ${subject}); that name is on: ${seen.join(', ')}`,
|
|
447
490
|
observed: `no element has role '${query.role}'; elements named '${query.name}': ${seen.join(', ')}`,
|
|
448
491
|
expected: `a '${query.role}' named '${query.name}'`,
|
|
449
492
|
assertion: 'element.role+name',
|
|
@@ -492,7 +535,7 @@ fullText = false) {
|
|
|
492
535
|
caseOnlyMiss: true,
|
|
493
536
|
wouldHold: `the same check with ignoreCase: true (the page shows "${match.hint?.caseMiss ?? ''}")`,
|
|
494
537
|
}),
|
|
495
|
-
failureReason: `no element matched ${subject}${state === undefined ? '' : ` in state '${state}'`}${suffix}${cut}`,
|
|
538
|
+
failureReason: `no element matched ${subject}${state === undefined ? '' : ` in state '${state}'`}${describeScopeMatches(match.scopeMatches)}${suffix}${cut}`,
|
|
496
539
|
observed: `no matching element on the page${suffix}`,
|
|
497
540
|
expected: `an element matching ${subject}${state === undefined ? '' : ` in state '${state}'`}`,
|
|
498
541
|
assertion: 'element.present',
|
|
@@ -550,6 +593,33 @@ function shownBounded(element) {
|
|
|
550
593
|
const text = textOf(element);
|
|
551
594
|
return text.length > max ? { ...element, text: `${text.slice(0, max)}…` } : element;
|
|
552
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* An absence check that carries a property: "no element whose text satisfies it".
|
|
598
|
+
*
|
|
599
|
+
* The recorder writes "no 'bookmark 02'" as text containing 'bookmark' that matches /bookmark \d+/.
|
|
600
|
+
* Read as a plain absence, any other 'bookmark' on the page ("Add bookmark") failed it, and the
|
|
601
|
+
* property was then judged on an empty text. Only a match whose text satisfies the property fails
|
|
602
|
+
* it. A match that was not described, or not read in full, could be the one, so it is undecided.
|
|
603
|
+
*/
|
|
604
|
+
function absentUnlessSatisfied(match, assertion, subject) {
|
|
605
|
+
const hits = match.elements.filter((el) => satisfiesProperty(textOf(el), assertion).ok);
|
|
606
|
+
if (0 < hits.length) {
|
|
607
|
+
return {
|
|
608
|
+
pass: false,
|
|
609
|
+
failureReason: `expected no element matching ${subject} to satisfy ${assertion.property}, but found ${String(hits.length)}`,
|
|
610
|
+
observed: `${String(hits.length)} element(s) matching ${subject} satisfy ${assertion.property}`,
|
|
611
|
+
expected: `no element matching ${subject} that satisfies ${assertion.property}`,
|
|
612
|
+
assertion: 'element.absent',
|
|
613
|
+
evidence: hits.map(shownBounded),
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
if (match.count > match.elements.length || match.elements.some(wasCutAtFullBound)) {
|
|
617
|
+
const reason = `${String(match.count)} element(s) match ${subject} and not all of their text was read, so ` +
|
|
618
|
+
`whether one satisfies ${assertion.property} was not decided. Scope the predicate to a smaller element`;
|
|
619
|
+
return { pass: false, failureReason: reason, inconclusive: reason };
|
|
620
|
+
}
|
|
621
|
+
return { pass: true, evidence: { absent: true, unsatisfiedMatches: match.count } };
|
|
622
|
+
}
|
|
553
623
|
/**
|
|
554
624
|
* Whether a described text was cut at the full-text bound. A cut text is that many characters and
|
|
555
625
|
* an ellipsis, so only a cut one is ever longer than the bound.
|
|
@@ -175,3 +175,5 @@ export declare function clipBody(body: string): string;
|
|
|
175
175
|
export declare function describeNetFilter(p: Extract<Predicate, {
|
|
176
176
|
kind: typeof PredicateKind.NET;
|
|
177
177
|
}>): string;
|
|
178
|
+
/** Whether the page's SDK is older than `since`. An unknown or unreadable version is not. */
|
|
179
|
+
export declare function sdkPredates(sdk: string | undefined, since: string): boolean;
|
|
@@ -271,3 +271,22 @@ export function describeNetFilter(p) {
|
|
|
271
271
|
const { kind: _kind, count: _count, since: _since, ...filter } = p;
|
|
272
272
|
return JSON.stringify(filter);
|
|
273
273
|
}
|
|
274
|
+
/** Leading `major.minor.patch` as numbers; a pre-release of a version counts as that version. */
|
|
275
|
+
function versionParts(version) {
|
|
276
|
+
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
277
|
+
return null === m ? undefined : [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
278
|
+
}
|
|
279
|
+
/** Whether the page's SDK is older than `since`. An unknown or unreadable version is not. */
|
|
280
|
+
export function sdkPredates(sdk, since) {
|
|
281
|
+
const have = sdk === undefined ? undefined : versionParts(sdk);
|
|
282
|
+
const need = versionParts(since);
|
|
283
|
+
if (have === undefined || need === undefined) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
for (let i = 0; i < 3; i += 1) {
|
|
287
|
+
if (have[i] !== need[i]) {
|
|
288
|
+
return (have[i] ?? 0) < (need[i] ?? 0);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
@@ -22,10 +22,7 @@ export declare function skippedBodyRemedy(reason: unknown): string | undefined;
|
|
|
22
22
|
export declare function sharedSkipReason(reasons: readonly unknown[]): unknown;
|
|
23
23
|
export declare function evalNet(events: ReticleEvent[], p: Extract<Predicate, {
|
|
24
24
|
kind: typeof PredicateKind.NET;
|
|
25
|
-
}
|
|
26
|
-
export declare function evalAnimation(events: ReticleEvent[], p: Extract<Predicate, {
|
|
27
|
-
kind: typeof PredicateKind.ANIMATION;
|
|
28
|
-
}>): EvalResult;
|
|
25
|
+
}>, sdkVersion?: string): EvalResult;
|
|
29
26
|
export declare function evalSignal(events: ReticleEvent[], p: Extract<Predicate, {
|
|
30
27
|
kind: typeof PredicateKind.SIGNAL;
|
|
31
28
|
}>): EvalResult;
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import { EventType,
|
|
1
|
+
import { EventType, neverAnswered, PredicateKind, ResponseBodyReason, SettledChannel, StreamDirection, isDevToolingUrl, isForeignTraffic, urlForMatch, REDACTED_VALUE, } from '@reticlehq/core';
|
|
2
2
|
import { isReticleVoice } from '../../state-bookkeeping.js';
|
|
3
3
|
import { describeObserved } from './observed-in-window.js';
|
|
4
4
|
import { netEvidence } from './net-evidence.js';
|
|
5
|
-
import {
|
|
5
|
+
import { truncatedBodyAdvice } from './truncated-body-advice.js';
|
|
6
|
+
import { mergeNetworkDetail, withDownloadRequests } from '../../window/network-detail-merge.js';
|
|
7
|
+
import { departedInWindow, mediaEntryBeforeWindow } from '../../window/event-filters.js';
|
|
6
8
|
import { checkRequestBody, REMEDY_BODY_CAPTURE, newRequestBodyState, requestBodyVerdict, } from './predicate-request-body.js';
|
|
7
9
|
export { evalConsole } from './predicate-console.js';
|
|
8
10
|
import { clipBody, dataMatches, describeBodyFieldMiss, describeFieldMiss, describeNetFilter, matchJsonBody, num, redactedOnPath, str, } from './predicate-eval-kit.js';
|
|
9
11
|
import { keyFragmentOnly } from './body-key-fragment.js';
|
|
10
12
|
import { evalExactCount } from '../../exact-count.js';
|
|
11
|
-
import { PRE_ATTACH_CAVEAT, mediaLoadReason, nativeDownloadReason, targetsMediaLoad, targetsNativeDownload, targetsUnobservedChannel, unobservedChannelReason, } from './net-blind-spots.js';
|
|
13
|
+
import { PRE_ATTACH_CAVEAT, earlierMediaReason, mediaLoadReason, nativeDownloadReason, targetsMediaLoad, targetsNativeDownload, targetsUnobservedChannel, unobservedChannelReason, unrecordedCallMiss, } from './net-blind-spots.js';
|
|
12
14
|
export { clipBody, dataMatches, describeNetFilter, matchValue, str, } from './predicate-eval-kit.js';
|
|
13
15
|
/** The oracle a net body clause reports, so an agent can branch on which one decided. */
|
|
14
16
|
const NetBodyAssertion = {
|
|
15
17
|
CONTAINS: 'net.bodyContains',
|
|
16
18
|
MATCHES: 'net.bodyMatches',
|
|
17
19
|
};
|
|
18
|
-
/** A truncated body missed a `bodyContains`: the kept prefix can still answer a substring. */
|
|
19
|
-
const TRUNCATED_PREFIX_REMEDY = "Raise it past this response's size and re-run, or assert on something inside the recorded prefix";
|
|
20
|
-
/**
|
|
21
|
-
* A truncated body missed a `bodyMatches`. That clause parses the whole body and a JSON prefix never
|
|
22
|
-
* parses, so "assert inside the prefix" changes nothing for it (#1417): name what can work instead.
|
|
23
|
-
*/
|
|
24
|
-
const TRUNCATED_MATCHES_REMEDY = "Raise it past this response's size and re-run. `bodyMatches` parses the whole body, and a JSON prefix never parses, so it cannot be judged on the kept part: to assert on what was kept, use `bodyContains` with a substring from it";
|
|
25
20
|
// The predicate SHAPE — the discriminated union, its aliases and its zod schema — lives in
|
|
26
21
|
// predicate-schema.ts, and is re-exported here: the two halves are ONE public surface.
|
|
27
22
|
export * from './predicate-schema.js';
|
|
@@ -82,18 +77,32 @@ function describeSignalFilter(p) {
|
|
|
82
77
|
}
|
|
83
78
|
function nativeDownloadMiss(events, p) {
|
|
84
79
|
const media = targetsMediaLoad(p.urlContains);
|
|
85
|
-
|
|
80
|
+
const download = targetsNativeDownload(p.urlContains);
|
|
81
|
+
const departed = departedInWindow(events, p.since ?? 0, p.method, p.urlContains);
|
|
82
|
+
const earlierMedia = mediaEntryBeforeWindow(events, p.since ?? 0, p.method, p.urlContains);
|
|
83
|
+
if (!media && !download && !departed && earlierMedia === undefined) {
|
|
86
84
|
return undefined;
|
|
87
85
|
}
|
|
88
86
|
const filter = describeNetFilter(p);
|
|
89
|
-
|
|
87
|
+
let reason = nativeDownloadReason(filter);
|
|
88
|
+
let assertion = 'net.native-download';
|
|
89
|
+
if (media) {
|
|
90
|
+
reason = mediaLoadReason(filter);
|
|
91
|
+
assertion = 'net.media-load';
|
|
92
|
+
}
|
|
93
|
+
else if (!download && !departed) {
|
|
94
|
+
// The load the filter names was recorded before this window, and the observer reports no
|
|
95
|
+
// second entry for its URL: the empty window cannot say the load did not repeat inside it.
|
|
96
|
+
reason = earlierMediaReason(filter);
|
|
97
|
+
assertion = 'net.media-before-window';
|
|
98
|
+
}
|
|
90
99
|
return {
|
|
91
100
|
pass: false,
|
|
92
101
|
failureReason: reason,
|
|
93
102
|
inconclusive: reason,
|
|
94
103
|
observed: observedNetCalls(events, p.urlContains),
|
|
95
104
|
expected: `a fetch or XHR matching ${filter}`,
|
|
96
|
-
assertion
|
|
105
|
+
assertion,
|
|
97
106
|
};
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
@@ -179,11 +188,15 @@ function unrecordedBodyReason(p, reason) {
|
|
|
179
188
|
const head = `a call matching ${describeNetFilter(p)} was answered, but its body was not recorded, so ${wantedBody(p)} could not be checked, which is not the same as absent.`;
|
|
180
189
|
return `${head} ${skippedBodyRemedy(reason) ?? REMEDY_BODY_CAPTURE}`;
|
|
181
190
|
}
|
|
182
|
-
export function evalNet(events, p) {
|
|
191
|
+
export function evalNet(events, p, sdkVersion) {
|
|
183
192
|
// SSE headers close the request immediately. A later detail supplies its captured body without another call.
|
|
184
193
|
if (p.bodyContains !== undefined || p.bodyMatches !== undefined) {
|
|
185
194
|
events = mergeNetworkDetail(events);
|
|
186
195
|
}
|
|
196
|
+
else {
|
|
197
|
+
// A server-sent download is a request even when nothing asks for its body.
|
|
198
|
+
events = withDownloadRequests(events);
|
|
199
|
+
}
|
|
187
200
|
const since = p.since ?? 0;
|
|
188
201
|
/**
|
|
189
202
|
* Computed once: the gate every zero-match downgrade below reads. True means the resource-timing
|
|
@@ -365,10 +378,9 @@ export function evalNet(events, p) {
|
|
|
365
378
|
// stays inconclusive either way: a partial parse must not decide it, since a later duplicate key
|
|
366
379
|
// could overturn whatever the prefix seemed to say.
|
|
367
380
|
const missedMatch = NetBodyAssertion.MATCHES === truncatedClause;
|
|
368
|
-
const remedy = missedMatch ? TRUNCATED_MATCHES_REMEDY : TRUNCATED_PREFIX_REMEDY;
|
|
369
381
|
return {
|
|
370
382
|
pass: false,
|
|
371
|
-
inconclusive: `a call matching ${describeNetFilter(p)} was answered with a body that was TRUNCATED before it was recorded, and ${wantedBody(p)} is not in the part that was kept — so this is undecidable, not a failure.
|
|
383
|
+
inconclusive: `a call matching ${describeNetFilter(p)} was answered with a body that was TRUNCATED before it was recorded, and ${wantedBody(p)} is not in the part that was kept — so this is undecidable, not a failure. ${truncatedBodyAdvice(sdkVersion, missedMatch)}`,
|
|
372
384
|
observed: `the first ${String(truncatedBody.length)} characters of a truncated response body ${JSON.stringify(clipBody(truncatedBody))}`,
|
|
373
385
|
expected: `a response body carrying ${wantedBody(p)}`,
|
|
374
386
|
assertion: truncatedClause ?? NetBodyAssertion.CONTAINS,
|
|
@@ -396,6 +408,11 @@ export function evalNet(events, p) {
|
|
|
396
408
|
// useEffect-double-fire / retry-storm regression class, where the request DID fire (presence passes)
|
|
397
409
|
// but fired the WRONG number of times. Without `count`, the matcher is presence-only (≥1).
|
|
398
410
|
if (p.count !== undefined) {
|
|
411
|
+
// A marked call is not in `matches`, so no count over its URL can be judged, a pass included.
|
|
412
|
+
const unpatched = unrecordedCallMiss(events, p, () => observedNetCalls(events, p.urlContains));
|
|
413
|
+
if (unpatched !== undefined) {
|
|
414
|
+
return unpatched;
|
|
415
|
+
}
|
|
399
416
|
if (0 === matches.length) {
|
|
400
417
|
const download = nativeDownloadMiss(events, p);
|
|
401
418
|
if (download !== undefined) {
|
|
@@ -430,7 +447,8 @@ export function evalNet(events, p) {
|
|
|
430
447
|
}
|
|
431
448
|
const hit = matches[0];
|
|
432
449
|
if (hit === undefined) {
|
|
433
|
-
const download = nativeDownloadMiss(events, p)
|
|
450
|
+
const download = nativeDownloadMiss(events, p) ??
|
|
451
|
+
unrecordedCallMiss(events, p, () => observedNetCalls(events, p.urlContains));
|
|
434
452
|
if (download !== undefined) {
|
|
435
453
|
return download;
|
|
436
454
|
}
|
|
@@ -458,32 +476,6 @@ export function evalNet(events, p) {
|
|
|
458
476
|
assertion: 'net.present',
|
|
459
477
|
};
|
|
460
478
|
}
|
|
461
|
-
export function evalAnimation(events, p) {
|
|
462
|
-
const wantType = true === p.completed ? EventType.ANIM_END : EventType.ANIM_START;
|
|
463
|
-
const hit = events.find((e) => {
|
|
464
|
-
if (e.type !== wantType) {
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
const name = str(e.data['name']);
|
|
468
|
-
// A check with no name asks about the app, so Reticle's own bookkeeping signals do not count.
|
|
469
|
-
if (p.name === undefined ? isReticleVoice(name ?? '') : name !== p.name) {
|
|
470
|
-
return false;
|
|
471
|
-
}
|
|
472
|
-
if (p.target !== undefined && e.ref !== p.target) {
|
|
473
|
-
return false;
|
|
474
|
-
}
|
|
475
|
-
return true;
|
|
476
|
-
});
|
|
477
|
-
return hit !== undefined
|
|
478
|
-
? { pass: true, evidence: hit.data }
|
|
479
|
-
: {
|
|
480
|
-
pass: false,
|
|
481
|
-
failureReason: `no animation matched ${JSON.stringify(p)}`,
|
|
482
|
-
observed: 'no matching animation in the window',
|
|
483
|
-
expected: `an animation matching ${JSON.stringify(p)}`,
|
|
484
|
-
assertion: 'animation.present',
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
479
|
export function evalSignal(events, p) {
|
|
488
480
|
/**
|
|
489
481
|
* A pattern key the transport sanitizer redacted on a payload of the right name. The marker is
|
|
@@ -633,10 +625,10 @@ const RETICLE_BUSY_SIGNAL = 'reticle:busy';
|
|
|
633
625
|
* The act wait (`server/src/surface/tools/act/settle-in-flight.ts`) has always excluded it and
|
|
634
626
|
* `core/src/wire/net.ts` says it must be; this predicate counted it, so `act_and_wait { until:
|
|
635
627
|
* settled }` after a plain `<a href>` never passed and agents dropped `settled` from their `until`.
|
|
636
|
-
*
|
|
637
|
-
*
|
|
628
|
+
* Read through core's `neverAnswered`, so every settle decision uses one rule. It also covers a
|
|
629
|
+
* request whose page unloaded before its answer arrived (#1944): that answer went away too.
|
|
638
630
|
*/
|
|
639
|
-
const isDeparture =
|
|
631
|
+
const isDeparture = neverAnswered;
|
|
640
632
|
/**
|
|
641
633
|
* "The page has gone quiet": no network/DOM/animation activity for at least `quietMs`. Needs the
|
|
642
634
|
* wall-clock `now` (in the buffer's time base) because "no activity in the last N ms" is relative to
|
|
@@ -31,29 +31,34 @@ export const RouteDecidedBy = {
|
|
|
31
31
|
* about where the app is, which is the failure this predicate exists to prevent.
|
|
32
32
|
*/
|
|
33
33
|
export function routePathOf(pathname, hash) {
|
|
34
|
-
if (!hash.startsWith('#/'))
|
|
34
|
+
if (!hash.startsWith('#/')) {
|
|
35
35
|
return pathname;
|
|
36
|
+
}
|
|
36
37
|
const withoutHash = hash.slice(1);
|
|
37
38
|
const query = withoutHash.indexOf('?');
|
|
38
39
|
return -1 === query ? withoutHash : withoutHash.slice(0, query);
|
|
39
40
|
}
|
|
40
41
|
function asPayload(value) {
|
|
41
|
-
if (null === value || 'object' !== typeof value || Array.isArray(value))
|
|
42
|
+
if (null === value || 'object' !== typeof value || Array.isArray(value)) {
|
|
42
43
|
return undefined;
|
|
44
|
+
}
|
|
43
45
|
return value;
|
|
44
46
|
}
|
|
45
47
|
function payloadOf(eventOrData) {
|
|
46
|
-
if (eventOrData['type'] === EventType.ROUTE_CHANGE)
|
|
48
|
+
if (eventOrData['type'] === EventType.ROUTE_CHANGE) {
|
|
47
49
|
return asPayload(eventOrData['data']);
|
|
50
|
+
}
|
|
48
51
|
// A different event: refuse rather than read whatever happened to sit in `data`.
|
|
49
|
-
if (undefined !== eventOrData['type'] && undefined !== eventOrData['data'])
|
|
52
|
+
if (undefined !== eventOrData['type'] && undefined !== eventOrData['data']) {
|
|
50
53
|
return undefined;
|
|
54
|
+
}
|
|
51
55
|
return eventOrData;
|
|
52
56
|
}
|
|
53
57
|
function partsFromPayload(data) {
|
|
54
58
|
const docPath = str(data['pathname']) ?? str(data['to']);
|
|
55
|
-
if (docPath === undefined)
|
|
59
|
+
if (docPath === undefined) {
|
|
56
60
|
return undefined;
|
|
61
|
+
}
|
|
57
62
|
const hash = str(data['hash']) ?? '';
|
|
58
63
|
const search = str(data['search']) ?? '';
|
|
59
64
|
return {
|
|
@@ -83,21 +88,25 @@ export function routeOfEvent(eventOrData) {
|
|
|
83
88
|
* parse is returned untouched rather than lost.
|
|
84
89
|
*/
|
|
85
90
|
function withoutIdentityParams(value) {
|
|
86
|
-
if ('string' !== typeof value)
|
|
91
|
+
if ('string' !== typeof value) {
|
|
87
92
|
return value;
|
|
93
|
+
}
|
|
88
94
|
const isSearch = value.startsWith('?');
|
|
89
95
|
if (isSearch) {
|
|
90
96
|
const params = new URLSearchParams(value);
|
|
91
|
-
for (const name of Object.values(RETICLE_URL_PARAM))
|
|
97
|
+
for (const name of Object.values(RETICLE_URL_PARAM)) {
|
|
92
98
|
params.delete(name);
|
|
99
|
+
}
|
|
93
100
|
const rest = params.toString();
|
|
94
101
|
return 0 === rest.length ? '' : `?${rest}`;
|
|
95
102
|
}
|
|
96
|
-
if (!URL.canParse(value))
|
|
103
|
+
if (!URL.canParse(value)) {
|
|
97
104
|
return value;
|
|
105
|
+
}
|
|
98
106
|
const parsed = new URL(value);
|
|
99
|
-
for (const name of Object.values(RETICLE_URL_PARAM))
|
|
107
|
+
for (const name of Object.values(RETICLE_URL_PARAM)) {
|
|
100
108
|
parsed.searchParams.delete(name);
|
|
109
|
+
}
|
|
101
110
|
return parsed.toString();
|
|
102
111
|
}
|
|
103
112
|
/**
|
|
@@ -107,15 +116,50 @@ function withoutIdentityParams(value) {
|
|
|
107
116
|
*/
|
|
108
117
|
function searchWithoutIdentityParams(search) {
|
|
109
118
|
const query = search.startsWith('?') ? search.slice(1) : search;
|
|
110
|
-
if ('' === query)
|
|
119
|
+
if ('' === query) {
|
|
111
120
|
return '';
|
|
121
|
+
}
|
|
112
122
|
// Pair by pair, not through URLSearchParams: its round trip re-encodes what it keeps (`%20` comes
|
|
113
123
|
// back as `+`), so a hand-written startPath `/search?q=red%20shirt` would stop matching a tab on
|
|
114
124
|
// exactly that URL. Only Reticle's own pairs are removed; the rest keep their spelling.
|
|
115
125
|
const ours = new Set(Object.values(RETICLE_URL_PARAM));
|
|
116
|
-
const kept = query
|
|
126
|
+
const kept = query
|
|
127
|
+
.split('&')
|
|
128
|
+
.filter((pair) => !ours.has(paramNameOf(pair)))
|
|
129
|
+
.map((pair) => withoutNestedIdentityParams(pair, ours));
|
|
117
130
|
return 0 === kept.length ? '' : `?${kept.join('&')}`;
|
|
118
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* An app pair whose value is itself a path with a query (`redirect=%2F%3F__reticle_session%3D…`),
|
|
134
|
+
* with our params taken out of that inner query. A login redirect carries the page the tab came
|
|
135
|
+
* from, lease param and all, and a saved startPath sent the replay back to an old lease. A pair
|
|
136
|
+
* with none of our params keeps its spelling.
|
|
137
|
+
*/
|
|
138
|
+
function withoutNestedIdentityParams(pair, ours) {
|
|
139
|
+
const at = pair.indexOf('=');
|
|
140
|
+
if (at < 0) {
|
|
141
|
+
return pair;
|
|
142
|
+
}
|
|
143
|
+
let value;
|
|
144
|
+
try {
|
|
145
|
+
value = decodeURIComponent(pair.slice(at + 1).replaceAll('+', ' '));
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return pair;
|
|
149
|
+
}
|
|
150
|
+
const q = value.indexOf('?');
|
|
151
|
+
if (q < 0) {
|
|
152
|
+
return pair;
|
|
153
|
+
}
|
|
154
|
+
const inner = value.slice(q + 1).split('&');
|
|
155
|
+
const keptInner = inner.filter((p) => !ours.has(paramNameOf(p)));
|
|
156
|
+
if (keptInner.length === inner.length) {
|
|
157
|
+
return pair;
|
|
158
|
+
}
|
|
159
|
+
const path = value.slice(0, q);
|
|
160
|
+
const rebuilt = 0 === keptInner.length ? path : `${path}?${keptInner.join('&')}`;
|
|
161
|
+
return `${pair.slice(0, at)}=${encodeURIComponent(rebuilt)}`;
|
|
162
|
+
}
|
|
119
163
|
/** The decoded name of one `name=value` query pair, or the raw text when it does not decode. */
|
|
120
164
|
function paramNameOf(pair) {
|
|
121
165
|
const raw = pair.split('=', 1)[0] ?? '';
|
|
@@ -136,8 +180,9 @@ function routeEvidence(data) {
|
|
|
136
180
|
}
|
|
137
181
|
/** Same shape from a session URL (the fallback when the tab hard-loaded and emitted no route event). */
|
|
138
182
|
export function routeOfUrl(url) {
|
|
139
|
-
if (!URL.canParse(url))
|
|
183
|
+
if (!URL.canParse(url)) {
|
|
140
184
|
return undefined;
|
|
185
|
+
}
|
|
141
186
|
const parsed = new URL(url);
|
|
142
187
|
return partsFromPayload({
|
|
143
188
|
pathname: parsed.pathname,
|
|
@@ -164,6 +209,23 @@ function readCurrentRoute(url) {
|
|
|
164
209
|
data: routeEvidence({ pathname, search, hash, url, decidedBy: RouteDecidedBy.CURRENT }),
|
|
165
210
|
};
|
|
166
211
|
}
|
|
212
|
+
/** The route from the last route change in the window, else from the session's URL, else none. */
|
|
213
|
+
function latestRouteReading(last, currentUrl) {
|
|
214
|
+
const changed = last === undefined ? undefined : routeOfEvent(last);
|
|
215
|
+
if (changed !== undefined && last !== undefined) {
|
|
216
|
+
return {
|
|
217
|
+
pathname: changed.docPath,
|
|
218
|
+
routePath: changed.routePath,
|
|
219
|
+
full: changed.full,
|
|
220
|
+
decidedBy: RouteDecidedBy.CHANGE,
|
|
221
|
+
data: routeEvidence({ ...last.data, decidedBy: RouteDecidedBy.CHANGE }),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (currentUrl === undefined || 0 === currentUrl.length) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
return readCurrentRoute(currentUrl);
|
|
228
|
+
}
|
|
167
229
|
/** Name the source in the prose too — the structured `decidedBy` is for the agent, this is for a log. */
|
|
168
230
|
function describeRouteSource(reading) {
|
|
169
231
|
return reading.decidedBy === RouteDecidedBy.CHANGE
|
|
@@ -185,18 +247,7 @@ currentUrl,
|
|
|
185
247
|
since = 0) {
|
|
186
248
|
const routes = events.filter((e) => e.type === EventType.ROUTE_CHANGE);
|
|
187
249
|
const last = routes.at(-1);
|
|
188
|
-
const
|
|
189
|
-
const reading = changed !== undefined && last !== undefined
|
|
190
|
-
? {
|
|
191
|
-
pathname: changed.docPath,
|
|
192
|
-
routePath: changed.routePath,
|
|
193
|
-
full: changed.full,
|
|
194
|
-
decidedBy: RouteDecidedBy.CHANGE,
|
|
195
|
-
data: routeEvidence({ ...last.data, decidedBy: RouteDecidedBy.CHANGE }),
|
|
196
|
-
}
|
|
197
|
-
: currentUrl === undefined || 0 === currentUrl.length
|
|
198
|
-
? undefined
|
|
199
|
-
: readCurrentRoute(currentUrl);
|
|
250
|
+
const reading = latestRouteReading(last, currentUrl);
|
|
200
251
|
if (reading === undefined) {
|
|
201
252
|
// A navigation the SERVER never answered reads exactly like one the APP prevented, and only one
|
|
202
253
|
// of those is the user's bug. See unansweredIn.
|
|
@@ -308,13 +359,16 @@ const ROUTE_SETTLE_ACTIVITY = new Set([
|
|
|
308
359
|
*/
|
|
309
360
|
function unansweredIn(events, since) {
|
|
310
361
|
const settled = new Set();
|
|
311
|
-
for (const e of events)
|
|
312
|
-
if (e.type === EventType.NET_REQUEST)
|
|
362
|
+
for (const e of events) {
|
|
363
|
+
if (e.type === EventType.NET_REQUEST) {
|
|
313
364
|
settled.add(e.data['id']);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
314
367
|
const open = events.filter((e) => e.type === EventType.NET_PENDING && e.t >= since && !settled.has(e.data['id']));
|
|
315
368
|
const first = open[0];
|
|
316
|
-
if (first === undefined)
|
|
369
|
+
if (first === undefined) {
|
|
317
370
|
return undefined;
|
|
371
|
+
}
|
|
318
372
|
return {
|
|
319
373
|
count: open.length,
|
|
320
374
|
url: str(first.data['url']) ?? '(unknown url)',
|