@reticlehq/core 3.6.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activation-entry.d.ts +9 -0
- package/dist/activation-entry.js +9 -0
- package/dist/artifacts/artifacts-entry.d.ts +2 -0
- package/dist/artifacts/artifacts-entry.js +2 -0
- package/dist/artifacts/drive-script.d.ts +222 -116
- package/dist/artifacts/drive-script.js +24 -1
- package/dist/artifacts/flow-constants.d.ts +33 -0
- package/dist/artifacts/flow-constants.js +35 -0
- package/dist/artifacts/flow-expect-flat.d.ts +8 -8
- package/dist/artifacts/flow-results.d.ts +461 -0
- package/dist/artifacts/flow-results.js +1 -0
- package/dist/artifacts/flow-types.d.ts +177 -543
- package/dist/artifacts/flow-types.js +17 -2
- package/dist/artifacts/harness-credits.d.ts +42 -0
- package/dist/artifacts/harness-credits.js +72 -0
- package/dist/artifacts/harness-map.d.ts +98 -0
- package/dist/artifacts/harness-map.js +36 -0
- package/dist/artifacts/impact.d.ts +355 -149
- package/dist/artifacts/impact.js +84 -49
- package/dist/artifacts/journal.d.ts +81 -11
- package/dist/artifacts/journal.js +39 -0
- package/dist/artifacts/prompt-context.d.ts +12 -0
- package/dist/artifacts/prompt-context.js +14 -3
- package/dist/artifacts/screenshot-upload.d.ts +51 -0
- package/dist/artifacts/screenshot-upload.js +26 -0
- package/dist/graph/app-graph.d.ts +137 -0
- package/dist/graph/app-graph.js +498 -0
- package/dist/hooks/hook-events.d.ts +26 -26
- package/dist/hud-entry.d.ts +1 -0
- package/dist/hud-entry.js +2 -0
- package/dist/identity/checkout.d.ts +41 -0
- package/dist/identity/checkout.js +118 -0
- package/dist/identity/state-dir.d.ts +23 -0
- package/dist/identity/state-dir.js +43 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -0
- package/dist/onboarding.d.ts +30 -1
- package/dist/onboarding.js +25 -0
- package/dist/realm/registry.js +19 -1
- package/dist/registry/dev-server-registry.d.ts +2 -2
- package/dist/schema/command-message.json +30 -0
- package/dist/schema/command-name.json +3 -1
- package/dist/schema/event-message.json +3 -1
- package/dist/schema/event-payloads.json +156 -3
- package/dist/schema/event-type.json +3 -1
- package/dist/schema/hello-message.json +21 -0
- package/dist/schema/reticle-event.json +3 -1
- package/dist/schema/reticle-message.json +54 -1
- package/dist/telemetry-bug.d.ts +169 -0
- package/dist/telemetry-bug.js +123 -0
- package/dist/telemetry-entry.d.ts +2 -1
- package/dist/telemetry-entry.js +2 -1
- package/dist/telemetry-feedback.d.ts +16 -2
- package/dist/telemetry-feedback.js +19 -0
- package/dist/telemetry-session.d.ts +91 -2
- package/dist/telemetry-session.js +65 -0
- package/dist/telemetry-signals.d.ts +557 -0
- package/dist/telemetry-signals.js +225 -0
- package/dist/telemetry.d.ts +649 -296
- package/dist/telemetry.js +110 -119
- package/dist/verdict/check-sentence.d.ts +34 -0
- package/dist/verdict/check-sentence.js +228 -0
- package/dist/verdict/consequence.d.ts +15 -0
- package/dist/verdict/consequence.js +11 -0
- package/dist/verdict/disparity.d.ts +105 -0
- package/dist/verdict/disparity.js +40 -0
- package/dist/verdict/findings.d.ts +16 -0
- package/dist/verdict/findings.js +22 -0
- package/dist/verdict/instrumentation-coverage.d.ts +84 -0
- package/dist/verdict/instrumentation-coverage.js +182 -0
- package/dist/verdict/instrumentation-gap.d.ts +79 -0
- package/dist/verdict/instrumentation-gap.js +65 -1
- package/dist/verdict/intent.d.ts +19 -5
- package/dist/verdict/intent.js +13 -1
- package/dist/verdict/predicate-tree.d.ts +17 -0
- package/dist/verdict/predicate-tree.js +37 -0
- package/dist/verdict/predicate.d.ts +16 -1
- package/dist/verdict/predicate.js +188 -13
- package/dist/verdict/property-assertion.d.ts +2 -2
- package/dist/verdict/run-report.d.ts +166 -0
- package/dist/verdict/run-report.js +53 -0
- package/dist/verdict/security.d.ts +60 -1
- package/dist/verdict/security.js +174 -12
- package/dist/verdict/verification-run.d.ts +713 -68
- package/dist/verdict/verification-run.js +113 -0
- package/dist/verdict/verify-progress.d.ts +6 -6
- package/dist/wire/constants/constants.d.ts +69 -155
- package/dist/wire/constants/constants.js +78 -159
- package/dist/wire/constants/discovery.d.ts +4 -4
- package/dist/wire/constants/discovery.js +4 -4
- package/dist/wire/constants/event-types.d.ts +35 -1
- package/dist/wire/constants/event-types.js +33 -1
- package/dist/wire/constants/hud-controls.js +15 -5
- package/dist/wire/constants/hud-use.d.ts +33 -4
- package/dist/wire/constants/hud-use.js +30 -4
- package/dist/wire/constants/mcp-wire.d.ts +26 -0
- package/dist/wire/constants/mcp-wire.js +26 -0
- package/dist/wire/constants/response-body-reason.d.ts +19 -0
- package/dist/wire/constants/response-body-reason.js +18 -0
- package/dist/wire/constants/reticle-chrome.d.ts +19 -0
- package/dist/wire/constants/reticle-chrome.js +19 -0
- package/dist/wire/constants/reticle-env.d.ts +138 -0
- package/dist/wire/constants/reticle-env.js +138 -0
- package/dist/wire/constants/session-constants.d.ts +26 -2
- package/dist/wire/constants/session-constants.js +26 -2
- package/dist/wire/desktop-contract.d.ts +8 -0
- package/dist/wire/desktop-contract.js +11 -0
- package/dist/wire/event-payloads.d.ts +202 -36
- package/dist/wire/event-payloads.js +100 -16
- package/dist/wire/messages.d.ts +193 -54
- package/dist/wire/messages.js +25 -1
- package/dist/wire/narrow.d.ts +6 -0
- package/dist/wire/narrow.js +26 -0
- package/dist/wire/next-step.d.ts +90 -0
- package/dist/wire/next-step.js +37 -0
- package/dist/wire/platform-link.d.ts +84 -0
- package/dist/wire/platform-link.js +57 -6
- package/dist/wire/production/activation-ticket.d.ts +64 -0
- package/dist/wire/production/activation-ticket.js +148 -0
- package/dist/wire/production/hello-mode.d.ts +35 -0
- package/dist/wire/production/hello-mode.js +32 -0
- package/dist/wire/production/production-policy.d.ts +138 -0
- package/dist/wire/production/production-policy.js +133 -0
- package/dist/wire/tool-names.d.ts +4 -0
- package/dist/wire/tool-names.js +4 -0
- package/dist/wire/types.d.ts +90 -52
- package/dist/wire/types.js +5 -0
- package/dist/words/notices.d.ts +1 -1
- package/dist/words/notices.js +1 -1
- package/dist/words/upgrade.js +1 -1
- package/dist/words/writing-rule.d.ts +14 -0
- package/dist/words/writing-rule.js +17 -0
- package/package.json +5 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The App Graph (what the cloud calls the App Map): the app as a graph, built from what each run recorded.
|
|
3
|
+
*
|
|
4
|
+
* Nodes are screens (route patterns), actions (what an act pressed, anchored the way a saved flow
|
|
5
|
+
* anchors it), requests (method and route pattern) and the things writes made. Edges say a screen HAS
|
|
6
|
+
* an action, an action LEADS TO a screen, SENDS a request and MAKES a thing. Everything here was
|
|
7
|
+
* observed: the model's words never add a node. Ids collapse (`templatePath`), so a hundred
|
|
8
|
+
* conversations are one screen and a row the drive created is a thing made, never a new screen: the
|
|
9
|
+
* create-and-back-out loop a state graph otherwise falls into: each new row looks like a new screen,
|
|
10
|
+
* so the drive keeps making rows and backing out.
|
|
11
|
+
*
|
|
12
|
+
* Pure: a run's acts and recording in, a run's map out; merged into the app's map across runs. One fold,
|
|
13
|
+
* here in core, so the cloud verifier and the open-source daemon describe an app the same way: a fix to
|
|
14
|
+
* how a screen is named lands in both. A run's acts arrive already parsed (`DrivenStep`): reading them
|
|
15
|
+
* off a harness's tool calls needs the server package, so each caller does that and hands this the steps.
|
|
16
|
+
*/
|
|
17
|
+
import type { ReticleEvent } from '../wire/messages.js';
|
|
18
|
+
/** One act a drive dispatched, anchored the way a flow anchors it, with its own window of events. */
|
|
19
|
+
export interface DrivenStep {
|
|
20
|
+
anchor: Record<string, unknown>;
|
|
21
|
+
since: number;
|
|
22
|
+
window: readonly ReticleEvent[];
|
|
23
|
+
/** Whether the consequence it declared held: absent when it declared none. */
|
|
24
|
+
held?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** What a layout audit measured wrong on a screen (clipped text, overlap, contrast). */
|
|
27
|
+
export interface LayoutDefectSeen {
|
|
28
|
+
kind: string;
|
|
29
|
+
what: string;
|
|
30
|
+
value: number;
|
|
31
|
+
bound: number;
|
|
32
|
+
}
|
|
33
|
+
/** An app's identity: its origin, so every path of one deployment is one app. */
|
|
34
|
+
export declare function appIdentity(url: string): string;
|
|
35
|
+
/** A path or URL as a route pattern: query dropped, origin dropped, record ids as `:id`. */
|
|
36
|
+
export declare function templatePath(url: string): string;
|
|
37
|
+
/** The route a route-change event names: the app's own pattern first, else the path it went to. */
|
|
38
|
+
export declare const routeOf: (data: Record<string, unknown>) => string | undefined;
|
|
39
|
+
export declare const MapNodeKind: {
|
|
40
|
+
readonly SCREEN: "screen";
|
|
41
|
+
readonly ACTION: "action";
|
|
42
|
+
readonly REQUEST: "request";
|
|
43
|
+
readonly THING: "thing";
|
|
44
|
+
};
|
|
45
|
+
export type MapNodeKind = (typeof MapNodeKind)[keyof typeof MapNodeKind];
|
|
46
|
+
export declare const MapEdgeKind: {
|
|
47
|
+
readonly HAS: "has";
|
|
48
|
+
readonly LEADS_TO: "leads-to";
|
|
49
|
+
readonly SENDS: "sends";
|
|
50
|
+
readonly MAKES: "makes";
|
|
51
|
+
};
|
|
52
|
+
export type MapEdgeKind = (typeof MapEdgeKind)[keyof typeof MapEdgeKind];
|
|
53
|
+
export interface MapNode {
|
|
54
|
+
id: string;
|
|
55
|
+
kind: MapNodeKind;
|
|
56
|
+
label: string;
|
|
57
|
+
/** Runs that saw it. */
|
|
58
|
+
seen: number;
|
|
59
|
+
lastRun: string;
|
|
60
|
+
/** For an action: runs in which a consequence it declared held, and in which one was refuted. */
|
|
61
|
+
proven?: number;
|
|
62
|
+
refuted?: number;
|
|
63
|
+
/** For an action: runs in which it was pressed. An action only seen on its screen has none. */
|
|
64
|
+
pressed?: number;
|
|
65
|
+
/** For a pressed action: how to press it again, as the act that pressed it named the element. */
|
|
66
|
+
anchor?: Anchor;
|
|
67
|
+
/** For a screen: problems the latest run that reached it found there. Cleared by a clean one. */
|
|
68
|
+
found?: number;
|
|
69
|
+
}
|
|
70
|
+
/** How an act names an element: by test id, or by role and accessible name. */
|
|
71
|
+
export interface Anchor {
|
|
72
|
+
by: string;
|
|
73
|
+
value: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface MapEdge {
|
|
77
|
+
from: string;
|
|
78
|
+
to: string;
|
|
79
|
+
kind: MapEdgeKind;
|
|
80
|
+
seen: number;
|
|
81
|
+
lastRun: string;
|
|
82
|
+
}
|
|
83
|
+
export interface AppMap {
|
|
84
|
+
nodes: readonly MapNode[];
|
|
85
|
+
edges: readonly MapEdge[];
|
|
86
|
+
}
|
|
87
|
+
/** One run's map, before it is merged: what it saw, without counts. */
|
|
88
|
+
export interface RunMap {
|
|
89
|
+
nodes: Map<string, {
|
|
90
|
+
kind: MapNodeKind;
|
|
91
|
+
label: string;
|
|
92
|
+
held?: boolean;
|
|
93
|
+
pressed?: true;
|
|
94
|
+
anchor?: Anchor;
|
|
95
|
+
found?: number;
|
|
96
|
+
}>;
|
|
97
|
+
edges: Map<string, {
|
|
98
|
+
from: string;
|
|
99
|
+
to: string;
|
|
100
|
+
kind: MapEdgeKind;
|
|
101
|
+
}>;
|
|
102
|
+
}
|
|
103
|
+
/** One control a look saw on a screen. */
|
|
104
|
+
export interface SeenControl {
|
|
105
|
+
role: string;
|
|
106
|
+
name: string;
|
|
107
|
+
testid?: string;
|
|
108
|
+
/** The component it renders in, when the engine names it: a data-named row's identity. */
|
|
109
|
+
component?: string;
|
|
110
|
+
}
|
|
111
|
+
/** The controls each look saw, and on which screen. */
|
|
112
|
+
export interface SeenScreen {
|
|
113
|
+
screen: string;
|
|
114
|
+
controls: readonly SeenControl[];
|
|
115
|
+
/** What the engine's layout audit measured wrong on it, when it was asked. */
|
|
116
|
+
defects?: readonly LayoutDefectSeen[];
|
|
117
|
+
}
|
|
118
|
+
/** The controls in a snapshot tree; rows (long, data-named, with no test id) left out. */
|
|
119
|
+
export declare const controlsOf: (tree: string) => SeenControl[];
|
|
120
|
+
/** The map one run recorded. `start` is the route the run was loaded on. */
|
|
121
|
+
export declare function mapOfRun(steps: readonly DrivenStep[], events: readonly ReticleEvent[], start?: string, seen?: readonly SeenScreen[]): RunMap;
|
|
122
|
+
/** The app's map with one more run folded in: counts add up, nothing a run did not see is lost. */
|
|
123
|
+
export declare function mergeMap(map: AppMap | undefined, run: RunMap, runId: string): AppMap;
|
|
124
|
+
/** What the map knows, in one line. */
|
|
125
|
+
export declare function mapLine(map: AppMap): string;
|
|
126
|
+
/**
|
|
127
|
+
* The most important screens first, with how much of each is proven: where the next run should go.
|
|
128
|
+
* Importance is read off the graph, never guessed: the actions that lead to a screen, and, twice over,
|
|
129
|
+
* the kinds of thing its actions make (the work people come to do).
|
|
130
|
+
*/
|
|
131
|
+
export declare function frontierLine(map: AppMap): string;
|
|
132
|
+
/**
|
|
133
|
+
* The actions to press to get from one screen to another, by the map's pressed edges: the shortest
|
|
134
|
+
* way, each by the anchor it was pressed with. Empty when already there; undefined when the map knows
|
|
135
|
+
* no way (a run then reaches it some other way, or a replay starts where it is).
|
|
136
|
+
*/
|
|
137
|
+
export declare function pathTo(map: AppMap, from: string, to: string): Anchor[] | undefined;
|
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The App Graph (what the cloud calls the App Map): the app as a graph, built from what each run recorded.
|
|
3
|
+
*
|
|
4
|
+
* Nodes are screens (route patterns), actions (what an act pressed, anchored the way a saved flow
|
|
5
|
+
* anchors it), requests (method and route pattern) and the things writes made. Edges say a screen HAS
|
|
6
|
+
* an action, an action LEADS TO a screen, SENDS a request and MAKES a thing. Everything here was
|
|
7
|
+
* observed: the model's words never add a node. Ids collapse (`templatePath`), so a hundred
|
|
8
|
+
* conversations are one screen and a row the drive created is a thing made, never a new screen: the
|
|
9
|
+
* create-and-back-out loop a state graph otherwise falls into: each new row looks like a new screen,
|
|
10
|
+
* so the drive keeps making rows and backing out.
|
|
11
|
+
*
|
|
12
|
+
* Pure: a run's acts and recording in, a run's map out; merged into the app's map across runs. One fold,
|
|
13
|
+
* here in core, so the cloud verifier and the open-source daemon describe an app the same way: a fix to
|
|
14
|
+
* how a screen is named lands in both. A run's acts arrive already parsed (`DrivenStep`): reading them
|
|
15
|
+
* off a harness's tool calls needs the server package, so each caller does that and hands this the steps.
|
|
16
|
+
*/
|
|
17
|
+
import { EventType } from '../wire/constants/event-types.js';
|
|
18
|
+
import { NetInitiator, isDevToolingUrl } from '../wire/net.js';
|
|
19
|
+
/** An app's identity: its origin, so every path of one deployment is one app. */
|
|
20
|
+
export function appIdentity(url) {
|
|
21
|
+
try {
|
|
22
|
+
return new URL(url).origin;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Segments that identify one record rather than one kind of record: numeric, uuid-shaped, and a long
|
|
30
|
+
* run of id characters (`chat_659b…`, `run_9_1792651401085`). Anything cleverer would start guessing.
|
|
31
|
+
*/
|
|
32
|
+
const UUID_LIKE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
33
|
+
const NUMERIC = /^\d+$/;
|
|
34
|
+
const ID_RUN = /[0-9a-f]{12,}|\d{9,}/i;
|
|
35
|
+
const ID_PLACEHOLDER = ':id';
|
|
36
|
+
/** A path or URL as a route pattern: query dropped, origin dropped, record ids as `:id`. */
|
|
37
|
+
export function templatePath(url) {
|
|
38
|
+
const withoutQuery = url.split('?')[0] ?? url;
|
|
39
|
+
const path = withoutQuery.startsWith('http')
|
|
40
|
+
? (withoutQuery.split('/').slice(3).join('/') ?? '')
|
|
41
|
+
: withoutQuery.replace(/^\/+/, '');
|
|
42
|
+
const segments = path
|
|
43
|
+
.split('/')
|
|
44
|
+
.map((segment) => NUMERIC.test(segment) || UUID_LIKE.test(segment) || ID_RUN.test(segment)
|
|
45
|
+
? ID_PLACEHOLDER
|
|
46
|
+
: segment);
|
|
47
|
+
return `/${segments.join('/')}`;
|
|
48
|
+
}
|
|
49
|
+
const asString = (value) => 'string' === typeof value ? value : undefined;
|
|
50
|
+
/** The route a route-change event names: the app's own pattern first, else the path it went to. */
|
|
51
|
+
export const routeOf = (data) => asString(data['pattern']) ??
|
|
52
|
+
asString(data['pathname']) ??
|
|
53
|
+
asString(data['to']) ??
|
|
54
|
+
asString(data['path']);
|
|
55
|
+
export const MapNodeKind = {
|
|
56
|
+
SCREEN: 'screen',
|
|
57
|
+
ACTION: 'action',
|
|
58
|
+
REQUEST: 'request',
|
|
59
|
+
THING: 'thing',
|
|
60
|
+
};
|
|
61
|
+
export const MapEdgeKind = {
|
|
62
|
+
HAS: 'has',
|
|
63
|
+
LEADS_TO: 'leads-to',
|
|
64
|
+
SENDS: 'sends',
|
|
65
|
+
MAKES: 'makes',
|
|
66
|
+
};
|
|
67
|
+
const WRITES = new Set(['POST', 'PUT', 'PATCH']);
|
|
68
|
+
const READS = new Set(['GET', 'HEAD']);
|
|
69
|
+
const APP_INITIATORS = new Set([NetInitiator.FETCH, NetInitiator.XHR]);
|
|
70
|
+
const OK_MIN = 200;
|
|
71
|
+
const OK_MAX = 300;
|
|
72
|
+
const str = (value) => 'string' === typeof value && '' !== value ? value : undefined;
|
|
73
|
+
/** A control's name with its counts taken out: "Open 2" and "Open 3" are one control. */
|
|
74
|
+
const normalName = (name) => name.replace(/\d+/g, '#').trim();
|
|
75
|
+
/** A name this long is a row's data, not a control's label: a row is a thing, never an action. */
|
|
76
|
+
const ROW_NAME_CHARS = 60;
|
|
77
|
+
/**
|
|
78
|
+
* What a person presses or fills. A list's options, a region or a heading is the screen's content: an
|
|
79
|
+
* option without a test id is a row of data (a palette entry, a search result), so it stays out.
|
|
80
|
+
*/
|
|
81
|
+
const CONTROL_ROLES = new Set([
|
|
82
|
+
'button',
|
|
83
|
+
'link',
|
|
84
|
+
'textbox',
|
|
85
|
+
'searchbox',
|
|
86
|
+
'combobox',
|
|
87
|
+
'checkbox',
|
|
88
|
+
'radio',
|
|
89
|
+
'switch',
|
|
90
|
+
'tab',
|
|
91
|
+
'menuitem',
|
|
92
|
+
'menuitemcheckbox',
|
|
93
|
+
'menuitemradio',
|
|
94
|
+
'slider',
|
|
95
|
+
'spinbutton',
|
|
96
|
+
]);
|
|
97
|
+
/** A snapshot line's start: `- <role> "`. */
|
|
98
|
+
const LINE_HEAD = /^\s*- (\S+) "/;
|
|
99
|
+
/** What ends a name, before the ref: `" (ref=`. */
|
|
100
|
+
const REF_OPEN = '" (ref=';
|
|
101
|
+
const REF_CLOSE = ')';
|
|
102
|
+
/** Line breaks other than `\n`. A name or a rest that holds one is not read. */
|
|
103
|
+
const LINE_BREAK = /[\r\u2028\u2029]/g;
|
|
104
|
+
/**
|
|
105
|
+
* A snapshot line as role, name and the part after the ref: `- <role> "<name>" (ref=<ref>)<rest>`.
|
|
106
|
+
* The name runs to the LAST `" (ref=` that a non-empty ref and a `)` follow.
|
|
107
|
+
*
|
|
108
|
+
* Read with `indexOf`, not one regular expression. The page writes this text, and a pattern with
|
|
109
|
+
* two open-ended groups backtracks: its time grows with the square of the line length.
|
|
110
|
+
*/
|
|
111
|
+
const snapshotLine = (line) => {
|
|
112
|
+
const head = LINE_HEAD.exec(line);
|
|
113
|
+
if (null === head) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const start = head[0].length;
|
|
117
|
+
const breaks = [...line.slice(start).matchAll(LINE_BREAK)].map((m) => start + m.index);
|
|
118
|
+
const firstBreak = breaks[0] ?? line.length;
|
|
119
|
+
const lastBreak = breaks[breaks.length - 1] ?? -1;
|
|
120
|
+
const lastClose = line.lastIndexOf(REF_CLOSE);
|
|
121
|
+
for (let at = line.lastIndexOf(REF_OPEN); start <= at; at = line.lastIndexOf(REF_OPEN, at - 1)) {
|
|
122
|
+
const ref = at + REF_OPEN.length;
|
|
123
|
+
if (ref < lastClose && REF_CLOSE !== line[ref]) {
|
|
124
|
+
const close = line.indexOf(REF_CLOSE, ref);
|
|
125
|
+
// A break may sit only inside the ref: never in the name, never in the rest.
|
|
126
|
+
if (at <= firstBreak && lastBreak < close) {
|
|
127
|
+
return { role: head[1] ?? '', name: line.slice(start, at), rest: line.slice(close + 1) };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
};
|
|
133
|
+
/** The value of the first `[key=value]` with a non-empty value, read in one pass. */
|
|
134
|
+
const bracketValue = (text, key) => {
|
|
135
|
+
const open = `[${key}=`;
|
|
136
|
+
for (let at = text.indexOf(open); -1 !== at; at = text.indexOf(open, at + 1)) {
|
|
137
|
+
const start = at + open.length;
|
|
138
|
+
const end = text.indexOf(']', start);
|
|
139
|
+
if (-1 === end) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
if (start < end) {
|
|
143
|
+
return text.slice(start, end);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
};
|
|
148
|
+
/** The controls in a snapshot tree; rows (long, data-named, with no test id) left out. */
|
|
149
|
+
export const controlsOf = (tree) => tree.split('\n').flatMap((line) => {
|
|
150
|
+
const parsed = snapshotLine(line);
|
|
151
|
+
if (parsed === undefined) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
const { role, name, rest } = parsed;
|
|
155
|
+
const testid = bracketValue(rest, 'testid');
|
|
156
|
+
const component = bracketValue(rest, 'component');
|
|
157
|
+
if (testid === undefined && !CONTROL_ROLES.has(role)) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
// A data-named row is kept only when its component names it; otherwise it is the row's data.
|
|
161
|
+
if (testid === undefined && component === undefined && name.length > ROW_NAME_CHARS) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
return [
|
|
165
|
+
{
|
|
166
|
+
role,
|
|
167
|
+
name: normalName(name),
|
|
168
|
+
...(testid === undefined ? {} : { testid }),
|
|
169
|
+
...(component === undefined ? {} : { component }),
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
});
|
|
173
|
+
/** A seen control's identity on its screen, the same as the act that presses it would have. */
|
|
174
|
+
const controlKey = (c) => {
|
|
175
|
+
if (c.testid !== undefined) {
|
|
176
|
+
return `testid=${c.testid}`;
|
|
177
|
+
}
|
|
178
|
+
if (c.component !== undefined && c.name.length > ROW_NAME_CHARS) {
|
|
179
|
+
return `component=${c.component}`;
|
|
180
|
+
}
|
|
181
|
+
if ('' === c.name) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
return `${c.role} "${c.name}"`;
|
|
185
|
+
};
|
|
186
|
+
/** An action's identity on its screen: the anchor a flow would use, never a ref. */
|
|
187
|
+
const anchorKey = (anchor) => {
|
|
188
|
+
const value = str(anchor['value']);
|
|
189
|
+
if ('testid' === anchor['by'] && value !== undefined) {
|
|
190
|
+
return `testid=${value}`;
|
|
191
|
+
}
|
|
192
|
+
const name = str(anchor['name']);
|
|
193
|
+
const component = str(anchor['component']);
|
|
194
|
+
// A row named by its data is one action of its component, as the look that saw it keyed it.
|
|
195
|
+
if (component !== undefined && name !== undefined && name.length > ROW_NAME_CHARS) {
|
|
196
|
+
return `component=${component}`;
|
|
197
|
+
}
|
|
198
|
+
if ('role' === anchor['by'] && value !== undefined && name !== undefined) {
|
|
199
|
+
return `${value} "${normalName(name)}"`;
|
|
200
|
+
}
|
|
201
|
+
return component === undefined ? undefined : `component=${component}`;
|
|
202
|
+
};
|
|
203
|
+
/** What a write to a path made: its last segment that names a kind (`/v1/projects/:id/envs` → envs). */
|
|
204
|
+
const thingOf = (path) => path
|
|
205
|
+
.split('/')
|
|
206
|
+
.filter((segment) => '' !== segment && !segment.startsWith(':') && !/^v\d+$/.test(segment))
|
|
207
|
+
.at(-1);
|
|
208
|
+
/**
|
|
209
|
+
* The type a write's answer names, when it is JSON and says: Stripe's `object`, JSON:API's
|
|
210
|
+
* `data.type`, or GraphQL's `__typename` a few levels down. Every GraphQL write goes to one path, so
|
|
211
|
+
* the path alone would call every thing "graphql"; a REST answer that declares nothing keeps its path.
|
|
212
|
+
*/
|
|
213
|
+
const TYPENAME_DEPTH = 4;
|
|
214
|
+
const typenameOf = (body) => {
|
|
215
|
+
if ('string' !== typeof body || '' === body) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
let parsed;
|
|
219
|
+
try {
|
|
220
|
+
parsed = JSON.parse(body);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
// REST's own declarations: Stripe's `object`, JSON:API's `data.type`.
|
|
226
|
+
const top = parsed;
|
|
227
|
+
if (null !== top && 'object' === typeof top) {
|
|
228
|
+
if ('string' === typeof top.object && '' !== top.object) {
|
|
229
|
+
return top.object;
|
|
230
|
+
}
|
|
231
|
+
if ('string' === typeof top.data?.type && '' !== top.data.type) {
|
|
232
|
+
return top.data.type;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (!body.includes('__typename')) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
const walk = (value, depth) => {
|
|
239
|
+
if (depth > TYPENAME_DEPTH || null === value || 'object' !== typeof value) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
const own = value['__typename'];
|
|
243
|
+
if ('string' === typeof own && '' !== own) {
|
|
244
|
+
return own;
|
|
245
|
+
}
|
|
246
|
+
for (const child of Object.values(value)) {
|
|
247
|
+
const found = walk(child, depth + 1);
|
|
248
|
+
if (found !== undefined) {
|
|
249
|
+
return found;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return undefined;
|
|
253
|
+
};
|
|
254
|
+
return walk(parsed, 0);
|
|
255
|
+
};
|
|
256
|
+
/** The map one run recorded. `start` is the route the run was loaded on. */
|
|
257
|
+
export function mapOfRun(steps, events, start, seen = []) {
|
|
258
|
+
const nodes = new Map();
|
|
259
|
+
const edges = new Map();
|
|
260
|
+
const node = (kind, label) => {
|
|
261
|
+
const id = `${kind} ${label}`;
|
|
262
|
+
if (!nodes.has(id)) {
|
|
263
|
+
nodes.set(id, { kind, label });
|
|
264
|
+
}
|
|
265
|
+
return id;
|
|
266
|
+
};
|
|
267
|
+
const edge = (from, to, kind) => {
|
|
268
|
+
edges.set(`${from} ${kind} ${to}`, { from, to, kind });
|
|
269
|
+
};
|
|
270
|
+
const screenOf = (path) => node(MapNodeKind.SCREEN, templatePath(path));
|
|
271
|
+
const routes = events
|
|
272
|
+
.filter((e) => EventType.ROUTE_CHANGE === e.type)
|
|
273
|
+
.map((e) => ({ t: e.t, path: routeOf(e.data) }))
|
|
274
|
+
.filter((r) => r.path !== undefined);
|
|
275
|
+
if (start !== undefined) {
|
|
276
|
+
screenOf(start);
|
|
277
|
+
}
|
|
278
|
+
for (const r of routes) {
|
|
279
|
+
screenOf(r.path);
|
|
280
|
+
}
|
|
281
|
+
// The screen an act was pressed on: the last route before its window opened.
|
|
282
|
+
const on = (since) => {
|
|
283
|
+
const before = routes.filter((r) => r.t < since).at(-1)?.path ?? start;
|
|
284
|
+
return before === undefined ? undefined : templatePath(before);
|
|
285
|
+
};
|
|
286
|
+
// A look records the address; the route change that reached it named the screen. Same screen.
|
|
287
|
+
const named = new Map(events
|
|
288
|
+
.filter((e) => EventType.ROUTE_CHANGE === e.type)
|
|
289
|
+
.flatMap((e) => {
|
|
290
|
+
const at = str(e.data['pathname']);
|
|
291
|
+
const pattern = str(e.data['pattern']);
|
|
292
|
+
return at === undefined || pattern === undefined ? [] : [[at, pattern]];
|
|
293
|
+
}));
|
|
294
|
+
// What each look saw: every control a screen offers, pressed or not.
|
|
295
|
+
for (const look of seen) {
|
|
296
|
+
const screen = templatePath(named.get(look.screen) ?? look.screen);
|
|
297
|
+
const at = node(MapNodeKind.SCREEN, screen);
|
|
298
|
+
for (const control of look.controls) {
|
|
299
|
+
const key = controlKey(control);
|
|
300
|
+
if (key !== undefined) {
|
|
301
|
+
edge(at, node(MapNodeKind.ACTION, `${screen} ${key}`), MapEdgeKind.HAS);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Reads the app sent with nothing pressed (a poll, a badge refresh) are its background: one that
|
|
307
|
+
* lands inside an action's window was not caused by it. Writes are always the action's.
|
|
308
|
+
*/
|
|
309
|
+
const pressedWindows = new Set(steps.flatMap((s) => s.window));
|
|
310
|
+
const background = new Set(events
|
|
311
|
+
.filter((e) => EventType.NET_REQUEST === e.type && !pressedWindows.has(e))
|
|
312
|
+
.map((e) => `${(str(e.data['method']) ?? 'GET').toUpperCase()} ${templatePath(str(e.data['url']) ?? '')}`)
|
|
313
|
+
.filter((key) => READS.has(key.split(' ')[0] ?? '')));
|
|
314
|
+
for (const s of steps) {
|
|
315
|
+
const key = anchorKey(s.anchor);
|
|
316
|
+
const screen = on(s.since);
|
|
317
|
+
if (key === undefined || screen === undefined) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const action = node(MapNodeKind.ACTION, `${screen} ${key}`);
|
|
321
|
+
// Proven if any press of it this run held; refuted only if one failed and none held.
|
|
322
|
+
const seenAs = nodes.get(action);
|
|
323
|
+
if (seenAs !== undefined) {
|
|
324
|
+
seenAs.pressed = true;
|
|
325
|
+
const by = str(s.anchor['by']);
|
|
326
|
+
const value = str(s.anchor['value']);
|
|
327
|
+
const name = str(s.anchor['name']);
|
|
328
|
+
if (by !== undefined && value !== undefined) {
|
|
329
|
+
seenAs.anchor = { by, value, ...(name === undefined ? {} : { name }) };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (seenAs !== undefined && s.held !== undefined && true !== seenAs.held) {
|
|
333
|
+
seenAs.held = s.held;
|
|
334
|
+
}
|
|
335
|
+
edge(node(MapNodeKind.SCREEN, screen), action, MapEdgeKind.HAS);
|
|
336
|
+
for (const e of s.window) {
|
|
337
|
+
if (EventType.ROUTE_CHANGE === e.type) {
|
|
338
|
+
const to = routeOf(e.data);
|
|
339
|
+
if (to !== undefined) {
|
|
340
|
+
edge(action, screenOf(to), MapEdgeKind.LEADS_TO);
|
|
341
|
+
}
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (EventType.NET_REQUEST !== e.type) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const url = str(e.data['url']) ?? '';
|
|
348
|
+
if (isDevToolingUrl(url) || !APP_INITIATORS.has(str(e.data['initiator']) ?? '')) {
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const method = (str(e.data['method']) ?? 'GET').toUpperCase();
|
|
352
|
+
const path = templatePath(url);
|
|
353
|
+
if (background.has(`${method} ${path}`)) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
edge(action, node(MapNodeKind.REQUEST, `${method} ${path}`), MapEdgeKind.SENDS);
|
|
357
|
+
const status = 'number' === typeof e.data['status'] ? e.data['status'] : 0;
|
|
358
|
+
const made = typenameOf(e.data['responseBody']) ?? thingOf(path);
|
|
359
|
+
if (WRITES.has(method) && status >= OK_MIN && status < OK_MAX && made !== undefined) {
|
|
360
|
+
edge(action, node(MapNodeKind.THING, made), MapEdgeKind.MAKES);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return { nodes, edges };
|
|
365
|
+
}
|
|
366
|
+
/** The app's map with one more run folded in: counts add up, nothing a run did not see is lost. */
|
|
367
|
+
export function mergeMap(map, run, runId) {
|
|
368
|
+
const nodes = new Map((map?.nodes ?? []).map((n) => [n.id, { ...n }]));
|
|
369
|
+
for (const [id, { held: verdict, pressed: wasPressed, anchor: pressedBy, ...n }] of run.nodes) {
|
|
370
|
+
const held = nodes.get(id);
|
|
371
|
+
const proven = (held?.proven ?? 0) + (true === verdict ? 1 : 0);
|
|
372
|
+
const refuted = (held?.refuted ?? 0) + (false === verdict ? 1 : 0);
|
|
373
|
+
const pressed = (held?.pressed ?? 0) + (true === wasPressed ? 1 : 0);
|
|
374
|
+
nodes.set(id, {
|
|
375
|
+
id,
|
|
376
|
+
...n,
|
|
377
|
+
seen: (held?.seen ?? 0) + 1,
|
|
378
|
+
lastRun: runId,
|
|
379
|
+
...(0 === proven ? {} : { proven }),
|
|
380
|
+
...(0 === refuted ? {} : { refuted }),
|
|
381
|
+
...(0 === pressed ? {} : { pressed }),
|
|
382
|
+
// The latest way it was pressed, else the one it was pressed by before.
|
|
383
|
+
...((a) => (a === undefined ? {} : { anchor: a }))(pressedBy ?? held?.anchor),
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
const key = (e) => `${e.from} ${e.kind} ${e.to}`;
|
|
387
|
+
const edges = new Map((map?.edges ?? []).map((e) => [key(e), { ...e }]));
|
|
388
|
+
for (const e of run.edges.values()) {
|
|
389
|
+
const held = edges.get(key(e));
|
|
390
|
+
edges.set(key(e), { ...e, seen: (held?.seen ?? 0) + 1, lastRun: runId });
|
|
391
|
+
}
|
|
392
|
+
const byId = (a, b) => a.id.localeCompare(b.id);
|
|
393
|
+
return {
|
|
394
|
+
nodes: [...nodes.values()].sort(byId),
|
|
395
|
+
edges: [...edges.values()].sort((a, b) => key(a).localeCompare(key(b))),
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/** What the map knows, in one line. */
|
|
399
|
+
export function mapLine(map) {
|
|
400
|
+
const of = (kind) => map.nodes.filter((n) => kind === n.kind);
|
|
401
|
+
const count = (n, one, many) => `${String(n)} ${1 === n ? one : many}`;
|
|
402
|
+
const things = of(MapNodeKind.THING).map((n) => n.label);
|
|
403
|
+
return `The map so far: ${count(of(MapNodeKind.SCREEN).length, 'screen', 'screens')}, ${count(of(MapNodeKind.ACTION).length, 'action', 'actions')}, ${count(of(MapNodeKind.REQUEST).length, 'request', 'requests')}, ${count(things.length, 'thing made', 'things made')}${0 === things.length ? '' : ` (${things.join(', ')})`}.`;
|
|
404
|
+
}
|
|
405
|
+
/** At most this many screens the frontier line names. */
|
|
406
|
+
const FRONTIER_NAMED = 6;
|
|
407
|
+
/**
|
|
408
|
+
* The most important screens first, with how much of each is proven: where the next run should go.
|
|
409
|
+
* Importance is read off the graph, never guessed: the actions that lead to a screen, and, twice over,
|
|
410
|
+
* the kinds of thing its actions make (the work people come to do).
|
|
411
|
+
*/
|
|
412
|
+
export function frontierLine(map) {
|
|
413
|
+
const plural = (n, one) => `${String(n)} ${one}${1 === n ? '' : 's'}`;
|
|
414
|
+
const screens = map.nodes
|
|
415
|
+
.filter((n) => MapNodeKind.SCREEN === n.kind)
|
|
416
|
+
.map((screen) => {
|
|
417
|
+
const actions = map.edges
|
|
418
|
+
.filter((e) => MapEdgeKind.HAS === e.kind && screen.id === e.from)
|
|
419
|
+
.map((e) => e.to);
|
|
420
|
+
const inbound = new Set(map.edges
|
|
421
|
+
.filter((e) => MapEdgeKind.LEADS_TO === e.kind && screen.id === e.to)
|
|
422
|
+
.map((e) => e.from)).size;
|
|
423
|
+
const makes = [
|
|
424
|
+
...new Set(map.edges
|
|
425
|
+
.filter((e) => MapEdgeKind.MAKES === e.kind && actions.includes(e.from))
|
|
426
|
+
.map((e) => e.to.replace(`${MapNodeKind.THING} `, ''))),
|
|
427
|
+
];
|
|
428
|
+
const count = (field) => actions.filter((id) => 0 < (map.nodes.find((n) => id === n.id)?.[field] ?? 0)).length;
|
|
429
|
+
const tried = count('pressed');
|
|
430
|
+
const facts = [
|
|
431
|
+
...(0 === actions.length
|
|
432
|
+
? []
|
|
433
|
+
: [
|
|
434
|
+
`${String(tried)} of ${plural(actions.length, 'action')} tried, ${String(count('proven'))} proven`,
|
|
435
|
+
]),
|
|
436
|
+
...(0 === inbound ? [] : [`reached from ${plural(inbound, 'action')}`]),
|
|
437
|
+
...(0 === makes.length ? [] : [`makes ${makes.join(', ')}`]),
|
|
438
|
+
];
|
|
439
|
+
return {
|
|
440
|
+
label: screen.label,
|
|
441
|
+
score: inbound + 2 * makes.length,
|
|
442
|
+
untried: actions.length - tried,
|
|
443
|
+
facts,
|
|
444
|
+
};
|
|
445
|
+
})
|
|
446
|
+
.filter((s) => 0 < s.facts.length)
|
|
447
|
+
// The most important first; among equals, the one with the most left to try (the frontier rule).
|
|
448
|
+
.sort((a, b) => b.score - a.score || b.untried - a.untried)
|
|
449
|
+
.slice(0, FRONTIER_NAMED);
|
|
450
|
+
return 0 === screens.length
|
|
451
|
+
? ''
|
|
452
|
+
: `Most important first: ${screens.map((s) => `${s.label} (${s.facts.join(', ')})`).join(', ')}.`;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* The actions to press to get from one screen to another, by the map's pressed edges: the shortest
|
|
456
|
+
* way, each by the anchor it was pressed with. Empty when already there; undefined when the map knows
|
|
457
|
+
* no way (a run then reaches it some other way, or a replay starts where it is).
|
|
458
|
+
*/
|
|
459
|
+
export function pathTo(map, from, to) {
|
|
460
|
+
const start = `${MapNodeKind.SCREEN} ${templatePath(from)}`;
|
|
461
|
+
const goal = `${MapNodeKind.SCREEN} ${templatePath(to)}`;
|
|
462
|
+
if (start === goal) {
|
|
463
|
+
return [];
|
|
464
|
+
}
|
|
465
|
+
const anchors = new Map(map.nodes.flatMap((n) => (n.anchor === undefined ? [] : [[n.id, n.anchor]])));
|
|
466
|
+
// screen -> (action, next screen), only through actions that can be pressed again.
|
|
467
|
+
const next = new Map();
|
|
468
|
+
for (const has of map.edges.filter((e) => MapEdgeKind.HAS === e.kind && anchors.has(e.to))) {
|
|
469
|
+
for (const lead of map.edges.filter((e) => MapEdgeKind.LEADS_TO === e.kind && has.to === e.from)) {
|
|
470
|
+
next.set(has.from, [...(next.get(has.from) ?? []), { action: has.to, to: lead.to }]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const via = new Map();
|
|
474
|
+
const queue = [start];
|
|
475
|
+
for (let at = queue.shift(); at !== undefined; at = queue.shift()) {
|
|
476
|
+
for (const step of next.get(at) ?? []) {
|
|
477
|
+
if (step.to === start || via.has(step.to)) {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
via.set(step.to, { from: at, action: step.action });
|
|
481
|
+
if (step.to === goal) {
|
|
482
|
+
const path = [];
|
|
483
|
+
for (let back = via.get(goal); back !== undefined; back = via.get(back.from)) {
|
|
484
|
+
const anchor = anchors.get(back.action);
|
|
485
|
+
if (anchor !== undefined) {
|
|
486
|
+
path.unshift(anchor);
|
|
487
|
+
}
|
|
488
|
+
if (back.from === start) {
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return path;
|
|
493
|
+
}
|
|
494
|
+
queue.push(step.to);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return undefined;
|
|
498
|
+
}
|