proofed-cli 0.1.2 → 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
@@ -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 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.
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
 
@@ -257,16 +257,16 @@ Node 22.18+ runs the checkout's TypeScript directly. The GitHub Action needs no
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.2`); published versions cannot be reused. From a clean checkout with Node 22.18+:
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.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
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
package/dist/check.js CHANGED
@@ -8,7 +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 { kaneLogin, LOGIN_FIX } from "./kaneauth.js";
11
+ import { KEYS_FIX, kaneLogin, LOGIN_FIX } from "./kaneauth.js";
12
12
  import { setLog } from "./log.js";
13
13
  import { runAll } from "./pipeline.js";
14
14
  import { colorOn, LiveView, PlainView } from "./render.js";
@@ -51,6 +51,7 @@ export function makeView(flags, io) {
51
51
  return new PlainView(io.stdout, { color: colorOn(io.env, false), err: io.stderr });
52
52
  }
53
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.`);
54
55
  const fromNote = (s) => (s.from.startsWith("--") ? "" : ` (url from ${s.from})`);
55
56
  // Flags that say where the app and the scenarios are and how to run, so a printed command runs
56
57
  // the same way. Not --no-cache or --dry-run: those were about this run.
@@ -269,7 +270,9 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
269
270
  }
270
271
  const login = await kaneLogin(kane.path, io.env);
271
272
  if (login.state === "not_signed_in")
272
- throw notSignedIn();
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);
273
276
  ensureOut(out);
274
277
  const runLog = join(out, "run.log");
275
278
  writeFileSync(runLog, "");
@@ -331,7 +334,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
331
334
  writeCache(cacheFile, cache);
332
335
  };
333
336
  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.
337
+ // A login can run out between the login check and the runs; running the check again wouldn't help then either.
335
338
  if (results.some((r) => r.notSignedIn))
336
339
  throw notSignedIn("Kane CLI refused to run a scenario: it is not signed in. The scenarios it refused weren't checked.");
337
340
  const byId = new Map(results.map((r) => [r.scenario.id, r]));
package/dist/doctor.js CHANGED
@@ -1,5 +1,5 @@
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
4
  import { createRequire } from "node:module";
5
5
  import { promisify } from "node:util";
@@ -8,7 +8,7 @@ import { scenariosDirOf } from "./check.js";
8
8
  import { findBase } from "./changes.js";
9
9
  import { findChrome } from "./chrome.js";
10
10
  import { depsMissing, installCommand } from "./deps.js";
11
- import { kaneCredentials, kaneLogin, LOGIN_FIX } from "./kaneauth.js";
11
+ import { KEYS_FIX, kaneLogin, LOGIN_FIX } from "./kaneauth.js";
12
12
  import { colorOn, palette, stripAnsi } from "./render.js";
13
13
  import { readScenarios } from "./scenarios.js";
14
14
  import { answers } from "./serve.js";
@@ -55,25 +55,25 @@ export async function doctorChecks(flags, io) {
55
55
  for (const e of loaded.errors)
56
56
  add("Scenario", "fail", `${e.file}: ${e.message}`, `Correct the frontmatter of ${e.file}: --- name, paths, url --- then the objective.`);
57
57
  const found = findKane(io.env);
58
- const creds = kaneCredentials(io.env);
59
58
  if (!found.path) {
60
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");
61
60
  }
62
61
  else {
63
- const [version, login, balance] = await Promise.all([
64
- kane(found.path, ["--version"], io.env),
65
- kaneLogin(found.path, io.env),
66
- kane(found.path, ["balance", ...creds], io.env),
67
- ]);
62
+ const [version, login] = await Promise.all([kane(found.path, ["--version"], io.env), kaneLogin(found.path, io.env)]);
68
63
  add("Kane CLI", "ok", `${found.path}, ${/\d+\.\d+\.\d+\S*/.exec(version.text)?.[0] ?? "version unknown"}`);
69
64
  if (login.state === "not_signed_in")
70
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);
71
68
  else if (login.state === "unknown")
72
- add("Kane login", "warn", login.detail, "kane-cli whoami");
69
+ add("Kane login", "warn", login.detail, "kane-cli balance");
73
70
  else
74
71
  add("Kane login", "ok", login.detail);
75
- const left = /credits:\s*([\d.,]+)/i.exec(balance.text)?.[1];
76
- if (balance.ok && left) {
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) {
77
77
  const n = Number(left.replace(/,/g, ""));
78
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.");
79
79
  }
package/dist/help.js CHANGED
@@ -54,7 +54,8 @@ For AI agents
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
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.`;
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.`;
58
59
  const CHECK = `proofed check [text] [flags]
59
60
 
60
61
  Runs the scenarios the local change touches, in Chrome, with Kane, and says what broke.
@@ -103,8 +104,9 @@ JSON (also written to <out>/result.json)
103
104
  Proofed couldn't run: {ok: false, exitCode: 3, error: {code, message, fix}}
104
105
  Interrupted: the same shape with exitCode 130 and scenarios [...] for what had finished
105
106
 
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".
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".
108
110
 
109
111
  Exit codes: 0 passed, 1 failed, 2 not_checked or error, 3 couldn't run, 130 interrupted.`;
110
112
  const LIST = `proofed list [flags]
package/dist/kaneauth.js CHANGED
@@ -1,25 +1,48 @@
1
1
  // Whether Kane can start a run: signed in with `kane-cli login`, or given LT_USERNAME and
2
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.
3
+ // without a working login every run ends at once, and a retry ends the same way.
4
4
  import { execFile } from "node:child_process";
5
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";
6
7
  // What `kane-cli run` prints on stderr when it can't start for want of a login (kane-cli 0.10):
7
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.'
8
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;
9
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()] : [];
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.
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.
12
28
  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" });
29
+ const creds = kaneCredentials(env);
15
30
  return new Promise((resolve) => {
16
- execFile(bin, ["whoami"], { env, timeout }, (error) => {
17
- if (!error)
18
- return resolve({ state: "signed_in", detail: "signed in" });
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
+ }
19
36
  const e = error;
20
37
  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" });
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}`}` });
23
46
  });
24
47
  });
25
48
  }
package/dist/run.js CHANGED
@@ -11,6 +11,13 @@ import { NOTHING_CHECKED } from "./runfile.js";
11
11
  import { startRecorder } from "./recorder.js";
12
12
  // Failures of the browser plumbing rather than of the app: the run is retried, never reported as a bug.
13
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
+ }
14
21
  // Words of what the run checked last: the quoted expectation of a failed check, or the values
15
22
  // Kane read off the page when it passed. The clip ends zoomed on the element that holds them.
16
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"]);
@@ -138,7 +145,7 @@ async function runOnce(scenario, o) {
138
145
  log(`→ ${outcome}${end?.reason ? `: ${end.reason}` : ""} (${frames.length} frames)`);
139
146
  const error = kane.timedOut
140
147
  ? "Kane stopped responding and the run was cut off"
141
- : (kane.end?.reason ?? kane.stderr.trim().split("\n").slice(-5).join("\n"));
148
+ : (kane.end?.reason ?? kaneError(kane.stderr));
142
149
  const film = { frames, actions: recorded.actions, focus: focusRect };
143
150
  writeFileSync(join(dir, "film.json"), JSON.stringify(film));
144
151
  // A step starts when Kane announces it (the "running" event), not when it reports it done.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proofed-cli",
3
- "version": "0.1.2",
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",