@reticlehq/engine 3.10.10 → 3.11.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.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A bounded list for the `detail` of a finding.
3
+ *
4
+ * On a page with a map, one `request-never-settled` finding listed every pending tile request. The
5
+ * compact result got so long that the client cut it, and the verdict was hard to find (#2496). A
6
+ * list here names at most `DETAIL_LIST_LIMIT` entries. It groups entries that share a prefix, and it
7
+ * returns `omitted`, so the finding can say how many entries the text does not name (rule 11). It
8
+ * also clips each name at `DETAIL_LABEL_LIMIT` characters, and returns `clipped` when it did.
9
+ */
10
+ /** The most entries, or groups of entries, that one list in a finding's detail names. */
11
+ export declare const DETAIL_LIST_LIMIT = 5;
12
+ /** The most characters of one name in a list. A URL can carry a query of any length. */
13
+ export declare const DETAIL_LABEL_LIMIT = 200;
14
+ /**
15
+ * One entry of a list: the text that names it, and the group it shares with similar entries.
16
+ * `first` puts its group ahead of the others when the list is cut, so the cut never hides it.
17
+ */
18
+ export interface ListEntry {
19
+ label: string;
20
+ group: string;
21
+ first?: boolean;
22
+ }
23
+ /** The joined text, how many entries it does not name, and whether it clipped a name. */
24
+ export interface BoundedList {
25
+ text: string;
26
+ omitted: number;
27
+ clipped: boolean;
28
+ }
29
+ /**
30
+ * Join `entries` with `separator`. A list at or under the limit comes back whole, in its order. A
31
+ * longer list is grouped: groups that hold a `first` entry come before the others, and otherwise
32
+ * keep their order. Each of the first `limit` groups names its first entry and counts the others
33
+ * under the group, and the groups past the limit are counted at the end.
34
+ */
35
+ export declare function boundedList(entries: readonly ListEntry[], separator: string, limit?: number): BoundedList;
36
+ /**
37
+ * The origin and the first path segment of a URL, as a group key: map tiles at
38
+ * `https://tiles.example.com/12/2048/1361.png` group under `https://tiles.example.com/12/`. A URL
39
+ * with one path segment is its own group. Text that is not a URL comes back as it is.
40
+ */
41
+ export declare function urlPrefix(url: string): string;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * A bounded list for the `detail` of a finding.
3
+ *
4
+ * On a page with a map, one `request-never-settled` finding listed every pending tile request. The
5
+ * compact result got so long that the client cut it, and the verdict was hard to find (#2496). A
6
+ * list here names at most `DETAIL_LIST_LIMIT` entries. It groups entries that share a prefix, and it
7
+ * returns `omitted`, so the finding can say how many entries the text does not name (rule 11). It
8
+ * also clips each name at `DETAIL_LABEL_LIMIT` characters, and returns `clipped` when it did.
9
+ */
10
+ /** The most entries, or groups of entries, that one list in a finding's detail names. */
11
+ export const DETAIL_LIST_LIMIT = 5;
12
+ /** The most characters of one name in a list. A URL can carry a query of any length. */
13
+ export const DETAIL_LABEL_LIMIT = 200;
14
+ /**
15
+ * Join `entries` with `separator`. A list at or under the limit comes back whole, in its order. A
16
+ * longer list is grouped: groups that hold a `first` entry come before the others, and otherwise
17
+ * keep their order. Each of the first `limit` groups names its first entry and counts the others
18
+ * under the group, and the groups past the limit are counted at the end.
19
+ */
20
+ export function boundedList(entries, separator, limit = DETAIL_LIST_LIMIT) {
21
+ let clipped = false;
22
+ const clip = (text) => {
23
+ if (text.length <= DETAIL_LABEL_LIMIT) {
24
+ return text;
25
+ }
26
+ clipped = true;
27
+ return `${text.slice(0, DETAIL_LABEL_LIMIT)}…`;
28
+ };
29
+ if (entries.length <= limit) {
30
+ return { text: entries.map((e) => clip(e.label)).join(separator), omitted: 0, clipped };
31
+ }
32
+ const groups = new Map();
33
+ for (const entry of entries) {
34
+ const group = groups.get(entry.group);
35
+ if (group === undefined) {
36
+ groups.set(entry.group, [entry]);
37
+ }
38
+ else {
39
+ group.push(entry);
40
+ }
41
+ }
42
+ const leads = (group) => group.some((e) => true === e.first);
43
+ const ordered = [...groups].sort(([, a], [, b]) => Number(leads(b)) - Number(leads(a)));
44
+ const shown = ordered.slice(0, limit);
45
+ const parts = shown.map(([name, group]) => {
46
+ const lead = group.find((e) => true === e.first) ?? group[0];
47
+ const first = clip(lead?.label ?? name);
48
+ return group.length > 1
49
+ ? `${first} and ${String(group.length - 1)} more under ${clip(name)}`
50
+ : first;
51
+ });
52
+ const rest = entries.length - shown.reduce((n, [, group]) => n + group.length, 0);
53
+ if (rest > 0) {
54
+ parts.push(`and ${String(rest)} more`);
55
+ }
56
+ return { text: parts.join(separator), omitted: entries.length - shown.length, clipped };
57
+ }
58
+ /** A base for a URL that has no origin. Its origin is removed again from the prefix. */
59
+ const RELATIVE_BASE = 'http://relative.invalid';
60
+ /**
61
+ * The origin and the first path segment of a URL, as a group key: map tiles at
62
+ * `https://tiles.example.com/12/2048/1361.png` group under `https://tiles.example.com/12/`. A URL
63
+ * with one path segment is its own group. Text that is not a URL comes back as it is.
64
+ */
65
+ export function urlPrefix(url) {
66
+ if (0 === url.length) {
67
+ return url;
68
+ }
69
+ let parsed;
70
+ try {
71
+ parsed = new URL(url, RELATIVE_BASE);
72
+ }
73
+ catch {
74
+ return url;
75
+ }
76
+ if ('null' === parsed.origin) {
77
+ return url;
78
+ }
79
+ const origin = parsed.origin === RELATIVE_BASE ? '' : parsed.origin;
80
+ const [, first = '', ...more] = parsed.pathname.split('/');
81
+ return 0 === more.length ? `${origin}${parsed.pathname}` : `${origin}/${first}/`;
82
+ }
@@ -212,34 +212,7 @@ export declare const POLL_JITTER_RATIO = 0.4;
212
212
  * apart they are, which is the classic double submit and every case this rule was written for.
213
213
  */
214
214
  export declare function isSteadyCadence(times: readonly number[]): boolean;
215
- /**
216
- * What this request CARRIED, as far as the record knows — `undefined` when it does not know.
217
- *
218
- * The page's shape fingerprint first: it is present on every request from an instrumented page,
219
- * including the overwhelming majority where body capture is off. A captured body is the fallback for
220
- * a realm that records one without a fingerprint (desktop IPC). Neither means the record does not
221
- * say what this request carried — a body the page could not read as text, or an SDK too old to
222
- * compute a fingerprint — and that is an ABSENCE of identity, not an identity shared with every
223
- * other silent request.
224
- *
225
- * A Server Action's action id joins both halves, and it is the half that survives a `FormData`
226
- * body: several actions POST to the page's own URL, so without it every call is an unknown identity
227
- * pooled with all the others, and no fingerprint can separate two that share a shape. The id alone
228
- * SPLITS two different actions; it cannot say that two runs of one action carried the same thing,
229
- * and `carried` keeps that limit on the record for the finding to say.
230
- */
231
- export interface WriteIdentity {
232
- /** The value the grouping compares. */
233
- readonly key: string;
234
- /** Whether the key also describes WHAT the request carried, not only which action ran. */
235
- readonly carried: boolean;
236
- }
237
- export declare function identityOf(event: ReticleEvent): WriteIdentity | undefined;
238
- /** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
239
- * every identity is known; an unknown one would otherwise pool with every other unknown. */
240
- export declare function groupByIdentity<T extends {
241
- identity: WriteIdentity | undefined;
242
- }>(calls: readonly T[]): T[][];
215
+ export { groupByIdentity, identityOf, type WriteIdentity } from '../write-identity.js';
243
216
  /**
244
217
  * The `net` clause that declares each of these failures, worded as a condition.
245
218
  *
@@ -371,11 +344,12 @@ export declare const RETICLE_SIGNAL_NAMESPACE = "reticle:";
371
344
  * stream, a polling store, a perf sample and a scroll position all move on their own. What counts:
372
345
  *
373
346
  * - a mutation inside the target's own subtree (what the target itself did),
347
+ * - a change to the target's own text, possibly inside a child element — "Copy code" becoming
348
+ * "Copied" (#2318) — or a state-attribute flip; press furniture does not count,
374
349
  * - a request (the action asked the server for something),
375
350
  * - a navigation, or a dialog/live region appearing — the two ways a real reaction legitimately
376
351
  * lands OUTSIDE the target, e.g. a modal portalled to the body,
377
- * - a store change or an app signal tied to the action (#1531): see
378
- * `tiedReaction`.
352
+ * - a store change or an app signal tied to the action (#1531): see `tiedReaction`.
379
353
  *
380
354
  * The last two clauses are what keep this from manufacturing noise: a button that opens a modal
381
355
  * mutates nothing within itself, and a Pause button whose store updates on the media `pause` event
@@ -12,7 +12,7 @@
12
12
  * new rule cannot quietly redefine what "in flight" or "ours" means for itself, which is how two
13
13
  * rules end up disagreeing about the same window.
14
14
  */
15
- import { CanvasTrigger, DepartedNetField, 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';
15
+ import { CanvasTrigger, DepartedNetField, EventType, FieldChangeField, FieldChangeKind, INSIDE_FIELD, MUTATING_METHODS, PredicateKind, ROUTE_CHANGE_HOW_FIELD, RouteChangeHow, asNumber, asString, isDevToolingUrl, isForeignTraffic, urlForMatch, } from '@reticlehq/core';
16
16
  import { isReticleVoice, tiedReaction } from '../state-bookkeeping.js';
17
17
  import { matchesDeclaredFailure } from '../question/declared.js';
18
18
  export function netCall(e) {
@@ -367,29 +367,8 @@ export function isSteadyCadence(times) {
367
367
  }
368
368
  return gaps.every((gap) => Math.abs(gap - median) <= median * POLL_JITTER_RATIO);
369
369
  }
370
- const nonEmpty = (text) => text === undefined || 0 === text.length ? undefined : text;
371
- export function identityOf(event) {
372
- const action = asString(event.data[NEXT_ACTION_FIELD]);
373
- const shape = asString(event.data[REQUEST_SHAPE_FIELD]);
374
- const body = asString(event.data['requestBody']);
375
- const carried = nonEmpty(shape) ?? nonEmpty(body);
376
- if (action === undefined || 0 === action.length) {
377
- return carried === undefined ? undefined : { key: carried, carried: true };
378
- }
379
- return carried === undefined
380
- ? { key: action, carried: false }
381
- : { key: `${action}:${carried}`, carried: true };
382
- }
383
- /** Split calls to one endpoint into the sets that sent the same thing. Callers check first that
384
- * every identity is known; an unknown one would otherwise pool with every other unknown. */
385
- export function groupByIdentity(calls) {
386
- const byIdentity = new Map();
387
- for (const call of calls) {
388
- const key = call.identity?.key ?? '';
389
- byIdentity.set(key, [...(byIdentity.get(key) ?? []), call]);
390
- }
391
- return [...byIdentity.values()];
392
- }
370
+ // Split out to `../write-identity.ts` at the line cap; re-exported so the published path does not move.
371
+ export { groupByIdentity, identityOf } from '../write-identity.js';
393
372
  /**
394
373
  * The `net` clause that declares each of these failures, worded as a condition.
395
374
  *
@@ -568,9 +547,10 @@ export const TargetFate = {
568
547
  };
569
548
  /** A value the control did not have: an absent attribute, or no text. */
570
549
  const ABSENT = '\u0000absent';
571
- /** The attribute or text change this event made to `ref`, or undefined. No-op writes are skipped. */
572
- function changeOf(event, ref) {
573
- if (event.ref !== ref) {
550
+ /** The attribute or text change this event made to `ref` — or, when `deep`, to a descendant of it via `inside` (#2318). No-op writes are skipped. */
551
+ function changeOf(event, ref, deep = false) {
552
+ const inside = event.data[INSIDE_FIELD];
553
+ if (event.ref !== ref && !(deep && Array.isArray(inside) && inside.includes(ref))) {
574
554
  return undefined;
575
555
  }
576
556
  let key;
@@ -589,6 +569,15 @@ function changeOf(event, ref) {
589
569
  const old = asString(event.data['old']) ?? ABSENT;
590
570
  return old === now ? undefined : { key, t: event.t, old, now };
591
571
  }
572
+ /** The state attributes a real press flips — `data-pressed`-style furniture moves on every tap and proves nothing (#2387). */
573
+ const EFFECT_ATTR = /^(?:aria-(?:pressed|expanded|checked|selected)|disabled)$/;
574
+ /** An effect of the action on `ref` or a descendant: text, or a state-attribute flip — press furniture does not count (#2387). */
575
+ function effectOn(event, ref) {
576
+ if (event.type === EventType.DOM_ATTR && !EFFECT_ATTR.test(asString(event.data['attr']) ?? '')) {
577
+ return false;
578
+ }
579
+ return changeOf(event, ref, true) !== undefined;
580
+ }
592
581
  export function targetFate(events, ref, failedAt) {
593
582
  if (ref === undefined) {
594
583
  return undefined;
@@ -755,11 +744,12 @@ export const RETICLE_SIGNAL_NAMESPACE = 'reticle:';
755
744
  * stream, a polling store, a perf sample and a scroll position all move on their own. What counts:
756
745
  *
757
746
  * - a mutation inside the target's own subtree (what the target itself did),
747
+ * - a change to the target's own text, possibly inside a child element — "Copy code" becoming
748
+ * "Copied" (#2318) — or a state-attribute flip; press furniture does not count,
758
749
  * - a request (the action asked the server for something),
759
750
  * - a navigation, or a dialog/live region appearing — the two ways a real reaction legitimately
760
751
  * lands OUTSIDE the target, e.g. a modal portalled to the body,
761
- * - a store change or an app signal tied to the action (#1531): see
762
- * `tiedReaction`.
752
+ * - a store change or an app signal tied to the action (#1531): see `tiedReaction`.
763
753
  *
764
754
  * The last two clauses are what keep this from manufacturing noise: a button that opens a modal
765
755
  * mutates nothing within itself, and a Pause button whose store updates on the media `pause` event
@@ -774,7 +764,10 @@ export function didNothing(events, requests, options) {
774
764
  return false;
775
765
  }
776
766
  const tied = tiedAppReaction(options);
777
- return !events.some((e) => e.type === EventType.ROUTE_CHANGE || e.type === EventType.VISIBLE_SHOWN || tied(e));
767
+ return !events.some((e) => e.type === EventType.ROUTE_CHANGE ||
768
+ e.type === EventType.VISIBLE_SHOWN ||
769
+ tied(e) ||
770
+ (options.ref !== undefined && effectOn(e, options.ref)));
778
771
  }
779
772
  const STATE_KEY_PREFIX = 'state:';
780
773
  const SIGNAL_KEY_PREFIX = 'signal:';
@@ -20,6 +20,14 @@ export type OwnContradiction = Contradiction & {
20
20
  kind: ContradictionKind;
21
21
  };
22
22
  export interface ContradictionOptions {
23
+ /**
24
+ * The signals of this session come from an observer outside the application, and not from the
25
+ * application. True for a realm with no SDK in the subject: the application cannot send a
26
+ * signal there, so a signal is never "the application saying so". The rule
27
+ * `signal-without-consequence` does not apply then. Absent: the SDK is in the application, and
28
+ * its signals are its own word.
29
+ */
30
+ signalsAreObserved?: boolean;
23
31
  /**
24
32
  * Somewhere to record a rule that threw while it ran. See engine-host.ts.
25
33
  *
@@ -201,10 +209,12 @@ export interface ContradictionOptions {
201
209
  namedStatePaths?: readonly string[] | undefined;
202
210
  namedSignals?: readonly string[] | undefined;
203
211
  /**
204
- * Endpoints the assertion declared as reads (`net { repeatable: true }`). Repeats on them are not
205
- * a double submit, so `duplicate-request` skips them (#1353). A call matches when its URL contains
206
- * `urlContains` and, if the clause named a method, its method is that one: a repeatable GET never
207
- * excuses a POST. Nothing else reads it: they are still waited for and still counted.
212
+ * Endpoints the assertion declared repeats on. A read (`net { repeatable: true }`, no `count`):
213
+ * repeats on it are not a double submit, so `duplicate-request` skips it (#1353). A count
214
+ * (`net { count: N }`): up to N landed writes there are the declared consequence, and only a
215
+ * group with more is reported (#2273). A call matches when its URL contains `urlContains` and, if
216
+ * the clause named a method, its method is that one: a repeatable GET never excuses a POST.
217
+ * Nothing else reads it: the calls are still waited for and still counted.
208
218
  */
209
219
  repeatableNetUrls?: readonly DeclaredRead[] | undefined;
210
220
  }
@@ -1,14 +1,16 @@
1
1
  import { neverAnswered, ContradictionKind, EventType, isAbsenceDerived, isSameDocument, isSameEditEpoch, } from '@reticlehq/core';
2
2
  import { describeSuperseded } from '../question/predicate/observed-in-window.js';
3
- import { declareFailureHint, describe, didNothing, RETICLE_SIGNAL_NAMESPACE, groupByIdentity, identityOf, isMutating, isSameDocumentHashAnchor, isSamePathnameReplace, isSteadyCadence, appIsSilent, CanvasPaint, canvasPaint, liveAlertAfterFailedSend, netCall, TargetFate, targetFate, pageNumber, pageRequest, recoveredByRetry, screenMoved, splitForeignTraffic, storeEchoesFailedStatus, successClaims, UNNAMED_SIGNAL, } from './contradiction-evidence.js';
3
+ import { declareFailureHint, describe, didNothing, RETICLE_SIGNAL_NAMESPACE, isMutating, isSameDocumentHashAnchor, isSamePathnameReplace, isSteadyCadence, appIsSilent, CanvasPaint, canvasPaint, liveAlertAfterFailedSend, netCall, TargetFate, targetFate, pageNumber, pageRequest, recoveredByRetry, screenMoved, splitForeignTraffic, storeEchoesFailedStatus, successClaims, UNNAMED_SIGNAL, } from './contradiction-evidence.js';
4
+ import { groupByIdentity, identityOf } from '../write-identity.js';
4
5
  import { answersWrites, movesUi } from '../write-answer.js';
5
6
  import { findStaleResponses } from './stale-response.js';
6
7
  import { findBodyFailures } from './body-failures.js';
7
8
  import { findEchoMismatches } from './echo-mismatch.js';
8
9
  import { findUnitMismatches } from './unit-mismatch.js';
9
10
  import { asString } from '@reticlehq/core';
10
- import { isDeclaredRead, matchesDeclaredFailure } from '../question/declared.js';
11
+ import { declaredCountFor, isDeclaredRead, matchesDeclaredFailure } from '../question/declared.js';
11
12
  import { runRegisteredFolds } from './contradiction-folds.js';
13
+ import { boundedList, urlPrefix } from '../bounded-list.js';
12
14
  import { isMeaningfulStateChange } from '../state-bookkeeping.js';
13
15
  /** What the state-vs-render rule makes of a window. See `readStateRender`. */
14
16
  export const StateRender = {
@@ -513,7 +515,7 @@ function findWindowContradictions(allEvents, options) {
513
515
  ? {
514
516
  kind: ContradictionKind.CONSEQUENCE_ELSEWHERE,
515
517
  claim: `${String(ignoredWrites.length)} write(s) succeeded on the server`,
516
- 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',
518
+ 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. Follow it with the computer realm: npx -p @reticlehq/computer reticle-computer --app "<the browser>"',
517
519
  detail: ignoredWrites.map(describe).join('; '),
518
520
  }
519
521
  : {
@@ -559,7 +561,12 @@ function findWindowContradictions(allEvents, options) {
559
561
  // one signal is an ordinary read, not a claim nothing backs. Without this the rule reddened eight
560
562
  // existing tests that assert exactly that, which is the false-positive class this scoping exists
561
563
  // to prevent.
564
+ //
565
+ // And not when the signals are observed from outside the application. The rule convicts "the
566
+ // app saying so"; an application with no SDK in it says nothing, and the signal is a file or a
567
+ // count of bytes that an observer saw.
562
568
  if (options.actionSince !== undefined &&
569
+ true !== options.signalsAreObserved &&
563
570
  false === advanced &&
564
571
  0 === settled.length &&
565
572
  successSignals.length > 0) {
@@ -611,6 +618,8 @@ function findWindowContradictions(allEvents, options) {
611
618
  */
612
619
  const navigatedAt = events.find((e) => EventType.ROUTE_CHANGE === e.type && e.t >= actionSince)?.t;
613
620
  const writes = new Map();
621
+ // How many calls the assertion declared for each endpoint, keyed like `writes`.
622
+ const declaredCount = new Map();
614
623
  for (const event of events) {
615
624
  if (event.type !== EventType.NET_REQUEST || event.t < actionSince) {
616
625
  continue;
@@ -632,6 +641,7 @@ function findWindowContradictions(allEvents, options) {
632
641
  // APPLIED and a group is only formed once the identities are known.
633
642
  calls.push({ t: event.t, landed: false !== call.ok, identity: identityOf(event) });
634
643
  writes.set(label, calls);
644
+ declaredCount.set(label, declaredCountFor(call, options.repeatableNetUrls));
635
645
  }
636
646
  /**
637
647
  * Did the assertion name this endpoint?
@@ -668,6 +678,13 @@ function findWindowContradictions(allEvents, options) {
668
678
  if (landed < 2) {
669
679
  continue;
670
680
  }
681
+ // The assertion said how many calls it expected here (`net { count: N }`): up to N landed
682
+ // writes are that declared consequence, not one action submitted twice. Two toggles that
683
+ // each save with the same body shape, asserted with `count: 2`, read as a double submit
684
+ // (#2273). A write past N is still reported.
685
+ if (landed <= (declaredCount.get(label) ?? 0)) {
686
+ continue;
687
+ }
671
688
  // A steady cadence is a POLL, and a poll is not a double submit. An app that polls could not
672
689
  // produce a verdict at all: a camera scan loop POSTing until it acquires a lock had every
673
690
  // assertion that had already seen its consequence come back `unknown` behind writes that
@@ -716,6 +733,16 @@ function findWindowContradictions(allEvents, options) {
716
733
  .map((e) => ({ id: asString(e.data['id']), call: netCall(e) }))
717
734
  .filter((p) => p.id === undefined || !settledIds.has(p.id));
718
735
  if (inFlight.length > 0) {
736
+ // A map page leaves hundreds of tiles pending (#2496). Both lists name a few entries, and the
737
+ // finding counts the rest, so the result stays short and the loss is declared. An open write
738
+ // is the call this finding is about, so a write is named before any read.
739
+ const calls = boundedList(inFlight.map((p) => ({
740
+ label: describe(p.call),
741
+ group: `${p.call.method} ${urlPrefix(p.call.url)}`,
742
+ first: isMutating(p.call),
743
+ })), '; ');
744
+ const ignored = boundedList(ignoredForeign.map((url) => ({ label: url, group: urlPrefix(url) })), ', ');
745
+ const omitted = calls.omitted + ignored.omitted;
719
746
  found.push({
720
747
  kind: ContradictionKind.REQUEST_NEVER_SETTLED,
721
748
  claim: 'the UI moved forward and the action reported done',
@@ -723,13 +750,13 @@ function findWindowContradictions(allEvents, options) {
723
750
  // The exclusion is never silent: if the toolchain's own traffic was dropped from this count,
724
751
  // the finding says which URLs, so an agent reading it can see what Reticle chose to ignore.
725
752
  detail: [
726
- inFlight.map((p) => describe(p.call)).join('; '),
753
+ calls.text,
727
754
  ...(0 === ignoredForeign.length
728
755
  ? []
729
- : [
730
- `ignored as dev tooling, third-party or declared background: ${ignoredForeign.join(', ')}`,
731
- ]),
756
+ : [`ignored as dev tooling, third-party or declared background: ${ignored.text}`]),
732
757
  ].join(' — '),
758
+ ...(omitted > 0 ? { omitted } : {}),
759
+ ...(omitted > 0 || calls.clipped || ignored.clipped ? { truncated: true } : {}),
733
760
  });
734
761
  }
735
762
  }
@@ -94,13 +94,20 @@ export declare function blindSpotsFromState(state: Readonly<Record<string, numbe
94
94
  interface AbsencePredicate {
95
95
  kind: string;
96
96
  absent?: boolean;
97
+ state?: string | undefined;
97
98
  query?: {
98
99
  scope?: unknown;
100
+ self?: boolean | undefined;
99
101
  role?: string | undefined;
102
+ name?: string | undefined;
100
103
  by?: string | undefined;
101
104
  value?: string | undefined;
102
105
  testid?: string | undefined;
103
106
  text?: string | undefined;
107
+ label?: string | undefined;
108
+ placeholder?: string | undefined;
109
+ alt?: string | undefined;
110
+ source?: unknown;
104
111
  };
105
112
  predicate?: AbsencePredicate;
106
113
  }
@@ -111,12 +118,13 @@ interface AbsencePredicate {
111
118
  *
112
119
  * Fires on three blind-spot kinds:
113
120
  * - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
114
- * - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element (scoped:
115
- * skipped when the queried role is structurally page-level, like dialog or a landmark, or when
116
- * the window saw the target itself leave as a page-level node)
117
- * - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
121
+ * - VIRTUALIZED_UNMOUNTED: a row that was never rendered could hold the element. Skipped when
122
+ * the queried role is structurally page-level, like dialog or a landmark. Skipped when the
123
+ * window saw the target itself leave as a page-level node. Skipped when the page proved that a
124
+ * ref `scope` and its one mounted match are outside every virtualized list (#2298).
125
+ * - CLOSED_SHADOW_ROOT: a subtree Reticle cannot see into
118
126
  */
119
- export declare function absenceBlindSpotNote(predicate: AbsencePredicate, spots: readonly BlindSpot[], windowEvents?: readonly ReticleEvent[]): string | undefined;
127
+ export declare function absenceBlindSpotNote(predicate: AbsencePredicate, spots: readonly BlindSpot[], windowEvents?: readonly ReticleEvent[], evidence?: unknown): string | undefined;
120
128
  /** The impeaching note for a transport gap, or undefined when the window was intact. */
121
129
  export declare function transportGapNote(events: readonly ReticleEvent[]): string | undefined;
122
130
  /**
@@ -8,6 +8,7 @@
8
8
  // honesty-side callers.
9
9
  export { BlindSpotKind } from '@reticlehq/core';
10
10
  import { readStateRender, StateRender } from '../disagreement/contradictions.js';
11
+ import { ELEMENT_STATE_ASSERTION } from '../question/predicate/predicate-eval-kit.js';
11
12
  import { BlindSpotKind, ChannelId, EventType, PredicateKind, QueryBy, ReticleEnv, TRANSPORT_LIMITS, asString, channelsReadBy, isDesktopBlindSpot, realmOf, } from '@reticlehq/core';
12
13
  /**
13
14
  * Whether the observation window saw everything it was asked about.
@@ -202,6 +203,82 @@ function droppedByTransport(events) {
202
203
  }
203
204
  return dropped;
204
205
  }
206
+ /**
207
+ * Does this query name a specific control rather than a bare role or an empty query?
208
+ *
209
+ * A bare `{ role: "checkbox" }` asks about every checkbox on the page, including any inside
210
+ * unmounted virtual rows. A query with a testid, name, text, label, placeholder, alt, source, or
211
+ * explicit self selector targets a specific control (#2298).
212
+ */
213
+ function namesSpecificElement(query) {
214
+ if (undefined === query) {
215
+ return false;
216
+ }
217
+ if (undefined !== query.testid ||
218
+ undefined !== query.name ||
219
+ undefined !== query.text ||
220
+ undefined !== query.label ||
221
+ undefined !== query.placeholder ||
222
+ undefined !== query.alt ||
223
+ undefined !== query.source ||
224
+ true === query.self) {
225
+ return true;
226
+ }
227
+ return undefined !== query.by && QueryBy.ROLE !== query.by && undefined !== query.value;
228
+ }
229
+ /**
230
+ * Extract the inner `element.state` near-miss evidence from a passing `not(element)` result.
231
+ *
232
+ * `negate()` wraps the failing inner result as `{ negated, held: false, saw }`. Only an
233
+ * `element.state` failure proves the locator itself matched a mounted element; other misses (such
234
+ * as `element.role+name`) matched a different element and must not lift the blind spot.
235
+ */
236
+ function negatedElementEvidence(evidence) {
237
+ if ('object' !== typeof evidence || null === evidence) {
238
+ return undefined;
239
+ }
240
+ const saw = evidence.saw;
241
+ if ('object' !== typeof saw || null === saw) {
242
+ return undefined;
243
+ }
244
+ const inner = saw;
245
+ if (ELEMENT_STATE_ASSERTION !== inner.assertion) {
246
+ return undefined;
247
+ }
248
+ return inner.evidence;
249
+ }
250
+ /**
251
+ * Did the page prove that this state-absence check cannot match an unmounted virtual row (#2298)?
252
+ *
253
+ * One mounted match in another state is not that proof. A virtual list repeats a control in each
254
+ * row, with the same role, name and testid, so an unmounted row can hold a copy in the negated
255
+ * state. The proof is the `outsideVirtualized` answer of the page. The page gives it only when the
256
+ * `scope` is a ref to a live region that is not inside a virtualized list and does not contain one,
257
+ * and the mounted match is not inside one. The search stays in that region, and a row that a list
258
+ * did not render is not in it.
259
+ *
260
+ * The other conditions keep the question about one control: a `scope`, a state, a query that names
261
+ * a specific control, and exactly one mounted match. An unscoped query, a CSS scope, an older page
262
+ * that does not answer, multiple mounted matches and a truncated count all keep the blind spot.
263
+ */
264
+ function mountedTargetOutsideVirtualized(predicate, evidence) {
265
+ if (undefined === predicate.state ||
266
+ 'string' !== typeof predicate.query?.scope ||
267
+ !namesSpecificElement(predicate.query)) {
268
+ return false;
269
+ }
270
+ if ('object' !== typeof evidence || null === evidence) {
271
+ return false;
272
+ }
273
+ const record = evidence;
274
+ if (true !== record.outsideVirtualized) {
275
+ return false;
276
+ }
277
+ if (!Array.isArray(record.nearMiss) || 1 !== record.nearMiss.length) {
278
+ return false;
279
+ }
280
+ return undefined === record.nearMissCount || 1 === record.nearMissCount;
281
+ }
205
282
  /**
206
283
  * Roles that are structurally page-level and can never be a virtualized list row. A dialog is
207
284
  * always a top-level overlay; a landmark is a page-structural element. Absence of one of these
@@ -221,7 +298,8 @@ const NEVER_VIRTUALIZED_ROLES = new Set([
221
298
  * names the target by its testid shows that the target was on the page and left (#2176). Only a
222
299
  * page-level role counts: a virtualizer unmounts a ROW when it scrolls out of view, and that row's
223
300
  * removal says nothing about the data. The blind-spot event carries a count and no container, so
224
- * the engine cannot tell whether a target is outside every virtualized container.
301
+ * the engine cannot tell from it whether a target is outside every virtualized container. Only the
302
+ * page can prove that: see `mountedTargetOutsideVirtualized`.
225
303
  */
226
304
  function sawPageLevelTargetLeave(query, windowEvents) {
227
305
  const testid = query?.testid ?? (QueryBy.TESTID === query?.by ? query.value : undefined);
@@ -239,12 +317,13 @@ function sawPageLevelTargetLeave(query, windowEvents) {
239
317
  *
240
318
  * Fires on three blind-spot kinds:
241
319
  * - CROSS_ORIGIN_IFRAME (only when the predicate is scoped to a frame region)
242
- * - VIRTUALIZED_UNMOUNTED — a row that was never rendered could hold the element (scoped:
243
- * skipped when the queried role is structurally page-level, like dialog or a landmark, or when
244
- * the window saw the target itself leave as a page-level node)
245
- * - CLOSED_SHADOW_ROOT — a subtree Reticle cannot see into
320
+ * - VIRTUALIZED_UNMOUNTED: a row that was never rendered could hold the element. Skipped when
321
+ * the queried role is structurally page-level, like dialog or a landmark. Skipped when the
322
+ * window saw the target itself leave as a page-level node. Skipped when the page proved that a
323
+ * ref `scope` and its one mounted match are outside every virtualized list (#2298).
324
+ * - CLOSED_SHADOW_ROOT: a subtree Reticle cannot see into
246
325
  */
247
- export function absenceBlindSpotNote(predicate, spots, windowEvents = []) {
326
+ export function absenceBlindSpotNote(predicate, spots, windowEvents = [], evidence) {
248
327
  // `not(element)` is the third spelling of an absence assertion — the `not` wrapper IS the
249
328
  // negation, so the inner predicate will not carry `absent: true`. Unwrap and synthesize it.
250
329
  // `not(element { absent: true })` is a double negative — presence — and a positive match is
@@ -254,7 +333,7 @@ export function absenceBlindSpotNote(predicate, spots, windowEvents = []) {
254
333
  if (true === predicate.predicate.absent) {
255
334
  return undefined;
256
335
  }
257
- return absenceBlindSpotNote({ ...predicate.predicate, absent: true }, spots, windowEvents);
336
+ return absenceBlindSpotNote({ ...predicate.predicate, absent: true }, spots, windowEvents, negatedElementEvidence(evidence));
258
337
  }
259
338
  return undefined;
260
339
  }
@@ -264,7 +343,8 @@ export function absenceBlindSpotNote(predicate, spots, windowEvents = []) {
264
343
  const role = predicate.query?.role ??
265
344
  (QueryBy.ROLE === predicate.query?.by ? predicate.query.value : undefined);
266
345
  const virtualizedApplies = (undefined === role || !NEVER_VIRTUALIZED_ROLES.has(role)) &&
267
- !sawPageLevelTargetLeave(predicate.query, windowEvents);
346
+ !sawPageLevelTargetLeave(predicate.query, windowEvents) &&
347
+ !mountedTargetOutsideVirtualized(predicate, evidence);
268
348
  const relevant = spots.filter((spot) => {
269
349
  if (spot.count <= 0) {
270
350
  return false;
@@ -78,6 +78,12 @@ export interface ActionInstrumentationFacts {
78
78
  * every hand-wired connect. See the HELLO field of the same name.
79
79
  */
80
80
  sourceMappingDisabled?: boolean;
81
+ /**
82
+ * The subject has no SDK in it: a desktop application read through the operating system, for
83
+ * one. It has no build plugin, no store to register and no signal to fire, so advice to add
84
+ * them is advice nobody can act on. What the run still owes is reported as usual.
85
+ */
86
+ noSdk?: boolean;
81
87
  /**
82
88
  * How long the OLDEST open intent has been owed, in ms.
83
89
  *
@@ -1,6 +1,7 @@
1
1
  import { InstrumentationGapKind, dedupeGaps, instrumentationGap, } from '@reticlehq/core/artifacts';
2
2
  export function gapsForAction(facts) {
3
3
  const gaps = [];
4
+ const sdk = true !== facts.noSdk;
4
5
  // A red verdict names the control and cannot name the line that renders it. That is the round trip
5
6
  // the agent is about to spend, and the one a build plugin removes permanently.
6
7
  //
@@ -10,7 +11,7 @@ export function gapsForAction(facts) {
10
11
  // a build plugin that was already there. Only a definite `false` counts — an SDK that says nothing
11
12
  // is unknown, and reading silence as an opt-out would mute the honest gap for every app that
12
13
  // simply has no source mapping at all.
13
- if (!facts.pass && facts.source === undefined) {
14
+ if (sdk && !facts.pass && facts.source === undefined) {
14
15
  const off = true === facts.sourceMappingDisabled;
15
16
  gaps.push(instrumentationGap(off ? InstrumentationGapKind.SOURCE_MAPPING_OFF : InstrumentationGapKind.NO_SOURCE_MAPPING, off
16
17
  ? 'source mapping is turned off for this build, so no element carries data-reticle-source'
@@ -44,7 +45,7 @@ export function gapsForAction(facts) {
44
45
  // The kind is NO_STORE_REGISTERED and every sentence it carries is about stores, so the store
45
46
  // registry is what it must be keyed on. An undeclared-capabilities app with a working store is a
46
47
  // different observation, and if it is worth reporting it needs its own kind and its own words.
47
- if (facts.stateUnwatched && (false === facts.hasCapabilities || facts.stateAsked)) {
48
+ if (sdk && facts.stateUnwatched && (false === facts.hasCapabilities || facts.stateAsked)) {
48
49
  // Same missing thing, two ways of meeting it — and the sentence has to say which. Describing an
49
50
  // assertion about state to an agent that made no such assertion is a false explanation, and a
50
51
  // gap nobody can act on is worse than no gap: it costs the trip and teaches the wrong lesson.
@@ -62,7 +63,7 @@ export function gapsForAction(facts) {
62
63
  : 'no state change is observed, so state, when it can be read at all, is read only as it stands and never seen changing'));
63
64
  }
64
65
  // The app moved and said nothing, and Reticle could not prove the outcome another way.
65
- if (facts.domMutated && 0 === facts.signalsFired && true !== facts.proved) {
66
+ if (sdk && facts.domMutated && 0 === facts.signalsFired && true !== facts.proved) {
66
67
  gaps.push(instrumentationGap(InstrumentationGapKind.NO_SIGNAL_ON_MUTATION, 'the DOM changed and no signal fired for it', 'the outcome had to be inferred from the DOM instead of read from the app asserting its own success, which is the strongest evidence available',
67
68
  // The one gap here that can be LOCATED. It is about the element that was driven, and that
68
69
  // element is exactly what `source` describes — so the pointer is a fact, not a guess. It