@reticlehq/engine 3.5.0 → 3.7.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 +73 -1
- package/dist/disagreement/contradiction-evidence.js +154 -6
- package/dist/disagreement/contradiction-types.d.ts +8 -1
- package/dist/disagreement/contradictions.d.ts +17 -1
- package/dist/disagreement/contradictions.js +111 -38
- package/dist/disagreement/echo-mismatch.js +42 -3
- package/dist/disagreement/reconcile.js +15 -0
- package/dist/disagreement/stale-response.js +37 -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 +16 -0
- package/dist/evidence/already-true.js +48 -0
- package/dist/evidence/baseline.js +2 -6
- package/dist/evidence/blind-spots.d.ts +14 -3
- package/dist/evidence/blind-spots.js +48 -10
- package/dist/evidence/body-capture-remedy.d.ts +10 -0
- package/dist/evidence/body-capture-remedy.js +15 -2
- package/dist/evidence/instrumentation-gaps.js +3 -1
- package/dist/evidence/state-bookkeeping.d.ts +2 -0
- package/dist/evidence/state-bookkeeping.js +2 -0
- package/dist/evidence/superseded-checks.d.ts +29 -0
- package/dist/evidence/superseded-checks.js +30 -0
- package/dist/evidence/unsettled.js +4 -2
- package/dist/evidence/verified.d.ts +8 -1
- package/dist/evidence/verified.js +42 -4
- package/dist/question/declared.d.ts +24 -4
- package/dist/question/declared.js +26 -5
- 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/net-blind-spots.d.ts +49 -0
- package/dist/question/predicate/net-blind-spots.js +153 -0
- package/dist/question/predicate/predicate-compare.js +13 -4
- package/dist/question/predicate/predicate-element.d.ts +15 -1
- package/dist/question/predicate/predicate-element.js +108 -7
- package/dist/question/predicate/predicate-eval-kit.d.ts +25 -0
- package/dist/question/predicate/predicate-eval-kit.js +31 -0
- package/dist/question/predicate/predicate-eval.d.ts +17 -2
- package/dist/question/predicate/predicate-eval.js +117 -180
- package/dist/question/predicate/predicate-parse.js +153 -13
- package/dist/question/predicate/predicate-request-body.d.ts +6 -1
- package/dist/question/predicate/predicate-request-body.js +7 -2
- package/dist/question/predicate/predicate-route.d.ts +2 -0
- package/dist/question/predicate/predicate-route.js +30 -0
- package/dist/question/predicate/predicate-schema.d.ts +11 -0
- package/dist/question/predicate/predicate-schema.js +110 -24
- package/dist/question/predicate/predicate-session.d.ts +10 -0
- package/dist/question/predicate/predicate-state.js +7 -0
- package/dist/question/predicate/predicate-to-links.js +1 -0
- package/dist/question/predicate/predicate.js +76 -25
- package/dist/question/predicate/split-text-miss.d.ts +6 -0
- package/dist/question/predicate/split-text-miss.js +10 -0
- package/dist/question/reaction.d.ts +1 -1
- package/dist/question/reaction.js +1 -1
- package/dist/state-bookkeeping.d.ts +25 -0
- package/dist/state-bookkeeping.js +70 -0
- 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. */
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Split out of `contradictions.ts` when that file crossed the line cap — and the seam was already
|
|
5
5
|
* there rather than invented for the occasion. Everything here answers a question ABOUT NETWORK
|
|
6
6
|
* EVIDENCE: what did this event mean, was it a write, did a retry rescue it, is it the toolchain's
|
|
7
|
-
* own traffic rather than the app's, is this cadence a poll
|
|
7
|
+
* own traffic rather than the app's, is this cadence a poll, what did a write carry, which page did
|
|
8
|
+
* a list request ask for, and which `net` clause would name this call. Nothing here knows what a
|
|
8
9
|
* contradiction is.
|
|
9
10
|
*
|
|
10
11
|
* The rules next door read this vocabulary and decide what disagrees. Keeping the two apart means a
|
|
@@ -66,6 +67,14 @@ export declare function hrefAsUrl(value: string | undefined): URL | undefined;
|
|
|
66
67
|
* Returns false when `from`/`to` are missing, so older events without hrefs keep the existing rule.
|
|
67
68
|
*/
|
|
68
69
|
export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* A `replaceState` that keeps the pathname recorded state in the URL. It is not a navigation.
|
|
72
|
+
*
|
|
73
|
+
* Search and an in-page fragment may change (`?zoom=125`, `#main-content`). A hash-router fragment
|
|
74
|
+
* (`#/invoices`) is still a new view, and so is a replace onto a different pathname. Missing hrefs
|
|
75
|
+
* stay under the blank-destination rule: an event that cannot show the path stayed put is not exempt.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isSamePathnameReplace(event: ReticleEvent): boolean;
|
|
69
78
|
/**
|
|
70
79
|
* Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
|
|
71
80
|
*
|
|
@@ -75,6 +84,13 @@ export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
|
|
|
75
84
|
* over a request that never settled". Every app that logs one dev warning got a false negative on
|
|
76
85
|
* every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
|
|
77
86
|
* which is why the split happens ONCE here rather than in the one check that reported it.
|
|
87
|
+
*
|
|
88
|
+
* CLASSIFY on `urlForMatch`, DISCLOSE `url`. Redaction rewrites a sensitive path segment at emit
|
|
89
|
+
* time (`/verify/refresh-token` -> `/verify/[REDACTED]`) and keeps the original only in `urlRaw`, so
|
|
90
|
+
* a project's DECLARED `background` pattern — matched with `String.includes` — never matched what
|
|
91
|
+
* this read. The endpoint went back in among the app's own traffic and every rule below judged it,
|
|
92
|
+
* which is the half of the same defect the settle wait had. Disclosure deliberately keeps the
|
|
93
|
+
* DISPLAYED spelling: the raw one is the match haystack, not something to project into a transcript.
|
|
78
94
|
*/
|
|
79
95
|
export declare function splitForeignTraffic(events: readonly ReticleEvent[], appOrigin: string | undefined, background?: readonly string[]): {
|
|
80
96
|
app: readonly ReticleEvent[];
|
|
@@ -120,3 +136,59 @@ export declare const POLL_JITTER_RATIO = 0.4;
|
|
|
120
136
|
* apart they are, which is the classic double submit and every case this rule was written for.
|
|
121
137
|
*/
|
|
122
138
|
export declare function isSteadyCadence(times: readonly number[]): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* What this request CARRIED, as far as the record knows — `undefined` when it does not know.
|
|
141
|
+
*
|
|
142
|
+
* The page's shape fingerprint first: it is present on every request from an instrumented page,
|
|
143
|
+
* including the overwhelming majority where body capture is off. A captured body is the fallback for
|
|
144
|
+
* a realm that records one without a fingerprint (desktop IPC). Neither means the record does not
|
|
145
|
+
* say what this request carried — a body the page could not read as text, or an SDK too old to
|
|
146
|
+
* compute a fingerprint — and that is an ABSENCE of identity, not an identity shared with every
|
|
147
|
+
* other silent request.
|
|
148
|
+
*
|
|
149
|
+
* A Server Action's action id joins both halves, and it is the half that survives a `FormData`
|
|
150
|
+
* body: several actions POST to the page's own URL, so without it every call is an unknown identity
|
|
151
|
+
* pooled with all the others, and no fingerprint can separate two that share a shape. The id alone
|
|
152
|
+
* SPLITS two different actions; it cannot say that two runs of one action carried the same thing,
|
|
153
|
+
* and `carried` keeps that limit on the record for the finding to say.
|
|
154
|
+
*/
|
|
155
|
+
export interface WriteIdentity {
|
|
156
|
+
/** The value the grouping compares. */
|
|
157
|
+
readonly key: string;
|
|
158
|
+
/** Whether the key also describes WHAT the request carried, not only which action ran. */
|
|
159
|
+
readonly carried: boolean;
|
|
160
|
+
}
|
|
161
|
+
export declare function identityOf(event: ReticleEvent): WriteIdentity | undefined;
|
|
162
|
+
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
163
|
+
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
164
|
+
export declare function groupByIdentity<T extends {
|
|
165
|
+
identity: WriteIdentity | undefined;
|
|
166
|
+
}>(calls: readonly T[]): T[][];
|
|
167
|
+
/**
|
|
168
|
+
* The `net` clause that declares each of these failures, worded as a condition.
|
|
169
|
+
*
|
|
170
|
+
* A designed error path (a 402 paywall, a 429, a 428 confirmation) asserted through the UI it renders
|
|
171
|
+
* gets `ui-advanced-request-failed`, and declaring the failing call in the oracle is what exempts it
|
|
172
|
+
* (`matchesDeclaredFailure`). Nothing in the finding said so, so agents dropped the check or
|
|
173
|
+
* weakened it until it proved nothing (#1418). The clause is built from the call itself, so it is
|
|
174
|
+
* exactly what would match, and it is conditional: the finding is still a finding, and a clause
|
|
175
|
+
* pasted to make a red go away would be the same false green with extra steps.
|
|
176
|
+
*
|
|
177
|
+
* Built from the DISPLAY url, which is redacted, never from `matchUrl`, which is not: the detail is
|
|
178
|
+
* copied into crawl anomalies, and a hint must not put back a token the description took out. A
|
|
179
|
+
* call whose path cannot be named exactly and narrowly gets no clause rather than a loose one: a
|
|
180
|
+
* bare `/` is a substring of every url and would exempt unrelated failures with the same method.
|
|
181
|
+
*/
|
|
182
|
+
export declare function declareFailureHint(calls: readonly {
|
|
183
|
+
method: string;
|
|
184
|
+
url: string;
|
|
185
|
+
matchUrl?: string;
|
|
186
|
+
status: number | undefined;
|
|
187
|
+
}[]): string;
|
|
188
|
+
export declare function pageNumber(text: unknown): number | undefined;
|
|
189
|
+
/** The endpoint and its page parameter, for a GET that carries one. */
|
|
190
|
+
export declare function pageRequest(event: ReticleEvent): {
|
|
191
|
+
path: string;
|
|
192
|
+
param: string;
|
|
193
|
+
value: string;
|
|
194
|
+
} | undefined;
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
* Split out of `contradictions.ts` when that file crossed the line cap — and the seam was already
|
|
5
5
|
* there rather than invented for the occasion. Everything here answers a question ABOUT NETWORK
|
|
6
6
|
* EVIDENCE: what did this event mean, was it a write, did a retry rescue it, is it the toolchain's
|
|
7
|
-
* own traffic rather than the app's, is this cadence a poll
|
|
7
|
+
* own traffic rather than the app's, is this cadence a poll, what did a write carry, which page did
|
|
8
|
+
* a list request ask for, and which `net` clause would name this call. Nothing here knows what a
|
|
8
9
|
* contradiction is.
|
|
9
10
|
*
|
|
10
11
|
* The rules next door read this vocabulary and decide what disagrees. Keeping the two apart means a
|
|
11
12
|
* new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
|
|
12
13
|
* rules end up disagreeing about the same window.
|
|
13
14
|
*/
|
|
14
|
-
import { EventType, MUTATING_METHODS, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
|
|
15
|
+
import { EventType, MUTATING_METHODS, NEXT_ACTION_FIELD, PredicateKind, REQUEST_SHAPE_FIELD, ROUTE_CHANGE_HOW_FIELD, RouteChangeHow, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
|
|
15
16
|
export function netCall(e) {
|
|
16
17
|
const status = asNumber(e.data['status']);
|
|
17
18
|
return {
|
|
@@ -114,6 +115,28 @@ export function isSameDocumentHashAnchor(event) {
|
|
|
114
115
|
return false;
|
|
115
116
|
return isInPageFragment(to.hash);
|
|
116
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* A `replaceState` that keeps the pathname recorded state in the URL. It is not a navigation.
|
|
120
|
+
*
|
|
121
|
+
* Search and an in-page fragment may change (`?zoom=125`, `#main-content`). A hash-router fragment
|
|
122
|
+
* (`#/invoices`) is still a new view, and so is a replace onto a different pathname. Missing hrefs
|
|
123
|
+
* stay under the blank-destination rule: an event that cannot show the path stayed put is not exempt.
|
|
124
|
+
*/
|
|
125
|
+
export function isSamePathnameReplace(event) {
|
|
126
|
+
if (event.type !== EventType.ROUTE_CHANGE)
|
|
127
|
+
return false;
|
|
128
|
+
if (asString(event.data[ROUTE_CHANGE_HOW_FIELD]) !== RouteChangeHow.REPLACE)
|
|
129
|
+
return false;
|
|
130
|
+
const from = hrefAsUrl(asString(event.data['from']));
|
|
131
|
+
const to = hrefAsUrl(asString(event.data['to']));
|
|
132
|
+
if (from === undefined || to === undefined)
|
|
133
|
+
return false;
|
|
134
|
+
if (from.origin !== to.origin || from.pathname !== to.pathname)
|
|
135
|
+
return false;
|
|
136
|
+
if (from.hash !== to.hash && !isInPageFragment(to.hash))
|
|
137
|
+
return false;
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
117
140
|
/**
|
|
118
141
|
* Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
|
|
119
142
|
*
|
|
@@ -123,19 +146,28 @@ export function isSameDocumentHashAnchor(event) {
|
|
|
123
146
|
* over a request that never settled". Every app that logs one dev warning got a false negative on
|
|
124
147
|
* every action. The overlay's own 404s and duplicate fetches are the same story on other checks,
|
|
125
148
|
* which is why the split happens ONCE here rather than in the one check that reported it.
|
|
149
|
+
*
|
|
150
|
+
* CLASSIFY on `urlForMatch`, DISCLOSE `url`. Redaction rewrites a sensitive path segment at emit
|
|
151
|
+
* time (`/verify/refresh-token` -> `/verify/[REDACTED]`) and keeps the original only in `urlRaw`, so
|
|
152
|
+
* a project's DECLARED `background` pattern — matched with `String.includes` — never matched what
|
|
153
|
+
* this read. The endpoint went back in among the app's own traffic and every rule below judged it,
|
|
154
|
+
* which is the half of the same defect the settle wait had. Disclosure deliberately keeps the
|
|
155
|
+
* DISPLAYED spelling: the raw one is the match haystack, not something to project into a transcript.
|
|
126
156
|
*/
|
|
127
157
|
export function splitForeignTraffic(events, appOrigin, background = []) {
|
|
128
158
|
const ignored = [];
|
|
129
159
|
const app = events.filter((e) => {
|
|
130
160
|
if (!NET_TYPES.has(e.type))
|
|
131
161
|
return true;
|
|
132
|
-
const
|
|
162
|
+
const matchUrl = urlForMatch(e.data);
|
|
163
|
+
const shown = asString(e.data['url']);
|
|
133
164
|
// Somebody else's code, twice over: the toolchain's own channel, and any site that is not the
|
|
134
165
|
// app under test. Neither can answer the question every rule below asks.
|
|
135
|
-
|
|
166
|
+
const match = 0 === matchUrl.length ? undefined : matchUrl;
|
|
167
|
+
if (!isDevToolingUrl(match) && !isForeignTraffic(match, appOrigin, background))
|
|
136
168
|
return true;
|
|
137
|
-
if (
|
|
138
|
-
ignored.push(
|
|
169
|
+
if (shown !== undefined && !ignored.includes(shown))
|
|
170
|
+
ignored.push(shown);
|
|
139
171
|
return false;
|
|
140
172
|
});
|
|
141
173
|
return { app, ignored };
|
|
@@ -192,3 +224,119 @@ export function isSteadyCadence(times) {
|
|
|
192
224
|
return false;
|
|
193
225
|
return gaps.every((gap) => Math.abs(gap - median) <= median * POLL_JITTER_RATIO);
|
|
194
226
|
}
|
|
227
|
+
export function identityOf(event) {
|
|
228
|
+
const action = asString(event.data[NEXT_ACTION_FIELD]);
|
|
229
|
+
const shape = asString(event.data[REQUEST_SHAPE_FIELD]);
|
|
230
|
+
const body = asString(event.data['requestBody']);
|
|
231
|
+
const carried = shape !== undefined && 0 !== shape.length
|
|
232
|
+
? shape
|
|
233
|
+
: body === undefined || 0 === body.length
|
|
234
|
+
? undefined
|
|
235
|
+
: body;
|
|
236
|
+
if (action === undefined || 0 === action.length) {
|
|
237
|
+
return carried === undefined ? undefined : { key: carried, carried: true };
|
|
238
|
+
}
|
|
239
|
+
return carried === undefined
|
|
240
|
+
? { key: action, carried: false }
|
|
241
|
+
: { key: `${action}:${carried}`, carried: true };
|
|
242
|
+
}
|
|
243
|
+
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
244
|
+
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
245
|
+
export function groupByIdentity(calls) {
|
|
246
|
+
const byIdentity = new Map();
|
|
247
|
+
for (const call of calls) {
|
|
248
|
+
const key = call.identity?.key ?? '';
|
|
249
|
+
byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
|
|
250
|
+
}
|
|
251
|
+
return [...byIdentity.values()];
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The `net` clause that declares each of these failures, worded as a condition.
|
|
255
|
+
*
|
|
256
|
+
* A designed error path (a 402 paywall, a 429, a 428 confirmation) asserted through the UI it renders
|
|
257
|
+
* gets `ui-advanced-request-failed`, and declaring the failing call in the oracle is what exempts it
|
|
258
|
+
* (`matchesDeclaredFailure`). Nothing in the finding said so, so agents dropped the check or
|
|
259
|
+
* weakened it until it proved nothing (#1418). The clause is built from the call itself, so it is
|
|
260
|
+
* exactly what would match, and it is conditional: the finding is still a finding, and a clause
|
|
261
|
+
* pasted to make a red go away would be the same false green with extra steps.
|
|
262
|
+
*
|
|
263
|
+
* Built from the DISPLAY url, which is redacted, never from `matchUrl`, which is not: the detail is
|
|
264
|
+
* copied into crawl anomalies, and a hint must not put back a token the description took out. A
|
|
265
|
+
* call whose path cannot be named exactly and narrowly gets no clause rather than a loose one: a
|
|
266
|
+
* bare `/` is a substring of every url and would exempt unrelated failures with the same method.
|
|
267
|
+
*/
|
|
268
|
+
export function declareFailureHint(calls) {
|
|
269
|
+
const clauses = calls.flatMap((c) => {
|
|
270
|
+
const urlContains = narrowPathOf(c);
|
|
271
|
+
if (urlContains === undefined)
|
|
272
|
+
return [];
|
|
273
|
+
const clause = {
|
|
274
|
+
kind: PredicateKind.NET,
|
|
275
|
+
method: c.method.toUpperCase(),
|
|
276
|
+
urlContains,
|
|
277
|
+
...(c.status === undefined || 0 === c.status ? { ok: false } : { status: c.status }),
|
|
278
|
+
};
|
|
279
|
+
return [JSON.stringify(clause)];
|
|
280
|
+
});
|
|
281
|
+
if (0 === clauses.length)
|
|
282
|
+
return '';
|
|
283
|
+
const subject = 1 === clauses.length ? 'this failure is' : 'these failures are';
|
|
284
|
+
return `. If ${subject} the outcome you expect, declare it in the predicate: ${clauses.join(', ')}`;
|
|
285
|
+
}
|
|
286
|
+
/** Resolves a relative call url so its path can be read; the host is never shown or matched. */
|
|
287
|
+
const RELATIVE_URL_BASE = 'http://reticle.invalid';
|
|
288
|
+
/**
|
|
289
|
+
* The display url's path, when it is both safe to show and narrow enough to declare one call.
|
|
290
|
+
*
|
|
291
|
+
* Only when it is literally in the url the declaration is matched against: `urlContains` is a
|
|
292
|
+
* substring test, so a path the parser re-encoded, or one the redaction changed, would never match.
|
|
293
|
+
*/
|
|
294
|
+
function narrowPathOf(call) {
|
|
295
|
+
let path;
|
|
296
|
+
try {
|
|
297
|
+
path = new URL(call.url, RELATIVE_URL_BASE).pathname;
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
if (0 === path.replace(/\/+$/, '').length)
|
|
303
|
+
return undefined;
|
|
304
|
+
if (!call.url.includes(path) || !(call.matchUrl ?? call.url).includes(path))
|
|
305
|
+
return undefined;
|
|
306
|
+
return path;
|
|
307
|
+
}
|
|
308
|
+
/** Query parameters that say which page of a list is being asked for. */
|
|
309
|
+
const PAGE_PARAMS = ['page', 'offset', 'cursor', 'after', 'start', 'skip', 'from'];
|
|
310
|
+
/** "Page 2", "page 2 of 6", "2 / 6", "2 of 6". */
|
|
311
|
+
const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+\b/i;
|
|
312
|
+
export function pageNumber(text) {
|
|
313
|
+
if ('string' !== typeof text)
|
|
314
|
+
return undefined;
|
|
315
|
+
const match = PAGE_LABEL.exec(text);
|
|
316
|
+
const raw = match?.[1] ?? match?.[2];
|
|
317
|
+
return raw === undefined ? undefined : Number(raw);
|
|
318
|
+
}
|
|
319
|
+
/** The endpoint and its page parameter, for a GET that carries one. */
|
|
320
|
+
export function pageRequest(event) {
|
|
321
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
322
|
+
return undefined;
|
|
323
|
+
const method = event.data['method'];
|
|
324
|
+
if ('string' !== typeof method || 'GET' !== method.toUpperCase())
|
|
325
|
+
return undefined;
|
|
326
|
+
const raw = event.data['url'];
|
|
327
|
+
if ('string' !== typeof raw)
|
|
328
|
+
return undefined;
|
|
329
|
+
let url;
|
|
330
|
+
try {
|
|
331
|
+
url = new URL(raw, 'http://app.invalid');
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
for (const param of PAGE_PARAMS) {
|
|
337
|
+
const value = url.searchParams.get(param);
|
|
338
|
+
if (value !== null)
|
|
339
|
+
return { path: url.pathname, param, value };
|
|
340
|
+
}
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Contradiction, ContradictionKind, ReticleEvent } from '@reticlehq/core';
|
|
2
2
|
import type { NoteFn } from '../window/engine-host.js';
|
|
3
|
-
import type { DeclaredNetFailure } from '../question/declared.js';
|
|
3
|
+
import type { DeclaredNetFailure, DeclaredRead } from '../question/declared.js';
|
|
4
4
|
/**
|
|
5
5
|
* What a contradiction IS, separated from the rules that find one.
|
|
6
6
|
*
|
|
@@ -167,4 +167,11 @@ export interface ContradictionOptions {
|
|
|
167
167
|
* declared, nothing is unrelated.
|
|
168
168
|
*/
|
|
169
169
|
namedNetUrls?: readonly string[] | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Endpoints the assertion declared as reads (`net { repeatable: true }`). Repeats on them are not
|
|
172
|
+
* a double submit, so `duplicate-request` skips them (#1353). A call matches when its URL contains
|
|
173
|
+
* `urlContains` and, if the clause named a method, its method is that one: a repeatable GET never
|
|
174
|
+
* excuses a POST. Nothing else reads it: they are still waited for and still counted.
|
|
175
|
+
*/
|
|
176
|
+
repeatableNetUrls?: readonly DeclaredRead[] | undefined;
|
|
170
177
|
}
|
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
* The page label moved and the request did not.
|
|
8
|
+
*
|
|
9
|
+
* Measured on a real payments dashboard: "Next" relabels the table "Page 2 of 6" and the app
|
|
10
|
+
* refetches `GET /payments?page=1`, so 103 of 128 rows can never be reached. Every channel looks
|
|
11
|
+
* healthy on its own: the request is a 200, the label changed, the table rendered rows. The
|
|
12
|
+
* disagreement is between the label and the query string.
|
|
13
|
+
*
|
|
14
|
+
* Fires only on direct evidence, never on a guess: the window must show the label's page number
|
|
15
|
+
* changing AND a GET to the same endpoint carrying the same page parameter the last one carried.
|
|
16
|
+
* Client-side paging that fetches nothing is legitimate and stays silent.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @param prior events before the window: where the last page request to each endpoint is learned.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findStalledPagination(events: readonly ReticleEvent[], prior?: readonly ReticleEvent[]): OwnContradiction[];
|
|
@@ -1,39 +1,25 @@
|
|
|
1
|
-
import { ContradictionKind, EventType,
|
|
1
|
+
import { ContradictionKind, EventType, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
|
|
2
2
|
import { describeSuperseded } from '../question/predicate/observed-in-window.js';
|
|
3
|
-
import { describe, isMutating, isSameDocumentHashAnchor, isSteadyCadence, netCall, recoveredByRetry, splitForeignTraffic, } from './contradiction-evidence.js';
|
|
3
|
+
import { declareFailureHint, describe, groupByIdentity, identityOf, isMutating, isSameDocumentHashAnchor, isSamePathnameReplace, isSteadyCadence, netCall, pageNumber, pageRequest, recoveredByRetry, splitForeignTraffic, } from './contradiction-evidence.js';
|
|
4
4
|
import { findStaleResponses } from './stale-response.js';
|
|
5
5
|
import { findBodyFailures } from './body-failures.js';
|
|
6
6
|
import { findEchoMismatches } from './echo-mismatch.js';
|
|
7
7
|
import { findUnitMismatches } from './unit-mismatch.js';
|
|
8
8
|
import { asString } from '@reticlehq/core';
|
|
9
|
-
import { matchesDeclaredFailure } from '../question/declared.js';
|
|
9
|
+
import { isDeclaredRead, matchesDeclaredFailure } from '../question/declared.js';
|
|
10
10
|
import { runRegisteredFolds } from './contradiction-folds.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return carried === undefined
|
|
24
|
-
? { key: action, carried: false }
|
|
25
|
-
: { key: `${action}:${carried}`, carried: true };
|
|
26
|
-
}
|
|
27
|
-
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
28
|
-
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
29
|
-
function groupByIdentity(calls) {
|
|
30
|
-
const byIdentity = new Map();
|
|
31
|
-
for (const call of calls) {
|
|
32
|
-
const key = call.identity?.key ?? '';
|
|
33
|
-
byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
|
|
34
|
-
}
|
|
35
|
-
return [...byIdentity.values()];
|
|
36
|
-
}
|
|
11
|
+
import { isMeaningfulStateChange } from '../state-bookkeeping.js';
|
|
12
|
+
/**
|
|
13
|
+
* The contradiction hunter.
|
|
14
|
+
*
|
|
15
|
+
* Every other check reads ONE channel and asks "did something bad happen there?". This asks what a
|
|
16
|
+
* person watching the screen structurally cannot: do the channels DISAGREE? The DOM, the store, the
|
|
17
|
+
* app's own signals, the console and the network arrive in one causally ordered window, so the case
|
|
18
|
+
* where the screen says one thing and the network says the opposite is visible — and that gap is
|
|
19
|
+
* where false greens live, because a screenshot, a DOM assertion and a human all agree there.
|
|
20
|
+
*
|
|
21
|
+
* Pure: a window of events in, findings out. No session, no IO, no clock.
|
|
22
|
+
*/
|
|
37
23
|
function uiAdvanced(events) {
|
|
38
24
|
return events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
39
25
|
e.type === EventType.DOM_REMOVED ||
|
|
@@ -49,6 +35,10 @@ function uiAdvanced(events) {
|
|
|
49
35
|
* the structural check below cannot decide, not the primary signal.
|
|
50
36
|
*/
|
|
51
37
|
const ACKNOWLEDGED = /error|fail|invalid|reject|denied|unable|could not|couldn't/i;
|
|
38
|
+
// Refusal wording belongs to explicit signals; "checkout.blocking" can be an ordinary loading flag.
|
|
39
|
+
// Token boundaries keep "unblocked" and "blockchain" as success claims.
|
|
40
|
+
const REFUSAL_SIGNAL = /(?:^|[^a-z])(?:refus(?:e[ds]?|al|ing)|forbid(?:den|ding|s)?|blocked|not[ _-]+allowed)(?:$|[^a-z])/i;
|
|
41
|
+
const signalAcknowledgesFailure = (name) => ACKNOWLEDGED.test(name) || REFUSAL_SIGNAL.test(name);
|
|
52
42
|
/**
|
|
53
43
|
* Below this length an error string is too generic to be evidence — "no", "err", a bare code — and
|
|
54
44
|
* could coincide with unrelated state text.
|
|
@@ -88,18 +78,33 @@ function failureAcknowledged(events) {
|
|
|
88
78
|
.map((e) => asString(e.data['error']))
|
|
89
79
|
.filter((text) => text !== undefined && text.length >= MIN_ECHOED_ERROR_LENGTH);
|
|
90
80
|
const echoesAnError = events.some((e) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const value =
|
|
81
|
+
// On screen counts as much as in state: the user reading the server's message is the app
|
|
82
|
+
// acknowledging the failure, not hiding it (#984).
|
|
83
|
+
const value = e.type === EventType.STATE_CHANGE
|
|
84
|
+
? asString(e.data['value'])
|
|
85
|
+
: e.type === EventType.DOM_TEXT
|
|
86
|
+
? asString(e.data['text'])
|
|
87
|
+
: e.type === EventType.DOM_ADDED
|
|
88
|
+
? asString(e.data['name'])
|
|
89
|
+
: undefined;
|
|
94
90
|
return value !== undefined && errors.some((text) => value.includes(text));
|
|
95
91
|
});
|
|
96
92
|
if (echoesAnError)
|
|
97
93
|
return true;
|
|
94
|
+
// So does the accessible way of telling a user something went wrong: an alert appearing, or a
|
|
95
|
+
// field marked invalid. A rejected write that is the behaviour under test (a 409 on a duplicate
|
|
96
|
+
// email) is acknowledged exactly this way, and was contradicted for it (#984).
|
|
97
|
+
const shownAsError = events.some((e) => (e.type === EventType.DOM_ADDED && ALERT_ROLE === e.data['role']) ||
|
|
98
|
+
(e.type === EventType.DOM_ATTR &&
|
|
99
|
+
ARIA_INVALID === e.data['attr'] &&
|
|
100
|
+
'true' === e.data['value']));
|
|
101
|
+
if (shownAsError)
|
|
102
|
+
return true;
|
|
98
103
|
return events.some((e) => {
|
|
99
104
|
// A failure-shaped SIGNAL is an acknowledgement too. An app that fires `auth:denied` has plainly
|
|
100
105
|
// not proceeded as if it succeeded, whatever its state paths happen to be named.
|
|
101
106
|
if (e.type === EventType.SIGNAL)
|
|
102
|
-
return
|
|
107
|
+
return signalAcknowledgesFailure(asString(e.data['name']) ?? '');
|
|
103
108
|
if (e.type !== EventType.STATE_CHANGE)
|
|
104
109
|
return false;
|
|
105
110
|
const path = asString(e.data['path']) ?? '';
|
|
@@ -107,6 +112,10 @@ function failureAcknowledged(events) {
|
|
|
107
112
|
return ACKNOWLEDGED.test(path) || ('string' === typeof value && ACKNOWLEDGED.test(value));
|
|
108
113
|
});
|
|
109
114
|
}
|
|
115
|
+
const ALERT_ROLE = 'alert';
|
|
116
|
+
/** Reticle's own instrumentation's signals (core's `RETICLE_HYDRATION_SIGNAL`); not imported: coupling only shrinks. */
|
|
117
|
+
const RETICLE_SIGNAL_NAMESPACE = 'reticle:';
|
|
118
|
+
const ARIA_INVALID = 'aria-invalid';
|
|
110
119
|
const MUST_DO_SOMETHING = new Set(['click', 'dblclick', 'submit']);
|
|
111
120
|
/**
|
|
112
121
|
* Whether NOTHING in this window is attributable to the action.
|
|
@@ -226,6 +235,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
226
235
|
found.push(...findEchoMismatches(events, options.actionSince));
|
|
227
236
|
// ── A money value written back at the wrong SCALE ───────────────────────────────────────────
|
|
228
237
|
found.push(...findUnitMismatches(events, options.prior ?? []));
|
|
238
|
+
found.push(...findStalledPagination(events, options.prior ?? []));
|
|
229
239
|
// ── The action landed on something that does not react ──────────────────────────────────────
|
|
230
240
|
// Checked first and returned alone: nothing is attributable to the action, so every rule below is
|
|
231
241
|
// reasoning about someone else's events.
|
|
@@ -289,7 +299,12 @@ function findWindowContradictions(allEvents, options) {
|
|
|
289
299
|
// consequences are location.hash, focus, and scroll — not a DOM mutation. Treating it as a
|
|
290
300
|
// blank destination made "did my skip link work" unanswerable. Hash-router paths (`#/invoices`)
|
|
291
301
|
// still go through the rule: those ARE a new view.
|
|
292
|
-
|
|
302
|
+
//
|
|
303
|
+
// A `replaceState` that keeps the pathname is the same kind of non-navigation: the URL recorded
|
|
304
|
+
// state (a zoom, a filter, a selected tab) and the view did not change. A replace onto a new
|
|
305
|
+
// pathname, or a push onto one, is still a navigation.
|
|
306
|
+
const notANavigation = routed &&
|
|
307
|
+
routeEvents.every((event) => isSameDocumentHashAnchor(event) || isSamePathnameReplace(event));
|
|
293
308
|
// `dom.text` counts as rendered, and it has to: React reconciles a destination IN PLACE far more
|
|
294
309
|
// often than it adds nodes. Measured on three ordinary sidebar navigations of the bench app — every
|
|
295
310
|
// one emitted { dom.attr:2, dom.text:2, render.commit, state.change } and ZERO dom.added/removed,
|
|
@@ -304,7 +319,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
304
319
|
e.type === EventType.DOM_REMOVED ||
|
|
305
320
|
e.type === EventType.DOM_TEXT);
|
|
306
321
|
const fetched = events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING);
|
|
307
|
-
if (routed && !
|
|
322
|
+
if (routed && !notANavigation && !rendered && !fetched && true !== options.renderProved) {
|
|
308
323
|
// A console error in the SAME window turns "nothing rendered" from an absence into a positive
|
|
309
324
|
// claim: the destination did not merely fail to produce content, it crashed while trying to.
|
|
310
325
|
// Reported once as `unknown` when this held — a React hooks error and an empty destination were
|
|
@@ -360,7 +375,9 @@ function findWindowContradictions(allEvents, options) {
|
|
|
360
375
|
// A failure-shaped signal is not a success claim, so it must not be read as one: saying "the app
|
|
361
376
|
// claimed success" about an app that plainly reported a failure is true in outline and wrong in
|
|
362
377
|
// its reasoning, which is how a checker stops being believed.
|
|
363
|
-
|
|
378
|
+
// Nor is a signal Reticle's instrumentation fires: a revoked member's tab sent to /login by the
|
|
379
|
+
// intended 401 hydrated, and that read as a success claim graded the working revocation `no`.
|
|
380
|
+
const successSignals = signals.filter((name) => !name.startsWith(RETICLE_SIGNAL_NAMESPACE) && !signalAcknowledgesFailure(name));
|
|
364
381
|
// An app that RETRACTED has not claimed success, whenever it fired the optimistic signal.
|
|
365
382
|
//
|
|
366
383
|
// The weaker UI rule below already consulted this and the sharper signal rule did not, so an app
|
|
@@ -408,7 +425,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
408
425
|
kind: ContradictionKind.UI_ADVANCED_REQUEST_FAILED,
|
|
409
426
|
claim: 'the UI moved forward (DOM/store/route changed)',
|
|
410
427
|
counter: `${String(unexpectedWrites.length)} request(s) in the same window failed`,
|
|
411
|
-
detail: unexpectedWrites.map(describe).join('; ')
|
|
428
|
+
detail: `${unexpectedWrites.map(describe).join('; ')}${declareFailureHint(unexpectedWrites)}`,
|
|
412
429
|
});
|
|
413
430
|
}
|
|
414
431
|
// ── A write succeeded and nothing on the client moved ───────────────────────────────────────
|
|
@@ -456,7 +473,7 @@ function findWindowContradictions(allEvents, options) {
|
|
|
456
473
|
// signal rule below had to earn. Two existing tests proved it: both describe a window with a
|
|
457
474
|
// failed call in it, and both were already answered by the rule that owns that fact.
|
|
458
475
|
if (options.actionSince !== undefined &&
|
|
459
|
-
events.some(
|
|
476
|
+
events.some(isMeaningfulStateChange) &&
|
|
460
477
|
!events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING) &&
|
|
461
478
|
!events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
462
479
|
e.type === EventType.DOM_REMOVED ||
|
|
@@ -549,6 +566,9 @@ function findWindowContradictions(allEvents, options) {
|
|
|
549
566
|
const call = netCall(event);
|
|
550
567
|
if (!isMutating(call))
|
|
551
568
|
continue;
|
|
569
|
+
// Declared a read by the assertion itself (#1353): a repeat is the app reading twice.
|
|
570
|
+
if (isDeclaredRead(call, options.repeatableNetUrls))
|
|
571
|
+
continue;
|
|
552
572
|
const label = `${call.method} ${call.url}`;
|
|
553
573
|
const calls = writes.get(label) ?? [];
|
|
554
574
|
// `landed` is tracked per call rather than counted here, because the claim is about what
|
|
@@ -654,3 +674,56 @@ function findWindowContradictions(allEvents, options) {
|
|
|
654
674
|
// adds to the verdict rather than forking the file that produces it.
|
|
655
675
|
return [...found, ...runRegisteredFolds(events, options)];
|
|
656
676
|
}
|
|
677
|
+
// ── Pagination ───────────────────────────────────────────────────────────────────────────────
|
|
678
|
+
/**
|
|
679
|
+
* The page label moved and the request did not.
|
|
680
|
+
*
|
|
681
|
+
* Measured on a real payments dashboard: "Next" relabels the table "Page 2 of 6" and the app
|
|
682
|
+
* refetches `GET /payments?page=1`, so 103 of 128 rows can never be reached. Every channel looks
|
|
683
|
+
* healthy on its own: the request is a 200, the label changed, the table rendered rows. The
|
|
684
|
+
* disagreement is between the label and the query string.
|
|
685
|
+
*
|
|
686
|
+
* Fires only on direct evidence, never on a guess: the window must show the label's page number
|
|
687
|
+
* changing AND a GET to the same endpoint carrying the same page parameter the last one carried.
|
|
688
|
+
* Client-side paging that fetches nothing is legitimate and stays silent.
|
|
689
|
+
*/
|
|
690
|
+
/**
|
|
691
|
+
* @param prior events before the window: where the last page request to each endpoint is learned.
|
|
692
|
+
*/
|
|
693
|
+
export function findStalledPagination(events, prior = []) {
|
|
694
|
+
const moved = events.flatMap((event) => {
|
|
695
|
+
if (event.type !== EventType.DOM_TEXT)
|
|
696
|
+
return [];
|
|
697
|
+
const now = pageNumber(event.data['text']);
|
|
698
|
+
const before = pageNumber(event.data['old']);
|
|
699
|
+
return now !== undefined && before !== undefined && now !== before ? [{ before, now }] : [];
|
|
700
|
+
});
|
|
701
|
+
const label = moved[0];
|
|
702
|
+
if (label === undefined)
|
|
703
|
+
return [];
|
|
704
|
+
const last = new Map();
|
|
705
|
+
for (const event of prior) {
|
|
706
|
+
const request = pageRequest(event);
|
|
707
|
+
if (request !== undefined)
|
|
708
|
+
last.set(request.path, request);
|
|
709
|
+
}
|
|
710
|
+
for (const event of events) {
|
|
711
|
+
const request = pageRequest(event);
|
|
712
|
+
if (request === undefined)
|
|
713
|
+
continue;
|
|
714
|
+
const previous = last.get(request.path);
|
|
715
|
+
if (previous !== undefined &&
|
|
716
|
+
previous.param === request.param &&
|
|
717
|
+
previous.value === request.value)
|
|
718
|
+
return [
|
|
719
|
+
{
|
|
720
|
+
kind: ContradictionKind.PAGINATION_NOT_FETCHED,
|
|
721
|
+
claim: `the page label moved from ${String(label.before)} to ${String(label.now)}`,
|
|
722
|
+
counter: `the app asked ${request.path} for ${request.param}=${request.value} again — the same page it already had`,
|
|
723
|
+
detail: `${String(event.data['url'])} — the rows shown are still the earlier page, so everything past it cannot be reached`,
|
|
724
|
+
},
|
|
725
|
+
];
|
|
726
|
+
last.set(request.path, request);
|
|
727
|
+
}
|
|
728
|
+
return [];
|
|
729
|
+
}
|