@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
|
@@ -27,6 +27,36 @@ const ITEM_KEYS = ['results', 'items', 'data', 'records', 'responses'];
|
|
|
27
27
|
function isRecord(value) {
|
|
28
28
|
return 'object' === typeof value && value !== null && !Array.isArray(value);
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether the value under an error key carries an actual error.
|
|
32
|
+
*
|
|
33
|
+
* An API that always sends its error slot and leaves it EMPTY is saying the opposite of a failure,
|
|
34
|
+
* and every empty shape below was being read as one — because the test was the key's PRESENCE, with
|
|
35
|
+
* `[]` and `''` carved out by hand and nothing else. Reported from the field on a 200 whose error
|
|
36
|
+
* container was empty: `verified: "no"`, "its body reports the operation FAILED", nothing in the
|
|
37
|
+
* body reporting anything of the kind.
|
|
38
|
+
*
|
|
39
|
+
* `false` and `0` are the two that look like judgement calls and are not. `{"error": false}` is the
|
|
40
|
+
* envelope flag for "there was none" — the exact dual of the `ok`/`success` flags read above — and
|
|
41
|
+
* an errno-style `{"error": 0}` spells the same thing; under the plural key, `{"errors": 0}` is a
|
|
42
|
+
* count of none. Each says "none" in both available readings, and the non-empty side of each is
|
|
43
|
+
* untouched: a populated map, a non-zero code, `error: true` and a real message all still report.
|
|
44
|
+
*/
|
|
45
|
+
function carriesError(value) {
|
|
46
|
+
if (value === undefined || null === value)
|
|
47
|
+
return false;
|
|
48
|
+
if (Array.isArray(value))
|
|
49
|
+
return value.length > 0;
|
|
50
|
+
if ('string' === typeof value)
|
|
51
|
+
return value.trim().length > 0;
|
|
52
|
+
if ('boolean' === typeof value)
|
|
53
|
+
return value;
|
|
54
|
+
if ('number' === typeof value)
|
|
55
|
+
return 0 !== value;
|
|
56
|
+
if (isRecord(value))
|
|
57
|
+
return Object.keys(value).length > 0;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
30
60
|
/** Whether one object reports a failure of its own. */
|
|
31
61
|
function reportsFailure(item) {
|
|
32
62
|
if (!isRecord(item))
|
|
@@ -36,18 +66,8 @@ function reportsFailure(item) {
|
|
|
36
66
|
return true;
|
|
37
67
|
}
|
|
38
68
|
for (const key of ERROR_KEYS) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
continue;
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
if (value.length > 0)
|
|
44
|
-
return true;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
// An empty string or an explicit null is an API saying "no error", not an error.
|
|
48
|
-
if ('string' === typeof value && 0 === value.length)
|
|
49
|
-
continue;
|
|
50
|
-
return true;
|
|
69
|
+
if (carriesError(item[key]))
|
|
70
|
+
return true;
|
|
51
71
|
}
|
|
52
72
|
return false;
|
|
53
73
|
}
|
|
@@ -76,7 +76,7 @@ export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
|
|
|
76
76
|
* every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
|
|
77
77
|
* which is why the split happens ONCE here rather than in the one check that reported it.
|
|
78
78
|
*/
|
|
79
|
-
export declare function splitForeignTraffic(events: readonly ReticleEvent[], appOrigin: string | undefined): {
|
|
79
|
+
export declare function splitForeignTraffic(events: readonly ReticleEvent[], appOrigin: string | undefined, background?: readonly string[]): {
|
|
80
80
|
app: readonly ReticleEvent[];
|
|
81
81
|
ignored: string[];
|
|
82
82
|
};
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
|
|
12
12
|
* rules end up disagreeing about the same window.
|
|
13
13
|
*/
|
|
14
|
-
import { EventType, MUTATING_METHODS, asNumber, asString, isDevToolingUrl,
|
|
14
|
+
import { EventType, MUTATING_METHODS, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
|
|
15
15
|
export function netCall(e) {
|
|
16
16
|
const status = asNumber(e.data['status']);
|
|
17
17
|
return {
|
|
@@ -124,7 +124,7 @@ export function isSameDocumentHashAnchor(event) {
|
|
|
124
124
|
* every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
|
|
125
125
|
* which is why the split happens ONCE here rather than in the one check that reported it.
|
|
126
126
|
*/
|
|
127
|
-
export function splitForeignTraffic(events, appOrigin) {
|
|
127
|
+
export function splitForeignTraffic(events, appOrigin, background = []) {
|
|
128
128
|
const ignored = [];
|
|
129
129
|
const app = events.filter((e) => {
|
|
130
130
|
if (!NET_TYPES.has(e.type))
|
|
@@ -132,7 +132,7 @@ export function splitForeignTraffic(events, appOrigin) {
|
|
|
132
132
|
const url = asString(e.data['url']);
|
|
133
133
|
// Somebody else's code, twice over: the toolchain's own channel, and any site that is not the
|
|
134
134
|
// app under test. Neither can answer the question every rule below asks.
|
|
135
|
-
if (!isDevToolingUrl(url) && !
|
|
135
|
+
if (!isDevToolingUrl(url) && !isForeignTraffic(url, appOrigin, background))
|
|
136
136
|
return true;
|
|
137
137
|
if (url !== undefined && !ignored.includes(url))
|
|
138
138
|
ignored.push(url);
|
|
@@ -151,6 +151,12 @@ export interface ContradictionOptions {
|
|
|
151
151
|
* one: a caller that cannot say which page is under test gets the behaviour it had before this.
|
|
152
152
|
*/
|
|
153
153
|
appOrigin?: string | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Same-origin endpoints the project declared the app fires on its own (`.reticle.json`
|
|
156
|
+
* `background`). Dropped with the third-party traffic and disclosed the same way; empty or
|
|
157
|
+
* undefined excludes nothing, because same-origin traffic is never guessed at.
|
|
158
|
+
*/
|
|
159
|
+
background?: readonly string[] | undefined;
|
|
154
160
|
/**
|
|
155
161
|
* The traffic the assertion actually named — `urlContains` from each net clause, `''` for a clause
|
|
156
162
|
* that named the whole channel.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContradictionKind, EventType, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
|
|
1
|
+
import { ContradictionKind, EventType, REQUEST_SHAPE_FIELD, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
|
|
2
2
|
import { describeSuperseded } from '../question/predicate/observed-in-window.js';
|
|
3
3
|
import { describe, isMutating, isSameDocumentHashAnchor, isSteadyCadence, netCall, recoveredByRetry, splitForeignTraffic, } from './contradiction-evidence.js';
|
|
4
4
|
import { findStaleResponses } from './stale-response.js';
|
|
@@ -19,6 +19,33 @@ import { runRegisteredFolds } from './contradiction-folds.js';
|
|
|
19
19
|
*
|
|
20
20
|
* Pure: a window of events in, findings out. No session, no IO, no clock.
|
|
21
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* What this request CARRIED, as far as the record knows — `undefined` when it does not know.
|
|
24
|
+
*
|
|
25
|
+
* The page's shape fingerprint first: it is present on every request from an instrumented page,
|
|
26
|
+
* including the overwhelming majority where body capture is off. A captured body is the fallback for
|
|
27
|
+
* a realm that records one without a fingerprint (desktop IPC). Neither means the record does not
|
|
28
|
+
* say what this request carried — a body the page could not read as text, or an SDK too old to
|
|
29
|
+
* compute a fingerprint — and that is an ABSENCE of identity, not an identity shared with every
|
|
30
|
+
* other silent request.
|
|
31
|
+
*/
|
|
32
|
+
function identityOf(event) {
|
|
33
|
+
const shape = asString(event.data[REQUEST_SHAPE_FIELD]);
|
|
34
|
+
if (shape !== undefined && 0 !== shape.length)
|
|
35
|
+
return shape;
|
|
36
|
+
const body = asString(event.data['requestBody']);
|
|
37
|
+
return body === undefined || 0 === body.length ? undefined : body;
|
|
38
|
+
}
|
|
39
|
+
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
40
|
+
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
41
|
+
function groupByIdentity(calls) {
|
|
42
|
+
const byIdentity = new Map();
|
|
43
|
+
for (const call of calls) {
|
|
44
|
+
const key = call.identity ?? '';
|
|
45
|
+
byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
|
|
46
|
+
}
|
|
47
|
+
return [...byIdentity.values()];
|
|
48
|
+
}
|
|
22
49
|
function uiAdvanced(events) {
|
|
23
50
|
return events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
24
51
|
e.type === EventType.DOM_REMOVED ||
|
|
@@ -166,7 +193,7 @@ export function findContradictions(allEvents, options = {}) {
|
|
|
166
193
|
}
|
|
167
194
|
function findWindowContradictions(allEvents, options) {
|
|
168
195
|
const found = [];
|
|
169
|
-
const { app: allApp, ignored: ignoredForeign } = splitForeignTraffic(allEvents, options.appOrigin);
|
|
196
|
+
const { app: allApp, ignored: ignoredForeign } = splitForeignTraffic(allEvents, options.appOrigin, options.background);
|
|
170
197
|
// ── Evidence belonging to a document that has since been replaced ───────────────────────────
|
|
171
198
|
// Scoped ONCE, here, for the same reason the dev-tooling split is: every rule below asks "what
|
|
172
199
|
// else was in this window", and answering that with a dead page's traffic is a defect in all of
|
|
@@ -492,13 +519,23 @@ function findWindowContradictions(allEvents, options) {
|
|
|
492
519
|
// window the caller handed in turns two legitimate separate saves into a double submit. See
|
|
493
520
|
// ContradictionOptions.actionSince.
|
|
494
521
|
//
|
|
495
|
-
//
|
|
522
|
+
// What the request CARRIED joins the identity. A command-bus API posts every mutation to one URL
|
|
496
523
|
// and discriminates on a body field (`{"command":"study.stage.set"}` vs `{"command":"mesh.plan"}`),
|
|
497
|
-
//
|
|
498
|
-
//
|
|
499
|
-
//
|
|
500
|
-
//
|
|
501
|
-
//
|
|
524
|
+
// and a submit that intentionally saves and then advances sends two different payloads to the same
|
|
525
|
+
// endpoint; under URL alone each of those distinct writes read as a repeat of the first, and clean
|
|
526
|
+
// verdicts degraded to unknown behind doubles that were never doubles.
|
|
527
|
+
//
|
|
528
|
+
// The discriminator is `REQUEST_SHAPE_FIELD` — a fingerprint of the body's shape that the page can
|
|
529
|
+
// compute with body capture OFF, which is the configuration every session runs in. A captured body
|
|
530
|
+
// is used when there is one and no fingerprint (a realm that records bodies but not shapes).
|
|
531
|
+
//
|
|
532
|
+
// When NEITHER is on the record for any call at a URL, the identity of those writes is not known,
|
|
533
|
+
// and this used to be answered inconsistently and silently: two calls that both lacked a body got
|
|
534
|
+
// the same key and were reported as a duplicate, while two where only ONE carried a body got
|
|
535
|
+
// different keys and were reported as nothing at all — so the guess went one way on a false
|
|
536
|
+
// positive and the other way on a real double submit. An unknown group is now one group, reported
|
|
537
|
+
// with a finding that SAYS the identity could not be established. That is `unknown`, which is the
|
|
538
|
+
// honest verdict for it, rather than `unknown` dressed as an accusation.
|
|
502
539
|
const actionSince = options.actionSince;
|
|
503
540
|
if (actionSince !== undefined) {
|
|
504
541
|
/**
|
|
@@ -515,7 +552,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
515
552
|
* distinguishes them.
|
|
516
553
|
*/
|
|
517
554
|
const navigatedAt = events.find((e) => EventType.ROUTE_CHANGE === e.type && e.t >= actionSince)?.t;
|
|
518
|
-
const
|
|
555
|
+
const writes = new Map();
|
|
519
556
|
for (const event of events) {
|
|
520
557
|
if (event.type !== EventType.NET_REQUEST || event.t < actionSince)
|
|
521
558
|
continue;
|
|
@@ -525,14 +562,11 @@ function findWindowContradictions(allEvents, options) {
|
|
|
525
562
|
if (!isMutating(call))
|
|
526
563
|
continue;
|
|
527
564
|
const label = `${call.method} ${call.url}`;
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (false !== call.ok)
|
|
534
|
-
entry.landed += 1;
|
|
535
|
-
writeTimes.set(key, entry);
|
|
565
|
+
const calls = writes.get(label) ?? [];
|
|
566
|
+
// `landed` is tracked per call rather than counted here, because the claim is about what
|
|
567
|
+
// APPLIED and a group is only formed once the identities are known.
|
|
568
|
+
calls.push({ t: event.t, landed: false !== call.ok, identity: identityOf(event) });
|
|
569
|
+
writes.set(label, calls);
|
|
536
570
|
}
|
|
537
571
|
/**
|
|
538
572
|
* Did the assertion name this endpoint?
|
|
@@ -544,38 +578,53 @@ function findWindowContradictions(allEvents, options) {
|
|
|
544
578
|
*/
|
|
545
579
|
const named = options.namedNetUrls;
|
|
546
580
|
const wasNamed = (label) => named === undefined || named.some((u) => label.includes(u));
|
|
547
|
-
for (const [
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
//
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
581
|
+
for (const [label, calls] of writes) {
|
|
582
|
+
// One unknown identity makes the whole endpoint's traffic one group: the calls that DO have a
|
|
583
|
+
// fingerprint cannot be told apart from the ones that do not, so splitting on it would answer
|
|
584
|
+
// a question the record cannot answer.
|
|
585
|
+
const identified = calls.every((c) => c.identity !== undefined);
|
|
586
|
+
const groups = identified ? [...groupByIdentity(calls)] : [calls];
|
|
587
|
+
for (const group of groups) {
|
|
588
|
+
const times = group.map((c) => c.t);
|
|
589
|
+
const landed = group.filter((c) => c.landed).length;
|
|
590
|
+
if (times.length < 2)
|
|
591
|
+
continue;
|
|
592
|
+
// A DOUBLE SUBMIT is a write that landed twice. Two attempts of which one failed is a RETRY,
|
|
593
|
+
// and the field case is the commonest retry there is: a 401 that refreshed a token and went
|
|
594
|
+
// again, one row created, reported here as `duplicate-request ×2`. Two attempts that both
|
|
595
|
+
// failed are not a double submit either — nothing applied even once, so the claim "one user
|
|
596
|
+
// action was performed" is not contradicted by them. A call with no verdict at all still
|
|
597
|
+
// counts, because absence of a status is not evidence the write was rejected.
|
|
598
|
+
if (landed < 2)
|
|
599
|
+
continue;
|
|
600
|
+
// A steady cadence is a POLL, and a poll is not a double submit. An app that polls could not
|
|
601
|
+
// produce a verdict at all: a camera scan loop POSTing until it acquires a lock had every
|
|
602
|
+
// assertion that had already seen its consequence come back `unknown` behind writes that
|
|
603
|
+
// were the app working correctly (#673).
|
|
604
|
+
if (isSteadyCadence(times))
|
|
605
|
+
continue;
|
|
606
|
+
// A burst the assertion never mentioned is still worth telling the caller about -- a retry
|
|
607
|
+
// loop or a bursty beacon is a real finding -- but it is not evidence about the consequence
|
|
608
|
+
// they declared, so it is reported and decides nothing. The named case keeps its downgrade:
|
|
609
|
+
// "the write you asked about fired twice" is exactly what this rule is for.
|
|
610
|
+
const related = wasNamed(label);
|
|
611
|
+
const count = String(times.length);
|
|
612
|
+
found.push({
|
|
613
|
+
kind: related
|
|
614
|
+
? ContradictionKind.DUPLICATE_REQUEST
|
|
615
|
+
: ContradictionKind.DUPLICATE_REQUEST_UNRELATED,
|
|
616
|
+
claim: related
|
|
617
|
+
? 'one user action was performed'
|
|
618
|
+
: 'the assertion did not name this endpoint',
|
|
619
|
+
counter: identified
|
|
620
|
+
? `the same write fired ${count} times`
|
|
621
|
+
: `this endpoint was written to ${count} times`,
|
|
622
|
+
detail: identified
|
|
623
|
+
? `${label} ×${count}`
|
|
624
|
+
: `${label} ×${count} — nothing on the record says what these requests carried, ` +
|
|
625
|
+
'so whether they were one write repeated or different writes could not be established',
|
|
626
|
+
});
|
|
627
|
+
}
|
|
579
628
|
}
|
|
580
629
|
}
|
|
581
630
|
// ── The UI advanced over a request that never came back ─────────────────────────────────────
|
|
@@ -602,7 +651,9 @@ function findWindowContradictions(allEvents, options) {
|
|
|
602
651
|
inFlight.map((p) => describe(p.call)).join('; '),
|
|
603
652
|
...(0 === ignoredForeign.length
|
|
604
653
|
? []
|
|
605
|
-
: [
|
|
654
|
+
: [
|
|
655
|
+
`ignored as dev tooling, third-party or declared background: ${ignoredForeign.join(', ')}`,
|
|
656
|
+
]),
|
|
606
657
|
].join(' — '),
|
|
607
658
|
});
|
|
608
659
|
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* anything.
|
|
18
18
|
*/
|
|
19
19
|
import { PredicateKind } from '@reticlehq/core';
|
|
20
|
+
import { asksForComparison } from './baseline.js';
|
|
20
21
|
export function readsDomState(predicate) {
|
|
21
22
|
switch (predicate.kind) {
|
|
22
23
|
// ROUTE is here, and it did not used to be. It was purely event-based — satisfiable only by a
|
|
@@ -38,10 +39,16 @@ export function readsDomState(predicate) {
|
|
|
38
39
|
// rather than through the floored event buffer. If the store already holds the expected value
|
|
39
40
|
// before dispatch, an inert click would immediately pass post-dispatch on the pre-existing state.
|
|
40
41
|
// Evaluating before dispatch routes that pre-existing condition into already_true.
|
|
41
|
-
|
|
42
|
+
//
|
|
43
|
+
// A RELATIVE property is the one exception, and it is excluded by construction rather than by
|
|
44
|
+
// taste: `unchanged` compares this reading with the one taken a microsecond ago and is
|
|
45
|
+
// therefore always true before the action. Pre-checking it would report `already_true` — and
|
|
46
|
+
// so UNKNOWN — for the assertion whose whole purpose is that the value survives what follows.
|
|
42
47
|
case PredicateKind.TEXT:
|
|
43
|
-
case PredicateKind.ROUTE:
|
|
44
48
|
case PredicateKind.STATE:
|
|
49
|
+
return !asksForComparison(predicate);
|
|
50
|
+
case PredicateKind.ELEMENT:
|
|
51
|
+
case PredicateKind.ROUTE:
|
|
45
52
|
return true;
|
|
46
53
|
case PredicateKind.ALL_OF:
|
|
47
54
|
case PredicateKind.ANY_OF:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Predicate } from '../question/predicate/predicate.js';
|
|
2
|
+
import type { Baseline } from '../question/predicate/property.js';
|
|
3
|
+
import type { PredicateSession } from '../question/predicate/predicate-session.js';
|
|
4
|
+
/**
|
|
5
|
+
* Does this leaf's claim compare two readings?
|
|
6
|
+
*
|
|
7
|
+
* Exported because `readsDomState` has to exclude exactly these. A relative property is NEVER
|
|
8
|
+
* answerable before the action — `unchanged` is trivially true against a baseline taken a
|
|
9
|
+
* microsecond earlier — so pre-checking one would report `already_true` for the assertion whose
|
|
10
|
+
* entire purpose is that the value survives what comes next, and turn its verdict into UNKNOWN.
|
|
11
|
+
*/
|
|
12
|
+
export declare function asksForComparison(predicate: Predicate): boolean;
|
|
13
|
+
/** Does the whole tree need a pre-action reading at all? One walk, so the caller pays nothing. */
|
|
14
|
+
export declare function needsBaseline(predicate: Predicate | undefined): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Read what every comparing leaf needs, once, before the action.
|
|
17
|
+
*
|
|
18
|
+
* Keyed by the predicate OBJECT: the same parsed tree is evaluated before and after, so identity
|
|
19
|
+
* is exact and no path or index has to be kept in step with the walk.
|
|
20
|
+
*/
|
|
21
|
+
export declare function captureBaselines(session: PredicateSession, predicate: Predicate | undefined): Promise<ReadonlyMap<Predicate, Baseline>>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reading taken BEFORE the action, so a predicate can talk about the past.
|
|
3
|
+
*
|
|
4
|
+
* Every leaf in the grammar read the present tense — the DOM now, the store now, the events since a
|
|
5
|
+
* cursor — so the assertions that catch money bugs could not be written: the balance went down by
|
|
6
|
+
* what was charged, the list gained three rows, this field held its value across the re-render.
|
|
7
|
+
*
|
|
8
|
+
* Nothing new is observed to make them writable. `already-true` was already taking a pre-action
|
|
9
|
+
* reading and throwing it away one function short of being this feature; the only change is that a
|
|
10
|
+
* leaf which asked for a comparison gets its own value kept.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately just "before this action" — the window every verdict is already scoped to — and not
|
|
13
|
+
* arbitrary named checkpoints. A `snapshot("cart")` / `compare("cart")` pair is a different feature
|
|
14
|
+
* and has no evidence behind it.
|
|
15
|
+
*/
|
|
16
|
+
import { PredicateKind, ReticleCommand } from '@reticlehq/core';
|
|
17
|
+
/** The properties that mean nothing without a before-reading. Mirrors `RELATIVE` in property.ts. */
|
|
18
|
+
const NEEDS_BASELINE = new Set([
|
|
19
|
+
'changed',
|
|
20
|
+
'unchanged',
|
|
21
|
+
'increased',
|
|
22
|
+
'decreased',
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Does this leaf's claim compare two readings?
|
|
26
|
+
*
|
|
27
|
+
* Exported because `readsDomState` has to exclude exactly these. A relative property is NEVER
|
|
28
|
+
* answerable before the action — `unchanged` is trivially true against a baseline taken a
|
|
29
|
+
* microsecond earlier — so pre-checking one would report `already_true` for the assertion whose
|
|
30
|
+
* entire purpose is that the value survives what comes next, and turn its verdict into UNKNOWN.
|
|
31
|
+
*/
|
|
32
|
+
export function asksForComparison(predicate) {
|
|
33
|
+
if (PredicateKind.STATE === predicate.kind || PredicateKind.TEXT === predicate.kind) {
|
|
34
|
+
return predicate.satisfies !== undefined && NEEDS_BASELINE.has(predicate.satisfies.property);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
/** Every leaf that asked for a comparison, composites included. */
|
|
39
|
+
function leavesNeedingBaseline(predicate, into) {
|
|
40
|
+
switch (predicate.kind) {
|
|
41
|
+
case PredicateKind.ALL_OF:
|
|
42
|
+
case PredicateKind.ANY_OF:
|
|
43
|
+
for (const part of predicate.predicates)
|
|
44
|
+
leavesNeedingBaseline(part, into);
|
|
45
|
+
return;
|
|
46
|
+
case PredicateKind.NOT:
|
|
47
|
+
leavesNeedingBaseline(predicate.predicate, into);
|
|
48
|
+
return;
|
|
49
|
+
default:
|
|
50
|
+
if (asksForComparison(predicate))
|
|
51
|
+
into.push(predicate);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Does the whole tree need a pre-action reading at all? One walk, so the caller pays nothing. */
|
|
55
|
+
export function needsBaseline(predicate) {
|
|
56
|
+
if (predicate === undefined)
|
|
57
|
+
return false;
|
|
58
|
+
const found = [];
|
|
59
|
+
leavesNeedingBaseline(predicate, found);
|
|
60
|
+
return found.length > 0;
|
|
61
|
+
}
|
|
62
|
+
async function readStateValue(session, predicate) {
|
|
63
|
+
const args = predicate.store === undefined
|
|
64
|
+
? { path: predicate.path }
|
|
65
|
+
: { store: predicate.store, path: predicate.path };
|
|
66
|
+
const read = await session.command(ReticleCommand.STATE_READ, args);
|
|
67
|
+
if (!read.ok)
|
|
68
|
+
return undefined;
|
|
69
|
+
const reply = (read.result ?? {});
|
|
70
|
+
// `found: false` is a reading — the path held nothing — and it is NOT the same as "nobody
|
|
71
|
+
// looked". Only an unreadable store returns undefined above.
|
|
72
|
+
return 'boolean' === typeof reply.found ? { taken: true, value: reply.value } : undefined;
|
|
73
|
+
}
|
|
74
|
+
async function readText(session, predicate) {
|
|
75
|
+
const query = {
|
|
76
|
+
...(predicate.contains === undefined ? {} : { text: predicate.contains }),
|
|
77
|
+
...(predicate.scope === undefined
|
|
78
|
+
? {}
|
|
79
|
+
: { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
|
|
80
|
+
};
|
|
81
|
+
const match = await session.command(ReticleCommand.MATCH, { query });
|
|
82
|
+
if (!match.ok)
|
|
83
|
+
return undefined;
|
|
84
|
+
const elements = (match.result ?? {}).elements;
|
|
85
|
+
if (!Array.isArray(elements))
|
|
86
|
+
return undefined;
|
|
87
|
+
const text = elements
|
|
88
|
+
.map((element) => {
|
|
89
|
+
if ('object' !== typeof element || null === element)
|
|
90
|
+
return '';
|
|
91
|
+
const value = element.text;
|
|
92
|
+
return 'string' === typeof value ? value : '';
|
|
93
|
+
})
|
|
94
|
+
.join(' ')
|
|
95
|
+
.trim();
|
|
96
|
+
// An empty page is a reading of "": the element was not there, and that is what a later
|
|
97
|
+
// `changed` is comparing against. Refusing here would turn "it appeared" into "nobody looked".
|
|
98
|
+
return { taken: true, value: text };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Read what every comparing leaf needs, once, before the action.
|
|
102
|
+
*
|
|
103
|
+
* Keyed by the predicate OBJECT: the same parsed tree is evaluated before and after, so identity
|
|
104
|
+
* is exact and no path or index has to be kept in step with the walk.
|
|
105
|
+
*/
|
|
106
|
+
export async function captureBaselines(session, predicate) {
|
|
107
|
+
const captured = new Map();
|
|
108
|
+
if (predicate === undefined)
|
|
109
|
+
return captured;
|
|
110
|
+
const leaves = [];
|
|
111
|
+
leavesNeedingBaseline(predicate, leaves);
|
|
112
|
+
for (const leaf of leaves) {
|
|
113
|
+
try {
|
|
114
|
+
const reading = PredicateKind.STATE === leaf.kind
|
|
115
|
+
? await readStateValue(session, leaf)
|
|
116
|
+
: PredicateKind.TEXT === leaf.kind
|
|
117
|
+
? await readText(session, leaf)
|
|
118
|
+
: undefined;
|
|
119
|
+
if (reading !== undefined)
|
|
120
|
+
captured.set(leaf, reading);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// A reading that could not be taken leaves the leaf with no baseline, which the evaluator
|
|
124
|
+
// reports as `inconclusive`. Throwing here would lose the whole verdict for one unreadable
|
|
125
|
+
// store — and an unevaluated clause is already the honest answer for exactly this.
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return captured;
|
|
129
|
+
}
|
|
@@ -57,7 +57,12 @@ export function bodyCaptureRemedy(sdkVersion) {
|
|
|
57
57
|
return ENABLE_IT;
|
|
58
58
|
}
|
|
59
59
|
/** Clause names that can only be answered from a recorded body. */
|
|
60
|
-
const BODY_CLAUSE_FIELDS = [
|
|
60
|
+
const BODY_CLAUSE_FIELDS = [
|
|
61
|
+
'bodyContains',
|
|
62
|
+
'bodyMatches',
|
|
63
|
+
'requestBodyContains',
|
|
64
|
+
'requestBodyMatches',
|
|
65
|
+
];
|
|
61
66
|
/** Does this predicate, or anything nested in it, ask about a body? */
|
|
62
67
|
function asksAboutBody(predicate) {
|
|
63
68
|
if (null === predicate || 'object' !== typeof predicate)
|
|
@@ -42,6 +42,16 @@ interface HonestyInputs {
|
|
|
42
42
|
*/
|
|
43
43
|
coverageNote?: string;
|
|
44
44
|
truncated?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Did the durable event ledger stop accepting writes, on a path this verdict read from?
|
|
47
|
+
*
|
|
48
|
+
* Separate from `truncated`, which means the in-memory ring buffer evicted a window that had aged
|
|
49
|
+
* out. Both make a capture incomplete and both belong in `issues`, but they are opposite kinds of
|
|
50
|
+
* fact for whoever reads the sentence: an eviction is a window that scrolled past, recoverable by
|
|
51
|
+
* looking sooner, while a closed ledger is a file that will not take another byte for the rest of
|
|
52
|
+
* the session. One word for both would tell an agent to re-drive a thing no re-drive can fix.
|
|
53
|
+
*/
|
|
54
|
+
ledgerClosed?: boolean;
|
|
45
55
|
blindSpots?: readonly string[];
|
|
46
56
|
/**
|
|
47
57
|
* The machine-readable half of `issues` — WHICH kind of loss, from core's closed `CaptureLoss`.
|
package/dist/evidence/honesty.js
CHANGED
|
@@ -35,10 +35,14 @@ export const weakerGrade = (a, b) => GRADE_RANK[a] <= GRADE_RANK[b] ? a : b;
|
|
|
35
35
|
const MIN_ENVELOPE_SAMPLES = 3;
|
|
36
36
|
/** Coverage when the SDK reported no blind spots during the window — it saw everything it can see. */
|
|
37
37
|
const FULL_COVERAGE_PCT = 100;
|
|
38
|
+
/** What `integrity.issues` says when the durable ledger refused writes — see `ledgerClosed`. */
|
|
39
|
+
const LEDGER_CLOSED_ISSUE = 'durable event ledger closed at its size cap, so evidence after that point is not on disk';
|
|
38
40
|
export function buildHonestyBlock(inputs) {
|
|
39
41
|
const issues = [];
|
|
40
42
|
if (true === inputs.truncated)
|
|
41
43
|
issues.push('capture truncated');
|
|
44
|
+
if (true === inputs.ledgerClosed)
|
|
45
|
+
issues.push(LEDGER_CLOSED_ISSUE);
|
|
42
46
|
for (const spot of inputs.blindSpots ?? [])
|
|
43
47
|
issues.push(`blind spot: ${spot}`);
|
|
44
48
|
// Report only what was measured. `envelope` used to be emitted unconditionally with samples=0, so
|
|
@@ -2,6 +2,13 @@ import { type ChannelId, Verified, VerifiedReason } from '@reticlehq/core';
|
|
|
2
2
|
import { type HonestyBlock } from './honesty.js';
|
|
3
3
|
import { type UnsettledWindow } from './unsettled.js';
|
|
4
4
|
interface VerifiedInputs {
|
|
5
|
+
/**
|
|
6
|
+
* The page SDK and daemon wire mismatch, when the handshake found one. Absent means they agree.
|
|
7
|
+
*
|
|
8
|
+
* Carried rather than re-derived: only the bridge sees both halves of the handshake, and a verdict
|
|
9
|
+
* that re-guessed it from versions would disagree with the warning the session already printed.
|
|
10
|
+
*/
|
|
11
|
+
versionSkew?: string;
|
|
5
12
|
/** Did the declared consequence hold? Undefined when the action declared none. */
|
|
6
13
|
pass?: boolean;
|
|
7
14
|
/**
|
|
@@ -31,7 +31,24 @@ function undeclaredChannels(inputs) {
|
|
|
31
31
|
}
|
|
32
32
|
export function decideVerified(inputs) {
|
|
33
33
|
const { pass, honesty, contradictions = [], settled, outcomePending, outcomeUnread } = inputs;
|
|
34
|
-
//
|
|
34
|
+
// Ahead of everything, with `capability-absent` below it and for the same reason: a skewed wire
|
|
35
|
+
// means the ACTION may never have happened, so grading the quality of an observation of it is
|
|
36
|
+
// grading nothing. `session-health` already ranks skew above the throttle warning on this
|
|
37
|
+
// argument; this is the verdict finally agreeing with the warning it was printing beside.
|
|
38
|
+
//
|
|
39
|
+
// UNKNOWN, not NO. Nothing about the app was disproved -- the link under the evidence is what is
|
|
40
|
+
// in doubt. An empty string is not a skew.
|
|
41
|
+
const skew = inputs.versionSkew;
|
|
42
|
+
if (skew !== undefined && skew.length > 0) {
|
|
43
|
+
return {
|
|
44
|
+
verified: Verified.UNKNOWN,
|
|
45
|
+
verifiedReason: VerifiedReason.VERSION_SKEW,
|
|
46
|
+
because: `the page SDK and this daemon are on different wire contracts (${skew}), so dispatched ` +
|
|
47
|
+
'and settled may be silent no-ops — nothing was proved or disproved about the app. ' +
|
|
48
|
+
'Converge the versions and re-run',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// FIRST among the evidence clauses. A claim that needed to read something nobody was watching
|
|
35
52
|
// was never answerable, and any clause reaching a verdict before this one would report that as
|
|
36
53
|
// something else -- most often as a failure, which blames the app for a gap in the tooling.
|
|
37
54
|
const unobservable = undeclaredChannels(inputs);
|
|
@@ -207,6 +224,23 @@ export function decideVerified(inputs) {
|
|
|
207
224
|
'the store holds) before trusting it',
|
|
208
225
|
};
|
|
209
226
|
}
|
|
227
|
+
// `route-rendered-nothing` gets its own sentence for the same reason: the generic one blames churn
|
|
228
|
+
// and a slow app, and here nothing was busy - the URL moved and no view appeared for it. Driven on
|
|
229
|
+
// bench-app with a store that ignored the navigation: the route predicate held, this fired, and the
|
|
230
|
+
// generic sentence sent the reader to wait. UNKNOWN rather than NO because a view revealed from DOM
|
|
231
|
+
// that already existed (a CSS-toggled tab) emits this same window.
|
|
232
|
+
const routeOnly = deciding.length > 0 &&
|
|
233
|
+
deciding.every((c) => c.kind === ContradictionKind.ROUTE_RENDERED_NOTHING);
|
|
234
|
+
if (routeOnly) {
|
|
235
|
+
return {
|
|
236
|
+
verified: Verified.UNKNOWN,
|
|
237
|
+
verifiedReason: VerifiedReason.EVIDENCE_INCOMPLETE,
|
|
238
|
+
because: 'the URL changed, but nothing rendered for it: no content added or removed and no request ' +
|
|
239
|
+
'made, so the new route may show the old view. A route change alone does not prove the ' +
|
|
240
|
+
'destination appeared. Assert what the destination shows (its heading or a testid) or the ' +
|
|
241
|
+
'store value that selects it, rather than the URL',
|
|
242
|
+
};
|
|
243
|
+
}
|
|
210
244
|
if (deciding.length > 0 && !settlementOnly) {
|
|
211
245
|
const kinds = deciding.map((c) => c.kind).join(', ');
|
|
212
246
|
return {
|
|
@@ -97,8 +97,9 @@ export function declaredExpectations(predicate) {
|
|
|
97
97
|
case PredicateKind.TEXT:
|
|
98
98
|
if (true !== p.absent) {
|
|
99
99
|
rendersContent = true;
|
|
100
|
-
if (isDenialPhrase(p.contains))
|
|
100
|
+
if (p.contains !== undefined && isDenialPhrase(p.contains)) {
|
|
101
101
|
pushAuthDenialStatuses(netFailures);
|
|
102
|
+
}
|
|
102
103
|
}
|
|
103
104
|
return;
|
|
104
105
|
default:
|