@reticlehq/engine 3.1.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/LICENSE +202 -0
- package/README.md +36 -0
- package/dist/disagreement/body-failures.d.ts +4 -0
- package/dist/disagreement/body-failures.js +113 -0
- package/dist/disagreement/contradiction-evidence.d.ts +122 -0
- package/dist/disagreement/contradiction-evidence.js +194 -0
- package/dist/disagreement/contradiction-folds.d.ts +61 -0
- package/dist/disagreement/contradiction-folds.js +71 -0
- package/dist/disagreement/contradiction-types.d.ts +164 -0
- package/dist/disagreement/contradiction-types.js +1 -0
- package/dist/disagreement/contradictions.d.ts +5 -0
- package/dist/disagreement/contradictions.js +613 -0
- package/dist/disagreement/echo-mismatch.d.ts +10 -0
- package/dist/disagreement/echo-mismatch.js +299 -0
- package/dist/disagreement/reconcile.d.ts +39 -0
- package/dist/disagreement/reconcile.js +211 -0
- package/dist/disagreement/stale-response.d.ts +3 -0
- package/dist/disagreement/stale-response.js +186 -0
- package/dist/disagreement/unit-mismatch.d.ts +16 -0
- package/dist/disagreement/unit-mismatch.js +167 -0
- package/dist/disagreement/witness-disagreement.d.ts +42 -0
- package/dist/disagreement/witness-disagreement.js +43 -0
- package/dist/evidence/accepted-write.d.ts +35 -0
- package/dist/evidence/accepted-write.js +54 -0
- package/dist/evidence/already-true.d.ts +16 -0
- package/dist/evidence/already-true.js +89 -0
- package/dist/evidence/blind-spots.d.ts +133 -0
- package/dist/evidence/blind-spots.js +253 -0
- package/dist/evidence/body-capture-remedy.d.ts +42 -0
- package/dist/evidence/body-capture-remedy.js +96 -0
- package/dist/evidence/gap-ledger.d.ts +52 -0
- package/dist/evidence/gap-ledger.js +63 -0
- package/dist/evidence/honesty.d.ts +113 -0
- package/dist/evidence/honesty.js +105 -0
- package/dist/evidence/instrumentation-gaps.d.ts +91 -0
- package/dist/evidence/instrumentation-gaps.js +102 -0
- package/dist/evidence/learned-guards.d.ts +75 -0
- package/dist/evidence/learned-guards.js +78 -0
- package/dist/evidence/observability.d.ts +38 -0
- package/dist/evidence/observability.js +40 -0
- package/dist/evidence/page-teardown.d.ts +15 -0
- package/dist/evidence/page-teardown.js +17 -0
- package/dist/evidence/step-effect.d.ts +41 -0
- package/dist/evidence/step-effect.js +27 -0
- package/dist/evidence/uncaptured-bodies.d.ts +23 -0
- package/dist/evidence/uncaptured-bodies.js +41 -0
- package/dist/evidence/undeclared-change.d.ts +51 -0
- package/dist/evidence/undeclared-change.js +56 -0
- package/dist/evidence/unread-outcome.d.ts +10 -0
- package/dist/evidence/unread-outcome.js +77 -0
- package/dist/evidence/unsettled.d.ts +58 -0
- package/dist/evidence/unsettled.js +127 -0
- package/dist/evidence/verdict-intent-gap.d.ts +30 -0
- package/dist/evidence/verdict-intent-gap.js +35 -0
- package/dist/evidence/verified.d.ts +158 -0
- package/dist/evidence/verified.js +378 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +25 -0
- package/dist/question/declared.d.ts +74 -0
- package/dist/question/declared.js +171 -0
- package/dist/question/lineage.d.ts +52 -0
- package/dist/question/lineage.js +122 -0
- package/dist/question/predicate/net-evidence.d.ts +21 -0
- package/dist/question/predicate/net-evidence.js +81 -0
- package/dist/question/predicate/observed-in-window.d.ts +24 -0
- package/dist/question/predicate/observed-in-window.js +38 -0
- package/dist/question/predicate/predicate-asks.d.ts +28 -0
- package/dist/question/predicate/predicate-asks.js +46 -0
- package/dist/question/predicate/predicate-console.d.ts +13 -0
- package/dist/question/predicate/predicate-console.js +138 -0
- package/dist/question/predicate/predicate-element.d.ts +13 -0
- package/dist/question/predicate/predicate-element.js +214 -0
- package/dist/question/predicate/predicate-eval-kit.d.ts +90 -0
- package/dist/question/predicate/predicate-eval-kit.js +126 -0
- package/dist/question/predicate/predicate-eval.d.ts +24 -0
- package/dist/question/predicate/predicate-eval.js +710 -0
- package/dist/question/predicate/predicate-parse.d.ts +15 -0
- package/dist/question/predicate/predicate-parse.js +173 -0
- package/dist/question/predicate/predicate-precheck.d.ts +8 -0
- package/dist/question/predicate/predicate-precheck.js +41 -0
- package/dist/question/predicate/predicate-request-body.d.ts +50 -0
- package/dist/question/predicate/predicate-request-body.js +120 -0
- package/dist/question/predicate/predicate-route.d.ts +66 -0
- package/dist/question/predicate/predicate-route.js +293 -0
- package/dist/question/predicate/predicate-schema.d.ts +170 -0
- package/dist/question/predicate/predicate-schema.js +509 -0
- package/dist/question/predicate/predicate-session.d.ts +72 -0
- package/dist/question/predicate/predicate-session.js +1 -0
- package/dist/question/predicate/predicate-to-links.d.ts +13 -0
- package/dist/question/predicate/predicate-to-links.js +38 -0
- package/dist/question/predicate/predicate.d.ts +26 -0
- package/dist/question/predicate/predicate.js +785 -0
- package/dist/question/predicate/property.d.ts +102 -0
- package/dist/question/predicate/property.js +135 -0
- package/dist/question/predicate/split-text-miss.d.ts +32 -0
- package/dist/question/predicate/split-text-miss.js +51 -0
- package/dist/question/predicate/testid-near-miss.d.ts +22 -0
- package/dist/question/predicate/testid-near-miss.js +33 -0
- package/dist/question/reaction.d.ts +17 -0
- package/dist/question/reaction.js +67 -0
- package/dist/window/adversary.d.ts +28 -0
- package/dist/window/adversary.js +90 -0
- package/dist/window/ambient.d.ts +63 -0
- package/dist/window/ambient.js +76 -0
- package/dist/window/appearance-budget.d.ts +41 -0
- package/dist/window/appearance-budget.js +47 -0
- package/dist/window/asset-noise.d.ts +42 -0
- package/dist/window/asset-noise.js +35 -0
- package/dist/window/body-relevance.d.ts +54 -0
- package/dist/window/body-relevance.js +78 -0
- package/dist/window/byte-size.d.ts +1 -0
- package/dist/window/byte-size.js +16 -0
- package/dist/window/engine-host.d.ts +35 -0
- package/dist/window/engine-host.js +20 -0
- package/dist/window/event-filters.d.ts +121 -0
- package/dist/window/event-filters.js +215 -0
- package/dist/window/json-salvage.d.ts +33 -0
- package/dist/window/json-salvage.js +96 -0
- package/dist/window/network-detail-merge.d.ts +8 -0
- package/dist/window/network-detail-merge.js +89 -0
- package/dist/window/ring-buffer.d.ts +41 -0
- package/dist/window/ring-buffer.js +152 -0
- package/package.json +71 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
import { ContradictionKind, EventType, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
|
|
2
|
+
import { describeSuperseded } from '../question/predicate/observed-in-window.js';
|
|
3
|
+
import { describe, isMutating, isSameDocumentHashAnchor, isSteadyCadence, netCall, recoveredByRetry, splitForeignTraffic, } from './contradiction-evidence.js';
|
|
4
|
+
import { findStaleResponses } from './stale-response.js';
|
|
5
|
+
import { findBodyFailures } from './body-failures.js';
|
|
6
|
+
import { findEchoMismatches } from './echo-mismatch.js';
|
|
7
|
+
import { findUnitMismatches } from './unit-mismatch.js';
|
|
8
|
+
import { asString } from '@reticlehq/core';
|
|
9
|
+
import { matchesDeclaredFailure } from '../question/declared.js';
|
|
10
|
+
import { runRegisteredFolds } from './contradiction-folds.js';
|
|
11
|
+
/**
|
|
12
|
+
* The contradiction hunter.
|
|
13
|
+
*
|
|
14
|
+
* Every other check reads ONE channel and asks "did something bad happen there?". This asks what a
|
|
15
|
+
* person watching the screen structurally cannot: do the channels DISAGREE? The DOM, the store, the
|
|
16
|
+
* app's own signals, the console and the network arrive in one causally ordered window, so the case
|
|
17
|
+
* where the screen says one thing and the network says the opposite is visible — and that gap is
|
|
18
|
+
* where false greens live, because a screenshot, a DOM assertion and a human all agree there.
|
|
19
|
+
*
|
|
20
|
+
* Pure: a window of events in, findings out. No session, no IO, no clock.
|
|
21
|
+
*/
|
|
22
|
+
function uiAdvanced(events) {
|
|
23
|
+
return events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
24
|
+
e.type === EventType.DOM_REMOVED ||
|
|
25
|
+
e.type === EventType.DOM_ATTR ||
|
|
26
|
+
e.type === EventType.DOM_TEXT ||
|
|
27
|
+
e.type === EventType.STATE_CHANGE ||
|
|
28
|
+
e.type === EventType.ROUTE_CHANGE);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* State paths/values that read as the app recording a failure rather than hiding one.
|
|
32
|
+
*
|
|
33
|
+
* English-only, and knowingly so — this is the softest edge in the file. It is a fallback for when
|
|
34
|
+
* the structural check below cannot decide, not the primary signal.
|
|
35
|
+
*/
|
|
36
|
+
const ACKNOWLEDGED = /error|fail|invalid|reject|denied|unable|could not|couldn't/i;
|
|
37
|
+
/**
|
|
38
|
+
* Below this length an error string is too generic to be evidence — "no", "err", a bare code — and
|
|
39
|
+
* could coincide with unrelated state text.
|
|
40
|
+
*/
|
|
41
|
+
const MIN_ECHOED_ERROR_LENGTH = 8;
|
|
42
|
+
/**
|
|
43
|
+
* Wording that blames the USER — bad credentials, no permission, wrong input. Distinct from
|
|
44
|
+
* ACKNOWLEDGED, which merely means "a failure was recorded": an app can honestly report a failure
|
|
45
|
+
* ("server error, try again") without misattributing it.
|
|
46
|
+
*/
|
|
47
|
+
const BLAMES_USER = /denied|invalid|unauthor|forbidden|incorrect|wrong |not allowed|not permitted/i;
|
|
48
|
+
/** A server-fault status: the user cannot fix it and should never be asked to. */
|
|
49
|
+
const SERVER_FAULT_MIN = 500;
|
|
50
|
+
/**
|
|
51
|
+
* Did the app record the failure in its OWN state — the layer the UI renders from?
|
|
52
|
+
*
|
|
53
|
+
* Without this, "the UI moved while a request failed" fires on correct code: a handler that catches
|
|
54
|
+
* the rejection and renders "could not add" also moves the UI. Both look identical at the level of
|
|
55
|
+
* "DOM changed + request failed"; what separates them is whether the app acknowledged the failure
|
|
56
|
+
* anywhere, or silently proceeded as if it had succeeded.
|
|
57
|
+
*
|
|
58
|
+
* Deliberately NOT satisfied by a console error. `console.error` is invisible to the user, so an app
|
|
59
|
+
* that logs and then shows success is still lying to whoever is looking at it — precisely the case
|
|
60
|
+
* worth reporting.
|
|
61
|
+
*
|
|
62
|
+
* A heuristic, and the one soft edge in this file: an app that surfaces failure through a value this
|
|
63
|
+
* pattern does not recognize will produce a finding a human must dismiss. That direction is the safe
|
|
64
|
+
* one — a false alarm costs a glance, a missed false green ships.
|
|
65
|
+
*/
|
|
66
|
+
function failureAcknowledged(events) {
|
|
67
|
+
// STRUCTURAL first, and language-independent: if the app put the failed call's OWN error text into
|
|
68
|
+
// its state, it plainly knows the call failed — whatever language it says so in. The lexical
|
|
69
|
+
// patterns below are English-only, so without this a German or Japanese app that surfaces its
|
|
70
|
+
// failure perfectly well would be reported as hiding it.
|
|
71
|
+
const errors = events
|
|
72
|
+
.filter((e) => e.type === EventType.NET_REQUEST && e.data['ok'] !== true)
|
|
73
|
+
.map((e) => asString(e.data['error']))
|
|
74
|
+
.filter((text) => text !== undefined && text.length >= MIN_ECHOED_ERROR_LENGTH);
|
|
75
|
+
const echoesAnError = events.some((e) => {
|
|
76
|
+
if (e.type !== EventType.STATE_CHANGE)
|
|
77
|
+
return false;
|
|
78
|
+
const value = asString(e.data['value']);
|
|
79
|
+
return value !== undefined && errors.some((text) => value.includes(text));
|
|
80
|
+
});
|
|
81
|
+
if (echoesAnError)
|
|
82
|
+
return true;
|
|
83
|
+
return events.some((e) => {
|
|
84
|
+
// A failure-shaped SIGNAL is an acknowledgement too. An app that fires `auth:denied` has plainly
|
|
85
|
+
// not proceeded as if it succeeded, whatever its state paths happen to be named.
|
|
86
|
+
if (e.type === EventType.SIGNAL)
|
|
87
|
+
return ACKNOWLEDGED.test(asString(e.data['name']) ?? '');
|
|
88
|
+
if (e.type !== EventType.STATE_CHANGE)
|
|
89
|
+
return false;
|
|
90
|
+
const path = asString(e.data['path']) ?? '';
|
|
91
|
+
const value = e.data['value'];
|
|
92
|
+
return ACKNOWLEDGED.test(path) || ('string' === typeof value && ACKNOWLEDGED.test(value));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const MUST_DO_SOMETHING = new Set(['click', 'dblclick', 'submit']);
|
|
96
|
+
/**
|
|
97
|
+
* Whether NOTHING in this window is attributable to the action.
|
|
98
|
+
*
|
|
99
|
+
* Ambient churn is deliberately not counted as evidence the action worked — a background event
|
|
100
|
+
* stream, a polling store, a perf sample and a scroll position all move on their own. What counts:
|
|
101
|
+
*
|
|
102
|
+
* - a mutation inside the target's own subtree (what the target itself did),
|
|
103
|
+
* - a request (the action asked the server for something),
|
|
104
|
+
* - a navigation, or a dialog/live region appearing — the two ways a real reaction legitimately
|
|
105
|
+
* lands OUTSIDE the target, e.g. a modal portalled to the body.
|
|
106
|
+
*
|
|
107
|
+
* The last clause is what keeps this from manufacturing noise: a button that opens a modal mutates
|
|
108
|
+
* nothing within itself, and must not be called dead.
|
|
109
|
+
*/
|
|
110
|
+
function didNothing(events, requests, mutatedWithin) {
|
|
111
|
+
if (mutatedWithin === undefined)
|
|
112
|
+
return 0 === events.length;
|
|
113
|
+
if (mutatedWithin > 0 || requests.length > 0)
|
|
114
|
+
return false;
|
|
115
|
+
return !events.some((e) => e.type === EventType.ROUTE_CHANGE || e.type === EventType.VISIBLE_SHOWN);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Was the page HIDDEN at any point in this window?
|
|
119
|
+
*
|
|
120
|
+
* A backgrounded tab has its rAF and timers clamped by the browser, and the DOM observer flushes on
|
|
121
|
+
* rAF — so real mutations are never emitted. The window then looks silent when the app in fact
|
|
122
|
+
* rendered, and every absence-derived rule reads that silence as a fault.
|
|
123
|
+
*
|
|
124
|
+
* MEASURED, not theorised: a crawl over bench-app reported `state-vs-render` on a ⌘K button whose
|
|
125
|
+
* click both committed `paletteOpen: true` and mounted the palette inside `#root`. The recorded
|
|
126
|
+
* window held the store change, the app's own `palette:opened` signal, no DOM event whatsoever, and
|
|
127
|
+
* two `page.health` heartbeats reading `hidden: true`.
|
|
128
|
+
*
|
|
129
|
+
* ANY hidden heartbeat disqualifies the whole window rather than the part after it: the flush that
|
|
130
|
+
* was suppressed could be any of them, and a window that was hidden for part of its life cannot say
|
|
131
|
+
* which part lost events.
|
|
132
|
+
*/
|
|
133
|
+
function pageWasHidden(events, options) {
|
|
134
|
+
// The caller states it when it knows. A heartbeat landing inside the window is the fallback, not
|
|
135
|
+
// the mechanism — see the option doc for why the window alone cannot be trusted to carry one.
|
|
136
|
+
if (options.pageHidden !== undefined)
|
|
137
|
+
return options.pageHidden;
|
|
138
|
+
return events.some((e) => e.type === EventType.PAGE_HEALTH &&
|
|
139
|
+
true === e.data?.hidden);
|
|
140
|
+
}
|
|
141
|
+
/** Net-shaped events — the only ones that carry a URL a dev-tooling channel could occupy. */
|
|
142
|
+
export function findContradictions(allEvents, options = {}) {
|
|
143
|
+
const all = findWindowContradictions(allEvents, options);
|
|
144
|
+
// Filtered here rather than inside each rule, so a rule added later inherits the guard by being
|
|
145
|
+
// classified absence-derived — the one place that already knows which findings rest on silence.
|
|
146
|
+
// Hiding can only manufacture ABSENCE: a failed request or a contradicting channel is something
|
|
147
|
+
// that WAS seen, so evidence-derived findings are untouched and still report.
|
|
148
|
+
const found = pageWasHidden(allEvents, options)
|
|
149
|
+
? all.filter((c) => !isAbsenceDerived(c.kind))
|
|
150
|
+
: all;
|
|
151
|
+
const predates = allEvents.length > 0 &&
|
|
152
|
+
allEvents.every((e) => !isSameEditEpoch(e.editEpoch, options.currentEditEpoch));
|
|
153
|
+
if (!predates)
|
|
154
|
+
return found;
|
|
155
|
+
// Prepended, not appended: the caveat governs how everything under it should be read, and it has
|
|
156
|
+
// to survive the rules that return early with a single finding of their own.
|
|
157
|
+
return [
|
|
158
|
+
{
|
|
159
|
+
kind: ContradictionKind.EVIDENCE_PREDATES_EDIT,
|
|
160
|
+
claim: 'these observations describe the code as it is now',
|
|
161
|
+
counter: 'every one of them was recorded before the last hot update landed in the page',
|
|
162
|
+
detail: 'the source changed and the page re-rendered after this evidence was captured, so it describes code that has since been replaced — nothing here is necessarily wrong, but nothing here has seen the edit either. Drive the app again to verify the current code',
|
|
163
|
+
},
|
|
164
|
+
...found,
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
function findWindowContradictions(allEvents, options) {
|
|
168
|
+
const found = [];
|
|
169
|
+
const { app: allApp, ignored: ignoredForeign } = splitForeignTraffic(allEvents, options.appOrigin);
|
|
170
|
+
// ── Evidence belonging to a document that has since been replaced ───────────────────────────
|
|
171
|
+
// Scoped ONCE, here, for the same reason the dev-tooling split is: every rule below asks "what
|
|
172
|
+
// else was in this window", and answering that with a dead page's traffic is a defect in all of
|
|
173
|
+
// them rather than in whichever one reported it. Applied after the dev-tooling split so the count
|
|
174
|
+
// reported below is the app's own evidence and not the toolchain's noise.
|
|
175
|
+
const scoped = allApp.filter((e) => isSameDocument(e.documentId, options.currentDocumentId));
|
|
176
|
+
const superseded = allApp.length - scoped.length;
|
|
177
|
+
// An empty window was always allowed to mean "nothing happened"; that reading is only unsafe once
|
|
178
|
+
// supersession is what emptied it. Reported ALONE and before every rule below, because a window
|
|
179
|
+
// with nothing left in it is exactly the shape `action-had-no-effect` fires on — so without this
|
|
180
|
+
// the fix would have swapped a wrong citation for a wrong accusation.
|
|
181
|
+
if (superseded > 0 && 0 === scoped.length) {
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
kind: ContradictionKind.EVIDENCE_SUPERSEDED,
|
|
185
|
+
claim: 'this window holds observations that could answer for the action',
|
|
186
|
+
counter: describeSuperseded('observations', superseded),
|
|
187
|
+
detail: 'a full navigation or a reload built a new document, and everything recorded here belongs to the old one — citing it would name requests, errors and state that no longer describe anything on screen',
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
// ── Evidence that predates the action ───────────────────────────────────────────────────────
|
|
192
|
+
// The attribution floor, and it is scoped ONCE here for the same reason the two filters above are:
|
|
193
|
+
// a rule that reads "what else was in this window" and gets handed traffic from before the caller
|
|
194
|
+
// acted is not refining its answer, it is answering about somebody else's action. Three rules
|
|
195
|
+
// (`duplicate-request`, `signal-without-consequence`, `consequence-elsewhere`) each checked this
|
|
196
|
+
// for themselves and the other six swept the whole window — which is how an assert with no `since`
|
|
197
|
+
// came to be judged against everything that had ever happened in the tab.
|
|
198
|
+
//
|
|
199
|
+
// Undefined means nothing attributed the window to an action at all; the floor then does nothing,
|
|
200
|
+
// and the consequence rules below decline to speak instead. See `advanced`.
|
|
201
|
+
const floor = options.actionSince;
|
|
202
|
+
const events = floor === undefined ? scoped : scoped.filter((e) => e.t >= floor);
|
|
203
|
+
const settled = events.filter((e) => e.type === EventType.NET_REQUEST).map(netCall);
|
|
204
|
+
// ── Overlapping reads that settled out of order ─────────────────────────────────────────────
|
|
205
|
+
// Independent of any action, so it runs on every window: the race is a property of the timeline.
|
|
206
|
+
found.push(...findStaleResponses(events));
|
|
207
|
+
// ── A 2xx whose BODY says it failed ─────────────────────────────────────────────────────────
|
|
208
|
+
// Needs body capture; silent without it, which is why the assert path also declares when bodies
|
|
209
|
+
// were never recorded rather than letting an unread payload read as an empty one.
|
|
210
|
+
found.push(...findBodyFailures(events));
|
|
211
|
+
found.push(...findEchoMismatches(events, options.actionSince));
|
|
212
|
+
// ── A money value written back at the wrong SCALE ───────────────────────────────────────────
|
|
213
|
+
found.push(...findUnitMismatches(events, options.prior ?? []));
|
|
214
|
+
// ── The action landed on something that does not react ──────────────────────────────────────
|
|
215
|
+
// Checked first and returned alone: nothing is attributable to the action, so every rule below is
|
|
216
|
+
// reasoning about someone else's events.
|
|
217
|
+
const action = (options.action ?? '').toLowerCase();
|
|
218
|
+
if (MUST_DO_SOMETHING.has(action) && didNothing(events, settled, options.mutatedWithin)) {
|
|
219
|
+
const measured = options.mutatedWithin !== undefined;
|
|
220
|
+
return [
|
|
221
|
+
{
|
|
222
|
+
kind: ContradictionKind.ACTION_HAD_NO_EFFECT,
|
|
223
|
+
claim: `the ${action} was dispatched and the page settled`,
|
|
224
|
+
counter: measured
|
|
225
|
+
? 'nothing changed inside the target, and no request, navigation or dialog followed — whatever else moved on the page was not this'
|
|
226
|
+
: 'no channel observed anything at all — DOM, store, route, network, signal, console',
|
|
227
|
+
detail: 'the target does not react to this action (a non-interactive wrapper resolved instead of the control, a disabled handler, or a no-op) — settling proves only that the page was quiet, which a page that did nothing always is',
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
// A failure the app RECOVERED from is not evidence against anything.
|
|
232
|
+
//
|
|
233
|
+
// Reported from the field on an app whose api-client documents the pattern every token-refreshing
|
|
234
|
+
// app has: a 401 re-hydrates the session and retries once. One extraction produced a 401 and then
|
|
235
|
+
// a 200 to the same endpoint, with exactly one extraction in state, and Reticle called it two
|
|
236
|
+
// separate contradictions. Both were false, both cost calls to disprove, and a rule that
|
|
237
|
+
// manufactures reds costs more trust than a missed bug does.
|
|
238
|
+
//
|
|
239
|
+
// Structural, not a timing heuristic: what makes it a retry is that a LATER call to the same
|
|
240
|
+
// method and url SUCCEEDED. The write landed, so the UI was entitled to move and a success signal
|
|
241
|
+
// was entitled to fire. Filtered at the definition rather than at the two reading sites, because
|
|
242
|
+
// both rules make the same claim about the same evidence and a fix in one is a fix in half.
|
|
243
|
+
const recovered = recoveredByRetry(settled);
|
|
244
|
+
const failed = settled.filter((c) => false === c.ok && !recovered.has(c));
|
|
245
|
+
// The failures NOBODY declared — see ContradictionOptions.expectedFailures. Only the heuristic
|
|
246
|
+
// "the UI moved while a request failed" rule reads this; the sharp rules still read `failed`.
|
|
247
|
+
const unexpected = failed.filter((c) => !matchesDeclaredFailure(c, options.expectedFailures ?? []));
|
|
248
|
+
/**
|
|
249
|
+
* Did the UI move — and is anybody entitled to say so?
|
|
250
|
+
*
|
|
251
|
+
* `undefined` is the third answer and the point of the tri-state: "the UI moved forward while a
|
|
252
|
+
* request failed" is a claim about CAUSATION, and over a window nothing attributed to an action
|
|
253
|
+
* the two halves merely co-occurred. A passive `reticle_assert` performs nothing, so ambient
|
|
254
|
+
* traffic — a poll, a page-load bootstrap, a branding call — is not its consequence and must not
|
|
255
|
+
* decide its verdict.
|
|
256
|
+
*
|
|
257
|
+
* Typed rather than gated with a boolean so it cannot be skipped: every rule that reasons from UI
|
|
258
|
+
* movement has to answer `undefined` explicitly, including one added later. The rules that read
|
|
259
|
+
* the app's OWN claims (a success signal over a failed call) or its payloads (a 2xx whose body
|
|
260
|
+
* says it failed, a field echoed back wrong) are untouched — those are things the app said, not
|
|
261
|
+
* consequences anybody inferred, and they are true whoever caused them.
|
|
262
|
+
*/
|
|
263
|
+
const advanced = floor === undefined ? undefined : uiAdvanced(events);
|
|
264
|
+
const signals = events
|
|
265
|
+
.filter((e) => e.type === EventType.SIGNAL)
|
|
266
|
+
.map((e) => asString(e.data['name']) ?? 'signal');
|
|
267
|
+
// ── The route moved and nothing was rendered for it ─────────────────────────────────────────
|
|
268
|
+
// A navigation that neither fetches nor renders arrived nowhere. Distinct from a dead control:
|
|
269
|
+
// the control worked, the DESTINATION is empty — which is why every "did the click do something"
|
|
270
|
+
// heuristic passes it, a route change being unambiguously something.
|
|
271
|
+
const routeEvents = events.filter((e) => e.type === EventType.ROUTE_CHANGE);
|
|
272
|
+
const routed = routeEvents.length > 0;
|
|
273
|
+
// A skip link (`href="#main-content"`) is a same-document hash change. The observable
|
|
274
|
+
// consequences are location.hash, focus, and scroll — not a DOM mutation. Treating it as a
|
|
275
|
+
// blank destination made "did my skip link work" unanswerable. Hash-router paths (`#/invoices`)
|
|
276
|
+
// still go through the rule: those ARE a new view.
|
|
277
|
+
const hashAnchorOnly = routed && routeEvents.every(isSameDocumentHashAnchor);
|
|
278
|
+
// `dom.text` counts as rendered, and it has to: React reconciles a destination IN PLACE far more
|
|
279
|
+
// often than it adds nodes. Measured on three ordinary sidebar navigations of the bench app — every
|
|
280
|
+
// one emitted { dom.attr:2, dom.text:2, render.commit, state.change } and ZERO dom.added/removed,
|
|
281
|
+
// so all three were flagged as blank destinations, `verified` came back "no" on a correct green,
|
|
282
|
+
// and a bug_found was emitted for a navigation that worked.
|
|
283
|
+
//
|
|
284
|
+
// Deliberately NOT `dom.attr`: the nav link marks itself active whether or not the destination
|
|
285
|
+
// rendered, which is the true positive this rule exists for. Deliberately NOT `render.commit`
|
|
286
|
+
// either: React commits a render for a component that returns null, which is one of the very bugs
|
|
287
|
+
// named in `detail` below.
|
|
288
|
+
const rendered = events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
289
|
+
e.type === EventType.DOM_REMOVED ||
|
|
290
|
+
e.type === EventType.DOM_TEXT);
|
|
291
|
+
const fetched = events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING);
|
|
292
|
+
if (routed && !hashAnchorOnly && !rendered && !fetched && true !== options.renderProved) {
|
|
293
|
+
// A console error in the SAME window turns "nothing rendered" from an absence into a positive
|
|
294
|
+
// claim: the destination did not merely fail to produce content, it crashed while trying to.
|
|
295
|
+
// Reported once as `unknown` when this held — a React hooks error and an empty destination were
|
|
296
|
+
// both in hand, and the honest, definitive answer was available and not given (#897).
|
|
297
|
+
const consoleErrors = events
|
|
298
|
+
.filter((e) => e.type === EventType.CONSOLE_ERROR)
|
|
299
|
+
.map((e) => asString(e.data['message']))
|
|
300
|
+
.filter((m) => undefined !== m && m.length > 0);
|
|
301
|
+
if (consoleErrors.length > 0) {
|
|
302
|
+
found.push({
|
|
303
|
+
kind: ContradictionKind.ROUTE_RENDERED_NOTHING_CRASHED,
|
|
304
|
+
claim: 'the app navigated to a new route',
|
|
305
|
+
counter: `nothing was rendered for it, and the console shows why: ${consoleErrors[0] ?? ''}`,
|
|
306
|
+
detail: `the URL moved but the destination produced no content, and the same window logged ` +
|
|
307
|
+
`${String(consoleErrors.length)} console error(s) — the first: "${consoleErrors[0] ?? ''}". ` +
|
|
308
|
+
'The destination crashed rather than merely rendering nothing; read the error for the ' +
|
|
309
|
+
'component and line at fault.',
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
found.push({
|
|
314
|
+
kind: ContradictionKind.ROUTE_RENDERED_NOTHING,
|
|
315
|
+
claim: 'the app navigated to a new route',
|
|
316
|
+
counter: 'nothing was rendered for it — no content added or removed, and no request made',
|
|
317
|
+
detail: 'the URL moved but the destination produced no content: a route with no view, a view that returned null, or data the page never asked for. A control that navigates always looks alive, so this is invisible to a dead-control check. Confirm by reading the page — a view revealed from DOM that already existed emits this same window',
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// ── The app claimed success while its own request failed ────────────────────────────────────
|
|
322
|
+
// A signal is the sharper claim: the app did not merely LOOK right, it explicitly asserted
|
|
323
|
+
// success. When both hold it is one fact, so only the sharper one is reported.
|
|
324
|
+
// ── The server faulted and the app blamed the user ──────────────────────────────────────────
|
|
325
|
+
// Checked BEFORE the success-claim rules, because it is the sharper reading of the same events:
|
|
326
|
+
// the app did not claim success, it claimed the wrong failure. Telling someone their password is
|
|
327
|
+
// wrong while the backend is down sends them to fix something they cannot fix.
|
|
328
|
+
const serverFaults = settled.filter((c) => false === c.ok && c.status !== undefined && c.status >= SERVER_FAULT_MIN);
|
|
329
|
+
const userBlame = [
|
|
330
|
+
...signals.filter((name) => BLAMES_USER.test(name)),
|
|
331
|
+
...events
|
|
332
|
+
.filter((e) => e.type === EventType.STATE_CHANGE)
|
|
333
|
+
.map((e) => asString(e.data['value']) ?? '')
|
|
334
|
+
.filter((value) => BLAMES_USER.test(value)),
|
|
335
|
+
];
|
|
336
|
+
const misattributed = serverFaults.length > 0 && userBlame.length > 0;
|
|
337
|
+
if (misattributed) {
|
|
338
|
+
found.push({
|
|
339
|
+
kind: ContradictionKind.FAILURE_MISATTRIBUTED,
|
|
340
|
+
claim: `the app told the user they were at fault (${userBlame.map((b) => `"${b}"`).join(', ')})`,
|
|
341
|
+
counter: 'the server returned a 5xx — the user cannot fix this and the real fault is unreported',
|
|
342
|
+
detail: serverFaults.map(describe).join('; '),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
// A failure-shaped signal is not a success claim, so it must not be read as one: saying "the app
|
|
346
|
+
// claimed success" about an app that plainly reported a failure is true in outline and wrong in
|
|
347
|
+
// its reasoning, which is how a checker stops being believed.
|
|
348
|
+
const successSignals = signals.filter((name) => !ACKNOWLEDGED.test(name));
|
|
349
|
+
// An app that RETRACTED has not claimed success, whenever it fired the optimistic signal.
|
|
350
|
+
//
|
|
351
|
+
// The weaker UI rule below already consulted this and the sharper signal rule did not, so an app
|
|
352
|
+
// that announced "ack:requested", met a 500, and then correctly emitted "ack:failed" and rolled the
|
|
353
|
+
// row back was reported as explicitly asserting success — the strongest accusation this file makes,
|
|
354
|
+
// against code doing exactly the right thing. On a fixture suite the scenario's FIXED twin produced
|
|
355
|
+
// the same finding as the build that swallowed the failure, which makes the finding worthless on
|
|
356
|
+
// the one measurement that scores precision.
|
|
357
|
+
//
|
|
358
|
+
// Ordering cannot decide this: an optimistic UI legitimately fires its success signal BEFORE the
|
|
359
|
+
// response, so "the claim must follow the failure" would miss the real defect. What separates them
|
|
360
|
+
// is not when the app spoke, it is whether it took it back.
|
|
361
|
+
// WHAT failed decides this, not whether an action was attributed.
|
|
362
|
+
//
|
|
363
|
+
// The claim is a thing the app said, so the attribution floor does not apply to it — the flagship
|
|
364
|
+
// false green is an app asserting success on a PASSIVE assert while its own write failed, and
|
|
365
|
+
// requiring an action would lose exactly that. But the COUNTER was any failure in the window, and
|
|
366
|
+
// that is the same window statement scoped out of every other rule here. Measured: two of the
|
|
367
|
+
// three false positives surviving the first scoping pass were this rule.
|
|
368
|
+
//
|
|
369
|
+
// A success signal claims a CHANGE was made. A failed mutation is evidence against that claim; a
|
|
370
|
+
// failed read is not. Background polls, prefetches and telemetry GETs fail constantly in healthy
|
|
371
|
+
// apps and say nothing about whether a write landed. Structural, not a timing heuristic, and the
|
|
372
|
+
// distinction was already encoded next door in `isMutating`.
|
|
373
|
+
const failedWrites = failed.filter(isMutating);
|
|
374
|
+
// The same scoping, for the same reason, one branch down. "The UI moved forward" is also a claim
|
|
375
|
+
// that something CHANGED, and it was still reading ANY failure — so a first-party poll failing
|
|
376
|
+
// during an action contradicted a verdict the action had genuinely earned. Measured on the
|
|
377
|
+
// observation benchmark: one of two false positives across 47 cells, and the argument for it is
|
|
378
|
+
// the paragraph above, which had simply not been carried down here.
|
|
379
|
+
const unexpectedWrites = unexpected.filter(isMutating);
|
|
380
|
+
if (failedWrites.length > 0 && successSignals.length > 0 && !failureAcknowledged(events)) {
|
|
381
|
+
found.push({
|
|
382
|
+
kind: ContradictionKind.SIGNAL_CONTRADICTED,
|
|
383
|
+
claim: `the app fired ${successSignals.map((s) => `"${s}"`).join(', ')}`,
|
|
384
|
+
counter: `${String(failedWrites.length)} write(s) in the same window failed`,
|
|
385
|
+
detail: failedWrites.map(describe).join('; '),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
else if (unexpectedWrites.length > 0 &&
|
|
389
|
+
true === advanced &&
|
|
390
|
+
!misattributed &&
|
|
391
|
+
!failureAcknowledged(events)) {
|
|
392
|
+
found.push({
|
|
393
|
+
kind: ContradictionKind.UI_ADVANCED_REQUEST_FAILED,
|
|
394
|
+
claim: 'the UI moved forward (DOM/store/route changed)',
|
|
395
|
+
counter: `${String(unexpectedWrites.length)} request(s) in the same window failed`,
|
|
396
|
+
detail: unexpectedWrites.map(describe).join('; '),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
// ── A write succeeded and nothing on the client moved ───────────────────────────────────────
|
|
400
|
+
// Writes only: a GET that changes nothing is a prefetch; a POST that changes nothing is a lost
|
|
401
|
+
// write, a response parsed into the void, or a render that never happened.
|
|
402
|
+
if (false === advanced) {
|
|
403
|
+
const ignoredWrites = settled.filter((c) => true === c.ok && isMutating(c));
|
|
404
|
+
if (ignoredWrites.length > 0) {
|
|
405
|
+
// ...unless THIS document handed the consequence to another browsing context. An OAuth sign-in
|
|
406
|
+
// posts, succeeds, and continues in a popup the in-page SDK cannot follow (#508): the original
|
|
407
|
+
// tab legitimately never changes, and response-ignored would accuse it of ignoring a response
|
|
408
|
+
// it handed off. The opened-context event flips the reading from "the client did nothing" to
|
|
409
|
+
// "the client went where we cannot look". Scoped like every rule here to the attribution floor
|
|
410
|
+
// (`options.actionSince`; the local below is declared later, for the window rules).
|
|
411
|
+
const contextFloor = options.actionSince;
|
|
412
|
+
const openedContext = events.some((e) => e.type === EventType.CONTEXT_OPENED && contextFloor !== undefined && e.t >= contextFloor);
|
|
413
|
+
found.push(openedContext
|
|
414
|
+
? {
|
|
415
|
+
kind: ContradictionKind.CONSEQUENCE_ELSEWHERE,
|
|
416
|
+
claim: `${String(ignoredWrites.length)} write(s) succeeded on the server`,
|
|
417
|
+
counter: 'this document never changed because the page opened another browsing context during this window (e.g. an OAuth popup), where the in-page SDK cannot observe the result',
|
|
418
|
+
detail: ignoredWrites.map(describe).join('; '),
|
|
419
|
+
}
|
|
420
|
+
: {
|
|
421
|
+
kind: ContradictionKind.RESPONSE_IGNORED,
|
|
422
|
+
claim: `${String(ignoredWrites.length)} write(s) succeeded on the server`,
|
|
423
|
+
counter: 'nothing on the client changed — no DOM, store or route movement',
|
|
424
|
+
detail: ignoredWrites.map(describe).join('; '),
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// ── The store committed and the screen never moved ─────────────────────────────────────────
|
|
429
|
+
//
|
|
430
|
+
// Scoped as tightly as the one below, and for the same reason: it fires on an ABSENCE, which is
|
|
431
|
+
// the easiest way to build a false positive. Only for a window attributed to an ACTION, only when
|
|
432
|
+
// state actually moved, only when NO DOM node moved with it, and only when nothing is still in
|
|
433
|
+
// flight that the render could legitimately be waiting on.
|
|
434
|
+
//
|
|
435
|
+
// Route movement counts as the screen moving: a navigation IS a render, and a store change that
|
|
436
|
+
// drives one has been corroborated.
|
|
437
|
+
//
|
|
438
|
+
// And only when the window carries NO NETWORK AT ALL. A request means the app reached for
|
|
439
|
+
// something, and whether it failed, was ignored or never settled already belongs to three other
|
|
440
|
+
// rules — firing here as well would report one fact twice, which is exactly the scoping the
|
|
441
|
+
// signal rule below had to earn. Two existing tests proved it: both describe a window with a
|
|
442
|
+
// failed call in it, and both were already answered by the rule that owns that fact.
|
|
443
|
+
if (options.actionSince !== undefined &&
|
|
444
|
+
events.some((e) => e.type === EventType.STATE_CHANGE) &&
|
|
445
|
+
!events.some((e) => e.type === EventType.NET_REQUEST || e.type === EventType.NET_PENDING) &&
|
|
446
|
+
!events.some((e) => e.type === EventType.DOM_ADDED ||
|
|
447
|
+
e.type === EventType.DOM_REMOVED ||
|
|
448
|
+
e.type === EventType.DOM_ATTR ||
|
|
449
|
+
e.type === EventType.DOM_TEXT ||
|
|
450
|
+
e.type === EventType.ROUTE_CHANGE)) {
|
|
451
|
+
found.push({
|
|
452
|
+
kind: ContradictionKind.STATE_VS_RENDER,
|
|
453
|
+
claim: 'the store committed a change',
|
|
454
|
+
counter: 'nothing rendered in the same window — no DOM node added, removed or changed, and no ' +
|
|
455
|
+
'route movement, with no request still in flight the render could be waiting on',
|
|
456
|
+
detail: 'a component that does not re-render on a committed change shows the OLD value while the ' +
|
|
457
|
+
'app is internally consistent, which is why nothing else reports it',
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
// ── The app announced a consequence and nothing else moved ─────────────────────────────────
|
|
461
|
+
// Scoped as tightly as the evidence allows, because this rule fires on the ABSENCE of everything
|
|
462
|
+
// else and that is the easiest way to build a false positive.
|
|
463
|
+
//
|
|
464
|
+
// Only when the window is otherwise EMPTY: no DOM, no store, no route (`!advanced`) and no request
|
|
465
|
+
// at all. A request means the app reached for something, and whether it settled, failed or was
|
|
466
|
+
// ignored belongs to three other rules — firing here too would report one fact twice.
|
|
467
|
+
//
|
|
468
|
+
// `successSignals` reuses the failure-shaped filter above: an app that announced `deploy:failed`
|
|
469
|
+
// is correctly reporting that nothing happened, and accusing it inverts the meaning of the one app
|
|
470
|
+
// doing this right.
|
|
471
|
+
//
|
|
472
|
+
// And only for a window attributed to an ACTION. `reticle_assert` OBSERVES — there is no click
|
|
473
|
+
// whose consequence should have corroborated anything, so an assert over a quiet window carrying
|
|
474
|
+
// one signal is an ordinary read, not a claim nothing backs. Without this the rule reddened eight
|
|
475
|
+
// existing tests that assert exactly that, which is the false-positive class this scoping exists
|
|
476
|
+
// to prevent.
|
|
477
|
+
if (options.actionSince !== undefined &&
|
|
478
|
+
false === advanced &&
|
|
479
|
+
0 === settled.length &&
|
|
480
|
+
successSignals.length > 0) {
|
|
481
|
+
found.push({
|
|
482
|
+
kind: ContradictionKind.SIGNAL_WITHOUT_CONSEQUENCE,
|
|
483
|
+
claim: `the app fired ${successSignals.map((s) => `"${s}"`).join(', ')}`,
|
|
484
|
+
counter: 'nothing else in the window moved — no DOM, no store, no route, no request — so the only ' +
|
|
485
|
+
'evidence that anything happened is the app saying so',
|
|
486
|
+
detail: 'a signal emitted from the value the app was ASKED for, rather than the one it committed, ' +
|
|
487
|
+
'reads identically to one that worked',
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
// ── The same write fired more than once, inside ONE action's window ─────────────────────────
|
|
491
|
+
// Attribution is the whole rule here, not a refinement of it: counting `method + url` over whatever
|
|
492
|
+
// window the caller handed in turns two legitimate separate saves into a double submit. See
|
|
493
|
+
// ContradictionOptions.actionSince.
|
|
494
|
+
//
|
|
495
|
+
// A captured request body joins the identity. A command-bus API posts every mutation to one URL
|
|
496
|
+
// and discriminates on a body field (`{"command":"study.stage.set"}` vs `{"command":"mesh.plan"}`),
|
|
497
|
+
// so under URL alone each of those distinct writes read as a repeat of the first, and clean
|
|
498
|
+
// verdicts degraded to unknown behind doubles that were never doubles. When no body was captured
|
|
499
|
+
// (capture off, or a non-text body, which reports a type marker instead) there is nothing to
|
|
500
|
+
// compare and the URL alone stands, as before; a window where only some calls carried bodies
|
|
501
|
+
// compares nothing rather than guess.
|
|
502
|
+
const actionSince = options.actionSince;
|
|
503
|
+
if (actionSince !== undefined) {
|
|
504
|
+
/**
|
|
505
|
+
* When the window navigated, and therefore when a write stops belonging to the user's action.
|
|
506
|
+
*
|
|
507
|
+
* React StrictMode double-invokes a mount effect in development, so clicking a nav link lands
|
|
508
|
+
* two identical writes inside the action's own window. Nothing scoped them out and they read as
|
|
509
|
+
* a double submit — measured on the observation benchmark as one of two false positives.
|
|
510
|
+
*
|
|
511
|
+
* The route change is the structural tell, not a heuristic: the claim this rule makes is "one
|
|
512
|
+
* user action was performed", and writes that follow a navigation belong to the mount of the
|
|
513
|
+
* view navigated TO. A real double submit fires from the view it is already on, with nothing in
|
|
514
|
+
* between — and one that navigates AFTER submitting is still counted, because the order is what
|
|
515
|
+
* distinguishes them.
|
|
516
|
+
*/
|
|
517
|
+
const navigatedAt = events.find((e) => EventType.ROUTE_CHANGE === e.type && e.t >= actionSince)?.t;
|
|
518
|
+
const writeTimes = new Map();
|
|
519
|
+
for (const event of events) {
|
|
520
|
+
if (event.type !== EventType.NET_REQUEST || event.t < actionSince)
|
|
521
|
+
continue;
|
|
522
|
+
if (navigatedAt !== undefined && event.t >= navigatedAt)
|
|
523
|
+
continue;
|
|
524
|
+
const call = netCall(event);
|
|
525
|
+
if (!isMutating(call))
|
|
526
|
+
continue;
|
|
527
|
+
const label = `${call.method} ${call.url}`;
|
|
528
|
+
const body = asString(event.data['requestBody']);
|
|
529
|
+
const key = body === undefined || 0 === body.length ? label : `${label} ${body}`;
|
|
530
|
+
const entry = writeTimes.get(key) ?? { label, times: [], landed: 0 };
|
|
531
|
+
entry.times.push(event.t);
|
|
532
|
+
// Counted separately from the occurrences, because the claim is about what APPLIED.
|
|
533
|
+
if (false !== call.ok)
|
|
534
|
+
entry.landed += 1;
|
|
535
|
+
writeTimes.set(key, entry);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Did the assertion name this endpoint?
|
|
539
|
+
*
|
|
540
|
+
* `undefined` means the caller declared nothing (a bare `observe`), and with nothing declared
|
|
541
|
+
* nothing is unrelated — every duplicate keeps the behaviour it had. An empty-string entry is a
|
|
542
|
+
* net clause with no `urlContains`, which named the whole channel and therefore matches
|
|
543
|
+
* everything.
|
|
544
|
+
*/
|
|
545
|
+
const named = options.namedNetUrls;
|
|
546
|
+
const wasNamed = (label) => named === undefined || named.some((u) => label.includes(u));
|
|
547
|
+
for (const [, { label, times, landed }] of writeTimes) {
|
|
548
|
+
if (times.length < 2)
|
|
549
|
+
continue;
|
|
550
|
+
// A DOUBLE SUBMIT is a write that landed twice. Two attempts of which one failed is a RETRY,
|
|
551
|
+
// and the field case is the commonest retry there is: a 401 that refreshed a token and went
|
|
552
|
+
// again, one row created, reported here as `duplicate-request ×2`. Two attempts that both
|
|
553
|
+
// failed are not a double submit either — nothing applied even once, so the claim "one user
|
|
554
|
+
// action was performed" is not contradicted by them. A call with no verdict at all still
|
|
555
|
+
// counts, because absence of a status is not evidence the write was rejected.
|
|
556
|
+
if (landed < 2)
|
|
557
|
+
continue;
|
|
558
|
+
// A steady cadence is a POLL, and a poll is not a double submit. An app that polls could not
|
|
559
|
+
// produce a verdict at all: a camera scan loop POSTing until it acquires a lock had every
|
|
560
|
+
// assertion that had already seen its consequence come back `unknown` behind writes that
|
|
561
|
+
// were the app working correctly (#673).
|
|
562
|
+
if (isSteadyCadence(times))
|
|
563
|
+
continue;
|
|
564
|
+
// A burst the assertion never mentioned is still worth telling the caller about -- a retry
|
|
565
|
+
// loop or a bursty beacon is a real finding -- but it is not evidence about the consequence
|
|
566
|
+
// they declared, so it is reported and decides nothing. The named case keeps its downgrade:
|
|
567
|
+
// "the write you asked about fired twice" is exactly what this rule is for.
|
|
568
|
+
const related = wasNamed(label);
|
|
569
|
+
found.push({
|
|
570
|
+
kind: related
|
|
571
|
+
? ContradictionKind.DUPLICATE_REQUEST
|
|
572
|
+
: ContradictionKind.DUPLICATE_REQUEST_UNRELATED,
|
|
573
|
+
claim: related
|
|
574
|
+
? 'one user action was performed'
|
|
575
|
+
: 'the assertion did not name this endpoint',
|
|
576
|
+
counter: `the same write fired ${String(times.length)} times`,
|
|
577
|
+
detail: `${label} ×${String(times.length)}`,
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
// ── The UI advanced over a request that never came back ─────────────────────────────────────
|
|
582
|
+
// Gated on the UI having moved: an in-flight request while the app is still visibly waiting is
|
|
583
|
+
// just a slow request, not a contradiction. It becomes one when the app proceeded regardless —
|
|
584
|
+
// which is also what makes a later `{ kind: "settled" }` assertion a false green.
|
|
585
|
+
if (true === advanced) {
|
|
586
|
+
const settledIds = new Set(events
|
|
587
|
+
.filter((e) => e.type === EventType.NET_REQUEST)
|
|
588
|
+
.map((e) => asString(e.data['id']))
|
|
589
|
+
.filter((id) => id !== undefined));
|
|
590
|
+
const inFlight = events
|
|
591
|
+
.filter((e) => e.type === EventType.NET_PENDING)
|
|
592
|
+
.map((e) => ({ id: asString(e.data['id']), call: netCall(e) }))
|
|
593
|
+
.filter((p) => p.id === undefined || !settledIds.has(p.id));
|
|
594
|
+
if (inFlight.length > 0) {
|
|
595
|
+
found.push({
|
|
596
|
+
kind: ContradictionKind.REQUEST_NEVER_SETTLED,
|
|
597
|
+
claim: 'the UI moved forward and the action reported done',
|
|
598
|
+
counter: `${String(inFlight.length)} request(s) were still in flight`,
|
|
599
|
+
// The exclusion is never silent: if the toolchain's own traffic was dropped from this count,
|
|
600
|
+
// the finding says which URLs, so an agent reading it can see what Reticle chose to ignore.
|
|
601
|
+
detail: [
|
|
602
|
+
inFlight.map((p) => describe(p.call)).join('; '),
|
|
603
|
+
...(0 === ignoredForeign.length
|
|
604
|
+
? []
|
|
605
|
+
: [`ignored as dev tooling or third-party: ${ignoredForeign.join(', ')}`]),
|
|
606
|
+
].join(' — '),
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
// Consumer rules run LAST and over the same app-only window, so a service embedding this engine
|
|
611
|
+
// adds to the verdict rather than forking the file that produces it.
|
|
612
|
+
return [...found, ...runRegisteredFolds(events, options)];
|
|
613
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReticleEvent } from '@reticlehq/core';
|
|
2
|
+
import type { OwnContradiction } from './contradiction-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Contradictions for writes whose response echoes a different value than the request asked for.
|
|
5
|
+
*
|
|
6
|
+
* `actionSince` is the attribution floor `findContradictions` already keeps — the event time the
|
|
7
|
+
* action that opened this window was dispatched. A finding about a request that had already settled
|
|
8
|
+
* before the agent acted otherwise reads as a verdict on the change it just made.
|
|
9
|
+
*/
|
|
10
|
+
export declare function findEchoMismatches(events: readonly ReticleEvent[], actionSince?: number): OwnContradiction[];
|