proofed-cli 0.1.0 → 0.1.2

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,9 +121,9 @@ 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 Kane whether it is signed in (`kane-cli whoami`, free); if not, it stops at once with exit 3 and `kane-cli login` as the fix. 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
- 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. Shown with the current CLI wording and first-run estimate; paths are relative:
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
 
128
128
  ```
129
129
  Proofed: checking 1 of 3 scenario(s), --only, at http://localhost:4173.
@@ -133,22 +133,27 @@ Building the app: pnpm build
133
133
  Starting the app: pnpm preview --port 4173
134
134
  Started the app in 1 s (build from --build, serve from --serve); its output is in .proofed-out/serve.log
135
135
  [0:01] started free-shipping: Free shipping from €50
136
- [0:26] still running: free-shipping 0:25 at "click: Clicking Add House Espresso to bag"
137
- [0:51] still running: free-shipping 0:50 at "Step 7"
138
- [1:16] still running: free-shipping 1:15 at "Step 11"
139
- [1:41] still running: free-shipping 1:41 at "assert: shipping is now Free and the total is €51.00."
140
- [2:01] failed free-shipping: Free shipping from €50 (2:00, 27.4 credits)
141
-
142
- ✗ Free shipping from €50 failed after 2:00
136
+ [0:26] still running: free-shipping 0:25 at "Step 3"
137
+ [0:51] still running: free-shipping 0:50 at "Step 9"
138
+ [1:16] still running: free-shipping 1:15 at "assert: shipping is now Free and the total is €51.00."
139
+ [1:41] still running: free-shipping 1:40 at "assert: shipping is now Free and the total is €51.00."
140
+ [1:45] retrying free-shipping: the check failed, but Kane blames the scenario; running it once more to be sure
141
+ [2:11] still running: free-shipping 2:10 at "Step 3"
142
+ [2:36] still running: free-shipping 2:35 at "Step 8"
143
+ [3:01] still running: free-shipping 3:00 at "Step 10"
144
+ [3:26] still running: free-shipping 3:25 at "assert: shipping is now Free and the total is €51.00."
145
+ [3:51] failed free-shipping: Free shipping from €50 (3:50, 56.9 credits)
146
+
147
+ ✗ Free shipping from €50 failed after 3:50
143
148
  Kane saw Final verification failed: "shipping is now Free and the total is €51.00."
144
- Why The scenario's check did not hold on the page. Kane believes the scenario is out of date.
145
- Kane thinks The test used the wrong free-shipping threshold. The cart subtotal after adding one more Paper Filters was €51.00, which is still below the €60.00 threshold shown by the store.
149
+ Why The scenario's check did not hold on the page, on two runs in a row. Kane believes the scenario is out of date.
150
+ Kane thinks The test used the wrong free-shipping cutoff. After Paper Filters was increased, the basket subtotal was €51.00, which is still below the displayed €60.00 threshold, so the €4.90 shipping charge was correct.
146
151
  Next If the change in the app was intended, update the scenario; otherwise fix the app.
147
152
  Failed step assert: shipping is now Free and the total is €51.00.
148
153
  Clip .proofed-out/free-shipping/clip.mp4
149
154
  Scenario .proofed/scenarios/free-shipping.md
150
155
 
151
- ✗ 1 failed · 27.4 credits · 2m 2s
156
+ ✗ 1 failed · 56.9 credits · 3m 52s
152
157
  Credits are Kane's report; balance may drop slightly more.
153
158
  1 of 1 broke: Free shipping from €50
154
159
  Re-run what broke: proofed check --only free-shipping --url http://localhost:4173 --serve 'pnpm preview --port 4173' --build 'pnpm build'
@@ -156,9 +161,9 @@ Re-run what broke: proofed check --only free-shipping --url http://localhost:417
156
161
 
157
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.
158
163
 
159
- `--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.
160
165
 
161
- `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. This stays a failure (exit 1). `notChecked: "scenario_doubted"` is used when Kane doubted the scenario without a failed check (exit 2).
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).
162
167
 
163
168
  For an agent, add this to the app's `AGENTS.md` or `CLAUDE.md`:
164
169
 
@@ -227,7 +232,7 @@ jobs:
227
232
 
228
233
  ## Limits
229
234
 
230
- - **Kane's verdict on the same failure varies.** On [#6](https://github.com/t1dem/proofed-demo-store/pull/6) the check that [#9](https://github.com/t1dem/proofed-demo-store/pull/9) reports as a break came back twice as "the test may be wrong". Without a failed check, Proofed shows such a run as not confirmed and starts no fix. A failed `assert:` stays a failure even when Kane blames the scenario.
235
+ - **Kane's verdict on the same failure varies.** On [#6](https://github.com/t1dem/proofed-demo-store/pull/6) the check that [#9](https://github.com/t1dem/proofed-demo-store/pull/9) reports as a break came back twice as "the test may be wrong". Without a failed check, Proofed shows such a run as not confirmed and starts no fix. A failed `assert:` that Kane blames on the scenario is run a second time, and stays a failure when it fails again.
231
236
  - **Fixes need Claude's usage limit to have room.** On [#7](https://github.com/t1dem/proofed-demo-store/pull/7) and [#8](https://github.com/t1dem/proofed-demo-store/pull/8) it ran out: Kane caught the break, no fix followed, and the report says so.
232
237
  - **Only flows with a scenario are checked.** A scenario whose `paths` miss a file isn't picked when that file changes.
233
238
  - **Slow next to unit tests.** One to four minutes of Kane per scenario, plus a build and a re-check per fix attempt.
@@ -242,25 +247,26 @@ Each fix is a few lines, found by a run that went wrong.
242
247
  | Kane routed around a broken button and passed | Kane is told to do each step once, with no other way to the goal | `src/run.ts` |
243
248
  | A run was still going after 361 seconds | A 360-second wall-clock limit over Kane's own `--timeout 300` | `src/kane.ts` |
244
249
  | Kane's children outlived a plain kill and held the output open | Kane runs in its own process group, killed as a whole | `src/kane.ts` |
250
+ | On a page that was fine, Kane reported a heading as not visible and blamed the scenario | A failed check Kane blames on the scenario is run a second time; the second run is the result | `src/run.ts` |
245
251
  | In 13 of 36 parallel starts, a scenario exited within seconds | One `kane-cli login` before the scenarios, and one retry; the retry always reached a verdict | `action.yml`, `src/run.ts` |
246
252
 
247
253
  ## Code
248
254
 
249
- 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.
250
256
  `pnpm build` emits the CLI and its imports to `dist/` for npm. `npm pack` builds it automatically.
251
257
  `pnpm typecheck` and `pnpm test` check the source. `pnpm check:package` builds a tarball, checks its
252
258
  contents, installs it into a temporary prefix and runs its version and help. It removes its temp files.
253
259
 
254
- To release, confirm the version in `package.json` (currently `0.1.0`); published versions cannot be reused. From a clean checkout with Node 24+:
260
+ To release, confirm the version in `package.json` (currently `0.1.2`); published versions cannot be reused. From a clean checkout with Node 22.18+:
255
261
 
256
262
  ```sh
257
263
  pnpm install --frozen-lockfile
258
264
  npm login --registry=https://registry.npmjs.org/
259
265
  npm whoami --registry=https://registry.npmjs.org/
260
266
  npm publish --access public --registry=https://registry.npmjs.org/
261
- npm view proofed-cli@0.1.0 version bin engines dist.tarball --registry=https://registry.npmjs.org/
262
- npx --yes proofed-cli@0.1.0 --version
263
- npx --yes proofed-cli@0.1.0 --help
267
+ npm view proofed-cli@0.1.2 version bin engines dist.tarball --registry=https://registry.npmjs.org/
268
+ npx --yes proofed-cli@0.1.2 --version
269
+ npx --yes proofed-cli@0.1.2 --help
264
270
  ```
265
271
 
266
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,11 +8,13 @@ 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 { 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";
14
15
  import { askedScenario } from "./requests.js";
15
16
  import { buildDoc, errorDoc, quote, sameCommand, scenarioDoc } from "./result.js";
17
+ import { creditsOf } from "./run.js";
16
18
  import { affectedBy, readScenarios } from "./scenarios.js";
17
19
  import { answers, startApp } from "./serve.js";
18
20
  import { SetupError } from "./setuperror.js";
@@ -48,6 +50,7 @@ export function makeView(flags, io) {
48
50
  }
49
51
  return new PlainView(io.stdout, { color: colorOn(io.env, false), err: io.stderr });
50
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.`);
51
54
  const fromNote = (s) => (s.from.startsWith("--") ? "" : ` (url from ${s.from})`);
52
55
  // Flags that say where the app and the scenarios are and how to run, so a printed command runs
53
56
  // the same way. Not --no-cache or --dry-run: those were about this run.
@@ -56,6 +59,7 @@ function rerunFlags(flags) {
56
59
  ["--url", flags.url],
57
60
  ["--serve", flags.serve],
58
61
  ["--build", flags.build],
62
+ ["--install", flags.install],
59
63
  ["--serve-timeout", flags.serveTimeout?.toString()],
60
64
  ["--base", flags.base],
61
65
  ["--scenarios", flags.scenarios],
@@ -114,7 +118,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
114
118
  }
115
119
  else if (doc.dryRun) {
116
120
  for (const d of doc.scenarios)
117
- view.info(`${d.cached ? "cached: " : "would run:"} ${d.id} (${d.name})${d.cached ? "" : `, about ${d.estimatedCredits} credits`}`);
121
+ view.info(`${d.cached ? "cached: " : "would run:"} ${d.id} (${d.name})${d.cached ? "" : `, about ${Math.round((d.estimatedCredits ?? 0) * 100) / 100} credits`}`);
118
122
  view.info(`${doc.summary}. Dry run: nothing ran, no credits spent.`);
119
123
  view.info(doc.next);
120
124
  view.close();
@@ -152,7 +156,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
152
156
  throw scenariosMissing(dir, flags, io, "check");
153
157
  if (!text && loaded.errors.length) {
154
158
  const [first] = loaded.errors;
155
- throw new SetupError("scenario_invalid", loaded.errors.map((e) => `${e.file}: ${e.message}`).join("\n"), `Fix the frontmatter of ${first.file} (see proofed list).`);
159
+ throw new SetupError("scenario_invalid", loaded.errors.map((e) => `${e.file}: ${e.message}`).join("\n"), `Correct the frontmatter of ${first.file} (see proofed list).`);
156
160
  }
157
161
  const all = loaded.scenarios;
158
162
  const base = text ? undefined : findBase(io.cwd, flags.base);
@@ -201,15 +205,13 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
201
205
  return buildDoc({ ...common, items: [], skipped, url: null, idle: { summary, next: `Nothing to check. To run every scenario anyway: ${sameCommand(rerun, "--all")}` } });
202
206
  }
203
207
  }
204
- const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build }, env: io.env, cwd: io.cwd });
208
+ const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build, install: flags.install }, env: io.env, cwd: io.cwd });
205
209
  const url = target.url?.value;
206
210
  if (url !== undefined && !isHttpUrl(url)) {
207
211
  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");
208
212
  }
209
213
  const baseId = base?.rev ? mergeBaseOf(io.cwd, base.rev) : "";
210
214
  let appState;
211
- // What the attempts before an automatic retry took, per scenario.
212
- const retried = new Map();
213
215
  const cacheFile = join(out, CACHE_FILE);
214
216
  const cache = readCache(cacheFile);
215
217
  const keys = new Map();
@@ -265,6 +267,9 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
265
267
  if (!url) {
266
268
  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" }`);
267
269
  }
270
+ const login = await kaneLogin(kane.path, io.env);
271
+ if (login.state === "not_signed_in")
272
+ throw notSignedIn();
268
273
  ensureOut(out);
269
274
  const runLog = join(out, "run.log");
270
275
  writeFileSync(runLog, "");
@@ -291,6 +296,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
291
296
  url,
292
297
  serve: target.serve.value,
293
298
  build: target.build?.value,
299
+ install: target.install,
294
300
  cwd: target.dir,
295
301
  logFile,
296
302
  timeoutSeconds: flags.serveTimeout ?? 60,
@@ -307,17 +313,14 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
307
313
  const cacheable = !(appState === "reused" && target.build);
308
314
  const onEvent = (e) => {
309
315
  view.event(e);
310
- if (e.type === "retry" && e.credits)
311
- retried.set(e.id, (retried.get(e.id) ?? 0) + e.credits);
312
316
  if (e.type !== "finished")
313
317
  return;
314
318
  finished.set(e.id, e.result);
315
319
  const key = keys.get(e.id);
316
320
  if (!key)
317
321
  return;
318
- const credits = e.result.end?.credits_consumed;
319
- if (credits !== undefined)
320
- cache.last[e.id] = { credits: credits + (retried.get(e.id) ?? 0) };
322
+ if (e.result.end?.credits_consumed !== undefined)
323
+ cache.last[e.id] = { credits: creditsOf(e.result) };
321
324
  if (e.result.outcome === "passed" && cacheable) {
322
325
  const clip = e.result.clip && { ...(e.result.clip.mp4 && { mp4: resolve(e.result.clip.mp4) }), jpg: resolve(e.result.clip.jpg) };
323
326
  cache.passes[e.id] = { key, passedAt: new Date().toISOString(), seconds: e.result.seconds, ...(clip && { clip }) };
@@ -328,10 +331,13 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
328
331
  writeCache(cacheFile, cache);
329
332
  };
330
333
  const results = await runAll(toRun, out, plan.concurrency, { baseUrl: url, headless: !flags.headed, onEvent });
334
+ // A login can run out between whoami and the runs; running the check again wouldn't help then either.
335
+ if (results.some((r) => r.notSignedIn))
336
+ throw notSignedIn("Kane CLI refused to run a scenario: it is not signed in. The scenarios it refused weren't checked.");
331
337
  const byId = new Map(results.map((r) => [r.scenario.id, r]));
332
338
  return docOf(selected.map((s) => {
333
339
  const r = byId.get(s.id);
334
- return r ? { scenario: s, result: r, extraCredits: retried.get(s.id) } : items.get(s.id);
340
+ return r ? { scenario: s, result: r } : items.get(s.id);
335
341
  }));
336
342
  }
337
343
  }
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
2
  // calls Kane's free commands (--version, whoami, 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 { kaneCredentials, 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,25 +53,25 @@ 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] : [];
58
+ const creds = kaneCredentials(io.env);
54
59
  if (!found.path) {
55
60
  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
61
  }
57
62
  else {
58
- const [version, who, balance] = await Promise.all([
63
+ const [version, login, balance] = await Promise.all([
59
64
  kane(found.path, ["--version"], io.env),
60
- kane(found.path, ["whoami"], io.env),
65
+ kaneLogin(found.path, io.env),
61
66
  kane(found.path, ["balance", ...creds], io.env),
62
67
  ]);
63
68
  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");
69
+ if (login.state === "not_signed_in")
70
+ add("Kane login", "fail", login.detail, LOGIN_FIX);
71
+ else if (login.state === "unknown")
72
+ add("Kane login", "warn", login.detail, "kane-cli whoami");
68
73
  else
69
- add("Kane login", "fail", "not signed in", "kane-cli login (or export LT_USERNAME and LT_ACCESS_KEY from TestMu: Settings → Keys)");
74
+ add("Kane login", "ok", login.detail);
70
75
  const left = /credits:\s*([\d.,]+)/i.exec(balance.text)?.[1];
71
76
  if (balance.ok && left) {
72
77
  const n = Number(left.replace(/,/g, ""));
@@ -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
@@ -32,6 +32,8 @@ Time and credits
32
32
  Outcomes
33
33
  passed Kane checked what the scenario says, and it held
34
34
  failed A scenario's check did not hold on the page. Review the failure and fix it.
35
+ When Kane blames the scenario for it, the scenario is run a second time, at
36
+ its cost again, and the second run is the result.
35
37
  not_checked Kane asserted nothing, or thinks the scenario text is wrong. Not a pass.
36
38
  error Kane couldn't finish, even on one automatic retry (browser or service trouble).
37
39
  Says nothing about the app.
@@ -40,7 +42,7 @@ Exit codes
40
42
  0 everything that ran passed, or nothing needed to run
41
43
  1 at least one scenario failed
42
44
  2 nothing failed, but at least one was not_checked or error
43
- 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
44
46
  130 interrupted
45
47
 
46
48
  For AI agents
@@ -51,7 +53,8 @@ For AI agents
51
53
  failedCheck: "scenario_doubted" means the check failed but Kane believes it is out of date.
52
54
  Diagnosis is Kane's opinion. If the app change was intended, update the scenario; otherwise fix the app.
53
55
  Never treat "not_checked" as a pass: fix the scenario or tell the user why Kane doubts it.
54
- 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.`;
55
58
  const CHECK = `proofed check [text] [flags]
56
59
 
57
60
  Runs the scenarios the local change touches, in Chrome, with Kane, and says what broke.
@@ -69,6 +72,9 @@ Where the app is (flag, then env, then .proofed/config.json, then the Proofed wo
69
72
  --url <url> Where it runs (env PROOFED_URL), e.g. http://localhost:5173
70
73
  --serve <cmd> Starts it when the URL doesn't answer; stopped at the end (env PROOFED_SERVE)
71
74
  --build <cmd> Runs before --serve (env PROOFED_BUILD)
75
+ --install <cmd> Installs the app's dependencies before the build, when node_modules is
76
+ missing or older than package.json or the lockfile (env PROOFED_INSTALL;
77
+ default: the workflow's install, else the app's package manager)
72
78
  --reuse With a build set, a URL that already answers stops the check (exit 3): it
73
79
  may be an old build. --reuse tests what is running; its passes aren't cached
74
80
  --serve-timeout <s> How long the URL gets to answer after --serve (default 60)
@@ -97,6 +103,9 @@ JSON (also written to <out>/result.json)
97
103
  Proofed couldn't run: {ok: false, exitCode: 3, error: {code, message, fix}}
98
104
  Interrupted: the same shape with exitCode 130 and scenarios [...] for what had finished
99
105
 
106
+ Before anything is built, the Kane login is checked (kane-cli whoami, free): without one the
107
+ check stops with exit 3 and error.code "kane_not_signed_in".
108
+
100
109
  Exit codes: 0 passed, 1 failed, 2 not_checked or error, 3 couldn't run, 130 interrupted.`;
101
110
  const LIST = `proofed list [flags]
102
111
 
@@ -116,7 +125,7 @@ Checks Node, git, the scenarios, Kane CLI (installed, signed in, credits left),
116
125
  problem comes with the command or step that fixes it. Uses only Kane's free commands.
117
126
  Exit 0 when proofed check can run, else 3.
118
127
 
119
- --url, --serve, --build As for proofed check
120
- --scenarios <dir> Default .proofed/scenarios
121
- --json {ok, exitCode, checks [{name, status: ok | warn | fail, detail, fix}]}`;
128
+ --url, --serve, --build, --install As for proofed check
129
+ --scenarios <dir> Default .proofed/scenarios
130
+ --json {ok, exitCode, checks [{name, status: ok | warn | fail, detail, fix}]}`;
122
131
  export const helpText = (command) => (command === "check" ? CHECK : command === "list" ? LIST : command === "doctor" ? DOCTOR : MAIN);
@@ -0,0 +1,25 @@
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 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
+ // What `kane-cli run` prints on stderr when it can't start for want of a login (kane-cli 0.10):
7
+ // "Not authenticated. Run: kane-cli login --oauth, or kane-cli login --username <user> --access-key <key>"
8
+ export const NOT_SIGNED_IN = /\bnot authenticated\b|\bnot (?:logged|signed) in\b|\btoken (?:missing|expired|invalid)\b/i;
9
+ 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()] : [];
10
+ // `kane-cli whoami` is free and local: it exits 0 when signed in and 1 when not. One that can't be
11
+ // started or doesn't answer says nothing either way, and the check goes on.
12
+ export function kaneLogin(bin, env, timeout = 20_000) {
13
+ if (kaneCredentials(env).length)
14
+ return Promise.resolve({ state: "keys", detail: "LT_USERNAME and LT_ACCESS_KEY are set; Kane uses them" });
15
+ return new Promise((resolve) => {
16
+ execFile(bin, ["whoami"], { env, timeout }, (error) => {
17
+ if (!error)
18
+ return resolve({ state: "signed_in", detail: "signed in" });
19
+ const e = error;
20
+ if (e.killed || typeof e.code !== "number")
21
+ return resolve({ state: "unknown", detail: `kane-cli whoami didn't answer${e.killed ? ` within ${timeout / 1000} s` : `: ${e.message}`}` });
22
+ resolve({ state: "not_signed_in", detail: "not signed in" });
23
+ });
24
+ });
25
+ }
package/dist/pipeline.js CHANGED
@@ -8,7 +8,7 @@ import { log } from "./log.js";
8
8
  import { crashResult, findCrashes } from "./precheck.js";
9
9
  import { buildReport, outdated, postsNew } from "./report.js";
10
10
  import { nothingAsked } from "./requests.js";
11
- import { scenarioDoubted, runScenario } from "./run.js";
11
+ import { creditsOf, scenarioDoubted, runScenario } from "./run.js";
12
12
  import { FAILED_CHECK_ACTION, FAILED_CHECK_REASON, RUN_FILE } from "./runfile.js";
13
13
  import { affectedBy, loadScenariosOr } from "./scenarios.js";
14
14
  export const env = (name, fallback) => {
@@ -128,7 +128,7 @@ export function runFile({ sha, results, skipped, runUrl, fix }, clips) {
128
128
  .slice(-30)
129
129
  .map((s) => ({ remark: s.remark.slice(0, 200), ...(s.status === "failed" && { failed: true }), ...(s.at !== undefined && { at: s.at }) })),
130
130
  clip: clips.get(r.scenario.id),
131
- credits: r.end?.credits_consumed,
131
+ credits: r.end?.credits_consumed === undefined ? undefined : creditsOf(r),
132
132
  seconds: r.seconds,
133
133
  })),
134
134
  fix: fix && {
package/dist/render.js CHANGED
@@ -3,6 +3,7 @@
3
3
  // agents and logs: no escape codes and no redraw, one line per event, a heartbeat at least every 30
4
4
  // seconds, then the same details. Colour is drawn by hand; there are no runtime dependencies.
5
5
  import { FAILED_CHECK_REASON } from "./runfile.js";
6
+ import { creditsOf } from "./run.js";
6
7
  import { outcomeOf } from "./result.js";
7
8
  // FORCE_COLOR=0 and NO_COLOR turn colour off, FORCE_COLOR=1 turns it on, even in a pipe.
8
9
  export function colorOn(env, isTTY) {
@@ -149,7 +150,7 @@ export class Board {
149
150
  if (e.type === "retry")
150
151
  Object.assign(row, { retry: e.error, remark: undefined });
151
152
  if (e.type === "finished") {
152
- Object.assign(row, { state: "done", outcome: outcomeOf(e.result), credits: e.result.end?.credits_consumed ?? 0, seconds: e.result.seconds ?? 0 });
153
+ Object.assign(row, { state: "done", outcome: outcomeOf(e.result), credits: Math.round(creditsOf(e.result) * 100) / 100, seconds: e.result.seconds ?? 0 });
153
154
  }
154
155
  }
155
156
  running() {
package/dist/report.js CHANGED
@@ -2,7 +2,7 @@ import { MARKER, OLD_MARKER } from "./github.js";
2
2
  import { BLANK_PAGE, FAILED_CHECK_ACTION, FAILED_CHECK_REASON, runMarker } from "./runfile.js";
3
3
  import { describeFixer } from "./models.js";
4
4
  import { nothingAsked } from "./requests.js";
5
- import { scenarioDoubted, unchecked } from "./run.js";
5
+ import { creditsOf, scenarioDoubted, unchecked } from "./run.js";
6
6
  const DATA_RE = /<!-- proofed:data (.*?) -->/s;
7
7
  export const FIX_BOX = "Fix with Claude";
8
8
  const COMMENT_LIMIT = 65_536;
@@ -202,7 +202,7 @@ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, a
202
202
  const errored = results.filter((r) => r.outcome === "error");
203
203
  const unsure = results.filter((r) => r.outcome === "unsure");
204
204
  const passed = results.filter((r) => r.outcome === "passed");
205
- const credits = all.reduce((sum, r) => sum + (r.end?.credits_consumed ?? 0), written?.credits ?? 0);
205
+ const credits = all.reduce((sum, r) => sum + creditsOf(r), written?.credits ?? 0);
206
206
  const repaired = fix?.status === "fixed" && previous
207
207
  ? passed.flatMap((after) => {
208
208
  const before = previous.failures.find((f) => f.id === after.scenario.id);
package/dist/result.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // The result of `proofed check` as one JSON document: what `--json` prints, what <out>/result.json
2
2
  // holds, and what the terminal views draw from. Its names are the CLI's contract with coding agents.
3
3
  import { resolve } from "node:path";
4
- import { scenarioDoubted, unchecked } from "./run.js";
4
+ import { creditsOf, scenarioDoubted, unchecked } from "./run.js";
5
5
  import { FAILED_CHECK_ACTION } from "./runfile.js";
6
6
  export const outcomeOf = (r) => (r.outcome === "unsure" ? "not_checked" : r.outcome);
7
7
  // Shell-safe as typed.
@@ -58,7 +58,7 @@ export function scenarioDoc(item, ctx) {
58
58
  .map((step) => ({ remark: step.remark.slice(0, 200), ...(step.status === "failed" && { failed: true }) })),
59
59
  ...(r.pageError && { pageError: r.pageError }),
60
60
  ...(r.clip && { clip: { ...(r.clip.mp4 && { mp4: resolve(r.clip.mp4) }), jpg: resolve(r.clip.jpg) } }),
61
- credits: round((r.end?.credits_consumed ?? 0) + (item.extraCredits ?? 0)),
61
+ credits: round(creditsOf(r)),
62
62
  ...(r.seconds !== undefined && { seconds: r.seconds }),
63
63
  rerun,
64
64
  };
package/dist/run.js CHANGED
@@ -4,6 +4,7 @@ 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";
@@ -30,7 +31,7 @@ export { NOTHING_CHECKED };
30
31
  const checked = (steps) => steps.some((s) => s.status === "done" && /^assert:/i.test(s.remark));
31
32
  // Kane read the page and the scenario's own check came out false. When the app is wrong all over
32
33
  // (a changed threshold shown in its banner too), Kane sides with the app and blames the test; the
33
- // scenario is what the app was meant to do, so that is a failure.
34
+ // scenario is what the app was meant to do, so that is a failure. runScenario runs it a second time.
34
35
  const refuted = (steps) => steps.some((s) => s.status === "failed" && /^assert:/i.test(s.remark));
35
36
  export function outcomeOf(end, steps) {
36
37
  if (!end || INFRA.test(end.reason ?? ""))
@@ -43,6 +44,9 @@ export function outcomeOf(end, steps) {
43
44
  // An unsure run where Kane said "passed": nothing was checked, as opposed to Kane doubting the test.
44
45
  export const unchecked = (r) => r.outcome === "unsure" && r.end?.status === "passed";
45
46
  export const scenarioDoubted = (r) => r.outcome === "failed" && r.end?.verdict?.family === "automation_bug";
47
+ // All the credits a scenario took, the runs before the last one included.
48
+ export const creditsOf = (r) => (r.end?.credits_consumed ?? 0) + (r.earlierCredits ?? 0);
49
+ const RECHECK = "the check failed, but Kane blames the scenario; running it once more to be sure";
46
50
  // Kane is good at reaching a goal, so on its own it routes around a broken button (a key press, another
47
51
  // link) and passes. A user who clicks the button and gets the wrong screen has found a bug.
48
52
  const NO_WORKAROUNDS = "Do each step once, the way it is described. If a click or a key press does something other than what " +
@@ -52,13 +56,27 @@ export function kaneObjective(objective) {
52
56
  return `${objective}\n\n${NO_WORKAROUNDS}`;
53
57
  }
54
58
  export async function runScenario(scenario, o) {
55
- let result = await runOnce(scenario, o);
56
- for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !stopping(); i++) {
57
- logLine(`[${scenario.id}] ${result.error ?? "infra error"}; retrying`);
58
- o.onEvent?.({ type: "retry", id: scenario.id, error: result.error ?? "infra error", credits: result.end?.credits_consumed });
59
- result = await runOnce(scenario, o);
59
+ let earlier = 0;
60
+ const again = (last, why) => {
61
+ earlier += last.end?.credits_consumed ?? 0;
62
+ logLine(`[${scenario.id}] ${why}`);
63
+ o.onEvent?.({ type: "retry", id: scenario.id, error: why });
64
+ return runOnce(scenario, o);
65
+ };
66
+ const settle = async (result) => {
67
+ for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !result.notSignedIn && !stopping(); i++) {
68
+ result = await again(result, result.error ?? "infra error");
69
+ }
70
+ return result;
71
+ };
72
+ let result = await settle(await runOnce(scenario, o));
73
+ // Kane gives the same verdict for a wrong value all over the app and for a page it misread (a
74
+ // heading that is there, reported as not visible). A wrong value is wrong again on a second
75
+ // run; a misreading rarely is. So the second run decides, whatever it comes to.
76
+ if (scenarioDoubted(result) && !stopping()) {
77
+ result = await settle(await again(result, RECHECK));
60
78
  }
61
- return result;
79
+ return earlier ? { ...result, earlierCredits: earlier } : result;
62
80
  }
63
81
  async function runOnce(scenario, o) {
64
82
  const log = (line) => logLine(`[${scenario.id}] ${line}`);
@@ -138,6 +156,7 @@ async function runOnce(scenario, o) {
138
156
  end,
139
157
  clip,
140
158
  ...(outcome === "error" && { error }),
159
+ ...(!kane.end && NOT_SIGNED_IN.test(kane.stderr) && { notSignedIn: true }),
141
160
  };
142
161
  }
143
162
  finally {
package/dist/runfile.js CHANGED
@@ -7,5 +7,5 @@ export const RUN_FILE = "run.json";
7
7
  export const runMarker = (key) => `<!-- proofed:run ${key} -->`;
8
8
  export const readRunKey = (body) => /<!-- proofed:run (pr-\d+\/[\w.-]+) -->/.exec(body)?.[1];
9
9
  // A refuted check stays a failure even when Kane blames the scenario. Consumers share the next step.
10
- export const FAILED_CHECK_REASON = "The scenario's check did not hold on the page. Kane believes the scenario is out of date.";
10
+ export const FAILED_CHECK_REASON = "The scenario's check did not hold on the page, on two runs in a row. Kane believes the scenario is out of date.";
11
11
  export const FAILED_CHECK_ACTION = "If the change in the app was intended, update the scenario; otherwise fix the app.";
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.0",
3
+ "version": "0.1.2",
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",