proofed-cli 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +176 -122
  2. package/dist/action/requests.js +130 -0
  3. package/dist/{server.js → action/server.js} +17 -3
  4. package/dist/changes.js +7 -1
  5. package/dist/{args.js → check/args.js} +31 -3
  6. package/dist/check/cache.js +89 -0
  7. package/dist/{check.js → check/check.js} +86 -40
  8. package/dist/{doctor.js → check/doctor.js} +55 -19
  9. package/dist/check/help.js +139 -0
  10. package/dist/{list.js → check/list.js} +27 -15
  11. package/dist/{pipeline.js → check/pipeline.js} +106 -68
  12. package/dist/{render.js → check/render.js} +22 -15
  13. package/dist/check/run.js +277 -0
  14. package/dist/check/targetfilter.js +10 -0
  15. package/dist/check/textcheck.js +162 -0
  16. package/dist/env.js +6 -0
  17. package/dist/fix/agent.js +21 -0
  18. package/dist/fix/claude.js +30 -0
  19. package/dist/fix/codex.js +71 -0
  20. package/dist/fix/fixsetup.js +76 -0
  21. package/dist/fix/fixtarget.js +48 -0
  22. package/dist/fix/models.js +67 -0
  23. package/dist/github.js +62 -14
  24. package/dist/integrations/claude-stop.js +104 -0
  25. package/dist/integrations/cli.js +63 -0
  26. package/dist/integrations/mcp.js +130 -0
  27. package/dist/kane/creditmeter.js +104 -0
  28. package/dist/kane/kane.js +131 -0
  29. package/dist/kane/kaneauth.js +84 -0
  30. package/dist/kane/kaneversion.js +13 -0
  31. package/dist/paths.js +32 -0
  32. package/dist/process.js +65 -0
  33. package/dist/proofed.js +34 -16
  34. package/dist/{live.js → report/live.js} +1 -1
  35. package/dist/{livefile.js → report/livefile.js} +1 -1
  36. package/dist/{report.js → report/report.js} +105 -125
  37. package/dist/report/reportdata.js +120 -0
  38. package/dist/{result.js → report/result.js} +12 -7
  39. package/dist/{runfile.js → report/runfile.js} +2 -2
  40. package/dist/report/runresult.js +5 -0
  41. package/dist/scenarios.js +41 -19
  42. package/dist/secrets.js +74 -0
  43. package/dist/{cdp.js → targets/cdp.js} +20 -6
  44. package/dist/targets/chrome.js +98 -0
  45. package/dist/{clip.js → targets/clip.js} +21 -11
  46. package/dist/{precheck.js → targets/precheck.js} +53 -20
  47. package/dist/targets/preparetarget.js +350 -0
  48. package/dist/{recorder.js → targets/recorder.js} +154 -19
  49. package/dist/{serve.js → targets/serve.js} +9 -13
  50. package/dist/{target.js → targets/target.js} +42 -7
  51. package/dist/targets/targetchecks.js +139 -0
  52. package/dist/timing.js +25 -0
  53. package/dist/types.js +1 -0
  54. package/dist/which.js +26 -13
  55. package/docs/cli.md +370 -0
  56. package/package.json +10 -5
  57. package/dist/cache.js +0 -48
  58. package/dist/chrome.js +0 -77
  59. package/dist/help.js +0 -133
  60. package/dist/kane.js +0 -75
  61. package/dist/kaneauth.js +0 -48
  62. package/dist/models.js +0 -44
  63. package/dist/requests.js +0 -58
  64. package/dist/run.js +0 -173
  65. /package/dist/{deps.js → targets/deps.js} +0 -0
package/dist/kane.js DELETED
@@ -1,75 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { createInterface } from "node:readline";
3
- import { adopt } from "./children.js";
4
- const isStep = (e) => "step" in e && "status" in e;
5
- const isRunEnd = (e) => "type" in e && e.type === "run_end";
6
- export function runKane(o) {
7
- const args = [
8
- "run",
9
- o.objective,
10
- "--agent",
11
- "--url",
12
- o.url,
13
- "--cdp-endpoint",
14
- o.cdpEndpoint,
15
- "--timeout",
16
- String(o.timeoutSeconds ?? 300),
17
- ...(o.username && o.accessKey ? ["--username", o.username, "--access-key", o.accessKey] : []),
18
- ];
19
- // Own process group: Kane spawns runner and Playwright children that outlive a plain kill.
20
- const proc = spawn(process.env.KANE_CLI ?? "kane-cli", args, { stdio: ["ignore", "pipe", "pipe"], detached: true });
21
- const killGroup = (signal) => {
22
- try {
23
- if (proc.pid)
24
- process.kill(-proc.pid, signal);
25
- }
26
- catch {
27
- // Already gone.
28
- }
29
- };
30
- const release = adopt({ kill: killGroup, exited: new Promise((r) => proc.once("exit", r)) });
31
- const steps = [];
32
- let end;
33
- let stderr = "";
34
- proc.stderr.on("data", (d) => (stderr += d));
35
- const lines = createInterface({ input: proc.stdout });
36
- const drained = new Promise((r) => lines.once("close", r));
37
- lines.on("line", (line) => {
38
- let event;
39
- try {
40
- event = JSON.parse(line);
41
- }
42
- catch {
43
- return; // Kane occasionally prints a non-JSON notice; it carries nothing we use.
44
- }
45
- if (typeof event !== "object" || event === null)
46
- return;
47
- if (isStep(event)) {
48
- steps.push(event);
49
- o.onStep?.(event);
50
- }
51
- else if (isRunEnd(event)) {
52
- end = event;
53
- o.onEnd?.(event);
54
- }
55
- });
56
- // Kane's own --timeout counts only active time; when its backend stalls a run can hang for
57
- // a quarter of an hour, so we also enforce a wall-clock limit.
58
- let timedOut = false;
59
- let hardKill;
60
- const watchdog = setTimeout(() => {
61
- timedOut = true;
62
- killGroup("SIGTERM");
63
- hardKill = setTimeout(() => killGroup("SIGKILL"), 5000);
64
- }, (o.wallTimeoutSeconds ?? 360) * 1000);
65
- // "exit", not "close": an orphaned grandchild can hold stdout open long after Kane is gone.
66
- return new Promise((resolve) => proc.on("exit", async (exitCode) => {
67
- clearTimeout(watchdog);
68
- clearTimeout(hardKill);
69
- // Let the last lines (run_end) through, but don't wait on a stream an orphan keeps open.
70
- await Promise.race([drained, new Promise((r) => setTimeout(r, 2000))]);
71
- killGroup("SIGKILL");
72
- release();
73
- resolve({ steps, end, exitCode, stderr, timedOut });
74
- }));
75
- }
package/dist/kaneauth.js DELETED
@@ -1,48 +0,0 @@
1
- // Whether Kane can start a run: signed in with `kane-cli login`, or given LT_USERNAME and
2
- // LT_ACCESS_KEY, which Proofed passes to every run. `proofed check` asks before it builds anything:
3
- // without a working login every run ends at once, and a retry ends the same way.
4
- import { execFile } from "node:child_process";
5
- export const LOGIN_FIX = "kane-cli login (or export LT_USERNAME and LT_ACCESS_KEY from TestMu: Settings → Keys)";
6
- export const KEYS_FIX = "LT_USERNAME and LT_ACCESS_KEY: copy both again from TestMu (Settings → Keys), in the GitHub repository secrets too, or unset them to use kane-cli login";
7
- // What `kane-cli run` prints on stderr when it can't start for want of a login (kane-cli 0.10):
8
- // "Not authenticated. Run: kane-cli login --oauth, or kane-cli login --username <user> --access-key <key>"
9
- // and `kane-cli balance`: 'Not authenticated [prod]. Run "kane-cli login" first.'
10
- export const NOT_SIGNED_IN = /\bnot authenticated\b|\bnot (?:logged|signed) in\b|\btoken (?:missing|expired|invalid)\b/i;
11
- // What TestMu answers a login or keys it doesn't accept, through `kane-cli balance` (kane-cli 0.10):
12
- // 'Error: Credit balance request failed: 401 {"error":"authentication failed"}'
13
- const REJECTED = /\b40[13]\b|\bauthentication failed\b|\bcredentials not valid\b|\bunauthori[sz]ed\b/i;
14
- export const kaneCredentials = (env) => env.LT_USERNAME?.trim() && env.LT_ACCESS_KEY?.trim() ? ["--username", env.LT_USERNAME.trim(), "--access-key", env.LT_ACCESS_KEY.trim()] : [];
15
- const ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
16
- const NOTICE = /^(?:update available|skill update available)\b/i;
17
- // The line Kane gives its reason in, without the update notices it prints around it.
18
- const reasonIn = (output) => output
19
- .replace(ANSI, "")
20
- .split("\n")
21
- .map((l) => l.trim().replace(/^error:\s*/i, ""))
22
- .filter((l) => l && !NOTICE.test(l))
23
- .at(-1) ?? "";
24
- // `kane-cli balance` is free and asks TestMu with the login or the keys a run would use, so a
25
- // missing, expired or wrong one shows here and not after the build. `whoami` only reads the local
26
- // login: it can't tell a wrong key from a good one. A balance that can't be started, doesn't answer
27
- // or fails for another reason (no network) says nothing either way, and the check goes on.
28
- export function kaneLogin(bin, env, timeout = 20_000) {
29
- const creds = kaneCredentials(env);
30
- return new Promise((resolve) => {
31
- execFile(bin, ["balance", ...creds], { env, timeout }, (error, stdout, stderr) => {
32
- const output = `${stdout}\n${stderr}`.replace(ANSI, "");
33
- if (!error) {
34
- return resolve(creds.length ? { state: "keys", detail: "LT_USERNAME and LT_ACCESS_KEY work; Kane uses them", balance: output } : { state: "signed_in", detail: "signed in", balance: output });
35
- }
36
- const e = error;
37
- if (e.killed || typeof e.code !== "number")
38
- return resolve({ state: "unknown", detail: `kane-cli balance didn't answer${e.killed ? ` within ${timeout / 1000} s` : `: ${e.message}`}` });
39
- const said = reasonIn(output);
40
- if (REJECTED.test(output) || NOT_SIGNED_IN.test(output)) {
41
- return resolve(creds.length
42
- ? { state: "keys_rejected", detail: `Kane rejected LT_USERNAME and LT_ACCESS_KEY${said ? ` (${said})` : ""}` }
43
- : { state: "not_signed_in", detail: REJECTED.test(output) ? `the login was rejected${said ? ` (${said})` : ""}` : "not signed in" });
44
- }
45
- resolve({ state: "unknown", detail: `kane-cli balance failed${said ? `: ${said}` : ` with exit ${e.code}`}` });
46
- });
47
- });
48
- }
package/dist/models.js DELETED
@@ -1,44 +0,0 @@
1
- // The models "Fix with Claude" can run, by short name. Also imported by the dashboard (site/),
2
- // so this file has no imports and nothing Node-specific.
3
- export const MODELS = [
4
- { name: "haiku", id: "claude-haiku-5-5" },
5
- { name: "sonnet", id: "claude-sonnet-5-5" },
6
- { name: "opus", id: "claude-opus-5-5" },
7
- { name: "fable", id: "claude-fable-5-2" },
8
- ];
9
- export const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
10
- // What the fixer uses when the repo sets nothing.
11
- export const DEFAULT_FIXER = { model: "claude-haiku-5-5", effort: "xhigh" };
12
- export const isEffort = (word) => EFFORTS.includes(word);
13
- // A full model ID as Claude Code takes it, e.g. claude-opus-5-1. Whether it exists is up to Anthropic.
14
- export const isModelId = (text) => /^claude-[a-z0-9][a-z0-9.-]{2,60}$/.test(text);
15
- // "claude-opus-5-5" → "Opus 5.5". An ID that doesn't follow that pattern is shown as is.
16
- export function modelLabel(id) {
17
- const match = /^claude-([a-z]+)-(\d+)-(\d+)(?:-\d{8})?$/.exec(id);
18
- if (!match)
19
- return id;
20
- const [, family = "", major, minor] = match;
21
- return `${family[0].toUpperCase()}${family.slice(1)} ${major}.${minor}`;
22
- }
23
- // Who fixed it, for the PR comment: "Claude Opus 5.5, high effort". An unknown ID is shown as written.
24
- export function describeFixer({ model, effort }) {
25
- const label = modelLabel(model);
26
- return `${label === model ? `\`${model}\`` : `Claude ${label}`}, ${effort} effort`;
27
- }
28
- // "opus" → the latest Opus; "opus 5.1" → claude-opus-5-1; "claude-opus-5-1" → as written.
29
- export function parseModel(words) {
30
- const [first = "", version, ...rest] = words.map((w) => w.toLowerCase());
31
- const family = MODELS.find((m) => m.name === first);
32
- if (family && version === undefined)
33
- return { model: family.id };
34
- if (family && rest.length === 0 && version && /^\d+([.-]\d+)?$/.test(version)) {
35
- return { model: `claude-${family.name}-${version.replace(".", "-")}` };
36
- }
37
- if (words.length === 1 && isModelId(first))
38
- return { model: first };
39
- return {
40
- error: `Proofed doesn't know the model \`${words.join(" ")}\`. Use ${MODELS.map((m) => `\`${m.name}\``).join(", ")} ` +
41
- "for the latest version, add a version (`opus 5.5`), or give a full model ID (`claude-opus-5-5`). " +
42
- `Effort goes last and is optional: ${EFFORTS.map((e) => `\`${e}\``).join(", ")}.`,
43
- };
44
- }
package/dist/requests.js DELETED
@@ -1,58 +0,0 @@
1
- import { isEffort, parseModel } from "./models.js";
2
- // "/proofed" in a PR comment re-runs the check, which also gives a PR opened before Proofed was
3
- // added its first run. "/proofed <what to check>" has Kane check just that. A slash command,
4
- // not "@proofed": that name belongs to someone else on GitHub and would mention them.
5
- const COMMAND = /(?:^|\s)\/proofed\b([\s\S]*)/i;
6
- export function parseCommand(comment) {
7
- const match = COMMAND.exec(comment);
8
- return match ? match[1].trim() : undefined;
9
- }
10
- // "/proofed fix [model] [effort]" has Claude fix the broken scenarios, with that model this once.
11
- // Only the first line counts, so a note under the command doesn't become part of the model name.
12
- export function parseFix(command) {
13
- const words = (command.split("\n")[0] ?? "").trim().split(/\s+/).filter(Boolean);
14
- if (words[0]?.toLowerCase() !== "fix")
15
- return undefined;
16
- const rest = words.slice(1);
17
- const last = rest.at(-1)?.toLowerCase() ?? "";
18
- const effort = isEffort(last) ? last : undefined;
19
- const modelWords = effort ? rest.slice(0, -1) : rest;
20
- if (modelWords.length === 0)
21
- return { effort };
22
- const choice = parseModel(modelWords);
23
- return "error" in choice ? choice : { model: choice.model, effort };
24
- }
25
- // What the PR description asks to have checked. HTML comments (PR templates) are dropped, and a
26
- // long description is a changelog rather than a request, so it's left alone.
27
- export function descriptionRequest(body) {
28
- const text = (body ?? "").replace(/<!--[\s\S]*?-->/g, "").trim();
29
- return text && text.length <= 1500 ? text : undefined;
30
- }
31
- // Any short description becomes a request, and many ask for nothing ("Will be closed, not merged.").
32
- // Left to itself Kane then improvises: it signs in, ends up on GitHub's OAuth page, and the report
33
- // says the test may be wrong. A /proofed comment is always a request, so it gets no such way out.
34
- const MAY_ASK_NOTHING = "If the text above doesn't describe something a user can see or do in this app, stop right away " +
35
- "without clicking anything: there is nothing to check. Never sign in, and never leave the app's own pages to get there.";
36
- // The description asked for nothing Kane could check: not a result of the PR, only a line under the report.
37
- export const nothingAsked = (r) => r.scenario.id === "asked-in-description" && r.outcome === "unsure";
38
- const NAMES = {
39
- description: "What the PR description asks",
40
- comment: "What the /proofed comment asks",
41
- terminal: "What you asked to check",
42
- };
43
- // "terminal": `proofed check "<text>"`, run by a person or a coding agent on their own machine.
44
- export function askedScenario(where, text) {
45
- return {
46
- id: where === "terminal" ? "asked" : `asked-in-${where}`,
47
- file: "",
48
- name: NAMES[where],
49
- paths: [],
50
- url: "/",
51
- objective: (where === "terminal"
52
- ? `The developer of this app asked for this to be checked:\n\n${text}\n\n`
53
- : `The author of this pull request asked for this to be checked:\n\n${text}\n\n`) +
54
- "Open the app and check exactly that in the browser, the way a user would. It passes only if what they " +
55
- "asked about actually works; the page loading is not enough." +
56
- (where === "description" ? ` ${MAY_ASK_NOTHING}` : ""),
57
- };
58
- }
package/dist/run.js DELETED
@@ -1,173 +0,0 @@
1
- import { mkdirSync, rmSync, writeFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { stopping } from "./children.js";
4
- import { launchChrome } from "./chrome.js";
5
- import { makeClip } from "./clip.js";
6
- import { live } from "./live.js";
7
- import { NOT_SIGNED_IN } from "./kaneauth.js";
8
- import { log as logLine } from "./log.js";
9
- import { runKane } from "./kane.js";
10
- import { NOTHING_CHECKED } from "./runfile.js";
11
- import { startRecorder } from "./recorder.js";
12
- // Failures of the browser plumbing rather than of the app: the run is retried, never reported as a bug.
13
- const INFRA = /Screenshot failed|TimeoutError|TargetClosedError|has been closed|ECONNREFUSED|ECONNRESET|socket hang up|Project and folder must be configured/i;
14
- // What Kane said when it left without a verdict. Kane puts the cause on an "error:" line and its
15
- // hints after it, so the last lines alone can start in the middle of a hint.
16
- export function kaneError(stderr) {
17
- const lines = stderr.trim().split("\n");
18
- const cause = lines.findLast((l) => /^\s*(?:error|fatal)\b/i.test(l));
19
- return cause ? cause.trim().replace(/^(?:error|fatal):\s*/i, "") : lines.slice(-5).join("\n");
20
- }
21
- // Words of what the run checked last: the quoted expectation of a failed check, or the values
22
- // Kane read off the page when it passed. The clip ends zoomed on the element that holds them.
23
- const STOP = new Set(["that", "this", "with", "from", "have", "after", "then", "should", "shows", "page", "into", "when", "each", "there", "them", "than", "what", "which", "only", "also", "visible", "displayed"]);
24
- export function focusWords(end) {
25
- const text = end.status === "passed"
26
- ? Object.values(end.final_state ?? {})
27
- .filter((v) => typeof v === "string" && !v.startsWith("http"))
28
- .join(" ")
29
- : (/["“«]([^"”»]+)["”»]/.exec(end.reason ?? "")?.[1] ?? "");
30
- const words = (text.toLowerCase().replace(/[‘’]/g, "'").match(/[\p{L}\p{Sc}\d][\p{L}\p{N}\p{Sc}.,%'-]*/gu) ?? [])
31
- .map((w) => w.replace(/[.,]+$/, ""))
32
- .filter((w) => (/\d/.test(w) ? w.length >= 2 : w.length >= 4) && !STOP.has(w));
33
- return [...new Set(words)];
34
- }
35
- export { NOTHING_CHECKED };
36
- // Each step's remark starts with its kind ("navigate: …", "wait: …", "analyze: …", "assert: …").
37
- // Only an assert compares the page with what the scenario expects.
38
- const checked = (steps) => steps.some((s) => s.status === "done" && /^assert:/i.test(s.remark));
39
- // Kane read the page and the scenario's own check came out false. When the app is wrong all over
40
- // (a changed threshold shown in its banner too), Kane sides with the app and blames the test; the
41
- // scenario is what the app was meant to do, so that is a failure. runScenario runs it a second time.
42
- const refuted = (steps) => steps.some((s) => s.status === "failed" && /^assert:/i.test(s.remark));
43
- export function outcomeOf(end, steps) {
44
- if (!end || INFRA.test(end.reason ?? ""))
45
- return "error";
46
- // A vague objective lets Kane open the page, wait, and call that a pass.
47
- if (end.status === "passed")
48
- return checked(steps) ? "passed" : "unsure";
49
- return end.verdict?.family === "automation_bug" && !refuted(steps) ? "unsure" : "failed";
50
- }
51
- // An unsure run where Kane said "passed": nothing was checked, as opposed to Kane doubting the test.
52
- export const unchecked = (r) => r.outcome === "unsure" && r.end?.status === "passed";
53
- export const scenarioDoubted = (r) => r.outcome === "failed" && r.end?.verdict?.family === "automation_bug";
54
- // All the credits a scenario took, the runs before the last one included.
55
- export const creditsOf = (r) => (r.end?.credits_consumed ?? 0) + (r.earlierCredits ?? 0);
56
- const RECHECK = "the check failed, but Kane blames the scenario; running it once more to be sure";
57
- // Kane is good at reaching a goal, so on its own it routes around a broken button (a key press, another
58
- // link) and passes. A user who clicks the button and gets the wrong screen has found a bug.
59
- const NO_WORKAROUNDS = "Do each step once, the way it is described. If a click or a key press does something other than what " +
60
- "the step expects, the check fails: don't retry it, and don't reach the goal another way (other " +
61
- "buttons, links, keyboard shortcuts, typing the URL). Waiting for a slow page to load is fine.";
62
- export function kaneObjective(objective) {
63
- return `${objective}\n\n${NO_WORKAROUNDS}`;
64
- }
65
- export async function runScenario(scenario, o) {
66
- let earlier = 0;
67
- const again = (last, why) => {
68
- earlier += last.end?.credits_consumed ?? 0;
69
- logLine(`[${scenario.id}] ${why}`);
70
- o.onEvent?.({ type: "retry", id: scenario.id, error: why });
71
- return runOnce(scenario, o);
72
- };
73
- const settle = async (result) => {
74
- for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !result.notSignedIn && !stopping(); i++) {
75
- result = await again(result, result.error ?? "infra error");
76
- }
77
- return result;
78
- };
79
- let result = await settle(await runOnce(scenario, o));
80
- // Kane gives the same verdict for a wrong value all over the app and for a page it misread (a
81
- // heading that is there, reported as not visible). A wrong value is wrong again on a second
82
- // run; a misreading rarely is. So the second run decides, whatever it comes to.
83
- if (scenarioDoubted(result) && !stopping()) {
84
- result = await settle(await again(result, RECHECK));
85
- }
86
- return earlier ? { ...result, earlierCredits: earlier } : result;
87
- }
88
- async function runOnce(scenario, o) {
89
- const log = (line) => logLine(`[${scenario.id}] ${line}`);
90
- const dir = join(o.outDir, scenario.id);
91
- rmSync(dir, { recursive: true, force: true });
92
- mkdirSync(dir, { recursive: true });
93
- let chrome;
94
- try {
95
- chrome = await launchChrome({ headless: o.headless ?? true });
96
- }
97
- catch (e) {
98
- // Counts as a browser hiccup: retried, and reported as "couldn't finish", never as a bug.
99
- return { scenario, outcome: "error", steps: [], end: undefined, clip: undefined, error: String(e) };
100
- }
101
- let stills;
102
- try {
103
- const recorder = await startRecorder(chrome.endpoint, join(dir, "frames"));
104
- live.scenario(scenario.id, { status: "running", steps: [], startedAt: Date.now() });
105
- // A still for each click or typing with the cursor on it: the frame from just before it, or a
106
- // new screenshot when there is none to use. Between actions, one every couple of seconds.
107
- const still = (action) => {
108
- if (live.on())
109
- void recorder.snapshot().then((s) => s && live.frame(scenario.id, s, action));
110
- };
111
- recorder.onAction = (before) => {
112
- if (before)
113
- live.frame(scenario.id, before, true);
114
- else
115
- still(true);
116
- };
117
- stills = setInterval(() => still(false), 2000);
118
- let focus = Promise.resolve(undefined);
119
- const kane = await runKane({
120
- objective: kaneObjective(scenario.objective),
121
- url: new URL(scenario.url, o.baseUrl).href,
122
- cdpEndpoint: chrome.endpoint,
123
- username: o.username,
124
- accessKey: o.accessKey,
125
- onStep: (s) => {
126
- live.step(scenario.id, s);
127
- o.onEvent?.({ type: "step", id: scenario.id, step: s });
128
- if (s.status !== "running" && s.remark)
129
- log(`${s.status === "failed" ? "✗" : "·"} ${s.remark}`);
130
- },
131
- onEnd: (end) => (focus = recorder.locate(focusWords(end))),
132
- });
133
- clearInterval(stills);
134
- const focusRect = await focus;
135
- // Drop the blank about:blank frames from before Kane's first navigation.
136
- const start = Date.parse(kane.steps[0]?.ts ?? "") / 1000 || 0;
137
- const recorded = recorder.stop();
138
- const frames = recorded.frames.filter((f) => f.time >= start);
139
- const outcome = outcomeOf(kane.end, kane.steps);
140
- // Kane left without a verdict: all it said goes to the log, where the cause can be read later.
141
- if (!kane.end)
142
- log(`Kane exited with code ${kane.exitCode} and no verdict${kane.timedOut ? " (cut off by Proofed's time limit)" : ""}. Its stderr:\n${kane.stderr.trim() || "(empty)"}`);
143
- // Kane's reason for such a pass is "Objective completed"; the report, the run file and the fixer show ours.
144
- const end = kane.end && outcome === "unsure" && kane.end.status === "passed" ? { ...kane.end, reason: NOTHING_CHECKED } : kane.end;
145
- log(`→ ${outcome}${end?.reason ? `: ${end.reason}` : ""} (${frames.length} frames)`);
146
- const error = kane.timedOut
147
- ? "Kane stopped responding and the run was cut off"
148
- : (kane.end?.reason ?? kaneError(kane.stderr));
149
- const film = { frames, actions: recorded.actions, focus: focusRect };
150
- writeFileSync(join(dir, "film.json"), JSON.stringify(film));
151
- // A step starts when Kane announces it (the "running" event), not when it reports it done.
152
- const announced = new Map(kane.steps.filter((s) => s.status === "running").map((s) => [s.step, s.ts]));
153
- const marks = kane.steps.map((s) => Date.parse(announced.get(s.step) ?? s.ts) / 1000);
154
- const made = await makeClip({ ...film, marks, endpoint: chrome.endpoint }, join(dir, "clip")).catch((e) => {
155
- log(`clip failed: ${String(e)}`);
156
- return undefined;
157
- });
158
- const clip = made && { mp4: made.mp4, gif: made.gif, jpg: made.jpg };
159
- return {
160
- scenario,
161
- outcome,
162
- steps: kane.steps.map((s, i) => ({ ...s, at: made?.marks[i] })),
163
- end,
164
- clip,
165
- ...(outcome === "error" && { error }),
166
- ...(!kane.end && NOT_SIGNED_IN.test(kane.stderr) && { notSignedIn: true }),
167
- };
168
- }
169
- finally {
170
- clearInterval(stills);
171
- chrome.close();
172
- }
173
- }
File without changes