screw-bugs 0.1.8 → 0.1.10
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 +49 -34
- package/dist/browser-playwright/capture.js +1 -1
- package/dist/browser-playwright/launch.js +27 -10
- package/dist/browser-playwright/page.d.ts +48 -26
- package/dist/browser-playwright/page.js +86 -89
- package/dist/browser-playwright/recorder.d.ts +154 -0
- package/dist/browser-playwright/recorder.js +382 -0
- 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 +2 -2
- 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 -554
- 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 -574
- 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 -47
- package/dist/core/video.js +0 -233
- 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/report/view.js
DELETED
|
@@ -1,702 +0,0 @@
|
|
|
1
|
-
import { DateTime, Duration, Option } from 'effect';
|
|
2
|
-
import { clipBox, drawableAction, drawableShot, MISMATCH_ALLOWED, withStartPage, } from '../core/index.js';
|
|
3
|
-
import { casesOf, framesOf, agentFailures, baseName, judgedCase, judgedLedger, customTimeoutOf, uploadFileOf, } from '../schema/index.js';
|
|
4
|
-
/* What both reports show, worked out once. Plain data: escaping is each format's job. */
|
|
5
|
-
export const statuses = ['passed', 'failed', 'blocked', 'not_verified'];
|
|
6
|
-
export const statusLabel = {
|
|
7
|
-
passed: 'Passed',
|
|
8
|
-
failed: 'Failed',
|
|
9
|
-
blocked: 'Blocked',
|
|
10
|
-
not_verified: 'Not verified',
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* The code's result, shown under the agent's verdict on a case its findings mark failed:
|
|
14
|
-
* `Checks passed`, `Checks: blocked`.
|
|
15
|
-
*/
|
|
16
|
-
export const checksNote = (status) => status === 'passed' ? 'Checks passed' : `Checks: ${statusLabel[status].toLowerCase()}`;
|
|
17
|
-
export const countsOf = (cases) => {
|
|
18
|
-
const counts = { passed: 0, failed: 0, blocked: 0, not_verified: 0 };
|
|
19
|
-
for (const c of cases)
|
|
20
|
-
counts[c.status]++;
|
|
21
|
-
return counts;
|
|
22
|
-
};
|
|
23
|
-
const t = (text) => ({ kind: 'text', text });
|
|
24
|
-
const v = (text) => ({ kind: 'value', text });
|
|
25
|
-
const c = (text) => ({ kind: 'code', text });
|
|
26
|
-
const elementParts = (target) => {
|
|
27
|
-
if (target.role !== undefined)
|
|
28
|
-
return target.name === undefined
|
|
29
|
-
? [t(`the ${target.role}`)]
|
|
30
|
-
: [t(`${target.role} `), v(target.name)];
|
|
31
|
-
if (target.text !== undefined)
|
|
32
|
-
return [t('text '), v(target.text)];
|
|
33
|
-
if (target.label !== undefined)
|
|
34
|
-
return [t('the field labelled '), v(target.label)];
|
|
35
|
-
if (target.alt !== undefined)
|
|
36
|
-
return [t('the image '), v(target.alt)];
|
|
37
|
-
return [t('the element matching '), c(target.css ?? '')];
|
|
38
|
-
};
|
|
39
|
-
/** Where it is, innermost frame first, such as ` in the frame iframe.preview`. */
|
|
40
|
-
const frameParts = (frame) => framesOf(frame)
|
|
41
|
-
.toReversed()
|
|
42
|
-
.flatMap((f) => f.role !== undefined
|
|
43
|
-
? [t(` in the frame ${f.role}`), ...(f.name !== undefined ? [t(' '), v(f.name)] : [])]
|
|
44
|
-
: f.text !== undefined
|
|
45
|
-
? [t(' in the frame with text '), v(f.text)]
|
|
46
|
-
: f.label !== undefined
|
|
47
|
-
? [t(' in the frame labelled '), v(f.label)]
|
|
48
|
-
: f.alt !== undefined
|
|
49
|
-
? [t(' in the frame with alt text '), v(f.alt)]
|
|
50
|
-
: [t(' in the frame '), c(f.css ?? '')]);
|
|
51
|
-
const targetParts = (target) => [
|
|
52
|
-
...elementParts(target),
|
|
53
|
-
...frameParts(target.frame),
|
|
54
|
-
];
|
|
55
|
-
const waitStateParts = {
|
|
56
|
-
visible: ' to be visible',
|
|
57
|
-
hidden: ' to be hidden',
|
|
58
|
-
attached: ' to be in the page',
|
|
59
|
-
detached: ' to be gone from the page',
|
|
60
|
-
};
|
|
61
|
-
/** A step as a sentence, such as Click button “Sign up”. */
|
|
62
|
-
export const stepParts = (step) => {
|
|
63
|
-
switch (step.action) {
|
|
64
|
-
case 'goto':
|
|
65
|
-
return [t('Go to '), c(step.url)];
|
|
66
|
-
case 'reload':
|
|
67
|
-
return [t('Reload the page')];
|
|
68
|
-
case 'click':
|
|
69
|
-
return [t('Click '), ...targetParts(step.target)];
|
|
70
|
-
case 'hover':
|
|
71
|
-
return [t('Hover over '), ...targetParts(step.target)];
|
|
72
|
-
case 'fill':
|
|
73
|
-
return step.value === ''
|
|
74
|
-
? [t('Clear '), ...targetParts(step.target)]
|
|
75
|
-
: [t('Fill '), ...targetParts(step.target), t(' with '), v(step.value)];
|
|
76
|
-
case 'upload':
|
|
77
|
-
return [
|
|
78
|
-
t('Upload '),
|
|
79
|
-
v(step.files.map((file) => baseName(uploadFileOf(file).path)).join(', ')),
|
|
80
|
-
t(' to '),
|
|
81
|
-
...targetParts(step.target),
|
|
82
|
-
];
|
|
83
|
-
case 'press':
|
|
84
|
-
return [t('Press '), c(step.key)];
|
|
85
|
-
case 'expectText':
|
|
86
|
-
return [t('Expect the text '), v(step.text), t(' to appear'), ...frameParts(step.frame)];
|
|
87
|
-
case 'expectNoText':
|
|
88
|
-
return [
|
|
89
|
-
t('Expect the text '),
|
|
90
|
-
v(step.text),
|
|
91
|
-
t(' not to show'),
|
|
92
|
-
...(step.target !== undefined
|
|
93
|
-
? [t(' in '), ...targetParts(step.target)]
|
|
94
|
-
: frameParts(step.frame)),
|
|
95
|
-
];
|
|
96
|
-
case 'waitFor':
|
|
97
|
-
return [
|
|
98
|
-
t('Wait for '),
|
|
99
|
-
...targetParts(step.target),
|
|
100
|
-
t(waitStateParts[step.state ?? 'visible']),
|
|
101
|
-
];
|
|
102
|
-
case 'scroll':
|
|
103
|
-
if (step.target !== undefined)
|
|
104
|
-
return [t('Scroll to '), ...targetParts(step.target)];
|
|
105
|
-
if (step.to !== undefined)
|
|
106
|
-
return step.frame === undefined
|
|
107
|
-
? [t(`Scroll to the ${step.to} of the page`)]
|
|
108
|
-
: [t(`Scroll to the ${step.to}`), ...frameParts(step.frame)];
|
|
109
|
-
return [
|
|
110
|
-
t(`Scroll ${(step.by ?? 0) < 0 ? 'up' : 'down'} ${Math.abs(step.by ?? 0)} px`),
|
|
111
|
-
...frameParts(step.frame),
|
|
112
|
-
];
|
|
113
|
-
case 'expectUrl':
|
|
114
|
-
return [t('Expect the URL to contain '), c(step.includes)];
|
|
115
|
-
case 'expectLink':
|
|
116
|
-
return [
|
|
117
|
-
t('Expect '),
|
|
118
|
-
...targetParts(step.target),
|
|
119
|
-
t(step.match === 'exact' ? ' to link to exactly ' : ' to link to an address with '),
|
|
120
|
-
c(step.href),
|
|
121
|
-
];
|
|
122
|
-
case 'screenshot':
|
|
123
|
-
return [t('Take a screenshot '), v(step.name)];
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
export const stepText = (step) => stepParts(step)
|
|
127
|
-
.map((p) => p.text)
|
|
128
|
-
.join('');
|
|
129
|
-
/** A step's own `timeoutMs` in words, when it is not the default, such as `waited up to 120 s`. */
|
|
130
|
-
export const waitNote = (step, ran) => {
|
|
131
|
-
const ms = customTimeoutOf(step);
|
|
132
|
-
return ms === undefined ? undefined : `${ran ? 'waited' : 'waits'} up to ${ms / 1000} s`;
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* The files an upload step sends, each with its size once it ran and what the job says it is.
|
|
136
|
-
* `sizes` come from the ledger (`StepTiming.files`), by file name.
|
|
137
|
-
*/
|
|
138
|
-
export const uploadNotes = (step, sizes = []) => step.action !== 'upload'
|
|
139
|
-
? []
|
|
140
|
-
: step.files.map((file) => {
|
|
141
|
-
const { path, about, allowMismatch } = uploadFileOf(file);
|
|
142
|
-
const name = baseName(path);
|
|
143
|
-
const size = sizes.find((s) => s.name === name)?.size;
|
|
144
|
-
return {
|
|
145
|
-
name,
|
|
146
|
-
...(size !== undefined ? { size } : {}),
|
|
147
|
-
...(about?.trim() ? { about } : {}),
|
|
148
|
-
...(allowMismatch === true ? { note: MISMATCH_ALLOWED } : {}),
|
|
149
|
-
};
|
|
150
|
-
});
|
|
151
|
-
/** A file size as people read it: `840 B`, `12 KB`, `3.4 MB`. */
|
|
152
|
-
export const formatBytes = (bytes) => bytes < 1024
|
|
153
|
-
? `${bytes} B`
|
|
154
|
-
: bytes < 1024 * 1024
|
|
155
|
-
? `${Math.round(bytes / 1024)} KB`
|
|
156
|
-
: `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
157
|
-
const stateOf = (entry, index) => {
|
|
158
|
-
switch (entry.status) {
|
|
159
|
-
case 'passed':
|
|
160
|
-
return 'done';
|
|
161
|
-
case 'not_verified':
|
|
162
|
-
return 'not-run';
|
|
163
|
-
default:
|
|
164
|
-
if (entry.step === undefined)
|
|
165
|
-
return 'unknown';
|
|
166
|
-
return index < entry.step ? 'done' : index === entry.step ? 'decided' : 'not-run';
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* `evidence/01/04-step3-failed.png`; in older runs `evidence/<case>/step3-failed.png` or
|
|
171
|
-
* `evidence/<case>-step3-failed.png`. The last such file is the one taken when the case stopped.
|
|
172
|
-
*/
|
|
173
|
-
const isFailureShot = (entry, path) => (entry.status === 'failed' || entry.status === 'blocked') &&
|
|
174
|
-
entry.step !== undefined &&
|
|
175
|
-
[`/step${entry.step}-${entry.status}.png`, `-step${entry.step}-${entry.status}.png`].some((ending) => path.endsWith(ending));
|
|
176
|
-
/** The video of `entry`'s session, if the run had sessions. */
|
|
177
|
-
export const videoOf = (bundle, entry) => {
|
|
178
|
-
const session = bundle.ledger.sessions?.find((s) => s.number === (entry.session ?? 1));
|
|
179
|
-
if (session === undefined)
|
|
180
|
-
return undefined;
|
|
181
|
-
return {
|
|
182
|
-
session,
|
|
183
|
-
path: session.video,
|
|
184
|
-
problem: session.videoProblem ??
|
|
185
|
-
(session.video === undefined
|
|
186
|
-
? session.endedAt === undefined
|
|
187
|
-
? 'The session did not end, so its video was not checked.'
|
|
188
|
-
: 'The video file was not saved.'
|
|
189
|
-
: undefined),
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* A case's record with only the boxes that can be drawn where they show on a run on `device`:
|
|
194
|
-
* older runs on a phone measured them in the page's layout (see `boxesDrawable`).
|
|
195
|
-
*/
|
|
196
|
-
const drawableEntry = (entry, device) => ({
|
|
197
|
-
...entry,
|
|
198
|
-
...(entry.shots !== undefined
|
|
199
|
-
? { shots: entry.shots.map((shot) => drawableShot(shot, device)) }
|
|
200
|
-
: {}),
|
|
201
|
-
...(entry.steps !== undefined
|
|
202
|
-
? {
|
|
203
|
-
steps: entry.steps.map((timing) => timing.action === undefined
|
|
204
|
-
? timing
|
|
205
|
-
: { ...timing, action: drawableAction(timing.action, device) }),
|
|
206
|
-
}
|
|
207
|
-
: {}),
|
|
208
|
-
});
|
|
209
|
-
export const caseViews = (bundle) => {
|
|
210
|
-
const specs = new Map(casesOf(bundle.spec).map((spec) => [spec.id, spec]));
|
|
211
|
-
const written = new Map((bundle.findings?.cases ?? []).map((c) => [c.id, c]));
|
|
212
|
-
const failures = agentFailures(bundle.findings);
|
|
213
|
-
return bundle.ledger.cases.map((recorded) => {
|
|
214
|
-
// Steps and screenshots are as the code ran them; the status is the one results show.
|
|
215
|
-
const checked = drawableEntry(recorded, bundle.device.kind);
|
|
216
|
-
const { checkStatus, agentFailed, ...entry } = judgedCase(checked, failures);
|
|
217
|
-
const spec = specs.get(entry.id);
|
|
218
|
-
const steps = spec ? withStartPage(spec, bundle.spec.url) : [];
|
|
219
|
-
const offset = spec ? steps.length - spec.steps.length : 0;
|
|
220
|
-
const records = new Map((entry.shots ?? []).map((shot) => [shot.path, shot]));
|
|
221
|
-
const timings = new Map((entry.steps ?? []).map((timing) => [timing.index, timing]));
|
|
222
|
-
const shots = entry.evidence.map((path) => {
|
|
223
|
-
const shot = records.get(path);
|
|
224
|
-
return {
|
|
225
|
-
path,
|
|
226
|
-
shot,
|
|
227
|
-
marks: (shot && bundle.marks?.[shot.id]) ?? [],
|
|
228
|
-
elements: (shot && bundle.elements?.[shot.id]) ?? [],
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
const failurePath = entry.evidence.findLast((path) => records.get(path)?.kind === 'failure' || isFailureShot(checked, path));
|
|
232
|
-
return {
|
|
233
|
-
entry,
|
|
234
|
-
spec,
|
|
235
|
-
steps: steps.map((step, i) => ({
|
|
236
|
-
index: i + 1 - offset,
|
|
237
|
-
step,
|
|
238
|
-
implicit: i < offset,
|
|
239
|
-
state: stateOf(checked, i + 1 - offset),
|
|
240
|
-
timing: timings.get(i + 1 - offset),
|
|
241
|
-
})),
|
|
242
|
-
failureShot: shots.find((s) => s.path === failurePath),
|
|
243
|
-
otherShots: shots.filter((s) => s.path !== failurePath),
|
|
244
|
-
findings: written.get(entry.id),
|
|
245
|
-
checkStatus,
|
|
246
|
-
agentFailed,
|
|
247
|
-
video: videoOf(bundle, entry),
|
|
248
|
-
};
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
/**
|
|
252
|
-
* `3 areas not tested`, when the agent's write-up names any: next to the counts, so passing cases
|
|
253
|
-
* are not read as everything working.
|
|
254
|
-
*/
|
|
255
|
-
export const notTestedCount = (bundle) => {
|
|
256
|
-
const n = bundle.findings?.notTested?.length ?? 0;
|
|
257
|
-
return n === 0 ? undefined : `${n} ${n === 1 ? 'area' : 'areas'} not tested`;
|
|
258
|
-
};
|
|
259
|
-
const severityRank = { high: 0, medium: 1, low: 2 };
|
|
260
|
-
/** The agent's fixes, most severe first; the agent's own order within a severity. */
|
|
261
|
-
export const fixesOf = (bundle) => (bundle.findings?.fixes ?? []).toSorted((a, b) => severityRank[a.severity] - severityRank[b.severity]);
|
|
262
|
-
export const severityLabel = {
|
|
263
|
-
high: 'High',
|
|
264
|
-
medium: 'Medium',
|
|
265
|
-
low: 'Low',
|
|
266
|
-
};
|
|
267
|
-
/**
|
|
268
|
-
* `0:07.3`, `1:05.0`, `1:02:03.4`: a timecode as people read it, from ms, to the nearest tenth of
|
|
269
|
-
* a second (so 59.96 s is `1:00.0`).
|
|
270
|
-
*/
|
|
271
|
-
export const formatTimecode = (ms) => {
|
|
272
|
-
const tenths = Math.max(0, Math.round(ms / 100));
|
|
273
|
-
const total = Math.floor(tenths / 10);
|
|
274
|
-
const [h, m, s] = [Math.floor(total / 3600), Math.floor((total % 3600) / 60), total % 60];
|
|
275
|
-
const seconds = `${pad(s)}.${tenths % 10}`;
|
|
276
|
-
return h > 0 ? `${h}:${pad(m)}:${seconds}` : `${m}:${seconds}`;
|
|
277
|
-
};
|
|
278
|
-
/** A time to seek to, for a media fragment (`#t=6.25`) and the page's script: seconds, to the ms. */
|
|
279
|
-
export const fragmentSeconds = (ms) => String(Math.max(0, Math.round(ms)) / 1000);
|
|
280
|
-
/** The room kept around the boxes at `frame`, in CSS pixels: beside them, and above and below
|
|
281
|
-
* them for a label (its height, the gap and the box's line). */
|
|
282
|
-
const ROOM_SIDE = 12;
|
|
283
|
-
const ROOM_LABEL = 34;
|
|
284
|
-
/** How far a crop zooms in on boxes that are readable without more: it keeps their surroundings. */
|
|
285
|
-
const ZOOM = 2.5;
|
|
286
|
-
/**
|
|
287
|
-
* The part of a `width` × `height` screenshot a frame shows, zoomed in on `boxes`: all of them
|
|
288
|
-
* with room around (for their lines and labels), at least a `1 / maxZoom` share of the image's
|
|
289
|
-
* width, in the image's shape but no taller than `minShape` (so a full-page screenshot gives a
|
|
290
|
-
* strip of the page). Undefined when there are no boxes or the part would be most of the image.
|
|
291
|
-
*/
|
|
292
|
-
export const cropAround = (width, height, boxes, { frame, maxZoom, readable, minShape } = { frame: 300, maxZoom: 2.5, minShape: 1.6 }) => {
|
|
293
|
-
if (boxes.length === 0 || width <= 0 || height <= 0)
|
|
294
|
-
return undefined;
|
|
295
|
-
const shown = boxes.flatMap((b) => {
|
|
296
|
-
const x = Math.max(0, b.x);
|
|
297
|
-
const y = Math.max(0, b.y);
|
|
298
|
-
const w = Math.min(width, b.x + b.width) - x;
|
|
299
|
-
const h = Math.min(height, b.y + b.height) - y;
|
|
300
|
-
return w > 0 && h > 0 ? [{ box: { x, y, width: w, height: h }, content: b.content }] : [];
|
|
301
|
-
});
|
|
302
|
-
if (shown.length === 0)
|
|
303
|
-
return undefined;
|
|
304
|
-
// Rooms as shares of the crop's width, as they are CSS pixels at `frame`.
|
|
305
|
-
const [side, label] = [ROOM_SIDE / frame, ROOM_LABEL / frame];
|
|
306
|
-
// The widest crop at which the shortest box is still `readable` tall; a box wider than fits in
|
|
307
|
-
// it with its room is cut to that width around the middle of its content, kept inside it.
|
|
308
|
-
const legible = readable === undefined
|
|
309
|
-
? Infinity
|
|
310
|
-
: (frame * Math.min(...shown.map(({ box }) => box.height))) / readable;
|
|
311
|
-
const cap = legible * (1 - 2 * side);
|
|
312
|
-
const spans = shown.map(({ box, content }) => {
|
|
313
|
-
const end = box.x + box.width;
|
|
314
|
-
const inside = content && clipBox(content, box);
|
|
315
|
-
if (box.width <= cap || inside === undefined || inside.width <= 0)
|
|
316
|
-
return [box.x, end];
|
|
317
|
-
const at = Math.min(Math.max(box.x, inside.x + inside.width / 2 - cap / 2), end - cap);
|
|
318
|
-
return [at, at + cap];
|
|
319
|
-
});
|
|
320
|
-
const left = Math.min(...spans.map(([start]) => start));
|
|
321
|
-
const right = Math.max(...spans.map(([, end]) => end));
|
|
322
|
-
const top = Math.min(...shown.map(({ box }) => box.y));
|
|
323
|
-
const bottom = Math.max(...shown.map(({ box }) => box.y + box.height));
|
|
324
|
-
const shape = Math.max(width / height, minShape);
|
|
325
|
-
const least = Math.max(width / maxZoom, Math.min(legible, width / ZOOM));
|
|
326
|
-
let w = Math.min(width, Math.max(least, (right - left) / (1 - 2 * side)));
|
|
327
|
-
let h = w / shape;
|
|
328
|
-
if (h < bottom - top + 2 * label * w) {
|
|
329
|
-
// Taller boxes: as tall as they need with their rooms, and as wide as that shape gives.
|
|
330
|
-
w = Math.min(width, Math.max(w, (shape * (bottom - top)) / Math.max(0.2, 1 - 2 * label * shape)));
|
|
331
|
-
h = Math.max(w / shape, bottom - top + 2 * label * w);
|
|
332
|
-
}
|
|
333
|
-
[w, h] = [Math.round(w), Math.round(Math.min(height, h))];
|
|
334
|
-
if (w >= width * 0.9 && h >= height * 0.9)
|
|
335
|
-
return undefined;
|
|
336
|
-
const clamp = (at, size, of) => Math.round(Math.min(Math.max(0, at), of - size));
|
|
337
|
-
return {
|
|
338
|
-
x: clamp((left + right) / 2 - w / 2, w, width),
|
|
339
|
-
y: clamp((top + bottom) / 2 - h / 2, h, height),
|
|
340
|
-
width: w,
|
|
341
|
-
height: h,
|
|
342
|
-
};
|
|
343
|
-
};
|
|
344
|
-
/**
|
|
345
|
-
* How far a frame zooms in on its boxes: as wide as the case or wider, and on a narrow screen (or
|
|
346
|
-
* in the grid of thumbnails), where it zooms in more so the marked element stays readable. A
|
|
347
|
-
* figure whose two crops differ has a frame for each, and its width picks one; `CROP_NARROW.frame`
|
|
348
|
-
* is also the narrowest a frame is shown.
|
|
349
|
-
*/
|
|
350
|
-
export const CROP_WIDE = { frame: 560, maxZoom: 2.5, readable: 12, minShape: 1.6 };
|
|
351
|
-
export const CROP_NARROW = { frame: 250, maxZoom: 6, readable: 16, minShape: 1.2 };
|
|
352
|
-
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
353
|
-
const pad = (n) => String(n).padStart(2, '0');
|
|
354
|
-
/** A timestamp from the ledger, parsed; the clock is never read here. */
|
|
355
|
-
const parse = (iso) => DateTime.make(iso).pipe(Option.map(DateTime.toUtc));
|
|
356
|
-
/** `29 Oct 2026, 10:48:57 UTC`: the same for every reader, wherever the report is opened. */
|
|
357
|
-
export const formatTime = (iso) => Option.match(parse(iso), {
|
|
358
|
-
onNone: () => iso,
|
|
359
|
-
onSome: (time) => {
|
|
360
|
-
const { day, month, year, hour, minute, second } = DateTime.toPartsUtc(time);
|
|
361
|
-
return `${day} ${months[month - 1]} ${year}, ${pad(hour)}:${pad(minute)}:${pad(second)} UTC`;
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
/** `850 ms`, `4.2 s`, `3 min 05 s`; undefined while the run has not finished. */
|
|
365
|
-
export const durationOf = (startedAt, finishedAt) => {
|
|
366
|
-
if (finishedAt === undefined)
|
|
367
|
-
return undefined;
|
|
368
|
-
const [start, end] = [parse(startedAt), parse(finishedAt)];
|
|
369
|
-
if (Option.isNone(start) || Option.isNone(end))
|
|
370
|
-
return undefined;
|
|
371
|
-
const ms = Duration.toMillis(DateTime.distance(start.value, end.value));
|
|
372
|
-
if (ms < 0)
|
|
373
|
-
return undefined;
|
|
374
|
-
if (ms < 1000)
|
|
375
|
-
return `${ms} ms`;
|
|
376
|
-
if (ms < 60_000)
|
|
377
|
-
return `${(ms / 1000).toFixed(1)} s`;
|
|
378
|
-
const seconds = Math.round(ms / 1000);
|
|
379
|
-
return `${Math.floor(seconds / 60)} min ${pad(seconds % 60)} s`;
|
|
380
|
-
};
|
|
381
|
-
/* ---------------------------------------------------------------------------------------------
|
|
382
|
-
* The players of both pages: one video, a time line per session, and what the run recorded at
|
|
383
|
-
* each moment of it. Everything here comes from the ledger and the saved page states; where the
|
|
384
|
-
* run recorded nothing, nothing is said.
|
|
385
|
-
* ------------------------------------------------------------------------------------------- */
|
|
386
|
-
/** `0:13`, `1:05`, `1:02:03`: a time on the player's clock, to the second. */
|
|
387
|
-
export const formatClock = (ms) => {
|
|
388
|
-
const total = Math.max(0, Math.floor(ms / 1000));
|
|
389
|
-
const [h, m, s] = [Math.floor(total / 3600), Math.floor((total % 3600) / 60), total % 60];
|
|
390
|
-
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
|
|
391
|
-
};
|
|
392
|
-
/**
|
|
393
|
-
* `Nov 4, 2026 · 23:50 UTC`: when a run started, the same for every reader, as the pages say it
|
|
394
|
-
* without script (with it, their script says it in the reader's own time, in the same form).
|
|
395
|
-
*/
|
|
396
|
-
export const formatDate = (iso) => Option.match(parse(iso), {
|
|
397
|
-
onNone: () => iso,
|
|
398
|
-
onSome: (time) => {
|
|
399
|
-
const { day, month, year, hour, minute } = DateTime.toPartsUtc(time);
|
|
400
|
-
return `${months[month - 1]} ${day}, ${year} · ${pad(hour)}:${pad(minute)} UTC`;
|
|
401
|
-
},
|
|
402
|
-
});
|
|
403
|
-
/** How long the run took, in ms; undefined while it has not finished. */
|
|
404
|
-
export const runMs = (bundle) => {
|
|
405
|
-
if (bundle.finishedAt === undefined)
|
|
406
|
-
return undefined;
|
|
407
|
-
const [start, end] = [parse(bundle.startedAt), parse(bundle.finishedAt)];
|
|
408
|
-
if (Option.isNone(start) || Option.isNone(end))
|
|
409
|
-
return undefined;
|
|
410
|
-
const ms = Duration.toMillis(DateTime.distance(start.value, end.value));
|
|
411
|
-
return ms < 0 ? undefined : ms;
|
|
412
|
-
};
|
|
413
|
-
/** An address as the player's URL field shows it: without `https://`, cut to `max` characters. */
|
|
414
|
-
export const displayUrl = (url, max = 80) => {
|
|
415
|
-
const bare = url.replace(/^https?:\/\//, '');
|
|
416
|
-
return bare.length <= max ? bare : `${bare.slice(0, max - 1)}…`;
|
|
417
|
-
};
|
|
418
|
-
/**
|
|
419
|
-
* The browser the run recorded, in words such as `Chrome 131` or `Chromium 131`; undefined for a
|
|
420
|
-
* run that recorded none, which shows no browser at all.
|
|
421
|
-
*/
|
|
422
|
-
export const browserWords = (browser) => {
|
|
423
|
-
if (browser === undefined)
|
|
424
|
-
return undefined;
|
|
425
|
-
const version = browser.version.trim();
|
|
426
|
-
const major = /^\d+/.exec(version)?.[0] ?? version;
|
|
427
|
-
const channel = browser.channel?.toLowerCase() ?? '';
|
|
428
|
-
const type = browser.type.toLowerCase();
|
|
429
|
-
const [name, chromeLogo] = type !== 'chromium'
|
|
430
|
-
? [type === 'webkit' ? 'WebKit' : `${type.charAt(0).toUpperCase()}${type.slice(1)}`, false]
|
|
431
|
-
: channel.startsWith('msedge')
|
|
432
|
-
? ['Edge', false]
|
|
433
|
-
: channel.startsWith('chrome') && !channel.startsWith('chromium')
|
|
434
|
-
? ['Chrome', true]
|
|
435
|
-
: ['Chromium', true];
|
|
436
|
-
return { text: major ? `${name} ${major}` : name, chromeLogo };
|
|
437
|
-
};
|
|
438
|
-
/** The device in a word or two for the meta row: its own label when that says more. */
|
|
439
|
-
export const deviceWords = (device) => {
|
|
440
|
-
const generic = device.kind === 'mobile' ? 'phone' : 'desktop';
|
|
441
|
-
return ['desktop', 'mobile', 'phone'].includes(device.label.trim().toLowerCase())
|
|
442
|
-
? generic
|
|
443
|
-
: device.label;
|
|
444
|
-
};
|
|
445
|
-
const sessionNumber = (entry) => entry.session ?? 1;
|
|
446
|
-
/** How long a session's video is, in ms: as the file gives it, else as recorded, else as far as
|
|
447
|
-
* anything in it was timed. Undefined when nothing in it was. */
|
|
448
|
-
export const sessionLength = (bundle, session) => {
|
|
449
|
-
const record = bundle.ledger.sessions?.find((s) => s.number === session);
|
|
450
|
-
if (record?.videoDurationMs !== undefined && record.videoDurationMs > 0)
|
|
451
|
-
return record.videoDurationMs;
|
|
452
|
-
if (record?.durationMs !== undefined && record.durationMs > 0)
|
|
453
|
-
return record.durationMs;
|
|
454
|
-
const ends = bundle.ledger.cases
|
|
455
|
-
.filter((c) => sessionNumber(c) === session)
|
|
456
|
-
.flatMap((c) => [
|
|
457
|
-
...(c.endMs !== undefined ? [c.endMs] : []),
|
|
458
|
-
...(c.steps ?? []).map((s) => s.endMs),
|
|
459
|
-
]);
|
|
460
|
-
return ends.length === 0 ? undefined : Math.max(...ends);
|
|
461
|
-
};
|
|
462
|
-
/**
|
|
463
|
-
* Each case's place on its session's video, by case ID: from its start to its end, or, for a case
|
|
464
|
-
* whose end was not recorded (a run still going), to its last step's end, else the next case's
|
|
465
|
-
* start, else the end of the video. Cases whose start was not recorded have none.
|
|
466
|
-
*/
|
|
467
|
-
export const caseSpans = (bundle) => {
|
|
468
|
-
const cases = bundle.ledger.cases;
|
|
469
|
-
const spans = new Map();
|
|
470
|
-
cases.forEach((entry, i) => {
|
|
471
|
-
if (entry.startMs === undefined)
|
|
472
|
-
return;
|
|
473
|
-
const session = sessionNumber(entry);
|
|
474
|
-
const next = cases
|
|
475
|
-
.slice(i + 1)
|
|
476
|
-
.find((c) => sessionNumber(c) === session && c.startMs !== undefined)?.startMs;
|
|
477
|
-
const lastStep = (entry.steps ?? []).reduce((end, s) => (end === undefined ? s.endMs : Math.max(end, s.endMs)), undefined);
|
|
478
|
-
const end = entry.endMs ?? lastStep ?? next ?? sessionLength(bundle, session) ?? entry.startMs;
|
|
479
|
-
spans.set(entry.id, { session, startMs: entry.startMs, endMs: Math.max(entry.startMs, end) });
|
|
480
|
-
});
|
|
481
|
-
return spans;
|
|
482
|
-
};
|
|
483
|
-
const resolved = (url, base) => URL.canParse(url, base) ? new URL(url, base).href : url;
|
|
484
|
-
/**
|
|
485
|
-
* Every moment the run recorded the page's address, in time order: each screenshot's saved page
|
|
486
|
-
* state (when it was taken), each `goto` step that ran (when it ended, at the address it opened),
|
|
487
|
-
* and the page when each case ended. Between them the address is the last one recorded; before
|
|
488
|
-
* the first, unknown.
|
|
489
|
-
*/
|
|
490
|
-
export const urlTimeline = (bundle, views = caseViews(bundle)) => {
|
|
491
|
-
const urls = bundle.urls ?? {};
|
|
492
|
-
const points = views.flatMap(({ entry, steps }) => {
|
|
493
|
-
const session = sessionNumber(entry);
|
|
494
|
-
return [
|
|
495
|
-
...steps.flatMap((s) => s.step.action === 'goto' && s.state === 'done' && s.timing !== undefined
|
|
496
|
-
? [{ session, ms: s.timing.endMs, url: resolved(s.step.url, bundle.spec.url) }]
|
|
497
|
-
: []),
|
|
498
|
-
...(entry.shots ?? []).flatMap((shot) => {
|
|
499
|
-
const url = urls[shot.id];
|
|
500
|
-
return url !== undefined && shot.atMs !== undefined
|
|
501
|
-
? [{ session, ms: shot.atMs, url }]
|
|
502
|
-
: [];
|
|
503
|
-
}),
|
|
504
|
-
...(entry.facts?.url && entry.endMs !== undefined
|
|
505
|
-
? [{ session, ms: entry.endMs, url: entry.facts.url }]
|
|
506
|
-
: []),
|
|
507
|
-
];
|
|
508
|
-
});
|
|
509
|
-
return points.toSorted((a, b) => a.session - b.session || a.ms - b.ms);
|
|
510
|
-
};
|
|
511
|
-
/** The address at `ms` into a session's video: the last one recorded by then, if any. */
|
|
512
|
-
export const urlAt = (points, session, ms) => points.findLast((p) => p.session === session && p.ms <= ms)?.url;
|
|
513
|
-
/** Idle stretches shorter than this are played: skipping them would only make the video jump. */
|
|
514
|
-
export const IDLE_MIN_MS = 1500;
|
|
515
|
-
/** How much of an idle stretch is still played at either end, so a step's result can be seen. */
|
|
516
|
-
export const IDLE_MARGIN_MS = 300;
|
|
517
|
-
/**
|
|
518
|
-
* Around a recorded action (a press of the mouse or a key) the video is never idle, even where
|
|
519
|
-
* it stands still: the walkthrough's cursor glides to it before (`GLIDE_S`) and its ripple and
|
|
520
|
-
* label show after.
|
|
521
|
-
*/
|
|
522
|
-
export const ACTION_BEFORE_MS = 600;
|
|
523
|
-
export const ACTION_AFTER_MS = 1500;
|
|
524
|
-
/** `spans` with every part `busy` covers taken out; both in time order or not. */
|
|
525
|
-
const without = (spans, busy) => busy.reduce((left, [b0, b1]) => left.flatMap(([a0, a1]) => b1 <= a0 || b0 >= a1
|
|
526
|
-
? [[a0, a1]]
|
|
527
|
-
: [...(b0 > a0 ? [[a0, b0]] : []), ...(b1 < a1 ? [[b1, a1]] : [])]), spans);
|
|
528
|
-
/**
|
|
529
|
-
* The stretches of each session's video where nothing happened, at least `IDLE_MIN_MS` long once
|
|
530
|
-
* `IDLE_MARGIN_MS` is kept at either end (none at the very start of the video). Where the run
|
|
531
|
-
* measured its video (`Session.still`), they are where its picture stood still, even while a step
|
|
532
|
-
* waited, except around each recorded action (`ACTION_BEFORE_MS`, `ACTION_AFTER_MS`; the whole
|
|
533
|
-
* step for an action recorded without a time, whose label shows while its step plays). For an
|
|
534
|
-
* older run they are where no step ran: before the first step, between steps and after the last
|
|
535
|
-
* one (to the end of the video, when its length is known); there a step that waited is not idle,
|
|
536
|
-
* since what it waited for may show at any moment.
|
|
537
|
-
*/
|
|
538
|
-
export const idleStretches = (bundle) => {
|
|
539
|
-
const steps = new Map();
|
|
540
|
-
const actions = new Map();
|
|
541
|
-
for (const entry of bundle.ledger.cases) {
|
|
542
|
-
const session = sessionNumber(entry);
|
|
543
|
-
for (const s of entry.steps ?? []) {
|
|
544
|
-
steps.set(session, [
|
|
545
|
-
...(steps.get(session) ?? []),
|
|
546
|
-
[s.startMs, Math.max(s.startMs, s.endMs)],
|
|
547
|
-
]);
|
|
548
|
-
if (s.action === undefined)
|
|
549
|
-
continue;
|
|
550
|
-
const at = s.action.atMs;
|
|
551
|
-
// An action whose input was not seen (a fill, a frame's click) is labelled while its step
|
|
552
|
-
// plays: all of that step is kept.
|
|
553
|
-
const busy = at !== undefined
|
|
554
|
-
? [at - ACTION_BEFORE_MS, at + ACTION_AFTER_MS]
|
|
555
|
-
: [s.startMs, Math.max(s.startMs, s.endMs)];
|
|
556
|
-
actions.set(session, [...(actions.get(session) ?? []), busy]);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
const measured = new Map((bundle.ledger.sessions ?? []).flatMap((s) => s.still !== undefined ? [[s.number, s.still]] : []));
|
|
560
|
-
const sessions = [...new Set([...steps.keys(), ...measured.keys()])].toSorted((a, b) => a - b);
|
|
561
|
-
return sessions.flatMap((session) => {
|
|
562
|
-
const still = measured.get(session);
|
|
563
|
-
const gaps = still !== undefined
|
|
564
|
-
? without(still.map((s) => [s.fromMs, s.toMs]), actions.get(session) ?? [])
|
|
565
|
-
: (() => {
|
|
566
|
-
const sorted = (steps.get(session) ?? []).toSorted((a, b) => a[0] - b[0]);
|
|
567
|
-
const found = [];
|
|
568
|
-
let at = 0;
|
|
569
|
-
for (const [start, end] of sorted) {
|
|
570
|
-
if (start > at)
|
|
571
|
-
found.push([at, start]);
|
|
572
|
-
at = Math.max(at, end);
|
|
573
|
-
}
|
|
574
|
-
const length = sessionLength(bundle, session);
|
|
575
|
-
if (length !== undefined && length > at)
|
|
576
|
-
found.push([at, length]);
|
|
577
|
-
return found;
|
|
578
|
-
})();
|
|
579
|
-
return gaps.flatMap(([from, to]) => {
|
|
580
|
-
const [a, b] = [from <= 0 ? 0 : from + IDLE_MARGIN_MS, to - IDLE_MARGIN_MS];
|
|
581
|
-
return b - a >= IDLE_MIN_MS ? [{ session, fromMs: a, toMs: b }] : [];
|
|
582
|
-
});
|
|
583
|
-
});
|
|
584
|
-
};
|
|
585
|
-
const shotName = (view, shot) => {
|
|
586
|
-
const name = view.entry.evidenceNames?.[shot.path] ?? shot.shot?.name;
|
|
587
|
-
if (name !== undefined)
|
|
588
|
-
return name;
|
|
589
|
-
// Older runs have no names; their file names were `<name>.png` or `<case>-<name>.png`.
|
|
590
|
-
const file = shot.path.split('/').at(-1) ?? shot.path;
|
|
591
|
-
const prefix = `${view.entry.id}-`;
|
|
592
|
-
return (file.startsWith(prefix) ? file.slice(prefix.length) : file).replace(/\.png$/, '');
|
|
593
|
-
};
|
|
594
|
-
/** Every screenshot of a case, in the order they were taken, with what each is. */
|
|
595
|
-
export const caseShots = (view) => {
|
|
596
|
-
const all = view.entry.evidence.flatMap((path) => {
|
|
597
|
-
const shot = view.failureShot?.path === path
|
|
598
|
-
? view.failureShot
|
|
599
|
-
: view.otherShots.find((s) => s.path === path);
|
|
600
|
-
return shot === undefined ? [] : [shot];
|
|
601
|
-
});
|
|
602
|
-
const actual = view.entry.status === 'passed' ? undefined : (view.failureShot ?? all.at(-1));
|
|
603
|
-
const counted = view.steps.filter((s) => !s.implicit).length;
|
|
604
|
-
return all.map((shot) => {
|
|
605
|
-
const marks = shot.marks;
|
|
606
|
-
const expected = marks.some((m) => m.mark === 'green') && !marks.some((m) => m.mark === 'red');
|
|
607
|
-
const index = shot.shot?.step;
|
|
608
|
-
return {
|
|
609
|
-
shot,
|
|
610
|
-
role: shot === actual ? 'actual' : expected ? 'expected' : 'shot',
|
|
611
|
-
name: shotName(view, shot),
|
|
612
|
-
step: index === undefined
|
|
613
|
-
? undefined
|
|
614
|
-
: index === 0
|
|
615
|
-
? 'Opening page'
|
|
616
|
-
: counted > 0 && index <= counted
|
|
617
|
-
? `Step ${index} of ${counted}`
|
|
618
|
-
: `Step ${index}`,
|
|
619
|
-
};
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
/**
|
|
623
|
-
* What a case's card shows of its screenshots: for a case that did not pass, the page when it
|
|
624
|
-
* stopped (`Actual`), beside an `Expected` one where the agent marked one so; for one that passed,
|
|
625
|
-
* up to two the agent marked (it saw something there), else up to two small ones. `more` counts
|
|
626
|
-
* the rest, which the screenshot viewer steps through.
|
|
627
|
-
*/
|
|
628
|
-
export const cardShots = (shots) => {
|
|
629
|
-
const actual = shots.find((s) => s.role === 'actual');
|
|
630
|
-
if (actual !== undefined) {
|
|
631
|
-
const expected = shots.find((s) => s.role === 'expected');
|
|
632
|
-
const large = expected === undefined ? [actual] : [expected, actual];
|
|
633
|
-
return { large, small: [], more: shots.length - large.length };
|
|
634
|
-
}
|
|
635
|
-
const marked = shots.filter((s) => s.shot.marks.some((m) => m.box !== undefined)).slice(0, 2);
|
|
636
|
-
if (marked.length > 0)
|
|
637
|
-
return { large: marked, small: [], more: shots.length - marked.length };
|
|
638
|
-
const small = shots.slice(0, 2);
|
|
639
|
-
return { large: [], small, more: shots.length - small.length };
|
|
640
|
-
};
|
|
641
|
-
/**
|
|
642
|
-
* The report's heading: the name the job gave the run; else the app's own page title as the run
|
|
643
|
-
* recorded it (that of the first case, in run order, whose page facts at its end have one); else
|
|
644
|
-
* the target's host. Only what the job said or the run recorded, never a guess.
|
|
645
|
-
*/
|
|
646
|
-
export const reportHeading = (bundle) => {
|
|
647
|
-
const given = bundle.spec.title?.trim();
|
|
648
|
-
if (given)
|
|
649
|
-
return given;
|
|
650
|
-
for (const entry of bundle.ledger.cases) {
|
|
651
|
-
const recorded = entry.facts?.title?.trim();
|
|
652
|
-
if (recorded)
|
|
653
|
-
return recorded;
|
|
654
|
-
}
|
|
655
|
-
const { url } = bundle.spec;
|
|
656
|
-
return URL.canParse(url) ? new URL(url).host : url;
|
|
657
|
-
};
|
|
658
|
-
/**
|
|
659
|
-
* The counts in a sentence. With areas the agent did not test, a run whose cases all passed says
|
|
660
|
-
* `7 of 7 cases passed · 3 areas not tested`, never that all passed.
|
|
661
|
-
*/
|
|
662
|
-
export const verdictOf = (bundle) => {
|
|
663
|
-
const { cases, state } = judgedLedger(bundle.ledger, bundle.findings);
|
|
664
|
-
const passed = cases.filter((c) => c.status === 'passed').length;
|
|
665
|
-
if (state !== 'finished' && state !== 'errored')
|
|
666
|
-
return `In progress: ${passed} of ${cases.length} passed so far`;
|
|
667
|
-
const gaps = notTestedCount(bundle);
|
|
668
|
-
if (state === 'finished' && passed === cases.length && gaps === undefined)
|
|
669
|
-
return cases.length === 1 ? 'The case passed' : `All ${cases.length} cases passed`;
|
|
670
|
-
return `${passed} of ${cases.length} ${cases.length === 1 ? 'case' : 'cases'} passed${gaps ? ` · ${gaps}` : ''}`;
|
|
671
|
-
};
|
|
672
|
-
/** `2 failed`, `1 not verified`: a count of cases with a status, as the filters say it. */
|
|
673
|
-
export const countWords = (status, n) => `${n} ${statusLabel[status].toLowerCase()}`;
|
|
674
|
-
export const evaluationOf = (bundle) => {
|
|
675
|
-
const counts = countsOf(judgedLedger(bundle.ledger, bundle.findings).cases);
|
|
676
|
-
const line = statuses
|
|
677
|
-
.filter((s) => s !== 'passed' && counts[s] > 0)
|
|
678
|
-
.map((s) => countWords(s, counts[s]))
|
|
679
|
-
.concat(counts.passed > 0 ? [countWords('passed', counts.passed)] : []);
|
|
680
|
-
const findings = bundle.findings;
|
|
681
|
-
if (findings === undefined)
|
|
682
|
-
return {
|
|
683
|
-
verdict: verdictOf(bundle),
|
|
684
|
-
byAgent: false,
|
|
685
|
-
counts: line.length > 0 ? `${line.join(', ')}.` : 'No cases ran.',
|
|
686
|
-
issues: [],
|
|
687
|
-
fixFirst: undefined,
|
|
688
|
-
};
|
|
689
|
-
const first = findings.fixes[0];
|
|
690
|
-
return {
|
|
691
|
-
verdict: findings.headline,
|
|
692
|
-
byAgent: true,
|
|
693
|
-
counts: verdictOf(bundle),
|
|
694
|
-
issues: fixesOf(bundle).map(({ title, why, severity, caseIds }) => ({
|
|
695
|
-
title,
|
|
696
|
-
why,
|
|
697
|
-
severity,
|
|
698
|
-
caseIds,
|
|
699
|
-
})),
|
|
700
|
-
fixFirst: first === undefined ? undefined : { title: first.title, why: first.why },
|
|
701
|
-
};
|
|
702
|
-
};
|