@reticlehq/engine 3.8.2 → 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 +28 -12
- 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 +40 -1
- package/dist/question/predicate/net-blind-spots.js +110 -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-compare.js +53 -26
- package/dist/question/predicate/predicate-element.d.ts +20 -2
- package/dist/question/predicate/predicate-element.js +207 -45
- 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 +41 -47
- package/dist/question/predicate/predicate-parse.js +132 -4
- package/dist/question/predicate/predicate-route.js +81 -27
- package/dist/question/predicate/predicate-schema.js +84 -34
- package/dist/question/predicate/predicate-session.d.ts +5 -0
- package/dist/question/predicate/predicate.js +119 -50
- 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 +3 -3
|
@@ -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
|
+
}
|
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
* could have read it. Neither is ever a pass, since a comparison with a side missing compares nothing.
|
|
9
9
|
*/
|
|
10
10
|
import { CompareAs, EventType, NetBodySide, PredicateKind, REDACTED_VALUE, urlForMatch, } from '@reticlehq/core';
|
|
11
|
-
import { parseJsonObject, readField, redactedOnPath, str, } from './predicate-eval-kit.js';
|
|
12
|
-
import { evalElement,
|
|
11
|
+
import { clipBody, parseJsonObject, readField, redactedOnPath, str, } from './predicate-eval-kit.js';
|
|
12
|
+
import { evalElement, wholeTextOf } from './predicate-element.js';
|
|
13
13
|
import { evalState } from './predicate-state.js';
|
|
14
14
|
import { skippedBodyRemedy } from './predicate-eval.js';
|
|
15
15
|
import { REMEDY_BODY_CAPTURE, requestBodySkipRemedy } from './predicate-request-body.js';
|
|
16
|
+
/** What a verdict quotes of a reading: the slice when there is one, the value as it is otherwise. */
|
|
17
|
+
function quoted(reading) {
|
|
18
|
+
return reading.shown ?? reading.value;
|
|
19
|
+
}
|
|
16
20
|
function unknown(reason) {
|
|
17
21
|
return { result: { pass: false, failureReason: reason, inconclusive: reason } };
|
|
18
22
|
}
|
|
@@ -42,10 +46,12 @@ function redacted(label) {
|
|
|
42
46
|
* different secrets arrive as the same string and would compare equal.
|
|
43
47
|
*/
|
|
44
48
|
function asScalar(value, label) {
|
|
45
|
-
if (REDACTED_VALUE === value)
|
|
49
|
+
if (REDACTED_VALUE === value) {
|
|
46
50
|
return redacted(label);
|
|
47
|
-
|
|
51
|
+
}
|
|
52
|
+
if (isScalar(value)) {
|
|
48
53
|
return { value, label };
|
|
54
|
+
}
|
|
49
55
|
return unknown(`${label} is ${Array.isArray(value) ? 'an array' : 'an object'}, not a single value — point the path at one field inside it`);
|
|
50
56
|
}
|
|
51
57
|
function describeNetSource(source) {
|
|
@@ -80,8 +86,9 @@ function readNet(events, source) {
|
|
|
80
86
|
? unknown(`the ${label} was TRUNCATED before it was recorded, so the field could not be read`)
|
|
81
87
|
: unknown(`the body is not a JSON object, so ${label} names no field — compare reads JSON fields`);
|
|
82
88
|
}
|
|
83
|
-
if (redactedOnPath(payload, source.path))
|
|
89
|
+
if (redactedOnPath(payload, source.path)) {
|
|
84
90
|
return redacted(label);
|
|
91
|
+
}
|
|
85
92
|
const field = readField(payload, source.path);
|
|
86
93
|
if (!field.found) {
|
|
87
94
|
if (truncated) {
|
|
@@ -104,8 +111,9 @@ function readSignal(events, source) {
|
|
|
104
111
|
? payload
|
|
105
112
|
: undefined;
|
|
106
113
|
// Signal payloads cross the same transport sanitizer as state, so a parent can be redacted too.
|
|
107
|
-
if (record !== undefined && redactedOnPath(record, source.path))
|
|
114
|
+
if (record !== undefined && redactedOnPath(record, source.path)) {
|
|
108
115
|
return redacted(label);
|
|
116
|
+
}
|
|
109
117
|
const field = record === undefined ? { found: false, value: undefined } : readField(record, source.path);
|
|
110
118
|
if (!field.found) {
|
|
111
119
|
return missing(`${label} is missing; the payload was ${JSON.stringify(payload)}`, label);
|
|
@@ -119,17 +127,25 @@ async function readStore(session, source) {
|
|
|
119
127
|
path: source.path,
|
|
120
128
|
...(source.store === undefined ? {} : { store: source.store }),
|
|
121
129
|
});
|
|
122
|
-
if (!read.pass)
|
|
130
|
+
if (!read.pass) {
|
|
123
131
|
return { result: read };
|
|
132
|
+
}
|
|
124
133
|
const value = read.evidence?.value;
|
|
125
134
|
return asScalar(value, label);
|
|
126
135
|
}
|
|
127
136
|
async function readText(session, source, diagnose) {
|
|
128
137
|
const label = `text of ${source.scope}`;
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
// Read in full: two texts that differ only past the display form's 80 characters would otherwise
|
|
139
|
+
// compare equal, and the equality would be a verdict on a string the page never showed.
|
|
140
|
+
const found = await evalElement(session, { scope: source.scope, self: true }, undefined, false, diagnose, true);
|
|
141
|
+
if (!found.pass) {
|
|
131
142
|
return { result: found };
|
|
132
|
-
|
|
143
|
+
}
|
|
144
|
+
const whole = wholeTextOf(found.evidence, source.scope, 'the comparison');
|
|
145
|
+
if ('result' in whole) {
|
|
146
|
+
return whole;
|
|
147
|
+
}
|
|
148
|
+
return { value: whole.text, label, shown: clipBody(whole.text) };
|
|
133
149
|
}
|
|
134
150
|
function readSide(session, events, source, diagnose) {
|
|
135
151
|
switch (source.from) {
|
|
@@ -150,16 +166,19 @@ function readSide(session, events, source, diagnose) {
|
|
|
150
166
|
*/
|
|
151
167
|
const NUMBER_TOKEN = /(?:-(?:[\p{Sc}]\s*)?|[\p{Sc}]\s*-?)?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?/gu;
|
|
152
168
|
/** One number out of a reading, or why there is not exactly one. */
|
|
153
|
-
function numberOf(
|
|
154
|
-
|
|
169
|
+
function numberOf(reading) {
|
|
170
|
+
const { value } = reading;
|
|
171
|
+
if ('number' === typeof value) {
|
|
155
172
|
return Number.isFinite(value) ? { n: value } : { why: 'is not finite' };
|
|
156
|
-
|
|
173
|
+
}
|
|
174
|
+
if ('string' !== typeof value) {
|
|
157
175
|
return { why: `is ${JSON.stringify(value)}, not a number` };
|
|
176
|
+
}
|
|
158
177
|
const tokens = value.match(NUMBER_TOKEN) ?? [];
|
|
159
178
|
const [only] = tokens;
|
|
160
179
|
if (1 !== tokens.length || only === undefined) {
|
|
161
180
|
return {
|
|
162
|
-
why: `holds ${String(tokens.length)} numbers in ${JSON.stringify(
|
|
181
|
+
why: `holds ${String(tokens.length)} numbers in ${JSON.stringify(quoted(reading))}, so which one was meant is a guess — narrow the scope to one value`,
|
|
163
182
|
};
|
|
164
183
|
}
|
|
165
184
|
const isNegative = only.includes('-');
|
|
@@ -180,12 +199,13 @@ function numberOf(value) {
|
|
|
180
199
|
*/
|
|
181
200
|
const LAST_PLACE_NOISE = 2 * Number.EPSILON;
|
|
182
201
|
function closeEnough(a, b, tolerance) {
|
|
183
|
-
if (a === b)
|
|
202
|
+
if (a === b) {
|
|
184
203
|
return true;
|
|
204
|
+
}
|
|
185
205
|
return Math.abs(a - b) <= tolerance + LAST_PLACE_NOISE * Math.max(Math.abs(a), Math.abs(b));
|
|
186
206
|
}
|
|
187
207
|
function describe(reading) {
|
|
188
|
-
return `${reading.label} is ${JSON.stringify(reading
|
|
208
|
+
return `${reading.label} is ${JSON.stringify(quoted(reading))}`;
|
|
189
209
|
}
|
|
190
210
|
export async function evalCompare(session, events, p, diagnose) {
|
|
191
211
|
const [left, right] = await Promise.all([
|
|
@@ -199,19 +219,20 @@ export async function evalCompare(session, events, p, diagnose) {
|
|
|
199
219
|
return results.find((r) => r.inconclusive !== undefined) ?? results[0] ?? { pass: false };
|
|
200
220
|
}
|
|
201
221
|
const evidence = {
|
|
202
|
-
left: { source: left.label, value: left
|
|
203
|
-
right: { source: right.label, value: right
|
|
222
|
+
left: { source: left.label, value: quoted(left) },
|
|
223
|
+
right: { source: right.label, value: quoted(right) },
|
|
204
224
|
};
|
|
205
225
|
if (CompareAs.NUMBER === p.as) {
|
|
206
|
-
const a = numberOf(left
|
|
207
|
-
const b = numberOf(right
|
|
226
|
+
const a = numberOf(left);
|
|
227
|
+
const b = numberOf(right);
|
|
208
228
|
if ('why' in a || 'why' in b) {
|
|
209
229
|
const why = 'why' in a ? `${left.label} ${a.why}` : `${right.label} ${'why' in b ? b.why : ''}`;
|
|
210
230
|
return { pass: false, failureReason: why, inconclusive: why, evidence };
|
|
211
231
|
}
|
|
212
232
|
const tolerance = p.tolerance ?? 0;
|
|
213
|
-
if (closeEnough(a.n, b.n, tolerance))
|
|
233
|
+
if (closeEnough(a.n, b.n, tolerance)) {
|
|
214
234
|
return { pass: true, evidence };
|
|
235
|
+
}
|
|
215
236
|
const band = 0 === tolerance ? '' : ` (tolerance ${String(tolerance)})`;
|
|
216
237
|
return {
|
|
217
238
|
pass: false,
|
|
@@ -222,17 +243,23 @@ export async function evalCompare(session, events, p, diagnose) {
|
|
|
222
243
|
evidence,
|
|
223
244
|
};
|
|
224
245
|
}
|
|
225
|
-
if (left.value === right.value)
|
|
246
|
+
if (left.value === right.value) {
|
|
226
247
|
return { pass: true, evidence };
|
|
227
|
-
|
|
228
|
-
const
|
|
248
|
+
}
|
|
249
|
+
const numeric = numberOf(left);
|
|
250
|
+
const other = numberOf(right);
|
|
229
251
|
const hint = 'n' in numeric && 'n' in other && closeEnough(numeric.n, other.n, 0)
|
|
230
252
|
? ' — they hold the same number in different forms; compare them with `as: "number"`'
|
|
231
253
|
: '';
|
|
254
|
+
// Two long texts that differ only past what is quoted would read as equal in the message that says
|
|
255
|
+
// they are not, so say where the difference is.
|
|
256
|
+
const unquoted = quoted(left) === quoted(right)
|
|
257
|
+
? ' — they agree on the part quoted here and differ further on'
|
|
258
|
+
: '';
|
|
232
259
|
return {
|
|
233
260
|
pass: false,
|
|
234
|
-
failureReason: `${describe(left)}, but ${describe(right)}${hint}`,
|
|
235
|
-
observed: `${JSON.stringify(left
|
|
261
|
+
failureReason: `${describe(left)}, but ${describe(right)}${hint}${unquoted}`,
|
|
262
|
+
observed: `${JSON.stringify(quoted(left))} against ${JSON.stringify(quoted(right))}`,
|
|
236
263
|
expected: 'the two values to be equal',
|
|
237
264
|
assertion: 'compare.value',
|
|
238
265
|
evidence,
|
|
@@ -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,27 @@ 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
|
|
20
|
+
export declare function matchOnce(session: PredicateSession, query: ElementQuery, state: ElementState | undefined, diagnose?: boolean, fullText?: boolean): Promise<MatchResult>;
|
|
21
|
+
export declare function evalElement(session: PredicateSession, query: ElementQuery, state: ElementState | undefined, absent: boolean, diagnose: boolean,
|
|
22
|
+
/** Describe the matches with their full text, for a caller that will JUDGE it (see `withTextProperty`). */
|
|
23
|
+
fullText?: boolean,
|
|
24
|
+
/** For an absence: only an element whose text satisfies this fails it. See `absentUnlessSatisfied`. */
|
|
25
|
+
unlessText?: PropertyAssertion): Promise<EvalResult>;
|
|
21
26
|
/** The text of every element a passing match described, joined — what a reader sees there. */
|
|
22
27
|
export declare function joinedText(evidence: unknown): string;
|
|
28
|
+
/**
|
|
29
|
+
* The whole text of a passing match read in full (see `evalElement`'s `fullText`), or the result that
|
|
30
|
+
* says it was cut short.
|
|
31
|
+
*
|
|
32
|
+
* Whatever judges the text on a reading that stopped short could pass or fail on the part not read,
|
|
33
|
+
* so it is not judged: the same refusal a truncated state value gets. `undecided` names what was
|
|
34
|
+
* left undecided, so the caller's own question is the one the message answers.
|
|
35
|
+
*/
|
|
36
|
+
export declare function wholeTextOf(evidence: unknown, subject: string, undecided: string): {
|
|
37
|
+
text: string;
|
|
38
|
+
} | {
|
|
39
|
+
result: EvalResult;
|
|
40
|
+
};
|
|
23
41
|
export declare function withTextProperty(base: EvalResult, assertion: PropertyAssertion, subject: string, baseline?: Baseline): EvalResult;
|
|
24
42
|
/**
|
|
25
43
|
* The element query a text predicate is evaluated through — one builder for the verdict and its
|