@reticlehq/engine 3.6.0 → 3.8.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/contradiction-evidence.d.ts +134 -2
- package/dist/disagreement/contradiction-evidence.js +291 -3
- package/dist/disagreement/contradiction-types.d.ts +16 -1
- package/dist/disagreement/contradictions.d.ts +12 -0
- package/dist/disagreement/contradictions.js +56 -84
- package/dist/disagreement/stale-response.js +56 -17
- package/dist/evidence/already-true.d.ts +5 -0
- package/dist/evidence/already-true.js +27 -6
- 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 +1 -15
- package/dist/evidence/body-capture-remedy.js +6 -1
- 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/step-effect.d.ts +20 -1
- package/dist/evidence/step-effect.js +30 -2
- package/dist/evidence/superseded-checks.d.ts +29 -0
- package/dist/evidence/superseded-checks.js +30 -0
- package/dist/evidence/uncaptured-bodies.d.ts +18 -1
- package/dist/evidence/uncaptured-bodies.js +22 -1
- package/dist/evidence/unread-outcome.d.ts +7 -0
- package/dist/evidence/unread-outcome.js +22 -0
- package/dist/evidence/unsettled.js +29 -2
- package/dist/evidence/verified.d.ts +8 -1
- package/dist/evidence/verified.js +33 -5
- package/dist/question/declared.d.ts +20 -0
- package/dist/question/declared.js +20 -1
- 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 +7 -1
- package/dist/question/predicate/predicate-console.js +23 -10
- package/dist/question/predicate/predicate-element.d.ts +23 -0
- package/dist/question/predicate/predicate-element.js +208 -16
- package/dist/question/predicate/predicate-eval-kit.d.ts +28 -3
- package/dist/question/predicate/predicate-eval-kit.js +34 -7
- package/dist/question/predicate/predicate-eval.d.ts +11 -1
- package/dist/question/predicate/predicate-eval.js +138 -177
- package/dist/question/predicate/predicate-parse.js +34 -0
- package/dist/question/predicate/predicate-request-body.d.ts +15 -1
- package/dist/question/predicate/predicate-request-body.js +23 -3
- 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 +52 -1
- package/dist/question/predicate/predicate-state.js +7 -0
- package/dist/question/predicate/predicate.js +58 -18
- package/dist/question/predicate/split-text-miss.d.ts +7 -0
- package/dist/question/predicate/split-text-miss.js +18 -1
- package/dist/state-bookkeeping.d.ts +27 -0
- package/dist/state-bookkeeping.js +74 -0
- package/dist/window/adversary.js +5 -1
- package/package.json +2 -2
|
@@ -4,8 +4,9 @@
|
|
|
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
|
|
8
|
-
*
|
|
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 — and whether a settled field
|
|
9
|
+
* reading shows the app wrote the screen forward. Nothing here knows what a 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
|
|
@@ -13,6 +14,8 @@
|
|
|
13
14
|
*/
|
|
14
15
|
import { EventType, type ReticleEvent } from '@reticlehq/core';
|
|
15
16
|
export interface NetCall {
|
|
17
|
+
/** When the call settled, on the session clock. */
|
|
18
|
+
t: number;
|
|
16
19
|
method: string;
|
|
17
20
|
url: string;
|
|
18
21
|
/** Grader haystack — the raw request when redaction rewrote `url`. */
|
|
@@ -66,6 +69,35 @@ export declare function hrefAsUrl(value: string | undefined): URL | undefined;
|
|
|
66
69
|
* Returns false when `from`/`to` are missing, so older events without hrefs keep the existing rule.
|
|
67
70
|
*/
|
|
68
71
|
export declare function isSameDocumentHashAnchor(event: ReticleEvent): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* A `replaceState` that keeps the pathname recorded state in the URL. It is not a navigation.
|
|
74
|
+
*
|
|
75
|
+
* Search and an in-page fragment may change (`?zoom=125`, `#main-content`). A hash-router fragment
|
|
76
|
+
* (`#/invoices`) is still a new view, and so is a replace onto a different pathname. Missing hrefs
|
|
77
|
+
* stay under the blank-destination rule: an event that cannot show the path stayed put is not exempt.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isSamePathnameReplace(event: ReticleEvent): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Did this event show a field whose post-handler reading differs from its pre-action one?
|
|
82
|
+
*
|
|
83
|
+
* React writes `checked` and `value` as properties, so a controlled checkbox that re-renders
|
|
84
|
+
* produces no attribute mutation. The field change from the input event itself cannot fill that
|
|
85
|
+
* gap: it is emitted from the user's own event, before a controlled component restores the
|
|
86
|
+
* property, and counting it would treat a box React immediately reverted as rendered.
|
|
87
|
+
*
|
|
88
|
+
* A settled read carries the value from before the action beside the value after the handlers
|
|
89
|
+
* ran. The browser only sends one when the app itself wrote the property during the action, so an
|
|
90
|
+
* uncontrolled field the browser toggled on its own never counts. The screen moved only when the
|
|
91
|
+
* two readings differ.
|
|
92
|
+
*/
|
|
93
|
+
export declare function settledFieldRendered(event: ReticleEvent): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Did this event show the screen moving, for the state-vs-render rule? A DOM node added, removed or
|
|
96
|
+
* changed, route movement (a navigation IS a render), or a field the app itself wrote to a new
|
|
97
|
+
* value (`settledFieldRendered`). The input event's own field change does not count: that is the
|
|
98
|
+
* keystroke or the browser's own toggle, true of a component that never re-rendered.
|
|
99
|
+
*/
|
|
100
|
+
export declare function screenMoved(event: ReticleEvent): boolean;
|
|
69
101
|
/**
|
|
70
102
|
* Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
|
|
71
103
|
*
|
|
@@ -127,3 +159,103 @@ export declare const POLL_JITTER_RATIO = 0.4;
|
|
|
127
159
|
* apart they are, which is the classic double submit and every case this rule was written for.
|
|
128
160
|
*/
|
|
129
161
|
export declare function isSteadyCadence(times: readonly number[]): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* What this request CARRIED, as far as the record knows — `undefined` when it does not know.
|
|
164
|
+
*
|
|
165
|
+
* The page's shape fingerprint first: it is present on every request from an instrumented page,
|
|
166
|
+
* including the overwhelming majority where body capture is off. A captured body is the fallback for
|
|
167
|
+
* a realm that records one without a fingerprint (desktop IPC). Neither means the record does not
|
|
168
|
+
* say what this request carried — a body the page could not read as text, or an SDK too old to
|
|
169
|
+
* compute a fingerprint — and that is an ABSENCE of identity, not an identity shared with every
|
|
170
|
+
* other silent request.
|
|
171
|
+
*
|
|
172
|
+
* A Server Action's action id joins both halves, and it is the half that survives a `FormData`
|
|
173
|
+
* body: several actions POST to the page's own URL, so without it every call is an unknown identity
|
|
174
|
+
* pooled with all the others, and no fingerprint can separate two that share a shape. The id alone
|
|
175
|
+
* SPLITS two different actions; it cannot say that two runs of one action carried the same thing,
|
|
176
|
+
* and `carried` keeps that limit on the record for the finding to say.
|
|
177
|
+
*/
|
|
178
|
+
export interface WriteIdentity {
|
|
179
|
+
/** The value the grouping compares. */
|
|
180
|
+
readonly key: string;
|
|
181
|
+
/** Whether the key also describes WHAT the request carried, not only which action ran. */
|
|
182
|
+
readonly carried: boolean;
|
|
183
|
+
}
|
|
184
|
+
export declare function identityOf(event: ReticleEvent): WriteIdentity | undefined;
|
|
185
|
+
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
186
|
+
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
187
|
+
export declare function groupByIdentity<T extends {
|
|
188
|
+
identity: WriteIdentity | undefined;
|
|
189
|
+
}>(calls: readonly T[]): T[][];
|
|
190
|
+
/**
|
|
191
|
+
* The `net` clause that declares each of these failures, worded as a condition.
|
|
192
|
+
*
|
|
193
|
+
* A designed error path (a 402 paywall, a 429, a 428 confirmation) asserted through the UI it renders
|
|
194
|
+
* gets `ui-advanced-request-failed`, and declaring the failing call in the oracle is what exempts it
|
|
195
|
+
* (`matchesDeclaredFailure`). Nothing in the finding said so, so agents dropped the check or
|
|
196
|
+
* weakened it until it proved nothing (#1418). The clause is built from the call itself, so it is
|
|
197
|
+
* exactly what would match, and it is conditional: the finding is still a finding, and a clause
|
|
198
|
+
* pasted to make a red go away would be the same false green with extra steps.
|
|
199
|
+
*
|
|
200
|
+
* Built from the DISPLAY url, which is redacted, never from `matchUrl`, which is not: the detail is
|
|
201
|
+
* copied into crawl anomalies, and a hint must not put back a token the description took out. A
|
|
202
|
+
* call whose path cannot be named exactly and narrowly gets no clause rather than a loose one: a
|
|
203
|
+
* bare `/` is a substring of every url and would exempt unrelated failures with the same method.
|
|
204
|
+
*/
|
|
205
|
+
export declare function declareFailureHint(calls: readonly {
|
|
206
|
+
method: string;
|
|
207
|
+
url: string;
|
|
208
|
+
matchUrl?: string;
|
|
209
|
+
status: number | undefined;
|
|
210
|
+
}[]): string;
|
|
211
|
+
export declare function pageNumber(text: unknown): number | undefined;
|
|
212
|
+
/** The endpoint, page parameter and remaining query, for a GET that carries a page parameter. */
|
|
213
|
+
export declare function pageRequest(event: ReticleEvent): {
|
|
214
|
+
path: string;
|
|
215
|
+
param: string;
|
|
216
|
+
value: string;
|
|
217
|
+
query: string;
|
|
218
|
+
} | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* True when the app published no signal and no store change, in the window or before it.
|
|
221
|
+
*
|
|
222
|
+
* Undefined `prior` means the caller did not look before the window, so it cannot say: false. A
|
|
223
|
+
* zero-install page is the common case here. With no voice of its own, the app cannot say whether
|
|
224
|
+
* it handled a failure, so a finding that rests on that is weak rather than proof.
|
|
225
|
+
*/
|
|
226
|
+
export declare function appIsSilent(events: readonly ReticleEvent[], prior: readonly ReticleEvent[] | undefined): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* What became of the acted control's own change once its failed request settled.
|
|
229
|
+
*
|
|
230
|
+
* `ui-advanced-request-failed` asks whether the UI moved over a failed write. "Moved" was any DOM,
|
|
231
|
+
* store or route change in the window, and that reads a correct optimistic UI as a lie. Measured on
|
|
232
|
+
* a live incident feed with no SDK signals: acknowledging a row disables its button, POSTs, gets a
|
|
233
|
+
* 500, and enables the button again with a banner. The fixed build and the build that swallows the
|
|
234
|
+
* 500 both got the finding, twice each, because the feed appends a row every 800 ms on its own and
|
|
235
|
+
* the button was disabled while the request was in flight.
|
|
236
|
+
*
|
|
237
|
+
* What separates the two builds is the control's fate AFTER the failure:
|
|
238
|
+
*
|
|
239
|
+
* - REVERTED: every change the action made to the control before the failure is back at its value
|
|
240
|
+
* from before the action. The app handled the failure on the thing the user touched.
|
|
241
|
+
* - PENDING: the control still shows its in-flight value and nothing on it moved after the failure.
|
|
242
|
+
* The request was in flight; the app did not go on as if it succeeded.
|
|
243
|
+
* - PERSISTED: the control moved on after the failure. The app went on as if it succeeded.
|
|
244
|
+
*
|
|
245
|
+
* Undefined when this cannot be told: no ref was acted on, or the control did not change before the
|
|
246
|
+
* failure settled. The caller then keeps the old window-wide reading.
|
|
247
|
+
*
|
|
248
|
+
* Only the control's own changes count, so rows the action did not touch (a live feed, a clock)
|
|
249
|
+
* decide nothing.
|
|
250
|
+
*
|
|
251
|
+
* ponytail: the control alone decides. A control rolled back while an unrelated element keeps a
|
|
252
|
+
* change (an item added to a list as its button re-enables) reads as handled. Telling that apart
|
|
253
|
+
* needs the DOM ancestry of each event, which the wire does not carry.
|
|
254
|
+
*/
|
|
255
|
+
export declare const TargetFate: {
|
|
256
|
+
readonly PERSISTED: "persisted";
|
|
257
|
+
readonly REVERTED: "reverted";
|
|
258
|
+
readonly PENDING: "pending";
|
|
259
|
+
};
|
|
260
|
+
export type TargetFate = (typeof TargetFate)[keyof typeof TargetFate];
|
|
261
|
+
export declare function targetFate(events: readonly ReticleEvent[], ref: string | undefined, failedAt: number): TargetFate | undefined;
|
|
@@ -4,17 +4,20 @@
|
|
|
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
|
|
8
|
-
*
|
|
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 — and whether a settled field
|
|
9
|
+
* reading shows the app wrote the screen forward. Nothing here knows what a 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, FieldChangeField, FieldChangeKind, MUTATING_METHODS, NEXT_ACTION_FIELD, PredicateKind, REQUEST_SHAPE_FIELD, ROUTE_CHANGE_HOW_FIELD, RouteChangeHow, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
|
|
16
|
+
import { isReticleVoice } from '../state-bookkeeping.js';
|
|
15
17
|
export function netCall(e) {
|
|
16
18
|
const status = asNumber(e.data['status']);
|
|
17
19
|
return {
|
|
20
|
+
t: e.t,
|
|
18
21
|
method: (asString(e.data['method']) ?? '').toUpperCase(),
|
|
19
22
|
url: asString(e.data['url']) ?? '',
|
|
20
23
|
matchUrl: urlForMatch(e.data),
|
|
@@ -114,6 +117,69 @@ export function isSameDocumentHashAnchor(event) {
|
|
|
114
117
|
return false;
|
|
115
118
|
return isInPageFragment(to.hash);
|
|
116
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* A `replaceState` that keeps the pathname recorded state in the URL. It is not a navigation.
|
|
122
|
+
*
|
|
123
|
+
* Search and an in-page fragment may change (`?zoom=125`, `#main-content`). A hash-router fragment
|
|
124
|
+
* (`#/invoices`) is still a new view, and so is a replace onto a different pathname. Missing hrefs
|
|
125
|
+
* stay under the blank-destination rule: an event that cannot show the path stayed put is not exempt.
|
|
126
|
+
*/
|
|
127
|
+
export function isSamePathnameReplace(event) {
|
|
128
|
+
if (event.type !== EventType.ROUTE_CHANGE)
|
|
129
|
+
return false;
|
|
130
|
+
if (asString(event.data[ROUTE_CHANGE_HOW_FIELD]) !== RouteChangeHow.REPLACE)
|
|
131
|
+
return false;
|
|
132
|
+
const from = hrefAsUrl(asString(event.data['from']));
|
|
133
|
+
const to = hrefAsUrl(asString(event.data['to']));
|
|
134
|
+
if (from === undefined || to === undefined)
|
|
135
|
+
return false;
|
|
136
|
+
if (from.origin !== to.origin || from.pathname !== to.pathname)
|
|
137
|
+
return false;
|
|
138
|
+
if (from.hash !== to.hash && !isInPageFragment(to.hash))
|
|
139
|
+
return false;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Did this event show a field whose post-handler reading differs from its pre-action one?
|
|
144
|
+
*
|
|
145
|
+
* React writes `checked` and `value` as properties, so a controlled checkbox that re-renders
|
|
146
|
+
* produces no attribute mutation. The field change from the input event itself cannot fill that
|
|
147
|
+
* gap: it is emitted from the user's own event, before a controlled component restores the
|
|
148
|
+
* property, and counting it would treat a box React immediately reverted as rendered.
|
|
149
|
+
*
|
|
150
|
+
* A settled read carries the value from before the action beside the value after the handlers
|
|
151
|
+
* ran. The browser only sends one when the app itself wrote the property during the action, so an
|
|
152
|
+
* uncontrolled field the browser toggled on its own never counts. The screen moved only when the
|
|
153
|
+
* two readings differ.
|
|
154
|
+
*/
|
|
155
|
+
export function settledFieldRendered(event) {
|
|
156
|
+
if (event.type !== EventType.FIELD_CHANGE)
|
|
157
|
+
return false;
|
|
158
|
+
if (event.data[FieldChangeField.KIND] !== FieldChangeKind.SETTLED)
|
|
159
|
+
return false;
|
|
160
|
+
const checked = event.data[FieldChangeField.CHECKED];
|
|
161
|
+
const previousChecked = event.data[FieldChangeField.PREVIOUS_CHECKED];
|
|
162
|
+
if ('boolean' === typeof checked && 'boolean' === typeof previousChecked) {
|
|
163
|
+
return checked !== previousChecked;
|
|
164
|
+
}
|
|
165
|
+
const value = event.data[FieldChangeField.VALUE];
|
|
166
|
+
const previous = event.data[FieldChangeField.PREVIOUS];
|
|
167
|
+
return 'string' === typeof value && 'string' === typeof previous && value !== previous;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Did this event show the screen moving, for the state-vs-render rule? A DOM node added, removed or
|
|
171
|
+
* changed, route movement (a navigation IS a render), or a field the app itself wrote to a new
|
|
172
|
+
* value (`settledFieldRendered`). The input event's own field change does not count: that is the
|
|
173
|
+
* keystroke or the browser's own toggle, true of a component that never re-rendered.
|
|
174
|
+
*/
|
|
175
|
+
export function screenMoved(event) {
|
|
176
|
+
return (event.type === EventType.DOM_ADDED ||
|
|
177
|
+
event.type === EventType.DOM_REMOVED ||
|
|
178
|
+
event.type === EventType.DOM_ATTR ||
|
|
179
|
+
event.type === EventType.DOM_TEXT ||
|
|
180
|
+
event.type === EventType.ROUTE_CHANGE ||
|
|
181
|
+
settledFieldRendered(event));
|
|
182
|
+
}
|
|
117
183
|
/**
|
|
118
184
|
* Split the window into the app's traffic and the dev toolchain's own (see `DevToolingChannel`).
|
|
119
185
|
*
|
|
@@ -201,3 +267,225 @@ export function isSteadyCadence(times) {
|
|
|
201
267
|
return false;
|
|
202
268
|
return gaps.every((gap) => Math.abs(gap - median) <= median * POLL_JITTER_RATIO);
|
|
203
269
|
}
|
|
270
|
+
export function identityOf(event) {
|
|
271
|
+
const action = asString(event.data[NEXT_ACTION_FIELD]);
|
|
272
|
+
const shape = asString(event.data[REQUEST_SHAPE_FIELD]);
|
|
273
|
+
const body = asString(event.data['requestBody']);
|
|
274
|
+
const carried = shape !== undefined && 0 !== shape.length
|
|
275
|
+
? shape
|
|
276
|
+
: body === undefined || 0 === body.length
|
|
277
|
+
? undefined
|
|
278
|
+
: body;
|
|
279
|
+
if (action === undefined || 0 === action.length) {
|
|
280
|
+
return carried === undefined ? undefined : { key: carried, carried: true };
|
|
281
|
+
}
|
|
282
|
+
return carried === undefined
|
|
283
|
+
? { key: action, carried: false }
|
|
284
|
+
: { key: `${action}:${carried}`, carried: true };
|
|
285
|
+
}
|
|
286
|
+
/** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
|
|
287
|
+
* every identity is known; an unknown one would otherwise pool with every other unknown. */
|
|
288
|
+
export function groupByIdentity(calls) {
|
|
289
|
+
const byIdentity = new Map();
|
|
290
|
+
for (const call of calls) {
|
|
291
|
+
const key = call.identity?.key ?? '';
|
|
292
|
+
byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
|
|
293
|
+
}
|
|
294
|
+
return [...byIdentity.values()];
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The `net` clause that declares each of these failures, worded as a condition.
|
|
298
|
+
*
|
|
299
|
+
* A designed error path (a 402 paywall, a 429, a 428 confirmation) asserted through the UI it renders
|
|
300
|
+
* gets `ui-advanced-request-failed`, and declaring the failing call in the oracle is what exempts it
|
|
301
|
+
* (`matchesDeclaredFailure`). Nothing in the finding said so, so agents dropped the check or
|
|
302
|
+
* weakened it until it proved nothing (#1418). The clause is built from the call itself, so it is
|
|
303
|
+
* exactly what would match, and it is conditional: the finding is still a finding, and a clause
|
|
304
|
+
* pasted to make a red go away would be the same false green with extra steps.
|
|
305
|
+
*
|
|
306
|
+
* Built from the DISPLAY url, which is redacted, never from `matchUrl`, which is not: the detail is
|
|
307
|
+
* copied into crawl anomalies, and a hint must not put back a token the description took out. A
|
|
308
|
+
* call whose path cannot be named exactly and narrowly gets no clause rather than a loose one: a
|
|
309
|
+
* bare `/` is a substring of every url and would exempt unrelated failures with the same method.
|
|
310
|
+
*/
|
|
311
|
+
export function declareFailureHint(calls) {
|
|
312
|
+
const clauses = calls.flatMap((c) => {
|
|
313
|
+
const urlContains = narrowPathOf(c);
|
|
314
|
+
if (urlContains === undefined)
|
|
315
|
+
return [];
|
|
316
|
+
const clause = {
|
|
317
|
+
kind: PredicateKind.NET,
|
|
318
|
+
method: c.method.toUpperCase(),
|
|
319
|
+
urlContains,
|
|
320
|
+
...(c.status === undefined || 0 === c.status ? { ok: false } : { status: c.status }),
|
|
321
|
+
};
|
|
322
|
+
return [JSON.stringify(clause)];
|
|
323
|
+
});
|
|
324
|
+
if (0 === clauses.length)
|
|
325
|
+
return '';
|
|
326
|
+
const subject = 1 === clauses.length ? 'this failure is' : 'these failures are';
|
|
327
|
+
return `. If ${subject} the outcome you expect, declare it in the predicate: ${clauses.join(', ')}`;
|
|
328
|
+
}
|
|
329
|
+
/** Resolves a relative call url so its path can be read; the host is never shown or matched. */
|
|
330
|
+
const RELATIVE_URL_BASE = 'http://reticle.invalid';
|
|
331
|
+
/**
|
|
332
|
+
* The display url's path, when it is both safe to show and narrow enough to declare one call.
|
|
333
|
+
*
|
|
334
|
+
* Only when it is literally in the url the declaration is matched against: `urlContains` is a
|
|
335
|
+
* substring test, so a path the parser re-encoded, or one the redaction changed, would never match.
|
|
336
|
+
*/
|
|
337
|
+
function narrowPathOf(call) {
|
|
338
|
+
let path;
|
|
339
|
+
try {
|
|
340
|
+
path = new URL(call.url, RELATIVE_URL_BASE).pathname;
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
if (0 === path.replace(/\/+$/, '').length)
|
|
346
|
+
return undefined;
|
|
347
|
+
if (!call.url.includes(path) || !(call.matchUrl ?? call.url).includes(path))
|
|
348
|
+
return undefined;
|
|
349
|
+
return path;
|
|
350
|
+
}
|
|
351
|
+
/** Query parameters that say which page of a list is being asked for. */
|
|
352
|
+
const PAGE_PARAMS = ['page', 'offset', 'cursor', 'after', 'start', 'skip', 'from'];
|
|
353
|
+
/** "Page 2", "page 2 of 6", "2 / 6", "2 of 6". */
|
|
354
|
+
const PAGE_LABEL = /\bpage\s+(\d+)\b|\b(\d+)\s*(?:of|\/)\s*\d+(?:,\d{3})*\b/i;
|
|
355
|
+
const RECORD_RANGE_LABEL = /\b\d[\d,]*\s*(?:[-–—]|\bto\b)\s*\d[\d,]*\s+of\s+\d[\d,]*\b|\b\d[\d,]*\s+of\s+\d[\d,]*\s+(?:records|items|results)\b/i;
|
|
356
|
+
export function pageNumber(text) {
|
|
357
|
+
if ('string' !== typeof text)
|
|
358
|
+
return undefined;
|
|
359
|
+
if (RECORD_RANGE_LABEL.test(text))
|
|
360
|
+
return undefined;
|
|
361
|
+
const match = PAGE_LABEL.exec(text);
|
|
362
|
+
const raw = match?.[1] ?? match?.[2];
|
|
363
|
+
return raw === undefined ? undefined : Number(raw);
|
|
364
|
+
}
|
|
365
|
+
/** The endpoint, page parameter and remaining query, for a GET that carries a page parameter. */
|
|
366
|
+
export function pageRequest(event) {
|
|
367
|
+
if (event.type !== EventType.NET_REQUEST)
|
|
368
|
+
return undefined;
|
|
369
|
+
const method = event.data['method'];
|
|
370
|
+
if ('string' !== typeof method || 'GET' !== method.toUpperCase())
|
|
371
|
+
return undefined;
|
|
372
|
+
const raw = event.data['url'];
|
|
373
|
+
if ('string' !== typeof raw)
|
|
374
|
+
return undefined;
|
|
375
|
+
let url;
|
|
376
|
+
try {
|
|
377
|
+
url = new URL(raw, 'http://app.invalid');
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
for (const param of PAGE_PARAMS) {
|
|
383
|
+
const value = url.searchParams.get(param);
|
|
384
|
+
if (value !== null) {
|
|
385
|
+
url.searchParams.delete(param);
|
|
386
|
+
// jQuery `cache: false` changes `_` on every otherwise identical GET.
|
|
387
|
+
url.searchParams.delete('_');
|
|
388
|
+
url.searchParams.sort();
|
|
389
|
+
return { path: url.pathname, param, value, query: url.searchParams.toString() };
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* True when the app published no signal and no store change, in the window or before it.
|
|
396
|
+
*
|
|
397
|
+
* Undefined `prior` means the caller did not look before the window, so it cannot say: false. A
|
|
398
|
+
* zero-install page is the common case here. With no voice of its own, the app cannot say whether
|
|
399
|
+
* it handled a failure, so a finding that rests on that is weak rather than proof.
|
|
400
|
+
*/
|
|
401
|
+
export function appIsSilent(events, prior) {
|
|
402
|
+
if (prior === undefined)
|
|
403
|
+
return false;
|
|
404
|
+
const speaks = (e) => {
|
|
405
|
+
if (e.type === EventType.SIGNAL)
|
|
406
|
+
return !isReticleVoice(asString(e.data['name']) ?? '');
|
|
407
|
+
if (e.type !== EventType.STATE_CHANGE)
|
|
408
|
+
return false;
|
|
409
|
+
return !isReticleVoice(asString(e.data['store']) ?? asString(e.data['name']) ?? '');
|
|
410
|
+
};
|
|
411
|
+
return !prior.some(speaks) && !events.some(speaks);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* What became of the acted control's own change once its failed request settled.
|
|
415
|
+
*
|
|
416
|
+
* `ui-advanced-request-failed` asks whether the UI moved over a failed write. "Moved" was any DOM,
|
|
417
|
+
* store or route change in the window, and that reads a correct optimistic UI as a lie. Measured on
|
|
418
|
+
* a live incident feed with no SDK signals: acknowledging a row disables its button, POSTs, gets a
|
|
419
|
+
* 500, and enables the button again with a banner. The fixed build and the build that swallows the
|
|
420
|
+
* 500 both got the finding, twice each, because the feed appends a row every 800 ms on its own and
|
|
421
|
+
* the button was disabled while the request was in flight.
|
|
422
|
+
*
|
|
423
|
+
* What separates the two builds is the control's fate AFTER the failure:
|
|
424
|
+
*
|
|
425
|
+
* - REVERTED: every change the action made to the control before the failure is back at its value
|
|
426
|
+
* from before the action. The app handled the failure on the thing the user touched.
|
|
427
|
+
* - PENDING: the control still shows its in-flight value and nothing on it moved after the failure.
|
|
428
|
+
* The request was in flight; the app did not go on as if it succeeded.
|
|
429
|
+
* - PERSISTED: the control moved on after the failure. The app went on as if it succeeded.
|
|
430
|
+
*
|
|
431
|
+
* Undefined when this cannot be told: no ref was acted on, or the control did not change before the
|
|
432
|
+
* failure settled. The caller then keeps the old window-wide reading.
|
|
433
|
+
*
|
|
434
|
+
* Only the control's own changes count, so rows the action did not touch (a live feed, a clock)
|
|
435
|
+
* decide nothing.
|
|
436
|
+
*
|
|
437
|
+
* ponytail: the control alone decides. A control rolled back while an unrelated element keeps a
|
|
438
|
+
* change (an item added to a list as its button re-enables) reads as handled. Telling that apart
|
|
439
|
+
* needs the DOM ancestry of each event, which the wire does not carry.
|
|
440
|
+
*/
|
|
441
|
+
export const TargetFate = {
|
|
442
|
+
PERSISTED: 'persisted',
|
|
443
|
+
REVERTED: 'reverted',
|
|
444
|
+
PENDING: 'pending',
|
|
445
|
+
};
|
|
446
|
+
/** A value the control did not have: an absent attribute, or no text. */
|
|
447
|
+
const ABSENT = '\u0000absent';
|
|
448
|
+
/** The attribute or text change this event made to `ref`, or undefined. No-op writes are skipped. */
|
|
449
|
+
function changeOf(event, ref) {
|
|
450
|
+
if (event.ref !== ref)
|
|
451
|
+
return undefined;
|
|
452
|
+
let key;
|
|
453
|
+
let now;
|
|
454
|
+
if (event.type === EventType.DOM_ATTR) {
|
|
455
|
+
key = `attr:${asString(event.data['attr']) ?? ''}`;
|
|
456
|
+
now = asString(event.data['value']) ?? ABSENT;
|
|
457
|
+
}
|
|
458
|
+
else if (event.type === EventType.DOM_TEXT) {
|
|
459
|
+
key = 'text';
|
|
460
|
+
now = asString(event.data['text']) ?? ABSENT;
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
return undefined;
|
|
464
|
+
}
|
|
465
|
+
const old = asString(event.data['old']) ?? ABSENT;
|
|
466
|
+
return old === now ? undefined : { key, t: event.t, old, now };
|
|
467
|
+
}
|
|
468
|
+
export function targetFate(events, ref, failedAt) {
|
|
469
|
+
if (ref === undefined)
|
|
470
|
+
return undefined;
|
|
471
|
+
const before = new Map();
|
|
472
|
+
const atFailure = new Map();
|
|
473
|
+
const last = new Map();
|
|
474
|
+
for (const event of events) {
|
|
475
|
+
const change = changeOf(event, ref);
|
|
476
|
+
if (change === undefined)
|
|
477
|
+
continue;
|
|
478
|
+
if (!before.has(change.key))
|
|
479
|
+
before.set(change.key, change.old);
|
|
480
|
+
if (change.t <= failedAt)
|
|
481
|
+
atFailure.set(change.key, change.now);
|
|
482
|
+
last.set(change.key, change.now);
|
|
483
|
+
}
|
|
484
|
+
if (0 === atFailure.size)
|
|
485
|
+
return undefined;
|
|
486
|
+
const reverted = [...last].every(([key, value]) => before.get(key) === value);
|
|
487
|
+
if (reverted)
|
|
488
|
+
return TargetFate.REVERTED;
|
|
489
|
+
const movedAfter = [...last].some(([key, value]) => (atFailure.get(key) ?? before.get(key)) !== value);
|
|
490
|
+
return movedAfter ? TargetFate.PERSISTED : TargetFate.PENDING;
|
|
491
|
+
}
|
|
@@ -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
|
*
|
|
@@ -29,6 +29,14 @@ export interface ContradictionOptions {
|
|
|
29
29
|
note?: NoteFn;
|
|
30
30
|
/** The action that opened this window, when one did. Enables the no-effect check. */
|
|
31
31
|
action?: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The ref of the control the action was dispatched on.
|
|
34
|
+
*
|
|
35
|
+
* Lets `ui-advanced-request-failed` read what became of that control after its request failed:
|
|
36
|
+
* rolled back, still pending, or moved on. Undefined keeps the window-wide reading. See
|
|
37
|
+
* `targetFate`.
|
|
38
|
+
*/
|
|
39
|
+
ref?: string | undefined;
|
|
32
40
|
/**
|
|
33
41
|
* Was the page HIDDEN while this window was recorded? Stated by the caller, which knows.
|
|
34
42
|
*
|
|
@@ -167,4 +175,11 @@ export interface ContradictionOptions {
|
|
|
167
175
|
* declared, nothing is unrelated.
|
|
168
176
|
*/
|
|
169
177
|
namedNetUrls?: readonly string[] | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* Endpoints the assertion declared as reads (`net { repeatable: true }`). Repeats on them are not
|
|
180
|
+
* a double submit, so `duplicate-request` skips them (#1353). A call matches when its URL contains
|
|
181
|
+
* `urlContains` and, if the clause named a method, its method is that one: a repeatable GET never
|
|
182
|
+
* excuses a POST. Nothing else reads it: they are still waited for and still counted.
|
|
183
|
+
*/
|
|
184
|
+
repeatableNetUrls?: readonly DeclaredRead[] | undefined;
|
|
170
185
|
}
|
|
@@ -3,6 +3,18 @@ import type { Contradiction, OwnContradiction, ContradictionOptions } from './co
|
|
|
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
|
+
*/
|
|
6
18
|
/**
|
|
7
19
|
* @param prior events before the window: where the last page request to each endpoint is learned.
|
|
8
20
|
*/
|