architecture-harness 0.16.0 → 0.17.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/package.json +8 -3
- package/src/cli/bash-command-guard.mjs +25 -10
- package/src/cli/bash-command-guard.test.mjs +30 -0
- package/src/cli/bash-edit-guard.mjs +28 -7
- package/src/cli/bash-edit-guard.test.mjs +24 -0
- package/src/cli/check-registries.test.mjs +181 -0
- package/src/cli/check.mjs +130 -9
- package/src/cli/cli.test.mjs +215 -2
- package/src/cli/contract-history.mjs +46 -0
- package/src/cli/contract-history.test.mjs +118 -0
- package/src/cli/controller-guard.mjs +73 -0
- package/src/cli/controller-guard.test.mjs +119 -0
- package/src/cli/dispatch-guard.mjs +9 -3
- package/src/cli/dispatch-reminder.mjs +19 -11
- package/src/cli/dispatch-reminder.test.mjs +32 -0
- package/src/cli/dispatch.mjs +3 -0
- package/src/cli/dispatch.test.mjs +15 -1
- package/src/cli/doctor.mjs +2 -1
- package/src/cli/explore-guard.mjs +2 -2
- package/src/cli/gh-merge-command.mjs +228 -0
- package/src/cli/gh-merge-command.test.mjs +273 -0
- package/src/cli/gh-run.mjs +30 -0
- package/src/cli/gh-run.test.mjs +22 -0
- package/src/cli/git-hooks.test.mjs +28 -0
- package/src/cli/git-read.mjs +42 -0
- package/src/cli/git-read.test.mjs +94 -0
- package/src/cli/init.mjs +7 -3
- package/src/cli/issue-gate.mjs +169 -0
- package/src/cli/issue-gate.test.mjs +234 -0
- package/src/cli/ledger.mjs +136 -0
- package/src/cli/ledger.test.mjs +127 -0
- package/src/cli/merge-guard.mjs +193 -0
- package/src/cli/merge-guard.test.mjs +328 -0
- package/src/cli/plan-check.mjs +151 -0
- package/src/cli/plan-check.test.mjs +143 -0
- package/src/cli/plan-stop.mjs +101 -0
- package/src/cli/plan-stop.test.mjs +136 -0
- package/src/cli/plugin-agents.test.mjs +96 -8
- package/src/cli/pr-check.mjs +17 -5
- package/src/cli/pr-check.test.mjs +85 -4
- package/src/cli/prose.mjs +192 -0
- package/src/cli/prose.test.mjs +248 -0
- package/src/cli/qc.mjs +16 -0
- package/src/cli/registry-history.mjs +1 -1
- package/src/cli/report-stash.mjs +69 -0
- package/src/cli/report-stash.test.mjs +71 -0
- package/src/cli/report-stop.mjs +256 -0
- package/src/cli/report-stop.test.mjs +432 -0
- package/src/cli/shell-command.mjs +81 -6
- package/src/cli/shell-command.test.mjs +101 -1
- package/src/cli/task-gate.mjs +157 -0
- package/src/cli/task-gate.test.mjs +421 -0
- package/src/cli/workflow-hooks.test.mjs +72 -0
- package/src/cli/workflow-place.mjs +143 -0
- package/src/cli/workflow-place.test.mjs +146 -0
- package/src/cli/workflow-settings.mjs +77 -0
- package/src/cli/workflow-settings.test.mjs +79 -0
- package/src/cli/worktree.mjs +1 -1
- package/src/cli/worktree.test.mjs +19 -2
- package/src/config.mjs +84 -3
- package/src/config.test.mjs +38 -3
- package/src/descriptions.mjs +5 -1
- package/src/eslint/index.mjs +2 -0
- package/src/eslint/jsx.mjs +57 -0
- package/src/eslint/preset.mjs +32 -6
- package/src/eslint/preset.test.mjs +60 -0
- package/src/eslint/rules/durable-idempotency-key.mjs +26 -0
- package/src/eslint/rules/ime-safe-key.mjs +1 -50
- package/src/eslint/rules/mutation-control-pending.mjs +128 -0
- package/src/eslint/rules/no-supersession-trail.mjs +8 -4
- package/src/eslint/rules/registry-literal.mjs +36 -2
- package/src/eslint/rules.test.mjs +153 -0
- package/src/gates/call-args.mjs +90 -0
- package/src/gates/call-args.test.mjs +21 -0
- package/src/gates/config-floor.mjs +41 -20
- package/src/gates/config-floor.test.mjs +71 -1
- package/src/gates/contract-idempotency.mjs +103 -0
- package/src/gates/contract-idempotency.test.mjs +276 -0
- package/src/gates/contract-operations.mjs +120 -0
- package/src/gates/contract-operations.test.mjs +275 -0
- package/src/gates/contract-routes.mjs +82 -0
- package/src/gates/contract-routes.test.mjs +210 -0
- package/src/gates/registry-literal.mjs +79 -15
- package/src/gates/registry-literal.test.mjs +89 -0
- package/src/gates/saga-key.mjs +253 -0
- package/src/gates/saga-key.test.mjs +322 -0
- package/src/gates/scrub.mjs +108 -0
- package/src/gates/scrub.test.mjs +29 -0
- package/src/gates/tenant-isolation-test.mjs +80 -0
- package/src/gates/tenant-isolation-test.test.mjs +129 -0
- package/src/gates/tenant-predicate.mjs +644 -91
- package/src/gates/tenant-predicate.test.mjs +662 -1
- package/src/prose-lines.mjs +49 -0
- package/src/prose-lines.test.mjs +63 -0
- package/src/registries.mjs +89 -0
- package/src/registries.test.mjs +44 -0
- package/src/vale-style.test.mjs +158 -0
- package/templates/docs/enforcement.md +26 -2
- package/templates/github/workflows/ci.yml +18 -1
- package/templates/quality-thresholds.json +1 -1
- package/templates/vale/.vale.ini +7 -0
- package/templates/vale/styles/Qc/AndOr.yml +7 -0
- package/templates/vale/styles/Qc/InOrderTo.yml +6 -0
- package/templates/vale/styles/Qc/Latin.yml +9 -0
- package/templates/vale/styles/Qc/PassiveVoice.yml +21 -0
- package/templates/vale/styles/Qc/Please.yml +6 -0
- package/templates/vale/styles/Qc/Progress.yml +9 -0
- package/templates/vale/styles/Qc/SentenceLength.yml +6 -0
- package/templates/vale/styles/Qc/Utilize.yml +10 -0
package/src/cli/pr-check.mjs
CHANGED
|
@@ -18,17 +18,25 @@ export function issueReferences(body, repo) {
|
|
|
18
18
|
function runGh(args) {
|
|
19
19
|
return new Promise((resolve) => {
|
|
20
20
|
execFile("gh", args, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
21
|
-
resolve(error ? { ok: false, stderr: `${stderr || error.message}` } : { ok: true, stdout });
|
|
21
|
+
resolve(error ? { ok: false, missing: error.code === "ENOENT", stderr: `${stderr || error.message}` } : { ok: true, stdout });
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** @returns whether `CI` is set to a value that means yes: an empty value and `false` mean no. */
|
|
27
|
+
export function isCi(env) {
|
|
28
|
+
const value = `${env.CI ?? ""}`.trim().toLowerCase();
|
|
29
|
+
return value !== "" && value !== "false";
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
/**
|
|
33
|
+
* In CI a missing `gh` or a failed call fails the check, so a broken runner cannot pass it in silence.
|
|
34
|
+
* Elsewhere the same failure is a note.
|
|
27
35
|
* @param {object} event the GitHub event payload
|
|
28
|
-
* @param {{gh?: (args: string[]) => Promise<{ok: boolean, stdout?: string, stderr?: string}>, hasToken: boolean}} options
|
|
36
|
+
* @param {{gh?: (args: string[]) => Promise<{ok: boolean, missing?: boolean, stdout?: string, stderr?: string}>, hasToken: boolean, ci?: boolean}} options
|
|
29
37
|
* @returns {Promise<{problems: string[], notes: string[]}>}
|
|
30
38
|
*/
|
|
31
|
-
export async function checkPullRequest(event, { gh = runGh, hasToken }) {
|
|
39
|
+
export async function checkPullRequest(event, { gh = runGh, hasToken, ci = false }) {
|
|
32
40
|
const pr = event?.pull_request;
|
|
33
41
|
if (!pr) return { problems: [], notes: ["the event is not a pull request, so there is no body to read"] };
|
|
34
42
|
const references = issueReferences(pr.body, event.repository?.full_name);
|
|
@@ -49,7 +57,11 @@ export async function checkPullRequest(event, { gh = runGh, hasToken }) {
|
|
|
49
57
|
const stderr = result.stderr ?? "";
|
|
50
58
|
if (NO_ISSUE.test(stderr)) problems.push(`${name} does not exist. Open the issue, then reference it.`);
|
|
51
59
|
else if (NO_REPOSITORY.test(stderr)) notes.push(`the token cannot see ${repo}, so ${name} was not looked up`);
|
|
52
|
-
else
|
|
60
|
+
else if (ci && result.missing) problems.push(`gh is not installed, so ${name} cannot be checked`);
|
|
61
|
+
else {
|
|
62
|
+
const message = `could not reach GitHub for ${name}: ${stderr.trim().split("\n")[0]}`;
|
|
63
|
+
(ci ? problems : notes).push(message);
|
|
64
|
+
}
|
|
53
65
|
continue;
|
|
54
66
|
}
|
|
55
67
|
const created = JSON.parse(result.stdout).createdAt;
|
|
@@ -66,7 +78,7 @@ export async function runPrCheck(env = process.env) {
|
|
|
66
78
|
return 0;
|
|
67
79
|
}
|
|
68
80
|
const event = JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf8"));
|
|
69
|
-
const { problems, notes } = await checkPullRequest(event, { hasToken: Boolean(env.GH_TOKEN || env.GITHUB_TOKEN) });
|
|
81
|
+
const { problems, notes } = await checkPullRequest(event, { hasToken: Boolean(env.GH_TOKEN || env.GITHUB_TOKEN), ci: isCi(env) });
|
|
70
82
|
for (const note of notes) console.log(`NOTE pr-check ${note}`);
|
|
71
83
|
for (const problem of problems) console.error(`FAIL pr-check ${problem}`);
|
|
72
84
|
if (problems.length === 0) console.log("OK pr-check the pull request names an issue opened before it");
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { strict as assert } from "node:assert";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { checkPullRequest, isCi, issueReferences, runPrCheck } from "./pr-check.mjs";
|
|
4
7
|
|
|
5
8
|
const event = (body) => ({
|
|
6
9
|
repository: { full_name: "acme/app" },
|
|
@@ -14,6 +17,9 @@ const ghKnowing = (issues) => async (args) => {
|
|
|
14
17
|
return { ok: true, stdout: JSON.stringify({ createdAt: created }) };
|
|
15
18
|
};
|
|
16
19
|
|
|
20
|
+
const unreachable = async () => ({ ok: false, stderr: "dial tcp: lookup api.github.com: no such host" });
|
|
21
|
+
const missingGh = async () => ({ ok: false, missing: true, stderr: "spawn gh ENOENT" });
|
|
22
|
+
|
|
17
23
|
test("a PR body names its issue as Fixes #n, Refs #n, or a cross-repository Refs owner/repo#n", () => {
|
|
18
24
|
assert.deepEqual(issueReferences("Fixes #12\nrefs #3, and Refs other/lib#7", "acme/app"), [
|
|
19
25
|
{ repo: "acme/app", number: 12 },
|
|
@@ -35,14 +41,59 @@ test("an issue that exists and predates the PR passes; a missing or newer one fa
|
|
|
35
41
|
assert.match((await checkPullRequest(event("Refs #13"), { gh, hasToken: true })).problems.join(), /was opened after the pull request/);
|
|
36
42
|
});
|
|
37
43
|
|
|
38
|
-
test("with no token, or no network, the issue lookup skips with a note, but the reference is still required", async () => {
|
|
44
|
+
test("with no token, or outside CI with no network, the issue lookup skips with a note, but the reference is still required", async () => {
|
|
39
45
|
const noToken = await checkPullRequest(event("Fixes #12"), { gh: ghKnowing({}), hasToken: false });
|
|
40
46
|
assert.deepEqual(noToken.problems, []);
|
|
41
47
|
assert.match(noToken.notes.join(), /no GH_TOKEN/);
|
|
42
|
-
|
|
48
|
+
assert.match((await checkPullRequest(event(""), { gh: ghKnowing({}), hasToken: false })).problems.join(), /names no issue/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("outside CI the same failure stays a note", async () => {
|
|
52
|
+
const offline = await checkPullRequest(event("Fixes #12"), { gh: unreachable, hasToken: true, ci: false });
|
|
43
53
|
assert.deepEqual(offline.problems, []);
|
|
44
54
|
assert.match(offline.notes.join(), /could not reach GitHub/);
|
|
45
|
-
|
|
55
|
+
const noGh = await checkPullRequest(event("Fixes #12"), { gh: missingGh, hasToken: true, ci: false });
|
|
56
|
+
assert.deepEqual(noGh.problems, []);
|
|
57
|
+
assert.match(noGh.notes.join(), /could not reach GitHub/);
|
|
58
|
+
const unset = await checkPullRequest(event("Fixes #12"), { gh: unreachable, hasToken: true });
|
|
59
|
+
assert.deepEqual(unset.problems, []);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("in CI a missing gh fails with a message that names gh", async () => {
|
|
63
|
+
const result = await checkPullRequest(event("Fixes #12"), { gh: missingGh, hasToken: true, ci: true });
|
|
64
|
+
assert.equal(result.problems.length, 1);
|
|
65
|
+
assert.match(result.problems[0], /gh is not installed, so acme\/app#12 cannot be checked/);
|
|
66
|
+
assert.deepEqual(result.notes, []);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("in CI a failed call to GitHub fails and quotes the first stderr line", async () => {
|
|
70
|
+
const gh = async () => ({ ok: false, stderr: "HTTP 502: Bad Gateway\nsecond line" });
|
|
71
|
+
const result = await checkPullRequest(event("Fixes #12"), { gh, hasToken: true, ci: true });
|
|
72
|
+
assert.equal(result.problems.length, 1);
|
|
73
|
+
assert.match(result.problems[0], /could not reach GitHub for acme\/app#12: HTTP 502: Bad Gateway$/);
|
|
74
|
+
assert.deepEqual(result.notes, []);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("in CI with no token the check is still a note", async () => {
|
|
78
|
+
const result = await checkPullRequest(event("Fixes #12"), { gh: missingGh, hasToken: false, ci: true });
|
|
79
|
+
assert.deepEqual(result.problems, []);
|
|
80
|
+
assert.match(result.notes.join(), /no GH_TOKEN/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("in CI a repository the token cannot see is still a note", async () => {
|
|
84
|
+
const gh = async () => ({ ok: false, stderr: "GraphQL: Could not resolve to a Repository with the name 'acme/private'. (repository)" });
|
|
85
|
+
const result = await checkPullRequest(event("Refs acme/private#5"), { gh, hasToken: true, ci: true });
|
|
86
|
+
assert.deepEqual(result.problems, []);
|
|
87
|
+
assert.match(result.notes.join(), /the token cannot see acme.private/);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("CI=false is not CI", () => {
|
|
91
|
+
assert.equal(isCi({ CI: "true" }), true);
|
|
92
|
+
assert.equal(isCi({ CI: "1" }), true);
|
|
93
|
+
assert.equal(isCi({ CI: "" }), false);
|
|
94
|
+
assert.equal(isCi({ CI: "false" }), false);
|
|
95
|
+
assert.equal(isCi({ CI: "FALSE" }), false);
|
|
96
|
+
assert.equal(isCi({}), false);
|
|
46
97
|
});
|
|
47
98
|
|
|
48
99
|
test("a repository the token cannot see is a note, never a missing issue", async () => {
|
|
@@ -57,3 +108,33 @@ test("an event that is no pull request is skipped", async () => {
|
|
|
57
108
|
assert.deepEqual(result.problems, []);
|
|
58
109
|
assert.match(result.notes.join(), /not a pull request/);
|
|
59
110
|
});
|
|
111
|
+
|
|
112
|
+
test("runPrCheck reads CI, and a gh that is not on PATH fails only in CI", async () => {
|
|
113
|
+
const dir = mkdtempSync(join(tmpdir(), "pr-check-"));
|
|
114
|
+
const eventPath = join(dir, "event.json");
|
|
115
|
+
writeFileSync(eventPath, JSON.stringify(event("Fixes #12")));
|
|
116
|
+
const run = async (ci) => {
|
|
117
|
+
const lines = [];
|
|
118
|
+
const { log, error } = console;
|
|
119
|
+
console.log = console.error = (...args) => lines.push(args.join(" "));
|
|
120
|
+
try {
|
|
121
|
+
return { code: await runPrCheck({ GITHUB_EVENT_PATH: eventPath, GH_TOKEN: "x", CI: ci }), output: lines.join("\n") };
|
|
122
|
+
} finally {
|
|
123
|
+
console.log = log;
|
|
124
|
+
console.error = error;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const path = process.env.PATH;
|
|
128
|
+
process.env.PATH = "";
|
|
129
|
+
try {
|
|
130
|
+
const inCi = await run("true");
|
|
131
|
+
assert.equal(inCi.code, 1);
|
|
132
|
+
assert.match(inCi.output, /gh is not installed/);
|
|
133
|
+
const notCi = await run("false");
|
|
134
|
+
assert.equal(notCi.code, 0);
|
|
135
|
+
assert.match(notCi.output, /could not reach GitHub/);
|
|
136
|
+
} finally {
|
|
137
|
+
process.env.PATH = path;
|
|
138
|
+
rmSync(dir, { recursive: true, force: true });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// `qc prose` holds the lines a change adds to the prose style, and no others. Vale reads whole files,
|
|
2
|
+
// so a sentence keeps its context, and this module keeps the alerts that fall on an added line.
|
|
3
|
+
// Vale is an external binary: outside CI its absence is a note, and in CI it fails the check, as a
|
|
4
|
+
// missing `gh` fails `qc pr-check`.
|
|
5
|
+
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { adrLog } from "../config.mjs";
|
|
12
|
+
import { globMatcher } from "../glob.mjs";
|
|
13
|
+
import { parseAddedLines } from "../prose-lines.mjs";
|
|
14
|
+
import { isCi } from "./pr-check.mjs";
|
|
15
|
+
|
|
16
|
+
const KIT_VALE_CONFIG = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../templates/vale/.vale.ini");
|
|
17
|
+
const MARKDOWN = /\.mdx?$/i;
|
|
18
|
+
const FILES_PER_CALL = 100;
|
|
19
|
+
const BUFFER_BYTES = 64 * 1024 * 1024;
|
|
20
|
+
const TIMEOUT_MS = 60_000;
|
|
21
|
+
const USAGE = "usage: qc prose [--base <ref>] [--pr-body <file>] [--pr-body-event]";
|
|
22
|
+
|
|
23
|
+
/** Runs one process, and never throws: a missing binary is a failed call like any other. */
|
|
24
|
+
function run(command, args, cwd) {
|
|
25
|
+
const result = spawnSync(command, args, { cwd, encoding: "utf8", windowsHide: true, maxBuffer: BUFFER_BYTES, timeout: TIMEOUT_MS });
|
|
26
|
+
if (result.error) return { ok: false, missing: result.error.code === "ENOENT", stderr: result.error.message };
|
|
27
|
+
return result.status === 0 ? { ok: true, stdout: result.stdout ?? "" } : { ok: false, stderr: `${result.stderr || result.stdout || ""}` };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @returns the Vale run of `args` from `cwd`, as `{ok, missing?, stdout?, stderr?}`. */
|
|
31
|
+
export const runVale = async (args, { cwd }) => run("vale", args, cwd);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @returns one spelling of `file`, so a key Vale prints matches the path that was passed. `path.resolve`
|
|
35
|
+
* gives the platform's own separator. Windows paths ignore case. On POSIX a backslash is part of a name.
|
|
36
|
+
*/
|
|
37
|
+
function canonical(root, file) {
|
|
38
|
+
const absolute = path.resolve(root, file);
|
|
39
|
+
return process.platform === "win32" ? absolute.toLowerCase() : absolute;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @returns the unified diff of the markdown files that `base...HEAD` changed, or null when git cannot read it. */
|
|
43
|
+
function readDiff(root, base) {
|
|
44
|
+
const args = ["-c", "core.quotepath=off", "diff", "-U0", "--no-color", "--no-ext-diff", `${base}...HEAD`, "--", "*.md", "*.mdx"];
|
|
45
|
+
const result = run("git", args, root);
|
|
46
|
+
return result.ok ? result.stdout : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @returns the added lines that sit in a linted markdown file: in `prose.paths`, and outside the ADR log and `prose.exempt`. */
|
|
50
|
+
export function inScope(config, added) {
|
|
51
|
+
const linted = globMatcher(config.prose.paths);
|
|
52
|
+
const exempt = globMatcher([...adrLog(config), ...config.prose.exempt]);
|
|
53
|
+
return added.filter((line) => MARKDOWN.test(line.path) && linted(line.path) && !exempt(line.path));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const valeConfigOf = (config) => {
|
|
57
|
+
const own = path.join(config.root, config.prose.valeConfig);
|
|
58
|
+
return existsSync(own) ? own : KIT_VALE_CONFIG;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Runs Vale on the files that hold `added`, and keeps the alerts on those lines. An error fails; a
|
|
63
|
+
* warning or a suggestion is advice.
|
|
64
|
+
* @param {object} config
|
|
65
|
+
* @param {{added: {path: string, line: number, text: string, label?: string}[], vale?: typeof runVale, ci?: boolean}} options
|
|
66
|
+
* @returns {Promise<{problems: string[], warnings: string[], notes: string[], checked: number, complete: boolean}>}
|
|
67
|
+
*/
|
|
68
|
+
export async function checkProse(config, { added, vale = runVale, ci = false }) {
|
|
69
|
+
const result = { problems: [], warnings: [], notes: [], checked: added.length, complete: true };
|
|
70
|
+
if (added.length === 0) return result;
|
|
71
|
+
|
|
72
|
+
const files = new Map();
|
|
73
|
+
for (const { path: file, line, label } of added) {
|
|
74
|
+
const key = canonical(config.root, file);
|
|
75
|
+
const entry = files.get(key) ?? { file, label: label ?? file, lines: new Set() };
|
|
76
|
+
entry.lines.add(line);
|
|
77
|
+
files.set(key, entry);
|
|
78
|
+
}
|
|
79
|
+
const failure = ci ? result.problems : result.notes;
|
|
80
|
+
const ini = valeConfigOf(config);
|
|
81
|
+
const names = [...files.values()].map((entry) => entry.file);
|
|
82
|
+
|
|
83
|
+
for (let from = 0; from < names.length; from += FILES_PER_CALL) {
|
|
84
|
+
const call = await vale([`--config=${ini}`, "--output=JSON", "--no-exit", ...names.slice(from, from + FILES_PER_CALL)], { cwd: config.root });
|
|
85
|
+
if (!call.ok) {
|
|
86
|
+
const cause = call.missing ? "vale is not installed" : `vale failed: ${(call.stderr ?? "").trim().split("\n")[0]}`;
|
|
87
|
+
failure.push(`${cause}, so the ${added.length} added line(s) were not checked. Install Vale from https://vale.sh to run this check.`);
|
|
88
|
+
return { ...result, complete: false };
|
|
89
|
+
}
|
|
90
|
+
let report;
|
|
91
|
+
try {
|
|
92
|
+
report = JSON.parse(call.stdout?.trim() || "{}");
|
|
93
|
+
} catch {
|
|
94
|
+
failure.push("vale printed output that is not JSON, so the added lines were not checked");
|
|
95
|
+
return { ...result, complete: false };
|
|
96
|
+
}
|
|
97
|
+
for (const [file, alerts] of Object.entries(report)) {
|
|
98
|
+
const entry = files.get(canonical(config.root, file));
|
|
99
|
+
if (!entry || !Array.isArray(alerts)) continue;
|
|
100
|
+
for (const alert of alerts.filter((each) => entry.lines.has(each.Line))) {
|
|
101
|
+
const text = `${entry.label}:${alert.Line} ${alert.Check}: ${alert.Message}`;
|
|
102
|
+
(alert.Severity === "error" ? result.problems : result.warnings).push(text);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseArgs(args) {
|
|
110
|
+
const parsed = { base: null, prBodyFile: null, prBodyEvent: false };
|
|
111
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
112
|
+
const arg = args[index];
|
|
113
|
+
if (arg === "--base" && args[index + 1]) parsed.base = args[++index];
|
|
114
|
+
else if (arg === "--pr-body" && args[index + 1]) parsed.prBodyFile = args[++index];
|
|
115
|
+
else if (arg === "--pr-body-event") parsed.prBodyEvent = true;
|
|
116
|
+
else return null;
|
|
117
|
+
}
|
|
118
|
+
return parsed;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @returns the pull request bodies the options name, each as `{label, text}`. A reason for none goes to `notes` or `problems`. */
|
|
122
|
+
function readBodies(root, parsed, env, notes, problems) {
|
|
123
|
+
const bodies = [];
|
|
124
|
+
if (parsed.prBodyFile) {
|
|
125
|
+
try {
|
|
126
|
+
bodies.push({ label: "PR body (file)", text: readFileSync(path.resolve(root, parsed.prBodyFile), "utf8") });
|
|
127
|
+
} catch (error) {
|
|
128
|
+
problems.push(`cannot read the pull request body: ${error.message}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (parsed.prBodyEvent) {
|
|
132
|
+
if (!env.GITHUB_EVENT_PATH) {
|
|
133
|
+
notes.push("no GITHUB_EVENT_PATH, so there is no pull request body to read");
|
|
134
|
+
} else {
|
|
135
|
+
try {
|
|
136
|
+
const pr = JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf8"))?.pull_request;
|
|
137
|
+
if (pr) bodies.push({ label: "PR body (event)", text: pr.body ?? "" });
|
|
138
|
+
else notes.push("the event is not a pull request, so there is no body to read");
|
|
139
|
+
} catch (error) {
|
|
140
|
+
problems.push(`cannot read the pull request body: ${error.message}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// One body keeps the plain label. Two need a label that tells their lines apart.
|
|
145
|
+
return bodies.length === 1 ? [{ ...bodies[0], label: "PR body" }] : bodies;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {object} config
|
|
150
|
+
* @param {string[]} args `--base <ref>`, `--pr-body <file>`, `--pr-body-event`
|
|
151
|
+
* @param {{env?: NodeJS.ProcessEnv, vale?: typeof runVale, base?: string}} [options]
|
|
152
|
+
* @returns {Promise<number>} the exit code
|
|
153
|
+
*/
|
|
154
|
+
export async function runProse(config, args, { env = process.env, vale = runVale, base } = {}) {
|
|
155
|
+
const parsed = parseArgs(args);
|
|
156
|
+
if (parsed === null) {
|
|
157
|
+
console.error(USAGE);
|
|
158
|
+
return 2;
|
|
159
|
+
}
|
|
160
|
+
const ci = isCi(env);
|
|
161
|
+
const notes = [];
|
|
162
|
+
const problems = [];
|
|
163
|
+
const ref = parsed.base ?? base ?? config.prose.base;
|
|
164
|
+
|
|
165
|
+
let added = [];
|
|
166
|
+
const diff = readDiff(config.root, ref);
|
|
167
|
+
if (diff === null) {
|
|
168
|
+
(ci ? problems : notes).push(`git cannot diff ${ref}...HEAD, so the added lines were not read. In CI, check out full history and fetch ${ref}.`);
|
|
169
|
+
} else {
|
|
170
|
+
added = inScope(config, parseAddedLines(diff));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const scratch = mkdtempSync(path.join(os.tmpdir(), "qc-prose-"));
|
|
174
|
+
try {
|
|
175
|
+
for (const [index, body] of readBodies(config.root, parsed, env, notes, problems).entries()) {
|
|
176
|
+
const file = path.join(scratch, `pr-body-${index + 1}.md`);
|
|
177
|
+
const text = body.text.replace(/\r\n/g, "\n");
|
|
178
|
+
writeFileSync(file, text);
|
|
179
|
+
added.push(...text.split("\n").map((line, at) => ({ path: file, line: at + 1, text: line, label: body.label })));
|
|
180
|
+
}
|
|
181
|
+
const result = await checkProse(config, { added, vale, ci });
|
|
182
|
+
problems.push(...result.problems);
|
|
183
|
+
notes.push(...result.notes);
|
|
184
|
+
for (const note of notes) console.log(`NOTE prose ${note}`);
|
|
185
|
+
for (const warning of result.warnings) console.log(`WARN prose ${warning}`);
|
|
186
|
+
for (const problem of problems) console.error(`FAIL prose ${problem}`);
|
|
187
|
+
if (problems.length === 0 && result.complete && diff !== null) console.log(`OK prose ${result.checked} added line(s) meet the prose style`);
|
|
188
|
+
} finally {
|
|
189
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
190
|
+
}
|
|
191
|
+
return problems.length > 0 ? 1 : 0;
|
|
192
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { defaults, merge } from "../config.mjs";
|
|
8
|
+
import { checkProse, runProse } from "./prose.mjs";
|
|
9
|
+
|
|
10
|
+
const config = (root) => ({ ...merge(defaults, {}), root });
|
|
11
|
+
|
|
12
|
+
/** A stand-in for Vale: it flags the words the style forbids, as Vale's JSON output reports them. */
|
|
13
|
+
const RULES = [
|
|
14
|
+
{ check: "Qc.Utilize", severity: "error", pattern: /\butilize\b/i, message: "Use 'use' instead of 'utilize'." },
|
|
15
|
+
{ check: "Qc.Please", severity: "error", pattern: /\bplease\b/i, message: "Do not write 'please' in an instruction." },
|
|
16
|
+
{ check: "Qc.SentenceLength", severity: "warning", pattern: /(\S+\s+){25}\S+/, message: "Write 25 words or fewer." },
|
|
17
|
+
];
|
|
18
|
+
function fakeVale(calls = []) {
|
|
19
|
+
return async (args, { cwd }) => {
|
|
20
|
+
const files = args.filter((arg) => !arg.startsWith("--"));
|
|
21
|
+
calls.push(files);
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const file of files) {
|
|
24
|
+
const lines = readFileSync(path.resolve(cwd, file), "utf8").split("\n");
|
|
25
|
+
out[file] = lines.flatMap((text, index) =>
|
|
26
|
+
RULES.filter((rule) => rule.pattern.test(text)).map((rule) => ({
|
|
27
|
+
Check: rule.check,
|
|
28
|
+
Severity: rule.severity,
|
|
29
|
+
Message: rule.message,
|
|
30
|
+
Line: index + 1,
|
|
31
|
+
Span: [1, 2],
|
|
32
|
+
})),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return { ok: true, stdout: JSON.stringify(out) };
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const missingVale = async () => ({ ok: false, missing: true, stderr: "spawn vale ENOENT" });
|
|
39
|
+
|
|
40
|
+
function git(cwd, ...args) {
|
|
41
|
+
return execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", ...args], { cwd, encoding: "utf8" });
|
|
42
|
+
}
|
|
43
|
+
/** A repository whose `main` holds `before`, and whose `topic` branch holds `after`; each maps a path to its text. */
|
|
44
|
+
function repo(before, after) {
|
|
45
|
+
const root = mkdtempSync(path.join(tmpdir(), "prose-"));
|
|
46
|
+
git(root, "init", "-q", "-b", "main");
|
|
47
|
+
const write = (files) => {
|
|
48
|
+
for (const [file, text] of Object.entries(files)) {
|
|
49
|
+
mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
50
|
+
writeFileSync(path.join(root, file), text);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
write(before);
|
|
54
|
+
git(root, "add", "-A");
|
|
55
|
+
git(root, "commit", "-q", "-m", "base");
|
|
56
|
+
git(root, "checkout", "-q", "-b", "topic");
|
|
57
|
+
write(after);
|
|
58
|
+
git(root, "add", "-A");
|
|
59
|
+
git(root, "commit", "-q", "--allow-empty", "-m", "topic");
|
|
60
|
+
return root;
|
|
61
|
+
}
|
|
62
|
+
/** Runs `runProse` in `root` with the given argument list, and returns the exit code and both output streams. */
|
|
63
|
+
async function run(root, args, options = {}) {
|
|
64
|
+
const lines = { out: [], err: [] };
|
|
65
|
+
const log = console.log;
|
|
66
|
+
const error = console.error;
|
|
67
|
+
console.log = (line) => lines.out.push(line);
|
|
68
|
+
console.error = (line) => lines.err.push(line);
|
|
69
|
+
try {
|
|
70
|
+
const code = await runProse(config(root), args, { env: {}, vale: fakeVale(), base: "main", ...options });
|
|
71
|
+
return { code, out: lines.out.join("\n"), err: lines.err.join("\n") };
|
|
72
|
+
} finally {
|
|
73
|
+
console.log = log;
|
|
74
|
+
console.error = error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Runs the body of a test in a repository, and removes the repository afterwards. */
|
|
78
|
+
async function inRepo(before, after, body) {
|
|
79
|
+
const root = repo(before, after);
|
|
80
|
+
try {
|
|
81
|
+
await body(root);
|
|
82
|
+
} finally {
|
|
83
|
+
rmSync(root, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
test("an added line with 'please utilize' fails", async () => {
|
|
88
|
+
await inRepo({ "docs/a.md": "# A\n" }, { "docs/a.md": "# A\nPlease utilize the map.\n" }, async (root) => {
|
|
89
|
+
const { code, err } = await run(root, []);
|
|
90
|
+
assert.equal(code, 1);
|
|
91
|
+
assert.match(err, /docs\/a\.md:2/);
|
|
92
|
+
assert.match(err, /Qc\.Utilize/);
|
|
93
|
+
assert.match(err, /Qc\.Please/);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("an unchanged old line with the same words does not", async () => {
|
|
98
|
+
await inRepo({ "docs/a.md": "Please utilize the map.\n" }, { "docs/a.md": "Please utilize the map.\nA clean new line.\n" }, async (root) => {
|
|
99
|
+
const { code, err } = await run(root, []);
|
|
100
|
+
assert.equal(code, 0, err);
|
|
101
|
+
assert.equal(err, "");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("an ADR path, a changelog and a session report are exempt", async () => {
|
|
106
|
+
const bad = "Please utilize the map.\n";
|
|
107
|
+
const after = { "docs/decisions/0001-x.md": bad, "docs/decisions.md": bad, "CHANGELOG.md": bad, "docs/reports/s1.md": bad };
|
|
108
|
+
await inRepo({ "README.md": "# R\n" }, after, async (root) => {
|
|
109
|
+
const calls = [];
|
|
110
|
+
const { code, err } = await run(root, [], { vale: fakeVale(calls) });
|
|
111
|
+
assert.equal(code, 0, err);
|
|
112
|
+
assert.deepEqual(calls, []);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("a file outside prose.paths is not linted", async () => {
|
|
117
|
+
await inRepo({ "README.md": "# R\n" }, { "src/notes.md": "Please utilize the map.\n" }, async (root) => {
|
|
118
|
+
assert.equal((await run(root, [])).code, 0);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a warning is printed and never fails", async () => {
|
|
123
|
+
const long = Array.from({ length: 30 }, (_, index) => `word${index}`).join(" ");
|
|
124
|
+
await inRepo({ "docs/a.md": "# A\n" }, { "docs/a.md": `# A\n${long}\n` }, async (root) => {
|
|
125
|
+
const { code, out } = await run(root, []);
|
|
126
|
+
assert.equal(code, 0);
|
|
127
|
+
assert.match(out, /WARN\s+prose\s+docs\/a\.md:2\s+Qc\.SentenceLength/);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("a missing vale binary is a note, not a failure, outside CI", async () => {
|
|
132
|
+
await inRepo({ "docs/a.md": "# A\n" }, { "docs/a.md": "# A\nPlease utilize the map.\n" }, async (root) => {
|
|
133
|
+
const { code, out } = await run(root, [], { vale: missingVale });
|
|
134
|
+
assert.equal(code, 0);
|
|
135
|
+
assert.match(out, /NOTE\s+prose.*vale/i);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("a missing vale binary fails in CI", async () => {
|
|
140
|
+
await inRepo({ "docs/a.md": "# A\n" }, { "docs/a.md": "# A\nA clean line.\n" }, async (root) => {
|
|
141
|
+
const { code, err } = await run(root, [], { vale: missingVale, env: { CI: "true" } });
|
|
142
|
+
assert.equal(code, 1);
|
|
143
|
+
assert.match(err, /FAIL\s+prose.*vale is not installed/i);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("a change with no prose in scope does not need vale", async () => {
|
|
148
|
+
await inRepo({ "src/a.ts": "a\n" }, { "src/a.ts": "b\n" }, async (root) => {
|
|
149
|
+
const { code, out } = await run(root, [], { vale: missingVale, env: { CI: "true" } });
|
|
150
|
+
assert.equal(code, 0);
|
|
151
|
+
assert.match(out, /OK\s+prose/);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("a base ref that git cannot read fails in CI and is a note elsewhere", async () => {
|
|
156
|
+
await inRepo({ "docs/a.md": "# A\n" }, { "docs/a.md": "# A\nx\n" }, async (root) => {
|
|
157
|
+
const ci = await run(root, ["--base", "origin/nope"], { env: { CI: "1" } });
|
|
158
|
+
assert.equal(ci.code, 1);
|
|
159
|
+
assert.match(ci.err, /origin\/nope/);
|
|
160
|
+
const local = await run(root, ["--base", "origin/nope"]);
|
|
161
|
+
assert.equal(local.code, 0);
|
|
162
|
+
assert.match(local.out, /NOTE\s+prose.*origin\/nope/);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("a PR body is linted whole, from a file or from the event", async () => {
|
|
167
|
+
await inRepo({ "README.md": "# R\n" }, { "README.md": "# R\n" }, async (root) => {
|
|
168
|
+
writeFileSync(path.join(root, "body.md"), "Fixes #3\n\nPlease utilize the map.\n");
|
|
169
|
+
const fromFile = await run(root, ["--pr-body", "body.md"]);
|
|
170
|
+
assert.equal(fromFile.code, 1);
|
|
171
|
+
assert.match(fromFile.err, /PR body:3/);
|
|
172
|
+
|
|
173
|
+
const eventPath = path.join(root, "event.json");
|
|
174
|
+
const env = { GITHUB_EVENT_PATH: eventPath };
|
|
175
|
+
writeFileSync(eventPath, JSON.stringify({ pull_request: { number: 3, body: "Fixes #3\n\nA clean body.\n" } }));
|
|
176
|
+
const clean = await run(root, ["--pr-body-event"], { env });
|
|
177
|
+
assert.equal(clean.code, 0, clean.err);
|
|
178
|
+
writeFileSync(eventPath, JSON.stringify({ pull_request: { number: 3, body: "Utilize it." } }));
|
|
179
|
+
const dirty = await run(root, ["--pr-body-event"], { env });
|
|
180
|
+
assert.equal(dirty.code, 1);
|
|
181
|
+
assert.match(dirty.err, /PR body:1/);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("--pr-body-event outside a pull request event is a note", async () => {
|
|
186
|
+
await inRepo({ "README.md": "# R\n" }, { "README.md": "# R\n" }, async (root) => {
|
|
187
|
+
const { code, out } = await run(root, ["--pr-body-event"], { env: {} });
|
|
188
|
+
assert.equal(code, 0);
|
|
189
|
+
assert.match(out, /NOTE\s+prose.*no pull request/i);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("checkProse keeps only the alerts on added lines", async () => {
|
|
194
|
+
const root = mkdtempSync(path.join(tmpdir(), "prose-"));
|
|
195
|
+
try {
|
|
196
|
+
writeFileSync(path.join(root, "a.md"), "Please old.\nPlease new.\n");
|
|
197
|
+
const added = [{ path: "a.md", line: 2, text: "Please new." }];
|
|
198
|
+
const { problems } = await checkProse(config(root), { added, vale: fakeVale(), ci: false });
|
|
199
|
+
assert.equal(problems.length, 1);
|
|
200
|
+
assert.match(problems[0], /a\.md:2/);
|
|
201
|
+
} finally {
|
|
202
|
+
rmSync(root, { recursive: true, force: true });
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("a skipped check does not print OK", async () => {
|
|
207
|
+
await inRepo({ "docs/a.md": "# A\n" }, { "docs/a.md": "# A\nA clean line.\n" }, async (root) => {
|
|
208
|
+
const { out } = await run(root, [], { vale: missingVale });
|
|
209
|
+
assert.doesNotMatch(out, /OK\s+prose/);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
/** Every spelling of `a.md` that Vale may print for the file: as passed, absolute, and on Windows the other separator and the other case. */
|
|
214
|
+
function spellings(root) {
|
|
215
|
+
const absolute = path.resolve(root, "a.md");
|
|
216
|
+
const list = ["a.md", absolute];
|
|
217
|
+
if (process.platform === "win32") list.push(absolute.replaceAll("\\", "/"), absolute.toLowerCase(), absolute.toUpperCase());
|
|
218
|
+
return list;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
test("an alert keyed by any spelling of the file's path maps to that file", async () => {
|
|
222
|
+
const root = mkdtempSync(path.join(tmpdir(), "prose-"));
|
|
223
|
+
try {
|
|
224
|
+
writeFileSync(path.join(root, "a.md"), "Please new.\n");
|
|
225
|
+
for (const key of spellings(root)) {
|
|
226
|
+
const vale = async (args, options) => {
|
|
227
|
+
const relative = JSON.parse((await fakeVale()(args, options)).stdout);
|
|
228
|
+
return { ok: true, stdout: JSON.stringify(Object.fromEntries(Object.entries(relative).map(([, alerts]) => [key, alerts]))) };
|
|
229
|
+
};
|
|
230
|
+
const { problems } = await checkProse(config(root), { added: [{ path: "a.md", line: 1, text: "Please new." }], vale, ci: false });
|
|
231
|
+
assert.equal(problems.length, 1, key);
|
|
232
|
+
}
|
|
233
|
+
} finally {
|
|
234
|
+
rmSync(root, { recursive: true, force: true });
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("--pr-body and --pr-body-event together check both bodies", async () => {
|
|
239
|
+
await inRepo({ "README.md": "# R\n" }, { "README.md": "# R\n" }, async (root) => {
|
|
240
|
+
writeFileSync(path.join(root, "body.md"), "Please read.\n");
|
|
241
|
+
const eventPath = path.join(root, "event.json");
|
|
242
|
+
writeFileSync(eventPath, JSON.stringify({ pull_request: { number: 3, body: "\nUtilize it." } }));
|
|
243
|
+
const { code, err } = await run(root, ["--pr-body", "body.md", "--pr-body-event"], { env: { GITHUB_EVENT_PATH: eventPath } });
|
|
244
|
+
assert.equal(code, 1);
|
|
245
|
+
assert.match(err, /PR body \(file\):1.*Qc\.Please/);
|
|
246
|
+
assert.match(err, /PR body \(event\):2.*Qc\.Utilize/);
|
|
247
|
+
});
|
|
248
|
+
});
|
package/src/cli/qc.mjs
CHANGED
|
@@ -16,8 +16,12 @@ const USAGE = `qc — architecture gates
|
|
|
16
16
|
qc lease status [path] who holds this worktree's lease, since when, and when it lapses
|
|
17
17
|
qc lease release [path] remove it: --session <id> for your own, --force for another's
|
|
18
18
|
qc pr-check in CI: the pull request names an issue that exists and predates it
|
|
19
|
+
qc prose [--base <ref>] [--pr-body <file>] [--pr-body-event]
|
|
20
|
+
Vale on the lines a diff adds to the docs, and on a PR body; needs the vale binary
|
|
19
21
|
qc commit-msg <file> conventional (commitlint), English, and the trailer when attribution is on
|
|
20
22
|
qc decisions [id] where decisions are cited; --squash closes the gaps
|
|
23
|
+
qc ledger [branch] the workflow ledger: dispatches, stops, verdicts, merges, issue updates
|
|
24
|
+
qc plan-check <plan.md> each task names files, a test step and a commit step, within the tool-call budget
|
|
21
25
|
qc worktree add <name> <branch> [--from <ref>]
|
|
22
26
|
fetch, add ../<name> beside the main checkout, install, print the path
|
|
23
27
|
qc worktree remove <name>
|
|
@@ -77,10 +81,22 @@ async function main() {
|
|
|
77
81
|
const { runPrCheck } = await import("./pr-check.mjs");
|
|
78
82
|
process.exit(await runPrCheck());
|
|
79
83
|
}
|
|
84
|
+
case "prose": {
|
|
85
|
+
const { runProse } = await import("./prose.mjs");
|
|
86
|
+
process.exit(await runProse(config, rest));
|
|
87
|
+
}
|
|
80
88
|
case "commit-msg": {
|
|
81
89
|
const { runCommitMsg } = await import("./commit-msg.mjs");
|
|
82
90
|
process.exit(await runCommitMsg(config, rest[0]));
|
|
83
91
|
}
|
|
92
|
+
case "ledger": {
|
|
93
|
+
const { runLedger } = await import("./ledger.mjs");
|
|
94
|
+
process.exit(runLedger(config, rest));
|
|
95
|
+
}
|
|
96
|
+
case "plan-check": {
|
|
97
|
+
const { runPlanCheck } = await import("./plan-check.mjs");
|
|
98
|
+
process.exit(runPlanCheck(config, rest));
|
|
99
|
+
}
|
|
84
100
|
case "decisions": {
|
|
85
101
|
const { runDecisions } = await import("./decisions.mjs");
|
|
86
102
|
process.exit(await runDecisions(config, rest));
|
|
@@ -7,7 +7,7 @@ import path from "node:path";
|
|
|
7
7
|
import { globMatcher } from "../glob.mjs";
|
|
8
8
|
|
|
9
9
|
/** @returns {string|null} stdout, or null when git is absent or the command fails. */
|
|
10
|
-
function git(root, ...args) {
|
|
10
|
+
export function git(root, ...args) {
|
|
11
11
|
const result = spawnSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
12
12
|
return result.status === 0 ? result.stdout : null;
|
|
13
13
|
}
|