@reticlehq/engine 3.5.0 → 3.6.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 +2 -1
- package/dist/disagreement/contradiction-evidence.d.ts +7 -0
- package/dist/disagreement/contradiction-evidence.js +13 -4
- package/dist/disagreement/contradictions.d.ts +5 -1
- package/dist/disagreement/contradictions.js +109 -3
- package/dist/disagreement/echo-mismatch.js +42 -3
- package/dist/disagreement/reconcile.js +15 -0
- package/dist/disagreement/stale-response.js +32 -2
- package/dist/evidence/accepted-write.d.ts +26 -2
- package/dist/evidence/accepted-write.js +35 -18
- package/dist/evidence/already-true.d.ts +11 -0
- package/dist/evidence/already-true.js +27 -0
- package/dist/evidence/body-capture-remedy.d.ts +10 -0
- package/dist/evidence/body-capture-remedy.js +15 -2
- package/dist/evidence/verified.d.ts +2 -0
- package/dist/evidence/verified.js +10 -0
- package/dist/question/declared.d.ts +4 -4
- package/dist/question/declared.js +6 -4
- package/dist/question/predicate/name-near-miss.d.ts +24 -0
- package/dist/question/predicate/name-near-miss.js +39 -0
- package/dist/question/predicate/predicate-compare.js +13 -4
- package/dist/question/predicate/predicate-element.d.ts +1 -1
- package/dist/question/predicate/predicate-element.js +33 -3
- package/dist/question/predicate/predicate-eval.d.ts +16 -1
- package/dist/question/predicate/predicate-eval.js +70 -13
- package/dist/question/predicate/predicate-parse.js +119 -13
- package/dist/question/predicate/predicate-schema.js +58 -23
- package/dist/question/predicate/predicate-session.d.ts +10 -0
- package/dist/question/predicate/predicate-to-links.js +1 -0
- package/dist/question/predicate/predicate.js +72 -15
- package/dist/question/reaction.d.ts +1 -1
- package/dist/question/reaction.js +1 -1
- package/package.json +2 -2
|
@@ -53,8 +53,9 @@ function carriesError(value) {
|
|
|
53
53
|
return value;
|
|
54
54
|
if ('number' === typeof value)
|
|
55
55
|
return 0 !== value;
|
|
56
|
+
// An envelope carries an error only if something inside it does: `{ fieldErrors: {}, formErrors: [] }` is none.
|
|
56
57
|
if (isRecord(value))
|
|
57
|
-
return Object.
|
|
58
|
+
return Object.values(value).some(carriesError);
|
|
58
59
|
return true;
|
|
59
60
|
}
|
|
60
61
|
/** Whether one object reports a failure of its own. */
|
|
@@ -75,6 +75,13 @@ export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
|
|
|
75
75
|
* over a request that never settled". Every app that logs one dev warning got a false negative on
|
|
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
|
+
*
|
|
79
|
+
* CLASSIFY on `urlForMatch`, DISCLOSE `url`. Redaction rewrites a sensitive path segment at emit
|
|
80
|
+
* time (`/verify/refresh-token` -> `/verify/[REDACTED]`) and keeps the original only in `urlRaw`, so
|
|
81
|
+
* a project's DECLARED `background` pattern — matched with `String.includes` — never matched what
|
|
82
|
+
* this read. The endpoint went back in among the app's own traffic and every rule below judged it,
|
|
83
|
+
* which is the half of the same defect the settle wait had. Disclosure deliberately keeps the
|
|
84
|
+
* DISPLAYED spelling: the raw one is the match haystack, not something to project into a transcript.
|
|
78
85
|
*/
|
|
79
86
|
export declare function splitForeignTraffic(events: readonly ReticleEvent[], appOrigin: string | undefined, background?: readonly string[]): {
|
|
80
87
|
app: readonly ReticleEvent[];
|
|
@@ -123,19 +123,28 @@ export function isSameDocumentHashAnchor(event) {
|
|
|
123
123
|
* over a request that never settled". Every app that logs one dev warning got a false negative on
|
|
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
|
+
*
|
|
127
|
+
* CLASSIFY on `urlForMatch`, DISCLOSE `url`. Redaction rewrites a sensitive path segment at emit
|
|
128
|
+
* time (`/verify/refresh-token` -> `/verify/[REDACTED]`) and keeps the original only in `urlRaw`, so
|
|
129
|
+
* a project's DECLARED `background` pattern — matched with `String.includes` — never matched what
|
|
130
|
+
* this read. The endpoint went back in among the app's own traffic and every rule below judged it,
|
|
131
|
+
* which is the half of the same defect the settle wait had. Disclosure deliberately keeps the
|
|
132
|
+
* DISPLAYED spelling: the raw one is the match haystack, not something to project into a transcript.
|
|
126
133
|
*/
|
|
127
134
|
export function splitForeignTraffic(events, appOrigin, background = []) {
|
|
128
135
|
const ignored = [];
|
|
129
136
|
const app = events.filter((e) => {
|
|
130
137
|
if (!NET_TYPES.has(e.type))
|
|
131
138
|
return true;
|
|
132
|
-
const
|
|
139
|
+
const matchUrl = urlForMatch(e.data);
|
|
140
|
+
const shown = asString(e.data['url']);
|
|
133
141
|
// Somebody else's code, twice over: the toolchain's own channel, and any site that is not the
|
|
134
142
|
// app under test. Neither can answer the question every rule below asks.
|
|
135
|
-
|
|
143
|
+
const match = 0 === matchUrl.length ? undefined : matchUrl;
|
|
144
|
+
if (!isDevToolingUrl(match) && !isForeignTraffic(match, appOrigin, background))
|
|
136
145
|
return true;
|
|
137
|
-
if (
|
|
138
|
-
ignored.push(
|
|
146
|
+
if (shown !== undefined && !ignored.includes(shown))
|
|
147
|
+
ignored.push(shown);
|
|
139
148
|
return false;
|
|
140
149
|
});
|
|
141
150
|
return { app, ignored };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type ReticleEvent } from '@reticlehq/core';
|
|
2
|
-
import type { Contradiction, ContradictionOptions } from './contradiction-types.js';
|
|
2
|
+
import type { Contradiction, OwnContradiction, ContradictionOptions } from './contradiction-types.js';
|
|
3
3
|
export type { Contradiction, OwnContradiction, ContradictionOptions, } from './contradiction-types.js';
|
|
4
4
|
/** Net-shaped events — the only ones that carry a URL a dev-tooling channel could occupy. */
|
|
5
5
|
export declare function findContradictions(allEvents: readonly ReticleEvent[], options?: ContradictionOptions): Contradiction[];
|
|
6
|
+
/**
|
|
7
|
+
* @param prior events before the window: where the last page request to each endpoint is learned.
|
|
8
|
+
*/
|
|
9
|
+
export declare function findStalledPagination(events: readonly ReticleEvent[], prior?: readonly ReticleEvent[]): OwnContradiction[];
|
|
@@ -88,13 +88,28 @@ function failureAcknowledged(events) {
|
|
|
88
88
|
.map((e) => asString(e.data['error']))
|
|
89
89
|
.filter((text) => text !== undefined && text.length >= MIN_ECHOED_ERROR_LENGTH);
|
|
90
90
|
const echoesAnError = events.some((e) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const value =
|
|
91
|
+
// On screen counts as much as in state: the user reading the server's message is the app
|
|
92
|
+
// acknowledging the failure, not hiding it (#984).
|
|
93
|
+
const value = e.type === EventType.STATE_CHANGE
|
|
94
|
+
? asString(e.data['value'])
|
|
95
|
+
: e.type === EventType.DOM_TEXT
|
|
96
|
+
? asString(e.data['text'])
|
|
97
|
+
: e.type === EventType.DOM_ADDED
|
|
98
|
+
? asString(e.data['name'])
|
|
99
|
+
: undefined;
|
|
94
100
|
return value !== undefined && errors.some((text) => value.includes(text));
|
|
95
101
|
});
|
|
96
102
|
if (echoesAnError)
|
|
97
103
|
return true;
|
|
104
|
+
// So does the accessible way of telling a user something went wrong: an alert appearing, or a
|
|
105
|
+
// field marked invalid. A rejected write that is the behaviour under test (a 409 on a duplicate
|
|
106
|
+
// email) is acknowledged exactly this way, and was contradicted for it (#984).
|
|
107
|
+
const shownAsError = events.some((e) => (e.type === EventType.DOM_ADDED && ALERT_ROLE === e.data['role']) ||
|
|
108
|
+
(e.type === EventType.DOM_ATTR &&
|
|
109
|
+
ARIA_INVALID === e.data['attr'] &&
|
|
110
|
+
'true' === e.data['value']));
|
|
111
|
+
if (shownAsError)
|
|
112
|
+
return true;
|
|
98
113
|
return events.some((e) => {
|
|
99
114
|
// A failure-shaped SIGNAL is an acknowledgement too. An app that fires `auth:denied` has plainly
|
|
100
115
|
// not proceeded as if it succeeded, whatever its state paths happen to be named.
|
|
@@ -107,6 +122,8 @@ function failureAcknowledged(events) {
|
|
|
107
122
|
return ACKNOWLEDGED.test(path) || ('string' === typeof value && ACKNOWLEDGED.test(value));
|
|
108
123
|
});
|
|
109
124
|
}
|
|
125
|
+
const ALERT_ROLE = 'alert';
|
|
126
|
+
const ARIA_INVALID = 'aria-invalid';
|
|
110
127
|
const MUST_DO_SOMETHING = new Set(['click', 'dblclick', 'submit']);
|
|
111
128
|
/**
|
|
112
129
|
* Whether NOTHING in this window is attributable to the action.
|
|
@@ -226,6 +243,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
226
243
|
found.push(...findEchoMismatches(events, options.actionSince));
|
|
227
244
|
// ── A money value written back at the wrong SCALE ───────────────────────────────────────────
|
|
228
245
|
found.push(...findUnitMismatches(events, options.prior ?? []));
|
|
246
|
+
found.push(...findStalledPagination(events, options.prior ?? []));
|
|
229
247
|
// ── The action landed on something that does not react ──────────────────────────────────────
|
|
230
248
|
// Checked first and returned alone: nothing is attributable to the action, so every rule below is
|
|
231
249
|
// reasoning about someone else's events.
|
|
@@ -654,3 +672,91 @@ function findWindowContradictions(allEvents, options) {
|
|
|
654
672
|
// adds to the verdict rather than forking the file that produces it.
|
|
655
673
|
return [...found, ...runRegisteredFolds(events, options)];
|
|
656
674
|
}
|
|
675
|
+
// ── Pagination ───────────────────────────────────────────────────────────────────────────────
|
|
676
|
+
/**
|
|
677
|
+
* The page label moved and the request did not.
|
|
678
|
+
*
|
|
679
|
+
* Measured on a real payments dashboard: "Next" relabels the table "Page 2 of 6" and the app
|
|
680
|
+
* refetches `GET /payments?page=1`, so 103 of 128 rows can never be reached. Every channel looks
|
|
681
|
+
* healthy on its own: the request is a 200, the label changed, the table rendered rows. The
|
|
682
|
+
* disagreement is between the label and the query string.
|
|
683
|
+
*
|
|
684
|
+
* Fires only on direct evidence, never on a guess: the window must show the label's page number
|
|
685
|
+
* changing AND a GET to the same endpoint carrying the same page parameter the last one carried.
|
|
686
|
+
* Client-side paging that fetches nothing is legitimate and stays silent.
|
|
687
|
+
*/
|
|
688
|
+
/** Query parameters that say which page of a list is being asked for. */
|
|
689
|
+
const PAGE_PARAMS = ['page', 'offset', 'cursor', 'after', 'start', 'skip', 'from'];
|
|
690
|
+
/** "Page 2", "page 2 of 6", "2 / 6", "2 of 6". */
|
|
691
|
+
const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+\b/i;
|
|
692
|
+
function pageNumber(text) {
|
|
693
|
+
if ('string' !== typeof text)
|
|
694
|
+
return undefined;
|
|
695
|
+
const match = PAGE_LABEL.exec(text);
|
|
696
|
+
const raw = match?.[1] ?? match?.[2];
|
|
697
|
+
return raw === undefined ? undefined : Number(raw);
|
|
698
|
+
}
|
|
699
|
+
/** The endpoint and its page parameter, for a GET that carries one. */
|
|
700
|
+
function pageRequest(event) {
|
|
701
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
702
|
+
return undefined;
|
|
703
|
+
const method = event.data['method'];
|
|
704
|
+
if ('string' !== typeof method || 'GET' !== method.toUpperCase())
|
|
705
|
+
return undefined;
|
|
706
|
+
const raw = event.data['url'];
|
|
707
|
+
if ('string' !== typeof raw)
|
|
708
|
+
return undefined;
|
|
709
|
+
let url;
|
|
710
|
+
try {
|
|
711
|
+
url = new URL(raw, 'http://app.invalid');
|
|
712
|
+
}
|
|
713
|
+
catch {
|
|
714
|
+
return undefined;
|
|
715
|
+
}
|
|
716
|
+
for (const param of PAGE_PARAMS) {
|
|
717
|
+
const value = url.searchParams.get(param);
|
|
718
|
+
if (value !== null)
|
|
719
|
+
return { path: url.pathname, param, value };
|
|
720
|
+
}
|
|
721
|
+
return undefined;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* @param prior events before the window: where the last page request to each endpoint is learned.
|
|
725
|
+
*/
|
|
726
|
+
export function findStalledPagination(events, prior = []) {
|
|
727
|
+
const moved = events.flatMap((event) => {
|
|
728
|
+
if (event.type !== EventType.DOM_TEXT)
|
|
729
|
+
return [];
|
|
730
|
+
const now = pageNumber(event.data['text']);
|
|
731
|
+
const before = pageNumber(event.data['old']);
|
|
732
|
+
return now !== undefined && before !== undefined && now !== before ? [{ before, now }] : [];
|
|
733
|
+
});
|
|
734
|
+
const label = moved[0];
|
|
735
|
+
if (label === undefined)
|
|
736
|
+
return [];
|
|
737
|
+
const last = new Map();
|
|
738
|
+
for (const event of prior) {
|
|
739
|
+
const request = pageRequest(event);
|
|
740
|
+
if (request !== undefined)
|
|
741
|
+
last.set(request.path, request);
|
|
742
|
+
}
|
|
743
|
+
for (const event of events) {
|
|
744
|
+
const request = pageRequest(event);
|
|
745
|
+
if (request === undefined)
|
|
746
|
+
continue;
|
|
747
|
+
const previous = last.get(request.path);
|
|
748
|
+
if (previous !== undefined &&
|
|
749
|
+
previous.param === request.param &&
|
|
750
|
+
previous.value === request.value)
|
|
751
|
+
return [
|
|
752
|
+
{
|
|
753
|
+
kind: ContradictionKind.PAGINATION_NOT_FETCHED,
|
|
754
|
+
claim: `the page label moved from ${String(label.before)} to ${String(label.now)}`,
|
|
755
|
+
counter: `the app asked ${request.path} for ${request.param}=${request.value} again — the same page it already had`,
|
|
756
|
+
detail: `${String(event.data['url'])} — the rows shown are still the earlier page, so everything past it cannot be reached`,
|
|
757
|
+
},
|
|
758
|
+
];
|
|
759
|
+
last.set(request.path, request);
|
|
760
|
+
}
|
|
761
|
+
return [];
|
|
762
|
+
}
|
|
@@ -28,8 +28,10 @@ import { ContradictionKind, EventType, MUTATING_METHODS } from '@reticlehq/core'
|
|
|
28
28
|
* that share a field name were never expected to match. Both used to fire on every healthy POST;
|
|
29
29
|
* - only keys the request actually SENT are considered;
|
|
30
30
|
* - only scalars, since deep structural diffing is where the false positives live;
|
|
31
|
-
* - values are compared NORMALISED (trimmed, case-folded, numbers as numbers
|
|
32
|
-
* `1` vs `1.0` stay silent while `fr` vs `en`
|
|
31
|
+
* - values are compared NORMALISED (trimmed, case-folded, numbers as numbers, ISO-8601 instants
|
|
32
|
+
* as instants), so `FR` vs `fr`, `1` vs `1.0` and `.000Z` vs `Z` stay silent while `fr` vs `en`
|
|
33
|
+
* speaks;
|
|
34
|
+
* - server-stamped audit columns (`updated_at` and its spellings) are not compared;
|
|
33
35
|
* - if the key appears anywhere in the response carrying the requested value, it is treated as
|
|
34
36
|
* applied — an envelope that echoes both the old and the new value is not a dropped write;
|
|
35
37
|
* - the response must look like a restatement of the request before any key is compared. Reported
|
|
@@ -64,10 +66,29 @@ function parse(raw) {
|
|
|
64
66
|
return undefined;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* An ISO-8601 date-time that names one instant: it carries a time AND a zone (`Z` or `±hh:mm`).
|
|
71
|
+
* A bare date or a zone-less local time is not an instant and is compared as text.
|
|
72
|
+
*/
|
|
73
|
+
const ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/i;
|
|
74
|
+
/**
|
|
75
|
+
* Two spellings of one instant — `…:00.000Z`, `…:00Z`, `…+05:30` — are the same value. Servers
|
|
76
|
+
* re-serialise timestamps through their own date type, so precision and zone spelling are
|
|
77
|
+
* formatting, not a dropped write.
|
|
78
|
+
*/
|
|
79
|
+
function normalizeString(value) {
|
|
80
|
+
const trimmed = value.trim();
|
|
81
|
+
if (ISO_INSTANT.test(trimmed)) {
|
|
82
|
+
const instant = Date.parse(trimmed);
|
|
83
|
+
if (Number.isFinite(instant))
|
|
84
|
+
return new Date(instant).toISOString().toLowerCase();
|
|
85
|
+
}
|
|
86
|
+
return trimmed.toLowerCase();
|
|
87
|
+
}
|
|
67
88
|
/** Comparable form of a scalar. Non-scalars return undefined and are never compared. */
|
|
68
89
|
function normalize(value) {
|
|
69
90
|
if ('string' === typeof value)
|
|
70
|
-
return value
|
|
91
|
+
return normalizeString(value);
|
|
71
92
|
if ('number' === typeof value)
|
|
72
93
|
return Number.isFinite(value) ? String(value) : undefined;
|
|
73
94
|
if ('boolean' === typeof value)
|
|
@@ -105,6 +126,22 @@ function isVersionKey(key) {
|
|
|
105
126
|
'rev' === lower ||
|
|
106
127
|
'revision' === lower);
|
|
107
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Audit columns the server stamps with its own clock on every write. A client that sends one back
|
|
131
|
+
* (a PATCH of the whole record it read) is not asking for that value to be kept, and the changed
|
|
132
|
+
* value in the response is the proof the write applied — the same reasoning as a version token.
|
|
133
|
+
*/
|
|
134
|
+
const AUDIT_TIMESTAMP_KEYS = new Set([
|
|
135
|
+
'updated_at',
|
|
136
|
+
'updatedat',
|
|
137
|
+
'modified_at',
|
|
138
|
+
'modifiedat',
|
|
139
|
+
'last_modified',
|
|
140
|
+
'lastmodified',
|
|
141
|
+
]);
|
|
142
|
+
function isAuditTimestampKey(key) {
|
|
143
|
+
return AUDIT_TIMESTAMP_KEYS.has(key.toLowerCase());
|
|
144
|
+
}
|
|
108
145
|
/**
|
|
109
146
|
* Every scalar value the response carries for each key, at any depth.
|
|
110
147
|
*
|
|
@@ -289,6 +326,8 @@ export function findEchoMismatches(events, actionSince) {
|
|
|
289
326
|
continue;
|
|
290
327
|
if (isVersionKey(key))
|
|
291
328
|
continue;
|
|
329
|
+
if (isAuditTimestampKey(key))
|
|
330
|
+
continue;
|
|
292
331
|
const values = echoed.get(key);
|
|
293
332
|
// Not echoed at all = no evidence either way. Only a key the server chose to report back can
|
|
294
333
|
// contradict the request, and silence is not a contradiction.
|
|
@@ -129,6 +129,11 @@ function shows(text, value) {
|
|
|
129
129
|
const haystack = text.toLowerCase();
|
|
130
130
|
return renderedForms(value).some((form) => haystack.includes(form.toLowerCase()));
|
|
131
131
|
}
|
|
132
|
+
/** Whether the page shows this record at all: its id appears in the page's text. */
|
|
133
|
+
function onPage(entity, pageText) {
|
|
134
|
+
const id = entity['id'];
|
|
135
|
+
return ('string' === typeof id || 'number' === typeof id) && pageText.includes(String(id));
|
|
136
|
+
}
|
|
132
137
|
/**
|
|
133
138
|
* Compare entities against the page's rendered text.
|
|
134
139
|
*
|
|
@@ -142,8 +147,14 @@ export function reconcile(bodies, pageText) {
|
|
|
142
147
|
// Every value each state field took across the response set — used to tell "this value is simply
|
|
143
148
|
// not rendered anywhere" (uninteresting) from "a DIFFERENT value of this same field is rendered"
|
|
144
149
|
// (a mapping bug). Without that distinction the check would flag any field a UI chooses not to show.
|
|
150
|
+
//
|
|
151
|
+
// Built only from records the page shows. From every response in the session it mixed record
|
|
152
|
+
// types and pages: on a disputes page, a payment's "captured" made each dispute's status look
|
|
153
|
+
// misrendered, and twenty bogus findings led the report.
|
|
145
154
|
const vocabulary = new Map();
|
|
146
155
|
for (const entity of entities) {
|
|
156
|
+
if (!onPage(entity, pageText))
|
|
157
|
+
continue;
|
|
147
158
|
for (const [field, value] of Object.entries(entity)) {
|
|
148
159
|
if (!STATE_FIELDS.has(field) || typeof value !== 'string')
|
|
149
160
|
continue;
|
|
@@ -186,6 +197,10 @@ export function reconcile(bodies, pageText) {
|
|
|
186
197
|
});
|
|
187
198
|
}
|
|
188
199
|
}
|
|
200
|
+
// A record the page does not show cannot be shown wrongly: a filtered list, or another page's
|
|
201
|
+
// data still in the session, is not a misrendering.
|
|
202
|
+
if (!onPage(entity, pageText))
|
|
203
|
+
continue;
|
|
189
204
|
for (const [field, value] of Object.entries(entity)) {
|
|
190
205
|
if (!STATE_FIELDS.has(field) || typeof value !== 'string')
|
|
191
206
|
continue;
|
|
@@ -47,6 +47,35 @@ function differsOnlyByEnumeration(first, second) {
|
|
|
47
47
|
}
|
|
48
48
|
return differed;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Parameters that NAME a resource. Two reads differing in one of these fetch two different things
|
|
52
|
+
* (a tile grid's `?id=1` and `?id=2`), and neither answer can overwrite the other's view.
|
|
53
|
+
*/
|
|
54
|
+
const IDENTITY_PARAMS = new Set(['id', 'ids', 'uuid', 'slug', 'key']);
|
|
55
|
+
/**
|
|
56
|
+
* Issued this close together, two requests came from one task (a `Promise.all`, two effects in one
|
|
57
|
+
* commit), so no later intent superseded the first: they are a fan-out, not a race (#1225).
|
|
58
|
+
* ponytail: a time bound stands in for "same task", which the event stream does not carry. A slow
|
|
59
|
+
* commit can space its effects wider than this; carry an issuing-task id if that shows up.
|
|
60
|
+
*/
|
|
61
|
+
const SAME_TASK_MS = 2;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the second read could have made the first obsolete. Not when they ask for differently
|
|
64
|
+
* shaped answers (the key sets differ: a page of rows beside a count), not when they name different
|
|
65
|
+
* resources, and not when only enumeration changed.
|
|
66
|
+
*/
|
|
67
|
+
function couldSupersede(first, second) {
|
|
68
|
+
const a = new URLSearchParams(first);
|
|
69
|
+
const b = new URLSearchParams(second);
|
|
70
|
+
const keysA = [...new Set(a.keys())].sort().join('&');
|
|
71
|
+
const keysB = [...new Set(b.keys())].sort().join('&');
|
|
72
|
+
if (keysA !== keysB)
|
|
73
|
+
return false;
|
|
74
|
+
for (const key of IDENTITY_PARAMS)
|
|
75
|
+
if (a.get(key) !== b.get(key))
|
|
76
|
+
return false;
|
|
77
|
+
return !differsOnlyByEnumeration(first, second);
|
|
78
|
+
}
|
|
50
79
|
/** Pair NET_PENDING with its NET_REQUEST by the id both carry. Unpaired events are still in flight. */
|
|
51
80
|
function flights(events) {
|
|
52
81
|
const issued = new Map();
|
|
@@ -167,8 +196,9 @@ function raceIn(reads, events) {
|
|
|
167
196
|
continue; // settled in order — no race
|
|
168
197
|
if (queryOf(first.url) === queryOf(second.url))
|
|
169
198
|
continue; // a retry, not a superseding query
|
|
170
|
-
|
|
171
|
-
|
|
199
|
+
if (second.issuedAt - first.issuedAt < SAME_TASK_MS)
|
|
200
|
+
continue; // one task's fan-out
|
|
201
|
+
if (!couldSupersede(queryOf(first.url), queryOf(second.url)))
|
|
172
202
|
continue;
|
|
173
203
|
// The race happened. Whether it MATTERS is whether the app acted on the loser — an app that
|
|
174
204
|
// drops superseded responses races just as visibly and is not broken.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReticleEvent } from '@reticlehq/core';
|
|
1
|
+
import { type ExpectedLink, type ReticleEvent } from '@reticlehq/core';
|
|
2
2
|
/**
|
|
3
3
|
* Did a write in this window answer `202 Accepted`?
|
|
4
4
|
*
|
|
@@ -14,6 +14,30 @@ import { type ReticleEvent } from '@reticlehq/core';
|
|
|
14
14
|
* The DEV TOOLCHAIN's own traffic is excluded, on the same rule every other check applies: a verdict
|
|
15
15
|
* about the app must not be decided by a request the app did not make.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* What the caller knows about the claim, which a bare window scan cannot (#1120).
|
|
19
|
+
*
|
|
20
|
+
* The rule is right for the write the claim depends on and wrong for everything else that answered
|
|
21
|
+
* 202 in the same window. An analytics beacon made every verdict in the app `unknown`, and a claim
|
|
22
|
+
* that deliberately asserted "the POST returned 202 and accepted: true" could not say so. The
|
|
23
|
+
* filter lives here, at the evidence boundary, so both callers inherit it.
|
|
24
|
+
*
|
|
25
|
+
* Every field is optional: a caller with no page URL, no declared background and no proven links
|
|
26
|
+
* gets exactly the behaviour this function had before, which the older unit tests pin.
|
|
27
|
+
*/
|
|
28
|
+
export interface AcceptedWriteFilter {
|
|
29
|
+
/** The page under test. A 202 from another origin is not its outcome. */
|
|
30
|
+
readonly appUrl?: string | undefined;
|
|
31
|
+
/** Endpoints the project declared as background; their 202s are a heartbeat, not the action. */
|
|
32
|
+
readonly background?: readonly string[] | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The NET links the claim actually PROVED, from a green verdict only. A 202 a link names with
|
|
35
|
+
* `status: 202` is the claim's own acceptance: it held, and the global rule must not override it.
|
|
36
|
+
* On `anyOf` the proven list carries only the branch that won — a static scan of the predicate
|
|
37
|
+
* could exempt a 202 the verdict never rested on.
|
|
38
|
+
*/
|
|
39
|
+
readonly asserted?: readonly ExpectedLink[] | undefined;
|
|
40
|
+
}
|
|
17
41
|
/**
|
|
18
42
|
* Which writes in this window answered `202 Accepted`, as "METHOD url".
|
|
19
43
|
*
|
|
@@ -25,7 +49,7 @@ import { type ReticleEvent } from '@reticlehq/core';
|
|
|
25
49
|
* Duplicates are folded, so a retried request names its endpoint once instead of filling the
|
|
26
50
|
* sentence with the same line three times.
|
|
27
51
|
*/
|
|
28
|
-
export declare function acceptedWriteLabels(events: readonly ReticleEvent[]): string[];
|
|
52
|
+
export declare function acceptedWriteLabels(events: readonly ReticleEvent[], filter?: AcceptedWriteFilter): string[];
|
|
29
53
|
/**
|
|
30
54
|
* Did a write in this window answer `202 Accepted`?
|
|
31
55
|
*
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import { EventType, HTTP_ACCEPTED, isDevToolingUrl } from '@reticlehq/core';
|
|
1
|
+
import { ConsequenceKind, EventType, HTTP_ACCEPTED, MUTATING_METHODS, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
|
|
2
2
|
import { asNumber, asString } from '@reticlehq/core';
|
|
3
|
-
/**
|
|
4
|
-
* Did a write in this window answer `202 Accepted`?
|
|
5
|
-
*
|
|
6
|
-
* `202` is the only status in HTTP whose meaning is "no outcome yet" — the server took the request
|
|
7
|
-
* and has not finished with it. Folding it into the 2xx success band is how an asynchronous workflow
|
|
8
|
-
* gets a green verdict at exactly the moment nothing has been decided.
|
|
9
|
-
*
|
|
10
|
-
* Measured on a logistics console with server-side reconciliation: a dispatch answered 202, the row
|
|
11
|
-
* optimistically rendered "dispatched", the page settled, every channel agreed — and the server
|
|
12
|
-
* REVERTED it to `held` 1.2 s later. The verdict was not wrong about what it observed. It was early,
|
|
13
|
-
* and nothing in the response said so except the status code nobody was reading.
|
|
14
|
-
*
|
|
15
|
-
* The DEV TOOLCHAIN's own traffic is excluded, on the same rule every other check applies: a verdict
|
|
16
|
-
* about the app must not be decided by a request the app did not make.
|
|
17
|
-
*/
|
|
18
3
|
/**
|
|
19
4
|
* Which writes in this window answered `202 Accepted`, as "METHOD url".
|
|
20
5
|
*
|
|
@@ -26,23 +11,55 @@ import { asNumber, asString } from '@reticlehq/core';
|
|
|
26
11
|
* Duplicates are folded, so a retried request names its endpoint once instead of filling the
|
|
27
12
|
* sentence with the same line three times.
|
|
28
13
|
*/
|
|
29
|
-
export function acceptedWriteLabels(events) {
|
|
14
|
+
export function acceptedWriteLabels(events, filter = {}) {
|
|
30
15
|
const labels = [];
|
|
31
16
|
for (const event of events) {
|
|
32
17
|
if (event.type !== EventType.NET_REQUEST)
|
|
33
18
|
continue;
|
|
34
19
|
if (asNumber(event.data['status']) !== HTTP_ACCEPTED)
|
|
35
20
|
continue;
|
|
21
|
+
const method = ('string' === typeof event.data['method'] ? event.data['method'] : '').toUpperCase();
|
|
22
|
+
// A read has no outcome to reconcile: a 202 on one is a poll or a prefetch.
|
|
23
|
+
if (!MUTATING_METHODS.includes(method))
|
|
24
|
+
continue;
|
|
36
25
|
const url = asString(event.data['url']);
|
|
37
26
|
if (isDevToolingUrl(url))
|
|
38
27
|
continue;
|
|
39
|
-
|
|
28
|
+
// The same split `splitForeignTraffic` makes for every other rule: somebody else's origin, or
|
|
29
|
+
// an endpoint the project itself declared as background, is not the app's work under test.
|
|
30
|
+
if (isForeignTraffic(url, filter.appUrl, filter.background ?? []))
|
|
31
|
+
continue;
|
|
32
|
+
if (isAssertedAcceptance(method, urlForMatch(event.data), filter.asserted))
|
|
33
|
+
continue;
|
|
40
34
|
const label = `${method} ${url ?? ''}`.trim();
|
|
41
35
|
if ('' !== label && !labels.includes(label))
|
|
42
36
|
labels.push(label);
|
|
43
37
|
}
|
|
44
38
|
return labels;
|
|
45
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Did the claim's OWN proven evidence settle this exact request?
|
|
42
|
+
*
|
|
43
|
+
* For the request to be exempt, EVERY proven link that names it must assert `status: 202`. One link
|
|
44
|
+
* that names the same URL with another status — a 200 branch of an `anyOf` that also held, or a
|
|
45
|
+
* presence-only clause — means the verdict could have been green without this acceptance, and the
|
|
46
|
+
* accepted write's outcome is still owed. Method is matched when the link carries one, so a claim
|
|
47
|
+
* about `GET /save` cannot exempt the pending `POST /save`.
|
|
48
|
+
*
|
|
49
|
+
* `urlForMatch` and not `url`: a predicate matches the raw path, and redaction rewrites some public
|
|
50
|
+
* REST paths, so matching the displayed URL would drop the exemption for exactly the calls a
|
|
51
|
+
* predicate can still name.
|
|
52
|
+
*/
|
|
53
|
+
function isAssertedAcceptance(method, url, asserted) {
|
|
54
|
+
if (asserted === undefined)
|
|
55
|
+
return false;
|
|
56
|
+
const naming = asserted.filter((link) => ConsequenceKind.NET === link.kind &&
|
|
57
|
+
link.urlContains !== undefined &&
|
|
58
|
+
url.includes(link.urlContains) &&
|
|
59
|
+
(link.method === undefined || link.method.toUpperCase() === method));
|
|
60
|
+
return (naming.length > 0 &&
|
|
61
|
+
naming.every((link) => ConsequenceKind.NET === link.kind && HTTP_ACCEPTED === link.status));
|
|
62
|
+
}
|
|
46
63
|
/**
|
|
47
64
|
* Did a write in this window answer `202 Accepted`?
|
|
48
65
|
*
|
|
@@ -14,3 +14,14 @@ export declare function readsDomState(predicate: Predicate): boolean;
|
|
|
14
14
|
* one visible match among several is a fair, ordinary read and is left alone.
|
|
15
15
|
*/
|
|
16
16
|
export declare function alreadyTrueHiddenMatch(predicate: Predicate, evidence: unknown): boolean;
|
|
17
|
+
/** What a green resting on hidden matches says instead of `yes`. See `hiddenMatchNote`. */
|
|
18
|
+
export declare const HIDDEN_MATCH_NOTE: string;
|
|
19
|
+
/**
|
|
20
|
+
* #1408: the post-action half of `alreadyTrueHiddenMatch`. A `text` clause beside a `net` clause is
|
|
21
|
+
* never already true, so a success template still hidden in the DOM passed with no caveat at all.
|
|
22
|
+
* Returns the note when any clause the green rests on matched only hidden elements.
|
|
23
|
+
*
|
|
24
|
+
* `evidence` is the passing result's: an `allOf` carries one entry per clause, in order, and an
|
|
25
|
+
* `anyOf` carries only the branch that held, which is why each branch is tried against it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function hiddenMatchNote(predicate: Predicate, evidence: unknown): string | undefined;
|
|
@@ -98,3 +98,30 @@ export function alreadyTrueHiddenMatch(predicate, evidence) {
|
|
|
98
98
|
return false;
|
|
99
99
|
return evidence.every((el) => !el.visible);
|
|
100
100
|
}
|
|
101
|
+
/** What a green resting on hidden matches says instead of `yes`. See `hiddenMatchNote`. */
|
|
102
|
+
export const HIDDEN_MATCH_NOTE = 'the declared consequence held only on a hidden element: a text or element check matches DOM ' +
|
|
103
|
+
'presence, not visibility, by default, so nothing here shows it is on screen. Add `visible: true` ' +
|
|
104
|
+
'if you meant "this is showing", not merely "this exists"';
|
|
105
|
+
/**
|
|
106
|
+
* #1408: the post-action half of `alreadyTrueHiddenMatch`. A `text` clause beside a `net` clause is
|
|
107
|
+
* never already true, so a success template still hidden in the DOM passed with no caveat at all.
|
|
108
|
+
* Returns the note when any clause the green rests on matched only hidden elements.
|
|
109
|
+
*
|
|
110
|
+
* `evidence` is the passing result's: an `allOf` carries one entry per clause, in order, and an
|
|
111
|
+
* `anyOf` carries only the branch that held, which is why each branch is tried against it.
|
|
112
|
+
*/
|
|
113
|
+
export function hiddenMatchNote(predicate, evidence) {
|
|
114
|
+
return restsOnHiddenMatch(predicate, evidence) ? HIDDEN_MATCH_NOTE : undefined;
|
|
115
|
+
}
|
|
116
|
+
function restsOnHiddenMatch(predicate, evidence) {
|
|
117
|
+
if (PredicateKind.ALL_OF === predicate.kind) {
|
|
118
|
+
if (!Array.isArray(evidence))
|
|
119
|
+
return false;
|
|
120
|
+
const each = evidence;
|
|
121
|
+
return predicate.predicates.some((clause, i) => restsOnHiddenMatch(clause, each[i]));
|
|
122
|
+
}
|
|
123
|
+
if (PredicateKind.ANY_OF === predicate.kind) {
|
|
124
|
+
return predicate.predicates.some((clause) => restsOnHiddenMatch(clause, evidence));
|
|
125
|
+
}
|
|
126
|
+
return alreadyTrueHiddenMatch(predicate, evidence);
|
|
127
|
+
}
|
|
@@ -22,6 +22,16 @@ export declare const BODY_CAPTURE_MIN_VERSION = "2.4.0";
|
|
|
22
22
|
* one wasted read. The asymmetry decides it.
|
|
23
23
|
*/
|
|
24
24
|
export declare function bodyCaptureRemedy(sdkVersion: string | undefined): string;
|
|
25
|
+
/**
|
|
26
|
+
* The invariant opening of the refusal below, named so the error envelope can recognise it.
|
|
27
|
+
*
|
|
28
|
+
* The refusal's TAIL is the remedy, and there are two of those — switch the setting on, or upgrade
|
|
29
|
+
* an SDK too old to have it — so the opening is the only text both shapes share. The envelope's
|
|
30
|
+
* self-recovering table keys on phrasing, and a reword here with the phrasing retyped over there
|
|
31
|
+
* would silently unmap the refusal and put the "may be a defect in Reticle" ask back on a message
|
|
32
|
+
* that already names the fix.
|
|
33
|
+
*/
|
|
34
|
+
export declare const BODY_CLAUSE_REFUSAL_OPENING = "this assertion reads a request/response BODY, and this session is not recording them";
|
|
25
35
|
/**
|
|
26
36
|
* Refuse a body clause the session cannot answer, BEFORE the action is spent.
|
|
27
37
|
*
|
|
@@ -40,7 +40,10 @@ function isAtLeast(version, minimum) {
|
|
|
40
40
|
/** The sentence naming the setting — only ever produced for an SDK that HAS it. */
|
|
41
41
|
const ENABLE_IT = 'Turn it on where your app calls connect(): `reticle.connect({ captureNetworkBodies: true })`, ' +
|
|
42
42
|
'or for the Vite plugin `reticle({ captureNetworkBodies: true })` / VITE_RETICLE_CAPTURE_BODIES=1. ' +
|
|
43
|
-
'
|
|
43
|
+
'Before bodies are kept, built-in rules redact keys such as `password`, `apiKey` and ' +
|
|
44
|
+
'`authorization`, selected token keys, and known secret shapes. Other credential fields may ' +
|
|
45
|
+
'remain; add their names with `redact.keys` and use staging. See ' +
|
|
46
|
+
'https://docs.reticle.sh/what-is-recorded for the limits. Then re-run the action.';
|
|
44
47
|
/**
|
|
45
48
|
* The remedy for this session, or the honest statement that there is none.
|
|
46
49
|
*
|
|
@@ -77,6 +80,16 @@ function asksAboutBody(predicate) {
|
|
|
77
80
|
return nested.some(asksAboutBody);
|
|
78
81
|
return asksAboutBody(nested);
|
|
79
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The invariant opening of the refusal below, named so the error envelope can recognise it.
|
|
85
|
+
*
|
|
86
|
+
* The refusal's TAIL is the remedy, and there are two of those — switch the setting on, or upgrade
|
|
87
|
+
* an SDK too old to have it — so the opening is the only text both shapes share. The envelope's
|
|
88
|
+
* self-recovering table keys on phrasing, and a reword here with the phrasing retyped over there
|
|
89
|
+
* would silently unmap the refusal and put the "may be a defect in Reticle" ask back on a message
|
|
90
|
+
* that already names the fix.
|
|
91
|
+
*/
|
|
92
|
+
export const BODY_CLAUSE_REFUSAL_OPENING = 'this assertion reads a request/response BODY, and this session is not recording them';
|
|
80
93
|
/**
|
|
81
94
|
* Refuse a body clause the session cannot answer, BEFORE the action is spent.
|
|
82
95
|
*
|
|
@@ -96,6 +109,6 @@ export function bodyClauseRefusal(predicate, session) {
|
|
|
96
109
|
return undefined;
|
|
97
110
|
if (!asksAboutBody(predicate))
|
|
98
111
|
return undefined;
|
|
99
|
-
return (
|
|
112
|
+
return (`${BODY_CLAUSE_REFUSAL_OPENING} — it ` +
|
|
100
113
|
`would fail whatever the app did. Nothing ran, so no action was spent. ${bodyCaptureRemedy(session.sdkVersion)}`);
|
|
101
114
|
}
|
|
@@ -148,6 +148,8 @@ interface VerifiedInputs {
|
|
|
148
148
|
unsettled?: UnsettledWindow;
|
|
149
149
|
/** A passing absence assertion targeted a region that the current capture could not observe. */
|
|
150
150
|
absenceBlindSpot?: string;
|
|
151
|
+
/** The green rested on matches that are all hidden; the sentence that says so. See `hiddenMatchNote`. */
|
|
152
|
+
hiddenMatch?: string;
|
|
151
153
|
}
|
|
152
154
|
interface VerifiedVerdict {
|
|
153
155
|
verified: Verified;
|
|
@@ -297,6 +297,16 @@ export function decideVerified(inputs) {
|
|
|
297
297
|
: ''),
|
|
298
298
|
};
|
|
299
299
|
}
|
|
300
|
+
// A green whose text or element clause matched only hidden nodes says the node exists, not that it
|
|
301
|
+
// is showing (#1408). UNKNOWN, not NO: the node may be hidden by design and the caller asked only
|
|
302
|
+
// for presence.
|
|
303
|
+
if (true === pass && inputs.hiddenMatch !== undefined) {
|
|
304
|
+
return {
|
|
305
|
+
verified: Verified.UNKNOWN,
|
|
306
|
+
verifiedReason: VerifiedReason.HIDDEN_MATCH,
|
|
307
|
+
because: inputs.hiddenMatch,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
300
310
|
// Dirty capture is NOT failure. The layer could not see part of the window, so any green is a
|
|
301
311
|
// statement about what it happened to observe — which is precisely the thing that must not be
|
|
302
312
|
// reported as proof.
|
|
@@ -52,10 +52,10 @@ export declare function declaredExpectations(predicate: Predicate | undefined):
|
|
|
52
52
|
* verdict (measured: a 201 plus the unique row, unread body, agent went to enable capture instead
|
|
53
53
|
* of finishing the drive).
|
|
54
54
|
*
|
|
55
|
-
* Same conservatism as `declaredExpectations`: only the top level and `allOf
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
55
|
+
* Same conservatism as `declaredExpectations`: only the top level and `allOf`, plus an `anyOf` whose
|
|
56
|
+
* every branch is body-independent. An `anyOf` with a net branch may have held on that branch alone,
|
|
57
|
+
* so it must not skip the unread caveat. An `absent` element is not a consequence the body cannot
|
|
58
|
+
* own.
|
|
59
59
|
*/
|
|
60
60
|
export declare function declaresBodyIndependentChannel(predicate: Predicate | undefined): boolean;
|
|
61
61
|
/**
|