screw-bugs 0.1.7 → 0.1.9
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 +83 -13
- package/dist/browser-playwright/launch.js +27 -10
- package/dist/browser-playwright/page.d.ts +50 -28
- package/dist/browser-playwright/page.js +101 -91
- 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/commands.js +56 -11
- 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 +540 -109
- package/dist/cli/sign-in.d.ts +22 -10
- package/dist/cli/sign-in.js +23 -23
- package/dist/core/engine.js +54 -13
- package/dist/core/liveness.js +3 -1
- package/dist/core/services.d.ts +29 -4
- 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 +6 -0
- package/dist/core/video.js +8 -0
- package/dist/report/html.d.ts +4 -2
- package/dist/report/html.js +36 -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 +3 -3
- 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.js +2 -0
- package/dist/report/walkthrough.d.ts +5 -2
- package/dist/report/walkthrough.js +17 -5
- package/dist/schema/accounts.js +10 -1
- package/dist/schema/evidence.d.ts +15 -8
- package/dist/schema/evidence.js +9 -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 +80 -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/mcp.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
3
|
-
import { Effect, Option, Path, Schema } from 'effect';
|
|
3
|
+
import { Duration, Effect, Option, Path, Schedule, Schema } from 'effect';
|
|
4
4
|
import { describeOnScreen } from '../core/index.js';
|
|
5
5
|
import { LEDGER_FILE } from '../store-local/index.js';
|
|
6
|
-
import { CaseSpec, Device, Findings, JobAccount, REASON_MAX, } from '../schema/index.js';
|
|
7
|
-
import { MAX_WAIT_SECONDS, Operations } from './operations.js';
|
|
6
|
+
import { CaseSpec, Device, Findings, JobAccount, progressText, REASON_MAX, } from '../schema/index.js';
|
|
7
|
+
import { MAX_SIGN_IN_WAIT_SECONDS, MAX_WAIT_SECONDS, Operations, } from './operations.js';
|
|
8
8
|
import { PackageInfo } from './package-info.js';
|
|
9
9
|
import { ReportServer } from './report-server.js';
|
|
10
10
|
import { UpdateCheck } from './update-check.js';
|
|
@@ -17,8 +17,10 @@ import { UpdateCheck } from './update-check.js';
|
|
|
17
17
|
* unusable starts nothing and lists the files needed, one line each (`formatFilesNeeded`), then
|
|
18
18
|
* one sentence asking the agent to create them, then the project folder. start_run whose test
|
|
19
19
|
* account has no session to start from starts nothing either: one sentence, then the link of the
|
|
20
|
-
* sign-in it opened for the user, then `accounts.json
|
|
21
|
-
*
|
|
20
|
+
* sign-in it opened for the user, then `accounts.json`; with `waitSeconds` it first waits for the
|
|
21
|
+
* user to save that sign-in, then starts the run (a normal reply), or says it was cancelled.
|
|
22
|
+
* Wherever the report is given, it is its http://127.0.0.1 URL (or `SCREW_BUGS_REPORT_HOST`'s, see
|
|
23
|
+
* `ReportServer`) in place of
|
|
22
24
|
* its path, for browsers built into coding tools, which cannot open file:// pages and whose file
|
|
23
25
|
* viewers do not play its video; the path only when there is no URL. Then the run's walkthrough
|
|
24
26
|
* (`walkthrough.html`), when it has one, the same way, and the reply's sentence names it as the
|
|
@@ -56,8 +58,14 @@ const failedByAgent = (c) => 'agentFailed' in c ? c.agentFailed : undefined;
|
|
|
56
58
|
/**
|
|
57
59
|
* `Job … is finished: 3 passed, 2 failed (1 by the agent's review), 0 blocked, 0 not verified.`
|
|
58
60
|
* The counts are the statuses results show: a case the agent's findings mark failed is failed.
|
|
61
|
+
* A running job also says where it is (`progressText`): `Job … is running case 2 of 3
|
|
62
|
+
* (reply-maya), step 4 (click): …`.
|
|
59
63
|
*/
|
|
60
|
-
export const formatLedger = (ledger) =>
|
|
64
|
+
export const formatLedger = (ledger) => {
|
|
65
|
+
const where = progressText(ledger);
|
|
66
|
+
return (`Job ${ledger.jobId} is ${ledger.state.replaceAll('_', ' ')}` +
|
|
67
|
+
`${where === undefined ? '' : ` ${where}`}: ${countsText(ledger)}.`);
|
|
68
|
+
};
|
|
61
69
|
/** `3 passed, 2 failed (1 by the agent's review), 0 blocked, 0 not verified`. */
|
|
62
70
|
const countsText = (ledger) => {
|
|
63
71
|
const count = (status) => ledger.cases.filter((c) => c.status === status).length;
|
|
@@ -173,19 +181,25 @@ export const formatEvidence = (ledger, pack) => {
|
|
|
173
181
|
};
|
|
174
182
|
/** One line per case that did not pass, for a run without an evidence pack. */
|
|
175
183
|
export const formatNotPassing = (ledger) => isOver(ledger) ? ledger.cases.filter((c) => c.status !== 'passed').map(caseLine) : [];
|
|
176
|
-
/**
|
|
177
|
-
|
|
184
|
+
/**
|
|
185
|
+
* The counts sentence, saying where to watch the run: in its walkthrough, when it has one, or
|
|
186
|
+
* while it is going, in its `live.html` (`live`).
|
|
187
|
+
*/
|
|
188
|
+
export const countsSentence = (ledger, walkthrough, live) => {
|
|
178
189
|
const counts = formatLedger(ledger);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
190
|
+
const below = (link) => `(the ${link === 'url' ? 'URL' : 'path'} below)`;
|
|
191
|
+
return walkthrough !== undefined
|
|
192
|
+
? `${trimPeriod(counts)}; watch it step by step in walkthrough.html ${below(walkthrough)}.`
|
|
193
|
+
: live !== undefined
|
|
194
|
+
? `${trimPeriod(counts)}; follow it as it runs in live.html ${below(live)}.`
|
|
195
|
+
: counts;
|
|
182
196
|
};
|
|
183
197
|
/**
|
|
184
198
|
* A status reply: the counts (and where to watch the run, when it has a walkthrough), then the
|
|
185
199
|
* evidence pack (see `formatEvidence`).
|
|
186
200
|
*/
|
|
187
|
-
export const formatStatus = (ledger, pack, walkthrough) => [
|
|
188
|
-
countsSentence(ledger, walkthrough),
|
|
201
|
+
export const formatStatus = (ledger, pack, walkthrough, live) => [
|
|
202
|
+
countsSentence(ledger, walkthrough, live),
|
|
189
203
|
...(pack ? formatEvidence(ledger, pack) : formatNotPassing(ledger)),
|
|
190
204
|
].join('\n');
|
|
191
205
|
/** Highlights that could not be drawn, for the agent to name better and submit again. */
|
|
@@ -252,6 +266,8 @@ const StartRunInput = Schema.Struct({
|
|
|
252
266
|
'{"action":"goto","url":"/login"}, ' +
|
|
253
267
|
'{"action":"fill","target":{"label":"Email"},"value":"a@b.co"}, ' +
|
|
254
268
|
'{"action":"click","target":{"role":"button","name":"Sign in"}}, ' +
|
|
269
|
+
'{"action":"hover","target":{"text":"Hi there"}} (moves the pointer over it, for controls ' +
|
|
270
|
+
"that only show on hover, such as a message's Reply button; it stays there), " +
|
|
255
271
|
'{"action":"press","key":"Enter"}, {"action":"expectText","text":"Welcome"}, ' +
|
|
256
272
|
'{"action":"expectNoText","text":"Acme"} (passes when it does not show as text, image ' +
|
|
257
273
|
'alt text or ARIA label, in the page and its frames, or with frame or target only there), ' +
|
|
@@ -291,12 +307,22 @@ const StartRunInput = Schema.Struct({
|
|
|
291
307
|
'accounts are saved (for public pages, the sign-up or sign-in flow itself, or what a ' +
|
|
292
308
|
'visitor sees). Give it to run signed in as a test account: ' +
|
|
293
309
|
'the label of one in .screw-bugs/accounts.json (in the ' +
|
|
294
|
-
'project; read it to pick the one whose about fits, such as a user on a trial or a
|
|
295
|
-
'one), or {"label":"paid-user","about":"Pro plan, paying monthly"} for one the
|
|
296
|
-
|
|
297
|
-
'origin, nothing starts and the reply gives a link:
|
|
298
|
-
'start the same job again
|
|
299
|
-
'
|
|
310
|
+
'project; read it first, to pick the one whose about fits, such as a user on a trial or a ' +
|
|
311
|
+
'paying one), or {"label":"paid-user","about":"Pro plan, paying monthly"} for one the ' +
|
|
312
|
+
'user signs in to first. Every case starts signed in. When it has no saved session for ' +
|
|
313
|
+
"this URL's origin, nothing starts and the reply gives a link: show it to the user, who " +
|
|
314
|
+
'signs in there, then start the same job again (with waitSeconds to wait for the save). ' +
|
|
315
|
+
'The sign-in opens the app at once, so when the account the cases need is not in ' +
|
|
316
|
+
'accounts.json, get the app running and that user in place first, then start the job ' +
|
|
317
|
+
'before the rest of your preparation, and the user signs in while you prepare. If its ' +
|
|
318
|
+
'session stopped working (the run lands on a sign-in page), give ' +
|
|
319
|
+
'{"label":…,"renew":true} once to have the user sign in again.',
|
|
320
|
+
})),
|
|
321
|
+
waitSeconds: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: MAX_SIGN_IN_WAIT_SECONDS })).annotate({
|
|
322
|
+
description: `0-${MAX_SIGN_IN_WAIT_SECONDS}, default 0. If the account still needs the user to sign ` +
|
|
323
|
+
'in, wait up to this many seconds for them to press Save sign-in, then start the run. ' +
|
|
324
|
+
'The link reaches the user only in a reply, so first call with 0 to get it and show it, ' +
|
|
325
|
+
'then call again with waitSeconds.',
|
|
300
326
|
})),
|
|
301
327
|
});
|
|
302
328
|
const RunStatusInput = Schema.Struct({
|
|
@@ -325,6 +351,34 @@ const AnswerQuestionInput = Schema.Struct({
|
|
|
325
351
|
questionId: Schema.NonEmptyString,
|
|
326
352
|
answer: Schema.String,
|
|
327
353
|
});
|
|
354
|
+
/** How often `start_run` sends progress while it waits for a sign-in. */
|
|
355
|
+
export const SIGN_IN_PROGRESS_INTERVAL = Duration.seconds(15);
|
|
356
|
+
/**
|
|
357
|
+
* While `start_run` waits for a sign-in, a progress notification with the link every
|
|
358
|
+
* `SIGN_IN_PROGRESS_INTERVAL`, when the client asked for progress (`progressToken`). Clients that
|
|
359
|
+
* time a call out unless it makes progress keep waiting; Claude Code shows the message as the
|
|
360
|
+
* tool's one-line status, which may cut the link, so the reply that gives it stays the way to
|
|
361
|
+
* reach the user.
|
|
362
|
+
*/
|
|
363
|
+
const signInProgress = (request) => (wait) => {
|
|
364
|
+
const token = request._meta?.progressToken;
|
|
365
|
+
if (token === undefined)
|
|
366
|
+
return Effect.void;
|
|
367
|
+
let progress = 0;
|
|
368
|
+
// Boundary: the MCP SDK sends notifications through promises.
|
|
369
|
+
const send = Effect.promise(() => request
|
|
370
|
+
.notify({
|
|
371
|
+
method: 'notifications/progress',
|
|
372
|
+
params: {
|
|
373
|
+
progressToken: token,
|
|
374
|
+
progress: ++progress,
|
|
375
|
+
message: `Waiting for the user to sign in to test account "${wait.label}" and press ` +
|
|
376
|
+
`Save sign-in: ${wait.link}`,
|
|
377
|
+
},
|
|
378
|
+
})
|
|
379
|
+
.catch(() => undefined));
|
|
380
|
+
return send.pipe(Effect.repeat(Schedule.spaced(SIGN_IN_PROGRESS_INTERVAL)), Effect.asVoid);
|
|
381
|
+
};
|
|
328
382
|
/** The MCP server: exactly five tools, each a thin call into `Operations`. */
|
|
329
383
|
export const makeMcpServer = Effect.gen(function* () {
|
|
330
384
|
const ops = yield* Operations;
|
|
@@ -354,7 +408,9 @@ export const makeMcpServer = Effect.gen(function* () {
|
|
|
354
408
|
// Boundary: the MCP SDK calls tools through promises. Each call runs with the services this
|
|
355
409
|
// server was made with (clock, config, logger), not a fresh default runtime.
|
|
356
410
|
const runPromise = Effect.runPromiseWith(yield* Effect.context());
|
|
357
|
-
const run = (effect, onSuccess
|
|
411
|
+
const run = (effect, onSuccess,
|
|
412
|
+
// Interrupts the call when the client cancels it (or times it out), so nothing starts unseen.
|
|
413
|
+
signal) => runPromise(effect.pipe(Effect.match({ onFailure: replyFailure, onSuccess })), signal ? { signal } : undefined);
|
|
358
414
|
const server = new McpServer({ name, version }, instructions ? { instructions } : undefined);
|
|
359
415
|
server.registerTool('doctor', {
|
|
360
416
|
description: 'Check this machine can run screw-bugs: Node, a browser, disk space and updates.',
|
|
@@ -362,13 +418,18 @@ export const makeMcpServer = Effect.gen(function* () {
|
|
|
362
418
|
server.registerTool('start_run', {
|
|
363
419
|
description: 'Run your QA cases (structured steps) in a headless browser; returns a job ID immediately. Upload files are yours to create in the project (such as fixtures/), with synthetic content.',
|
|
364
420
|
inputSchema: input(StartRunInput),
|
|
365
|
-
}, (
|
|
421
|
+
}, ({ waitSeconds, ...spec }, ctx) => run(ops.startRun({ spec }, {
|
|
422
|
+
requireConfig: false,
|
|
423
|
+
signIn: 'serve',
|
|
424
|
+
waitSeconds,
|
|
425
|
+
onSignInWait: signInProgress(ctx.mcpReq),
|
|
426
|
+
}), ({ jobId, runDir }) => reply(`Started job ${jobId}; check it with run_status.`, [runDir]), ctx.mcpReq.signal));
|
|
366
427
|
server.registerTool('run_status', {
|
|
367
|
-
description: 'Get the state and case results of a run by job ID; an ended run
|
|
428
|
+
description: 'Get the state and case results of a run by job ID; a running run gives a live page URL, an ended run its report and video walkthrough URLs.',
|
|
368
429
|
inputSchema: input(RunStatusInput),
|
|
369
430
|
}, ({ jobId, waitSeconds }) => run(ops
|
|
370
431
|
.runStatus(jobId, { waitSeconds })
|
|
371
|
-
.pipe(Effect.flatMap((status) => reportLinks(status).pipe(Effect.map((report) => ({ ...status, report }))))), ({ ledger, judged, runDir, report, evidence, evidencePath }) => reply(formatStatus(judged, evidence, report.walkthrough), [
|
|
432
|
+
.pipe(Effect.flatMap((status) => Effect.all({ report: reportLinks(status), live: pageLink(status.livePath) }).pipe(Effect.map(({ report, live }) => ({ ...status, report, live }))))), ({ ledger, judged, runDir, report, live, evidence, evidencePath }) => reply(formatStatus(judged, evidence, report.walkthrough, live?.kind), [
|
|
372
433
|
runDir,
|
|
373
434
|
path.join(runDir, LEDGER_FILE),
|
|
374
435
|
...(evidencePath ? [evidencePath] : []),
|
|
@@ -378,6 +439,8 @@ export const makeMcpServer = Effect.gen(function* () {
|
|
|
378
439
|
? evidence.videos.flatMap((v) => v.path !== undefined && isOver(ledger) ? [path.join(runDir, v.path)] : [])
|
|
379
440
|
: []),
|
|
380
441
|
...report.links,
|
|
442
|
+
// While the run is going: the page to follow it on.
|
|
443
|
+
...(live ? [live.link] : []),
|
|
381
444
|
])));
|
|
382
445
|
server.registerTool('submit_findings', {
|
|
383
446
|
description: 'Submit your write-up of an ended run; screw-bugs checks it and re-renders the report.',
|
package/dist/cli/operations.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, Effect, FileSystem, Layer, Path } from 'effect';
|
|
1
|
+
import { Context, Duration, Effect, FileSystem, Layer, Path } from 'effect';
|
|
2
2
|
import { AccountBook, Browser, Engine, type RunSummary, Storage } from '../core/index.js';
|
|
3
3
|
import { type AccountEntry, type CaseLedger, type Device, type DoctorReport, type EvidencePack, JobId, type JobRecord, type JudgedLedger, type PlacedMark, type ReportBundle } from '../schema/index.js';
|
|
4
4
|
import { Failure } from './failure.js';
|
|
@@ -8,6 +8,24 @@ import { type SignInOutcome } from './sign-in.js';
|
|
|
8
8
|
export declare const STATUS_POLL_MS = 500;
|
|
9
9
|
/** The longest a status call may wait for a run to end. */
|
|
10
10
|
export declare const MAX_WAIT_SECONDS = 60;
|
|
11
|
+
/**
|
|
12
|
+
* The longest `start_run` may wait for a person to sign in to its test account. A person is
|
|
13
|
+
* slower than a run: finding the tab, typing a password, a code from an email or a second factor.
|
|
14
|
+
* Ten minutes covers that, stays under a sign-in's own `SIGN_IN_IDLE` (15 minutes), and bounds how
|
|
15
|
+
* long an agent sits blocked; Claude Code's default MCP tool timeout is far longer.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MAX_SIGN_IN_WAIT_SECONDS = 600;
|
|
18
|
+
/**
|
|
19
|
+
* How long, once a sign-in wait's time is up, a save already in progress may take to finish and
|
|
20
|
+
* count. A save that takes longer (a stalled disk, a browser not answering) is not waited for: the
|
|
21
|
+
* call looks for a session once more and replies with the link.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SAVE_SETTLE: Duration.Duration;
|
|
24
|
+
/** A sign-in `startRun` waits for: the account, and the link the person signs in at. */
|
|
25
|
+
export interface SignInWait {
|
|
26
|
+
readonly label: string;
|
|
27
|
+
readonly link: string;
|
|
28
|
+
}
|
|
11
29
|
export interface StartRunInput {
|
|
12
30
|
/** A JobSpec, or part of one, as parsed JSON (from `--spec` or the MCP tool input). */
|
|
13
31
|
readonly spec?: unknown;
|
|
@@ -65,6 +83,11 @@ export interface RunResult {
|
|
|
65
83
|
* (never for an interrupted run's report).
|
|
66
84
|
*/
|
|
67
85
|
readonly walkthroughPath: string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* While the run is queued or running: its `live.html`, the page to watch it on, once the run
|
|
88
|
+
* wrote it. Only read: the run writes it.
|
|
89
|
+
*/
|
|
90
|
+
readonly livePath: string | undefined;
|
|
68
91
|
/**
|
|
69
92
|
* The ledger as results show it: each case's status after the agent's saved findings, if any
|
|
70
93
|
* (see `judgedLedger`). `ledger` keeps the code's statuses.
|
|
@@ -80,10 +103,15 @@ declare const Operations_base: Context.ServiceClass<Operations, "screw-bugs/Oper
|
|
|
80
103
|
* Starts a run. A job whose test account needs a person to sign in first starts nothing and
|
|
81
104
|
* fails with `SignInNeeded`: with `signIn: 'serve'` (a process that lives on, the MCP
|
|
82
105
|
* server), a sign-in is opened and its link given; otherwise the command that opens one.
|
|
106
|
+
* With `signIn: 'serve'` and `waitSeconds`, it first waits up to that long for the person to
|
|
107
|
+
* save that sign-in, and then starts the run as if called afresh; `onSignInWait` runs for as
|
|
108
|
+
* long as it waits (the MCP server sends progress with the link).
|
|
83
109
|
*/
|
|
84
110
|
readonly startRun: (input: StartRunInput, options: {
|
|
85
111
|
readonly requireConfig: boolean;
|
|
86
112
|
readonly signIn?: 'serve' | 'command';
|
|
113
|
+
readonly waitSeconds?: number | undefined;
|
|
114
|
+
readonly onSignInWait?: ((wait: SignInWait) => Effect.Effect<void>) | undefined;
|
|
87
115
|
}) => Effect.Effect<{
|
|
88
116
|
readonly jobId: JobId;
|
|
89
117
|
readonly runDir: string;
|
|
@@ -99,7 +127,7 @@ declare const Operations_base: Context.ServiceClass<Operations, "screw-bugs/Oper
|
|
|
99
127
|
*/
|
|
100
128
|
readonly signIn: (input: SignInInput) => Effect.Effect<{
|
|
101
129
|
readonly link: string;
|
|
102
|
-
readonly done: Effect.Effect<SignInOutcome
|
|
130
|
+
readonly done: Effect.Effect<SignInOutcome>;
|
|
103
131
|
}, Failure>;
|
|
104
132
|
/** Removes a saved account and its session; false when there was none. */
|
|
105
133
|
readonly removeAccount: (label: string) => Effect.Effect<boolean, Failure>;
|
package/dist/cli/operations.js
CHANGED
|
@@ -14,6 +14,19 @@ import { SignIns } from './sign-in.js';
|
|
|
14
14
|
export const STATUS_POLL_MS = 500;
|
|
15
15
|
/** The longest a status call may wait for a run to end. */
|
|
16
16
|
export const MAX_WAIT_SECONDS = 60;
|
|
17
|
+
/**
|
|
18
|
+
* The longest `start_run` may wait for a person to sign in to its test account. A person is
|
|
19
|
+
* slower than a run: finding the tab, typing a password, a code from an email or a second factor.
|
|
20
|
+
* Ten minutes covers that, stays under a sign-in's own `SIGN_IN_IDLE` (15 minutes), and bounds how
|
|
21
|
+
* long an agent sits blocked; Claude Code's default MCP tool timeout is far longer.
|
|
22
|
+
*/
|
|
23
|
+
export const MAX_SIGN_IN_WAIT_SECONDS = 600;
|
|
24
|
+
/**
|
|
25
|
+
* How long, once a sign-in wait's time is up, a save already in progress may take to finish and
|
|
26
|
+
* count. A save that takes longer (a stalled disk, a browser not answering) is not waited for: the
|
|
27
|
+
* call looks for a session once more and replies with the link.
|
|
28
|
+
*/
|
|
29
|
+
export const SAVE_SETTLE = Duration.seconds(5);
|
|
17
30
|
/** Whether a run is past queued and running: it ended, or it waits for an answer. */
|
|
18
31
|
const hasEnded = (ledger) => ledger.state !== 'queued' && ledger.state !== 'running';
|
|
19
32
|
const isOver = (ledger) => ledger.state === 'finished' || ledger.state === 'errored';
|
|
@@ -126,11 +139,17 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
126
139
|
? yield* reportOf(jobId, ledger, writeReport)
|
|
127
140
|
: undefined;
|
|
128
141
|
const walkthroughPath = yield* walkthroughOf(jobId, reportPath);
|
|
142
|
+
const livePath = ledger.state === 'queued' || ledger.state === 'running'
|
|
143
|
+
? yield* storage
|
|
144
|
+
.probe(jobId, runFiles.live, 0)
|
|
145
|
+
.pipe(Effect.map((file) => file === undefined ? undefined : storage.filePath(jobId, runFiles.live)))
|
|
146
|
+
: undefined;
|
|
129
147
|
return {
|
|
130
148
|
ledger,
|
|
131
149
|
runDir: storage.runDir(jobId),
|
|
132
150
|
reportPath,
|
|
133
151
|
walkthroughPath,
|
|
152
|
+
livePath,
|
|
134
153
|
judged: judgedLedger(ledger, findings),
|
|
135
154
|
};
|
|
136
155
|
});
|
|
@@ -199,14 +218,22 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
199
218
|
shellWord(needed.url),
|
|
200
219
|
...(needed.about !== undefined ? ['--about', shellWord(needed.about)] : []),
|
|
201
220
|
].join(' ');
|
|
221
|
+
/** `test account "trial-user" (On a trial)`. */
|
|
222
|
+
const accountText = (needed) => `test account "${needed.label}"` +
|
|
223
|
+
(needed.about !== undefined ? ` (${needed.about})` : '');
|
|
202
224
|
/**
|
|
203
225
|
* Nothing started: a person has to sign in to the job's account first. A process that
|
|
204
|
-
* stays (`serve`) opens the sign-in now
|
|
226
|
+
* stays (`serve`) opens the sign-in now (or gives the one already open) and its link;
|
|
227
|
+
* otherwise the command. `waited`: the seconds it already waited for a save, in vain;
|
|
228
|
+
* `link`: the link of the sign-in it waited on, still open, given again instead of
|
|
229
|
+
* opening one.
|
|
205
230
|
*/
|
|
206
|
-
const signInNeeded = (needed, mode) => Effect.gen(function* () {
|
|
207
|
-
const account =
|
|
208
|
-
|
|
209
|
-
|
|
231
|
+
const signInNeeded = (needed, mode, waited, link) => Effect.gen(function* () {
|
|
232
|
+
const account = accountText(needed);
|
|
233
|
+
const why = describeSignInWhy(needed.why) +
|
|
234
|
+
(waited !== undefined
|
|
235
|
+
? `, and the user did not save one within ${waited} seconds`
|
|
236
|
+
: '');
|
|
210
237
|
const details = {
|
|
211
238
|
account: needed.label,
|
|
212
239
|
...(needed.about !== undefined ? { about: needed.about } : {}),
|
|
@@ -215,19 +242,27 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
215
242
|
accountsFile: accountBook.file,
|
|
216
243
|
};
|
|
217
244
|
if (mode === 'serve' && Option.isSome(signIns)) {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
const signInUrl = link ??
|
|
246
|
+
(yield* signIns.value.begin({
|
|
247
|
+
label: needed.label,
|
|
248
|
+
about: needed.about,
|
|
249
|
+
origin: needed.origin,
|
|
250
|
+
url: needed.url,
|
|
251
|
+
})).link;
|
|
224
252
|
return yield* new Failure({
|
|
225
253
|
code: ExitCode.SignInNeeded,
|
|
226
254
|
reason: 'sign_in_needed',
|
|
227
255
|
message: `Nothing was started: ${account} ${why}. Ask the user to open the link below, ` +
|
|
228
|
-
'sign in there as that user and press Save sign-in, then start the same job
|
|
229
|
-
|
|
230
|
-
|
|
256
|
+
'sign in there as that user and press Save sign-in, then start the same job ' +
|
|
257
|
+
(waited !== undefined
|
|
258
|
+
? 'again, with waitSeconds to wait for the save.'
|
|
259
|
+
: 'again.'),
|
|
260
|
+
paths: [signInUrl, accountBook.file],
|
|
261
|
+
details: {
|
|
262
|
+
...details,
|
|
263
|
+
signInUrl,
|
|
264
|
+
...(waited !== undefined ? { waitedSeconds: waited } : {}),
|
|
265
|
+
},
|
|
231
266
|
});
|
|
232
267
|
}
|
|
233
268
|
const command = signInCommand(needed);
|
|
@@ -240,6 +275,76 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
240
275
|
details: { ...details, command },
|
|
241
276
|
});
|
|
242
277
|
});
|
|
278
|
+
/**
|
|
279
|
+
* Starts `start` (a run that may need a sign-in). With `serve`, a sign-in service and
|
|
280
|
+
* `waitSeconds`, a run that needs one opens it and waits for the person to save it, then
|
|
281
|
+
* starts as if called afresh; a cancel ends it. `waitSeconds` bounds the whole wait,
|
|
282
|
+
* opening the sign-in included: a call never waits for a save past it. When the time runs
|
|
283
|
+
* out it looks once more (a save may have landed just then), and then fails as
|
|
284
|
+
* `signInNeeded` says, with the link of the sign-in it waited on while that is open.
|
|
285
|
+
*/
|
|
286
|
+
const startSignedIn = (start, options,
|
|
287
|
+
/** When the call began (ms): its checks before this count against the wait too. */
|
|
288
|
+
since) => Effect.gen(function* () {
|
|
289
|
+
const mode = options.signIn ?? 'command';
|
|
290
|
+
const waitSeconds = options.waitSeconds ?? 0;
|
|
291
|
+
const deadline = since + waitSeconds * 1000;
|
|
292
|
+
const left = Clock.currentTimeMillis.pipe(Effect.map((now) => Duration.millis(Math.max(0, deadline - now))));
|
|
293
|
+
/** Started, or the `SignInNeeded` that stopped it. */
|
|
294
|
+
const attempt = start.pipe(Effect.map((started) => ({ started })), Effect.catchTag('SignInNeeded', (needed) => Effect.succeed({ needed })));
|
|
295
|
+
let tried = yield* attempt;
|
|
296
|
+
while (true) {
|
|
297
|
+
if ('started' in tried)
|
|
298
|
+
return tried.started;
|
|
299
|
+
const needed = tried.needed;
|
|
300
|
+
if (mode !== 'serve' || Option.isNone(signIns) || waitSeconds <= 0)
|
|
301
|
+
return yield* signInNeeded(needed, mode);
|
|
302
|
+
if (Duration.isZero(yield* left))
|
|
303
|
+
return yield* signInNeeded(needed, mode, waitSeconds);
|
|
304
|
+
// The opening counts against the deadline; the link is needed for any reply, so it is
|
|
305
|
+
// never cut short, but no save is waited for past the deadline after it.
|
|
306
|
+
const signIn = yield* signIns.value.begin({
|
|
307
|
+
label: needed.label,
|
|
308
|
+
about: needed.about,
|
|
309
|
+
origin: needed.origin,
|
|
310
|
+
url: needed.url,
|
|
311
|
+
});
|
|
312
|
+
const waiting = options.onSignInWait?.({ label: needed.label, link: signIn.link });
|
|
313
|
+
const remaining = yield* left;
|
|
314
|
+
const ended = yield* (Duration.isZero(remaining)
|
|
315
|
+
? Effect.succeedNone
|
|
316
|
+
: signIn.done.pipe(Effect.timeoutOption(remaining))).pipe(
|
|
317
|
+
// Whatever the wait does meanwhile ends with it.
|
|
318
|
+
waiting === undefined
|
|
319
|
+
? (self) => self
|
|
320
|
+
: (self) => Effect.raceFirst(self, waiting.pipe(Effect.andThen(Effect.never))));
|
|
321
|
+
// At the deadline, a save in progress finishes first and counts, if it does so within
|
|
322
|
+
// SAVE_SETTLE; one that stalls is treated as not done (the look below may still
|
|
323
|
+
// find its session).
|
|
324
|
+
const outcome = Option.isSome(ended)
|
|
325
|
+
? ended.value
|
|
326
|
+
: yield* signIn.outcome.pipe(Effect.timeoutOption(SAVE_SETTLE), Effect.map(Option.getOrUndefined));
|
|
327
|
+
if (outcome === 'cancelled')
|
|
328
|
+
return yield* new Failure({
|
|
329
|
+
code: ExitCode.SignInNeeded,
|
|
330
|
+
reason: 'sign_in_cancelled',
|
|
331
|
+
message: `Nothing was started: the sign-in to ${accountText(needed)} was cancelled. ` +
|
|
332
|
+
'Start the same job again only if the user wants to sign in; it gives a new link.',
|
|
333
|
+
paths: [accountBook.file],
|
|
334
|
+
details: { account: needed.label, accountsFile: accountBook.file },
|
|
335
|
+
});
|
|
336
|
+
// Saved: start again, as a call made now would.
|
|
337
|
+
tried = yield* attempt;
|
|
338
|
+
if (outcome === 'saved')
|
|
339
|
+
continue;
|
|
340
|
+
// Not saved in time, or it ended unsaved (left idle). The look just now may still
|
|
341
|
+
// find a session (saved as the time ran out); otherwise the reply gives the link of
|
|
342
|
+
// the sign-in still open, or a new one's.
|
|
343
|
+
if ('started' in tried)
|
|
344
|
+
return tried.started;
|
|
345
|
+
return yield* signInNeeded(tried.needed, mode, waitSeconds, outcome === undefined ? signIn.link : undefined);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
243
348
|
const accountsFailure = (error) => storageFailure(error);
|
|
244
349
|
return Operations.of({
|
|
245
350
|
doctor: runDoctor(projectRoot, undefined, Option.getOrUndefined(Option.map(updateCheck, (check) => check.doctorCheck))).pipe(Effect.provideService(Browser, browser), platform),
|
|
@@ -265,6 +370,8 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
265
370
|
return { path: file };
|
|
266
371
|
}),
|
|
267
372
|
startRun: (input, options) => Effect.gen(function* () {
|
|
373
|
+
// waitSeconds counts from here: the checks before a sign-in is opened count too.
|
|
374
|
+
const since = yield* Clock.currentTimeMillis;
|
|
268
375
|
const config = yield* platform(loadConfig(projectRoot));
|
|
269
376
|
if (!config && options.requireConfig)
|
|
270
377
|
return yield* missingConfig(projectRoot);
|
|
@@ -299,10 +406,9 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
299
406
|
const uploads = yield* platform(checkUploads(projectRoot, spec));
|
|
300
407
|
if (uploads.needed.length > 0)
|
|
301
408
|
return yield* filesNeeded(projectRoot, uploads.needed);
|
|
302
|
-
const jobId = yield* engine
|
|
303
|
-
|
|
304
|
-
StorageFailed
|
|
305
|
-
}));
|
|
409
|
+
const jobId = yield* startSignedIn(engine
|
|
410
|
+
.startRun(spec, { uploads: uploads.sources })
|
|
411
|
+
.pipe(Effect.catchTag('StorageFailed', (e) => Effect.fail(storageFailure(e)))), options, since);
|
|
306
412
|
return { jobId, runDir: storage.runDir(jobId) };
|
|
307
413
|
}),
|
|
308
414
|
awaitRun: (jobId) => ledgerOf(jobId, engine.awaitRun),
|
|
@@ -414,13 +520,13 @@ export class Operations extends Context.Service()('screw-bugs/Operations') {
|
|
|
414
520
|
message: 'This process cannot open a sign-in.',
|
|
415
521
|
});
|
|
416
522
|
const saved = (yield* accountBook.list.pipe(Effect.mapError(accountsFailure))).find((a) => a.label === label);
|
|
417
|
-
const { link } = yield* signIns.value.begin({
|
|
523
|
+
const { link, done } = yield* signIns.value.begin({
|
|
418
524
|
label,
|
|
419
525
|
about: about ?? saved?.about,
|
|
420
526
|
origin,
|
|
421
527
|
url: input.url,
|
|
422
528
|
});
|
|
423
|
-
return { link, done
|
|
529
|
+
return { link, done };
|
|
424
530
|
}),
|
|
425
531
|
removeAccount: (raw) => decodeLabel(raw).pipe(Effect.flatMap((label) => accountBook.remove(label).pipe(Effect.mapError(accountsFailure)))),
|
|
426
532
|
listRuns: (limit) => storage.listRuns(limit).pipe(Effect.mapError(storageFailure), Effect.flatMap((runs) => Effect.forEach(runs, (run) => run.ledger === undefined || !isOver(run.ledger)
|
package/dist/cli/report-links.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Clock, Context, Duration, Effect, FileSystem, Layer, Option, Path, Ref
|
|
|
2
2
|
import { ChildProcess, ChildProcessSpawner } from 'effect/process';
|
|
3
3
|
import { runsDir } from '../store-local/index.js';
|
|
4
4
|
import { isCi } from './environment.js';
|
|
5
|
-
import { fileUrl, folderOf, listen,
|
|
5
|
+
import { fileUrl, folderOf, listen, reportHost, serveEnabled, servesSameRoot, stablePortOf, urlHost, } from './report-server.js';
|
|
6
6
|
/**
|
|
7
7
|
* Report URLs for CLI commands (`run`, `status`, `report`, `findings`, `walkthrough`), which end
|
|
8
8
|
* long before anyone opens the page. The project's report server on its stable port (see
|
|
@@ -99,7 +99,7 @@ export class ReportLinks extends Context.Service()('screw-bugs/ReportLinks') {
|
|
|
99
99
|
return undefined;
|
|
100
100
|
const secret = folder.secret.value;
|
|
101
101
|
const port = options.preferredPort ?? stablePortOf(folder.rootId);
|
|
102
|
-
const base = `http://${
|
|
102
|
+
const base = `http://${urlHost(yield* reportHost)}:${port}`;
|
|
103
103
|
const answers = servesSameRoot(port, folder.rootId, secret);
|
|
104
104
|
if (yield* answers)
|
|
105
105
|
return base;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Context, Duration, Effect, FileSystem, Layer, Option, Path, Schema, Scope } from 'effect';
|
|
2
|
-
import { HttpServerRequest, HttpServerResponse, type HttpServerError } from 'effect/http';
|
|
2
|
+
import { HttpServerRequest, HttpServerResponse, HttpServer, type HttpServerError } from 'effect/http';
|
|
3
3
|
import { type ShareRoutes } from './share.js';
|
|
4
4
|
import { Failure } from './failure.js';
|
|
5
5
|
/**
|
|
6
6
|
* A local HTTP server for reports, for browsers that cannot open `file://` (the ones built into
|
|
7
|
-
* coding tools). It binds 127.0.0.1
|
|
7
|
+
* coding tools). It binds one address, 127.0.0.1 unless `SCREW_BUGS_REPORT_HOST` says another
|
|
8
|
+
* (see `reportHost`), and serves the runs folder read-only: only files with
|
|
8
9
|
* the extensions a report uses, never a directory listing, a dotfile, or anything outside the
|
|
9
10
|
* folder (also through symlinks). Range requests (206, 416) come from `HttpStaticServer`, so
|
|
10
11
|
* videos seek and play. In a process that can share (see `ShareSource`), it also answers the
|
|
@@ -12,6 +13,36 @@ import { Failure } from './failure.js';
|
|
|
12
13
|
* confirms it there.
|
|
13
14
|
*/
|
|
14
15
|
export declare const REPORT_HOST = "127.0.0.1";
|
|
16
|
+
/** Whether `host` (as `reportHost` gives it) is this machine's loopback. */
|
|
17
|
+
export declare const isLoopback: (host: string) => boolean;
|
|
18
|
+
/** A host as it goes in a URL: an IPv6 address in brackets. */
|
|
19
|
+
export declare const urlHost: (host: string) => string;
|
|
20
|
+
/**
|
|
21
|
+
* `SCREW_BUGS_REPORT_HOST`: where the report server listens, and the host in its links. 127.0.0.1
|
|
22
|
+
* unless set; set it to this machine's MagicDNS name or tailnet IP to open reports from another
|
|
23
|
+
* device (a name binds the one address it resolves to). Never every interface: `0.0.0.0` or `::`
|
|
24
|
+
* is a `Failure` (an empty value is unset).
|
|
25
|
+
*/
|
|
26
|
+
export declare const reportHost: Effect.Effect<string, Failure, never>;
|
|
27
|
+
/**
|
|
28
|
+
* A server's host setting (`SCREW_BUGS_REPORT_HOST`, `SCREW_BUGS_SIGN_IN_HOST`): one address or
|
|
29
|
+
* name of this machine, canonical (`canonicalHost`); 127.0.0.1 when unset or empty. Every
|
|
30
|
+
* spelling of every interface (`0.0.0.0`, `0`, `::`, …) is a `Failure` with `reason`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const hostSetting: (variable: string, reason: string) => Effect.Effect<string, Failure, never>;
|
|
33
|
+
/**
|
|
34
|
+
* The address a server set to `host` (from `variable`) listens on, as a URL writes it without
|
|
35
|
+
* brackets; a `Failure` with `reason` when that is every interface (a name that resolved to an
|
|
36
|
+
* unspecified address), or loopback for a name other than localhost (many Linux systems map the
|
|
37
|
+
* machine's own name to 127.0.1.1): its links would not open on another device.
|
|
38
|
+
*/
|
|
39
|
+
export declare const boundAddress: (address: Parameters<typeof HttpServer.formatAddress>[0], host: string, variable: string, reason: string) => Effect.Effect<string, never, never> | Effect.Effect<never, Failure, never>;
|
|
40
|
+
/**
|
|
41
|
+
* `host` as a browser writes it in a URL (lowercase, IPv4 shorthand such as `0` expanded, IPv6
|
|
42
|
+
* compressed), without IPv6 brackets; undefined for what is not a host. Links, the Host check and
|
|
43
|
+
* the address bound all use this one spelling, so a browser's Host header matches it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const canonicalHost: (host: string) => string | undefined;
|
|
15
46
|
/**
|
|
16
47
|
* Without `--port`, a project's report server takes a port from this range, the same one every
|
|
17
48
|
* time: a hash of the runs folder's real path picks it, so report links keep working across
|
|
@@ -69,11 +100,12 @@ export declare const stablePortOf: (rootId: string) => number;
|
|
|
69
100
|
/** What a report links to; anything else is a 404. */
|
|
70
101
|
export declare const SERVED_TYPES: Readonly<Record<string, string>>;
|
|
71
102
|
/**
|
|
72
|
-
* The request handler for `root`, answering only requests addressed to `port` on
|
|
73
|
-
* name
|
|
74
|
-
* function, read per request, so the handler can be made
|
|
103
|
+
* The request handler for `root`, answering only requests addressed to `port` on `host` (and, for
|
|
104
|
+
* a loopback host, on 127.0.0.1 or localhost) by name: a Host check, so a web page cannot reach it
|
|
105
|
+
* through DNS rebinding. `port` may be a function, read per request, so the handler can be made
|
|
106
|
+
* before the server knows its port.
|
|
75
107
|
*/
|
|
76
|
-
export declare const makeReportApp: (root: string, port: number | (() => number), secret?: Uint8Array<ArrayBufferLike> | undefined, share?: ShareRoutes | undefined) => Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest>, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/http/HttpPlatform").HttpPlatform | Path.Path>;
|
|
108
|
+
export declare const makeReportApp: (root: string, port: number | (() => number), secret?: Uint8Array<ArrayBufferLike> | undefined, share?: ShareRoutes | undefined, host?: string | undefined, boundAt?: (() => string | undefined) | undefined) => Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, never, HttpServerRequest.HttpServerRequest>, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/http/HttpPlatform").HttpPlatform | Path.Path>;
|
|
77
109
|
/** The URL of `file` (an absolute path inside `root`) on a server at `base`, or undefined. */
|
|
78
110
|
export declare const fileUrl: (path: Path.Path, base: string, root: string, file: string) => string | undefined;
|
|
79
111
|
/**
|
|
@@ -87,7 +119,7 @@ export declare const listen: (root: string, port: number, secret?: Uint8Array, o
|
|
|
87
119
|
readonly port: number;
|
|
88
120
|
readonly held: () => number;
|
|
89
121
|
}) => Effect.Effect<void>;
|
|
90
|
-
}) => Effect.Effect<string, import("effect/PlatformError").PlatformError | HttpServerError.ServeError, Scope.Scope>;
|
|
122
|
+
}) => Effect.Effect<string, Failure | import("effect/PlatformError").PlatformError | HttpServerError.ServeError, Scope.Scope>;
|
|
91
123
|
/** How long to wait for whatever holds a port to answer the identity challenge. */
|
|
92
124
|
export declare const IDENTITY_TIMEOUT: Duration.Duration;
|
|
93
125
|
/**
|
|
@@ -127,7 +159,7 @@ export declare const folderOf: (root: string, options?: {
|
|
|
127
159
|
* down); else serves with `fallback` (by default on a free port). `probe` is for tests.
|
|
128
160
|
*/
|
|
129
161
|
export declare const serveOnPreferredPort: (root: string, preferred: number, folder: Folder, options?: {
|
|
130
|
-
readonly fallback?: Effect.Effect<string, HttpServerError.ServeError, Scope.Scope | FileSystem.FileSystem | Path.Path>;
|
|
162
|
+
readonly fallback?: Effect.Effect<string, HttpServerError.ServeError | Failure, Scope.Scope | FileSystem.FileSystem | Path.Path>;
|
|
131
163
|
readonly probe?: Effect.Effect<boolean>;
|
|
132
164
|
}) => Effect.Effect<{
|
|
133
165
|
base: string;
|
|
@@ -138,7 +170,7 @@ export declare const serveOnPreferredPort: (root: string, preferred: number, fol
|
|
|
138
170
|
} | {
|
|
139
171
|
base: string;
|
|
140
172
|
on: "fallback";
|
|
141
|
-
}, import("effect/PlatformError").PlatformError | HttpServerError.ServeError, FileSystem.FileSystem | Path.Path | Scope.Scope>;
|
|
173
|
+
}, Failure | import("effect/PlatformError").PlatformError | HttpServerError.ServeError, FileSystem.FileSystem | Path.Path | Scope.Scope>;
|
|
142
174
|
/**
|
|
143
175
|
* Serves `root` while the scope is open. With `port`, exactly there (0 picks a free one), failing
|
|
144
176
|
* if it is taken. Without, on `preferred` (by default the folder's stable port, see
|