@reticlehq/engine 3.1.0 → 3.3.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 +32 -12
- package/dist/disagreement/contradiction-evidence.d.ts +1 -1
- package/dist/disagreement/contradiction-evidence.js +3 -3
- package/dist/disagreement/contradiction-types.d.ts +6 -0
- package/dist/disagreement/contradictions.js +101 -50
- package/dist/evidence/already-true.js +9 -2
- package/dist/evidence/baseline.d.ts +21 -0
- package/dist/evidence/baseline.js +129 -0
- package/dist/evidence/body-capture-remedy.js +6 -1
- package/dist/evidence/honesty.d.ts +10 -0
- package/dist/evidence/honesty.js +4 -0
- package/dist/evidence/verified.d.ts +7 -0
- package/dist/evidence/verified.js +35 -1
- package/dist/question/declared.js +2 -1
- package/dist/question/lineage.d.ts +14 -5
- package/dist/question/lineage.js +65 -10
- package/dist/question/predicate/body-key-fragment.d.ts +25 -0
- package/dist/question/predicate/body-key-fragment.js +57 -0
- package/dist/question/predicate/predicate-element.d.ts +3 -2
- package/dist/question/predicate/predicate-element.js +68 -3
- package/dist/question/predicate/predicate-eval-kit.d.ts +21 -0
- package/dist/question/predicate/predicate-eval-kit.js +28 -1
- package/dist/question/predicate/predicate-eval.d.ts +6 -0
- package/dist/question/predicate/predicate-eval.js +89 -26
- package/dist/question/predicate/predicate-precheck.d.ts +7 -0
- package/dist/question/predicate/predicate-precheck.js +81 -0
- package/dist/question/predicate/predicate-request-body.d.ts +1 -1
- package/dist/question/predicate/predicate-request-body.js +10 -19
- package/dist/question/predicate/predicate-route.d.ts +2 -1
- package/dist/question/predicate/predicate-schema.d.ts +12 -91
- package/dist/question/predicate/predicate-schema.js +15 -267
- package/dist/question/predicate/predicate-session.d.ts +15 -1
- package/dist/question/predicate/predicate-session.js +25 -1
- package/dist/question/predicate/predicate-state.d.ts +15 -0
- package/dist/question/predicate/predicate-state.js +317 -0
- package/dist/question/predicate/predicate.d.ts +17 -3
- package/dist/question/predicate/predicate.js +139 -328
- package/dist/question/predicate/property.d.ts +24 -73
- package/dist/question/predicate/property.js +134 -20
- package/dist/window/json-salvage.d.ts +2 -1
- package/dist/window/json-salvage.js +2 -1
- package/package.json +2 -2
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ElementState, PredicateKind,
|
|
2
|
-
import { satisfiesProperty } from './property.js';
|
|
1
|
+
import { ElementState, PredicateKind, THROTTLED_STARVED_NOTE, isSameDocument, } from '@reticlehq/core';
|
|
3
2
|
import { predicateToExpectedLinks } from './predicate-to-links.js';
|
|
4
3
|
import { isAmbient, ambientKeyOf } from '../../window/ambient.js';
|
|
5
4
|
import { evalRoute } from './predicate-route.js';
|
|
6
5
|
import { describeSuperseded } from './observed-in-window.js';
|
|
7
|
-
import { evalElement } from './predicate-element.js';
|
|
8
|
-
import {
|
|
6
|
+
import { evalElement, withTextProperty } from './predicate-element.js';
|
|
7
|
+
import { evalState } from './predicate-state.js';
|
|
8
|
+
import { PredicateSchema, evalNet, evalConsole, evalAnimation, evalSignal, evalSettled, } from './predicate-eval.js';
|
|
9
9
|
export { PredicateSchema, PredicateKind };
|
|
10
|
+
import { withinBudget } from './predicate-session.js';
|
|
10
11
|
/**
|
|
11
12
|
* A composite result that carries a child's "nobody could evaluate this" up to the verdict rule.
|
|
12
13
|
*
|
|
@@ -19,301 +20,6 @@ function unreadableComposite(child, evidence) {
|
|
|
19
20
|
const reason = child.inconclusive ?? 'a sub-predicate could not be evaluated';
|
|
20
21
|
return { pass: false, failureReason: reason, inconclusive: reason, evidence };
|
|
21
22
|
}
|
|
22
|
-
function oneOf(names) {
|
|
23
|
-
return 1 === names.length ? names[0] : undefined;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* `readState`'s truncation report, when the caps actually fired.
|
|
27
|
-
*
|
|
28
|
-
* Its PRESENCE is the warning — the field is omitted entirely on an intact read, which is what lets
|
|
29
|
-
* "the list is short" stay distinguishable from "I shortened the list".
|
|
30
|
-
*/
|
|
31
|
-
function truncationOf(result) {
|
|
32
|
-
if ('object' !== typeof result || null === result)
|
|
33
|
-
return undefined;
|
|
34
|
-
const report = result.truncation;
|
|
35
|
-
return 'object' === typeof report && null !== report
|
|
36
|
-
? report
|
|
37
|
-
: undefined;
|
|
38
|
-
}
|
|
39
|
-
/** A scoped `readState` reply, narrowed to the shape `selectPath` would have produced. */
|
|
40
|
-
function asSelection(result) {
|
|
41
|
-
if ('object' !== typeof result || null === result)
|
|
42
|
-
return undefined;
|
|
43
|
-
const record = result;
|
|
44
|
-
return 'boolean' === typeof record.found
|
|
45
|
-
? { found: record.found, value: record.value }
|
|
46
|
-
: undefined;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* A NAMED store needs no whole-store read. `reticle_state`'s scoped mode selects the path out of the
|
|
50
|
-
* RAW store IN-PAGE and returns only it, so the assertion resolves in one round trip against a payload
|
|
51
|
-
* the size of the value — not the store. The unnamed case below still needs the wide read, because
|
|
52
|
-
* that is how it discovers WHICH store carries the path; only the named branch changes.
|
|
53
|
-
*
|
|
54
|
-
* A scoped read answers `found: false` for both "no such store" and "no such path", so the two are
|
|
55
|
-
* kept distinct here using the `storeNames` list the reply always carries — otherwise the payload gets
|
|
56
|
-
* cheaper while the message gets worse.
|
|
57
|
-
*/
|
|
58
|
-
async function evalStateNamed(session, p, storeName) {
|
|
59
|
-
const scoped = await session.command(ReticleCommand.STATE_READ, {
|
|
60
|
-
store: storeName,
|
|
61
|
-
path: p.path,
|
|
62
|
-
});
|
|
63
|
-
if (!scoped.ok) {
|
|
64
|
-
return {
|
|
65
|
-
pass: false,
|
|
66
|
-
failureReason: 'state read failed',
|
|
67
|
-
observed: 'the store could not be read',
|
|
68
|
-
expected: 'a readable registered store',
|
|
69
|
-
assertion: 'state.unreadable',
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const reply = (scoped.result ?? {});
|
|
73
|
-
const names = Array.isArray(reply.storeNames) ? reply.storeNames : [];
|
|
74
|
-
// Resolve the value. A CURRENT SDK honours the scoped read and answers `{ found, value }` selected
|
|
75
|
-
// in-page — the whole point of this path. An OLDER SDK (version skew) or any transport that ignores
|
|
76
|
-
// `path` answers the whole-store shape `{ stores }`; walk the path server-side there so the verdict
|
|
77
|
-
// stays correct across SDK versions. The scoped win is simply unavailable on the old ones.
|
|
78
|
-
const scopedSel = asSelection(scoped.result);
|
|
79
|
-
const wholeStores = reply.stores;
|
|
80
|
-
const scopedKeys = Array.isArray(reply.availableKeys)
|
|
81
|
-
? reply.availableKeys
|
|
82
|
-
: undefined;
|
|
83
|
-
let selection;
|
|
84
|
-
if (scopedSel !== undefined) {
|
|
85
|
-
selection =
|
|
86
|
-
scopedKeys === undefined
|
|
87
|
-
? { found: scopedSel.found, value: scopedSel.value }
|
|
88
|
-
: { found: scopedSel.found, value: scopedSel.value, availableKeys: scopedKeys };
|
|
89
|
-
}
|
|
90
|
-
else if (wholeStores !== undefined) {
|
|
91
|
-
selection = selectPath(wholeStores[storeName], p.path);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
selection = { found: false };
|
|
95
|
-
}
|
|
96
|
-
// "no store named X" and "X has no such path" both surface as found:false; keep them distinct using
|
|
97
|
-
// the store list the reply carries, or the message regresses while the payload improves.
|
|
98
|
-
const storeAbsent = wholeStores !== undefined
|
|
99
|
-
? !(storeName in wholeStores)
|
|
100
|
-
: names.length > 0 && !names.includes(storeName);
|
|
101
|
-
if (!selection.found && storeAbsent) {
|
|
102
|
-
return {
|
|
103
|
-
pass: false,
|
|
104
|
-
failureReason: `no store named '${storeName}' is registered (${names.join(', ')})`,
|
|
105
|
-
observed: `store '${storeName}' is not registered`,
|
|
106
|
-
expected: `a registered store named '${storeName}'`,
|
|
107
|
-
assertion: 'state.store-missing',
|
|
108
|
-
evidence: { searchedStores: names },
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
// A scoped sub-tree can itself be too big for the caps; a comparison against a value known to be
|
|
112
|
-
// incomplete is an unanswered question, not a failure. Same rule the whole-store path applies.
|
|
113
|
-
if (truncationOf(scoped.result) !== undefined) {
|
|
114
|
-
const reason = `state '${p.path}' could not be read intact — the transport caps truncated it, so the ` +
|
|
115
|
-
'value was never compared. Assert a narrower path, or a smaller field inside it';
|
|
116
|
-
return { pass: false, failureReason: reason, inconclusive: reason };
|
|
117
|
-
}
|
|
118
|
-
if (!selection.found) {
|
|
119
|
-
return {
|
|
120
|
-
pass: false,
|
|
121
|
-
failureReason: `state path '${p.path}' not found in store '${storeName}'`,
|
|
122
|
-
observed: `no path '${p.path}' in store '${storeName}'`,
|
|
123
|
-
expected: `store '${storeName}' to expose '${p.path}'`,
|
|
124
|
-
assertion: 'state.path-missing',
|
|
125
|
-
evidence: { availableKeys: selection.availableKeys },
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/*
|
|
129
|
-
* A PROPERTY assertion runs before equality and can stand alone.
|
|
130
|
-
*
|
|
131
|
-
* `satisfies` is what makes a generated value verifiable at all: its exact bytes differ every run
|
|
132
|
-
* and are right every time, so `equals` can only ever be wrong about it. Both may be supplied and
|
|
133
|
-
* then both must hold — `satisfies` narrows, it never excuses.
|
|
134
|
-
*/
|
|
135
|
-
if (p.satisfies !== undefined) {
|
|
136
|
-
const r = satisfiesProperty(selection.value, p.satisfies);
|
|
137
|
-
if (!r.ok) {
|
|
138
|
-
return {
|
|
139
|
-
pass: false,
|
|
140
|
-
failureReason: `state '${p.path}' ${r.because}`,
|
|
141
|
-
observed: `${p.path} = ${JSON.stringify(capDepth(selection.value, 0))}`,
|
|
142
|
-
expected: `${p.path} to satisfy ${p.satisfies.property}`,
|
|
143
|
-
assertion: `state.${p.satisfies.property}`,
|
|
144
|
-
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
if (p.equals === undefined) {
|
|
148
|
-
return {
|
|
149
|
-
pass: true,
|
|
150
|
-
evidence: {
|
|
151
|
-
store: storeName,
|
|
152
|
-
path: p.path,
|
|
153
|
-
value: capDepth(selection.value, 1),
|
|
154
|
-
satisfied: r.because,
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const want = p.equals === undefined ? '*' : p.equals;
|
|
160
|
-
if (matchValue(selection.value, want)) {
|
|
161
|
-
return {
|
|
162
|
-
pass: true,
|
|
163
|
-
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
pass: false,
|
|
168
|
-
failureReason: `state '${p.path}' is ${JSON.stringify(capDepth(selection.value, 0))}, expected ${JSON.stringify(want)}`,
|
|
169
|
-
observed: `${p.path} = ${JSON.stringify(capDepth(selection.value, 0))}`,
|
|
170
|
-
expected: `${p.path} = ${JSON.stringify(want)}`,
|
|
171
|
-
assertion: 'state.equals',
|
|
172
|
-
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
async function evalState(session, p) {
|
|
176
|
-
// Named store: one scoped read, no whole-store payload (issue #336).
|
|
177
|
-
if (p.store !== undefined)
|
|
178
|
-
return await evalStateNamed(session, p, p.store);
|
|
179
|
-
const res = await session.command(ReticleCommand.STATE_READ, {});
|
|
180
|
-
if (!res.ok) {
|
|
181
|
-
return {
|
|
182
|
-
pass: false,
|
|
183
|
-
failureReason: 'state read failed',
|
|
184
|
-
observed: 'the store could not be read',
|
|
185
|
-
expected: 'a readable registered store',
|
|
186
|
-
assertion: 'state.unreadable',
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
const stores = (res.result ?? {}).stores ?? {};
|
|
190
|
-
const names = Object.keys(stores);
|
|
191
|
-
// Ambiguity is about the PATH, not the store count.
|
|
192
|
-
//
|
|
193
|
-
// Registering more than one store is normal — an app store, a query cache, and the render meter
|
|
194
|
-
// Reticle registers itself — and asking "which of these three?" when only one of them HAS the
|
|
195
|
-
// path is a question with one possible answer. It was costing a real verdict: a bench-app drive
|
|
196
|
-
// asserting `{path:'view'}` returned `unknown` while the same response body carried the matching
|
|
197
|
-
// `view` state diff. `unknown` is not a pass, so that is a verification that did not happen.
|
|
198
|
-
//
|
|
199
|
-
// So narrow to the stores that actually carry the path, and refuse only when THOSE collide.
|
|
200
|
-
const candidates = p.store === undefined ? names.filter((n) => selectPath(stores[n], p.path).found) : [];
|
|
201
|
-
const storeName = p.store ?? (1 === names.length ? names[0] : oneOf(candidates));
|
|
202
|
-
if (storeName === undefined) {
|
|
203
|
-
// With no store registered there is nothing to read, and with two stores that both carry the
|
|
204
|
-
// path there is no way to pick — neither is a finding about the app, no assertion was evaluated,
|
|
205
|
-
// so both are inconclusive rather than failed: an unevaluated predicate is never a failure.
|
|
206
|
-
//
|
|
207
|
-
// Zero candidates is the one case that is NOT a question: every registered store was searched
|
|
208
|
-
// and none exposes the path, so the assertion cannot hold anywhere. That is the same verdict a
|
|
209
|
-
// named store has always produced for a missing path, and it falls through to it below.
|
|
210
|
-
if (0 === names.length) {
|
|
211
|
-
const reason = 'no registered store to read state from';
|
|
212
|
-
return { pass: false, failureReason: reason, inconclusive: reason };
|
|
213
|
-
}
|
|
214
|
-
if (candidates.length > 1) {
|
|
215
|
-
// Names the stores that actually collide. Listing all of them made the reader weigh
|
|
216
|
-
// candidates that could never have matched.
|
|
217
|
-
const reason = `multiple stores (${candidates.join(', ')}) expose '${p.path}'; name one with \`store\``;
|
|
218
|
-
return { pass: false, failureReason: reason, inconclusive: reason };
|
|
219
|
-
}
|
|
220
|
-
return {
|
|
221
|
-
pass: false,
|
|
222
|
-
failureReason: `state path '${p.path}' not found in any registered store (${names.join(', ')})`,
|
|
223
|
-
observed: `no path '${p.path}' in ${names.join(', ')}`,
|
|
224
|
-
expected: `some registered store to expose '${p.path}'`,
|
|
225
|
-
assertion: 'state.path-missing',
|
|
226
|
-
evidence: { searchedStores: names },
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
let selection = selectPath(stores[storeName], p.path);
|
|
230
|
-
// The whole-store read walks into a value the transport caps may already have mangled.
|
|
231
|
-
//
|
|
232
|
-
// `readState` has a SCOPED mode that selects the path out of the RAW store before sanitising, added
|
|
233
|
-
// precisely so a large or deep path still resolves. This path was not using it, so a store with one
|
|
234
|
-
// big collection in it truncated the small value sitting beside it, and the comparison then ran
|
|
235
|
-
// against the literal string "[TRUNCATED]" and returned a confident `no`. Measured on the Atlas
|
|
236
|
-
// fixture: a one-element array reported as a failed assertion while the same payload's state diffs
|
|
237
|
-
// showed the assertion holding.
|
|
238
|
-
//
|
|
239
|
-
// Re-read only when a cap actually fired, so an intact read costs exactly what it did before.
|
|
240
|
-
if (truncationOf(res.result) !== undefined) {
|
|
241
|
-
const scoped = await session.command(ReticleCommand.STATE_READ, {
|
|
242
|
-
store: storeName,
|
|
243
|
-
path: p.path,
|
|
244
|
-
});
|
|
245
|
-
const result = scoped.ok ? scoped.result : undefined;
|
|
246
|
-
const scopedTruncation = truncationOf(result);
|
|
247
|
-
if (scopedTruncation !== undefined) {
|
|
248
|
-
// Even the raw sub-tree was too big. Nothing here knows what the value IS, so nothing here can
|
|
249
|
-
// say the assertion failed — that would be an accusation the evidence does not support.
|
|
250
|
-
const reason = `state '${p.path}' could not be read intact — the transport caps truncated it, so the ` +
|
|
251
|
-
'value was never compared. Assert a narrower path, or a smaller field inside it';
|
|
252
|
-
return { pass: false, failureReason: reason, inconclusive: reason };
|
|
253
|
-
}
|
|
254
|
-
if (result !== undefined) {
|
|
255
|
-
const scopedSelection = asSelection(result);
|
|
256
|
-
if (scopedSelection !== undefined)
|
|
257
|
-
selection = scopedSelection;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (!selection.found) {
|
|
261
|
-
return {
|
|
262
|
-
pass: false,
|
|
263
|
-
failureReason: `state path '${p.path}' not found in store '${storeName}'`,
|
|
264
|
-
observed: `no path '${p.path}' in store '${storeName}'`,
|
|
265
|
-
expected: `store '${storeName}' to expose '${p.path}'`,
|
|
266
|
-
assertion: 'state.path-missing',
|
|
267
|
-
evidence: { availableKeys: selection.availableKeys },
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
/*
|
|
271
|
-
* A PROPERTY assertion runs before equality and can stand alone.
|
|
272
|
-
*
|
|
273
|
-
* `satisfies` is what makes a generated value verifiable at all: its exact bytes differ every run
|
|
274
|
-
* and are right every time, so `equals` can only ever be wrong about it. Both may be supplied and
|
|
275
|
-
* then both must hold — `satisfies` narrows, it never excuses.
|
|
276
|
-
*/
|
|
277
|
-
if (p.satisfies !== undefined) {
|
|
278
|
-
const r = satisfiesProperty(selection.value, p.satisfies);
|
|
279
|
-
if (!r.ok) {
|
|
280
|
-
return {
|
|
281
|
-
pass: false,
|
|
282
|
-
failureReason: `state '${p.path}' ${r.because}`,
|
|
283
|
-
observed: `${p.path} = ${JSON.stringify(capDepth(selection.value, 0))}`,
|
|
284
|
-
expected: `${p.path} to satisfy ${p.satisfies.property}`,
|
|
285
|
-
assertion: `state.${p.satisfies.property}`,
|
|
286
|
-
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
if (p.equals === undefined) {
|
|
290
|
-
return {
|
|
291
|
-
pass: true,
|
|
292
|
-
evidence: {
|
|
293
|
-
store: storeName,
|
|
294
|
-
path: p.path,
|
|
295
|
-
value: capDepth(selection.value, 1),
|
|
296
|
-
satisfied: r.because,
|
|
297
|
-
},
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const want = p.equals === undefined ? '*' : p.equals;
|
|
302
|
-
if (matchValue(selection.value, want)) {
|
|
303
|
-
return {
|
|
304
|
-
pass: true,
|
|
305
|
-
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
pass: false,
|
|
310
|
-
failureReason: `state '${p.path}' is ${JSON.stringify(capDepth(selection.value, 0))}, expected ${JSON.stringify(want)}`,
|
|
311
|
-
observed: `${p.path} = ${JSON.stringify(capDepth(selection.value, 0))}`,
|
|
312
|
-
expected: `${p.path} = ${JSON.stringify(want)}`,
|
|
313
|
-
assertion: 'state.equals',
|
|
314
|
-
evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
23
|
/**
|
|
318
24
|
* Oracles whose ONLY source of truth is the event window.
|
|
319
25
|
*
|
|
@@ -360,10 +66,82 @@ function annotateThrottledMiss(session, predicate, result) {
|
|
|
360
66
|
}
|
|
361
67
|
if (true !== session.throttled?.())
|
|
362
68
|
return result;
|
|
69
|
+
if (decidedByAnAlreadyAnnotatedClause(predicate))
|
|
70
|
+
return result;
|
|
363
71
|
if (failureRestsOnSeeing(predicate))
|
|
364
72
|
return result;
|
|
365
73
|
return { ...result, inconclusive: THROTTLED_STARVED_NOTE };
|
|
366
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Has this predicate's failure ALREADY been adjudicated, one level down?
|
|
77
|
+
*
|
|
78
|
+
* `allOf`/`anyOf` evaluate their clauses through `evaluatePredicate`, so every clause arrives here
|
|
79
|
+
* first and carries its own verdict on the starved-tab question. Asking again at the composite
|
|
80
|
+
* re-decides it with strictly less information: the composite knows only that SOMETHING failed.
|
|
81
|
+
*
|
|
82
|
+
* A readable `allOf` failure is a clause that failed by having SEEN something, because a clause that
|
|
83
|
+
* failed by NOT seeing is stamped starved before the composite looks (or cleared by
|
|
84
|
+
* `clearStarvedWhenSiblingsSaw` when a sibling proved the tab renders). An `anyOf` reports "no
|
|
85
|
+
* sub-predicate matched" only when every clause failed readably. Without this, an `absent: true`
|
|
86
|
+
* clause that matched 13 elements was graded honestly as a clause and then re-graded `unknown` as an
|
|
87
|
+
* `allOf` of one (#897).
|
|
88
|
+
*
|
|
89
|
+
* `not` is deliberately absent: it fails when its child PASSED, and a passing child is never
|
|
90
|
+
* annotated, so there is nothing decided to defer to. `failureRestsOnSeeing` answers it by flipping.
|
|
91
|
+
*/
|
|
92
|
+
function decidedByAnAlreadyAnnotatedClause(predicate) {
|
|
93
|
+
return PredicateKind.ALL_OF === predicate.kind || PredicateKind.ANY_OF === predicate.kind;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Did this arm PROVE the tab rendered?
|
|
97
|
+
*
|
|
98
|
+
* An element predicate that passed did so by finding matches, and nothing about a starved tab
|
|
99
|
+
* conjures elements that were not there. `absent: true` is the exception and the reason this is not
|
|
100
|
+
* simply `result.pass`: that one passes by finding NOTHING, which is precisely the reading a starved
|
|
101
|
+
* tab makes untrustworthy, so it proves the opposite of a render.
|
|
102
|
+
*
|
|
103
|
+
* Composites recurse: a passing `allOf` proves a render if any of its own arms did.
|
|
104
|
+
*/
|
|
105
|
+
function provesRender(predicate, result) {
|
|
106
|
+
if (!result.pass)
|
|
107
|
+
return false;
|
|
108
|
+
if (PredicateKind.ELEMENT === predicate.kind)
|
|
109
|
+
return true !== predicate.absent;
|
|
110
|
+
if (PredicateKind.ALL_OF === predicate.kind || PredicateKind.ANY_OF === predicate.kind) {
|
|
111
|
+
return predicate.predicates.some((p) => provesRender(p, result));
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Drop the starved-tab caveat from arms whose SIBLINGS demonstrated that the tab renders.
|
|
117
|
+
*
|
|
118
|
+
* Reported as the most frequent condition in the whole field export (#1004), in its sharpest form:
|
|
119
|
+
* "A negative arm inside `allOf` was graded 'unknown / this tab is throttled and has not rendered'
|
|
120
|
+
* in the SAME evaluation where three sibling arms returned rendered, visible, inViewport elements."
|
|
121
|
+
* A verdict that contradicts its own evidence is worse than either answer on its own.
|
|
122
|
+
*
|
|
123
|
+
* The caveat exists because a negative reading on a starved tab may mean "I could not look". A
|
|
124
|
+
* sibling that found an element is direct proof that looking worked, in this evaluation, on this
|
|
125
|
+
* tab. Keeping the caveat anyway turns a real product failure into `unknown` — which an agent
|
|
126
|
+
* re-drives or walks away from, so the defect it was holding proof of never reaches anybody.
|
|
127
|
+
*
|
|
128
|
+
* Only the throttle note is cleared. An arm that was unreadable for its own reason — an unparseable
|
|
129
|
+
* locator, a superseded window — is still unreadable however well its siblings did.
|
|
130
|
+
*/
|
|
131
|
+
function clearStarvedWhenSiblingsSaw(predicates, results) {
|
|
132
|
+
const rendered = results.some((r, i) => {
|
|
133
|
+
const p = predicates[i];
|
|
134
|
+
return p !== undefined && provesRender(p, r);
|
|
135
|
+
});
|
|
136
|
+
if (!rendered)
|
|
137
|
+
return results;
|
|
138
|
+
return results.map((r) => {
|
|
139
|
+
if (THROTTLED_STARVED_NOTE !== r.inconclusive)
|
|
140
|
+
return r;
|
|
141
|
+
const { inconclusive: _dropped, ...rest } = r;
|
|
142
|
+
return rest;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
367
145
|
/**
|
|
368
146
|
* Does this predicate FAIL by having seen something, rather than by not having seen it?
|
|
369
147
|
*
|
|
@@ -377,27 +155,42 @@ function annotateThrottledMiss(session, predicate, result) {
|
|
|
377
155
|
* agent re-drives or walks away from — so the proof it was holding never reached anybody.
|
|
378
156
|
*
|
|
379
157
|
* `not` flips the polarity again, and nests, so this recurses rather than checking one level.
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
158
|
+
*
|
|
159
|
+
* A composite reaches here only under a `not` (a bare one is answered by
|
|
160
|
+
* `decidedByAnAlreadyAnnotatedClause`). There the question is whether it could have PASSED by not
|
|
161
|
+
* seeing something, and `some` is the conservative answer: one clause that passes by absence makes
|
|
162
|
+
* the whole pass untrustworthy on a starved tab. An over-cautious `unknown` costs a re-drive, a
|
|
163
|
+
* missing one costs a wrong verdict.
|
|
383
164
|
*/
|
|
384
165
|
function failureRestsOnSeeing(predicate) {
|
|
385
166
|
if (PredicateKind.NOT === predicate.kind)
|
|
386
167
|
return !failureRestsOnSeeing(predicate.predicate);
|
|
168
|
+
if (PredicateKind.ALL_OF === predicate.kind || PredicateKind.ANY_OF === predicate.kind) {
|
|
169
|
+
return predicate.predicates.some(failureRestsOnSeeing);
|
|
170
|
+
}
|
|
387
171
|
if ('absent' in predicate && true === predicate.absent)
|
|
388
172
|
return true;
|
|
389
173
|
// `count: 0` is absence written as arithmetic, and fails the same way: by matching something.
|
|
390
174
|
return 'count' in predicate && 0 === predicate.count;
|
|
391
175
|
}
|
|
392
|
-
export async function evaluatePredicate(session, predicate, since = 0, diagnose = true
|
|
393
|
-
|
|
176
|
+
export async function evaluatePredicate(session, predicate, since = 0, diagnose = true,
|
|
177
|
+
/**
|
|
178
|
+
* The readings taken BEFORE the action, keyed by the leaf that asked for one.
|
|
179
|
+
*
|
|
180
|
+
* Only the relative properties (`changed`/`unchanged`/`increased`/`decreased`) look at it, and a
|
|
181
|
+
* leaf with none evaluates as `inconclusive` rather than false — nothing was compared, so a
|
|
182
|
+
* `false` would blame the app for a reading nobody took. Keyed by the predicate OBJECT because
|
|
183
|
+
* the same parsed tree is evaluated before and after, so identity is exact and needs no path.
|
|
184
|
+
*/
|
|
185
|
+
baselines) {
|
|
186
|
+
return annotateThrottledMiss(session, predicate, await evaluatePredicateRaw(session, predicate, since, diagnose, baselines));
|
|
394
187
|
}
|
|
395
188
|
async function evaluatePredicateRaw(session, predicate, since = 0,
|
|
396
189
|
// Compute the (extra-round-trip) near-miss diagnostics on element failures. Default true so a
|
|
397
190
|
// one-shot assert is fully diagnostic; the wait loop passes false on its interim polls (which read
|
|
398
191
|
// only `pass`) and true on the final timeout eval, so a flood no longer pays for a diagnostic nobody
|
|
399
192
|
// reads. Only element/text failures have a near-miss; everything else ignores this.
|
|
400
|
-
diagnose = true) {
|
|
193
|
+
diagnose = true, baselines) {
|
|
401
194
|
// A predicate's own `since` is a TIGHTER event-time floor than the caller's — an agent that took
|
|
402
195
|
// `since` from the act it just performed is scoping the assertion to that action's aftermath. It is
|
|
403
196
|
// applied here, once, rather than in each eval: the floor means the same thing for every kind that
|
|
@@ -427,17 +220,22 @@ diagnose = true) {
|
|
|
427
220
|
switch (predicate.kind) {
|
|
428
221
|
case PredicateKind.ELEMENT:
|
|
429
222
|
return evalElement(session, predicate.query, predicate.state, predicate.absent ?? false, diagnose);
|
|
430
|
-
case PredicateKind.TEXT:
|
|
431
|
-
|
|
432
|
-
// `
|
|
433
|
-
//
|
|
434
|
-
undefined
|
|
435
|
-
|
|
436
|
-
: {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
...(true === predicate.self ? { self: true } : {}),
|
|
440
|
-
|
|
223
|
+
case PredicateKind.TEXT: {
|
|
224
|
+
// `scope` passes straight through: the text predicate has always been an element query with
|
|
225
|
+
// only `text` filled in, so scoping it needs the field, not a second code path. `contains` is
|
|
226
|
+
// optional now that `satisfies` can carry the claim, and an undefined one must not reach the
|
|
227
|
+
// query as `text: undefined` — that is a locator asking for the empty string.
|
|
228
|
+
const query = {
|
|
229
|
+
...(undefined === predicate.contains ? {} : { text: predicate.contains }),
|
|
230
|
+
...(undefined === predicate.scope
|
|
231
|
+
? {}
|
|
232
|
+
: { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
|
|
233
|
+
};
|
|
234
|
+
const found = await evalElement(session, query, true === predicate.visible ? ElementState.VISIBLE : undefined, predicate.absent ?? false, diagnose);
|
|
235
|
+
if (undefined === predicate.satisfies)
|
|
236
|
+
return found;
|
|
237
|
+
return withTextProperty(found, predicate.satisfies, JSON.stringify(query), baselines?.get(predicate));
|
|
238
|
+
}
|
|
441
239
|
case PredicateKind.NET:
|
|
442
240
|
return evalNet(events, predicate);
|
|
443
241
|
case PredicateKind.ROUTE:
|
|
@@ -451,7 +249,7 @@ diagnose = true) {
|
|
|
451
249
|
case PredicateKind.SIGNAL:
|
|
452
250
|
return evalSignal(events, predicate);
|
|
453
251
|
case PredicateKind.STATE:
|
|
454
|
-
return evalState(session, predicate);
|
|
252
|
+
return evalState(session, predicate, baselines?.get(predicate));
|
|
455
253
|
case PredicateKind.SETTLED: {
|
|
456
254
|
// Drop events on learned-ambient regions (chat/ticker churn) before the settle check — by ref
|
|
457
255
|
// alone, NOT by attribution: window-attribution ("happened during the action window") is a time
|
|
@@ -461,7 +259,7 @@ diagnose = true) {
|
|
|
461
259
|
return evalSettled(settleEvents, predicate, session.elapsed());
|
|
462
260
|
}
|
|
463
261
|
case PredicateKind.ALL_OF: {
|
|
464
|
-
const results = await Promise.all(predicate.predicates.map((p) => evaluatePredicate(session, p, since, diagnose)));
|
|
262
|
+
const results = clearStarvedWhenSiblingsSaw(predicate.predicates, await Promise.all(predicate.predicates.map((p) => evaluatePredicate(session, p, since, diagnose, baselines))));
|
|
465
263
|
// A clause that genuinely failed OUTRANKS one nobody could read. Softening a real failure to
|
|
466
264
|
// UNKNOWN would hide the defect the agent came for, which is the more expensive of the two
|
|
467
265
|
// mistakes; the reverse — grading an unreadable clause as a defect in the app — is the one
|
|
@@ -484,7 +282,7 @@ diagnose = true) {
|
|
|
484
282
|
return { pass: true, evidence: results.map((r) => r.evidence) };
|
|
485
283
|
}
|
|
486
284
|
case PredicateKind.ANY_OF: {
|
|
487
|
-
const results = await Promise.all(predicate.predicates.map((p) => evaluatePredicate(session, p, since, diagnose)));
|
|
285
|
+
const results = clearStarvedWhenSiblingsSaw(predicate.predicates, await Promise.all(predicate.predicates.map((p) => evaluatePredicate(session, p, since, diagnose, baselines))));
|
|
488
286
|
const passed = results.find((r) => r.pass);
|
|
489
287
|
if (passed !== undefined)
|
|
490
288
|
return { pass: true, evidence: passed.evidence };
|
|
@@ -496,7 +294,7 @@ diagnose = true) {
|
|
|
496
294
|
return { pass: false, failureReason: 'no sub-predicate of anyOf matched', evidence: results };
|
|
497
295
|
}
|
|
498
296
|
case PredicateKind.NOT: {
|
|
499
|
-
const inner = await evaluatePredicate(session, predicate.predicate, since, diagnose);
|
|
297
|
+
const inner = await evaluatePredicate(session, predicate.predicate, since, diagnose, baselines);
|
|
500
298
|
// The sharpest case of the three, and the only one that produced a GREEN. `not` read the
|
|
501
299
|
// child's `pass: false` as "the inner predicate did not hold" and passed — so an assertion
|
|
502
300
|
// nobody could evaluate became a verdict of verified, manufactured out of a missing reading.
|
|
@@ -564,13 +362,26 @@ function assertsExactCount(predicate) {
|
|
|
564
362
|
* Evaluate now, else wait for it to become true (on each event + a poll) until timeout. `since` is
|
|
565
363
|
* the event-time floor (see evaluatePredicate) so a waiter cannot resolve on a stale buffered event.
|
|
566
364
|
*/
|
|
567
|
-
export function waitForPredicate(session, predicate, timeoutMs, since = 0
|
|
365
|
+
export function waitForPredicate(session, predicate, timeoutMs, since = 0,
|
|
366
|
+
/** Pre-action readings, for the relative properties. See `evaluatePredicate`. */
|
|
367
|
+
baselines) {
|
|
368
|
+
// Every read in this wait shares the caller's budget; see withinBudget.
|
|
369
|
+
const deadline = session.elapsed() + timeoutMs;
|
|
370
|
+
const reader = withinBudget(session, () => deadline - session.elapsed());
|
|
568
371
|
return new Promise((resolve) => {
|
|
569
372
|
let done = false;
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
373
|
+
// A read that threw never looked at the app: the page did not answer, or went away. That is
|
|
374
|
+
// "could not tell", not "looked and it was false", so it is inconclusive, which the verdict rule
|
|
375
|
+
// turns into unknown. As a plain false it was graded assertion_failed: a command timeout on a
|
|
376
|
+
// live, throttled tab came back verified:no against a page that was never read.
|
|
377
|
+
const failed = (error) => {
|
|
378
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
379
|
+
return {
|
|
380
|
+
pass: false,
|
|
381
|
+
failureReason: reason,
|
|
382
|
+
inconclusive: `the page did not answer: ${reason}`,
|
|
383
|
+
};
|
|
384
|
+
};
|
|
574
385
|
let cooldownTimer;
|
|
575
386
|
/** One-shot re-check timed to when a time-based predicate could first pass. See retryAfterMs. */
|
|
576
387
|
let hintTimer;
|
|
@@ -629,7 +440,7 @@ export function waitForPredicate(session, predicate, timeoutMs, since = 0) {
|
|
|
629
440
|
inFlight = true;
|
|
630
441
|
// Interim poll: read only `pass`, so skip the extra near-miss round-trips (diagnose=false). The
|
|
631
442
|
// final timeout eval below runs with full diagnostics.
|
|
632
|
-
void evaluatePredicate(
|
|
443
|
+
void evaluatePredicate(reader, predicate, since, false, baselines)
|
|
633
444
|
.then((r) => {
|
|
634
445
|
if (!r.pass) {
|
|
635
446
|
// Final already: stop rather than spend a budget that cannot change the answer. Only
|
|
@@ -663,7 +474,7 @@ export function waitForPredicate(session, predicate, timeoutMs, since = 0) {
|
|
|
663
474
|
return;
|
|
664
475
|
confirming = true;
|
|
665
476
|
confirmTimer = setTimeout(() => {
|
|
666
|
-
void evaluatePredicate(
|
|
477
|
+
void evaluatePredicate(reader, predicate, since, true, baselines)
|
|
667
478
|
.then(finish)
|
|
668
479
|
.catch((error) => {
|
|
669
480
|
finish(failed(error));
|
|
@@ -738,7 +549,7 @@ export function waitForPredicate(session, predicate, timeoutMs, since = 0) {
|
|
|
738
549
|
});
|
|
739
550
|
const interval = setInterval(boundCheck, POLL_INTERVAL_MS);
|
|
740
551
|
const timer = setTimeout(() => {
|
|
741
|
-
void evaluatePredicate(
|
|
552
|
+
void evaluatePredicate(reader, predicate, since, true, baselines)
|
|
742
553
|
.then((r) => {
|
|
743
554
|
// Spread the near-miss, do NOT hand-copy two fields. The oracle computes observed / expected
|
|
744
555
|
// / assertion — the structured cause the repair literature ranks above prose — and the old
|