proofed-cli 0.1.1 → 0.1.3

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 CHANGED
@@ -100,7 +100,7 @@ The repo's model is set in the [dashboard](https://proofed.neptunescodm.workers.
100
100
 
101
101
  `proofed check` runs the same check on your machine, against the change you haven't pushed yet: the scenarios its files touch, in Chrome, with Kane CLI. A coding agent can run it before it says a UI change is done.
102
102
 
103
- It needs Node 24 or later, Chrome, [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli) signed in (`kane-cli login`) and ffmpeg for the clips.
103
+ It needs Node 22.18 or later, Chrome, [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli) signed in (`kane-cli login`) and ffmpeg for the clips.
104
104
 
105
105
  Install the registry package with one manager:
106
106
 
@@ -111,7 +111,7 @@ Install the registry package with one manager:
111
111
  | Update | `npm install -g proofed-cli@latest` | `pnpm add -g proofed-cli@latest` | `bun add -g proofed-cli@latest` |
112
112
  | Uninstall | `npm uninstall -g proofed-cli` | `pnpm remove -g proofed-cli` | `bun remove -g proofed-cli` |
113
113
 
114
- The command is `proofed`; `proofed doctor` says what else is missing. It runs on Node 24 or later with any of the three, bun included, and an older Node gets an error that says so. The package is built JavaScript with no dependencies and no install scripts. From a clone, `npm link` runs the TypeScript source instead.
114
+ The command is `proofed`; `proofed doctor` says what else is missing. It runs on Node 22.18 or later with any of the three, bun included, and an older Node gets an error that says so. The package is built JavaScript with no dependencies and no install scripts. From a clone, `npm link` runs the TypeScript source instead.
115
115
 
116
116
  In the app's repo:
117
117
 
@@ -121,7 +121,7 @@ In the app's repo:
121
121
  | `proofed list` | Every scenario, whether the change touches it and whether its pass is cached |
122
122
  | `proofed check` | Runs the scenarios the change touches; `proofed check "the cart total updates"` checks just that |
123
123
 
124
- The change is everything since the merge base with the default branch (`origin/HEAD`, else `origin/main`, or `--base`), uncommitted and untracked files included. The URL and the commands that build and serve the app come from `--url`, `--build` and `--serve`, then `PROOFED_URL`, `PROOFED_BUILD` and `PROOFED_SERVE`, then `.proofed/config.json`, then the Proofed step of the repo's workflow. In a repo that already runs Proofed on its PRs, `proofed check` needs no flags. If the app isn't running, Proofed builds and starts it, and stops it at the end. If something already answers at the URL and a build is configured, the check stops rather than test what may be an old build; `--reuse` tests it anyway.
124
+ The change is everything since the merge base with the default branch (`origin/HEAD`, else `origin/main`, or `--base`), uncommitted and untracked files included. The URL and the commands that install, build and serve the app come from `--url`, `--install`, `--build` and `--serve`, then `PROOFED_URL`, `PROOFED_INSTALL`, `PROOFED_BUILD` and `PROOFED_SERVE`, then `.proofed/config.json`, then the Proofed step of the repo's workflow. In a repo that already runs Proofed on its PRs, `proofed check` needs no flags. Before anything is built, the check asks TestMu, through `kane-cli balance` (free), whether it accepts the login or the `LT_USERNAME` and `LT_ACCESS_KEY` the runs would use; if not, it stops at once with exit 3: `kane_not_signed_in` with `kane-cli login` as the fix, or `kane_keys_rejected` when the keys are wrong or expired. If the app isn't running, Proofed starts it and stops it at the end: it installs the dependencies first when `node_modules` is missing or older than `package.json` or the lockfile (with the install command found as above, else the app's package manager), then builds, then serves. If something already answers at the URL and a build is configured, the check stops rather than test what may be an old build; `--reuse` tests it anyway.
125
125
 
126
126
  A passed scenario isn't run again until its file, the URL, the base commit or a changed file in its `paths` changes. `--dry-run` shows what would run and the credit estimate, for free. In a terminal the scenarios update in place; in a pipe each event is one line, with a "still running" line at least every 30 seconds. From a real run on the demo store with the free shipping threshold changed to €60. Kane blamed the scenario, so the check ran twice, and the credits are for both runs. Paths are relative, and the credits in the "failed" line (56.8 in that run) are rounded as the CLI rounds them now:
127
127
 
@@ -161,7 +161,7 @@ Re-run what broke: proofed check --only free-shipping --url http://localhost:417
161
161
 
162
162
  A first run is estimated at 30 Kane credits per scenario. Later estimates use the last reported cost. Credits are what Kane reported for the runs; the account balance can drop slightly more. An interrupted run can spend credits before Kane reports them.
163
163
 
164
- `--json` prints one JSON document on stdout and the progress on stderr. Every run also writes it to `.proofed-out/result.json`, next to the clips; the folder has its own `.gitignore`. The exit code is 0 when everything checked passed, 1 when a scenario failed, 2 when nothing failed but something wasn't checked, 3 when the check couldn't start (the message says why and how to fix it) and 130 on Ctrl-C or a closed terminal, which stops Kane, Chrome and the app first.
164
+ `--json` prints one JSON document on stdout and the progress on stderr. Every run also writes it to `.proofed-out/result.json`, next to the clips; the folder has its own `.gitignore`. The exit code is 0 when everything checked passed, 1 when a scenario failed, 2 when nothing failed but something wasn't checked, 3 when the check couldn't start (the message says why and how to fix it; running it again unchanged won't help) and 130 on Ctrl-C or a closed terminal, which stops Kane, Chrome and the app first.
165
165
 
166
166
  `failedCheck: "scenario_doubted"` means a scenario's check failed, but Kane believes it is out of date. `diagnosis` is Kane's opinion; `suggestion` and `next` say to update the scenario if the app change was intended, otherwise fix the app. Such a failure is run a second time before it is reported, at the scenario's cost again, and the second run is the result: Kane gives the same verdict when it misreads a page that is fine, and a misreading rarely repeats. A check that fails both times is a failure (exit 1). `notChecked: "scenario_doubted"` is used when Kane doubted the scenario without a failed check (exit 2).
167
167
 
@@ -252,21 +252,21 @@ Each fix is a few lines, found by a run that went wrong.
252
252
 
253
253
  ## Code
254
254
 
255
- Node 24+ runs the checkout's TypeScript directly. The GitHub Action needs no build or package install.
255
+ Node 22.18+ runs the checkout's TypeScript directly. The GitHub Action needs no build or package install.
256
256
  `pnpm build` emits the CLI and its imports to `dist/` for npm. `npm pack` builds it automatically.
257
257
  `pnpm typecheck` and `pnpm test` check the source. `pnpm check:package` builds a tarball, checks its
258
258
  contents, installs it into a temporary prefix and runs its version and help. It removes its temp files.
259
259
 
260
- To release, confirm the version in `package.json` (currently `0.1.1`); published versions cannot be reused. From a clean checkout with Node 24+:
260
+ To release, confirm the version in `package.json` (currently `0.1.3`); published versions cannot be reused. From a clean checkout with Node 22.18+:
261
261
 
262
262
  ```sh
263
263
  pnpm install --frozen-lockfile
264
264
  npm login --registry=https://registry.npmjs.org/
265
265
  npm whoami --registry=https://registry.npmjs.org/
266
266
  npm publish --access public --registry=https://registry.npmjs.org/
267
- npm view proofed-cli@0.1.1 version bin engines dist.tarball --registry=https://registry.npmjs.org/
268
- npx --yes proofed-cli@0.1.1 --version
269
- npx --yes proofed-cli@0.1.1 --help
267
+ npm view proofed-cli@0.1.3 version bin engines dist.tarball --registry=https://registry.npmjs.org/
268
+ npx --yes proofed-cli@0.1.3 --version
269
+ npx --yes proofed-cli@0.1.3 --help
270
270
  ```
271
271
 
272
272
  Use the chosen version in the last three commands. `npm publish` runs typecheck, tests and the package
@@ -1,11 +1,23 @@
1
+ // 22.18 is the first Node 22 that runs TypeScript without a flag (a checkout runs the source); the
2
+ // built package needs path.matchesGlob, from 22.5.
3
+ const MIN = [22, 18];
4
+ const NEED = `Node ${MIN.join(".")} or newer`;
5
+
6
+ const supported = (version) => {
7
+ const [major, minor] = version.split(".").map(Number);
8
+ return major > MIN[0] || (major === MIN[0] && minor >= MIN[1]);
9
+ };
10
+
1
11
  const checkNode = (version = process.versions.node) => {
2
12
  if (process.versions.bun) {
3
- console.error("proofed: Node 24 or newer is required. Install Node 24+ from https://nodejs.org/ and put node on PATH. Run proofed without --bun.");
13
+ console.error(`proofed: ${NEED} is required. Install Node ${MIN[0]} or newer from https://nodejs.org/ and put node on PATH. Run proofed without --bun.`);
4
14
  process.exit(3);
5
15
  }
6
- if (Number(version.split(".")[0]) >= 24) return;
7
- console.error(`proofed: Node 24 or newer is required (found ${version}). Install Node 24+ from https://nodejs.org/ and run this command again.`);
16
+ if (supported(version)) return;
17
+ console.error(`proofed: ${NEED} is required (found ${version}). Install Node ${MIN[0]} or newer from https://nodejs.org/ (any current LTS) and run this command again.`);
8
18
  process.exit(3);
9
19
  };
10
20
 
11
21
  module.exports = checkNode;
22
+ module.exports.supported = supported;
23
+ module.exports.NEED = NEED;
package/dist/args.js CHANGED
@@ -12,6 +12,7 @@ const APP = {
12
12
  url: { type: "string" },
13
13
  serve: { type: "string" },
14
14
  build: { type: "string" },
15
+ install: { type: "string" },
15
16
  };
16
17
  export const FLAGS = {
17
18
  check: {
@@ -123,6 +124,7 @@ function parseFlags(command, args) {
123
124
  url: str("url"),
124
125
  serve: str("serve"),
125
126
  build: str("build"),
127
+ install: str("install"),
126
128
  base: str("base"),
127
129
  only,
128
130
  all: on("all"),
@@ -147,6 +149,7 @@ const EXAMPLES = {
147
149
  url: "http://localhost:5173",
148
150
  serve: '"npm run dev"',
149
151
  build: '"npm run build"',
152
+ install: '"npm install"',
150
153
  base: "origin/main",
151
154
  only: "free-shipping,checkout",
152
155
  out: ".proofed-out",
package/dist/check.js CHANGED
@@ -8,6 +8,7 @@ import { CACHE_FILE, DEFAULT_CREDITS, cacheKey, estimate, readCache, writeCache
8
8
  import { findBase, localChanges, mergeBaseOf, repoRoot } from "./changes.js";
9
9
  import { killChildren, stopChildren } from "./children.js";
10
10
  import { findChrome } from "./chrome.js";
11
+ import { KEYS_FIX, kaneLogin, LOGIN_FIX } from "./kaneauth.js";
11
12
  import { setLog } from "./log.js";
12
13
  import { runAll } from "./pipeline.js";
13
14
  import { colorOn, LiveView, PlainView } from "./render.js";
@@ -49,6 +50,8 @@ export function makeView(flags, io) {
49
50
  }
50
51
  return new PlainView(io.stdout, { color: colorOn(io.env, false), err: io.stderr });
51
52
  }
53
+ const notSignedIn = (message = "Kane CLI is not signed in, so it can't run the scenarios. Nothing was built or run.") => new SetupError("kane_not_signed_in", message, `${LOGIN_FIX}, then run the check again.`);
54
+ const keysRejected = (detail) => new SetupError("kane_keys_rejected", `${detail}, so Kane can't run the scenarios. Nothing was built or run.`, `${KEYS_FIX}, then run the check again.`);
52
55
  const fromNote = (s) => (s.from.startsWith("--") ? "" : ` (url from ${s.from})`);
53
56
  // Flags that say where the app and the scenarios are and how to run, so a printed command runs
54
57
  // the same way. Not --no-cache or --dry-run: those were about this run.
@@ -57,6 +60,7 @@ function rerunFlags(flags) {
57
60
  ["--url", flags.url],
58
61
  ["--serve", flags.serve],
59
62
  ["--build", flags.build],
63
+ ["--install", flags.install],
60
64
  ["--serve-timeout", flags.serveTimeout?.toString()],
61
65
  ["--base", flags.base],
62
66
  ["--scenarios", flags.scenarios],
@@ -115,7 +119,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
115
119
  }
116
120
  else if (doc.dryRun) {
117
121
  for (const d of doc.scenarios)
118
- view.info(`${d.cached ? "cached: " : "would run:"} ${d.id} (${d.name})${d.cached ? "" : `, about ${d.estimatedCredits} credits`}`);
122
+ view.info(`${d.cached ? "cached: " : "would run:"} ${d.id} (${d.name})${d.cached ? "" : `, about ${Math.round((d.estimatedCredits ?? 0) * 100) / 100} credits`}`);
119
123
  view.info(`${doc.summary}. Dry run: nothing ran, no credits spent.`);
120
124
  view.info(doc.next);
121
125
  view.close();
@@ -153,7 +157,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
153
157
  throw scenariosMissing(dir, flags, io, "check");
154
158
  if (!text && loaded.errors.length) {
155
159
  const [first] = loaded.errors;
156
- throw new SetupError("scenario_invalid", loaded.errors.map((e) => `${e.file}: ${e.message}`).join("\n"), `Fix the frontmatter of ${first.file} (see proofed list).`);
160
+ throw new SetupError("scenario_invalid", loaded.errors.map((e) => `${e.file}: ${e.message}`).join("\n"), `Correct the frontmatter of ${first.file} (see proofed list).`);
157
161
  }
158
162
  const all = loaded.scenarios;
159
163
  const base = text ? undefined : findBase(io.cwd, flags.base);
@@ -202,7 +206,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
202
206
  return buildDoc({ ...common, items: [], skipped, url: null, idle: { summary, next: `Nothing to check. To run every scenario anyway: ${sameCommand(rerun, "--all")}` } });
203
207
  }
204
208
  }
205
- const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build }, env: io.env, cwd: io.cwd });
209
+ const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build, install: flags.install }, env: io.env, cwd: io.cwd });
206
210
  const url = target.url?.value;
207
211
  if (url !== undefined && !isHttpUrl(url)) {
208
212
  throw new SetupError("url_invalid", `"${url}" (${target.url.from}) is not an http(s) URL.`, "Pass a full URL, e.g. --url http://localhost:5173");
@@ -264,6 +268,11 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
264
268
  if (!url) {
265
269
  throw new SetupError("no_url", "Proofed doesn't know where the app runs.", `Pass --url http://localhost:5173 (and --serve "npm run dev" to have Proofed start it), set PROOFED_URL, or write .proofed/config.json: { "url": "http://localhost:5173", "serve": "npm run dev" }`);
266
270
  }
271
+ const login = await kaneLogin(kane.path, io.env);
272
+ if (login.state === "not_signed_in")
273
+ throw notSignedIn(login.detail === "not signed in" ? undefined : `Kane CLI can't run the scenarios: ${login.detail}. Nothing was built or run.`);
274
+ if (login.state === "keys_rejected")
275
+ throw keysRejected(login.detail);
267
276
  ensureOut(out);
268
277
  const runLog = join(out, "run.log");
269
278
  writeFileSync(runLog, "");
@@ -290,6 +299,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
290
299
  url,
291
300
  serve: target.serve.value,
292
301
  build: target.build?.value,
302
+ install: target.install,
293
303
  cwd: target.dir,
294
304
  logFile,
295
305
  timeoutSeconds: flags.serveTimeout ?? 60,
@@ -324,6 +334,9 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
324
334
  writeCache(cacheFile, cache);
325
335
  };
326
336
  const results = await runAll(toRun, out, plan.concurrency, { baseUrl: url, headless: !flags.headed, onEvent });
337
+ // A login can run out between the login check and the runs; running the check again wouldn't help then either.
338
+ if (results.some((r) => r.notSignedIn))
339
+ throw notSignedIn("Kane CLI refused to run a scenario: it is not signed in. The scenarios it refused weren't checked.");
327
340
  const byId = new Map(results.map((r) => [r.scenario.id, r]));
328
341
  return docOf(selected.map((s) => {
329
342
  const r = byId.get(s.id);
package/dist/deps.js ADDED
@@ -0,0 +1,90 @@
1
+ // The app's dependencies, before Proofed builds and serves it: a fresh clone has none, and its build
2
+ // fails on the first import. They are installed only when node_modules is missing or older than
3
+ // package.json or the lockfile, never on every check: `npm ci` would wipe a working node_modules.
4
+ import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
5
+ import { basename, dirname, join, resolve } from "node:path";
6
+ const LOCKS = [
7
+ ["pnpm-lock.yaml", "pnpm install"],
8
+ ["bun.lock", "bun install"],
9
+ ["bun.lockb", "bun install"],
10
+ ["yarn.lock", "yarn install"],
11
+ ["package-lock.json", "npm install"],
12
+ ["npm-shrinkwrap.json", "npm install"],
13
+ ];
14
+ // What a manager writes when it installs. pnpm leaves .modules.yaml alone on an install that changes
15
+ // nothing, so Proofed stamps its own installs too.
16
+ const STAMP = ".proofed-installed";
17
+ const MARKERS = [STAMP, ".modules.yaml", ".package-lock.json", ".yarn-state.yml", ".yarn-integrity"];
18
+ const mtime = (file) => {
19
+ try {
20
+ return statSync(file).mtimeMs;
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ };
26
+ // The app's folder, then the folders above it up to the repository root: a workspace keeps its
27
+ // lockfile, and pnpm its install state, at the root.
28
+ function upward(dir) {
29
+ const dirs = [];
30
+ for (let d = resolve(dir);; d = dirname(d)) {
31
+ dirs.push(d);
32
+ if (existsSync(join(d, ".git")) || dirname(d) === d)
33
+ return dirs;
34
+ }
35
+ }
36
+ function lockOf(dir) {
37
+ for (const d of upward(dir)) {
38
+ for (const [file, install] of LOCKS)
39
+ if (existsSync(join(d, file)))
40
+ return { file: join(d, file), dir: d, install };
41
+ }
42
+ return undefined;
43
+ }
44
+ function managerOf(dir) {
45
+ try {
46
+ const name = /^(npm|pnpm|yarn|bun)@/.exec(JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).packageManager)?.[1];
47
+ return name && `${name} install`;
48
+ }
49
+ catch {
50
+ return undefined;
51
+ }
52
+ }
53
+ // Why the dependencies need installing, or undefined when they don't (or it can't be told, as for
54
+ // an app without package.json).
55
+ export function depsMissing(dir) {
56
+ const manifest = mtime(join(dir, "package.json"));
57
+ if (manifest === undefined)
58
+ return undefined;
59
+ if (!existsSync(join(dir, "node_modules")))
60
+ return "node_modules is missing";
61
+ const lock = lockOf(dir);
62
+ const homes = [...new Set([dir, lock?.dir ?? dir].map((d) => join(d, "node_modules")))];
63
+ const times = homes.flatMap((h) => MARKERS.map((m) => mtime(join(h, m)))).filter((t) => t !== undefined);
64
+ if (!times.length)
65
+ return undefined;
66
+ const installed = Math.max(...times);
67
+ if (lock && (mtime(lock.file) ?? 0) > installed)
68
+ return `${basename(lock.file)} changed since the last install`;
69
+ if (manifest > installed)
70
+ return "package.json changed since the last install";
71
+ return undefined;
72
+ }
73
+ export function stampInstall(dir) {
74
+ try {
75
+ writeFileSync(join(dir, "node_modules", STAMP), `${new Date().toISOString()}\n`);
76
+ }
77
+ catch {
78
+ // No node_modules after all (an install that put them elsewhere): the next check asks again.
79
+ }
80
+ }
81
+ // The command that installs them: the one configured, else the app's package manager.
82
+ export function installCommand(dir, configured) {
83
+ if (configured)
84
+ return configured;
85
+ const declared = managerOf(dir);
86
+ if (declared)
87
+ return { value: declared, from: "packageManager in package.json" };
88
+ const lock = lockOf(dir);
89
+ return lock ? { value: lock.install, from: basename(lock.file) } : { value: "npm install", from: "package.json" };
90
+ }
package/dist/doctor.js CHANGED
@@ -1,11 +1,14 @@
1
1
  // `proofed doctor`: whether `proofed check` can run here, and the exact fix for what can't. It only
2
- // calls Kane's free commands (--version, whoami, balance); no run, no credits.
2
+ // calls Kane's free commands (--version, balance); no run, no credits.
3
3
  import { execFile } from "node:child_process";
4
+ import { createRequire } from "node:module";
4
5
  import { promisify } from "node:util";
5
6
  import { DEFAULT_CREDITS } from "./cache.js";
6
7
  import { scenariosDirOf } from "./check.js";
7
8
  import { findBase } from "./changes.js";
8
9
  import { findChrome } from "./chrome.js";
10
+ import { depsMissing, installCommand } from "./deps.js";
11
+ import { KEYS_FIX, kaneLogin, LOGIN_FIX } from "./kaneauth.js";
9
12
  import { colorOn, palette, stripAnsi } from "./render.js";
10
13
  import { readScenarios } from "./scenarios.js";
11
14
  import { answers } from "./serve.js";
@@ -13,6 +16,8 @@ import { SetupError } from "./setuperror.js";
13
16
  import { isHttpUrl, resolveTarget } from "./target.js";
14
17
  import { findKane, findOnPath } from "./which.js";
15
18
  const run = promisify(execFile);
19
+ // The launcher's own gate, from bin/ next to both src/ and dist/.
20
+ const { supported: nodeSupported, NEED: NODE_NEED } = createRequire(import.meta.url)("../bin/node-version.cjs");
16
21
  // Kane prints update notices around its answer; only the answer counts.
17
22
  async function kane(bin, args, env) {
18
23
  try {
@@ -27,8 +32,8 @@ async function kane(bin, args, env) {
27
32
  export async function doctorChecks(flags, io) {
28
33
  const checks = [];
29
34
  const add = (name, status, detail, fix) => checks.push({ name, status, detail, ...(fix && { fix }) });
30
- const major = Number(process.versions.node.split(".")[0]);
31
- add("Node", major >= 24 ? "ok" : "fail", `v${process.versions.node}`, major >= 24 ? undefined : "Install Node 24 or newer from https://nodejs.org/.");
35
+ const nodeOk = nodeSupported(process.versions.node);
36
+ add("Node", nodeOk ? "ok" : "fail", `v${process.versions.node}`, nodeOk ? undefined : `Install ${NODE_NEED} from https://nodejs.org/ (any current LTS).`);
32
37
  try {
33
38
  const base = findBase(io.cwd, flags.base);
34
39
  if (base.rev)
@@ -48,27 +53,27 @@ export async function doctorChecks(flags, io) {
48
53
  else
49
54
  add("Scenarios", "ok", `${loaded.scenarios.length} in ${dir}`);
50
55
  for (const e of loaded.errors)
51
- add("Scenario", "fail", `${e.file}: ${e.message}`, `Fix the frontmatter of ${e.file}: --- name, paths, url --- then the objective.`);
56
+ add("Scenario", "fail", `${e.file}: ${e.message}`, `Correct the frontmatter of ${e.file}: --- name, paths, url --- then the objective.`);
52
57
  const found = findKane(io.env);
53
- const creds = io.env.LT_USERNAME && io.env.LT_ACCESS_KEY ? ["--username", io.env.LT_USERNAME, "--access-key", io.env.LT_ACCESS_KEY] : [];
54
58
  if (!found.path) {
55
59
  add("Kane CLI", "fail", `not found (${found.from})`, io.env.KANE_CLI ? "Point KANE_CLI at the kane-cli binary, or unset it." : "npm install -g @testmuai/kane-cli");
56
60
  }
57
61
  else {
58
- const [version, who, balance] = await Promise.all([
59
- kane(found.path, ["--version"], io.env),
60
- kane(found.path, ["whoami"], io.env),
61
- kane(found.path, ["balance", ...creds], io.env),
62
- ]);
62
+ const [version, login] = await Promise.all([kane(found.path, ["--version"], io.env), kaneLogin(found.path, io.env)]);
63
63
  add("Kane CLI", "ok", `${found.path}, ${/\d+\.\d+\.\d+\S*/.exec(version.text)?.[0] ?? "version unknown"}`);
64
- if (creds.length)
65
- add("Kane login", "ok", "LT_USERNAME and LT_ACCESS_KEY are set; Kane uses them");
66
- else if (who.ok)
67
- add("Kane login", "ok", "signed in");
64
+ if (login.state === "not_signed_in")
65
+ add("Kane login", "fail", login.detail, LOGIN_FIX);
66
+ else if (login.state === "keys_rejected")
67
+ add("Kane login", "fail", login.detail, KEYS_FIX);
68
+ else if (login.state === "unknown")
69
+ add("Kane login", "warn", login.detail, "kane-cli balance");
68
70
  else
69
- add("Kane login", "fail", "not signed in", "kane-cli login (or export LT_USERNAME and LT_ACCESS_KEY from TestMu: Settings → Keys)");
70
- const left = /credits:\s*([\d.,]+)/i.exec(balance.text)?.[1];
71
- if (balance.ok && left) {
71
+ add("Kane login", "ok", login.detail);
72
+ const left = /credits:\s*([\d.,]+)/i.exec(login.balance ?? "")?.[1];
73
+ if (login.state === "not_signed_in" || login.state === "keys_rejected") {
74
+ add("Credits", "warn", "unknown until Kane accepts the login");
75
+ }
76
+ else if (left) {
72
77
  const n = Number(left.replace(/,/g, ""));
73
78
  add("Credits", n >= DEFAULT_CREDITS ? "ok" : "warn", `${Math.floor(n)} available; a first run is estimated at ${DEFAULT_CREDITS} credits`, n >= DEFAULT_CREDITS ? undefined : "Top up your TestMu account before running scenarios.");
74
79
  }
@@ -81,7 +86,7 @@ export async function doctorChecks(flags, io) {
81
86
  const ffmpeg = findOnPath("ffmpeg", io.env);
82
87
  add("ffmpeg", ffmpeg ? "ok" : "warn", ffmpeg ?? "not found: no clips, the verdicts still work", ffmpeg ? undefined : process.platform === "darwin" ? "brew install ffmpeg" : "sudo apt-get install ffmpeg");
83
88
  try {
84
- const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build }, env: io.env, cwd: io.cwd });
89
+ const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build, install: flags.install }, env: io.env, cwd: io.cwd });
85
90
  const url = target.url;
86
91
  if (!url) {
87
92
  add("App", "fail", "no URL", 'Pass --url http://localhost:5173 to proofed check, set PROOFED_URL, or write .proofed/config.json: { "url": "http://localhost:5173", "serve": "npm run dev" }');
@@ -91,6 +96,14 @@ export async function doctorChecks(flags, io) {
91
96
  }
92
97
  else {
93
98
  add("App URL", "ok", `${url.value} (from ${url.from})`);
99
+ const missing = target.serve && depsMissing(target.dir);
100
+ if (missing) {
101
+ const install = installCommand(target.dir, target.install);
102
+ add("Install", "ok", `${missing}: proofed check runs ${install.value} (from ${install.from}) before the build`);
103
+ }
104
+ else if (target.install) {
105
+ add("Install", "ok", `${target.install.value} (from ${target.install.from}), run when node_modules is missing or out of date`);
106
+ }
94
107
  if (target.build)
95
108
  add("Build", "ok", `${target.build.value} (from ${target.build.from})`);
96
109
  if (target.serve)
package/dist/help.js CHANGED
@@ -4,11 +4,11 @@ It runs the plain-English scenarios in .proofed/scenarios/ that your local chang
4
4
  Usage
5
5
  proofed check [text] [flags] Run the scenarios the local change touches, or check just [text]
6
6
  proofed list [flags] Every scenario: does the change touch it, is a pass cached
7
- proofed doctor [flags] Is Kane CLI, Chrome, ffmpeg and the app ready
7
+ proofed doctor [flags] Is Kane CLI (and its login), Chrome, ffmpeg and the app ready
8
8
  proofed <command> --help The flags of one command
9
9
  proofed --version
10
10
 
11
- Install (macOS and Linux; Node 24+ is required, including with bun)
11
+ Install (macOS and Linux; Node 22.18+ is required, including with bun)
12
12
  npm install -g proofed-cli pnpm add -g proofed-cli bun add -g proofed-cli
13
13
  Run without installing: npx proofed-cli | pnpm dlx proofed-cli | bunx proofed-cli
14
14
  Update: npm install -g proofed-cli@latest | pnpm add -g proofed-cli@latest | bun add -g proofed-cli@latest
@@ -42,7 +42,7 @@ Exit codes
42
42
  0 everything that ran passed, or nothing needed to run
43
43
  1 at least one scenario failed
44
44
  2 nothing failed, but at least one was not_checked or error
45
- 3 Proofed couldn't run: usage, setup, app not reachable
45
+ 3 Proofed couldn't run: usage, setup (such as no Kane login), app not reachable
46
46
  130 interrupted
47
47
 
48
48
  For AI agents
@@ -53,7 +53,9 @@ For AI agents
53
53
  failedCheck: "scenario_doubted" means the check failed but Kane believes it is out of date.
54
54
  Diagnosis is Kane's opinion. If the app change was intended, update the scenario; otherwise fix the app.
55
55
  Never treat "not_checked" as a pass: fix the scenario or tell the user why Kane doubts it.
56
- On "error", run the "rerun" command once more. On exit 3, do what error.fix says.`;
56
+ On "error", run the "rerun" command once more. On exit 3, do what error.fix says; running the
57
+ same command again without that won't help. kane_not_signed_in needs the user: kane-cli login;
58
+ kane_keys_rejected needs working LT_USERNAME and LT_ACCESS_KEY from the user.`;
57
59
  const CHECK = `proofed check [text] [flags]
58
60
 
59
61
  Runs the scenarios the local change touches, in Chrome, with Kane, and says what broke.
@@ -71,6 +73,9 @@ Where the app is (flag, then env, then .proofed/config.json, then the Proofed wo
71
73
  --url <url> Where it runs (env PROOFED_URL), e.g. http://localhost:5173
72
74
  --serve <cmd> Starts it when the URL doesn't answer; stopped at the end (env PROOFED_SERVE)
73
75
  --build <cmd> Runs before --serve (env PROOFED_BUILD)
76
+ --install <cmd> Installs the app's dependencies before the build, when node_modules is
77
+ missing or older than package.json or the lockfile (env PROOFED_INSTALL;
78
+ default: the workflow's install, else the app's package manager)
74
79
  --reuse With a build set, a URL that already answers stops the check (exit 3): it
75
80
  may be an old build. --reuse tests what is running; its passes aren't cached
76
81
  --serve-timeout <s> How long the URL gets to answer after --serve (default 60)
@@ -99,6 +104,10 @@ JSON (also written to <out>/result.json)
99
104
  Proofed couldn't run: {ok: false, exitCode: 3, error: {code, message, fix}}
100
105
  Interrupted: the same shape with exitCode 130 and scenarios [...] for what had finished
101
106
 
107
+ Before anything is built, the Kane login is checked with TestMu (kane-cli balance, free): without
108
+ one the check stops with exit 3 and error.code "kane_not_signed_in"; with LT_USERNAME and
109
+ LT_ACCESS_KEY that TestMu rejects, error.code "kane_keys_rejected".
110
+
102
111
  Exit codes: 0 passed, 1 failed, 2 not_checked or error, 3 couldn't run, 130 interrupted.`;
103
112
  const LIST = `proofed list [flags]
104
113
 
@@ -118,7 +127,7 @@ Checks Node, git, the scenarios, Kane CLI (installed, signed in, credits left),
118
127
  problem comes with the command or step that fixes it. Uses only Kane's free commands.
119
128
  Exit 0 when proofed check can run, else 3.
120
129
 
121
- --url, --serve, --build As for proofed check
122
- --scenarios <dir> Default .proofed/scenarios
123
- --json {ok, exitCode, checks [{name, status: ok | warn | fail, detail, fix}]}`;
130
+ --url, --serve, --build, --install As for proofed check
131
+ --scenarios <dir> Default .proofed/scenarios
132
+ --json {ok, exitCode, checks [{name, status: ok | warn | fail, detail, fix}]}`;
124
133
  export const helpText = (command) => (command === "check" ? CHECK : command === "list" ? LIST : command === "doctor" ? DOCTOR : MAIN);
@@ -0,0 +1,48 @@
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/run.js CHANGED
@@ -4,12 +4,20 @@ import { stopping } from "./children.js";
4
4
  import { launchChrome } from "./chrome.js";
5
5
  import { makeClip } from "./clip.js";
6
6
  import { live } from "./live.js";
7
+ import { NOT_SIGNED_IN } from "./kaneauth.js";
7
8
  import { log as logLine } from "./log.js";
8
9
  import { runKane } from "./kane.js";
9
10
  import { NOTHING_CHECKED } from "./runfile.js";
10
11
  import { startRecorder } from "./recorder.js";
11
12
  // Failures of the browser plumbing rather than of the app: the run is retried, never reported as a bug.
12
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
+ }
13
21
  // Words of what the run checked last: the quoted expectation of a failed check, or the values
14
22
  // Kane read off the page when it passed. The clip ends zoomed on the element that holds them.
15
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"]);
@@ -63,7 +71,7 @@ export async function runScenario(scenario, o) {
63
71
  return runOnce(scenario, o);
64
72
  };
65
73
  const settle = async (result) => {
66
- for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !stopping(); i++) {
74
+ for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !result.notSignedIn && !stopping(); i++) {
67
75
  result = await again(result, result.error ?? "infra error");
68
76
  }
69
77
  return result;
@@ -137,7 +145,7 @@ async function runOnce(scenario, o) {
137
145
  log(`→ ${outcome}${end?.reason ? `: ${end.reason}` : ""} (${frames.length} frames)`);
138
146
  const error = kane.timedOut
139
147
  ? "Kane stopped responding and the run was cut off"
140
- : (kane.end?.reason ?? kane.stderr.trim().split("\n").slice(-5).join("\n"));
148
+ : (kane.end?.reason ?? kaneError(kane.stderr));
141
149
  const film = { frames, actions: recorded.actions, focus: focusRect };
142
150
  writeFileSync(join(dir, "film.json"), JSON.stringify(film));
143
151
  // A step starts when Kane announces it (the "running" event), not when it reports it done.
@@ -155,6 +163,7 @@ async function runOnce(scenario, o) {
155
163
  end,
156
164
  clip,
157
165
  ...(outcome === "error" && { error }),
166
+ ...(!kane.end && NOT_SIGNED_IN.test(kane.stderr) && { notSignedIn: true }),
158
167
  };
159
168
  }
160
169
  finally {
package/dist/serve.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { spawn } from "node:child_process";
5
5
  import { closeSync, openSync, readFileSync, writeSync } from "node:fs";
6
6
  import { adopt } from "./children.js";
7
+ import { depsMissing, installCommand, stampInstall } from "./deps.js";
7
8
  import { SetupError } from "./setuperror.js";
8
9
  // Any HTTP answer below 500 means a server is there; a proxy in front of nothing gives 502.
9
10
  export async function answers(url, timeout = 2000) {
@@ -47,12 +48,22 @@ function start(command, cwd, logFile) {
47
48
  return { proc, exited, kill, release };
48
49
  }
49
50
  export async function startApp(o) {
51
+ const missing = depsMissing(o.cwd);
52
+ if (missing) {
53
+ const install = installCommand(o.cwd, o.install);
54
+ o.onPhase?.(`Installing dependencies (${missing}): ${install.value}`);
55
+ const code = await start(install.value, o.cwd, o.logFile).exited;
56
+ if (code !== 0) {
57
+ throw new SetupError("install_failed", `The install command exited with code ${code}: ${install.value} (from ${install.from}, in ${o.cwd})\n${tail(o.logFile)}`, `Make it install, or set the command with --install "<command>". Full output: ${o.logFile}`);
58
+ }
59
+ stampInstall(o.cwd);
60
+ }
50
61
  if (o.build) {
51
62
  o.onPhase?.(`Building the app: ${o.build}`);
52
63
  const build = start(o.build, o.cwd, o.logFile);
53
64
  const code = await build.exited;
54
65
  if (code !== 0) {
55
- throw new SetupError("build_failed", `The build command exited with code ${code}: ${o.build}\n${tail(o.logFile)}`, `Fix the build, or pass --build "<command>". Full output: ${o.logFile}`);
66
+ throw new SetupError("build_failed", `The build command exited with code ${code}: ${o.build}\n${tail(o.logFile)}`, `Make the build pass, or set another one with --build "<command>". Full output: ${o.logFile}`);
56
67
  }
57
68
  }
58
69
  o.onPhase?.(`Starting the app: ${o.serve}`);
@@ -70,7 +81,7 @@ export async function startApp(o) {
70
81
  while (!(await answers(o.url, 1000))) {
71
82
  if (exitCode !== undefined) {
72
83
  await stop();
73
- throw new SetupError("serve_failed", `The serve command exited with code ${exitCode} before ${o.url} answered: ${o.serve}\n${tail(o.logFile)}`, `Fix the serve command, or pass --serve "<command>". Full output: ${o.logFile}`);
84
+ throw new SetupError("serve_failed", `The serve command exited with code ${exitCode} before ${o.url} answered: ${o.serve}\n${tail(o.logFile)}`, `Make the serve command start the app, or set another one with --serve "<command>". Full output: ${o.logFile}`);
74
85
  }
75
86
  if (Date.now() > deadline) {
76
87
  await stop();
package/dist/target.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import { existsSync, readdirSync, readFileSync } from "node:fs";
6
6
  import { join, resolve } from "node:path";
7
7
  import { SetupError } from "./setuperror.js";
8
- const KEYS = ["url", "serve", "build"];
8
+ const KEYS = ["url", "serve", "build", "install"];
9
9
  export const CONFIG_FILE = ".proofed/config.json";
10
10
  // "localhost:5173" parses as a URL with the scheme "localhost:", so parsing alone isn't the test.
11
11
  export function isHttpUrl(value) {
@@ -25,7 +25,7 @@ export function readConfig(cwd) {
25
25
  data = JSON.parse(readFileSync(file, "utf8"));
26
26
  }
27
27
  catch (e) {
28
- throw new SetupError("config_invalid", `${CONFIG_FILE} is not valid JSON: ${e instanceof Error ? e.message : e}`, `Fix ${CONFIG_FILE}; it holds { "url", "serve", "build" }.`);
28
+ throw new SetupError("config_invalid", `${CONFIG_FILE} is not valid JSON: ${e instanceof Error ? e.message : e}`, `Correct the JSON in ${CONFIG_FILE}; it holds { "url", "serve", "build", "install" }.`);
29
29
  }
30
30
  if (typeof data !== "object" || data === null)
31
31
  return {};
@@ -104,10 +104,13 @@ export function resolveTarget({ flags, env, cwd }) {
104
104
  const workflow = readWorkflow(cwd);
105
105
  const layers = [
106
106
  { from: (k) => `--${k}`, values: flags },
107
- { from: (k) => `PROOFED_${k.toUpperCase()}`, values: { url: env.PROOFED_URL?.trim(), serve: env.PROOFED_SERVE?.trim(), build: env.PROOFED_BUILD?.trim() } },
107
+ {
108
+ from: (k) => `PROOFED_${k.toUpperCase()}`,
109
+ values: { url: env.PROOFED_URL?.trim(), serve: env.PROOFED_SERVE?.trim(), build: env.PROOFED_BUILD?.trim(), install: env.PROOFED_INSTALL?.trim() },
110
+ },
108
111
  { from: () => CONFIG_FILE, values: readConfig(cwd) },
109
112
  ...(workflow
110
- ? [{ from: () => workflow.file, values: { url: workflow.inputs.url, serve: workflow.inputs.serve, build: workflow.inputs.build }, dir: workflow.inputs["working-directory"] }]
113
+ ? [{ from: () => workflow.file, values: { url: workflow.inputs.url, serve: workflow.inputs.serve, build: workflow.inputs.build, install: workflow.inputs.install }, dir: workflow.inputs["working-directory"] }]
111
114
  : []),
112
115
  ];
113
116
  const pick = (key, from = layers) => {
@@ -120,13 +123,16 @@ export function resolveTarget({ flags, env, cwd }) {
120
123
  };
121
124
  const url = pick("url");
122
125
  const serve = pick("serve");
123
- // A build belongs with its serve command: the workflow's build is for the workflow's serve. One
124
- // given as a flag or in the environment applies to whichever serve is used.
125
- const build = pick("build", layers.slice(0, 2)) ?? (serve && pick("build", [serve.layer]));
126
+ // A build and an install belong with their serve command: the workflow's build is for the
127
+ // workflow's serve. One given as a flag or in the environment applies to whichever serve is used.
128
+ const withServe = (key) => pick(key, layers.slice(0, 2)) ?? (serve && pick(key, [serve.layer]));
129
+ const build = withServe("build");
130
+ const install = withServe("install");
126
131
  return {
127
132
  url: url?.setting,
128
133
  serve: serve?.setting,
129
134
  build: build?.setting,
135
+ install: install?.setting,
130
136
  dir: resolve(cwd, serve?.layer.dir ?? "."),
131
137
  };
132
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proofed-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Check web app scenarios in Chrome with Kane CLI before you call a change done.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "proofed": "bin/proofed.cjs"
24
24
  },
25
25
  "engines": {
26
- "node": ">=24"
26
+ "node": ">=22.18"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "node --input-type=module -e 'import { rmSync } from \"node:fs\"; rmSync(\"dist\", { recursive: true, force: true });' && tsc -p tsconfig.build.json",