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.
- package/README.md +100 -54
- package/dist/browser-playwright/capture.js +1 -1
- package/dist/build-info.json +3 -3
- package/dist/cli/app.js +6 -2
- package/dist/cli/commands.js +4 -3
- package/dist/cli/doctor.d.ts +17 -2
- package/dist/cli/doctor.js +62 -4
- package/dist/cli/mcp.js +7 -4
- package/dist/cli/report-server.d.ts +19 -10
- package/dist/cli/report-server.js +43 -18
- package/dist/cli/share.js +2 -2
- package/dist/cli/sign-in.d.ts +9 -3
- package/dist/cli/sign-in.js +12 -9
- package/dist/cli/tailnet.d.ts +57 -0
- package/dist/cli/tailnet.js +82 -0
- package/dist/core/index.d.ts +1 -14
- package/dist/core/index.js +3 -14
- package/dist/report/index.d.ts +1 -10
- package/dist/report/index.js +3 -10
- package/dist/schema/index.d.ts +1 -9
- package/dist/schema/index.js +3 -9
- package/package.json +14 -14
- package/dist/core/accounts.d.ts +0 -40
- package/dist/core/accounts.js +0 -95
- package/dist/core/css.d.ts +0 -95
- package/dist/core/css.js +0 -436
- package/dist/core/engine.d.ts +0 -75
- package/dist/core/engine.js +0 -560
- package/dist/core/errors.d.ts +0 -85
- package/dist/core/errors.js +0 -36
- package/dist/core/evidence.d.ts +0 -14
- package/dist/core/evidence.js +0 -131
- package/dist/core/labels.d.ts +0 -47
- package/dist/core/labels.js +0 -199
- package/dist/core/liveness.d.ts +0 -45
- package/dist/core/liveness.js +0 -66
- package/dist/core/marks.d.ts +0 -63
- package/dist/core/marks.js +0 -410
- package/dist/core/services.d.ts +0 -579
- package/dist/core/services.js +0 -25
- package/dist/core/share.d.ts +0 -68
- package/dist/core/share.js +0 -318
- package/dist/core/steps.d.ts +0 -106
- package/dist/core/steps.js +0 -722
- package/dist/core/uploads.d.ts +0 -49
- package/dist/core/uploads.js +0 -133
- package/dist/core/video.d.ts +0 -53
- package/dist/core/video.js +0 -241
- package/dist/core/viewport.d.ts +0 -28
- package/dist/core/viewport.js +0 -50
- package/dist/report/assets.d.ts +0 -34
- package/dist/report/assets.js +0 -105
- package/dist/report/bug.d.ts +0 -11
- package/dist/report/bug.js +0 -20
- package/dist/report/html.d.ts +0 -47
- package/dist/report/html.js +0 -923
- package/dist/report/icons.d.ts +0 -51
- package/dist/report/icons.js +0 -93
- package/dist/report/live.d.ts +0 -7
- package/dist/report/live.js +0 -135
- package/dist/report/logos.d.ts +0 -4
- package/dist/report/logos.js +0 -19
- package/dist/report/markup.d.ts +0 -50
- package/dist/report/markup.js +0 -156
- package/dist/report/menu-bar.d.ts +0 -60
- package/dist/report/menu-bar.js +0 -157
- package/dist/report/player.d.ts +0 -102
- package/dist/report/player.js +0 -315
- package/dist/report/pr-summary.d.ts +0 -11
- package/dist/report/pr-summary.js +0 -119
- package/dist/report/sha256.d.ts +0 -9
- package/dist/report/sha256.js +0 -97
- package/dist/report/share-page.d.ts +0 -48
- package/dist/report/share-page.js +0 -291
- package/dist/report/shots.d.ts +0 -59
- package/dist/report/shots.js +0 -280
- package/dist/report/sign-in.d.ts +0 -41
- package/dist/report/sign-in.js +0 -568
- package/dist/report/styles.d.ts +0 -3
- package/dist/report/styles.js +0 -274
- package/dist/report/view.d.ts +0 -296
- package/dist/report/view.js +0 -702
- package/dist/report/walkthrough.d.ts +0 -93
- package/dist/report/walkthrough.js +0 -716
- package/dist/schema/accounts.d.ts +0 -137
- package/dist/schema/accounts.js +0 -121
- package/dist/schema/config.d.ts +0 -7
- package/dist/schema/config.js +0 -6
- package/dist/schema/doctor.d.ts +0 -46
- package/dist/schema/doctor.js +0 -30
- package/dist/schema/evidence.d.ts +0 -1115
- package/dist/schema/evidence.js +0 -565
- package/dist/schema/findings.d.ts +0 -161
- package/dist/schema/findings.js +0 -82
- package/dist/schema/job.d.ts +0 -1905
- package/dist/schema/job.js +0 -577
- package/dist/schema/ledger.d.ts +0 -1124
- package/dist/schema/ledger.js +0 -285
- package/dist/schema/share.d.ts +0 -55
- package/dist/schema/share.js +0 -64
- package/dist/schema/status.d.ts +0 -7
- package/dist/schema/status.js +0 -11
package/dist/core/share.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* What a share on screw-bugs Cloud holds (see `src/schema/share.ts` for the protocol): the run's
|
|
3
|
-
* report bundle with secrets taken out, and the screenshots and videos it links to. Cloud takes
|
|
4
|
-
* only image and video files under the run's `evidence/`, `annotated/` and `video/` folders, by the
|
|
5
|
-
* same relative paths the bundle uses; never HTML or JSON. Taking secrets out is the local side's
|
|
6
|
-
* job: Cloud only drops fields its schema does not know.
|
|
7
|
-
*/
|
|
8
|
-
/** The folders of a run whose files a share may hold. */
|
|
9
|
-
export const SHARE_DIRS = ['evidence', 'annotated', 'video'];
|
|
10
|
-
/** The file types a share may hold, by extension. */
|
|
11
|
-
export const SHARE_EXTENSIONS = new Set([
|
|
12
|
-
'png',
|
|
13
|
-
'jpg',
|
|
14
|
-
'jpeg',
|
|
15
|
-
'webp',
|
|
16
|
-
'webm',
|
|
17
|
-
'mp4',
|
|
18
|
-
]);
|
|
19
|
-
const SEGMENT = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
20
|
-
const MAX_PATH = 200;
|
|
21
|
-
/**
|
|
22
|
-
* Whether Cloud takes a file at `path` (relative to the run folder): under one of `SHARE_DIRS`,
|
|
23
|
-
* plain segments only (no `..`, hidden files or escapes), an image or video, at most 200
|
|
24
|
-
* characters. The same rule as Cloud's own.
|
|
25
|
-
*/
|
|
26
|
-
export const shareable = (path) => {
|
|
27
|
-
if (path.length === 0 || path.length > MAX_PATH)
|
|
28
|
-
return false;
|
|
29
|
-
const segments = path.split('/');
|
|
30
|
-
if (segments.length < 2 || !SHARE_DIRS.includes(segments[0]))
|
|
31
|
-
return false;
|
|
32
|
-
if (!segments.every((segment) => SEGMENT.test(segment)))
|
|
33
|
-
return false;
|
|
34
|
-
const dot = path.lastIndexOf('.');
|
|
35
|
-
return dot > 0 && SHARE_EXTENSIONS.has(path.slice(dot + 1).toLowerCase());
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* The files of the run a share of `bundle` holds: every screenshot, annotated copy and session
|
|
39
|
-
* video the bundle links to that Cloud takes (`shareable`), each once, in a stable order.
|
|
40
|
-
*/
|
|
41
|
-
export const shareFiles = (bundle) => {
|
|
42
|
-
const paths = new Set();
|
|
43
|
-
for (const entry of bundle.ledger.cases) {
|
|
44
|
-
for (const path of entry.evidence)
|
|
45
|
-
paths.add(path);
|
|
46
|
-
for (const shot of entry.shots ?? [])
|
|
47
|
-
paths.add(shot.path);
|
|
48
|
-
}
|
|
49
|
-
for (const session of bundle.ledger.sessions ?? [])
|
|
50
|
-
if (session.video !== undefined)
|
|
51
|
-
paths.add(session.video);
|
|
52
|
-
for (const path of Object.values(bundle.annotated ?? {}))
|
|
53
|
-
paths.add(path);
|
|
54
|
-
return [...paths].filter(shareable).sort();
|
|
55
|
-
};
|
|
56
|
-
/** What a secret is replaced with in a shared bundle. */
|
|
57
|
-
export const HIDDEN = 'hidden';
|
|
58
|
-
/**
|
|
59
|
-
* A field that takes a secret, by how a step names it (its label, accessible name, text, alt or CSS
|
|
60
|
-
* selector): a password, PIN, one-time or security code, token, key, card number and the like.
|
|
61
|
-
*/
|
|
62
|
-
const SECRET_FIELD = /pass(?:word|code|phrase)?|pwd|secret|token|api[\s_-]?key|private[\s_-]?key|\botp\b|one[\s_-]?time|2fa|mfa|totp|\bpin\b|cvc|cvv|security[\s_-]?code|card[\s_-]?number|cc-?num|\bssn\b|social[\s_-]?security|credential/i;
|
|
63
|
-
/**
|
|
64
|
-
* A URL query or fragment parameter whose value may be a secret: tokens, keys, signatures,
|
|
65
|
-
* sessions, codes, passwords and the like.
|
|
66
|
-
*/
|
|
67
|
-
const SECRET_PARAM = /token|secret|pass|pwd|auth|key|sig|session|sess|sid|code|otp|jwt|credential|nonce|ticket|state|cookie/i;
|
|
68
|
-
/**
|
|
69
|
-
* URLs inside any text: `http:` or `https:` up to whitespace. What ends one in prose (`.`, `,`, a
|
|
70
|
-
* closing bracket or quote) stays outside it, unless the URL ends with a secret's value, which
|
|
71
|
-
* that punctuation could belong to: then the whole match is scrubbed as one URL, so the secret is
|
|
72
|
-
* hidden whole (and the prose loses that punctuation).
|
|
73
|
-
*/
|
|
74
|
-
const URL_IN_TEXT = /\bhttps?:\/\/\S+/gi;
|
|
75
|
-
const URL_END = /[.,;:!?)\]}'"`>]+$/;
|
|
76
|
-
/** A string that is a URL and nothing else, scrubbed whole. */
|
|
77
|
-
const WHOLE_URL = /^https?:\/\/\S+$/i;
|
|
78
|
-
/** `params` with the values of secret-looking names hidden, in place and order; or undefined. */
|
|
79
|
-
const hideParams = (params) => {
|
|
80
|
-
let changed = false;
|
|
81
|
-
const entries = [...params].map(([name, value]) => {
|
|
82
|
-
if (!SECRET_PARAM.test(name) || value === HIDDEN)
|
|
83
|
-
return [name, value];
|
|
84
|
-
changed = true;
|
|
85
|
-
return [name, HIDDEN];
|
|
86
|
-
});
|
|
87
|
-
return changed ? new URLSearchParams(entries) : undefined;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* `url` without what may be a secret: a user name and password, and the values of query and
|
|
91
|
-
* fragment parameters with secret-looking names (`?token=hidden`). Unchanged, byte for byte, when
|
|
92
|
-
* it has none, or does not parse.
|
|
93
|
-
*/
|
|
94
|
-
export const scrubUrl = (url) => {
|
|
95
|
-
let parsed;
|
|
96
|
-
try {
|
|
97
|
-
parsed = new URL(url);
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return url;
|
|
101
|
-
}
|
|
102
|
-
let changed = false;
|
|
103
|
-
if (parsed.username !== '' || parsed.password !== '') {
|
|
104
|
-
parsed.username = '';
|
|
105
|
-
parsed.password = '';
|
|
106
|
-
changed = true;
|
|
107
|
-
}
|
|
108
|
-
const query = hideParams(new URLSearchParams(parsed.search));
|
|
109
|
-
if (query !== undefined) {
|
|
110
|
-
parsed.search = query.toString();
|
|
111
|
-
changed = true;
|
|
112
|
-
}
|
|
113
|
-
// A fragment of parameters, as OAuth's implicit flow gives tokens (`#access_token=…`).
|
|
114
|
-
if (parsed.hash.includes('=')) {
|
|
115
|
-
const fragment = hideParams(new URLSearchParams(parsed.hash.slice(1)));
|
|
116
|
-
if (fragment !== undefined) {
|
|
117
|
-
parsed.hash = fragment.toString();
|
|
118
|
-
changed = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return changed ? parsed.href : url;
|
|
122
|
-
};
|
|
123
|
-
/** Whether `url` ends with the value of a secret-looking parameter (of its fragment, else query). */
|
|
124
|
-
const endsWithSecret = (url) => {
|
|
125
|
-
let parsed;
|
|
126
|
-
try {
|
|
127
|
-
parsed = new URL(url);
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
const params = parsed.hash !== ''
|
|
133
|
-
? parsed.hash.includes('=')
|
|
134
|
-
? new URLSearchParams(parsed.hash.slice(1))
|
|
135
|
-
: undefined
|
|
136
|
-
: new URLSearchParams(parsed.search);
|
|
137
|
-
const last = params === undefined ? undefined : [...params.keys()].at(-1);
|
|
138
|
-
return last !== undefined && SECRET_PARAM.test(last);
|
|
139
|
-
};
|
|
140
|
-
/** `text` with every URL in it scrubbed (`scrubUrl`). */
|
|
141
|
-
export const scrubText = (text) => WHOLE_URL.test(text)
|
|
142
|
-
? scrubUrl(text)
|
|
143
|
-
: text.replace(URL_IN_TEXT, (found) => {
|
|
144
|
-
const end = URL_END.exec(found)?.[0] ?? '';
|
|
145
|
-
const url = found.slice(0, found.length - end.length);
|
|
146
|
-
if (end === '' || !endsWithSecret(url))
|
|
147
|
-
return scrubUrl(url) + end;
|
|
148
|
-
return scrubUrl(found);
|
|
149
|
-
});
|
|
150
|
-
/** Every string in `value` (a JSON value), scrubbed (`scrubText`). */
|
|
151
|
-
const scrubStrings = (value) => {
|
|
152
|
-
if (typeof value === 'string')
|
|
153
|
-
return scrubText(value);
|
|
154
|
-
if (Array.isArray(value))
|
|
155
|
-
return value.map(scrubStrings);
|
|
156
|
-
if (value !== null && typeof value === 'object')
|
|
157
|
-
return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, scrubStrings(inner)]));
|
|
158
|
-
return value;
|
|
159
|
-
};
|
|
160
|
-
/** Whether `step` types into a field that takes a secret (see `SECRET_FIELD`). */
|
|
161
|
-
export const typesSecret = (step) => step.action === 'fill' &&
|
|
162
|
-
Object.values(step.target).some((name) => typeof name === 'string' && SECRET_FIELD.test(name));
|
|
163
|
-
/**
|
|
164
|
-
* `bundle` as it may leave the machine: what was typed into a field that takes a secret (a
|
|
165
|
-
* password, a code, a token, see `typesSecret`) is `hidden`, and so are the credentials and
|
|
166
|
-
* secret-looking parameters of every URL in it (`scrubUrl`), wherever they appear (the target, its
|
|
167
|
-
* steps, page addresses, reasons, the write-up). What it cannot know stays: a secret in a URL's
|
|
168
|
-
* path or in free text, or typed into a field named like any other, and whatever the screenshots
|
|
169
|
-
* and video show.
|
|
170
|
-
*/
|
|
171
|
-
export const scrubBundle = (bundle) => {
|
|
172
|
-
const cases = bundle.spec.cases?.map((entry) => ({
|
|
173
|
-
...entry,
|
|
174
|
-
steps: entry.steps.map((step) => typesSecret(step) && step.action === 'fill' ? { ...step, value: HIDDEN } : step),
|
|
175
|
-
}));
|
|
176
|
-
const typed = cases === undefined ? bundle : { ...bundle, spec: { ...bundle.spec, cases } };
|
|
177
|
-
// Only strings change, so the result keeps the bundle's shape.
|
|
178
|
-
return scrubStrings(typed);
|
|
179
|
-
};
|
|
180
|
-
/*
|
|
181
|
-
* Smaller screenshots for a share: the person's browser re-encodes PNG screenshots as WebP at
|
|
182
|
-
* their own size (see `src/cli/share.ts`), and the share holds the WebP in its place, under the
|
|
183
|
-
* same path with `.webp`. Only screenshots the ledger describes (`shots`) and annotated copies
|
|
184
|
-
* change: older runs without `shots` name their screenshots by `.png` endings the report reads.
|
|
185
|
-
*/
|
|
186
|
-
/** The screenshots of `bundle` a share may hold as WebP instead: its PNGs, of `shareFiles`. */
|
|
187
|
-
export const encodableFiles = (bundle) => {
|
|
188
|
-
const paths = new Set();
|
|
189
|
-
for (const entry of bundle.ledger.cases)
|
|
190
|
-
for (const shot of entry.shots ?? [])
|
|
191
|
-
paths.add(shot.path);
|
|
192
|
-
for (const path of Object.values(bundle.annotated ?? {}))
|
|
193
|
-
paths.add(path);
|
|
194
|
-
return new Set([...paths].filter((path) => shareable(path) && /\.png$/i.test(path)));
|
|
195
|
-
};
|
|
196
|
-
/** Where the WebP of the screenshot at `path` goes: the same path, ending `.webp`. */
|
|
197
|
-
export const webpPath = (path) => path.replace(/\.png$/i, '.webp');
|
|
198
|
-
/**
|
|
199
|
-
* `bundle` with its file paths changed as `renames` says (old path to new), wherever the bundle
|
|
200
|
-
* names them: each case's evidence, their names and shots, and the annotated copies.
|
|
201
|
-
*/
|
|
202
|
-
export const renameFiles = (bundle, renames) => {
|
|
203
|
-
if (renames.size === 0)
|
|
204
|
-
return bundle;
|
|
205
|
-
const to = (path) => renames.get(path) ?? path;
|
|
206
|
-
return {
|
|
207
|
-
...bundle,
|
|
208
|
-
ledger: {
|
|
209
|
-
...bundle.ledger,
|
|
210
|
-
cases: bundle.ledger.cases.map((entry) => ({
|
|
211
|
-
...entry,
|
|
212
|
-
evidence: entry.evidence.map(to),
|
|
213
|
-
...(entry.evidenceNames === undefined
|
|
214
|
-
? {}
|
|
215
|
-
: {
|
|
216
|
-
evidenceNames: Object.fromEntries(Object.entries(entry.evidenceNames).map(([path, name]) => [to(path), name])),
|
|
217
|
-
}),
|
|
218
|
-
...(entry.shots === undefined
|
|
219
|
-
? {}
|
|
220
|
-
: { shots: entry.shots.map((shot) => ({ ...shot, path: to(shot.path) })) }),
|
|
221
|
-
})),
|
|
222
|
-
},
|
|
223
|
-
...(bundle.annotated === undefined
|
|
224
|
-
? {}
|
|
225
|
-
: {
|
|
226
|
-
annotated: Object.fromEntries(Object.entries(bundle.annotated).map(([id, path]) => [id, to(path)])),
|
|
227
|
-
}),
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
const ascii = (bytes, at, text) => [...text].every((char, i) => bytes[at + i] === char.charCodeAt(0));
|
|
231
|
-
const u32be = (bytes, at) => ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
|
|
232
|
-
const u32le = (bytes, at) => (bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16) | (bytes[at + 3] << 24)) >>> 0;
|
|
233
|
-
/**
|
|
234
|
-
* The most pixels a WebP image has on a side. A browser asked to encode a taller screenshot (a
|
|
235
|
-
* long full-page one) gives a cut-down image, so such screenshots are never offered.
|
|
236
|
-
*/
|
|
237
|
-
export const WEBP_MAX_SIDE = 16383;
|
|
238
|
-
/** How many bytes of a PNG `pngSize` reads: the signature and the IHDR chunk's size fields. */
|
|
239
|
-
export const PNG_HEADER_BYTES = 24;
|
|
240
|
-
/** The size of the PNG whose first bytes are `bytes`, or undefined for anything else. */
|
|
241
|
-
export const pngSize = (bytes) => {
|
|
242
|
-
const signature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
243
|
-
if (bytes.length < PNG_HEADER_BYTES || !signature.every((byte, i) => bytes[i] === byte))
|
|
244
|
-
return undefined;
|
|
245
|
-
if (!ascii(bytes, 12, 'IHDR'))
|
|
246
|
-
return undefined;
|
|
247
|
-
const width = u32be(bytes, 16);
|
|
248
|
-
const height = u32be(bytes, 20);
|
|
249
|
-
return width > 0 && height > 0 ? { width, height } : undefined;
|
|
250
|
-
};
|
|
251
|
-
/** The size a VP8 (lossy) or VP8L (lossless) image chunk's `data` says, or undefined. */
|
|
252
|
-
const imageSize = (kind, data) => {
|
|
253
|
-
if (kind === 'VP8 ') {
|
|
254
|
-
// A frame tag that says key frame, its start code, then 14 bits each of width and height
|
|
255
|
-
// (2 bits of scale above), and image data after them.
|
|
256
|
-
if (data.length <= 10 || (data[0] & 1) !== 0)
|
|
257
|
-
return undefined;
|
|
258
|
-
if (data[3] !== 0x9d || data[4] !== 0x01 || data[5] !== 0x2a)
|
|
259
|
-
return undefined;
|
|
260
|
-
const width = (data[6] | (data[7] << 8)) & 0x3fff;
|
|
261
|
-
const height = (data[8] | (data[9] << 8)) & 0x3fff;
|
|
262
|
-
return width > 0 && height > 0 ? { width, height } : undefined;
|
|
263
|
-
}
|
|
264
|
-
if (kind === 'VP8L') {
|
|
265
|
-
// A signature byte, then 14 bits each of width - 1 and height - 1, and image data after them.
|
|
266
|
-
if (data.length <= 5 || data[0] !== 0x2f)
|
|
267
|
-
return undefined;
|
|
268
|
-
const bits = u32le(data, 1);
|
|
269
|
-
return { width: (bits & 0x3fff) + 1, height: ((bits >>> 14) & 0x3fff) + 1 };
|
|
270
|
-
}
|
|
271
|
-
return undefined;
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* The size of the WebP file `bytes`, or undefined unless it is one whole still image: a RIFF
|
|
275
|
-
* `WEBP` container whose length is the file's, made of chunks that fill it exactly (each padded
|
|
276
|
-
* to an even length), holding one lossy (`VP8 `) or lossless (`VP8L`) image with data in it,
|
|
277
|
-
* first or after an extended header (`VP8X`, not animated) whose canvas is the image's size.
|
|
278
|
-
* It does not decode the image, so a file can still be broken inside its image data.
|
|
279
|
-
*/
|
|
280
|
-
export const webpSize = (bytes) => {
|
|
281
|
-
if (bytes.length < 20 || !ascii(bytes, 0, 'RIFF') || !ascii(bytes, 8, 'WEBP'))
|
|
282
|
-
return undefined;
|
|
283
|
-
if (u32le(bytes, 4) + 8 !== bytes.length)
|
|
284
|
-
return undefined;
|
|
285
|
-
const chunks = [];
|
|
286
|
-
let at = 12;
|
|
287
|
-
while (at < bytes.length) {
|
|
288
|
-
if (at + 8 > bytes.length)
|
|
289
|
-
return undefined;
|
|
290
|
-
const kind = String.fromCharCode(...bytes.subarray(at, at + 4));
|
|
291
|
-
const size = u32le(bytes, at + 4);
|
|
292
|
-
const end = at + 8 + size;
|
|
293
|
-
if (end > bytes.length)
|
|
294
|
-
return undefined;
|
|
295
|
-
chunks.push({ kind, data: bytes.subarray(at + 8, end) });
|
|
296
|
-
at = end + (size % 2);
|
|
297
|
-
}
|
|
298
|
-
if (at !== bytes.length)
|
|
299
|
-
return undefined;
|
|
300
|
-
const images = chunks.filter((chunk) => chunk.kind === 'VP8 ' || chunk.kind === 'VP8L');
|
|
301
|
-
if (images.length !== 1)
|
|
302
|
-
return undefined;
|
|
303
|
-
const image = images[0];
|
|
304
|
-
const size = imageSize(image.kind, image.data);
|
|
305
|
-
if (size === undefined)
|
|
306
|
-
return undefined;
|
|
307
|
-
const first = chunks[0];
|
|
308
|
-
if (first === image)
|
|
309
|
-
return size;
|
|
310
|
-
if (first.kind !== 'VP8X' || first.data.length < 10)
|
|
311
|
-
return undefined;
|
|
312
|
-
// Not animated (an animation has frames in ANMF chunks, not one image).
|
|
313
|
-
if ((first.data[0] & 0x02) !== 0)
|
|
314
|
-
return undefined;
|
|
315
|
-
const width = (first.data[4] | (first.data[5] << 8) | (first.data[6] << 16)) + 1;
|
|
316
|
-
const height = (first.data[7] | (first.data[8] << 8) | (first.data[9] << 16)) + 1;
|
|
317
|
-
return width === size.width && height === size.height ? size : undefined;
|
|
318
|
-
};
|
package/dist/core/steps.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Effect } from 'effect';
|
|
2
|
-
import { type CaseEntry, type CaseSpec, type LinkMatch, type OnScreen, type ShotPage, type Step, type Target } from '../schema/index.js';
|
|
3
|
-
import type { BrowserPage, Elsewhere, Frames, TextSeen, UploadSource } from './services.js';
|
|
4
|
-
/** Where a screenshot goes: `path` is absolute, `relative` is what the ledger records. */
|
|
5
|
-
export interface EvidenceFile {
|
|
6
|
-
readonly path: string;
|
|
7
|
-
readonly relative: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* A screenshot name as a decorative part of a file name: lowercase letters, digits and dashes,
|
|
11
|
-
* at most `SLUG_MAX` characters. It never makes a file name unique on its own; see
|
|
12
|
-
* {@link evidenceFileName}.
|
|
13
|
-
*/
|
|
14
|
-
export declare const fileSlug: (name: string) => string;
|
|
15
|
-
/**
|
|
16
|
-
* Where the `shot`th screenshot of the `caseNumber`th case is stored, relative to the evidence
|
|
17
|
-
* folder, such as `01/03-after-login.png`. Both numbers are 1-based. The numbers alone make a name
|
|
18
|
-
* unique, so it does not depend on how a file system compares names: `A` and `a`, or `shot` and
|
|
19
|
-
* `SHOT`, never land on the same file on Windows or macOS. The name starts with digits and holds
|
|
20
|
-
* only lowercase letters, digits and dashes, so it is never a reserved Windows name (`CON`,
|
|
21
|
-
* `LPT1`) and never ends in a dot or space.
|
|
22
|
-
*/
|
|
23
|
-
export declare const evidenceFileName: (caseNumber: number, shot: number, name: string) => string;
|
|
24
|
-
/** Where something is, innermost frame first, such as ` in iframe css "iframe.preview"`. */
|
|
25
|
-
export declare const describeFrames: (frames: Frames) => string;
|
|
26
|
-
/** Such as `text "Save" in iframe css "iframe.preview"`. */
|
|
27
|
-
export declare const describeTarget: (target: Target) => string;
|
|
28
|
-
export declare const describeStep: (step: Step) => string;
|
|
29
|
-
/** Relative URLs (`/login`) are resolved against the job URL. */
|
|
30
|
-
export declare const resolveUrl: (url: string, base: string) => string;
|
|
31
|
-
/**
|
|
32
|
-
* The scheme of a URL screw-bugs must not open or capture, such as `file:`; undefined for http
|
|
33
|
-
* and https (see `WEB_SCHEMES`). `about:blank` holds nothing, so it passes too: it is where a
|
|
34
|
-
* page starts, and where it stays when a load fails.
|
|
35
|
-
*/
|
|
36
|
-
export declare const refusedScheme: (url: string) => string | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* The first step of every case is a navigation, so each case starts from a known page: a case
|
|
39
|
-
* that does not begin with goto starts at the job URL. A case that continues (`CaseSpec.continue`)
|
|
40
|
-
* starts where the case before it ended instead, with its own steps only.
|
|
41
|
-
*/
|
|
42
|
-
export declare const withStartPage: (spec: Pick<CaseSpec, 'steps' | 'continue'>, jobUrl: string) => ReadonlyArray<Step>;
|
|
43
|
-
/**
|
|
44
|
-
* What to change when a step did not find its text or element where it looked (`given`, the
|
|
45
|
-
* page itself when empty) but it is somewhere else (`found`): the `frame` to add, to use instead,
|
|
46
|
-
* or to remove. Up to `named` frames are named, and how many hold it. `inTarget` says that `frame`
|
|
47
|
-
* goes on the step's target. Undefined when there is nothing to say.
|
|
48
|
-
*/
|
|
49
|
-
export declare const frameHint: (found: Elsewhere, given: Frames, inTarget: boolean, named?: number) => string | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* A reason with a hint after it (see `frameHint`), kept within `REASON_MAX` so the hint shows
|
|
52
|
-
* whole where reasons are cut. `hints` says the same in fewer words each, most first; the first
|
|
53
|
-
* that fits is used, with the step's own message, else with `short`. When none fits, the
|
|
54
|
-
* shortest is used, with `label` cut at a word (or only its step number).
|
|
55
|
-
*/
|
|
56
|
-
export declare const withHint: (label: string, message: string, short: string, hints: ReadonlyArray<string>) => string;
|
|
57
|
-
/**
|
|
58
|
-
* Whether a link's address `href` (absolute) is what an `expectLink` step expects: contains its
|
|
59
|
-
* `href`, or with `exact` is it, resolved against the page's URL `pageUrl` when it is a path.
|
|
60
|
-
*/
|
|
61
|
-
export declare const linkMatches: (href: string, expected: string, match: LinkMatch, pageUrl: string) => boolean;
|
|
62
|
-
/** How text that should not show did, such as `image alt "Acme logo" in .clients`. */
|
|
63
|
-
export declare const seenText: (seen: TextSeen) => string;
|
|
64
|
-
/**
|
|
65
|
-
* A measurement of how a step's element showed (see `OnScreen`) in a few words, such as `0% on
|
|
66
|
-
* screen: clipped by div[role="menu"]`; undefined when it showed.
|
|
67
|
-
*/
|
|
68
|
-
export declare const describeOnScreen: (seen: OnScreen) => string | undefined;
|
|
69
|
-
/** `01-03`: the ID of the 3rd screenshot of the 1st case, as agents name screenshots. */
|
|
70
|
-
export declare const shotId: (caseNumber: number, shot: number) => string;
|
|
71
|
-
/**
|
|
72
|
-
* Runs one case's steps in order and maps the outcome to a status: `passed` when every step ran
|
|
73
|
-
* and every expectation held, `failed` at the first expectation that did not hold, `blocked`
|
|
74
|
-
* at the first step that could not run. A case that does not pass also gets a screenshot of
|
|
75
|
-
* the page as it was. Records when it and each step ran (`now`), every screenshot with the page
|
|
76
|
-
* state saved next to it, and a few facts about the page at the end.
|
|
77
|
-
*/
|
|
78
|
-
export declare const runCase: (page: BrowserPage, spec: CaseSpec, options: {
|
|
79
|
-
readonly jobUrl: string;
|
|
80
|
-
/** 1-based position of the case in its job; it names the case's evidence folder. */
|
|
81
|
-
readonly caseNumber: number;
|
|
82
|
-
/**
|
|
83
|
-
* Maps a screenshot's file name in the evidence folder (see {@link evidenceFileName}) to where
|
|
84
|
-
* it is stored.
|
|
85
|
-
*/
|
|
86
|
-
readonly evidenceFile: (fileName: string) => EvidenceFile;
|
|
87
|
-
/** Milliseconds since the session's video started. */
|
|
88
|
-
readonly now: Effect.Effect<number>;
|
|
89
|
-
/** Saves the page state of a screenshot (`ShotPage`) as JSON at an evidence file name. */
|
|
90
|
-
readonly savePage: (fileName: string, page: ShotPage) => Effect.Effect<void, unknown>;
|
|
91
|
-
/**
|
|
92
|
-
* The checked file behind an upload path as the job gives it; undefined for one that was not
|
|
93
|
-
* checked, which is never sent.
|
|
94
|
-
*/
|
|
95
|
-
readonly uploads?: ((path: string) => UploadSource | undefined) | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* For a case that continues: the ID of the case before it, whose page it starts on. The
|
|
98
|
-
* ledger records it.
|
|
99
|
-
*/
|
|
100
|
-
readonly continuedFrom?: string | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* Told as each step starts: its number, as the ledger numbers steps (0 is the opening
|
|
103
|
-
* navigation), and its action. For showing where a running job is; it must not fail or block.
|
|
104
|
-
*/
|
|
105
|
-
readonly onStep?: ((step: number, kind: Step['action']) => Effect.Effect<void>) | undefined;
|
|
106
|
-
}) => Effect.Effect<CaseEntry>;
|