proofed-cli 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -122
- package/dist/action/requests.js +130 -0
- package/dist/{server.js → action/server.js} +17 -3
- package/dist/changes.js +7 -1
- package/dist/{args.js → check/args.js} +31 -3
- package/dist/check/cache.js +89 -0
- package/dist/{check.js → check/check.js} +91 -42
- package/dist/{doctor.js → check/doctor.js} +63 -27
- package/dist/check/help.js +139 -0
- package/dist/{list.js → check/list.js} +27 -15
- package/dist/{pipeline.js → check/pipeline.js} +106 -68
- package/dist/{render.js → check/render.js} +22 -15
- package/dist/check/run.js +277 -0
- package/dist/check/targetfilter.js +10 -0
- package/dist/check/textcheck.js +162 -0
- package/dist/env.js +6 -0
- package/dist/fix/agent.js +21 -0
- package/dist/fix/claude.js +30 -0
- package/dist/fix/codex.js +71 -0
- package/dist/fix/fixsetup.js +76 -0
- package/dist/fix/fixtarget.js +48 -0
- package/dist/fix/models.js +67 -0
- package/dist/github.js +62 -14
- package/dist/integrations/claude-stop.js +104 -0
- package/dist/integrations/cli.js +63 -0
- package/dist/integrations/mcp.js +130 -0
- package/dist/kane/creditmeter.js +104 -0
- package/dist/kane/kane.js +131 -0
- package/dist/kane/kaneauth.js +84 -0
- package/dist/kane/kaneversion.js +13 -0
- package/dist/paths.js +32 -0
- package/dist/process.js +65 -0
- package/dist/proofed.js +34 -16
- package/dist/{live.js → report/live.js} +1 -1
- package/dist/{livefile.js → report/livefile.js} +1 -1
- package/dist/{report.js → report/report.js} +105 -125
- package/dist/report/reportdata.js +120 -0
- package/dist/{result.js → report/result.js} +12 -7
- package/dist/{runfile.js → report/runfile.js} +2 -2
- package/dist/report/runresult.js +5 -0
- package/dist/scenarios.js +41 -19
- package/dist/secrets.js +74 -0
- package/dist/{cdp.js → targets/cdp.js} +20 -6
- package/dist/targets/chrome.js +98 -0
- package/dist/{clip.js → targets/clip.js} +21 -11
- package/dist/{precheck.js → targets/precheck.js} +53 -20
- package/dist/targets/preparetarget.js +350 -0
- package/dist/{recorder.js → targets/recorder.js} +154 -19
- package/dist/{serve.js → targets/serve.js} +9 -13
- package/dist/{target.js → targets/target.js} +42 -7
- package/dist/targets/targetchecks.js +139 -0
- package/dist/timing.js +25 -0
- package/dist/types.js +1 -0
- package/dist/which.js +26 -13
- package/docs/cli.md +370 -0
- package/package.json +10 -5
- package/dist/cache.js +0 -48
- package/dist/chrome.js +0 -77
- package/dist/help.js +0 -131
- package/dist/kane.js +0 -75
- package/dist/kaneauth.js +0 -25
- package/dist/models.js +0 -44
- package/dist/requests.js +0 -58
- package/dist/run.js +0 -166
- /package/dist/{deps.js → targets/deps.js} +0 -0
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
// Proofed's server, as the action talks to it: the job proves which repository it runs in with the
|
|
2
2
|
// OIDC token GitHub gives a job that has `id-token: write` (site/src/worker/actions.ts checks it).
|
|
3
|
+
export function proofedServer(server) {
|
|
4
|
+
const url = new URL(server);
|
|
5
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname))) {
|
|
6
|
+
throw new Error("The Proofed server needs HTTPS outside localhost");
|
|
7
|
+
}
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
3
10
|
// Set when the workflow names a Proofed server and may ask GitHub for an OIDC token.
|
|
4
11
|
export const serverUrl = () => {
|
|
5
12
|
const { ACTIONS_ID_TOKEN_REQUEST_URL: url, ACTIONS_ID_TOKEN_REQUEST_TOKEN: bearer, PROOFED_SERVER: server } = process.env;
|
|
6
|
-
|
|
13
|
+
if (!url || !bearer || !server)
|
|
14
|
+
return undefined;
|
|
15
|
+
try {
|
|
16
|
+
return proofedServer(server).href;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
7
21
|
};
|
|
8
22
|
// GitHub's tokens last five minutes; one is reused for four.
|
|
9
23
|
const TOKEN_LASTS = 4 * 60_000;
|
|
10
24
|
let token;
|
|
11
|
-
export async function oidcToken() {
|
|
25
|
+
export async function oidcToken(signal = AbortSignal.timeout(10_000)) {
|
|
12
26
|
if (token && Date.now() - token.at < TOKEN_LASTS)
|
|
13
27
|
return token.value;
|
|
14
28
|
const { ACTIONS_ID_TOKEN_REQUEST_URL: url = "", ACTIONS_ID_TOKEN_REQUEST_TOKEN: bearer } = process.env;
|
|
15
29
|
const request = new URL(url);
|
|
16
30
|
request.searchParams.set("audience", "proofed");
|
|
17
|
-
const oidc = await fetch(request, { headers: { authorization: `bearer ${bearer}` } });
|
|
31
|
+
const oidc = await fetch(request, { headers: { authorization: `bearer ${bearer}` }, signal });
|
|
18
32
|
const { value } = oidc.ok ? (await oidc.json()) : {};
|
|
19
33
|
if (!value)
|
|
20
34
|
throw new Error(`GitHub gave no OIDC token (${oidc.status})`);
|
package/dist/changes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gitPath } from "./paths.js";
|
|
1
2
|
// What the local change is, for `proofed check`: every file that differs between the merge base
|
|
2
3
|
// with the base branch and the working tree (committed, staged or not) plus new files git doesn't
|
|
3
4
|
// ignore. A coding agent's edits are usually uncommitted, so the PR check's base...HEAD isn't enough.
|
|
@@ -15,6 +16,11 @@ const tries = (fn) => {
|
|
|
15
16
|
return undefined;
|
|
16
17
|
}
|
|
17
18
|
};
|
|
19
|
+
export const changedFiles = (base, head = "HEAD") => git(process.cwd(), "diff", "--name-only", "--no-renames", "-z", `${base}...${head}`).split("\0").filter(Boolean);
|
|
20
|
+
// Use the runner's current remote-tracking commit for both the diff and fallback scenarios.
|
|
21
|
+
export function baseRev(base) {
|
|
22
|
+
return tries(() => git(process.cwd(), "rev-parse", "--verify", "--quiet", `refs/remotes/origin/${base.ref}^{commit}`)) ?? base.sha;
|
|
23
|
+
}
|
|
18
24
|
export const BASES = ["origin/HEAD", "origin/main", "origin/master", "main", "master"];
|
|
19
25
|
// The remote's default branch as origin/HEAD names it, else the usual names.
|
|
20
26
|
export function findBase(cwd, asked) {
|
|
@@ -55,5 +61,5 @@ export function localChanges(cwd, base) {
|
|
|
55
61
|
...names(git(root, "diff", "--name-only", "--no-renames", "-z", mergeBaseOf(cwd, base))),
|
|
56
62
|
...names(git(root, "ls-files", "--others", "--exclude-standard", "--full-name", "-z")),
|
|
57
63
|
]);
|
|
58
|
-
return [...files].map((f) => relative(here, join(root, f))).sort();
|
|
64
|
+
return [...files].map((f) => gitPath(relative(here, join(root, f)))).sort();
|
|
59
65
|
}
|
|
@@ -8,7 +8,17 @@ const COMMON = {
|
|
|
8
8
|
scenarios: { type: "string" },
|
|
9
9
|
out: { type: "string" },
|
|
10
10
|
};
|
|
11
|
+
const TARGET = {
|
|
12
|
+
"target": { type: "string" },
|
|
13
|
+
"execution": { type: "string" },
|
|
14
|
+
"app": { type: "string" },
|
|
15
|
+
"device": { type: "string" },
|
|
16
|
+
"os-version": { type: "string" },
|
|
17
|
+
"launch": { type: "string" },
|
|
18
|
+
"cdp-endpoint": { type: "string" },
|
|
19
|
+
};
|
|
11
20
|
const APP = {
|
|
21
|
+
...TARGET,
|
|
12
22
|
url: { type: "string" },
|
|
13
23
|
serve: { type: "string" },
|
|
14
24
|
build: { type: "string" },
|
|
@@ -23,14 +33,17 @@ export const FLAGS = {
|
|
|
23
33
|
all: { type: "boolean" },
|
|
24
34
|
"dry-run": { type: "boolean" },
|
|
25
35
|
"no-cache": { type: "boolean" },
|
|
36
|
+
"no-retry": { type: "boolean" },
|
|
26
37
|
headed: { type: "boolean" },
|
|
27
38
|
reuse: { type: "boolean" },
|
|
28
39
|
concurrency: { type: "string" },
|
|
29
40
|
"serve-timeout": { type: "string" },
|
|
30
41
|
verbose: { type: "boolean" },
|
|
31
42
|
},
|
|
32
|
-
list: { ...COMMON, base: { type: "string" }, url: { type: "string" } },
|
|
43
|
+
list: { ...COMMON, ...TARGET, base: { type: "string" }, all: { type: "boolean" }, url: { type: "string" } },
|
|
33
44
|
doctor: { ...COMMON, ...APP },
|
|
45
|
+
mcp: { help: COMMON.help },
|
|
46
|
+
hook: { help: COMMON.help },
|
|
34
47
|
};
|
|
35
48
|
export const COMMANDS = Object.keys(FLAGS);
|
|
36
49
|
const isCommand = (word) => Object.hasOwn(FLAGS, word);
|
|
@@ -92,7 +105,8 @@ function parseFlags(command, args) {
|
|
|
92
105
|
? `proofed ${command} has no ${t.rawName}; it belongs to proofed ${elsewhere[0]}.`
|
|
93
106
|
: `Unknown flag ${t.rawName} for proofed ${command}. Did you mean: ${closest(t.rawName, known)}?`);
|
|
94
107
|
}
|
|
95
|
-
|
|
108
|
+
const needsNonblank = t.name === "target" || t.name === "execution";
|
|
109
|
+
if (type === "string" && (t.value === undefined || (needsNonblank && !t.value.trim()) || (t.inlineValue !== true && t.value.startsWith("--")))) {
|
|
96
110
|
throw new UsageError(`${t.rawName} needs a value, e.g. ${t.rawName} ${EXAMPLES[t.name] ?? "<value>"}`);
|
|
97
111
|
}
|
|
98
112
|
if (type === "boolean" && t.inlineValue)
|
|
@@ -121,6 +135,13 @@ function parseFlags(command, args) {
|
|
|
121
135
|
help: on("help"),
|
|
122
136
|
scenarios: str("scenarios"),
|
|
123
137
|
out: str("out"),
|
|
138
|
+
target: str("target"),
|
|
139
|
+
execution: str("execution"),
|
|
140
|
+
app: str("app"),
|
|
141
|
+
device: str("device"),
|
|
142
|
+
os_version: str("os-version"),
|
|
143
|
+
launch: str("launch"),
|
|
144
|
+
cdp_endpoint: str("cdp-endpoint"),
|
|
124
145
|
url: str("url"),
|
|
125
146
|
serve: str("serve"),
|
|
126
147
|
build: str("build"),
|
|
@@ -130,6 +151,7 @@ function parseFlags(command, args) {
|
|
|
130
151
|
all: on("all"),
|
|
131
152
|
dryRun: on("dry-run"),
|
|
132
153
|
noCache: on("no-cache"),
|
|
154
|
+
noRetry: on("no-retry"),
|
|
133
155
|
headed: on("headed"),
|
|
134
156
|
reuse: on("reuse"),
|
|
135
157
|
verbose: on("verbose"),
|
|
@@ -137,8 +159,14 @@ function parseFlags(command, args) {
|
|
|
137
159
|
serveTimeout: count("serve-timeout"),
|
|
138
160
|
};
|
|
139
161
|
const text = positionals.join(" ").trim() || undefined;
|
|
140
|
-
if (
|
|
162
|
+
if (command === "hook") {
|
|
163
|
+
if (!flags.help && (positionals.length !== 1 || text !== "claude-stop")) {
|
|
164
|
+
throw new UsageError("Expected proofed hook claude-stop.");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else if (text && command !== "check") {
|
|
141
168
|
throw new UsageError(`proofed ${command} takes no text. To have Kane check it: proofed check "${text}"`);
|
|
169
|
+
}
|
|
142
170
|
if (flags.only && flags.all)
|
|
143
171
|
throw new UsageError("Use either --only or --all, not both.");
|
|
144
172
|
if (text && (flags.only || flags.all))
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { matchesPath } from "../paths.js";
|
|
2
|
+
// Passes Proofed doesn't pay for twice. A coding agent runs the check again after each fix, and a
|
|
3
|
+
// scenario it didn't touch would cost another 20 to 30 credits to come out the same. A pass stays
|
|
4
|
+
// good while its scenario file, its start URL, the commit the change is measured from and the
|
|
5
|
+
// changed files in its `paths` (every changed file, when it has none) stay as they were. Only
|
|
6
|
+
// passes are kept; everything else runs again.
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { readFileSync, writeFileSync, lstatSync, readlinkSync, readdirSync, statSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
export const CACHE_FILE = "cache.json";
|
|
11
|
+
// The demo-store runs reported 27 to 30 credits without accounting for the balance change.
|
|
12
|
+
export const DEFAULT_CREDITS = 30;
|
|
13
|
+
export function readCache(file) {
|
|
14
|
+
try {
|
|
15
|
+
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
16
|
+
if (data.version === 1)
|
|
17
|
+
return { version: 1, passes: data.passes ?? {}, last: data.last ?? {} };
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Missing or unreadable: start over, the worst case is paying for a run again.
|
|
21
|
+
}
|
|
22
|
+
return { version: 1, passes: {}, last: {} };
|
|
23
|
+
}
|
|
24
|
+
export const writeCache = (file, cache) => writeFileSync(file, `${JSON.stringify(cache, null, 2)}\n`);
|
|
25
|
+
// Web runs have a known typical cost; native and desktop targets have none until their first run.
|
|
26
|
+
export const estimate = (cache, s, kaneVersion) => cache.last[historyKey(s, kaneVersion)]?.credits ?? ((s.resolvedTarget?.kind ?? "web") === "web" ? DEFAULT_CREDITS : null);
|
|
27
|
+
// The changed files a scenario depends on.
|
|
28
|
+
export const relevantChanges = (s, changed) => s.paths.length ? changed.filter((f) => s.paths.some((glob) => matchesPath(f, glob))) : changed;
|
|
29
|
+
const readOrUndefined = (file) => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync(file);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined; // Deleted in the change.
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// `base`: the commit the change is measured from (mergeBaseOf).
|
|
38
|
+
export function cacheKey(s, startUrl, changed, read = readOrUndefined, base = "", kaneVersion = "", service) {
|
|
39
|
+
const hash = createHash("sha256");
|
|
40
|
+
// Length-prefixed, so no two different lists of parts hash the same.
|
|
41
|
+
const add = (part) => hash.update(`${typeof part === "string" ? Buffer.byteLength(part) : part.length}:`).update(part);
|
|
42
|
+
add(read(s.file) ?? s.objective);
|
|
43
|
+
add(startUrl);
|
|
44
|
+
if (s.resolvedTarget) {
|
|
45
|
+
const { sources, ...target } = s.resolvedTarget;
|
|
46
|
+
add(JSON.stringify(target));
|
|
47
|
+
add(kaneVersion);
|
|
48
|
+
if ("app" in target && target.app && !/^APP[\w-]+$/.test(target.app)) {
|
|
49
|
+
const digest = (file, appRoot = false) => {
|
|
50
|
+
try {
|
|
51
|
+
let stat = lstatSync(file);
|
|
52
|
+
if (stat.isSymbolicLink()) {
|
|
53
|
+
add(readlinkSync(file));
|
|
54
|
+
if (!appRoot)
|
|
55
|
+
return;
|
|
56
|
+
// Follow the app path itself. Links inside the artifact remain leaves.
|
|
57
|
+
stat = statSync(file);
|
|
58
|
+
}
|
|
59
|
+
if (stat.isDirectory())
|
|
60
|
+
for (const name of readdirSync(file).sort()) {
|
|
61
|
+
add(name);
|
|
62
|
+
digest(join(file, name));
|
|
63
|
+
}
|
|
64
|
+
else
|
|
65
|
+
add(readFileSync(file));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
add("missing");
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
digest(target.app, true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (service && (s.resolvedTarget?.kind ?? s.target ?? "web") === "web" && (service.build || service.install)) {
|
|
75
|
+
add(JSON.stringify([service.build?.value, service.install?.value]));
|
|
76
|
+
}
|
|
77
|
+
add(base);
|
|
78
|
+
for (const file of relevantChanges(s, changed).toSorted()) {
|
|
79
|
+
add(file);
|
|
80
|
+
add(read(file) ?? "\0deleted");
|
|
81
|
+
}
|
|
82
|
+
return hash.digest("hex");
|
|
83
|
+
}
|
|
84
|
+
export function historyKey(s, version) {
|
|
85
|
+
return cacheKey({ ...s, file: "", paths: [], objective: s.id }, "", [], () => undefined, "", version);
|
|
86
|
+
}
|
|
87
|
+
// A configured native build must run before we know its artifact. Looking up the old artifact's
|
|
88
|
+
// pass first can skip the rebuild altogether, even when the fixer changed a file outside paths.
|
|
89
|
+
export const canReusePass = (s, build) => (s.resolvedTarget?.kind ?? s.target ?? "web") === "web" || !build?.trim();
|
|
@@ -4,22 +4,25 @@
|
|
|
4
4
|
// as one JSON document with --json.
|
|
5
5
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
|
-
import { CACHE_FILE, DEFAULT_CREDITS, cacheKey, estimate, readCache, writeCache } from "./cache.js";
|
|
8
|
-
import { findBase, localChanges, mergeBaseOf, repoRoot } from "
|
|
9
|
-
import { killChildren, stopChildren } from "
|
|
10
|
-
import { findChrome } from "
|
|
11
|
-
import { kaneLogin, LOGIN_FIX } from "
|
|
12
|
-
import { setLog } from "
|
|
13
|
-
import { runAll } from "./pipeline.js";
|
|
7
|
+
import { CACHE_FILE, canReusePass, DEFAULT_CREDITS, cacheKey, historyKey, estimate, readCache, writeCache } from "./cache.js";
|
|
8
|
+
import { findBase, localChanges, mergeBaseOf, repoRoot } from "../changes.js";
|
|
9
|
+
import { killChildren, stopChildren } from "../children.js";
|
|
10
|
+
import { findChrome } from "../targets/chrome.js";
|
|
11
|
+
import { KEYS_FIX, kaneLogin, LOGIN_FIX } from "../kane/kaneauth.js";
|
|
12
|
+
import { setLog } from "../log.js";
|
|
13
|
+
import { runAll, runConcurrency } from "./pipeline.js";
|
|
14
14
|
import { colorOn, LiveView, PlainView } from "./render.js";
|
|
15
|
-
import { askedScenario } from "
|
|
16
|
-
import { buildDoc, errorDoc, quote, sameCommand, scenarioDoc } from "
|
|
17
|
-
import { creditsOf } from "
|
|
18
|
-
import { affectedBy, readScenarios } from "
|
|
19
|
-
import { answers, startApp } from "
|
|
20
|
-
import { SetupError } from "
|
|
21
|
-
import { isHttpUrl, resolveTarget } from "
|
|
22
|
-
import {
|
|
15
|
+
import { askedScenario } from "../action/requests.js";
|
|
16
|
+
import { buildDoc, errorDoc, quote, sameCommand, scenarioDoc } from "../report/result.js";
|
|
17
|
+
import { creditsOf } from "../report/runresult.js";
|
|
18
|
+
import { affectedBy, readScenarios } from "../scenarios.js";
|
|
19
|
+
import { answers, buildApp, startApp } from "../targets/serve.js";
|
|
20
|
+
import { SetupError } from "../setuperror.js";
|
|
21
|
+
import { isHttpUrl, resolveTarget, resolveScenarioTarget } from "../targets/target.js";
|
|
22
|
+
import { targetFilter } from "./targetfilter.js";
|
|
23
|
+
import { readKaneVersion } from "../kane/kaneversion.js";
|
|
24
|
+
import { targetChecks } from "../targets/targetchecks.js";
|
|
25
|
+
import { findKane } from "../which.js";
|
|
23
26
|
export const RESULT_FILE = "result.json";
|
|
24
27
|
export const outDirOf = (flags, io) => resolve(io.cwd, flags.out || io.env.PROOFED_OUT?.trim() || ".proofed-out");
|
|
25
28
|
export const scenariosDirOf = (flags, io) => flags.scenarios || io.env.PROOFED_SCENARIOS?.trim() || ".proofed/scenarios";
|
|
@@ -51,11 +54,19 @@ export function makeView(flags, io) {
|
|
|
51
54
|
return new PlainView(io.stdout, { color: colorOn(io.env, false), err: io.stderr });
|
|
52
55
|
}
|
|
53
56
|
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.`);
|
|
57
|
+
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
58
|
const fromNote = (s) => (s.from.startsWith("--") ? "" : ` (url from ${s.from})`);
|
|
55
59
|
// Flags that say where the app and the scenarios are and how to run, so a printed command runs
|
|
56
60
|
// the same way. Not --no-cache or --dry-run: those were about this run.
|
|
57
61
|
function rerunFlags(flags) {
|
|
58
62
|
const pass = [
|
|
63
|
+
["--target", flags.target],
|
|
64
|
+
["--execution", flags.execution],
|
|
65
|
+
["--app", flags.app],
|
|
66
|
+
["--device", flags.device],
|
|
67
|
+
["--os-version", flags.os_version],
|
|
68
|
+
["--launch", flags.launch],
|
|
69
|
+
["--cdp-endpoint", flags.cdp_endpoint],
|
|
59
70
|
["--url", flags.url],
|
|
60
71
|
["--serve", flags.serve],
|
|
61
72
|
["--build", flags.build],
|
|
@@ -66,7 +77,7 @@ function rerunFlags(flags) {
|
|
|
66
77
|
["--out", flags.out],
|
|
67
78
|
["--concurrency", flags.concurrency?.toString()],
|
|
68
79
|
];
|
|
69
|
-
const on = [flags.reuse && "--reuse", flags.headed && "--headed", flags.json && "--json"].filter((f) => !!f);
|
|
80
|
+
const on = [flags.reuse && "--reuse", flags.noRetry && "--no-retry", flags.headed && "--headed", flags.json && "--json"].filter((f) => !!f);
|
|
70
81
|
return [...pass.flatMap(([name, v]) => (v ? [`${name} ${quote(v)}`] : [])), ...on];
|
|
71
82
|
}
|
|
72
83
|
export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
@@ -80,7 +91,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
80
91
|
ensureOut(out);
|
|
81
92
|
writeFileSync(join(out, RESULT_FILE), `${JSON.stringify(doc, null, 2)}\n`);
|
|
82
93
|
if (flags.json)
|
|
83
|
-
io.stdout.write(`${JSON.stringify(doc
|
|
94
|
+
io.stdout.write(`${JSON.stringify(doc)}\n`);
|
|
84
95
|
};
|
|
85
96
|
// Ctrl-C (or a kill) mid-run: Kane, every Chrome and the app go first, then the exit.
|
|
86
97
|
// The run that was going ends on its own once Kane is killed; its result is dropped, the
|
|
@@ -118,7 +129,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
118
129
|
}
|
|
119
130
|
else if (doc.dryRun) {
|
|
120
131
|
for (const d of doc.scenarios)
|
|
121
|
-
view.info(`${d.cached ? "cached: " : "would run:"} ${d.id} (${d.name})${d.cached ? "" : `,
|
|
132
|
+
view.info(`${d.cached ? "cached: " : "would run:"} ${d.id} (${d.name})${d.cached ? "" : `, ${d.estimatedCredits === null ? "unknown" : Math.round((d.estimatedCredits ?? 0) * 100) / 100} credits`}`);
|
|
122
133
|
view.info(`${doc.summary}. Dry run: nothing ran, no credits spent.`);
|
|
123
134
|
view.info(doc.next);
|
|
124
135
|
view.close();
|
|
@@ -172,7 +183,11 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
172
183
|
let skipped;
|
|
173
184
|
let selection;
|
|
174
185
|
if (text) {
|
|
175
|
-
|
|
186
|
+
// A scenario's id or name as the text would otherwise pay for a vague check of those words.
|
|
187
|
+
const named = all.find((s) => [s.id, s.name].some((n) => n.toLowerCase() === text.trim().toLowerCase()));
|
|
188
|
+
if (named)
|
|
189
|
+
throw new SetupError("text_is_scenario", `"${text}" is the scenario ${named.id} in ${dir}, not a behavior to check.`, `Run that scenario: proofed check --only ${named.id}. Or describe the behavior in words: proofed check "<what to check>".`);
|
|
190
|
+
selected = [askedScenario("terminal", text, resolveScenarioTarget({}, flags, io.env, io.cwd))];
|
|
176
191
|
skipped = all.map((s) => ({ id: s.id, name: s.name, why: "only your text is checked" }));
|
|
177
192
|
selection = "your text";
|
|
178
193
|
}
|
|
@@ -205,34 +220,51 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
205
220
|
return buildDoc({ ...common, items: [], skipped, url: null, idle: { summary, next: `Nothing to check. To run every scenario anyway: ${sameCommand(rerun, "--all")}` } });
|
|
206
221
|
}
|
|
207
222
|
}
|
|
223
|
+
if (!text) {
|
|
224
|
+
const matches = targetFilter(flags, io);
|
|
225
|
+
const incompatible = selected.filter((s) => !matches(s));
|
|
226
|
+
if (flags.only && incompatible.length)
|
|
227
|
+
throw new SetupError("target_selection", "--only contains scenarios incompatible with --target", "Select ids with the requested target.");
|
|
228
|
+
skipped.push(...incompatible.map((s) => ({ id: s.id, name: s.name, why: "different target" })));
|
|
229
|
+
selected = selected.filter(matches);
|
|
230
|
+
}
|
|
231
|
+
selected = selected.map((s) => ({ ...s, resolvedTarget: resolveScenarioTarget(s, flags, io.env, io.cwd) }));
|
|
208
232
|
const target = resolveTarget({ flags: { url: flags.url, serve: flags.serve, build: flags.build, install: flags.install }, env: io.env, cwd: io.cwd });
|
|
209
233
|
const url = target.url?.value;
|
|
210
|
-
if (url !== undefined && !isHttpUrl(url)) {
|
|
234
|
+
if (selected.some((s) => s.resolvedTarget.kind === "web") && url !== undefined && !isHttpUrl(url)) {
|
|
211
235
|
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");
|
|
212
236
|
}
|
|
213
237
|
const baseId = base?.rev ? mergeBaseOf(io.cwd, base.rev) : "";
|
|
214
238
|
let appState;
|
|
239
|
+
const concurrency = runConcurrency(io.env, flags.concurrency);
|
|
240
|
+
const kane = findKane(io.env);
|
|
241
|
+
const kaneVersion = kane.path ? readKaneVersion(kane.path, io.env) : "unknown";
|
|
215
242
|
const cacheFile = join(out, CACHE_FILE);
|
|
216
243
|
const cache = readCache(cacheFile);
|
|
217
244
|
const keys = new Map();
|
|
218
245
|
const items = new Map();
|
|
219
246
|
for (const s of selected) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (hit?.key === key)
|
|
247
|
+
const hit = cache.passes[s.id];
|
|
248
|
+
if (s.file && (s.resolvedTarget.kind !== "web" || url) && changed && (!flags.noCache || hit) && kaneVersion !== "unknown") {
|
|
249
|
+
const key = cacheKey(s, s.resolvedTarget.kind === "web" ? new URL(s.url, url).href : "", changed, undefined, baseId, kaneVersion, target);
|
|
250
|
+
// A forced check can replace or invalidate the matching pass it bypassed.
|
|
251
|
+
if (!flags.noCache || hit?.key === key)
|
|
252
|
+
keys.set(s.id, key);
|
|
253
|
+
if (!flags.noCache && (!flags.reuse || !target.build) && canReusePass(s, target.build?.value) && hit?.key === key) {
|
|
225
254
|
items.set(s.id, { scenario: s, cached: hit });
|
|
255
|
+
}
|
|
226
256
|
}
|
|
227
257
|
if (!items.has(s.id))
|
|
228
|
-
items.set(s.id, { scenario: s, estimate:
|
|
258
|
+
items.set(s.id, { scenario: s, estimate: estimate(cache, s, kaneVersion) });
|
|
229
259
|
}
|
|
230
260
|
const toRun = selected.filter((s) => "estimate" in items.get(s.id));
|
|
261
|
+
const needsHttp = toRun.some((s) => s.resolvedTarget.kind === "web");
|
|
231
262
|
const cachedPasses = selected.flatMap((s) => {
|
|
232
263
|
const item = items.get(s.id);
|
|
233
264
|
return "cached" in item ? [{ id: s.id, name: s.name, cachedAt: item.cached.passedAt }] : [];
|
|
234
265
|
});
|
|
235
|
-
const
|
|
266
|
+
const estimates = toRun.map((s) => items.get(s.id).estimate);
|
|
267
|
+
const estimatedCredits = estimates.includes(null) ? null : estimates.reduce((sum, n) => sum + (n ?? 0), 0);
|
|
236
268
|
const plan = {
|
|
237
269
|
run: toRun,
|
|
238
270
|
cached: cachedPasses,
|
|
@@ -240,7 +272,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
240
272
|
selection,
|
|
241
273
|
url,
|
|
242
274
|
estimate: estimatedCredits,
|
|
243
|
-
concurrency
|
|
275
|
+
concurrency,
|
|
244
276
|
dryRun: flags.dryRun,
|
|
245
277
|
};
|
|
246
278
|
const showPlan = () => {
|
|
@@ -258,18 +290,19 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
258
290
|
return docOf(selected.map((s) => items.get(s.id)));
|
|
259
291
|
}
|
|
260
292
|
// The cheap checks first: nothing starts unless Kane and Chrome are both there.
|
|
261
|
-
const kane = findKane(io.env);
|
|
262
293
|
if (!kane.path) {
|
|
263
294
|
throw new SetupError("kane_missing", `Kane CLI not found (${kane.from}).`, io.env.KANE_CLI ? "Point KANE_CLI at the kane-cli binary, or unset it." : "npm install -g @testmuai/kane-cli, then kane-cli login");
|
|
264
295
|
}
|
|
265
|
-
if (!findChrome())
|
|
296
|
+
if (toRun.some((s) => ["web", "desktop"].includes(s.resolvedTarget.kind)) && !findChrome(io.env))
|
|
266
297
|
throw new SetupError("chrome_missing", "Chrome not found.", "Install Google Chrome, or set CHROME_PATH to its binary.");
|
|
267
|
-
if (!url) {
|
|
298
|
+
if (needsHttp && !url) {
|
|
268
299
|
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" }`);
|
|
269
300
|
}
|
|
270
301
|
const login = await kaneLogin(kane.path, io.env);
|
|
271
302
|
if (login.state === "not_signed_in")
|
|
272
|
-
throw notSignedIn();
|
|
303
|
+
throw notSignedIn(login.detail === "not signed in" ? undefined : `Kane CLI can't run the scenarios: ${login.detail}. Nothing was built or run.`);
|
|
304
|
+
if (login.state === "keys_rejected")
|
|
305
|
+
throw keysRejected(login.detail);
|
|
273
306
|
ensureOut(out);
|
|
274
307
|
const runLog = join(out, "run.log");
|
|
275
308
|
writeFileSync(runLog, "");
|
|
@@ -279,7 +312,7 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
279
312
|
view.log(line);
|
|
280
313
|
});
|
|
281
314
|
showPlan();
|
|
282
|
-
if (await answers(url)) {
|
|
315
|
+
if (needsHttp && await answers(url)) {
|
|
283
316
|
// With a build configured, what answers was built from some earlier code, and a pass on it
|
|
284
317
|
// would be a pass nobody saw.
|
|
285
318
|
if (target.build && !flags.reuse) {
|
|
@@ -288,12 +321,12 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
288
321
|
appState = "reused";
|
|
289
322
|
view.info(`The app answers at ${url}; using it as it is${target.build ? " (--reuse: not rebuilt, passes are not cached)" : ""}.`);
|
|
290
323
|
}
|
|
291
|
-
else if (target.serve) {
|
|
324
|
+
else if (needsHttp && target.serve) {
|
|
292
325
|
const logFile = join(out, "serve.log");
|
|
293
326
|
writeFileSync(logFile, "");
|
|
294
327
|
const t0 = Date.now();
|
|
295
328
|
app = await startApp({
|
|
296
|
-
url,
|
|
329
|
+
url: url,
|
|
297
330
|
serve: target.serve.value,
|
|
298
331
|
build: target.build?.value,
|
|
299
332
|
install: target.install,
|
|
@@ -306,9 +339,20 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
306
339
|
const from = [target.build && `build from ${target.build.from}`, `serve from ${target.serve.from}`].filter(Boolean).join(", ");
|
|
307
340
|
view.info(`Started the app in ${Math.round((Date.now() - t0) / 1000)} s (${from}); its output is in ${logFile}`);
|
|
308
341
|
}
|
|
309
|
-
else {
|
|
342
|
+
else if (needsHttp) {
|
|
310
343
|
throw new SetupError("app_not_reachable", `Nothing answers at ${url}${fromNote(target.url)}.`, `Start the app first, or pass the command that serves it: proofed check --serve "npm run dev"`);
|
|
311
344
|
}
|
|
345
|
+
if (appState !== "started" && toRun.some((s) => s.resolvedTarget.kind !== "web") && (target.build || target.install)) {
|
|
346
|
+
await buildApp({ build: target.build?.value, install: target.install, cwd: target.dir, logFile: join(out, "build.log"), onPhase: (line) => view.phase(line) });
|
|
347
|
+
}
|
|
348
|
+
for (const s of toRun) {
|
|
349
|
+
if (s.resolvedTarget.kind !== "web" && keys.has(s.id))
|
|
350
|
+
keys.set(s.id, cacheKey(s, "", changed ?? [], undefined, baseId, kaneVersion));
|
|
351
|
+
const checks = await targetChecks(s.resolvedTarget, { env: io.env, launchPending: true });
|
|
352
|
+
const failed = checks.filter((c) => c.status === "fail");
|
|
353
|
+
if (failed.length)
|
|
354
|
+
throw new SetupError("target_not_ready", failed.map((c) => `${c.name}: ${c.detail}`).join("\n"), failed.map((c) => c.fix).join("\n"));
|
|
355
|
+
}
|
|
312
356
|
view.start();
|
|
313
357
|
const cacheable = !(appState === "reused" && target.build);
|
|
314
358
|
const onEvent = (e) => {
|
|
@@ -317,11 +361,16 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
317
361
|
return;
|
|
318
362
|
finished.set(e.id, e.result);
|
|
319
363
|
const key = keys.get(e.id);
|
|
320
|
-
if (!key)
|
|
321
|
-
return;
|
|
322
364
|
if (e.result.end?.credits_consumed !== undefined)
|
|
323
|
-
cache.last[e.id] = { credits: creditsOf(e.result) };
|
|
324
|
-
if (
|
|
365
|
+
cache.last[historyKey(selected.find((s) => s.id === e.id), kaneVersion)] = { credits: creditsOf(e.result) };
|
|
366
|
+
if (!key) {
|
|
367
|
+
// A forced failure invalidates the saved pass even when the version probe could not key it.
|
|
368
|
+
if (flags.noCache && kaneVersion === "unknown" && e.result.scenario.file && e.result.outcome !== "passed")
|
|
369
|
+
delete cache.passes[e.id];
|
|
370
|
+
writeCache(cacheFile, cache);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (e.result.outcome === "passed" && cacheable && (!flags.noCache || cache.passes[e.id]?.key === key)) {
|
|
325
374
|
const clip = e.result.clip && { ...(e.result.clip.mp4 && { mp4: resolve(e.result.clip.mp4) }), jpg: resolve(e.result.clip.jpg) };
|
|
326
375
|
cache.passes[e.id] = { key, passedAt: new Date().toISOString(), seconds: e.result.seconds, ...(clip && { clip }) };
|
|
327
376
|
}
|
|
@@ -330,8 +379,8 @@ export async function check(flags, text, io, view = makeView(flags, io)) {
|
|
|
330
379
|
}
|
|
331
380
|
writeCache(cacheFile, cache);
|
|
332
381
|
};
|
|
333
|
-
const results = await runAll(toRun, out, plan.concurrency, { baseUrl: url, headless: !flags.headed, onEvent });
|
|
334
|
-
// A login can run out between
|
|
382
|
+
const results = await runAll(toRun, out, plan.concurrency, { baseUrl: url ?? "", headless: !flags.headed, noRetry: flags.noRetry, onEvent, preselected: true });
|
|
383
|
+
// A login can run out between the login check and the runs; running the check again wouldn't help then either.
|
|
335
384
|
if (results.some((r) => r.notSignedIn))
|
|
336
385
|
throw notSignedIn("Kane CLI refused to run a scenario: it is not signed in. The scenarios it refused weren't checked.");
|
|
337
386
|
const byId = new Map(results.map((r) => [r.scenario.id, r]));
|