screw-bugs 0.1.9 → 0.1.11

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 (102) hide show
  1. package/README.md +100 -54
  2. package/dist/browser-playwright/capture.js +1 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli/app.js +6 -2
  5. package/dist/cli/commands.js +4 -3
  6. package/dist/cli/doctor.d.ts +17 -2
  7. package/dist/cli/doctor.js +62 -4
  8. package/dist/cli/mcp.js +7 -4
  9. package/dist/cli/report-server.d.ts +19 -10
  10. package/dist/cli/report-server.js +43 -18
  11. package/dist/cli/share.js +2 -2
  12. package/dist/cli/sign-in.d.ts +9 -3
  13. package/dist/cli/sign-in.js +12 -9
  14. package/dist/cli/tailnet.d.ts +57 -0
  15. package/dist/cli/tailnet.js +82 -0
  16. package/dist/core/index.d.ts +1 -14
  17. package/dist/core/index.js +3 -14
  18. package/dist/report/index.d.ts +1 -10
  19. package/dist/report/index.js +3 -10
  20. package/dist/schema/index.d.ts +1 -9
  21. package/dist/schema/index.js +3 -9
  22. package/package.json +14 -14
  23. package/dist/core/accounts.d.ts +0 -40
  24. package/dist/core/accounts.js +0 -95
  25. package/dist/core/css.d.ts +0 -95
  26. package/dist/core/css.js +0 -436
  27. package/dist/core/engine.d.ts +0 -75
  28. package/dist/core/engine.js +0 -560
  29. package/dist/core/errors.d.ts +0 -85
  30. package/dist/core/errors.js +0 -36
  31. package/dist/core/evidence.d.ts +0 -14
  32. package/dist/core/evidence.js +0 -131
  33. package/dist/core/labels.d.ts +0 -47
  34. package/dist/core/labels.js +0 -199
  35. package/dist/core/liveness.d.ts +0 -45
  36. package/dist/core/liveness.js +0 -66
  37. package/dist/core/marks.d.ts +0 -63
  38. package/dist/core/marks.js +0 -410
  39. package/dist/core/services.d.ts +0 -579
  40. package/dist/core/services.js +0 -25
  41. package/dist/core/share.d.ts +0 -68
  42. package/dist/core/share.js +0 -318
  43. package/dist/core/steps.d.ts +0 -106
  44. package/dist/core/steps.js +0 -722
  45. package/dist/core/uploads.d.ts +0 -49
  46. package/dist/core/uploads.js +0 -133
  47. package/dist/core/video.d.ts +0 -53
  48. package/dist/core/video.js +0 -241
  49. package/dist/core/viewport.d.ts +0 -28
  50. package/dist/core/viewport.js +0 -50
  51. package/dist/report/assets.d.ts +0 -34
  52. package/dist/report/assets.js +0 -105
  53. package/dist/report/bug.d.ts +0 -11
  54. package/dist/report/bug.js +0 -20
  55. package/dist/report/html.d.ts +0 -47
  56. package/dist/report/html.js +0 -923
  57. package/dist/report/icons.d.ts +0 -51
  58. package/dist/report/icons.js +0 -93
  59. package/dist/report/live.d.ts +0 -7
  60. package/dist/report/live.js +0 -135
  61. package/dist/report/logos.d.ts +0 -4
  62. package/dist/report/logos.js +0 -19
  63. package/dist/report/markup.d.ts +0 -50
  64. package/dist/report/markup.js +0 -156
  65. package/dist/report/menu-bar.d.ts +0 -60
  66. package/dist/report/menu-bar.js +0 -157
  67. package/dist/report/player.d.ts +0 -102
  68. package/dist/report/player.js +0 -315
  69. package/dist/report/pr-summary.d.ts +0 -11
  70. package/dist/report/pr-summary.js +0 -119
  71. package/dist/report/sha256.d.ts +0 -9
  72. package/dist/report/sha256.js +0 -97
  73. package/dist/report/share-page.d.ts +0 -48
  74. package/dist/report/share-page.js +0 -291
  75. package/dist/report/shots.d.ts +0 -59
  76. package/dist/report/shots.js +0 -280
  77. package/dist/report/sign-in.d.ts +0 -41
  78. package/dist/report/sign-in.js +0 -568
  79. package/dist/report/styles.d.ts +0 -3
  80. package/dist/report/styles.js +0 -274
  81. package/dist/report/view.d.ts +0 -296
  82. package/dist/report/view.js +0 -702
  83. package/dist/report/walkthrough.d.ts +0 -93
  84. package/dist/report/walkthrough.js +0 -716
  85. package/dist/schema/accounts.d.ts +0 -137
  86. package/dist/schema/accounts.js +0 -121
  87. package/dist/schema/config.d.ts +0 -7
  88. package/dist/schema/config.js +0 -6
  89. package/dist/schema/doctor.d.ts +0 -46
  90. package/dist/schema/doctor.js +0 -30
  91. package/dist/schema/evidence.d.ts +0 -1115
  92. package/dist/schema/evidence.js +0 -565
  93. package/dist/schema/findings.d.ts +0 -161
  94. package/dist/schema/findings.js +0 -82
  95. package/dist/schema/job.d.ts +0 -1905
  96. package/dist/schema/job.js +0 -577
  97. package/dist/schema/ledger.d.ts +0 -1124
  98. package/dist/schema/ledger.js +0 -285
  99. package/dist/schema/share.d.ts +0 -55
  100. package/dist/schema/share.js +0 -64
  101. package/dist/schema/status.d.ts +0 -7
  102. package/dist/schema/status.js +0 -11
@@ -1,577 +0,0 @@
1
- import { Schema } from 'effect';
2
- import { JobAccount } from './accounts.js';
3
- /** Sortable by creation time and safe as a folder name, for example `20261029-104857-3f9a01c2`. */
4
- export const JobId = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9][A-Za-z0-9-]*$/, {
5
- message: 'A job ID has only letters, digits and dashes',
6
- })).pipe(Schema.brand('JobId'));
7
- /** One short line of plain text: not blank, at most `max` characters. */
8
- export const ShortLine = (max, description) => Schema.String.check(Schema.makeFilter((text) => (text.trim() ? undefined : 'Must not be blank'), {
9
- toJsonSchema: () => ({ pattern: '\\S' }),
10
- }), Schema.isMaxLength(max, { message: `Use at most ${max} characters` })).annotate({
11
- description: `${description ? `${description} ` : ''}One line, at most ${max} characters.`,
12
- });
13
- /**
14
- * The only schemes screw-bugs opens: web pages, including local dev servers. Never local files,
15
- * `data:`, `blob:` or `javascript:` URLs, or the browser's own pages (`chrome:`, `view-source:`),
16
- * so a job cannot read anything off the machine into its evidence.
17
- */
18
- export const WEB_SCHEMES = ['http:', 'https:'];
19
- /** The scheme of an absolute URL, such as `file:`; undefined when it is not one. */
20
- export const schemeOf = (url) => URL.canParse(url) ? new URL(url).protocol : undefined;
21
- export const isWebUrl = (url) => WEB_SCHEMES.includes(schemeOf(url) ?? '');
22
- export const Device = Schema.Literals(['desktop', 'mobile']);
23
- /**
24
- * Case IDs and screenshot names: letters, digits, dots, dashes and underscores. They show up in
25
- * replies and reports but never become file names as they are; evidence files are numbered (see
26
- * `evidenceFileName` in core), so names such as `CON` or `a.` are harmless.
27
- */
28
- const Slug = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/, {
29
- message: 'Use 1-64 letters, digits, dots, dashes or underscores, starting with a letter or digit',
30
- // Effect leaves isPattern out of JSON Schema; this puts it in.
31
- toJsonSchema: () => ({ pattern: '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$' }),
32
- }));
33
- const targetKeys = ['role', 'text', 'label', 'alt', 'css'];
34
- /** Ways of finding an element, shared by a step's target and the frames it is in. */
35
- const targetFields = {
36
- role: Schema.optionalKey(Schema.NonEmptyString.annotate({
37
- description: 'ARIA role, such as button, link, textbox, checkbox or heading.',
38
- })),
39
- name: Schema.optionalKey(Schema.NonEmptyString.annotate({
40
- description: 'With role: the accessible name to match (case-insensitive substring).',
41
- })),
42
- text: Schema.optionalKey(Schema.NonEmptyString.annotate({ description: 'Visible text (case-insensitive substring).' })),
43
- label: Schema.optionalKey(Schema.NonEmptyString.annotate({ description: 'Text of the form label for an input.' })),
44
- alt: Schema.optionalKey(Schema.NonEmptyString.annotate({
45
- description: 'Alternative text of an image: the alt of an <img>, or the ARIA label of an element with ' +
46
- 'role img, such as an <svg> logo (case-insensitive substring).',
47
- })),
48
- css: Schema.optionalKey(Schema.NonEmptyString.annotate({ description: 'A CSS selector.' })),
49
- };
50
- /** {@link oneWay} in JSON Schema: exactly one way of finding the element, and name only with role. */
51
- const oneWayJson = {
52
- oneOf: targetKeys.map((key) => ({ required: [key] })),
53
- dependentRequired: { name: ['role'] },
54
- };
55
- const oneWay = (target) => {
56
- const set = targetKeys.filter((key) => target[key] !== undefined);
57
- if (set.length !== 1)
58
- return 'Set exactly one of role, text, label, alt or css';
59
- if (target.name !== undefined && target.role === undefined)
60
- return 'name needs role';
61
- return undefined;
62
- };
63
- /** The most frames a target may be nested in. */
64
- export const FRAME_DEPTH_MAX = 4;
65
- /**
66
- * An `<iframe>` element, found like a target. It has no `frame` of its own: frames inside frames
67
- * are given as a list, outermost first.
68
- */
69
- export const FrameTarget = Schema.Struct({
70
- ...targetFields,
71
- frame: Schema.optionalKey(Schema.Unknown.annotate({
72
- description: 'Not allowed here: give frames inside frames as a list, outermost first.',
73
- })),
74
- })
75
- .check(Schema.makeFilter((target) => target.frame !== undefined
76
- ? 'A frame cannot have its own frame; give frames inside frames as a list, outermost first'
77
- : oneWay(target), { toJsonSchema: () => ({ ...oneWayJson, not: { required: ['frame'] } }) }))
78
- .annotate({
79
- description: 'The <iframe> element: exactly one of role (optionally with name), text, label, alt or css, such as {"css":"iframe.preview"}.',
80
- });
81
- /** The frame a target or text is in: one `<iframe>`, or a list for frames inside frames. */
82
- export const FramePath = Schema.Union([
83
- FrameTarget,
84
- Schema.Array(FrameTarget).check(Schema.makeFilter((frames) => frames.length >= 1 && frames.length <= FRAME_DEPTH_MAX
85
- ? undefined
86
- : `Give 1-${FRAME_DEPTH_MAX} frames, outermost first`, { toJsonSchema: () => ({ minItems: 1, maxItems: FRAME_DEPTH_MAX }) })),
87
- ]).annotate({
88
- description: 'Optional: the <iframe> it is in, found like a target, such as {"css":"iframe.preview"}; for ' +
89
- 'frames inside frames, a list, outermost first. Same- and cross-origin frames both work.',
90
- });
91
- /**
92
- * The element a step acts on. Exactly one way of finding it; when several elements match, the
93
- * first visible one in page order is used. With `frame`, it is looked for inside that `<iframe>`.
94
- */
95
- export const Target = Schema.Struct({ ...targetFields, frame: Schema.optionalKey(FramePath) })
96
- .check(Schema.makeFilter(oneWay, { toJsonSchema: () => oneWayJson }))
97
- .annotate({
98
- description: 'Exactly one of role (optionally with name), text, label, alt or css. The first visible match ' +
99
- 'is used. Add frame to look inside an <iframe>: {"frame":{"css":"iframe.preview"},"text":"Hi"}.',
100
- });
101
- /** The frames of a `frame` field, outermost first; empty without one. */
102
- export const framesOf = (frame) => frame === undefined ? [] : Array.isArray(frame) ? frame : [frame];
103
- /** A target without its `frame`. */
104
- export const elementOf = (target) => {
105
- const { frame: _, ...element } = target;
106
- return element;
107
- };
108
- /** How long an element or expectation step waits by default (see `timeoutMs`). */
109
- export const DEFAULT_WAIT_MS = 5_000;
110
- /** How long a page load may take by default, from its start (see `timeoutMs`). */
111
- export const DEFAULT_LOAD_MS = 15_000;
112
- /** The bounds of `timeoutMs`. */
113
- export const TIMEOUT_MIN_MS = 100;
114
- export const TIMEOUT_MAX_MS = 180_000;
115
- const timeoutMs = (what) => Schema.optionalKey(
116
- // A plain number checked here, so a fraction gets the same plain error as one out of range.
117
- // Finite, not Number: JSON has no NaN or Infinity, and Number's JSON Schema allows them as
118
- // strings.
119
- Schema.Finite.check(Schema.makeFilter((ms) => Number.isInteger(ms) && ms >= TIMEOUT_MIN_MS && ms <= TIMEOUT_MAX_MS
120
- ? undefined
121
- : `timeoutMs must be a whole number of milliseconds from ${TIMEOUT_MIN_MS} to ${TIMEOUT_MAX_MS} (180 s)`, {
122
- toJsonSchema: () => ({
123
- type: 'integer',
124
- minimum: TIMEOUT_MIN_MS,
125
- maximum: TIMEOUT_MAX_MS,
126
- }),
127
- })).annotate({
128
- description: `Optional, ${TIMEOUT_MIN_MS}-${TIMEOUT_MAX_MS} ms: how long to wait ${what}.`,
129
- }));
130
- /** The most files one upload step may give, and the largest a file may be. */
131
- export const UPLOAD_FILES_MAX = 10;
132
- export const UPLOAD_MAX_BYTES = 50 * 1024 * 1024;
133
- /** The longest `about` an upload file may have. */
134
- export const ABOUT_MAX = 200;
135
- /**
136
- * Why an upload path is not one screw-bugs takes, judged from its text alone: it must be relative
137
- * to the project and stay inside it. Whether the file is there, and what it holds, is checked
138
- * against the disk before a run starts (see `FileNeeded`).
139
- */
140
- export const uploadPathProblem = (path) => {
141
- if (path.includes('\0'))
142
- return 'A file path must not contain a NUL character';
143
- if (/^([\\/]|[A-Za-z]:)/.test(path))
144
- return `"${path}" is absolute; give a path relative to the project, such as fixtures/resume.pdf`;
145
- if (path.split(/[\\/]/).includes('..'))
146
- return `"${path}" leaves the project; ".." is not allowed in a file path`;
147
- if (/[\\/]$/.test(path))
148
- return `"${path}" is a folder; give the path of a file`;
149
- return undefined;
150
- };
151
- const UploadPath = Schema.NonEmptyString.check(Schema.makeFilter(uploadPathProblem)).annotate({
152
- description: 'Path of a file in the project, relative to it, such as fixtures/resume.pdf.',
153
- });
154
- /**
155
- * One file an upload step sends: its path, or its path and what it is. `about` is the caller's
156
- * plain sentence of what the file holds, shown next to the step in the report and in the reply
157
- * that asks for a missing file; never interpreted.
158
- */
159
- export const UploadFile = Schema.Union([
160
- UploadPath,
161
- Schema.Struct({
162
- path: UploadPath,
163
- about: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(ABOUT_MAX, { message: `Use at most ${ABOUT_MAX} characters` })).annotate({
164
- description: 'One plain sentence of what the file holds, such as "A 2-page PDF résumé of a fictional designer". Shown in the report; never interpreted.',
165
- })),
166
- allowMismatch: Schema.optionalKey(Schema.Boolean.annotate({
167
- description: 'Optional: true to skip the check that its content matches its extension, to test how ' +
168
- 'the site handles an invalid file on purpose (such as a text file named .pdf). It must ' +
169
- 'still exist in the project, not be empty, and be at most 50 MB.',
170
- })),
171
- }),
172
- ]);
173
- /** An upload file as path, `about` and `allowMismatch`, whichever form it was given in. */
174
- export const uploadFileOf = (file) => typeof file === 'string' ? { path: file } : file;
175
- /** The last part of a path, such as `resume.pdf` for `fixtures/resume.pdf`. */
176
- export const baseName = (path) => path.split(/[\\/]/).at(-1) ?? path;
177
- /** The states `waitFor` waits for; see the step. */
178
- export const WaitState = Schema.Literals(['visible', 'hidden', 'attached', 'detached']);
179
- /** How `expectLink` compares a link's address with its `href`. */
180
- export const LinkMatch = Schema.Literals(['contains', 'exact']);
181
- /**
182
- * How long `expectNoText` watches for its text once there is something to look at: long enough
183
- * for what a page renders a moment after it loads to show up.
184
- */
185
- export const ABSENCE_WATCH_MS = 1_000;
186
- /** The most pixels one `scroll` step may scroll by. */
187
- export const SCROLL_BY_MAX = 20_000;
188
- /**
189
- * One deterministic browser action or check. The vocabulary is deliberately small: the caller
190
- * (usually a coding agent) decides what to test and writes these; screw-bugs only executes them.
191
- */
192
- export const Step = Schema.Union([
193
- Schema.Struct({
194
- action: Schema.Literal('goto'),
195
- url: Schema.NonEmptyString.annotate({
196
- description: 'Absolute URL, or a path resolved against the job URL (such as /login).',
197
- }),
198
- timeoutMs: timeoutMs('for the page to load (default 15000)'),
199
- }).annotate({ description: 'Open a URL. An HTTP error status (400 or above) fails the case.' }),
200
- Schema.Struct({
201
- action: Schema.Literal('reload'),
202
- timeoutMs: timeoutMs('for the page to load (default 15000)'),
203
- }).annotate({
204
- description: 'Reload the page. Judged like goto: an HTTP error status fails the case, a page that ' +
205
- 'cannot load blocks it.',
206
- }),
207
- Schema.Struct({
208
- action: Schema.Literal('click'),
209
- target: Target,
210
- timeoutMs: timeoutMs('for the element (default 5000); a page it opens gets at least 15000'),
211
- }).annotate({
212
- description: 'Click an element. If it opens a page with an HTTP error status, here or in a new tab or ' +
213
- 'window, the case fails. Later steps act on this page, not a new tab.',
214
- }),
215
- Schema.Struct({
216
- action: Schema.Literal('hover'),
217
- target: Target,
218
- timeoutMs: timeoutMs('for the element (default 5000)'),
219
- }).annotate({
220
- description: 'Move the pointer over an element, for controls that only show on hover, such as a ' +
221
- "message's Reply button. The pointer stays there until the next action moves it.",
222
- }),
223
- Schema.Struct({
224
- action: Schema.Literal('fill'),
225
- target: Target,
226
- value: Schema.String,
227
- timeoutMs: timeoutMs('for the element (default 5000)'),
228
- }).annotate({
229
- description: 'Replace the value of an input or textarea.',
230
- }),
231
- Schema.Struct({
232
- action: Schema.Literal('upload'),
233
- target: Target,
234
- files: Schema.Array(UploadFile)
235
- .check(Schema.makeFilter((files) => files.length >= 1 && files.length <= UPLOAD_FILES_MAX
236
- ? undefined
237
- : `Give 1-${UPLOAD_FILES_MAX} files`, { toJsonSchema: () => ({ minItems: 1, maxItems: UPLOAD_FILES_MAX }) }))
238
- .annotate({
239
- description: `1-${UPLOAD_FILES_MAX} files, each a path relative to the project (such as ` +
240
- 'fixtures/resume.pdf) or {"path","about"}. You create them, with synthetic content; ' +
241
- 'they are sent to the site under test.',
242
- }),
243
- timeoutMs: timeoutMs('for the file input or file chooser (default 5000)'),
244
- }).annotate({
245
- description: 'Choose files for a file input: the target is the input itself (hidden ones too) or the ' +
246
- 'control that opens the file chooser, such as an "Upload" button.',
247
- }),
248
- Schema.Struct({
249
- action: Schema.Literal('press'),
250
- key: Schema.NonEmptyString.annotate({
251
- description: 'A key or chord for the focused element, such as Enter, Tab or Control+A.',
252
- }),
253
- timeoutMs: timeoutMs('for a page it opens to load (default 15000)'),
254
- }).annotate({
255
- description: 'Press a key. If it opens a page with an HTTP error status, here or in a new tab or window, ' +
256
- 'the case fails. Later steps act on this page, not a new tab.',
257
- }),
258
- Schema.Struct({
259
- action: Schema.Literal('expectText'),
260
- text: Schema.NonEmptyString.annotate({ description: 'Case-insensitive substring.' }),
261
- frame: Schema.optionalKey(FramePath),
262
- timeoutMs: timeoutMs('for the text (default 5000)'),
263
- }).annotate({
264
- description: 'Expect this text to become visible on the page, or with frame inside that <iframe>. Use ' +
265
- 'text that proves the behavior, such as the exact success or error message, not a label ' +
266
- 'that is always there.',
267
- }),
268
- Schema.Struct({
269
- action: Schema.Literal('expectNoText'),
270
- text: Schema.NonEmptyString.annotate({ description: 'Case-insensitive substring.' }),
271
- target: Schema.optionalKey(Target.annotate({ description: 'Look only inside this element (in its frame, too).' })),
272
- frame: Schema.optionalKey(FramePath),
273
- timeoutMs: timeoutMs('for the page, frame or target to show something (default 5000)'),
274
- })
275
- .check(Schema.makeFilter((step) => step.target !== undefined && step.frame !== undefined
276
- ? 'With target, give the frame in the target itself'
277
- : undefined, { toJsonSchema: () => ({ not: { required: ['target', 'frame'] } }) }))
278
- .annotate({
279
- description: 'Expect this text not to show: not as visible text, not as the alt text of an image and ' +
280
- 'not as an ARIA label. Without frame or target, the page and the frames visible in it ' +
281
- 'are looked at. It waits until there is something to look at, then watches for ' +
282
- `${ABSENCE_WATCH_MS / 1000} s; the text showing at any point fails the case.`,
283
- }),
284
- Schema.Struct({
285
- action: Schema.Literal('waitFor'),
286
- target: Target,
287
- state: Schema.optionalKey(WaitState.annotate({
288
- description: 'Default visible. visible: a match is visible; hidden: none is; attached: a match is ' +
289
- 'in the page, seen or not; detached: none is.',
290
- })),
291
- timeoutMs: timeoutMs('for the state (default 5000)'),
292
- }).annotate({
293
- description: 'Wait until the target reaches a state, such as a "restyling" class going away: ' +
294
- '{"action":"waitFor","target":{"css":".restyling"},"state":"detached"}. Not reaching it ' +
295
- 'in time fails the case.',
296
- }),
297
- Schema.Struct({
298
- action: Schema.Literal('scroll'),
299
- target: Schema.optionalKey(Target.annotate({ description: 'Scroll this element into view (in its frame, too).' })),
300
- to: Schema.optionalKey(Schema.Literals(['top', 'bottom']).annotate({
301
- description: 'Scroll the page, or with frame that frame, to its top or bottom.',
302
- })),
303
- by: Schema.optionalKey(
304
- // A plain number checked here, so a fraction gets the same plain error as one out of range.
305
- Schema.Finite.check(Schema.makeFilter((px) => Number.isInteger(px) && px !== 0 && Math.abs(px) <= SCROLL_BY_MAX
306
- ? undefined
307
- : `by must be a whole number of pixels from -${SCROLL_BY_MAX} to ${SCROLL_BY_MAX}, not 0`, {
308
- toJsonSchema: () => ({
309
- type: 'integer',
310
- minimum: -SCROLL_BY_MAX,
311
- maximum: SCROLL_BY_MAX,
312
- not: { const: 0 },
313
- }),
314
- })).annotate({
315
- description: `Scroll the page, or with frame that frame, down this many CSS pixels (negative: up); at most ${SCROLL_BY_MAX}.`,
316
- })),
317
- frame: Schema.optionalKey(FramePath),
318
- timeoutMs: timeoutMs('for the target or frame (default 5000)'),
319
- })
320
- .check(Schema.makeFilter((step) => {
321
- const set = ['target', 'to', 'by'].filter((key) => step[key] !== undefined);
322
- if (set.length !== 1)
323
- return 'Set exactly one of target, to or by';
324
- if (step.target !== undefined && step.frame !== undefined)
325
- return 'With target, give the frame in the target itself';
326
- return undefined;
327
- }, {
328
- toJsonSchema: () => ({
329
- oneOf: [{ required: ['target'] }, { required: ['to'] }, { required: ['by'] }],
330
- not: { required: ['target', 'frame'] },
331
- }),
332
- }))
333
- .annotate({
334
- description: 'Scroll, then take a screenshot of what is in view: exactly one of target (into view), ' +
335
- 'to ("top" or "bottom") or by (pixels down, negative up). With to or by, frame scrolls ' +
336
- 'that <iframe> instead of the page.',
337
- }),
338
- Schema.Struct({
339
- action: Schema.Literal('expectUrl'),
340
- includes: Schema.NonEmptyString.annotate({ description: 'Substring of the full URL.' }),
341
- timeoutMs: timeoutMs('for the URL (default 5000)'),
342
- }).annotate({ description: 'Expect the page URL to contain this.' }),
343
- Schema.Struct({
344
- action: Schema.Literal('expectLink'),
345
- target: Target.annotate({
346
- description: 'The link, or an element inside one, such as {"role":"link","name":"LinkedIn"}.',
347
- }),
348
- href: Schema.NonEmptyString.annotate({
349
- description: 'What its address must hold, such as linkedin.com/in/; with match exact, the whole ' +
350
- 'address, absolute or a path resolved against the page URL.',
351
- }),
352
- match: Schema.optionalKey(LinkMatch.annotate({
353
- description: 'contains (default): the address contains href; exact: it is href.',
354
- })),
355
- timeoutMs: timeoutMs('for the link (default 5000)'),
356
- }).annotate({
357
- description: 'Expect a link to go to an address, without following it: ' +
358
- '{"action":"expectLink","target":{"role":"link","name":"LinkedIn"},"href":"linkedin.com/in/"}. ' +
359
- 'An element that is not a link, or a link elsewhere, fails the case.',
360
- }),
361
- Schema.Struct({
362
- action: Schema.Literal('screenshot'),
363
- name: Slug.annotate({ description: 'File name without extension, such as after-login.' }),
364
- }).annotate({ description: 'Save a full-page screenshot as evidence.' }),
365
- ]);
366
- /**
367
- * How long a page load that starts during `step` may take, from its start to its response:
368
- * `timeoutMs` for steps that load a page themselves (goto, reload, press), and for other steps at
369
- * least `DEFAULT_LOAD_MS`, so a long wait for an element never shortens one.
370
- */
371
- export const loadTimeoutOf = (step) => {
372
- if (step === undefined || step.action === 'screenshot')
373
- return DEFAULT_LOAD_MS;
374
- if (step.action === 'goto' || step.action === 'reload' || step.action === 'press')
375
- return step.timeoutMs ?? DEFAULT_LOAD_MS;
376
- return Math.max(DEFAULT_LOAD_MS, step.timeoutMs ?? 0);
377
- };
378
- /** The `timeoutMs` of a step when it is not that step's default, for reports to mention. */
379
- export const customTimeoutOf = (step) => {
380
- if (step.action === 'screenshot' || step.timeoutMs === undefined)
381
- return undefined;
382
- const fallback = step.action === 'goto' || step.action === 'reload' || step.action === 'press'
383
- ? DEFAULT_LOAD_MS
384
- : DEFAULT_WAIT_MS;
385
- return step.timeoutMs === fallback ? undefined : step.timeoutMs;
386
- };
387
- /**
388
- * Every upload file the steps of `cases` give, in order, each path once: with the first `about`
389
- * given for it, and `allowMismatch` only when every step that sends it allows it.
390
- */
391
- export const uploadFilesOf = (cases) => {
392
- const files = new Map();
393
- for (const c of cases)
394
- for (const step of c.steps)
395
- if (step.action === 'upload')
396
- for (const file of step.files.map(uploadFileOf)) {
397
- const before = files.get(file.path);
398
- const about = before?.about ?? file.about;
399
- const allowMismatch = file.allowMismatch === true && (before === undefined || before.allowMismatch === true);
400
- files.set(file.path, {
401
- path: file.path,
402
- ...(about !== undefined ? { about } : {}),
403
- ...(allowMismatch ? { allowMismatch } : {}),
404
- });
405
- }
406
- return [...files.values()];
407
- };
408
- /** The longest `success` sentence a case may have. */
409
- export const SUCCESS_MAX = 300;
410
- /** One thing to check, written by the caller. */
411
- export const CaseSpec = Schema.Struct({
412
- id: Slug.annotate({ description: 'Short unique ID, such as login-works.' }),
413
- title: Schema.NonEmptyString,
414
- steps: Schema.Array(Step)
415
- .check(Schema.isMinLength(1))
416
- .annotate({
417
- description: 'Run in order. Cases run one after another in one browser session, so cookies and storage ' +
418
- 'carry over. If the first step is not goto, the case starts at the job URL, unless it ' +
419
- 'continues.',
420
- }),
421
- /**
422
- * Starts where the case before it ended, on the same page, rather than at the job URL: for
423
- * what a run makes along the way, such as a page generated at a new URL. Not on a job's first case.
424
- */
425
- continue: Schema.optionalKey(Schema.Boolean.annotate({
426
- description: 'Optional: true to start on the page the case before this one ended on, as it is, ' +
427
- 'instead of opening the job URL; for checks of what an earlier case made, each in a ' +
428
- 'case of its own. Runs even when that case failed. Not allowed on the first case.',
429
- })),
430
- /**
431
- * What success looks like, in one plain sentence, written by the caller when it plans the case.
432
- * Shown in the report next to the case; never interpreted, and it decides nothing.
433
- */
434
- success: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(SUCCESS_MAX, { message: `Use at most ${SUCCESS_MAX} characters` })).annotate({
435
- description: 'One plain sentence of what success looks like, such as "A new user lands on the ' +
436
- 'dashboard and sees a welcome message." Shown in the report; never interpreted.',
437
- })),
438
- });
439
- /** What a run should test. The input to `screw-bugs run` and the `start_run` MCP tool. */
440
- export const JobSpec = Schema.Struct({
441
- version: Schema.Literal(1),
442
- url: Schema.NonEmptyString.check(Schema.makeFilter((url) => isWebUrl(url)
443
- ? undefined
444
- : 'The URL must start with http:// or https://, such as http://localhost:3000')).annotate({ description: 'http or https URL of the app to test.' }),
445
- /**
446
- * What the user asked screw-bugs to do: their original request in their own words, verbatim
447
- * when possible. Provenance only; screw-bugs stores and displays it but never interprets it or
448
- * plans from it. Only `cases` decide what runs.
449
- */
450
- instructions: Schema.optionalKey(Schema.String.annotate({
451
- description: "The user's original request in their own words, verbatim when possible. Shown in the report; never interpreted.",
452
- })),
453
- /**
454
- * A short name for this run, written by the caller, such as "Notes app walkthrough" or
455
- * "Checkout on mobile". Shown as the report's heading; never interpreted. Without one, the heading is the app's own page title as the run recorded it, or
456
- * else the target's host (see `reportHeading`).
457
- */
458
- title: Schema.optionalKey(ShortLine(80, `A short name for this run, such as "Notes app walkthrough" or "Checkout on mobile". Shown as the report's heading; never interpreted.`)),
459
- /**
460
- * A high-level summary of what this run tests and why, written by the caller from the cases it
461
- * built: what is being checked, not step by step, so it reads well at the top of a report for
462
- * someone who never saw the steps. screw-bugs stores and displays it but never interprets it.
463
- * Without one, {@link summaryOf} derives one from the case titles.
464
- */
465
- summary: Schema.optionalKey(Schema.String.annotate({
466
- description: 'What these cases test and why, for a human reader; not steps. Shown in the report; never interpreted.',
467
- })),
468
- cases: Schema.optionalKey(Schema.Array(CaseSpec)
469
- .check(Schema.makeFilter((cases) => {
470
- const ids = cases.map((c) => c.id);
471
- const duplicate = ids.find((id, i) => ids.indexOf(id) !== i);
472
- if (duplicate !== undefined)
473
- return `Case ID "${duplicate}" is used twice`;
474
- return cases[0]?.continue === true
475
- ? `The first case, "${cases[0].id}", cannot continue: there is no case before it to continue from. Remove "continue" from it, or put the case that sets the page up before it`
476
- : undefined;
477
- },
478
- // Unique IDs have no JSON Schema form (uniqueItems compares whole cases); the first
479
- // case's continue does.
480
- {
481
- toJsonSchema: () => [
482
- {
483
- prefixItems: [
484
- { not: { required: ['continue'], properties: { continue: { const: true } } } },
485
- ],
486
- },
487
- true,
488
- ],
489
- }))
490
- .annotate({
491
- description: 'Cases to run in order. Without cases, one "page loads" case runs.',
492
- })),
493
- device: Schema.optionalKey(Device),
494
- /**
495
- * The test account the session starts signed in as (see `JobAccount`): a session a person saved
496
- * once for this origin. Its cases run signed in from the first step.
497
- */
498
- account: Schema.optionalKey(JobAccount.annotate({
499
- description: 'Omit to run signed out (a fresh browser with no cookies or storage, whatever accounts ' +
500
- 'are saved). A test account to run signed in as: a label from .screw-bugs/accounts.json whose about ' +
501
- 'fits what the cases need (such as a user on a trial, or a paying one), or a new ' +
502
- '{"label":"paid-user","about":"Pro plan, paying monthly"} for the user to sign in to. ' +
503
- 'Read .screw-bugs/accounts.json first: when the account the cases need is not saved ' +
504
- 'there, get the app running and that user in place (the sign-in opens the app at once), ' +
505
- 'then start the job before the rest of your preparation. Without a saved session ' +
506
- 'nothing starts and the reply gives a link for the user, who signs in while you prepare.',
507
- })),
508
- });
509
- /**
510
- * A job as a caller submits it: a {@link JobSpec} whose case IDs are also unique ignoring case,
511
- * since replies and reports name cases by ID, where `Login` and `login` would read as one case.
512
- * Only new jobs are checked; a run recorded before this rule still reads as a JobSpec.
513
- */
514
- export const NewJobSpec = JobSpec.check(Schema.makeFilter((spec) => {
515
- const seen = new Map();
516
- for (const { id } of spec.cases ?? []) {
517
- const before = seen.get(id.toLowerCase());
518
- if (before !== undefined && before !== id)
519
- return `Case IDs "${before}" and "${id}" differ only in case; make them unique ignoring case`;
520
- seen.set(id.toLowerCase(), id);
521
- }
522
- return undefined;
523
- }));
524
- /** What `job.json` in a run folder holds. */
525
- export const JobRecord = Schema.Struct({
526
- jobId: JobId,
527
- spec: JobSpec,
528
- createdAt: Schema.String,
529
- });
530
- /** The case a job without cases gets: the page loads without an HTTP error, plus a screenshot. */
531
- export const casesOf = (spec) => spec.cases && spec.cases.length > 0
532
- ? spec.cases
533
- : [
534
- {
535
- id: 'page-loads',
536
- title: 'Page loads',
537
- steps: [
538
- { action: 'goto', url: spec.url },
539
- { action: 'screenshot', name: 'page' },
540
- ],
541
- },
542
- ];
543
- /** A case title as a clause of the derived summary: no final period, lowercase unless an acronym. */
544
- const asClause = (title) => {
545
- const flat = title
546
- .replace(/\s+/g, ' ')
547
- .trim()
548
- .replace(/[.;]+$/, '');
549
- const [first = ''] = flat.split(' ');
550
- return first.length > 1 && first === first.toUpperCase()
551
- ? flat
552
- : flat.charAt(0).toLowerCase() + flat.slice(1);
553
- };
554
- /**
555
- * The summary to show for a job: the caller's own when it gave one, otherwise one derived from
556
- * the case titles, such as `Checks: page loads; signup with a valid email`. Deterministic; no AI.
557
- * `derived` tells a report which of the two it got.
558
- */
559
- export const summaryOf = (spec) => spec.summary?.trim()
560
- ? { text: spec.summary, derived: false }
561
- : {
562
- text: `Checks: ${casesOf(spec)
563
- .map((c) => asClause(c.title))
564
- .join('; ')}`,
565
- derived: true,
566
- };
567
- /** A question the engine asks when it cannot continue on its own (for example, a one-time code). */
568
- export const Question = Schema.Struct({
569
- id: Schema.NonEmptyString,
570
- jobId: JobId,
571
- text: Schema.NonEmptyString,
572
- });
573
- export const Answer = Schema.Struct({
574
- questionId: Schema.NonEmptyString,
575
- jobId: JobId,
576
- text: Schema.String,
577
- });