@kurvball/rehearse 0.0.0-stage → 1.2.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.
- package/LICENSE +21 -0
- package/README.md +102 -2
- package/dist/affected/affected.d.ts +22 -0
- package/dist/affected/affected.js +162 -0
- package/dist/affected/index.d.ts +1 -0
- package/dist/affected/index.js +1 -0
- package/dist/args.d.ts +12 -0
- package/dist/args.js +42 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +100 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +42 -0
- package/dist/commands/clean.d.ts +2 -0
- package/dist/commands/clean.js +37 -0
- package/dist/commands/command.d.ts +29 -0
- package/dist/commands/command.js +29 -0
- package/dist/commands/compare.d.ts +4 -0
- package/dist/commands/compare.js +84 -0
- package/dist/commands/drive.d.ts +2 -0
- package/dist/commands/drive.js +244 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +32 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +19 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +69 -0
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +60 -0
- package/dist/commands/people.d.ts +2 -0
- package/dist/commands/people.js +49 -0
- package/dist/commands/run.d.ts +4 -0
- package/dist/commands/run.js +82 -0
- package/dist/commands/services.d.ts +28 -0
- package/dist/commands/services.js +51 -0
- package/dist/commands/stage.d.ts +7 -0
- package/dist/commands/stage.js +49 -0
- package/dist/commands/up.d.ts +3 -0
- package/dist/commands/up.js +77 -0
- package/dist/commands/validate.d.ts +2 -0
- package/dist/commands/validate.js +35 -0
- package/dist/commands/worlds.d.ts +2 -0
- package/dist/commands/worlds.js +15 -0
- package/dist/compare/announce.d.ts +6 -0
- package/dist/compare/announce.js +27 -0
- package/dist/compare/compare.d.ts +82 -0
- package/dist/compare/compare.js +310 -0
- package/dist/compare/diff.d.ts +15 -0
- package/dist/compare/diff.js +105 -0
- package/dist/compare/index.d.ts +4 -0
- package/dist/compare/index.js +4 -0
- package/dist/compare/setaside.d.ts +29 -0
- package/dist/compare/setaside.js +121 -0
- package/dist/compare/verdict.d.ts +21 -0
- package/dist/compare/verdict.js +30 -0
- package/dist/drive/aria.d.ts +8 -0
- package/dist/drive/aria.js +12 -0
- package/dist/drive/browser.d.ts +34 -0
- package/dist/drive/browser.js +216 -0
- package/dist/drive/daemon.d.ts +1 -0
- package/dist/drive/daemon.js +171 -0
- package/dist/drive/grammar.d.ts +93 -0
- package/dist/drive/grammar.js +303 -0
- package/dist/drive/index.d.ts +4 -0
- package/dist/drive/index.js +4 -0
- package/dist/drive/names.d.ts +24 -0
- package/dist/drive/names.js +97 -0
- package/dist/drive/state.d.ts +13 -0
- package/dist/drive/state.js +28 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +32 -0
- package/dist/exec.d.ts +16 -0
- package/dist/exec.js +43 -0
- package/dist/git/checkout.d.ts +11 -0
- package/dist/git/checkout.js +84 -0
- package/dist/git/git.d.ts +7 -0
- package/dist/git/git.js +27 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +15 -0
- package/dist/kinds/all.d.ts +4 -0
- package/dist/kinds/all.js +4 -0
- package/dist/kinds/call/check.d.ts +29 -0
- package/dist/kinds/call/check.js +187 -0
- package/dist/kinds/call/definition.d.ts +16 -0
- package/dist/kinds/call/definition.js +33 -0
- package/dist/kinds/call/hurl.d.ts +65 -0
- package/dist/kinds/call/hurl.js +333 -0
- package/dist/kinds/call/kind.d.ts +8 -0
- package/dist/kinds/call/kind.js +122 -0
- package/dist/kinds/call/send.d.ts +32 -0
- package/dist/kinds/call/send.js +152 -0
- package/dist/kinds/call/words.d.ts +22 -0
- package/dist/kinds/call/words.js +24 -0
- package/dist/kinds/file/kind.d.ts +44 -0
- package/dist/kinds/file/kind.js +331 -0
- package/dist/kinds/file/layouts.d.ts +14 -0
- package/dist/kinds/file/layouts.js +103 -0
- package/dist/kinds/flow/kind.d.ts +21 -0
- package/dist/kinds/flow/kind.js +401 -0
- package/dist/kinds/flow/literal.d.ts +8 -0
- package/dist/kinds/flow/literal.js +148 -0
- package/dist/kinds/index.d.ts +10 -0
- package/dist/kinds/index.js +8 -0
- package/dist/kinds/kind.d.ts +57 -0
- package/dist/kinds/kind.js +21 -0
- package/dist/kinds/piece/canvas.d.ts +18 -0
- package/dist/kinds/piece/canvas.js +165 -0
- package/dist/kinds/piece/conventions.d.ts +12 -0
- package/dist/kinds/piece/conventions.js +101 -0
- package/dist/kinds/piece/csf.d.ts +10 -0
- package/dist/kinds/piece/csf.js +304 -0
- package/dist/kinds/piece/kind.d.ts +12 -0
- package/dist/kinds/piece/kind.js +297 -0
- package/dist/kinds/piece/server.d.ts +23 -0
- package/dist/kinds/piece/server.js +236 -0
- package/dist/manifest/fill.d.ts +4 -0
- package/dist/manifest/fill.js +7 -0
- package/dist/manifest/index.d.ts +5 -0
- package/dist/manifest/index.js +5 -0
- package/dist/manifest/init.d.ts +1 -0
- package/dist/manifest/init.js +47 -0
- package/dist/manifest/load.d.ts +7 -0
- package/dist/manifest/load.js +244 -0
- package/dist/manifest/types.d.ts +253 -0
- package/dist/manifest/types.js +7 -0
- package/dist/manifest/yaml.d.ts +5 -0
- package/dist/manifest/yaml.js +47 -0
- package/dist/people/index.d.ts +1 -0
- package/dist/people/index.js +1 -0
- package/dist/people/people.d.ts +39 -0
- package/dist/people/people.js +139 -0
- package/dist/run/cache.d.ts +20 -0
- package/dist/run/cache.js +98 -0
- package/dist/run/index.d.ts +4 -0
- package/dist/run/index.js +3 -0
- package/dist/run/observation.d.ts +27 -0
- package/dist/run/observation.js +1 -0
- package/dist/run/session.d.ts +32 -0
- package/dist/run/session.js +258 -0
- package/dist/run/vars.d.ts +3 -0
- package/dist/run/vars.js +13 -0
- package/dist/scenarios/area.d.ts +6 -0
- package/dist/scenarios/area.js +37 -0
- package/dist/scenarios/files.d.ts +9 -0
- package/dist/scenarios/files.js +26 -0
- package/dist/scenarios/glob.d.ts +6 -0
- package/dist/scenarios/glob.js +106 -0
- package/dist/scenarios/index.d.ts +4 -0
- package/dist/scenarios/index.js +4 -0
- package/dist/scenarios/read.d.ts +18 -0
- package/dist/scenarios/read.js +54 -0
- package/dist/scenarios/scenario.d.ts +34 -0
- package/dist/scenarios/scenario.js +10 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +122 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/registry.d.ts +23 -0
- package/dist/services/registry.js +49 -0
- package/dist/services/service.d.ts +22 -0
- package/dist/services/service.js +284 -0
- package/dist/stage/api.d.ts +28 -0
- package/dist/stage/api.js +206 -0
- package/dist/stage/client/client/api.js +11 -0
- package/dist/stage/client/client/index.js +1 -0
- package/dist/stage/client/features/canvas/call.js +65 -0
- package/dist/stage/client/features/canvas/context.js +1 -0
- package/dist/stage/client/features/canvas/file.js +36 -0
- package/dist/stage/client/features/canvas/flow.js +59 -0
- package/dist/stage/client/features/canvas/index.js +1 -0
- package/dist/stage/client/features/canvas/observed.js +8 -0
- package/dist/stage/client/features/canvas/parts.js +24 -0
- package/dist/stage/client/features/canvas/piece.js +31 -0
- package/dist/stage/client/features/canvas/reach.js +6 -0
- package/dist/stage/client/features/canvas/views.js +16 -0
- package/dist/stage/client/features/list/index.js +1 -0
- package/dist/stage/client/features/list/list.js +53 -0
- package/dist/stage/client/features/list/reach.js +10 -0
- package/dist/stage/client/features/scenario/heading.js +14 -0
- package/dist/stage/client/features/scenario/index.js +1 -0
- package/dist/stage/client/features/scenario/reach.js +9 -0
- package/dist/stage/client/features/scenario/scenario.js +145 -0
- package/dist/stage/client/features/try/index.js +1 -0
- package/dist/stage/client/features/try/reach.js +12 -0
- package/dist/stage/client/features/try/try.js +65 -0
- package/dist/stage/client/index.html +16 -0
- package/dist/stage/client/main.js +24 -0
- package/dist/stage/client/primitives/busy.js +6 -0
- package/dist/stage/client/primitives/focus.js +21 -0
- package/dist/stage/client/primitives/h.js +25 -0
- package/dist/stage/client/primitives/index.js +6 -0
- package/dist/stage/client/primitives/keyed.js +16 -0
- package/dist/stage/client/primitives/say.js +6 -0
- package/dist/stage/client/primitives/state.js +21 -0
- package/dist/stage/client/primitives/types.js +1 -0
- package/dist/stage/client/primitives/verdicts.js +8 -0
- package/dist/stage/client/stage.css +652 -0
- package/dist/stage/compared.d.ts +20 -0
- package/dist/stage/compared.js +58 -0
- package/dist/stage/files.d.ts +4 -0
- package/dist/stage/files.js +59 -0
- package/dist/stage/guard.d.ts +3 -0
- package/dist/stage/guard.js +20 -0
- package/dist/stage/http.d.ts +12 -0
- package/dist/stage/http.js +34 -0
- package/dist/stage/index.d.ts +1 -0
- package/dist/stage/index.js +1 -0
- package/dist/stage/sending.d.ts +18 -0
- package/dist/stage/sending.js +66 -0
- package/dist/stage/server.d.ts +31 -0
- package/dist/stage/server.js +250 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/worlds/define.d.ts +16 -0
- package/dist/worlds/define.js +45 -0
- package/dist/worlds/index.d.ts +2 -0
- package/dist/worlds/index.js +2 -0
- package/dist/worlds/worlds.d.ts +15 -0
- package/dist/worlds/worlds.js +46 -0
- package/llms.txt +46 -0
- package/package.json +84 -3
- package/schema/v1/announce.schema.json +28 -0
- package/schema/v1/check.schema.json +67 -0
- package/schema/v1/clean.schema.json +19 -0
- package/schema/v1/common.schema.json +210 -0
- package/schema/v1/comparison.schema.json +298 -0
- package/schema/v1/dependents.schema.json +30 -0
- package/schema/v1/drive.schema.json +112 -0
- package/schema/v1/error.schema.json +26 -0
- package/schema/v1/file-scenario.schema.json +175 -0
- package/schema/v1/flow.schema.json +216 -0
- package/schema/v1/init.schema.json +20 -0
- package/schema/v1/list.schema.json +70 -0
- package/schema/v1/manifest.schema.json +430 -0
- package/schema/v1/observation.schema.json +388 -0
- package/schema/v1/open.schema.json +14 -0
- package/schema/v1/people.schema.json +88 -0
- package/schema/v1/samples/announce.yaml +5 -0
- package/schema/v1/samples/check.json +13 -0
- package/schema/v1/samples/clean.json +1 -0
- package/schema/v1/samples/comparison.json +83 -0
- package/schema/v1/samples/dependents.json +7 -0
- package/schema/v1/samples/drive.json +10 -0
- package/schema/v1/samples/error.json +10 -0
- package/schema/v1/samples/file-scenario.yaml +13 -0
- package/schema/v1/samples/flow.yaml +13 -0
- package/schema/v1/samples/init.json +1 -0
- package/schema/v1/samples/list.json +24 -0
- package/schema/v1/samples/manifest.yaml +55 -0
- package/schema/v1/samples/observation.json +49 -0
- package/schema/v1/samples/open.json +6 -0
- package/schema/v1/samples/people.json +11 -0
- package/schema/v1/samples/services.json +27 -0
- package/schema/v1/samples/stage.json +6 -0
- package/schema/v1/samples/try.json +13 -0
- package/schema/v1/samples/up.json +16 -0
- package/schema/v1/samples/validate.json +7 -0
- package/schema/v1/samples/worlds.json +21 -0
- package/schema/v1/services.schema.json +72 -0
- package/schema/v1/stage.schema.json +14 -0
- package/schema/v1/try.schema.json +56 -0
- package/schema/v1/up.schema.json +55 -0
- package/schema/v1/validate.schema.json +40 -0
- package/schema/v1/worlds.schema.json +33 -0
- package/skill/rehearse/SKILL.md +148 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
export const ROLES = [
|
|
2
|
+
'alert',
|
|
3
|
+
'alertdialog',
|
|
4
|
+
'application',
|
|
5
|
+
'article',
|
|
6
|
+
'banner',
|
|
7
|
+
'blockquote',
|
|
8
|
+
'button',
|
|
9
|
+
'caption',
|
|
10
|
+
'cell',
|
|
11
|
+
'checkbox',
|
|
12
|
+
'code',
|
|
13
|
+
'columnheader',
|
|
14
|
+
'combobox',
|
|
15
|
+
'complementary',
|
|
16
|
+
'contentinfo',
|
|
17
|
+
'definition',
|
|
18
|
+
'deletion',
|
|
19
|
+
'dialog',
|
|
20
|
+
'directory',
|
|
21
|
+
'document',
|
|
22
|
+
'emphasis',
|
|
23
|
+
'feed',
|
|
24
|
+
'figure',
|
|
25
|
+
'form',
|
|
26
|
+
'generic',
|
|
27
|
+
'grid',
|
|
28
|
+
'gridcell',
|
|
29
|
+
'group',
|
|
30
|
+
'heading',
|
|
31
|
+
'img',
|
|
32
|
+
'insertion',
|
|
33
|
+
'link',
|
|
34
|
+
'list',
|
|
35
|
+
'listbox',
|
|
36
|
+
'listitem',
|
|
37
|
+
'log',
|
|
38
|
+
'main',
|
|
39
|
+
'marquee',
|
|
40
|
+
'math',
|
|
41
|
+
'meter',
|
|
42
|
+
'menu',
|
|
43
|
+
'menubar',
|
|
44
|
+
'menuitem',
|
|
45
|
+
'menuitemcheckbox',
|
|
46
|
+
'menuitemradio',
|
|
47
|
+
'navigation',
|
|
48
|
+
'none',
|
|
49
|
+
'note',
|
|
50
|
+
'option',
|
|
51
|
+
'paragraph',
|
|
52
|
+
'presentation',
|
|
53
|
+
'progressbar',
|
|
54
|
+
'radio',
|
|
55
|
+
'radiogroup',
|
|
56
|
+
'region',
|
|
57
|
+
'row',
|
|
58
|
+
'rowgroup',
|
|
59
|
+
'rowheader',
|
|
60
|
+
'scrollbar',
|
|
61
|
+
'search',
|
|
62
|
+
'searchbox',
|
|
63
|
+
'separator',
|
|
64
|
+
'slider',
|
|
65
|
+
'spinbutton',
|
|
66
|
+
'status',
|
|
67
|
+
'strong',
|
|
68
|
+
'subscript',
|
|
69
|
+
'superscript',
|
|
70
|
+
'switch',
|
|
71
|
+
'tab',
|
|
72
|
+
'table',
|
|
73
|
+
'tablist',
|
|
74
|
+
'tabpanel',
|
|
75
|
+
'term',
|
|
76
|
+
'textbox',
|
|
77
|
+
'time',
|
|
78
|
+
'timer',
|
|
79
|
+
'toolbar',
|
|
80
|
+
'tooltip',
|
|
81
|
+
'tree',
|
|
82
|
+
'treegrid',
|
|
83
|
+
'treeitem',
|
|
84
|
+
];
|
|
85
|
+
export const isRole = (v) => typeof v === 'string' && ROLES.includes(v);
|
|
86
|
+
const NAMED_KEYS = [
|
|
87
|
+
'Enter',
|
|
88
|
+
'Escape',
|
|
89
|
+
'Tab',
|
|
90
|
+
'Backspace',
|
|
91
|
+
'Delete',
|
|
92
|
+
'Space',
|
|
93
|
+
'ArrowUp',
|
|
94
|
+
'ArrowDown',
|
|
95
|
+
'ArrowLeft',
|
|
96
|
+
'ArrowRight',
|
|
97
|
+
'Home',
|
|
98
|
+
'End',
|
|
99
|
+
'PageUp',
|
|
100
|
+
'PageDown',
|
|
101
|
+
];
|
|
102
|
+
const MODIFIERS = ['ControlOrMeta', 'Meta', 'Control', 'Alt', 'Shift'];
|
|
103
|
+
const KEY = new RegExp(`^(?:(?:${MODIFIERS.join('|')})\\+)*(?:${NAMED_KEYS.join('|')}|F(?:[1-9]|1[0-2])|[a-z0-9]|[,./;'\`\\[\\]\\\\=-])$`);
|
|
104
|
+
export const isKey = (v) => typeof v === 'string' && KEY.test(v);
|
|
105
|
+
export const VERBS = [
|
|
106
|
+
'start',
|
|
107
|
+
'click',
|
|
108
|
+
'type',
|
|
109
|
+
'key',
|
|
110
|
+
'fill',
|
|
111
|
+
'snapshot',
|
|
112
|
+
'screenshot',
|
|
113
|
+
'record',
|
|
114
|
+
'stop',
|
|
115
|
+
];
|
|
116
|
+
export const FAILURE_WORDS = {
|
|
117
|
+
not_found: (name) => `Nothing on screen is named ${name ? `“${name}”` : 'that'}.`,
|
|
118
|
+
ambiguous: (name) => `More than one element is named ${name ? `“${name}”` : 'that'}: give \`--role\` to say which.`,
|
|
119
|
+
not_running: () => 'Nothing is being driven: start with `rehearse drive start`.',
|
|
120
|
+
timed_out: (name) => `${name ? `“${name}”` : 'It'} didn’t answer in time.`,
|
|
121
|
+
crashed: () => 'The app stopped while Rehearse was driving it.',
|
|
122
|
+
};
|
|
123
|
+
export const EXIT = { done: 0, failed: 1, usage: 2 };
|
|
124
|
+
export const exitOf = (r) => r.ok ? EXIT.done : r.failure === 'usage' ? EXIT.usage : EXIT.failed;
|
|
125
|
+
export function stepCommand(step) {
|
|
126
|
+
const role = isRole(step.role) ? step.role : null;
|
|
127
|
+
if (step.click !== undefined)
|
|
128
|
+
return { command: 'click', name: step.click, role };
|
|
129
|
+
if (step.type !== undefined)
|
|
130
|
+
return { command: 'type', text: step.type };
|
|
131
|
+
if (step.key !== undefined)
|
|
132
|
+
return { command: 'key', key: step.key };
|
|
133
|
+
if (step.fill !== undefined)
|
|
134
|
+
return { command: 'fill', name: step.fill, role, text: step.with ?? '' };
|
|
135
|
+
return { command: 'snapshot', name: step.snapshot ?? null, role };
|
|
136
|
+
}
|
|
137
|
+
export function stepWords(step) {
|
|
138
|
+
const role = step.role ? ` (${step.role})` : '';
|
|
139
|
+
if (step.click !== undefined)
|
|
140
|
+
return `click “${step.click}”${role}`;
|
|
141
|
+
if (step.type !== undefined)
|
|
142
|
+
return `type “${step.type}”`;
|
|
143
|
+
if (step.key !== undefined)
|
|
144
|
+
return `press ${step.key}`;
|
|
145
|
+
if (step.fill !== undefined)
|
|
146
|
+
return `fill “${step.fill}”${role} with “${step.with ?? ''}”`;
|
|
147
|
+
return `look at “${step.snapshot}”${role}`;
|
|
148
|
+
}
|
|
149
|
+
export function stepOf(v, n) {
|
|
150
|
+
const s = v && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
151
|
+
const verbs = s ? ['click', 'type', 'key', 'snapshot', 'fill'].filter((k) => k in s) : [];
|
|
152
|
+
if (!s || verbs.length !== 1)
|
|
153
|
+
throw new Error(`Step ${n} isn't a step: one of click, type, key, fill or snapshot.`);
|
|
154
|
+
const verb = verbs[0];
|
|
155
|
+
if (typeof s[verb] !== 'string' || s[verb] === '')
|
|
156
|
+
throw new Error(`Step ${n}'s ${verb} needs words.`);
|
|
157
|
+
if (s.role !== undefined && !isRole(s.role))
|
|
158
|
+
throw new Error(`Step ${n} names a role Rehearse doesn't know: ${String(s.role)}.`);
|
|
159
|
+
if (verb === 'key' && !isKey(s.key))
|
|
160
|
+
throw new Error(`Step ${n} presses a key Rehearse doesn't know: name it as Playwright does, such as Enter or Meta+k.`);
|
|
161
|
+
const extra = Object.keys(s).filter((k) => k !== verb && k !== 'role' && !(verb === 'fill' && k === 'with'));
|
|
162
|
+
if (extra.length)
|
|
163
|
+
throw new Error(`Step ${n} has more than its ${verb}: ${extra.join(', ')}.`);
|
|
164
|
+
return s;
|
|
165
|
+
}
|
|
166
|
+
const FLAGS = {
|
|
167
|
+
start: ['service', 'piece', 'world', 'as', 'on', 'start', 'scheme'],
|
|
168
|
+
click: ['name', 'role'],
|
|
169
|
+
type: [],
|
|
170
|
+
key: [],
|
|
171
|
+
fill: ['name', 'role', 'with'],
|
|
172
|
+
snapshot: ['name', 'role'],
|
|
173
|
+
screenshot: [],
|
|
174
|
+
record: [],
|
|
175
|
+
stop: [],
|
|
176
|
+
};
|
|
177
|
+
export function parseDrive(argv) {
|
|
178
|
+
const [verb, ...rest] = argv;
|
|
179
|
+
if (verb === undefined || verb.startsWith('--'))
|
|
180
|
+
return { ok: false, says: `Name a drive command: ${VERBS.join(', ')}.` };
|
|
181
|
+
if (!VERBS.includes(verb))
|
|
182
|
+
return { ok: false, says: `Drive has no ${verb} command: ${VERBS.join(', ')}.` };
|
|
183
|
+
const v = verb;
|
|
184
|
+
const positional = [];
|
|
185
|
+
const options = {};
|
|
186
|
+
let json = false;
|
|
187
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
188
|
+
const arg = rest[i];
|
|
189
|
+
if (!arg.startsWith('--')) {
|
|
190
|
+
positional.push(arg);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const eq = arg.indexOf('=');
|
|
194
|
+
const flag = arg.slice(2, eq === -1 ? undefined : eq);
|
|
195
|
+
if (flag === 'json' && eq === -1) {
|
|
196
|
+
json = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (flag === 'manifest') {
|
|
200
|
+
i += eq === -1 ? 1 : 0;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (!FLAGS[v].includes(flag))
|
|
204
|
+
return { ok: false, says: `Drive's ${v} takes no --${flag}.` };
|
|
205
|
+
const value = eq === -1 ? rest[++i] : arg.slice(eq + 1);
|
|
206
|
+
if (!value || value.startsWith('--'))
|
|
207
|
+
return { ok: false, says: `Give \`--${flag}\` a value.` };
|
|
208
|
+
options[flag] = value;
|
|
209
|
+
}
|
|
210
|
+
const role = options.role ?? null;
|
|
211
|
+
if (role !== null && !isRole(role))
|
|
212
|
+
return { ok: false, says: `Drive knows no ${role} role.` };
|
|
213
|
+
if (options.scheme !== undefined && options.scheme !== 'light' && options.scheme !== 'dark')
|
|
214
|
+
return { ok: false, says: '`--scheme` is light or dark.' };
|
|
215
|
+
if (role !== null && !options.name)
|
|
216
|
+
return { ok: false, says: '`--role` narrows `--name`: give the name too.' };
|
|
217
|
+
const one = positional.length === 1 ? positional[0] : null;
|
|
218
|
+
if (positional.length > 1 ||
|
|
219
|
+
(positional.length === 1 && ['start', 'click', 'fill', 'snapshot', 'stop'].includes(v)))
|
|
220
|
+
return { ok: false, says: `Drive's ${v} takes nothing more.` };
|
|
221
|
+
const r = role;
|
|
222
|
+
switch (v) {
|
|
223
|
+
case 'start':
|
|
224
|
+
return { ok: true, command: { command: 'start' }, json, options };
|
|
225
|
+
case 'click':
|
|
226
|
+
return options.name
|
|
227
|
+
? { ok: true, command: { command: 'click', name: options.name, role: r }, json, options }
|
|
228
|
+
: { ok: false, says: 'Give `click` the element’s accessible name: `--name "Save"`.' };
|
|
229
|
+
case 'fill':
|
|
230
|
+
return options.name && options.with !== undefined
|
|
231
|
+
? {
|
|
232
|
+
ok: true,
|
|
233
|
+
command: { command: 'fill', name: options.name, role: r, text: options.with },
|
|
234
|
+
json,
|
|
235
|
+
options,
|
|
236
|
+
}
|
|
237
|
+
: {
|
|
238
|
+
ok: false,
|
|
239
|
+
says: 'Give `fill` the field’s accessible name and what to put in it: `--name "Email" --with "a@b.test"`.',
|
|
240
|
+
};
|
|
241
|
+
case 'snapshot':
|
|
242
|
+
return {
|
|
243
|
+
ok: true,
|
|
244
|
+
command: { command: 'snapshot', name: options.name ?? null, role: r },
|
|
245
|
+
json,
|
|
246
|
+
options,
|
|
247
|
+
};
|
|
248
|
+
case 'type':
|
|
249
|
+
return one
|
|
250
|
+
? { ok: true, command: { command: 'type', text: one }, json, options }
|
|
251
|
+
: { ok: false, says: 'Give `type` its text.' };
|
|
252
|
+
case 'key':
|
|
253
|
+
if (!one)
|
|
254
|
+
return { ok: false, says: 'Give `key` the key to press.' };
|
|
255
|
+
return isKey(one)
|
|
256
|
+
? { ok: true, command: { command: 'key', key: one }, json, options }
|
|
257
|
+
: {
|
|
258
|
+
ok: false,
|
|
259
|
+
says: `Drive can't press ${one}: name it as Playwright does, such as Enter or Meta+k.`,
|
|
260
|
+
};
|
|
261
|
+
case 'screenshot':
|
|
262
|
+
case 'record': {
|
|
263
|
+
const ext = v === 'screenshot' ? '.png' : '.webm';
|
|
264
|
+
if (!one)
|
|
265
|
+
return { ok: false, says: `Give \`${v}\` its file.` };
|
|
266
|
+
return one.toLowerCase().endsWith(ext)
|
|
267
|
+
? { ok: true, command: { command: v, file: one }, json, options }
|
|
268
|
+
: { ok: false, says: `\`${v}\` saves a ${ext} file: name it so.` };
|
|
269
|
+
}
|
|
270
|
+
case 'stop':
|
|
271
|
+
return { ok: true, command: { command: 'stop' }, json, options };
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export function driveArgv(c) {
|
|
275
|
+
const role = (r) => (r ? ['--role', r] : []);
|
|
276
|
+
switch (c.command) {
|
|
277
|
+
case 'click':
|
|
278
|
+
return ['click', '--name', c.name, ...role(c.role)];
|
|
279
|
+
case 'snapshot':
|
|
280
|
+
return ['snapshot', ...(c.name ? ['--name', c.name] : []), ...role(c.role)];
|
|
281
|
+
case 'type':
|
|
282
|
+
return ['type', c.text];
|
|
283
|
+
case 'key':
|
|
284
|
+
return ['key', c.key];
|
|
285
|
+
case 'fill':
|
|
286
|
+
return ['fill', '--name', c.name, ...role(c.role), '--with', c.text];
|
|
287
|
+
case 'screenshot':
|
|
288
|
+
case 'record':
|
|
289
|
+
return [c.command, c.file];
|
|
290
|
+
case 'start':
|
|
291
|
+
case 'stop':
|
|
292
|
+
return [c.command];
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export function resultText(r) {
|
|
296
|
+
if (!r.ok)
|
|
297
|
+
return `${r.says}\n`;
|
|
298
|
+
if (r.tree !== null)
|
|
299
|
+
return r.tree.endsWith('\n') ? r.tree : `${r.tree}\n`;
|
|
300
|
+
if (r.file !== null)
|
|
301
|
+
return `Saved ${r.file}.\n`;
|
|
302
|
+
return r.said ? `${r.said}\n` : '';
|
|
303
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { act, calm, contextFor, errorsOf, failed, FIXED_TIME, launch, signInBySteps, signInOf, type SignIn, } from './browser.ts';
|
|
2
|
+
export { driveArgv, exitOf, parseDrive, resultText, stepCommand, stepOf, stepWords, VERBS, type DriveResult, type Step, type Verb, } from './grammar.ts';
|
|
3
|
+
export { findNamed, namedIn } from './names.ts';
|
|
4
|
+
export { forgetDriving, readDriving, writeDriving } from './state.ts';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { act, calm, contextFor, errorsOf, failed, FIXED_TIME, launch, signInBySteps, signInOf, } from './browser.js';
|
|
2
|
+
export { driveArgv, exitOf, parseDrive, resultText, stepCommand, stepOf, stepWords, VERBS, } from './grammar.js';
|
|
3
|
+
export { findNamed, namedIn } from './names.js';
|
|
4
|
+
export { forgetDriving, readDriving, writeDriving } from './state.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface Named {
|
|
2
|
+
readonly role: string;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly raw: string;
|
|
5
|
+
readonly within: string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare const said: (role: string, name: string) => string;
|
|
8
|
+
export declare function namedIn(snapshot: string): Named[];
|
|
9
|
+
export type Found = {
|
|
10
|
+
found: 'one';
|
|
11
|
+
one: Named;
|
|
12
|
+
} | {
|
|
13
|
+
found: 'none';
|
|
14
|
+
near: Named[];
|
|
15
|
+
} | {
|
|
16
|
+
found: 'many';
|
|
17
|
+
many: Named[];
|
|
18
|
+
};
|
|
19
|
+
export declare function findNamed(all: readonly Named[], name: string, role: string | null): Found;
|
|
20
|
+
export declare const placed: (n: Named) => string;
|
|
21
|
+
export declare const listed: (all: readonly Named[]) => string;
|
|
22
|
+
export declare function notFoundWords(name: string, role: string | null, near: readonly Named[]): string;
|
|
23
|
+
export declare function ambiguousWords(name: string, many: readonly Named[]): string;
|
|
24
|
+
export declare function sameWords(one: Named, lines: readonly string[]): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ariaLine, tidyName } from './aria.js';
|
|
2
|
+
import { FAILURE_WORDS } from './grammar.js';
|
|
3
|
+
export const said = (role, name) => `${role} “${name}”`;
|
|
4
|
+
const comparable = tidyName;
|
|
5
|
+
function lineOf(raw) {
|
|
6
|
+
if (!raw.trimStart().startsWith('- '))
|
|
7
|
+
return null;
|
|
8
|
+
const line = ariaLine(raw);
|
|
9
|
+
return line && line.role !== 'text' ? line : null;
|
|
10
|
+
}
|
|
11
|
+
export function namedIn(snapshot) {
|
|
12
|
+
const named = [];
|
|
13
|
+
const open = [];
|
|
14
|
+
for (const raw of snapshot.split('\n')) {
|
|
15
|
+
const line = lineOf(raw);
|
|
16
|
+
if (!line)
|
|
17
|
+
continue;
|
|
18
|
+
while (open.length > 0 && open.at(-1).depth >= line.depth)
|
|
19
|
+
open.pop();
|
|
20
|
+
const within = open.toReversed().find((o) => o.says !== null)?.says ?? null;
|
|
21
|
+
const name = line.name ? comparable(line.name) : null;
|
|
22
|
+
if (line.name && name)
|
|
23
|
+
named.push({ role: line.role, name, raw: line.name, within });
|
|
24
|
+
open.push({ depth: line.depth, says: name ? said(line.role, name) : null });
|
|
25
|
+
}
|
|
26
|
+
return named;
|
|
27
|
+
}
|
|
28
|
+
const NEAR = 5;
|
|
29
|
+
function distance(a, b) {
|
|
30
|
+
const row = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
31
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
32
|
+
let diagonal = row[0];
|
|
33
|
+
row[0] = i;
|
|
34
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
35
|
+
const above = row[j];
|
|
36
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, diagonal + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
37
|
+
diagonal = above;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return row[b.length];
|
|
41
|
+
}
|
|
42
|
+
function closeness(wanted, name) {
|
|
43
|
+
const w = comparable(wanted).toLowerCase();
|
|
44
|
+
const n = comparable(name).toLowerCase();
|
|
45
|
+
if (w === n)
|
|
46
|
+
return 0;
|
|
47
|
+
if (n.startsWith(w) || w.startsWith(n))
|
|
48
|
+
return 1;
|
|
49
|
+
if (n.includes(w) || w.includes(n))
|
|
50
|
+
return 2;
|
|
51
|
+
const d = distance(w, n);
|
|
52
|
+
return d <= Math.max(2, Math.floor(w.length / 4)) ? 2 + d : null;
|
|
53
|
+
}
|
|
54
|
+
const unique = (all) => {
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
return all.filter((n) => {
|
|
57
|
+
const key = `${n.role}\0${n.name}\0${n.within}`;
|
|
58
|
+
if (seen.has(key))
|
|
59
|
+
return false;
|
|
60
|
+
seen.add(key);
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export function findNamed(all, name, role) {
|
|
65
|
+
const wanted = comparable(name);
|
|
66
|
+
const same = all.filter((n) => comparable(n.name) === wanted);
|
|
67
|
+
const matches = role ? same.filter((n) => n.role === role) : same;
|
|
68
|
+
if (matches.length === 1)
|
|
69
|
+
return { found: 'one', one: matches[0] };
|
|
70
|
+
if (matches.length > 1)
|
|
71
|
+
return { found: 'many', many: matches };
|
|
72
|
+
const near = unique(all
|
|
73
|
+
.map((n) => ({ n, close: closeness(name, n.name), apart: Math.abs(n.name.length - wanted.length) }))
|
|
74
|
+
.filter((c) => c.close !== null)
|
|
75
|
+
.sort((a, b) => a.close - b.close || a.apart - b.apart)
|
|
76
|
+
.map((c) => c.n));
|
|
77
|
+
return { found: 'none', near: near.slice(0, NEAR) };
|
|
78
|
+
}
|
|
79
|
+
export const placed = (n) => n.within ? `${said(n.role, n.name)} in ${n.within}` : said(n.role, n.name);
|
|
80
|
+
export const listed = (all) => all.map((n) => ` ${placed(n)}`).join('\n');
|
|
81
|
+
export function notFoundWords(name, role, near) {
|
|
82
|
+
const asked = role ? `Nothing on screen is a ${role} named “${name}”.` : FAILURE_WORDS.not_found(name);
|
|
83
|
+
return near.length > 0 ? `${asked} Close to it on screen:\n${listed(near)}` : asked;
|
|
84
|
+
}
|
|
85
|
+
export function ambiguousWords(name, many) {
|
|
86
|
+
const roles = new Set(many.map((n) => n.role));
|
|
87
|
+
const asked = roles.size === 1
|
|
88
|
+
? `More than one ${many[0].role} is named “${name}”, so drive can’t tell them apart:`
|
|
89
|
+
: FAILURE_WORDS.ambiguous(name);
|
|
90
|
+
return `${asked}\n${listed(many)}`;
|
|
91
|
+
}
|
|
92
|
+
export function sameWords(one, lines) {
|
|
93
|
+
const distinct = [...new Set(lines)];
|
|
94
|
+
if (distinct.length <= 1)
|
|
95
|
+
return `The page holds ${lines.length} elements that are each ${placed(one)}, alike in all the snapshot shows, so drive can’t tell them apart.`;
|
|
96
|
+
return `${lines.length} elements are ${said(one.role, one.name)}, so drive can’t tell them apart:\n${distinct.map((l) => ` ${l}`).join('\n')}`;
|
|
97
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface Driving {
|
|
2
|
+
driver: 'service' | 'browser';
|
|
3
|
+
service: string | null;
|
|
4
|
+
checkout: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
pid?: number;
|
|
7
|
+
secret?: string;
|
|
8
|
+
started?: boolean;
|
|
9
|
+
since: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function readDriving(manifestDir: string): Driving | null;
|
|
12
|
+
export declare function writeDriving(manifestDir: string, d: Driving): void;
|
|
13
|
+
export declare const forgetDriving: (manifestDir: string) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { alive, stateDir } from '../services/index.js';
|
|
4
|
+
const ONLY_THIS_USER_READS_ITS_SECRET = 0o600;
|
|
5
|
+
const fileOf = (manifestDir) => path.join(stateDir(manifestDir), 'drive.json');
|
|
6
|
+
export function readDriving(manifestDir) {
|
|
7
|
+
const file = fileOf(manifestDir);
|
|
8
|
+
if (!existsSync(file))
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
const d = JSON.parse(readFileSync(file, 'utf8'));
|
|
12
|
+
if (d.driver === 'browser' && (!d.pid || !alive(d.pid))) {
|
|
13
|
+
rmSync(file, { force: true });
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return d;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function writeDriving(manifestDir, d) {
|
|
23
|
+
mkdirSync(stateDir(manifestDir), { recursive: true });
|
|
24
|
+
writeFileSync(fileOf(manifestDir), `${JSON.stringify(d, null, 2)}\n`, {
|
|
25
|
+
mode: ONLY_THIS_USER_READS_ITS_SECRET,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export const forgetDriving = (manifestDir) => rmSync(fileOf(manifestDir), { force: true });
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class RehearseError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly says: string;
|
|
5
|
+
readonly file: string | undefined;
|
|
6
|
+
readonly line: number | undefined;
|
|
7
|
+
readonly exit: 1 | 2;
|
|
8
|
+
constructor(code: string, says: string, at?: {
|
|
9
|
+
file?: string;
|
|
10
|
+
line?: number;
|
|
11
|
+
exit?: 1 | 2;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export declare const usage: (says: string) => RehearseError;
|
|
15
|
+
export declare const errorText: (error: unknown) => string;
|
|
16
|
+
export interface ErrorJson {
|
|
17
|
+
v: 1;
|
|
18
|
+
ok: false;
|
|
19
|
+
error: {
|
|
20
|
+
code: string;
|
|
21
|
+
says: string;
|
|
22
|
+
file?: string;
|
|
23
|
+
line?: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare function errorJson(error: unknown): ErrorJson;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class RehearseError extends Error {
|
|
2
|
+
name = 'RehearseError';
|
|
3
|
+
code;
|
|
4
|
+
says;
|
|
5
|
+
file;
|
|
6
|
+
line;
|
|
7
|
+
exit;
|
|
8
|
+
constructor(code, says, at = {}) {
|
|
9
|
+
super(says);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.says = says;
|
|
12
|
+
this.file = at.file;
|
|
13
|
+
this.line = at.line;
|
|
14
|
+
this.exit = at.exit ?? (code === 'usage' ? 2 : 1);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const usage = (says) => new RehearseError('usage', says, { exit: 2 });
|
|
18
|
+
export const errorText = (error) => error instanceof Error ? error.message.split('\n')[0] || error.name : String(error);
|
|
19
|
+
export function errorJson(error) {
|
|
20
|
+
if (error instanceof RehearseError)
|
|
21
|
+
return {
|
|
22
|
+
v: 1,
|
|
23
|
+
ok: false,
|
|
24
|
+
error: {
|
|
25
|
+
code: error.code,
|
|
26
|
+
says: error.says,
|
|
27
|
+
...(error.file !== undefined && { file: error.file }),
|
|
28
|
+
...(error.line !== undefined && { line: error.line }),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
return { v: 1, ok: false, error: { code: 'crashed', says: `Rehearse stopped: ${errorText(error)}` } };
|
|
32
|
+
}
|
package/dist/exec.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Ran {
|
|
2
|
+
code: number | null;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
ms: number;
|
|
6
|
+
timedOut: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ExecOptions {
|
|
9
|
+
cwd: string;
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
keep?: number;
|
|
13
|
+
input?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function sh(command: string, options: ExecOptions): Promise<Ran>;
|
|
16
|
+
export declare const tail: (text: string, lines?: number, chars?: number) => string;
|
package/dist/exec.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export function sh(command, options) {
|
|
3
|
+
const begun = performance.now();
|
|
4
|
+
const keep = options.keep ?? 2_000_000;
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const child = spawn(process.env.SHELL && !process.env.SHELL.endsWith('fish') ? process.env.SHELL : '/bin/sh', ['-c', command], {
|
|
7
|
+
cwd: options.cwd,
|
|
8
|
+
env: { ...process.env, ...options.env },
|
|
9
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
10
|
+
detached: true,
|
|
11
|
+
});
|
|
12
|
+
let stdout = '';
|
|
13
|
+
let stderr = '';
|
|
14
|
+
let timedOut = false;
|
|
15
|
+
const clip = (s) => (s.length > keep ? s.slice(-keep) : s);
|
|
16
|
+
child.stdout.setEncoding('utf8').on('data', (d) => (stdout = clip(stdout + d)));
|
|
17
|
+
child.stderr.setEncoding('utf8').on('data', (d) => (stderr = clip(stderr + d)));
|
|
18
|
+
const timer = options.timeoutMs
|
|
19
|
+
? setTimeout(() => {
|
|
20
|
+
timedOut = true;
|
|
21
|
+
try {
|
|
22
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
child.kill('SIGKILL');
|
|
26
|
+
}
|
|
27
|
+
}, options.timeoutMs)
|
|
28
|
+
: null;
|
|
29
|
+
const done = (code) => {
|
|
30
|
+
if (timer)
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
resolve({ code, stdout, stderr, ms: Math.round(performance.now() - begun), timedOut });
|
|
33
|
+
};
|
|
34
|
+
child.on('error', (error) => {
|
|
35
|
+
stderr += String(error.message);
|
|
36
|
+
done(127);
|
|
37
|
+
});
|
|
38
|
+
child.on('close', (code) => done(code));
|
|
39
|
+
child.stdin.on('error', () => undefined);
|
|
40
|
+
child.stdin.end(options.input ?? '');
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export const tail = (text, lines = 3, chars = 400) => text.trim().split('\n').slice(-lines).join(' ').slice(-chars);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Manifest } from '../manifest/index.ts';
|
|
2
|
+
import type { CheckoutInfo } from '../run/index.ts';
|
|
3
|
+
export declare const checkoutsDir: (m: Manifest) => string;
|
|
4
|
+
export declare function dirtyOf(m: Manifest, checkout: string): boolean;
|
|
5
|
+
export declare function infoOf(m: Manifest, checkout: string, ref: string | null): CheckoutInfo;
|
|
6
|
+
export declare function overlay(m: Manifest, checkout: string): void;
|
|
7
|
+
export declare function checkoutFor(m: Manifest, repo: string, given: string, progress: (line: string) => void, keep?: readonly string[], cwd?: string): Promise<{
|
|
8
|
+
path: string;
|
|
9
|
+
ref: string | null;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function evict(m: Manifest, repo: string, keep?: readonly string[]): string[];
|