@reticlehq/engine 3.7.0 → 3.8.1

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.
Files changed (42) hide show
  1. package/dist/disagreement/contradiction-evidence.d.ts +70 -3
  2. package/dist/disagreement/contradiction-evidence.js +156 -7
  3. package/dist/disagreement/contradiction-types.d.ts +8 -0
  4. package/dist/disagreement/contradictions.js +21 -16
  5. package/dist/disagreement/stale-response.js +54 -15
  6. package/dist/evidence/baseline.js +1 -1
  7. package/dist/evidence/body-capture-remedy.d.ts +1 -15
  8. package/dist/evidence/body-capture-remedy.js +9 -2
  9. package/dist/evidence/step-effect.d.ts +20 -1
  10. package/dist/evidence/step-effect.js +30 -2
  11. package/dist/evidence/uncaptured-bodies.d.ts +18 -1
  12. package/dist/evidence/uncaptured-bodies.js +22 -1
  13. package/dist/evidence/unread-outcome.d.ts +7 -0
  14. package/dist/evidence/unread-outcome.js +22 -0
  15. package/dist/evidence/unsettled.js +25 -0
  16. package/dist/evidence/verified.d.ts +2 -0
  17. package/dist/evidence/verified.js +1 -1
  18. package/dist/exact-count.d.ts +19 -0
  19. package/dist/exact-count.js +25 -0
  20. package/dist/question/predicate/predicate-compare.js +7 -2
  21. package/dist/question/predicate/predicate-console.js +23 -10
  22. package/dist/question/predicate/predicate-element.d.ts +10 -1
  23. package/dist/question/predicate/predicate-element.js +138 -17
  24. package/dist/question/predicate/predicate-eval-kit.d.ts +3 -3
  25. package/dist/question/predicate/predicate-eval-kit.js +3 -7
  26. package/dist/question/predicate/predicate-eval.d.ts +10 -0
  27. package/dist/question/predicate/predicate-eval.js +169 -68
  28. package/dist/question/predicate/predicate-parse.d.ts +1 -1
  29. package/dist/question/predicate/predicate-parse.js +1 -1
  30. package/dist/question/predicate/predicate-request-body.d.ts +13 -0
  31. package/dist/question/predicate/predicate-request-body.js +23 -1
  32. package/dist/question/predicate/predicate-schema.d.ts +1 -1
  33. package/dist/question/predicate/predicate-schema.js +6 -5
  34. package/dist/question/predicate/predicate.js +54 -8
  35. package/dist/question/predicate/split-text-miss.d.ts +1 -0
  36. package/dist/question/predicate/split-text-miss.js +8 -1
  37. package/dist/state-bookkeeping.d.ts +2 -0
  38. package/dist/state-bookkeeping.js +4 -0
  39. package/dist/window/adversary.js +46 -40
  40. package/dist/window/network-detail-merge.d.ts +3 -4
  41. package/dist/window/network-detail-merge.js +43 -13
  42. package/package.json +3 -3
@@ -12,7 +12,17 @@
12
12
  */
13
13
  import { buildReactionReport, summarizeReaction } from '../question/reaction.js';
14
14
  import { findContradictions } from '../disagreement/contradictions.js';
15
- export function stepEffect(events, window) {
15
+ import { declaredExpectations } from '../question/declared.js';
16
+ /** The page origin and declared background, omitted when the caller cannot say. Absence fails open. */
17
+ export function appScope(session) {
18
+ return {
19
+ ...(session.url === undefined ? {} : { appOrigin: session.url }),
20
+ ...(session.background === undefined ? {} : { background: session.background }),
21
+ };
22
+ }
23
+ export function stepEffect(events, window,
24
+ /** The page under test, so a third-party write is not graded as the app ignoring a response. */
25
+ scope = {}) {
16
26
  const effect = {};
17
27
  if (window.until > window.since)
18
28
  effect.window = { since: window.since, until: window.until };
@@ -20,8 +30,26 @@ export function stepEffect(events, window) {
20
30
  // `actionSince` is what tells the detectors which window belongs to THIS action. Without it the
21
31
  // headline rule cannot attribute a failed request to the click that moved the screen, and the
22
32
  // whole family goes quiet while looking perfectly wired.
23
- const contradictions = findContradictions(events, { actionSince: window.since });
33
+ const contradictions = findContradictions(events, {
34
+ actionSince: window.since,
35
+ ...(scope.appOrigin === undefined ? {} : { appOrigin: scope.appOrigin }),
36
+ ...(scope.background === undefined ? {} : { background: scope.background }),
37
+ ...declaredOptions(scope.declared),
38
+ });
24
39
  if (contradictions.length > 0)
25
40
  effect.contradictions = contradictions;
26
41
  return effect;
27
42
  }
43
+ /** The contradiction options a step's own expectations give, merged over every one it declared. */
44
+ function declaredOptions(declared) {
45
+ // Nothing declared names no traffic: an empty `namedNetUrls` would hide every duplicate request.
46
+ if (declared === undefined || 0 === declared.length) {
47
+ return {};
48
+ }
49
+ const each = declared.map(declaredExpectations);
50
+ return {
51
+ expectedFailures: each.flatMap((d) => d.netFailures),
52
+ namedNetUrls: each.flatMap((d) => d.netUrls),
53
+ repeatableNetUrls: each.flatMap((d) => d.repeatableNetUrls),
54
+ };
55
+ }
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Does any of these events prove body capture is ON (#1520)?
3
+ *
4
+ * The SDK stamps a skip reason on a response body (a stream, a binary type, a failed read), or a
5
+ * `requestBodyType` on a request body it cannot stringify, only when capture is on. The
6
+ * `error-status` reason is the exception: it marks a body recorded with capture OFF, and it has no
7
+ * skip remedy, so it does not count here.
8
+ */
9
+ export declare function captureProvedOn(events: readonly {
10
+ data: Record<string, unknown>;
11
+ }[]): boolean;
1
12
  /**
2
13
  * Say so when a payload exists but was not recorded.
3
14
  *
@@ -18,6 +29,12 @@ export declare function bodiesNotCaptured(calls: {
18
29
  responseBody?: string;
19
30
  }[],
20
31
  /** The page SDK's version, so the remedy can check whether it applies. See body-capture-remedy. */
21
- sdkVersion?: string): {
32
+ sdkVersion?: string,
33
+ /**
34
+ * A call in the window carries a body-skip reason or a request body type, which the SDK stamps
35
+ * only with capture ON (#1520). Then the bodies are absent for that reason, not because nothing
36
+ * is recorded, and the note would say the opposite of the truth.
37
+ */
38
+ captureProvedOn?: boolean): {
22
39
  bodiesNotCaptured?: string;
23
40
  };
@@ -1,4 +1,17 @@
1
1
  import { bodyCaptureRemedy } from './body-capture-remedy.js';
2
+ import { skippedBodyRemedy } from '../question/predicate/predicate-eval.js';
3
+ /**
4
+ * Does any of these events prove body capture is ON (#1520)?
5
+ *
6
+ * The SDK stamps a skip reason on a response body (a stream, a binary type, a failed read), or a
7
+ * `requestBodyType` on a request body it cannot stringify, only when capture is on. The
8
+ * `error-status` reason is the exception: it marks a body recorded with capture OFF, and it has no
9
+ * skip remedy, so it does not count here.
10
+ */
11
+ export function captureProvedOn(events) {
12
+ return events.some((e) => skippedBodyRemedy(e.data['responseBodyReason']) !== undefined ||
13
+ ('string' === typeof e.data['requestBodyType'] && 0 < e.data['requestBodyType'].length));
14
+ }
2
15
  /** Methods that normally carry a payload — the ones where a missing body is worth explaining. */
3
16
  const BODY_BEARING_METHODS = new Set(['POST', 'PUT', 'PATCH']);
4
17
  /**
@@ -17,7 +30,13 @@ const BODY_BEARING_METHODS = new Set(['POST', 'PUT', 'PATCH']);
17
30
  */
18
31
  export function bodiesNotCaptured(calls,
19
32
  /** The page SDK's version, so the remedy can check whether it applies. See body-capture-remedy. */
20
- sdkVersion) {
33
+ sdkVersion,
34
+ /**
35
+ * A call in the window carries a body-skip reason or a request body type, which the SDK stamps
36
+ * only with capture ON (#1520). Then the bodies are absent for that reason, not because nothing
37
+ * is recorded, and the note would say the opposite of the truth.
38
+ */
39
+ captureProvedOn = false) {
21
40
  const bodyBearing = calls.filter((c) => BODY_BEARING_METHODS.has((c.method ?? '').toUpperCase()));
22
41
  if (0 === bodyBearing.length)
23
42
  return {};
@@ -27,6 +46,8 @@ sdkVersion) {
27
46
  // result, exactly on the question the note exists to answer. (#394)
28
47
  if (calls.some((c) => c.responseBody !== undefined))
29
48
  return {};
49
+ if (captureProvedOn)
50
+ return {};
30
51
  if (bodyBearing.some((c) => c.requestBody !== undefined))
31
52
  return {};
32
53
  return {
@@ -7,4 +7,11 @@ import { type ReticleEvent } from '@reticlehq/core';
7
7
  * name no write, which is unactionable on any page that makes more than one call.
8
8
  */
9
9
  export declare function unreadWriteLabels(events: readonly ReticleEvent[]): string[];
10
+ /**
11
+ * The reason the SDK stamped on every unread write in the window, when they all share one (#1520).
12
+ *
13
+ * Read beside `unreadWriteLabels`, with the same filter, so the remedy for an unread outcome can
14
+ * say "capture is on, this was a stream" instead of "enable capture".
15
+ */
16
+ export declare function unreadWriteReason(events: readonly ReticleEvent[]): unknown;
10
17
  export declare function hasUnreadWriteOutcome(events: readonly ReticleEvent[]): boolean;
@@ -1,5 +1,6 @@
1
1
  import { EventType, MUTATING_METHODS, NetInitiator, isDevToolingUrl, } from '@reticlehq/core';
2
2
  import { asString } from '@reticlehq/core';
3
+ import { sharedSkipReason } from '../question/predicate/predicate-eval.js';
3
4
  const IPC_METHOD = NetInitiator.IPC.toUpperCase();
4
5
  /**
5
6
  * A write whose outcome is sitting in a payload nobody read.
@@ -72,6 +73,27 @@ export function unreadWriteLabels(events) {
72
73
  }
73
74
  return labels;
74
75
  }
76
+ /**
77
+ * The reason the SDK stamped on every unread write in the window, when they all share one (#1520).
78
+ *
79
+ * Read beside `unreadWriteLabels`, with the same filter, so the remedy for an unread outcome can
80
+ * say "capture is on, this was a stream" instead of "enable capture".
81
+ */
82
+ export function unreadWriteReason(events) {
83
+ const labels = new Set(unreadWriteLabels(events));
84
+ if (0 === labels.size)
85
+ return undefined;
86
+ const reasons = [];
87
+ for (const event of events) {
88
+ if (event.type !== EventType.NET_REQUEST || event.data['responseBody'] !== undefined)
89
+ continue;
90
+ const method = ('string' === typeof event.data['method'] ? event.data['method'] : '').toUpperCase();
91
+ if (!labels.has(`${method} ${asString(event.data['url']) ?? ''}`.trim()))
92
+ continue;
93
+ reasons.push(event.data['responseBodyReason']);
94
+ }
95
+ return sharedSkipReason(reasons);
96
+ }
75
97
  export function hasUnreadWriteOutcome(events) {
76
98
  return unreadWriteLabels(events).length > 0;
77
99
  }
@@ -25,6 +25,31 @@ const MAX_LISTED_REQUESTS = 3;
25
25
  * agent that never chose that wait cannot be expected to recognise it in a timeout about it.
26
26
  */
27
27
  export function describeWaitTarget(predicate) {
28
+ return `${waitPhrase(predicate)}${otherConditions(predicate)}`;
29
+ }
30
+ /** The fields a phrase already words, per kind; `since` is a cursor, never a condition. */
31
+ const WORDED = {
32
+ [PredicateKind.SIGNAL]: ['name'],
33
+ [PredicateKind.NET]: ['method', 'urlContains'],
34
+ [PredicateKind.ROUTE]: ['pathname', 'contains'],
35
+ [PredicateKind.STATE]: ['path'],
36
+ [PredicateKind.TEXT]: ['contains', 'ignoreCase'],
37
+ [PredicateKind.ELEMENT]: ['query', 'state'],
38
+ [PredicateKind.ANIMATION]: ['name'],
39
+ };
40
+ const NEVER_WORDED = new Set(['kind', 'since']);
41
+ /**
42
+ * Every other condition the claim checks, as JSON. The label is the check's title and its issue
43
+ * key downstream, so a condition left out made a weaker check share a stricter one's issue.
44
+ */
45
+ function otherConditions(predicate) {
46
+ const worded = WORDED[predicate.kind];
47
+ if (worded === undefined)
48
+ return '';
49
+ const rest = Object.entries(predicate).filter(([key, value]) => value !== undefined && !NEVER_WORDED.has(key) && !worded.includes(key));
50
+ return 0 === rest.length ? '' : ` where ${JSON.stringify(Object.fromEntries(rest))}`;
51
+ }
52
+ function waitPhrase(predicate) {
28
53
  switch (predicate.kind) {
29
54
  case PredicateKind.SETTLED:
30
55
  return 'the page to go idle';
@@ -116,6 +116,8 @@ interface VerifiedInputs {
116
116
  * Empty means nothing went unread.
117
117
  */
118
118
  outcomeUnread?: readonly string[];
119
+ /** The skip reason every unread write carries, if any (`unreadWriteReason`), so the remedy fits it. */
120
+ outcomeUnreadReason?: unknown;
119
121
  /**
120
122
  * The page SDK's version, so the unread-body remedy can check whether it applies.
121
123
  *
@@ -406,7 +406,7 @@ export function decideVerified(inputs) {
406
406
  verifiedReason: VerifiedReason.OUTCOME_UNREAD,
407
407
  because: `a write returned 2xx with a response body that was never recorded (${outcomeUnread.join('; ')}), so its outcome is unread` +
408
408
  ' — a 200 describes the transport, not the result (a batch reports per-item failures in the body, and every GraphQL error is a 200). ' +
409
- bodyCaptureRemedy(inputs.sdkVersion),
409
+ bodyCaptureRemedy(inputs.sdkVersion, inputs.outcomeUnreadReason),
410
410
  };
411
411
  }
412
412
  // Never settled: the page may still be moving, so the observation window may have closed early.
@@ -0,0 +1,19 @@
1
+ import type { EvalResult } from './question/predicate/predicate-eval-kit.js';
2
+ /**
3
+ * Exact cardinality, once, for every channel that can count its matches.
4
+ *
5
+ * `net` and `signal` are the same assertion over different evidence — "this happened EXACTLY n
6
+ * times" — and the interesting half is the same on both: an over-count is `decided`, because a
7
+ * window only accumulates and a count cannot come back down, so waiting out the rest of the budget
8
+ * to report a double-fire buys nothing but latency.
9
+ *
10
+ * `noun` names the population in prose ("network call(s)", "signal(s)"), `filter` is the matcher as
11
+ * applied, and `assertion` is the oracle that judged it.
12
+ */
13
+ export declare function evalExactCount(args: {
14
+ matched: number;
15
+ want: number;
16
+ noun: string;
17
+ filter: string;
18
+ assertion: string;
19
+ }): EvalResult;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Exact cardinality, once, for every channel that can count its matches.
3
+ *
4
+ * `net` and `signal` are the same assertion over different evidence — "this happened EXACTLY n
5
+ * times" — and the interesting half is the same on both: an over-count is `decided`, because a
6
+ * window only accumulates and a count cannot come back down, so waiting out the rest of the budget
7
+ * to report a double-fire buys nothing but latency.
8
+ *
9
+ * `noun` names the population in prose ("network call(s)", "signal(s)"), `filter` is the matcher as
10
+ * applied, and `assertion` is the oracle that judged it.
11
+ */
12
+ export function evalExactCount(args) {
13
+ const { matched, want, noun, filter, assertion } = args;
14
+ if (matched === want) {
15
+ return { pass: true, evidence: { matched } };
16
+ }
17
+ return {
18
+ pass: false,
19
+ ...(matched > want ? { decided: true } : {}),
20
+ failureReason: `expected ${String(want)} ${noun} matching ${filter}, saw ${String(matched)}`,
21
+ observed: `${String(matched)} matching ${noun}`,
22
+ expected: `exactly ${String(want)} matching ${filter}`,
23
+ assertion,
24
+ };
25
+ }
@@ -11,7 +11,8 @@ import { CompareAs, EventType, NetBodySide, PredicateKind, REDACTED_VALUE, urlFo
11
11
  import { parseJsonObject, readField, redactedOnPath, str, } from './predicate-eval-kit.js';
12
12
  import { evalElement, joinedText } from './predicate-element.js';
13
13
  import { evalState } from './predicate-state.js';
14
- const REMEDY_BODY_CAPTURE = 'enable it where the app calls connect(): reticle({ captureNetworkBodies: true })';
14
+ import { skippedBodyRemedy } from './predicate-eval.js';
15
+ import { REMEDY_BODY_CAPTURE, requestBodySkipRemedy } from './predicate-request-body.js';
15
16
  function unknown(reason) {
16
17
  return { result: { pass: false, failureReason: reason, inconclusive: reason } };
17
18
  }
@@ -66,7 +67,11 @@ function readNet(events, source) {
66
67
  const request = NetBodySide.REQUEST === source.body;
67
68
  const body = str(call.data[request ? 'requestBody' : 'responseBody']);
68
69
  if (body === undefined) {
69
- return unknown(`the ${label} was not recorded, so it could not be read — ${REMEDY_BODY_CAPTURE}`);
70
+ // With capture on, the SDK says why it skipped this body; the capture remedy is for the rest.
71
+ const remedy = request
72
+ ? requestBodySkipRemedy(call.data['requestBodyType'])
73
+ : skippedBodyRemedy(call.data['responseBodyReason']);
74
+ return unknown(`the ${label} was not recorded, so it could not be read — ${remedy ?? REMEDY_BODY_CAPTURE}`);
70
75
  }
71
76
  const truncated = true === call.data[request ? 'requestBodyTruncated' : 'responseBodyTruncated'];
72
77
  const payload = parseJsonObject(body);
@@ -6,12 +6,26 @@
6
6
  * else in the evaluator reads a CONSOLE_* event.
7
7
  */
8
8
  import { CONSOLE_ATTACH_NOTE, EventType, PredicateKind } from '@reticlehq/core';
9
- /** The only console levels Reticle instruments (console.info/debug/trace are NOT patched). */
9
+ /** The console levels the SDK patches. console.trace is not patched, so it is not here. */
10
10
  const CONSOLE_LEVEL_TYPE = {
11
11
  log: EventType.CONSOLE_LOG,
12
12
  warn: EventType.CONSOLE_WARN,
13
13
  error: EventType.CONSOLE_ERROR,
14
+ info: EventType.CONSOLE_INFO,
15
+ debug: EventType.CONSOLE_DEBUG,
14
16
  };
17
+ /** What a check with no level reads: every level when it names a message, the loud ones when not. */
18
+ const LOUD_LEVELS = new Set([
19
+ EventType.CONSOLE_LOG,
20
+ EventType.CONSOLE_WARN,
21
+ EventType.CONSOLE_ERROR,
22
+ EventType.ERROR_UNCAUGHT,
23
+ ]);
24
+ const EVERY_LEVEL = new Set([
25
+ ...LOUD_LEVELS,
26
+ EventType.CONSOLE_INFO,
27
+ EventType.CONSOLE_DEBUG,
28
+ ]);
15
29
  /**
16
30
  * Has the console channel reported ANYTHING in this window, at any level?
17
31
  *
@@ -35,15 +49,14 @@ function channelReported(events, since) {
35
49
  }
36
50
  export function evalConsole(events, p) {
37
51
  const since = p.since ?? 0;
38
- // Reticle only instruments console.log/warn/error. A level outside that set is never captured,
39
- // so its events can't exist — and an `absent` assertion on it would verify NOTHING while
40
- // reporting green. Fail loudly instead of false-passing.
52
+ // A level the SDK does not patch is never captured, so its events can't exist — and an `absent`
53
+ // assertion on it would verify NOTHING while reporting green. Fail loudly instead of false-passing.
41
54
  if (p.level !== undefined && p.level !== 'error' && CONSOLE_LEVEL_TYPE[p.level] === undefined) {
42
55
  return {
43
56
  pass: false,
44
- failureReason: `console level '${p.level}' is not captured — Reticle instruments console.log, console.warn, console.error only`,
57
+ failureReason: `console level '${p.level}' is not captured — Reticle instruments console.log, console.warn, console.error, console.info and console.debug only`,
45
58
  observed: `level '${p.level}' is not instrumented, so no event of it can ever exist`,
46
- expected: 'a level Reticle captures: log, warn, or error',
59
+ expected: 'a level Reticle captures: log, warn, error, info or debug',
47
60
  assertion: 'console.uninstrumented-level',
48
61
  };
49
62
  }
@@ -52,10 +65,10 @@ export function evalConsole(events, p) {
52
65
  return false;
53
66
  const isErr = e.type === EventType.CONSOLE_ERROR || e.type === EventType.ERROR_UNCAUGHT;
54
67
  if (p.level === undefined) {
55
- return (e.type === EventType.CONSOLE_LOG ||
56
- e.type === EventType.CONSOLE_WARN ||
57
- e.type === EventType.CONSOLE_ERROR ||
58
- e.type === EventType.ERROR_UNCAUGHT);
68
+ // A named message is matched at any level: `{ contains: "X", absent: true }` used to pass
69
+ // while X was logged with console.info. A clean-console check names no message and stays
70
+ // deaf to info/debug chatter, which most apps produce on every action.
71
+ return ('contains' in p && p.contains !== undefined ? EVERY_LEVEL : LOUD_LEVELS).has(e.type);
59
72
  }
60
73
  if ('error' === p.level)
61
74
  return isErr;
@@ -10,6 +10,13 @@ import { type ElementQuery, ElementState } from '@reticlehq/core';
10
10
  import { type EvalResult } from './predicate-eval.js';
11
11
  import type { PredicateSession } from './predicate-session.js';
12
12
  import { type Baseline, type PropertyAssertion } from './property.js';
13
+ export declare const ARIA_HIDDEN_NOTE = "text is inside an aria-hidden subtree \u2014 drawn on screen but excluded from the accessible tree";
14
+ /**
15
+ * HTML tag names mapped to the ARIA role that `getRole` gives them. A query like `{ role: "iframe" }`
16
+ * always returns zero results because `iframe` is a tag, not a role. The map names the correct role
17
+ * so the hint can say exactly what to use instead.
18
+ */
19
+ export declare const HTML_TAG_TO_ARIA_ROLE: Map<string, string>;
13
20
  export declare function evalElement(session: PredicateSession, query: ElementQuery, state: ElementState | undefined, absent: boolean, diagnose: boolean): Promise<EvalResult>;
14
21
  /** The text of every element a passing match described, joined — what a reader sees there. */
15
22
  export declare function joinedText(evidence: unknown): string;
@@ -27,4 +34,6 @@ export declare function textPredicateQuery(predicate: {
27
34
  ignoreCase?: boolean | undefined;
28
35
  scope?: string | undefined;
29
36
  self?: boolean | undefined;
30
- }): ElementQuery;
37
+ },
38
+ /** The page SDK's version. A page older than MATCH_CASE_SINCE rejects the field outright. */
39
+ sdkVersion?: string): ElementQuery;
@@ -12,6 +12,72 @@ import { describeTestidMiss } from './testid-near-miss.js';
12
12
  import { describeCaseMiss, describeSplitTextMiss } from './split-text-miss.js';
13
13
  import { satisfiesProperty } from './property.js';
14
14
  import { describeNameNearMiss } from './name-near-miss.js';
15
+ export const ARIA_HIDDEN_NOTE = 'text is inside an aria-hidden subtree — drawn on screen but excluded from the accessible tree';
16
+ /**
17
+ * HTML tag names mapped to the ARIA role that `getRole` gives them. A query like `{ role: "iframe" }`
18
+ * always returns zero results because `iframe` is a tag, not a role. The map names the correct role
19
+ * so the hint can say exactly what to use instead.
20
+ */
21
+ export const HTML_TAG_TO_ARIA_ROLE = new Map([
22
+ ['iframe', 'generic'],
23
+ ['div', 'generic'],
24
+ ['span', 'generic'],
25
+ ['video', 'generic'],
26
+ ['audio', 'generic'],
27
+ ['canvas', 'generic'],
28
+ ['embed', 'generic'],
29
+ ['object', 'generic'],
30
+ ['input', 'textbox'],
31
+ ['textarea', 'textbox'],
32
+ ['a', 'link'],
33
+ ['select', 'combobox'],
34
+ ['nav', 'navigation'],
35
+ ['li', 'listitem'],
36
+ ['ul', 'list'],
37
+ ['ol', 'list'],
38
+ ['p', 'paragraph'],
39
+ ['h1', 'heading'],
40
+ ['h2', 'heading'],
41
+ ['h3', 'heading'],
42
+ ['h4', 'heading'],
43
+ ['h5', 'heading'],
44
+ ['h6', 'heading'],
45
+ ['header', 'banner'],
46
+ ['footer', 'contentinfo'],
47
+ ['aside', 'complementary'],
48
+ ['section', 'region'],
49
+ ]);
50
+ /**
51
+ * When the query's role is a raw HTML tag name, name the correct ARIA role to use instead.
52
+ * Context-dependent tags state the condition so the hint is never wrong.
53
+ */
54
+ function describeUnreachableRole(role) {
55
+ if (role === undefined)
56
+ return undefined;
57
+ const tag = role.toLowerCase();
58
+ const ariaRole = HTML_TAG_TO_ARIA_ROLE.get(tag);
59
+ if (ariaRole === undefined)
60
+ return undefined;
61
+ if ('section' === tag) {
62
+ return (`'section' is not an ARIA role — ` +
63
+ `a named <section> (with aria-label, aria-labelledby, or title) has role 'region'; ` +
64
+ `an unnamed one has role 'generic'`);
65
+ }
66
+ if ('a' === tag) {
67
+ return `'a' is not an ARIA role — <a> elements have role 'link' when they carry an href, otherwise 'generic'`;
68
+ }
69
+ if ('select' === tag) {
70
+ return `'select' is not an ARIA role — <select> elements have role 'combobox', or 'listbox' when the multiple attribute is set`;
71
+ }
72
+ if ('input' === tag) {
73
+ return (`'input' is not an ARIA role — <input> role depends on its type attribute: ` +
74
+ `'textbox' for text/email/url/password, 'checkbox', 'radio', 'button', or 'slider' for range`);
75
+ }
76
+ if ('generic' === ariaRole) {
77
+ return `'${role}' is not an ARIA role — <${role}> elements have role 'generic'; try { role: 'generic' } with a name or title, or use a testid`;
78
+ }
79
+ return `'${role}' is not an ARIA role — <${role}> elements have role '${ariaRole}'; try { role: '${ariaRole}' }`;
80
+ }
15
81
  /**
16
82
  * The caveat for a present-testid list that was cut at its cap, or nothing when it was whole.
17
83
  *
@@ -45,8 +111,28 @@ function describeAbsentMiss(match, state) {
45
111
  return (`${found}, but ${which} hidden — \`absent\` means removed from the DOM; ` +
46
112
  `to assert it isn't shown, use \`state: "${ElementState.HIDDEN}"\``);
47
113
  }
48
- async function matchOnce(session, query, state) {
49
- const res = await session.command(ReticleCommand.MATCH, { query, state });
114
+ /**
115
+ * Why a match under a framework error dialog proves nothing. The element is in the DOM, but a user
116
+ * sees only the dialog, so a `yes` here was a false green (#1768).
117
+ */
118
+ function describeCovered(dialog) {
119
+ return (`a ${dialog} covers the page, so a user cannot see this match. ` +
120
+ 'Read the error in the dialog and fix it, then check again');
121
+ }
122
+ /**
123
+ * Why a match that a person cannot read proves nothing. The text is in the DOM, but its colour is
124
+ * almost the colour behind it, or it is almost transparent. A `yes` here was a false green (#1797).
125
+ */
126
+ function describeUnreadable(why) {
127
+ return (`the text is on the page, but a user cannot read it (${why}). ` +
128
+ 'Fix the colour or the opacity, then check again');
129
+ }
130
+ async function matchOnce(session, query, state, diagnose) {
131
+ const res = await session.command(ReticleCommand.MATCH, {
132
+ query,
133
+ state,
134
+ ...(true === diagnose ? { diagnose: true } : {}),
135
+ });
50
136
  if (!res.ok)
51
137
  return { matched: false, count: 0, elements: [] };
52
138
  return (res.result ?? { matched: false, count: 0, elements: [] });
@@ -102,21 +188,27 @@ function versionParts(version) {
102
188
  const m = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
103
189
  return null === m ? undefined : [Number(m[1]), Number(m[2]), Number(m[3])];
104
190
  }
105
- /** The state, when the page's SDK is older than the first release that answers it. */
106
- function stateTheSdkPredates(sdk, state) {
107
- const since = state === undefined ? undefined : ELEMENT_STATE_SINCE[state];
108
- if (sdk === undefined || state === undefined || since === undefined)
109
- return undefined;
110
- const have = versionParts(sdk);
191
+ /** Whether the page's SDK is older than `since`. An unknown or unreadable version is not. */
192
+ function sdkPredates(sdk, since) {
193
+ const have = sdk === undefined ? undefined : versionParts(sdk);
111
194
  const need = versionParts(since);
112
195
  if (have === undefined || need === undefined)
113
- return undefined;
196
+ return false;
114
197
  for (let i = 0; i < 3; i += 1) {
115
198
  if (have[i] !== need[i])
116
- return (have[i] ?? 0) < (need[i] ?? 0) ? { sdk, state, since } : undefined;
199
+ return (have[i] ?? 0) < (need[i] ?? 0);
117
200
  }
118
- return undefined;
201
+ return false;
202
+ }
203
+ /** The state, when the page's SDK is older than the first release that answers it. */
204
+ function stateTheSdkPredates(sdk, state) {
205
+ const since = state === undefined ? undefined : ELEMENT_STATE_SINCE[state];
206
+ if (sdk === undefined || state === undefined || since === undefined)
207
+ return undefined;
208
+ return sdkPredates(sdk, since) ? { sdk, state, since } : undefined;
119
209
  }
210
+ /** The first SDK release whose element query accepts `matchCase`; an older page refuses the query. */
211
+ const MATCH_CASE_SINCE = '3.7.0';
120
212
  export async function evalElement(session, query, state, absent, diagnose) {
121
213
  const tooOld = stateTheSdkPredates(session.sdkVersion, state);
122
214
  if (tooOld !== undefined) {
@@ -140,7 +232,7 @@ export async function evalElement(session, query, state, absent, diagnose) {
140
232
  const reason = describeUnusableElementQuery(query, residual.unusable);
141
233
  return { pass: false, failureReason: reason, inconclusive: reason };
142
234
  }
143
- let match = await matchOnce(session, withAltProjected(query, residual.checks), state);
235
+ let match = await matchOnce(session, withAltProjected(query, residual.checks), state, diagnose);
144
236
  const subject = JSON.stringify(query);
145
237
  // A residual narrows the SET; `count` is every match while `elements` is only the described prefix,
146
238
  // so a locator broad enough to be truncated cannot be narrowed honestly. Say so instead of guessing.
@@ -210,6 +302,30 @@ export async function evalElement(session, query, state, absent, diagnose) {
210
302
  }
211
303
  const announced = substantiveMatches(query, match.elements);
212
304
  if (match.matched && (announced.length > 0 || 0 === match.elements.length)) {
305
+ if (match.coveredBy !== undefined) {
306
+ const reason = describeCovered(match.coveredBy);
307
+ return {
308
+ pass: false,
309
+ failureReason: reason,
310
+ inconclusive: reason,
311
+ observed: `element matching ${subject} is in the DOM under the ${match.coveredBy}`,
312
+ expected: `an element matching ${subject} that a user can see`,
313
+ assertion: 'element.covered',
314
+ evidence: announced,
315
+ };
316
+ }
317
+ if (match.unreadable !== undefined) {
318
+ const reason = describeUnreadable(match.unreadable);
319
+ return {
320
+ pass: false,
321
+ failureReason: reason,
322
+ inconclusive: reason,
323
+ observed: `element matching ${subject} is in the DOM, and ${match.unreadable}`,
324
+ expected: `an element matching ${subject} that a user can read`,
325
+ assertion: 'element.readable',
326
+ evidence: announced,
327
+ };
328
+ }
213
329
  return { pass: true, evidence: announced };
214
330
  }
215
331
  // Matched, but every match was a mounted-and-empty live region. Reported as its own failure rather
@@ -308,9 +424,13 @@ export async function evalElement(session, query, state, absent, diagnose) {
308
424
  const nearMissRole = QueryBy.ROLE === query.by ? query.value : query.role;
309
425
  const nearMiss = describeNameNearMiss(match.hint?.nameNearMiss, query.name, nearMissRole);
310
426
  const caseMiss = describeCaseMiss(match.hint?.caseMiss);
427
+ const ariaNote = true === match.hint?.ariaHiddenMatch ? ARIA_HIDDEN_NOTE : undefined;
428
+ const unreachableRole = describeUnreachableRole(nearMissRole);
311
429
  const clause = caseMiss ??
312
430
  splitText ??
313
431
  nearMiss ??
432
+ ariaNote ??
433
+ unreachableRole ??
314
434
  (alsoHere === undefined || '' === alsoHere ? undefined : alsoHere);
315
435
  const suffix = clause === undefined ? '' : ` — ${clause}`;
316
436
  // The evidence list is capped in document order, so a region low on the page is exactly what it
@@ -414,14 +534,15 @@ async function nearestByName(session, name, state) {
414
534
  * priya" could never catch a capitalisation defect. An undefined `contains` must not reach the query
415
535
  * as `text: undefined` — that is a locator asking for the empty string.
416
536
  */
417
- export function textPredicateQuery(predicate) {
537
+ export function textPredicateQuery(predicate,
538
+ /** The page SDK's version. A page older than MATCH_CASE_SINCE rejects the field outright. */
539
+ sdkVersion) {
540
+ // ponytail: an older page compares case-blind, as the engine did before it sent the field; update the SDK for case-exact checks.
541
+ const matchCase = true !== predicate.ignoreCase && !sdkPredates(sdkVersion, MATCH_CASE_SINCE);
418
542
  return {
419
543
  ...(undefined === predicate.contains
420
544
  ? {}
421
- : {
422
- text: predicate.contains,
423
- ...(true === predicate.ignoreCase ? {} : { matchCase: true }),
424
- }),
545
+ : { text: predicate.contains, ...(matchCase ? { matchCase: true } : {}) }),
425
546
  ...(undefined === predicate.scope
426
547
  ? {}
427
548
  : { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
@@ -1,4 +1,4 @@
1
- import { PredicateKind } from '@reticlehq/core';
1
+ import { PredicateKind, asNumber, asString } from '@reticlehq/core';
2
2
  import type { Predicate } from './predicate-schema.js';
3
3
  /**
4
4
  * What an evaluation ANSWERS, and the small comparisons every oracle answers it with.
@@ -74,8 +74,8 @@ export interface EvalResult {
74
74
  caseOnlyMiss?: boolean;
75
75
  wouldHold?: string;
76
76
  }
77
- export declare function str(value: unknown): string | undefined;
78
- export declare function num(value: unknown): number | undefined;
77
+ /** Core's `asString` and `asNumber`, under the names the oracles here read them by. */
78
+ export { asString as str, asNumber as num };
79
79
  /**
80
80
  * Match one value against a pattern. Supports `*` (present), strict equality, and operators:
81
81
  * `{$gte,$lte,$gt,$lt}` (numbers), `{$contains}` (array membership or substring), `{$length}`.
@@ -1,10 +1,6 @@
1
- import { PredicateKind, REDACTED_VALUE, selectPath } from '@reticlehq/core';
2
- export function str(value) {
3
- return 'string' === typeof value ? value : undefined;
4
- }
5
- export function num(value) {
6
- return 'number' === typeof value ? value : undefined;
7
- }
1
+ import { PredicateKind, REDACTED_VALUE, asNumber, asString, selectPath } from '@reticlehq/core';
2
+ /** Core's `asString` and `asNumber`, under the names the oracles here read them by. */
3
+ export { asString as str, asNumber as num };
8
4
  /**
9
5
  * Match one value against a pattern. Supports `*` (present), strict equality, and operators:
10
6
  * `{$gte,$lte,$gt,$lt}` (numbers), `{$contains}` (array membership or substring), `{$length}`.
@@ -10,6 +10,16 @@ export * from './predicate-schema.js';
10
10
  * IPC. The capsule's blast radius uses it to keep a page load out of "what this action also did".
11
11
  */
12
12
  export declare function isDocumentInitiated(event: ReticleEvent): boolean;
13
+ /**
14
+ * The remedy for a body the SDK skipped ON PURPOSE with capture on, or `undefined` (#1520).
15
+ *
16
+ * Shared by every message that would otherwise say "enable captureNetworkBodies": that advice is
17
+ * wrong when capture is already on and the body was a stream, a binary type, or a read that did
18
+ * not finish. `undefined` means no reason was stamped: capture was off, or the SDK predates it.
19
+ */
20
+ export declare function skippedBodyRemedy(reason: unknown): string | undefined;
21
+ /** The skip reason every one of these calls carries, when they all carry the same one. */
22
+ export declare function sharedSkipReason(reasons: readonly unknown[]): unknown;
13
23
  export declare function evalNet(events: ReticleEvent[], p: Extract<Predicate, {
14
24
  kind: typeof PredicateKind.NET;
15
25
  }>): EvalResult;