@reticlehq/engine 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/disagreement/contradiction-evidence.d.ts +66 -1
  2. package/dist/disagreement/contradiction-evidence.js +141 -2
  3. package/dist/disagreement/contradiction-types.d.ts +8 -1
  4. package/dist/disagreement/contradictions.d.ts +12 -0
  5. package/dist/disagreement/contradictions.js +37 -70
  6. package/dist/disagreement/stale-response.js +7 -2
  7. package/dist/evidence/already-true.d.ts +5 -0
  8. package/dist/evidence/already-true.js +27 -6
  9. package/dist/evidence/baseline.js +2 -6
  10. package/dist/evidence/blind-spots.d.ts +14 -3
  11. package/dist/evidence/blind-spots.js +48 -10
  12. package/dist/evidence/instrumentation-gaps.js +3 -1
  13. package/dist/evidence/state-bookkeeping.d.ts +2 -0
  14. package/dist/evidence/state-bookkeeping.js +2 -0
  15. package/dist/evidence/superseded-checks.d.ts +29 -0
  16. package/dist/evidence/superseded-checks.js +30 -0
  17. package/dist/evidence/unsettled.js +4 -2
  18. package/dist/evidence/verified.d.ts +6 -1
  19. package/dist/evidence/verified.js +32 -4
  20. package/dist/question/declared.d.ts +20 -0
  21. package/dist/question/declared.js +20 -1
  22. package/dist/question/predicate/net-blind-spots.d.ts +49 -0
  23. package/dist/question/predicate/net-blind-spots.js +153 -0
  24. package/dist/question/predicate/predicate-element.d.ts +14 -0
  25. package/dist/question/predicate/predicate-element.js +76 -5
  26. package/dist/question/predicate/predicate-eval-kit.d.ts +25 -0
  27. package/dist/question/predicate/predicate-eval-kit.js +31 -0
  28. package/dist/question/predicate/predicate-eval.d.ts +1 -1
  29. package/dist/question/predicate/predicate-eval.js +47 -167
  30. package/dist/question/predicate/predicate-parse.js +34 -0
  31. package/dist/question/predicate/predicate-request-body.d.ts +6 -1
  32. package/dist/question/predicate/predicate-request-body.js +7 -2
  33. package/dist/question/predicate/predicate-route.d.ts +2 -0
  34. package/dist/question/predicate/predicate-route.js +30 -0
  35. package/dist/question/predicate/predicate-schema.d.ts +11 -0
  36. package/dist/question/predicate/predicate-schema.js +52 -1
  37. package/dist/question/predicate/predicate-state.js +7 -0
  38. package/dist/question/predicate/predicate.js +5 -11
  39. package/dist/question/predicate/split-text-miss.d.ts +6 -0
  40. package/dist/question/predicate/split-text-miss.js +10 -0
  41. package/dist/state-bookkeeping.d.ts +25 -0
  42. package/dist/state-bookkeeping.js +70 -0
  43. package/package.json +2 -2
@@ -47,6 +47,8 @@ interface RouteParts {
47
47
  }
48
48
  /** A `ROUTE_CHANGE` event, or its `data` — one reading, so the sixth copy cannot drift. */
49
49
  export declare function routeOfEvent(eventOrData: ReticleEvent | Record<string, unknown>): RouteParts | undefined;
50
+ /** A route as a navigable path, pathname + app query + hash, with Reticle's own params dropped. */
51
+ export declare function navigablePath(parts: Pick<RouteParts, 'docPath' | 'search' | 'hash'>): string;
50
52
  /** Same shape from a session URL (the fallback when the tab hard-loaded and emitted no route event). */
51
53
  export declare function routeOfUrl(url: string): RouteParts | undefined;
52
54
  export declare function evalRoute(events: ReticleEvent[], p: Extract<Predicate, {
@@ -100,6 +100,36 @@ function withoutIdentityParams(value) {
100
100
  parsed.searchParams.delete(name);
101
101
  return parsed.toString();
102
102
  }
103
+ /**
104
+ * A `?query` with Reticle's own params removed and the app's pairs left exactly as written. A recording keeps the app's query in `startPath` and replay compares against it,
105
+ * so a leased tab's `__reticle_*` params must be dropped on both sides or a tab already on the page
106
+ * reads as somewhere else (#1411).
107
+ */
108
+ function searchWithoutIdentityParams(search) {
109
+ const query = search.startsWith('?') ? search.slice(1) : search;
110
+ if ('' === query)
111
+ return '';
112
+ // Pair by pair, not through URLSearchParams: its round trip re-encodes what it keeps (`%20` comes
113
+ // back as `+`), so a hand-written startPath `/search?q=red%20shirt` would stop matching a tab on
114
+ // exactly that URL. Only Reticle's own pairs are removed; the rest keep their spelling.
115
+ const ours = new Set(Object.values(RETICLE_URL_PARAM));
116
+ const kept = query.split('&').filter((pair) => !ours.has(paramNameOf(pair)));
117
+ return 0 === kept.length ? '' : `?${kept.join('&')}`;
118
+ }
119
+ /** The decoded name of one `name=value` query pair, or the raw text when it does not decode. */
120
+ function paramNameOf(pair) {
121
+ const raw = pair.split('=', 1)[0] ?? '';
122
+ try {
123
+ return decodeURIComponent(raw.replaceAll('+', ' '));
124
+ }
125
+ catch {
126
+ return raw;
127
+ }
128
+ }
129
+ /** A route as a navigable path, pathname + app query + hash, with Reticle's own params dropped. */
130
+ export function navigablePath(parts) {
131
+ return `${parts.docPath}${searchWithoutIdentityParams(parts.search)}${parts.hash}`;
132
+ }
103
133
  /** The event payload as evidence: every URL-ish field scrubbed of our own params. */
104
134
  function routeEvidence(data) {
105
135
  return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, withoutIdentityParams(value)]));
@@ -11,6 +11,17 @@ import { z } from 'zod';
11
11
  import { type ElementDescriptor, type ElementQuery } from '@reticlehq/core';
12
12
  export { PredicateSchema } from '@reticlehq/core';
13
13
  export type { Predicate, PropertyAssertion } from '@reticlehq/core';
14
+ /** The query to send, asking the browser to project `alt` when this side has to check it. */
15
+ export declare function withAltProjected(query: ElementQuery, checks: readonly [string, string][]): ElementQuery;
16
+ /**
17
+ * Why `alt` cannot be checked, when none of the matched elements is an image — or `undefined` when
18
+ * it can. A button has no alt, so grading it "no" would read as "the alt is wrong" when the truth is
19
+ * "this is not an image": a refusal that says what to use instead costs one turn.
20
+ *
21
+ * Only the case where NO match is an image is refused. With an image among them, the others simply do
22
+ * not satisfy `alt`, and the verdict is about the images.
23
+ */
24
+ export declare function describeAltOnNonImage(checks: readonly [string, string][], elements: readonly ElementDescriptor[]): string | undefined;
14
25
  interface ResidualQueryChecks {
15
26
  /** Dropped fields this side CAN check, as [field, wanted value] pairs. */
16
27
  checks: [string, string][];
@@ -54,6 +54,10 @@ function usedQueryFields(query) {
54
54
  used.add('attrs');
55
55
  if (query.self !== undefined)
56
56
  used.add('self');
57
+ // A modifier of the text rule, not a locator: the browser honours it wherever it reads `text`, and
58
+ // the residual text check below is already case-exact.
59
+ if (query.matchCase !== undefined)
60
+ used.add('matchCase');
57
61
  // The browser's `self` branch checks subtree text when supplied, but skips every other locator.
58
62
  // Mark only text as consumed so role/name/etc. remain residual checks on the returned descriptor.
59
63
  if (true === query.self)
@@ -86,6 +90,20 @@ function usedQueryFields(query) {
86
90
  }
87
91
  return used;
88
92
  }
93
+ /**
94
+ * The role the browser reports for an `<img>`. It stands in for "an image" because the descriptor
95
+ * carries no tag name, so anything else with this role — an `<svg role="img">` — counts as one too.
96
+ */
97
+ const IMAGE_ROLE = 'img';
98
+ const ALT_FIELD = 'alt';
99
+ /** How a failure reports an image that carries no `alt` attribute at all. */
100
+ const NO_ALT_ATTRIBUTE = '(no alt attribute)';
101
+ /** What the refusal says about `alt` on something that is not an image, and what to assert instead. */
102
+ const ALT_IMAGE_ONLY = '`alt` can only be checked on an image';
103
+ const ALT_USE_NAME = 'For an element that is not an image, assert its accessible name with `name` instead.';
104
+ function isImage(element) {
105
+ return IMAGE_ROLE === element.role;
106
+ }
89
107
  /**
90
108
  * How a dropped field is checked back on the server, against the descriptor the match returned.
91
109
  *
@@ -100,6 +118,11 @@ function usedQueryFields(query) {
100
118
  * copies out of a query result are the words that match here. `text` is a substring match, matching
101
119
  * Testing Library's `exact: false`, and falls back to the name because describe() omits `text` when it
102
120
  * equals the accessible name.
121
+ *
122
+ * `alt` is read from the image's `alt` ATTRIBUTE, projected onto the match by `withAltProjected` —
123
+ * not from its accessible name. Both a decorative `alt=""` and a missing alt give an empty name, and
124
+ * only the attribute tells them apart: a missing alt is the defect `alt: ""` exists to rule out. On
125
+ * anything but an image it is false, and `describeAltOnNonImage` turns that into a refusal.
103
126
  */
104
127
  /**
105
128
  * Does an element whose computed role is `actual` satisfy a query for `queried`?
@@ -120,7 +143,33 @@ const RESIDUAL_CHECKS = {
120
143
  role: (element, want) => matchesRole(element.role, want),
121
144
  name: (element, want) => element.name.trim() === want.trim(),
122
145
  text: (element, want) => (element.text ?? element.name).includes(want),
146
+ [ALT_FIELD]: (element, want) => {
147
+ const alt = element.attrs?.[ALT_FIELD];
148
+ return isImage(element) && alt !== undefined && alt.trim() === want.trim();
149
+ },
123
150
  };
151
+ /** The query to send, asking the browser to project `alt` when this side has to check it. */
152
+ export function withAltProjected(query, checks) {
153
+ const attrs = query.attrs ?? [];
154
+ if (!checks.some(([field]) => ALT_FIELD === field) || attrs.includes(ALT_FIELD))
155
+ return query;
156
+ return { ...query, attrs: [...attrs, ALT_FIELD] };
157
+ }
158
+ /**
159
+ * Why `alt` cannot be checked, when none of the matched elements is an image — or `undefined` when
160
+ * it can. A button has no alt, so grading it "no" would read as "the alt is wrong" when the truth is
161
+ * "this is not an image": a refusal that says what to use instead costs one turn.
162
+ *
163
+ * Only the case where NO match is an image is refused. With an image among them, the others simply do
164
+ * not satisfy `alt`, and the verdict is about the images.
165
+ */
166
+ export function describeAltOnNonImage(checks, elements) {
167
+ const wantsAlt = checks.some(([field]) => ALT_FIELD === field);
168
+ if (!wantsAlt || 0 === elements.length || elements.some(isImage))
169
+ return undefined;
170
+ const roles = [...new Set(elements.map((element) => element.role))].join(', ');
171
+ return `${ALT_IMAGE_ONLY}, and the element matched is ${roles}, not ${IMAGE_ROLE}. ${ALT_USE_NAME}`;
172
+ }
124
173
  /**
125
174
  * Split a query's dropped fields into the ones the server can still enforce and the ones it cannot.
126
175
  *
@@ -171,7 +220,9 @@ export function describeResidual(element, field) {
171
220
  ? (element.text ?? element.name)
172
221
  : 'role' === field
173
222
  ? element.role
174
- : element.name;
223
+ : ALT_FIELD === field
224
+ ? (element.attrs?.[ALT_FIELD] ?? NO_ALT_ATTRIBUTE)
225
+ : element.name;
175
226
  return `${element.role} "${element.name}" ${field}=${JSON.stringify(reading)}`;
176
227
  }
177
228
  /**
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { PredicateKind, ReticleCommand, capDepth, selectPath } from '@reticlehq/core';
10
10
  import { matchValue } from './predicate-eval.js';
11
+ import { isStringifiedPrimitiveMismatch, stringifiedPrimitiveResult, } from './predicate-eval-kit.js';
11
12
  import { satisfiesProperty } from './property.js';
12
13
  /** One name, or none — two candidates is a question, not an answer. */
13
14
  function oneOf(names) {
@@ -159,6 +160,9 @@ async function evalStateNamed(session, p, storeName, baseline) {
159
160
  evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
160
161
  };
161
162
  }
163
+ if (isStringifiedPrimitiveMismatch(selection.value, want)) {
164
+ return stringifiedPrimitiveResult(storeName, p.path, selection.value, want, capDepth);
165
+ }
162
166
  return {
163
167
  pass: false,
164
168
  failureReason: `state '${p.path}' is ${JSON.stringify(capDepth(selection.value, 0))}, expected ${JSON.stringify(want)}`,
@@ -306,6 +310,9 @@ export async function evalState(session, p, baseline) {
306
310
  evidence: { store: storeName, path: p.path, value: capDepth(selection.value, 1) },
307
311
  };
308
312
  }
313
+ if (isStringifiedPrimitiveMismatch(selection.value, want)) {
314
+ return stringifiedPrimitiveResult(storeName, p.path, selection.value, want, capDepth);
315
+ }
309
316
  return {
310
317
  pass: false,
311
318
  failureReason: `state '${p.path}' is ${JSON.stringify(capDepth(selection.value, 0))}, expected ${JSON.stringify(want)}`,
@@ -3,7 +3,7 @@ import { predicateToExpectedLinks } from './predicate-to-links.js';
3
3
  import { isAmbient, ambientKeyOf } from '../../window/ambient.js';
4
4
  import { evalRoute } from './predicate-route.js';
5
5
  import { describeSuperseded } from './observed-in-window.js';
6
- import { evalElement, withTextProperty } from './predicate-element.js';
6
+ import { evalElement, textPredicateQuery, withTextProperty } from './predicate-element.js';
7
7
  import { evalState } from './predicate-state.js';
8
8
  import { evalCompare } from './predicate-compare.js';
9
9
  import { PredicateSchema, evalNet, evalConsole, evalAnimation, evalSignal, evalSettled, } from './predicate-eval.js';
@@ -83,6 +83,7 @@ function annotateThrottledMiss(session, predicate, result) {
83
83
  *
84
84
  * - `splitText`: the browser found the requested string in the rendered page, split across
85
85
  * children. Target-specific — the text IS the thing that was asked for.
86
+ * - `caseMiss`: the browser found it in another case, for a case-exact check.
86
87
  * - `nearMiss` from `element.state`: the target element exists but in the wrong state. The DOM
87
88
  * painted the element itself, so starvation is not the explanation.
88
89
  *
@@ -96,7 +97,7 @@ function evidenceProvesPageRendered(result) {
96
97
  const evidence = result.evidence;
97
98
  if ('object' !== typeof evidence || null === evidence)
98
99
  return false;
99
- if ('splitText' in evidence)
100
+ if ('splitText' in evidence || 'caseMiss' in evidence)
100
101
  return true;
101
102
  if ('nearMiss' in evidence && 'element.state' === result.assertion)
102
103
  return true;
@@ -252,15 +253,8 @@ diagnose = true, baselines) {
252
253
  return evalElement(session, predicate.query, predicate.state, predicate.absent ?? false, diagnose);
253
254
  case PredicateKind.TEXT: {
254
255
  // `scope` passes straight through: the text predicate has always been an element query with
255
- // only `text` filled in, so scoping it needs the field, not a second code path. `contains` is
256
- // optional now that `satisfies` can carry the claim, and an undefined one must not reach the
257
- // query as `text: undefined` — that is a locator asking for the empty string.
258
- const query = {
259
- ...(undefined === predicate.contains ? {} : { text: predicate.contains }),
260
- ...(undefined === predicate.scope
261
- ? {}
262
- : { scope: predicate.scope, ...(true === predicate.self ? { self: true } : {}) }),
263
- };
256
+ // only `text` filled in, so scoping it needs the field, not a second code path.
257
+ const query = textPredicateQuery(predicate);
264
258
  const found = await evalElement(session, query, true === predicate.visible ? ElementState.VISIBLE : undefined, predicate.absent ?? false, diagnose);
265
259
  if (undefined === predicate.satisfies)
266
260
  return found;
@@ -29,4 +29,10 @@ interface SplitTextOwner {
29
29
  * short message it already had. A clause that fires on every failure stops carrying information.
30
30
  */
31
31
  export declare function describeSplitTextMiss(owner: SplitTextOwner | undefined, searchedText?: string): string | undefined;
32
+ /**
33
+ * The clause for a case-exact check that missed only on case: what the page shows, and the one
34
+ * change that matches it. It used to read "split across the children" with the same check as the
35
+ * recovery, which fails again.
36
+ */
37
+ export declare function describeCaseMiss(shown: string | undefined): string | undefined;
32
38
  export {};
@@ -49,3 +49,13 @@ export function describeSplitTextMiss(owner, searchedText) {
49
49
  })}`;
50
50
  return `that text IS on the page, split across the children of ${where} — no single element's own text carries it, so no text query can match it; ${recovery}`;
51
51
  }
52
+ /**
53
+ * The clause for a case-exact check that missed only on case: what the page shows, and the one
54
+ * change that matches it. It used to read "split across the children" with the same check as the
55
+ * recovery, which fails again.
56
+ */
57
+ export function describeCaseMiss(shown) {
58
+ if (shown === undefined || 0 === shown.length)
59
+ return undefined;
60
+ return `the page shows "${truncate(shown)}", which differs only by case — this check is case-exact; retry with ignoreCase: true if the case does not matter`;
61
+ }
@@ -0,0 +1,25 @@
1
+ import { type ReticleEvent } from '@reticlehq/core';
2
+ /**
3
+ * Meaningful state vs cache bookkeeping.
4
+ *
5
+ * A query cache (TanStack Query, SWR-shaped stores) re-emits every entry as it moves through
6
+ * pending → fetching → idle, stamping `fetchStatus`, `isStale` and `dataUpdatedAt` on the way. Those
7
+ * transitions are real, and they are not what an action CHANGED: one click on a cache-backed page
8
+ * reported a dozen `stateDiffs` whose only difference was the cache's own clock, and the one diff
9
+ * that mattered was the thirteenth.
10
+ *
11
+ * This rule classifies ONE before→after pair. It is deliberately narrow: a diff is bookkeeping only
12
+ * when both sides are plain objects AND every key that differs is a bookkeeping key. A change to
13
+ * `data`, `error`, or any key this list does not name is meaningful — so a value nobody anticipated
14
+ * is always reported, never silently classed as noise. `status` is included because on its own
15
+ * (no `data`/`error` move) it is the cache narrating its fetch, not the app changing.
16
+ *
17
+ * Predicates never read this: they evaluate the event window directly, so a `state` assertion on
18
+ * `isStale` still sees every transition. One verdict does: `state-vs-render` ignores a change this
19
+ * classes as bookkeeping, so a cache's own clock cannot stand in for an app change nobody rendered.
20
+ */
21
+ export declare const CACHE_BOOKKEEPING_KEYS: ReadonlySet<string>;
22
+ /** TRUE when this before→after differs only in cache-bookkeeping keys, and differs at all. */
23
+ export declare function isCacheBookkeepingDiff(from: unknown, to: unknown): boolean;
24
+ /** Whether a state event carries movement that can support state-vs-render. */
25
+ export declare function isMeaningfulStateChange(event: ReticleEvent): boolean;
@@ -0,0 +1,70 @@
1
+ import { EventType } from '@reticlehq/core';
2
+ /**
3
+ * Meaningful state vs cache bookkeeping.
4
+ *
5
+ * A query cache (TanStack Query, SWR-shaped stores) re-emits every entry as it moves through
6
+ * pending → fetching → idle, stamping `fetchStatus`, `isStale` and `dataUpdatedAt` on the way. Those
7
+ * transitions are real, and they are not what an action CHANGED: one click on a cache-backed page
8
+ * reported a dozen `stateDiffs` whose only difference was the cache's own clock, and the one diff
9
+ * that mattered was the thirteenth.
10
+ *
11
+ * This rule classifies ONE before→after pair. It is deliberately narrow: a diff is bookkeeping only
12
+ * when both sides are plain objects AND every key that differs is a bookkeeping key. A change to
13
+ * `data`, `error`, or any key this list does not name is meaningful — so a value nobody anticipated
14
+ * is always reported, never silently classed as noise. `status` is included because on its own
15
+ * (no `data`/`error` move) it is the cache narrating its fetch, not the app changing.
16
+ *
17
+ * Predicates never read this: they evaluate the event window directly, so a `state` assertion on
18
+ * `isStale` still sees every transition. One verdict does: `state-vs-render` ignores a change this
19
+ * classes as bookkeeping, so a cache's own clock cannot stand in for an app change nobody rendered.
20
+ */
21
+ export const CACHE_BOOKKEEPING_KEYS = new Set([
22
+ 'status',
23
+ 'fetchStatus',
24
+ 'isStale',
25
+ 'dataUpdatedAt',
26
+ 'errorUpdatedAt',
27
+ 'isFetching',
28
+ 'isInvalidated',
29
+ 'fetchFailureCount',
30
+ ]);
31
+ function plainObject(value) {
32
+ return 'object' === typeof value && null !== value && !Array.isArray(value);
33
+ }
34
+ function same(a, b) {
35
+ if (Object.is(a, b))
36
+ return true;
37
+ try {
38
+ return JSON.stringify(a) === JSON.stringify(b);
39
+ }
40
+ catch {
41
+ // Not comparable is not "equal": a pair we cannot read is reported, never classed as noise.
42
+ return false;
43
+ }
44
+ }
45
+ /** TRUE when this before→after differs only in cache-bookkeeping keys, and differs at all. */
46
+ export function isCacheBookkeepingDiff(from, to) {
47
+ if (!plainObject(from) || !plainObject(to))
48
+ return false;
49
+ let differed = false;
50
+ for (const key of new Set([...Object.keys(from), ...Object.keys(to)])) {
51
+ if (same(from[key], to[key]))
52
+ continue;
53
+ if (!CACHE_BOOKKEEPING_KEYS.has(key))
54
+ return false;
55
+ differed = true;
56
+ }
57
+ return differed;
58
+ }
59
+ /** Whether a state event carries movement that can support state-vs-render. */
60
+ export function isMeaningfulStateChange(event) {
61
+ if (event.type !== EventType.STATE_CHANGE)
62
+ return false;
63
+ if (!('old' in event.data))
64
+ return true;
65
+ const hasAfter = 'value' in event.data || 'new' in event.data;
66
+ if (!hasAfter)
67
+ return true;
68
+ const after = 'value' in event.data ? event.data['value'] : event.data['new'];
69
+ return !isCacheBookkeepingDiff(event.data['old'], after);
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/engine",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "The rules that decide a verdict: read what happened in a running app and say whether the declared consequence held. No browser, no daemon, no command line - an implementation of the OpenVerification specification you can use on its own.",
5
5
  "keywords": [
6
6
  "verification",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "zod": "^3.24.1",
60
- "@reticlehq/core": "3.6.0",
60
+ "@reticlehq/core": "3.7.0",
61
61
  "open-verification": "1.0.0"
62
62
  },
63
63
  "scripts": {