screw-bugs 0.1.6 → 0.1.8
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 +86 -16
- package/dist/browser-playwright/launch.d.ts +4 -2
- package/dist/browser-playwright/launch.js +8 -1
- package/dist/browser-playwright/page.d.ts +2 -2
- package/dist/browser-playwright/page.js +15 -2
- package/dist/browser-playwright/still.d.ts +12 -0
- package/dist/browser-playwright/still.js +51 -0
- package/dist/build-info.json +3 -3
- package/dist/cli/app.d.ts +1 -1
- package/dist/cli/commands.js +57 -12
- package/dist/cli/mcp.d.ts +11 -4
- package/dist/cli/mcp.js +86 -23
- package/dist/cli/operations.d.ts +30 -2
- package/dist/cli/operations.js +126 -20
- package/dist/cli/report-links.js +2 -2
- package/dist/cli/report-server.d.ts +41 -9
- package/dist/cli/report-server.js +139 -23
- package/dist/cli/share.d.ts +71 -4
- package/dist/cli/share.js +549 -118
- package/dist/cli/sign-in.d.ts +22 -10
- package/dist/cli/sign-in.js +23 -23
- package/dist/core/engine.js +67 -17
- package/dist/core/liveness.js +3 -1
- package/dist/core/services.d.ts +30 -5
- package/dist/core/share.d.ts +31 -0
- package/dist/core/share.js +139 -0
- package/dist/core/steps.d.ts +5 -0
- package/dist/core/steps.js +15 -1
- package/dist/core/video.d.ts +31 -0
- package/dist/core/video.js +132 -0
- package/dist/report/html.d.ts +4 -2
- package/dist/report/html.js +45 -13
- package/dist/report/icons.d.ts +3 -0
- package/dist/report/icons.js +5 -1
- package/dist/report/index.d.ts +3 -1
- package/dist/report/index.js +3 -1
- package/dist/report/live.d.ts +7 -0
- package/dist/report/live.js +135 -0
- package/dist/report/menu-bar.d.ts +3 -3
- package/dist/report/menu-bar.js +4 -4
- package/dist/report/player.d.ts +3 -3
- package/dist/report/player.js +3 -3
- package/dist/report/share-page.d.ts +48 -0
- package/dist/report/share-page.js +291 -0
- package/dist/report/styles.d.ts +2 -0
- package/dist/report/styles.js +2 -2
- package/dist/report/view.d.ts +16 -5
- package/dist/report/view.js +60 -24
- package/dist/report/walkthrough.d.ts +7 -3
- package/dist/report/walkthrough.js +21 -8
- package/dist/schema/accounts.js +10 -1
- package/dist/schema/evidence.d.ts +30 -8
- package/dist/schema/evidence.js +17 -4
- package/dist/schema/findings.js +1 -1
- package/dist/schema/job.d.ts +205 -65
- package/dist/schema/job.js +63 -11
- package/dist/schema/ledger.d.ts +88 -16
- package/dist/schema/ledger.js +36 -0
- package/dist/schema/share.d.ts +17 -0
- package/dist/schema/share.js +22 -0
- package/package.json +1 -1
package/dist/cli/sign-in.d.ts
CHANGED
|
@@ -9,10 +9,11 @@ export declare const FRAME_WAIT_MS = 15000;
|
|
|
9
9
|
/** How long fetching the app's icon may take in all; the sign-in opens without it after. */
|
|
10
10
|
export declare const SIGN_IN_ICON_TIMEOUT: Duration.Duration;
|
|
11
11
|
/**
|
|
12
|
-
* `SCREW_BUGS_SIGN_IN_HOST`:
|
|
13
|
-
* 127.0.0.1 unless set; set it to this machine's
|
|
12
|
+
* `SCREW_BUGS_SIGN_IN_HOST`: where the sign-in server listens, and the host in its link.
|
|
13
|
+
* 127.0.0.1 unless set; set it to this machine's MagicDNS name or tailnet IP to sign in from
|
|
14
|
+
* another device. Read as `SCREW_BUGS_REPORT_HOST` is (`hostSetting`): never every interface.
|
|
14
15
|
*/
|
|
15
|
-
export declare const signInHost: Effect.Effect<string,
|
|
16
|
+
export declare const signInHost: Effect.Effect<string, Failure, never>;
|
|
16
17
|
/** How a sign-in ended. */
|
|
17
18
|
export type SignInOutcome = 'saved' | 'cancelled' | 'idle';
|
|
18
19
|
export interface SignInRequest {
|
|
@@ -23,6 +24,20 @@ export interface SignInRequest {
|
|
|
23
24
|
/** Where the browser opens. */
|
|
24
25
|
readonly url: string;
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* One open sign-in, as `SignIns.begin` gave it: bound to that sign-in, never to whichever one its
|
|
29
|
+
* label has later (another origin's replaces it).
|
|
30
|
+
*/
|
|
31
|
+
export interface SignInHandle {
|
|
32
|
+
readonly link: string;
|
|
33
|
+
/** Waits for this sign-in to end. */
|
|
34
|
+
readonly done: Effect.Effect<SignInOutcome>;
|
|
35
|
+
/**
|
|
36
|
+
* How this sign-in ended, once any input or save in progress is over (a session that was
|
|
37
|
+
* written is then also reported saved); undefined while it is still open.
|
|
38
|
+
*/
|
|
39
|
+
readonly outcome: Effect.Effect<SignInOutcome | undefined>;
|
|
40
|
+
}
|
|
26
41
|
/** The app as the live view shows it: its title and its icon as an image data URL. */
|
|
27
42
|
export interface SignInSiteView {
|
|
28
43
|
readonly title: string | undefined;
|
|
@@ -59,14 +74,11 @@ export declare const makeSignInApp: (options: {
|
|
|
59
74
|
}) => Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest>;
|
|
60
75
|
declare const SignIns_base: Context.ServiceClass<SignIns, "screw-bugs/SignIns", {
|
|
61
76
|
/**
|
|
62
|
-
* Opens a sign-in for the account, or gives the
|
|
63
|
-
*
|
|
77
|
+
* Opens a sign-in for the account, or gives the one already open for it at the same origin
|
|
78
|
+
* (another origin's is ended first). Resolves at once with a handle bound to that sign-in, so
|
|
79
|
+
* a wait on it never moves to one that replaces it later.
|
|
64
80
|
*/
|
|
65
|
-
readonly begin: (request: SignInRequest) => Effect.Effect<
|
|
66
|
-
readonly link: string;
|
|
67
|
-
}, Failure>;
|
|
68
|
-
/** Waits for the sign-in open for `label` to end; undefined when none is open. */
|
|
69
|
-
readonly wait: (label: string) => Effect.Effect<SignInOutcome | undefined>;
|
|
81
|
+
readonly begin: (request: SignInRequest) => Effect.Effect<SignInHandle, Failure>;
|
|
70
82
|
}>;
|
|
71
83
|
/**
|
|
72
84
|
* The sign-ins this process holds open, one per account label. A long-lived process (the MCP
|
package/dist/cli/sign-in.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodeHttpServer } from '@effect/platform-node';
|
|
2
2
|
// Boundary: NodeHttpServer serves a Node `http.Server`, made here.
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
|
-
import { Clock,
|
|
4
|
+
import { Clock, Context, DateTime, Deferred, Duration, Effect, Exit, Layer, Option, Schema, Scope, Semaphore, Stream, } from 'effect';
|
|
5
5
|
import { Base64 } from 'effect/encoding';
|
|
6
6
|
import { HttpClient, HttpServerRequest, HttpServerResponse } from 'effect/http';
|
|
7
7
|
import { SecureRandom } from 'effect/crypto';
|
|
@@ -10,6 +10,7 @@ import { hex, renderSignInPage, SIGN_IN_CSP } from '../report/index.js';
|
|
|
10
10
|
import { SignInInputs } from '../schema/index.js';
|
|
11
11
|
import { ExitCode } from './exit-codes.js';
|
|
12
12
|
import { Failure } from './failure.js';
|
|
13
|
+
import { boundAddress, hostSetting, isLoopback, urlHost } from './report-server.js';
|
|
13
14
|
/*
|
|
14
15
|
* Signing in to a test account: a headless browser at the app, which a person drives from a web
|
|
15
16
|
* page (the live view, `renderSignInPage`) in whatever browser reaches this machine: the one built
|
|
@@ -28,14 +29,22 @@ export const FRAME_WAIT_MS = 15_000;
|
|
|
28
29
|
export const SIGN_IN_ICON_TIMEOUT = Duration.seconds(3);
|
|
29
30
|
/** The largest input request taken: a few hundred inputs. */
|
|
30
31
|
const INPUT_BYTES_MAX = 256 * 1024;
|
|
31
|
-
const LOOPBACK = new Set(['127.0.0.1', 'localhost', '::1']);
|
|
32
32
|
/**
|
|
33
|
-
* `SCREW_BUGS_SIGN_IN_HOST`:
|
|
34
|
-
* 127.0.0.1 unless set; set it to this machine's
|
|
33
|
+
* `SCREW_BUGS_SIGN_IN_HOST`: where the sign-in server listens, and the host in its link.
|
|
34
|
+
* 127.0.0.1 unless set; set it to this machine's MagicDNS name or tailnet IP to sign in from
|
|
35
|
+
* another device. Read as `SCREW_BUGS_REPORT_HOST` is (`hostSetting`): never every interface.
|
|
35
36
|
*/
|
|
36
|
-
export const signInHost =
|
|
37
|
-
/**
|
|
38
|
-
const
|
|
37
|
+
export const signInHost = Effect.suspend(() => hostSetting('SCREW_BUGS_SIGN_IN_HOST', 'sign_in_host'));
|
|
38
|
+
/** The handle for an open sign-in. */
|
|
39
|
+
const handleOf = (entry) => ({
|
|
40
|
+
link: entry.link,
|
|
41
|
+
done: Deferred.await(entry.done),
|
|
42
|
+
outcome: Effect.gen(function* () {
|
|
43
|
+
if (!(yield* Deferred.isDone(entry.done)))
|
|
44
|
+
return undefined;
|
|
45
|
+
return yield* Deferred.await(entry.done);
|
|
46
|
+
}).pipe(Semaphore.withPermit(entry.steps)),
|
|
47
|
+
});
|
|
39
48
|
const randomToken = SecureRandom.SecureRandom.use((random) => random.randomBytes(32)).pipe(Effect.map(hex), Effect.provide(SecureRandom.layerWebCrypto));
|
|
40
49
|
/** Compares in time that does not depend on where the strings differ. */
|
|
41
50
|
const sameText = (a, b) => {
|
|
@@ -202,13 +211,6 @@ export class SignIns extends Context.Service()('screw-bugs/SignIns') {
|
|
|
202
211
|
const pending = new Map();
|
|
203
212
|
const open = (request) => Effect.gen(function* () {
|
|
204
213
|
const host = yield* signInHost;
|
|
205
|
-
if (host === '' || host === '0.0.0.0' || host === '::')
|
|
206
|
-
return yield* new Failure({
|
|
207
|
-
code: ExitCode.Usage,
|
|
208
|
-
reason: 'sign_in_host',
|
|
209
|
-
message: `SCREW_BUGS_SIGN_IN_HOST is "${host}"; give one address of this machine, such ` +
|
|
210
|
-
'as 127.0.0.1 or its tailnet IP, never every interface.',
|
|
211
|
-
});
|
|
212
214
|
const own = yield* Scope.fork(scope);
|
|
213
215
|
const opened = yield* Effect.gen(function* () {
|
|
214
216
|
const live = yield* browser.signIn(request.url).pipe(Effect.mapError((error) => new Failure({
|
|
@@ -259,8 +261,11 @@ export class SignIns extends Context.Service()('screw-bugs/SignIns') {
|
|
|
259
261
|
})));
|
|
260
262
|
if ('port' in server.address)
|
|
261
263
|
port = server.address.port;
|
|
264
|
+
const bound = yield* boundAddress(server.address, host, 'SCREW_BUGS_SIGN_IN_HOST', 'sign_in_host');
|
|
265
|
+
// The host it was set to, and the address that is (a name's IP): both can be opened.
|
|
262
266
|
hosts.add(`${urlHost(host)}:${port}`);
|
|
263
|
-
|
|
267
|
+
hosts.add(`${urlHost(bound)}:${port}`);
|
|
268
|
+
if (isLoopback(host))
|
|
264
269
|
for (const name of ['127.0.0.1', 'localhost', '[::1]'])
|
|
265
270
|
hosts.add(`${name}:${port}`);
|
|
266
271
|
yield* server.serve(app).pipe(Effect.provide(NodeHttpServer.layerHttpServices));
|
|
@@ -273,7 +278,7 @@ export class SignIns extends Context.Service()('screw-bugs/SignIns') {
|
|
|
273
278
|
yield* end('idle');
|
|
274
279
|
}
|
|
275
280
|
}).pipe(Effect.forkIn(own));
|
|
276
|
-
return { link: `http://${urlHost(host)}:${port}/${token}/`, done, end };
|
|
281
|
+
return { link: `http://${urlHost(host)}:${port}/${token}/`, done, end, steps };
|
|
277
282
|
}).pipe(Scope.provide(own), Effect.onError(() => Scope.close(own, Exit.void)));
|
|
278
283
|
const entry = { origin: request.origin, ...opened };
|
|
279
284
|
pending.set(request.label, entry);
|
|
@@ -289,17 +294,12 @@ export class SignIns extends Context.Service()('screw-bugs/SignIns') {
|
|
|
289
294
|
const open_ = pending.get(request.label);
|
|
290
295
|
if (open_ !== undefined && !(yield* Deferred.isDone(open_.done))) {
|
|
291
296
|
if (open_.origin === request.origin)
|
|
292
|
-
return
|
|
297
|
+
return handleOf(open_);
|
|
293
298
|
// After a save in progress, which then stands until this one saves.
|
|
294
299
|
yield* open_.end('cancelled');
|
|
295
300
|
}
|
|
296
|
-
|
|
297
|
-
return { link: opened.link };
|
|
301
|
+
return handleOf(yield* open(request));
|
|
298
302
|
}).pipe(Semaphore.withPermit(lock)),
|
|
299
|
-
wait: (label) => Effect.suspend(() => {
|
|
300
|
-
const open_ = pending.get(label);
|
|
301
|
-
return open_ === undefined ? Effect.succeed(undefined) : Deferred.await(open_.done);
|
|
302
|
-
}),
|
|
303
303
|
});
|
|
304
304
|
}));
|
|
305
305
|
}
|
package/dist/core/engine.js
CHANGED
|
@@ -201,18 +201,24 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
201
201
|
/** Writes `evidence.json`, the evidence pack an agent writes its findings from. */
|
|
202
202
|
const writeEvidence = (job, ledger) => bounded(runFiles.evidence, storage.writeFile(job.jobId, runFiles.evidence, `${JSON.stringify(evidencePackOf(job, ledger), null, 2)}\n`));
|
|
203
203
|
/**
|
|
204
|
-
* Writes the report of a run that just ended
|
|
205
|
-
*
|
|
206
|
-
*
|
|
204
|
+
* Writes the report of a run that just ended, and returns the pages written with it,
|
|
205
|
+
* relative to the run folder, for `live.html` to link. The report is derived from the ledger
|
|
206
|
+
* and can be rewritten with `screw-bugs report`, so failing to write it never changes the
|
|
207
|
+
* run's result: the notifier says so.
|
|
207
208
|
*/
|
|
208
|
-
const reportOnEnd = (ledger) => storage.readJob(ledger.jobId).pipe(Effect.flatMap((job) => writeEvidence(job, ledger).pipe(Effect.andThen(renderReport(job, ledger)))), Effect.
|
|
209
|
+
const reportOnEnd = (ledger) => storage.readJob(ledger.jobId).pipe(Effect.flatMap((job) => writeEvidence(job, ledger).pipe(Effect.andThen(renderReport(job, ledger)))), Effect.map(({ bundle }) => ({
|
|
210
|
+
report: runFiles.html,
|
|
211
|
+
walkthrough: bundle.files.walkthrough,
|
|
212
|
+
})), Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause)
|
|
209
213
|
? Effect.failCause(cause)
|
|
210
|
-
: notifier
|
|
214
|
+
: notifier
|
|
215
|
+
.notify({
|
|
211
216
|
jobId: ledger.jobId,
|
|
212
217
|
state: ledger.state,
|
|
213
218
|
message: `The run ended, but report.html could not be written: ${messageOf(Cause.squash(cause)).replace(/\.$/, '')}. ` +
|
|
214
219
|
`Run \`screw-bugs report ${ledger.jobId}\` to try again.`,
|
|
215
|
-
})
|
|
220
|
+
})
|
|
221
|
+
.pipe(Effect.as({}))));
|
|
216
222
|
const device = (spec) => ({
|
|
217
223
|
deviceLabel: browser.deviceLabel(spec.device ?? 'desktop'),
|
|
218
224
|
});
|
|
@@ -234,16 +240,39 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
234
240
|
...device(spec),
|
|
235
241
|
...(version !== undefined ? { version } : {}),
|
|
236
242
|
};
|
|
243
|
+
/**
|
|
244
|
+
* Where the job is (see `RunProgress`): set as each case and step starts, and saved with
|
|
245
|
+
* the next ledger write (the heartbeat, or the case's end), never a write of its own.
|
|
246
|
+
*/
|
|
247
|
+
let progress;
|
|
248
|
+
/** The ledger with the progress as it is now; only a running ledger has one. */
|
|
249
|
+
const withProgress = (next) => {
|
|
250
|
+
const { progress: _, ...rest } = next;
|
|
251
|
+
return next.state === 'running' && progress !== undefined
|
|
252
|
+
? { ...rest, progress }
|
|
253
|
+
: rest;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Writes `live.html` from the ledger just written, with the pages its report came with
|
|
257
|
+
* once the run ended. Only a page to watch: a failed write changes nothing else.
|
|
258
|
+
*/
|
|
259
|
+
const writeLive = (next, pages) => bounded(runFiles.live, Effect.sync(() => renderer.live({ spec, ledger: next, ...pages })).pipe(Effect.flatMap((page) => storage.writeFile(jobId, runFiles.live, page)))).pipe(Effect.catchCause(() => Effect.void));
|
|
237
260
|
/**
|
|
238
261
|
* One write at a time, each finished even when interrupted (but bounded, see
|
|
239
262
|
* `WRITE_TIMEOUT_MS`), so a heartbeat never lands over a newer ledger such as the final one.
|
|
263
|
+
* Once a ledger has ended, only another final write may follow it (`stop` after a final
|
|
264
|
+
* write that failed): a write that was waiting its turn behind it (the heartbeat) writes
|
|
265
|
+
* nothing, as it would rewrite live.html without the report's links.
|
|
240
266
|
*/
|
|
241
267
|
const writes = yield* Semaphore.make(1);
|
|
242
268
|
const write = (change, ends) => writes.withPermits(1)(Effect.uninterruptible(Effect.gen(function* () {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
269
|
+
if (!ends && ledger.state !== 'running')
|
|
270
|
+
return;
|
|
271
|
+
const next = yield* stamped(withProgress(change(ledger)));
|
|
272
|
+
// The report goes first, so whoever sees the run end in the ledger can open it;
|
|
273
|
+
// then live.html, so whoever sees it running there can open that.
|
|
274
|
+
const pages = ends ? yield* reportOnEnd(next) : {};
|
|
275
|
+
yield* writeLive(next, pages);
|
|
247
276
|
ledger = next;
|
|
248
277
|
yield* bounded('ledger.json', storage.writeLedger(next));
|
|
249
278
|
})));
|
|
@@ -253,29 +282,43 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
253
282
|
const end = (next) => write(() => next, true);
|
|
254
283
|
/** The session that is open, if one is: its number, video and when its video started. */
|
|
255
284
|
let open;
|
|
285
|
+
/**
|
|
286
|
+
* The session that ended while its video is being measured, so a run interrupted then
|
|
287
|
+
* still records it (without `still`).
|
|
288
|
+
*/
|
|
289
|
+
let measuring;
|
|
256
290
|
/**
|
|
257
291
|
* Checks the video of the open session once its browser is closed: it exists, is not
|
|
258
|
-
* empty, and is about as long as the session ran (`videoProblemOf`)
|
|
292
|
+
* empty, and is about as long as the session ran (`videoProblemOf`); with `measure`, also
|
|
293
|
+
* where it stands still (`Browser.stillVideo`).
|
|
259
294
|
*/
|
|
260
|
-
const sessionEnd = Effect.gen(function* () {
|
|
295
|
+
const sessionEnd = (measure) => Effect.gen(function* () {
|
|
261
296
|
if (open === undefined)
|
|
262
|
-
return
|
|
297
|
+
return measuring;
|
|
263
298
|
const { number, video, startedAt } = open;
|
|
264
299
|
open = undefined;
|
|
265
300
|
const durationMs = Math.round((yield* Clock.currentTimeMillis) - startedAt);
|
|
266
301
|
const file = yield* storage.probe(jobId, video, VIDEO_HEAD_BYTES);
|
|
267
302
|
const videoDurationMs = file === undefined ? undefined : webmDurationMs(file.head);
|
|
268
303
|
const problem = videoProblemOf(file === undefined ? undefined : { size: file.size, durationMs: videoDurationMs }, durationMs);
|
|
269
|
-
|
|
304
|
+
const saved = file !== undefined && file.size > 0;
|
|
305
|
+
const ended = {
|
|
270
306
|
number,
|
|
271
307
|
fields: {
|
|
272
308
|
endedAt: yield* now,
|
|
273
309
|
durationMs,
|
|
274
|
-
...(
|
|
310
|
+
...(saved ? { video } : {}),
|
|
275
311
|
...(videoDurationMs !== undefined ? { videoDurationMs } : {}),
|
|
276
312
|
...(problem !== undefined ? { videoProblem: problem } : {}),
|
|
277
313
|
},
|
|
278
314
|
};
|
|
315
|
+
if (!measure || !saved)
|
|
316
|
+
return ended;
|
|
317
|
+
// Where the video stands still, for the walkthrough's "Skip inactive".
|
|
318
|
+
measuring = ended;
|
|
319
|
+
const still = yield* browser.stillVideo(storage.filePath(jobId, video));
|
|
320
|
+
measuring = undefined;
|
|
321
|
+
return still === undefined ? ended : { number, fields: { ...ended.fields, still } };
|
|
279
322
|
});
|
|
280
323
|
/** The sessions of `current` with the one that just ended filled in. */
|
|
281
324
|
const withSession = (current, ended, videoProblem) => current.sessions === undefined
|
|
@@ -292,7 +335,8 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
292
335
|
};
|
|
293
336
|
/** Ends the job early: whatever has not run stays not verified, with `reason`. */
|
|
294
337
|
const stop = (error, reason) => Effect.gen(function* () {
|
|
295
|
-
|
|
338
|
+
// An interrupted run ends at once: its video is not measured.
|
|
339
|
+
const ended = yield* sessionEnd(error !== RUN_INTERRUPTED);
|
|
296
340
|
yield* end({
|
|
297
341
|
...ledger,
|
|
298
342
|
state: 'errored',
|
|
@@ -340,6 +384,7 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
340
384
|
// A case that continues goes on from the page the one before it left, whatever
|
|
341
385
|
// that case came to; the first case of a job cannot (see `JobSpec`).
|
|
342
386
|
const continuedFrom = caseSpec.continue === true ? cases[index - 1]?.id : undefined;
|
|
387
|
+
progress = { case: index + 1 };
|
|
343
388
|
yield* session.beginCase({ continues: continuedFrom !== undefined });
|
|
344
389
|
const entry = yield* runCase(session.page, caseSpec, {
|
|
345
390
|
continuedFrom,
|
|
@@ -352,7 +397,12 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
352
397
|
now: sinceVideo,
|
|
353
398
|
savePage: (fileName, page) => storage.writeFile(jobId, `${runFiles.evidenceDir}/${fileName}`, JSON.stringify(page)),
|
|
354
399
|
uploads: (path) => sources.get(path),
|
|
400
|
+
onStep: (step, kind) => Effect.sync(() => {
|
|
401
|
+
progress = { case: index + 1, step, kind };
|
|
402
|
+
}),
|
|
355
403
|
});
|
|
404
|
+
// Saved with this case's result: the next case, which starts now, if there is one.
|
|
405
|
+
progress = index + 1 < cases.length ? { case: index + 2 } : undefined;
|
|
356
406
|
yield* update((current) => ({
|
|
357
407
|
...current,
|
|
358
408
|
cases: current.cases.with(index, { ...entry, session: 1 }),
|
|
@@ -365,7 +415,7 @@ export class Engine extends Context.Service()('screw-bugs/Engine') {
|
|
|
365
415
|
}
|
|
366
416
|
}
|
|
367
417
|
const { videoProblem } = yield* session.close;
|
|
368
|
-
const ended = yield* sessionEnd;
|
|
418
|
+
const ended = yield* sessionEnd(true);
|
|
369
419
|
if (crash !== undefined) {
|
|
370
420
|
const error = `The browser stopped working during case "${crash.caseId}": ${crash.message}`;
|
|
371
421
|
yield* end({
|
package/dist/core/liveness.js
CHANGED
|
@@ -46,7 +46,9 @@ export const withLiveness = (ledger, nowMs) => {
|
|
|
46
46
|
const beat = ledger.heartbeatAt === undefined ? Number.NaN : Date.parse(ledger.heartbeatAt);
|
|
47
47
|
if (nowMs - beat <= HEARTBEAT_STALE_MS)
|
|
48
48
|
return ledger;
|
|
49
|
-
|
|
49
|
+
// Where it was is no longer where it is: only a running ledger has a progress.
|
|
50
|
+
const { progress: _, ...rest } = ledger;
|
|
51
|
+
return { ...rest, state: 'errored', error: PROCESS_GONE, cases: markUnreached(ledger.cases) };
|
|
50
52
|
};
|
|
51
53
|
/**
|
|
52
54
|
* How long ago the heartbeat of a ledger that `withLiveness` reports errored was written; its
|
package/dist/core/services.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, type Effect, type Scope } from 'effect';
|
|
2
|
-
import type { AccountEntry, Box, Candidate, CaseLedger, Device, ElementTarget, JobId, JobRecord, JobSpec, JobState, OnScreen, PageFacts, PageNode, Point, ReportBundle, SavedSession, ShotFrame, SignInInput, Target, Truncated, VisualViewport, WaitState } from '../schema/index.js';
|
|
2
|
+
import type { AccountEntry, Box, Candidate, CaseLedger, Device, ElementTarget, JobId, JobRecord, JobSpec, JobState, OnScreen, PageFacts, PageNode, Point, ReportBundle, SavedSession, ShotFrame, SignInInput, StillStretch, Target, Truncated, VisualViewport, WaitState } from '../schema/index.js';
|
|
3
3
|
import type { BrowserNotFound, PageActionFailed, RunNotFound, StorageFailed } from './errors.js';
|
|
4
4
|
export type BrowserKind = 'chrome' | 'msedge' | 'playwright-chromium';
|
|
5
5
|
export interface BrowserInfo {
|
|
@@ -157,8 +157,9 @@ export interface TextScope {
|
|
|
157
157
|
export interface ActionTrace {
|
|
158
158
|
/**
|
|
159
159
|
* How long after the operation was called it acted, in ms: when the browser dispatched the
|
|
160
|
-
* click or the key to the page, or the load started. Missing when that was not seen,
|
|
161
|
-
* fill or files set on a file input directly (a page can make their edits itself)
|
|
160
|
+
* click or the key to the page, or the load started. Missing when that was not seen, for a
|
|
161
|
+
* fill or files set on a file input directly (a page can make their edits itself), and for a
|
|
162
|
+
* hover (see `StepAction.atMs`).
|
|
162
163
|
*/
|
|
163
164
|
readonly afterMs?: number | undefined;
|
|
164
165
|
/**
|
|
@@ -199,13 +200,19 @@ export interface UploadSource {
|
|
|
199
200
|
*/
|
|
200
201
|
export interface BrowserPage {
|
|
201
202
|
/**
|
|
202
|
-
* goto, reload, click, fill, upload and press fail only when the action itself could not be
|
|
203
|
+
* goto, reload, click, hover, fill, upload and press fail only when the action itself could not be
|
|
203
204
|
* performed. What the documents they load come to is judged by `settle`. Each says when it
|
|
204
205
|
* acted and, for an element, where (see `ActionTrace`).
|
|
205
206
|
*/
|
|
206
207
|
readonly goto: (url: string, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
|
|
207
208
|
readonly reload: (wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
|
|
208
209
|
readonly click: (target: Target, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
|
|
210
|
+
/**
|
|
211
|
+
* Moves the mouse over `target` (waiting for it like `click` does, and scrolling it into view),
|
|
212
|
+
* so the page's own hover styles and handlers run; the mouse stays there until the next action
|
|
213
|
+
* moves it. Records no time or point (see `StepAction.atMs`).
|
|
214
|
+
*/
|
|
215
|
+
readonly hover: (target: Target, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
|
|
209
216
|
readonly fill: (target: Target, value: string, wait?: Wait) => Effect.Effect<ActionTrace, PageActionFailed>;
|
|
210
217
|
/**
|
|
211
218
|
* Sets `files` (absolute paths) on the file input `target` matches, hidden or not, or else
|
|
@@ -238,7 +245,7 @@ export interface BrowserPage {
|
|
|
238
245
|
* How `target` shows on the screen now (see `OnScreen`), for the step's record; never changes
|
|
239
246
|
* what the step decided. For a `check` (a step that held: waitFor visible, expectText,
|
|
240
247
|
* expectLink), the best of its visible matches, scrolling the page to one that only the page's
|
|
241
|
-
* scrolling keeps off the screen, as a person would. For an `act` (a click or fill), the match
|
|
248
|
+
* scrolling keeps off the screen, as a person would. For an `act` (a click, hover or fill), the match
|
|
242
249
|
* the action takes, as it is: the action scrolls to it, through anything that scrolls. While it
|
|
243
250
|
* does not show, it is measured again for a few seconds (at most `wait`'s timeout, after one
|
|
244
251
|
* whole look at the first match), for what is still moving into place. Undefined when nothing matches visibly or it could not be measured. Never fails.
|
|
@@ -376,6 +383,11 @@ declare const Browser_base: Context.ServiceClass<Browser, "screw-bugs/Browser",
|
|
|
376
383
|
readonly detect: Effect.Effect<BrowserInfo, BrowserNotFound>;
|
|
377
384
|
/** Whether sessions can be recorded; looked up without downloading or launching anything. */
|
|
378
385
|
readonly videoSupport: Effect.Effect<VideoSupport>;
|
|
386
|
+
/**
|
|
387
|
+
* Where the saved video at `file` (an absolute path) stands still (see `stillStretches`);
|
|
388
|
+
* undefined when that could not be measured. Reads the video only.
|
|
389
|
+
*/
|
|
390
|
+
readonly stillVideo: (file: string) => Effect.Effect<ReadonlyArray<StillStretch> | undefined>;
|
|
379
391
|
readonly open: (options: {
|
|
380
392
|
readonly headed: boolean;
|
|
381
393
|
}) => Effect.Effect<BrowserSession, BrowserNotFound, Scope.Scope>;
|
|
@@ -495,10 +507,23 @@ declare const Storage_base: Context.ServiceClass<Storage, "screw-bugs/Storage",
|
|
|
495
507
|
*/
|
|
496
508
|
export declare class Storage extends Storage_base {
|
|
497
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* What `live.html` (`runFiles.live`) shows: the job and its ledger as just written. Once the run
|
|
512
|
+
* has ended (the ledger says so), `report` and `walkthrough` name the pages written with its
|
|
513
|
+
* report, relative to the run folder, when they were.
|
|
514
|
+
*/
|
|
515
|
+
export interface LivePage {
|
|
516
|
+
readonly spec: JobSpec;
|
|
517
|
+
readonly ledger: CaseLedger;
|
|
518
|
+
readonly report?: string | undefined;
|
|
519
|
+
readonly walkthrough?: string | undefined;
|
|
520
|
+
}
|
|
498
521
|
declare const ReportRenderer_base: Context.ServiceClass<ReportRenderer, "screw-bugs/ReportRenderer", {
|
|
499
522
|
readonly html: (bundle: ReportBundle) => string;
|
|
500
523
|
/** The run's walkthrough (`runFiles.walkthrough`): its video and every step as a script. */
|
|
501
524
|
readonly walkthrough: (bundle: ReportBundle) => string;
|
|
525
|
+
/** The page a person watches the run on while it goes (`runFiles.live`). */
|
|
526
|
+
readonly live: (page: LivePage) => string;
|
|
502
527
|
}>;
|
|
503
528
|
/**
|
|
504
529
|
* Turns a run into its HTML report. Pure: the `report` module provides it, and the engine writes
|
package/dist/core/share.d.ts
CHANGED
|
@@ -35,3 +35,34 @@ export declare const typesSecret: (step: Step) => boolean;
|
|
|
35
35
|
* and video show.
|
|
36
36
|
*/
|
|
37
37
|
export declare const scrubBundle: (bundle: ReportBundle) => ReportBundle;
|
|
38
|
+
/** The screenshots of `bundle` a share may hold as WebP instead: its PNGs, of `shareFiles`. */
|
|
39
|
+
export declare const encodableFiles: (bundle: ReportBundle) => ReadonlySet<string>;
|
|
40
|
+
/** Where the WebP of the screenshot at `path` goes: the same path, ending `.webp`. */
|
|
41
|
+
export declare const webpPath: (path: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* `bundle` with its file paths changed as `renames` says (old path to new), wherever the bundle
|
|
44
|
+
* names them: each case's evidence, their names and shots, and the annotated copies.
|
|
45
|
+
*/
|
|
46
|
+
export declare const renameFiles: (bundle: ReportBundle, renames: ReadonlyMap<string, string>) => ReportBundle;
|
|
47
|
+
/** An image's size in pixels. */
|
|
48
|
+
export interface PixelSize {
|
|
49
|
+
readonly width: number;
|
|
50
|
+
readonly height: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The most pixels a WebP image has on a side. A browser asked to encode a taller screenshot (a
|
|
54
|
+
* long full-page one) gives a cut-down image, so such screenshots are never offered.
|
|
55
|
+
*/
|
|
56
|
+
export declare const WEBP_MAX_SIDE = 16383;
|
|
57
|
+
/** How many bytes of a PNG `pngSize` reads: the signature and the IHDR chunk's size fields. */
|
|
58
|
+
export declare const PNG_HEADER_BYTES = 24;
|
|
59
|
+
/** The size of the PNG whose first bytes are `bytes`, or undefined for anything else. */
|
|
60
|
+
export declare const pngSize: (bytes: Uint8Array) => PixelSize | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* The size of the WebP file `bytes`, or undefined unless it is one whole still image: a RIFF
|
|
63
|
+
* `WEBP` container whose length is the file's, made of chunks that fill it exactly (each padded
|
|
64
|
+
* to an even length), holding one lossy (`VP8 `) or lossless (`VP8L`) image with data in it,
|
|
65
|
+
* first or after an extended header (`VP8X`, not animated) whose canvas is the image's size.
|
|
66
|
+
* It does not decode the image, so a file can still be broken inside its image data.
|
|
67
|
+
*/
|
|
68
|
+
export declare const webpSize: (bytes: Uint8Array) => PixelSize | undefined;
|
package/dist/core/share.js
CHANGED
|
@@ -177,3 +177,142 @@ export const scrubBundle = (bundle) => {
|
|
|
177
177
|
// Only strings change, so the result keeps the bundle's shape.
|
|
178
178
|
return scrubStrings(typed);
|
|
179
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
CHANGED
|
@@ -98,4 +98,9 @@ export declare const runCase: (page: BrowserPage, spec: CaseSpec, options: {
|
|
|
98
98
|
* ledger records it.
|
|
99
99
|
*/
|
|
100
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;
|
|
101
106
|
}) => Effect.Effect<CaseEntry>;
|