proofed-cli 0.1.1 → 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 +9 -9
- package/bin/node-version.cjs +15 -3
- package/dist/args.js +3 -0
- package/dist/check.js +13 -3
- package/dist/deps.js +90 -0
- package/dist/doctor.js +25 -12
- package/dist/help.js +14 -7
- package/dist/kaneauth.js +25 -0
- package/dist/run.js +3 -1
- package/dist/serve.js +13 -2
- package/dist/target.js +13 -7
- package/package.json +2 -2
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
|
|
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
|
|
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
|
|
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
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
|
|
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.
|
|
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+:
|
|
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.
|
|
268
|
-
npx --yes proofed-cli@0.1.
|
|
269
|
-
npx --yes proofed-cli@0.1.
|
|
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
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
Use the chosen version in the last three commands. `npm publish` runs typecheck, tests and the package
|
package/bin/node-version.cjs
CHANGED
|
@@ -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(
|
|
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 (
|
|
7
|
-
console.error(`proofed:
|
|
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 { 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,7 @@ 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.`);
|
|
52
54
|
const fromNote = (s) => (s.from.startsWith("--") ? "" : ` (url from ${s.from})`);
|
|
53
55
|
// Flags that say where the app and the scenarios are and how to run, so a printed command runs
|
|
54
56
|
// the same way. Not --no-cache or --dry-run: those were about this run.
|
|
@@ -57,6 +59,7 @@ function rerunFlags(flags) {
|
|
|
57
59
|
["--url", flags.url],
|
|
58
60
|
["--serve", flags.serve],
|
|
59
61
|
["--build", flags.build],
|
|
62
|
+
["--install", flags.install],
|
|
60
63
|
["--serve-timeout", flags.serveTimeout?.toString()],
|
|
61
64
|
["--base", flags.base],
|
|
62
65
|
["--scenarios", flags.scenarios],
|
|
@@ -115,7 +118,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
115
118
|
}
|
|
116
119
|
else if (doc.dryRun) {
|
|
117
120
|
for (const d of doc.scenarios)
|
|
118
|
-
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`}`);
|
|
119
122
|
view.info(`${doc.summary}. Dry run: nothing ran, no credits spent.`);
|
|
120
123
|
view.info(doc.next);
|
|
121
124
|
view.close();
|
|
@@ -153,7 +156,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
153
156
|
throw scenariosMissing(dir, flags, io, "check");
|
|
154
157
|
if (!text && loaded.errors.length) {
|
|
155
158
|
const [first] = loaded.errors;
|
|
156
|
-
throw new SetupError("scenario_invalid", loaded.errors.map((e) => `${e.file}: ${e.message}`).join("\n"), `
|
|
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).`);
|
|
157
160
|
}
|
|
158
161
|
const all = loaded.scenarios;
|
|
159
162
|
const base = text ? undefined : findBase(io.cwd, flags.base);
|
|
@@ -202,7 +205,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
202
205
|
return buildDoc({ ...common, items: [], skipped, url: null, idle: { summary, next: `Nothing to check. To run every scenario anyway: ${sameCommand(rerun, "--all")}` } });
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
|
-
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 });
|
|
206
209
|
const url = target.url?.value;
|
|
207
210
|
if (url !== undefined && !isHttpUrl(url)) {
|
|
208
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");
|
|
@@ -264,6 +267,9 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
264
267
|
if (!url) {
|
|
265
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" }`);
|
|
266
269
|
}
|
|
270
|
+
const login = await kaneLogin(kane.path, io.env);
|
|
271
|
+
if (login.state === "not_signed_in")
|
|
272
|
+
throw notSignedIn();
|
|
267
273
|
ensureOut(out);
|
|
268
274
|
const runLog = join(out, "run.log");
|
|
269
275
|
writeFileSync(runLog, "");
|
|
@@ -290,6 +296,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
290
296
|
url,
|
|
291
297
|
serve: target.serve.value,
|
|
292
298
|
build: target.build?.value,
|
|
299
|
+
install: target.install,
|
|
293
300
|
cwd: target.dir,
|
|
294
301
|
logFile,
|
|
295
302
|
timeoutSeconds: flags.serveTimeout ?? 60,
|
|
@@ -324,6 +331,9 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
324
331
|
writeCache(cacheFile, cache);
|
|
325
332
|
};
|
|
326
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.");
|
|
327
337
|
const byId = new Map(results.map((r) => [r.scenario.id, r]));
|
|
328
338
|
return docOf(selected.map((s) => {
|
|
329
339
|
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
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
|
|
31
|
-
add("Node",
|
|
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}`, `
|
|
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
|
|
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,
|
|
63
|
+
const [version, login, balance] = await Promise.all([
|
|
59
64
|
kane(found.path, ["--version"], io.env),
|
|
60
|
-
|
|
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 (
|
|
65
|
-
add("Kane login", "
|
|
66
|
-
else if (
|
|
67
|
-
add("Kane login", "
|
|
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", "
|
|
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
|
|
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,8 @@ 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.`;
|
|
57
58
|
const CHECK = `proofed check [text] [flags]
|
|
58
59
|
|
|
59
60
|
Runs the scenarios the local change touches, in Chrome, with Kane, and says what broke.
|
|
@@ -71,6 +72,9 @@ Where the app is (flag, then env, then .proofed/config.json, then the Proofed wo
|
|
|
71
72
|
--url <url> Where it runs (env PROOFED_URL), e.g. http://localhost:5173
|
|
72
73
|
--serve <cmd> Starts it when the URL doesn't answer; stopped at the end (env PROOFED_SERVE)
|
|
73
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)
|
|
74
78
|
--reuse With a build set, a URL that already answers stops the check (exit 3): it
|
|
75
79
|
may be an old build. --reuse tests what is running; its passes aren't cached
|
|
76
80
|
--serve-timeout <s> How long the URL gets to answer after --serve (default 60)
|
|
@@ -99,6 +103,9 @@ JSON (also written to <out>/result.json)
|
|
|
99
103
|
Proofed couldn't run: {ok: false, exitCode: 3, error: {code, message, fix}}
|
|
100
104
|
Interrupted: the same shape with exitCode 130 and scenarios [...] for what had finished
|
|
101
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
|
+
|
|
102
109
|
Exit codes: 0 passed, 1 failed, 2 not_checked or error, 3 couldn't run, 130 interrupted.`;
|
|
103
110
|
const LIST = `proofed list [flags]
|
|
104
111
|
|
|
@@ -118,7 +125,7 @@ Checks Node, git, the scenarios, Kane CLI (installed, signed in, credits left),
|
|
|
118
125
|
problem comes with the command or step that fixes it. Uses only Kane's free commands.
|
|
119
126
|
Exit 0 when proofed check can run, else 3.
|
|
120
127
|
|
|
121
|
-
--url, --serve, --build As for proofed check
|
|
122
|
-
--scenarios <dir>
|
|
123
|
-
--json
|
|
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}]}`;
|
|
124
131
|
export const helpText = (command) => (command === "check" ? CHECK : command === "list" ? LIST : command === "doctor" ? DOCTOR : MAIN);
|
package/dist/kaneauth.js
ADDED
|
@@ -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/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";
|
|
@@ -63,7 +64,7 @@ export async function runScenario(scenario, o) {
|
|
|
63
64
|
return runOnce(scenario, o);
|
|
64
65
|
};
|
|
65
66
|
const settle = async (result) => {
|
|
66
|
-
for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !stopping(); i++) {
|
|
67
|
+
for (let i = 2; i <= (o.attempts ?? 2) && result.outcome === "error" && !result.notSignedIn && !stopping(); i++) {
|
|
67
68
|
result = await again(result, result.error ?? "infra error");
|
|
68
69
|
}
|
|
69
70
|
return result;
|
|
@@ -155,6 +156,7 @@ async function runOnce(scenario, o) {
|
|
|
155
156
|
end,
|
|
156
157
|
clip,
|
|
157
158
|
...(outcome === "error" && { error }),
|
|
159
|
+
...(!kane.end && NOT_SIGNED_IN.test(kane.stderr) && { notSignedIn: true }),
|
|
158
160
|
};
|
|
159
161
|
}
|
|
160
162
|
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)}`, `
|
|
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)}`, `
|
|
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}`, `
|
|
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
|
-
{
|
|
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
|
|
124
|
-
// given as a flag or in the environment applies to whichever serve is used.
|
|
125
|
-
const
|
|
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.
|
|
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": ">=
|
|
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",
|