architecture-harness 0.23.1 → 0.25.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 +3 -1
- package/src/cli/budget-guard.mjs +1 -0
- package/src/cli/budget-guard.test.mjs +7 -1
- package/src/cli/budget.mjs +3 -4
- package/src/cli/budget.test.mjs +5 -5
- package/src/cli/ci-template.test.mjs +17 -27
- package/src/cli/cli.test.mjs +22 -2
- package/src/cli/commit-msg.mjs +7 -10
- package/src/cli/commit-msg.test.mjs +10 -7
- package/src/cli/generated-file-guard.mjs +1 -1
- package/src/cli/generated-file-guard.test.mjs +4 -2
- package/src/cli/init.mjs +70 -25
- package/src/cli/lint-changed.mjs +157 -0
- package/src/cli/lint-changed.test.mjs +102 -0
- package/src/cli/plugin-agents.test.mjs +1 -1
- package/src/cli/post-edit-gate.test.mjs +3 -1
- package/src/cli/qc.mjs +23 -3
- package/src/cli/scaffold.mjs +23 -2
- package/src/cli/scaffold.test.mjs +51 -0
- package/src/cli/stop-gate.test.mjs +32 -128
- package/src/cli/typecheck.mjs +46 -0
- package/src/cli/typecheck.test.mjs +43 -0
- package/src/cli/user-config-package.mjs +16 -0
- package/src/cli/user-config-toml.mjs +144 -0
- package/src/cli/user-config.mjs +155 -0
- package/src/cli/user-config.test.mjs +274 -0
- package/src/cli/worktree-gate.mjs +11 -12
- package/src/cli/worktree-gate.test.mjs +28 -29
- package/src/cli/worktree-isolation.mjs +3 -3
- package/src/cli/worktree-isolation.test.mjs +1 -1
- package/src/cli/worktree.mjs +9 -1
- package/src/cli/worktree.test.mjs +16 -1
- package/src/config.mjs +13 -11
- package/src/eslint/preset.mjs +8 -3
- package/src/eslint/preset.test.mjs +15 -8
- package/src/vale-style.test.mjs +5 -5
- package/templates/CLAUDE.md +2 -2
- package/templates/githooks/pre-commit +7 -10
- package/templates/github/workflows/ci.yml +22 -89
- package/templates/github/workflows/pr-policy.yml +36 -0
- package/user-config/claude/settings.shared.json +74 -0
- package/user-config/claude/statusline.js +323 -0
- package/user-config/codex/config.shared.toml +19 -0
- package/src/cli/edit-batch-guard.mjs +0 -77
- package/src/cli/edit-batch-guard.test.mjs +0 -131
|
@@ -38,41 +38,41 @@ function workspace(t, config = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const merge = (extra = {}) => ({ type: "merge", session: "s", pr: 60, repo: "o/r", sha: "abc1234", branch: BRANCH, base: "main", mergedAt: null, issues: [], ...extra });
|
|
41
|
-
const stopCall = (cwd
|
|
42
|
-
const gate = (ws, cwd = ws.main,
|
|
41
|
+
const stopCall = (cwd) => ({ session_id: "s", cwd, hook_event_name: "Stop" });
|
|
42
|
+
const gate = (ws, cwd = ws.main, projectDir = undefined) => decide(stopCall(cwd), { tmp: ws.tmp, projectDir });
|
|
43
43
|
const dropWorktree = (ws) => git(ws.main, "worktree", "remove", "--force", ws.worktree);
|
|
44
44
|
const dropBranch = (ws) => git(ws.main, "branch", "-D", BRANCH);
|
|
45
45
|
const dropRemote = (ws) => git(ws.main, "push", "-q", "origin", "--delete", BRANCH);
|
|
46
46
|
|
|
47
|
-
test("a merged PR whose worktree remains
|
|
47
|
+
test("a merged PR whose worktree remains gets a note that names qc worktree remove", (t) => {
|
|
48
48
|
const ws = workspace(t);
|
|
49
49
|
appendRecord(ws.ledger, merge());
|
|
50
50
|
const output = gate(ws);
|
|
51
|
-
assert.equal(output?.decision,
|
|
52
|
-
assert.match(output.
|
|
53
|
-
assert.match(output.
|
|
51
|
+
assert.equal(output?.decision, undefined);
|
|
52
|
+
assert.match(output.systemMessage, /o\/r#60 \(feat\/62-x\): `npx qc worktree remove kit-62`/);
|
|
53
|
+
assert.match(output.systemMessage, /from the main checkout/i);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
test("a merged PR whose local branch remains
|
|
56
|
+
test("a merged PR whose local branch remains gets a note that names git branch -D", (t) => {
|
|
57
57
|
const ws = workspace(t);
|
|
58
58
|
appendRecord(ws.ledger, merge());
|
|
59
59
|
dropWorktree(ws);
|
|
60
60
|
dropRemote(ws);
|
|
61
61
|
const output = gate(ws);
|
|
62
|
-
assert.equal(output?.decision,
|
|
63
|
-
assert.match(output.
|
|
64
|
-
assert.doesNotMatch(output.
|
|
62
|
+
assert.equal(output?.decision, undefined);
|
|
63
|
+
assert.match(output.systemMessage, /`git branch -D feat\/62-x`/);
|
|
64
|
+
assert.doesNotMatch(output.systemMessage, /qc worktree remove|push origin --delete/);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test("a merged PR whose remote branch remains
|
|
67
|
+
test("a merged PR whose remote branch remains gets a note that names git push origin --delete", (t) => {
|
|
68
68
|
const ws = workspace(t);
|
|
69
69
|
appendRecord(ws.ledger, merge());
|
|
70
70
|
dropWorktree(ws);
|
|
71
71
|
dropBranch(ws);
|
|
72
72
|
const output = gate(ws);
|
|
73
|
-
assert.equal(output?.decision,
|
|
74
|
-
assert.match(output.
|
|
75
|
-
assert.doesNotMatch(output.
|
|
73
|
+
assert.equal(output?.decision, undefined);
|
|
74
|
+
assert.match(output.systemMessage, /`git push origin --delete feat\/62-x`/);
|
|
75
|
+
assert.doesNotMatch(output.systemMessage, /branch -D/);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
test("a merged PR with its worktree, its branch, and its remote branch gone passes", (t) => {
|
|
@@ -106,35 +106,34 @@ test("the main checkout on the merged branch is told to switch to the base first
|
|
|
106
106
|
dropRemote(ws);
|
|
107
107
|
git(ws.main, "switch", "-q", BRANCH);
|
|
108
108
|
const output = gate(ws);
|
|
109
|
-
assert.match(output.
|
|
109
|
+
assert.match(output.systemMessage, /`git switch main`, then `git branch -D feat\/62-x`/);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
test("a repeat stop with the same leftovers
|
|
112
|
+
test("a repeat stop with the same leftovers is silent, and a changed set gets a note again", (t) => {
|
|
113
113
|
const ws = workspace(t);
|
|
114
114
|
appendRecord(ws.ledger, merge());
|
|
115
|
-
assert.
|
|
116
|
-
|
|
117
|
-
assert.equal(repeat?.decision, undefined);
|
|
118
|
-
assert.match(repeat.systemMessage, /same.*kit-62/s);
|
|
115
|
+
assert.match(gate(ws)?.systemMessage, /kit-62/);
|
|
116
|
+
assert.equal(gate(ws), null);
|
|
119
117
|
dropWorktree(ws);
|
|
120
118
|
dropRemote(ws);
|
|
121
|
-
assert.
|
|
119
|
+
assert.match(gate(ws)?.systemMessage, /branch -D/, "a changed set gets a note again");
|
|
122
120
|
dropBranch(ws);
|
|
123
|
-
assert.equal(gate(ws
|
|
124
|
-
assert.deepEqual(readdirSync(path.join(ws.tmp, "qc-worktree-gate")), [], "a clean stop forgets the last
|
|
121
|
+
assert.equal(gate(ws), null);
|
|
122
|
+
assert.deepEqual(readdirSync(path.join(ws.tmp, "qc-worktree-gate")), [], "a clean stop forgets the last note");
|
|
125
123
|
});
|
|
126
124
|
|
|
127
125
|
test("a stop whose cwd is a removed worktree judges its main checkout, and one outside every checkout reads the project dir", (t) => {
|
|
128
126
|
const ws = workspace(t);
|
|
129
127
|
appendRecord(ws.ledger, merge());
|
|
130
128
|
const gone = path.join(ws.main, ".worktree", "kit-61");
|
|
131
|
-
assert.
|
|
129
|
+
assert.match(gate(ws, gone)?.systemMessage, /kit-62/);
|
|
130
|
+
rmSync(path.join(ws.tmp, "qc-worktree-gate"), { recursive: true, force: true });
|
|
132
131
|
const outside = path.join(ws.top, "tmp");
|
|
133
132
|
assert.equal(gate(ws, outside), null);
|
|
134
|
-
assert.
|
|
133
|
+
assert.match(gate(ws, outside, ws.main)?.systemMessage, /kit-62/);
|
|
135
134
|
});
|
|
136
135
|
|
|
137
|
-
test("the hook process is silent in a checkout with no merge, and prints the
|
|
136
|
+
test("the hook process is silent in a checkout with no merge, and prints the note after one", (t) => {
|
|
138
137
|
const ws = workspace(t);
|
|
139
138
|
const run = () => spawnSync(process.execPath, [HOOK], {
|
|
140
139
|
input: JSON.stringify(stopCall(ws.main)),
|
|
@@ -145,8 +144,8 @@ test("the hook process is silent in a checkout with no merge, and prints the blo
|
|
|
145
144
|
assert.equal(quiet.status, 0, quiet.stderr);
|
|
146
145
|
assert.equal(quiet.stdout, "");
|
|
147
146
|
appendRecord(ws.ledger, merge());
|
|
148
|
-
const
|
|
149
|
-
assert.equal(
|
|
150
|
-
assert.
|
|
147
|
+
const noted = run();
|
|
148
|
+
assert.equal(noted.status, 0, noted.stderr);
|
|
149
|
+
assert.match(JSON.parse(noted.stdout).systemMessage, /kit-62/);
|
|
151
150
|
assert.ok(existsSync(ws.worktree));
|
|
152
151
|
});
|
|
@@ -81,7 +81,7 @@ function heldRefusal(held, { branch, now, leaseFile, root, qc }) {
|
|
|
81
81
|
return (
|
|
82
82
|
`Another agent (session ${held.holder}) is already working in this worktree on ` +
|
|
83
83
|
`"${held.branch ?? branch}". Two agents on one branch lose each other's edits. ` +
|
|
84
|
-
`Take your own: \`
|
|
84
|
+
`Take your own: \`npx qc worktree add <slug> <branch>\`. ` +
|
|
85
85
|
`The lease is ${leaseFile}, written ${duration(held.age)} ago; it lapses at ` +
|
|
86
86
|
`${timestamp(held.lapsesAt)}, in ${duration(held.lapsesAt - now)}. See it: \`${qc} lease status ${at}\`. ` +
|
|
87
87
|
`Its holder releases it: \`${qc} lease release ${at} --session <id>\`. ` +
|
|
@@ -106,13 +106,13 @@ export function isolationRefusal(state) {
|
|
|
106
106
|
if (settings.protectedBranches.includes(branch)) {
|
|
107
107
|
return (
|
|
108
108
|
`"${branch}" is a protected branch and an agent does not generate code on it. ` +
|
|
109
|
-
`Create a work order's own branch first: \`
|
|
109
|
+
`Create a work order's own branch first: \`npx qc worktree add <slug> <branch>\`.`
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
if (settings.require === WORKTREE && kind === "primary") {
|
|
113
113
|
return (
|
|
114
114
|
`This is the primary worktree, shared by every session that opens the repository. ` +
|
|
115
|
-
`Give this work order its own: \`
|
|
115
|
+
`Give this work order its own: \`npx qc worktree add <slug> ${branch}\`.`
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
const held = leaseHeldByAnother(lease, sessionId, now, settings.leaseHours);
|
|
@@ -54,7 +54,7 @@ test("an ignored path is still refused on a detached HEAD", () => {
|
|
|
54
54
|
test("generating code on a protected branch is refused and names the branch", () => {
|
|
55
55
|
const reason = isolationRefusal(base({ branch: "main" }));
|
|
56
56
|
assert.match(reason, /"main" is a protected branch/);
|
|
57
|
-
assert.match(reason, /
|
|
57
|
+
assert.match(reason, /qc worktree add/);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
test("the protected branch list is configurable", () => {
|
package/src/cli/worktree.mjs
CHANGED
|
@@ -16,6 +16,14 @@ export const USAGE = `qc worktree — a linked worktree under .worktree/ in the
|
|
|
16
16
|
The default is worktree.base in qc.config.json. The install is worktree.install.
|
|
17
17
|
The folder is worktree.dir. remove also finds a worktree at ../<name>, beside the main checkout.`;
|
|
18
18
|
|
|
19
|
+
/** The install of the package manager whose lockfile `root` holds, or null for a folder with no package.json. */
|
|
20
|
+
export function installCommand(root) {
|
|
21
|
+
if (existsSync(path.join(root, "pnpm-lock.yaml"))) return "pnpm install --frozen-lockfile";
|
|
22
|
+
if (existsSync(path.join(root, "yarn.lock"))) return "yarn install --frozen-lockfile";
|
|
23
|
+
if (existsSync(path.join(root, "package-lock.json"))) return "npm ci";
|
|
24
|
+
return existsSync(path.join(root, "package.json")) ? "npm install" : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
function git(cwd, ...args) {
|
|
20
28
|
const result = spawnSync("git", args, { cwd, encoding: "utf8" });
|
|
21
29
|
return { ok: result.status === 0, out: (result.stdout ?? "").trim(), err: (result.stderr ?? "").trim() };
|
|
@@ -85,7 +93,7 @@ async function add(config, main, target, branch, from) {
|
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
// Every add runs the install, so a second add finishes what a failed install left.
|
|
88
|
-
const install = config.worktree?.install;
|
|
96
|
+
const install = config.worktree?.install ?? installCommand(target);
|
|
89
97
|
if (install) {
|
|
90
98
|
const ran = spawnSync(install, { cwd: target, shell: true, stdio: "inherit" });
|
|
91
99
|
if (ran.status !== 0) {
|
|
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { load } from "../config.mjs";
|
|
9
|
-
import { runWorktree } from "./worktree.mjs";
|
|
9
|
+
import { installCommand, runWorktree } from "./worktree.mjs";
|
|
10
10
|
|
|
11
11
|
const QC = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
12
12
|
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
@@ -55,6 +55,21 @@ function added(main, name, branch) {
|
|
|
55
55
|
return lastLine(result.stdout);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
test("with no install configured, the lockfile picks the install, and a folder with no package.json installs nothing", () => {
|
|
59
|
+
const dir = realpathSync.native(mkdtempSync(path.join(tmpdir(), "qc-install-")));
|
|
60
|
+
try {
|
|
61
|
+
assert.equal(installCommand(dir), null);
|
|
62
|
+
writeFileSync(path.join(dir, "package.json"), "{}");
|
|
63
|
+
assert.equal(installCommand(dir), "npm install");
|
|
64
|
+
for (const [lockfile, command] of [["package-lock.json", "npm ci"], ["yarn.lock", "yarn install --frozen-lockfile"], ["pnpm-lock.yaml", "pnpm install --frozen-lockfile"]]) {
|
|
65
|
+
writeFileSync(path.join(dir, lockfile), "");
|
|
66
|
+
assert.equal(installCommand(dir), command);
|
|
67
|
+
}
|
|
68
|
+
} finally {
|
|
69
|
+
rmSync(dir, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
58
73
|
test("add makes a worktree under .worktree/ in the main checkout and installs it; remove deletes it and its merged branch", () => {
|
|
59
74
|
const { top, main } = fixture();
|
|
60
75
|
const where = added(main, "wt-a", "feat/a");
|
package/src/config.mjs
CHANGED
|
@@ -247,8 +247,9 @@ export const defaults = {
|
|
|
247
247
|
// restricted. `require`: off | branch (refuse the trunk) | worktree (also refuse the primary).
|
|
248
248
|
swarm: {
|
|
249
249
|
isolation: { require: "off", protectedBranches: ["main", "master"], leaseHours: 8, allow: [] },
|
|
250
|
-
// Tool calls per subagent
|
|
251
|
-
|
|
250
|
+
// Tool calls per subagent: off by default. A whole number turns the budget on: the hook reminds at seventy
|
|
251
|
+
// percent and denies all but the hand-off at the budget.
|
|
252
|
+
toolCallBudget: null,
|
|
252
253
|
// Off until a repository writes the section. `{}` turns it on, and `dispatchDefaults` fills each key it omits.
|
|
253
254
|
dispatch: null,
|
|
254
255
|
// Read only while `dispatch` is on. `reviewDefaults` fills each key it omits.
|
|
@@ -257,13 +258,13 @@ export const defaults = {
|
|
|
257
258
|
direct: null,
|
|
258
259
|
},
|
|
259
260
|
|
|
260
|
-
// Files a generator writes. The generated-file hook refuses a hand edit of one and names `command
|
|
261
|
-
generated: { globs: ["**/*.generated.*"], command:
|
|
261
|
+
// Files a generator writes. The generated-file hook refuses a hand edit of one and names `command`, when set.
|
|
262
|
+
generated: { globs: ["**/*.generated.*"], command: null },
|
|
262
263
|
|
|
263
|
-
// `qc worktree`. `install` runs in each new worktree. `base` is the default `--from`: the ref a
|
|
264
|
+
// `qc worktree`. `install` runs in each new worktree; null picks it from the lockfile. `base` is the default `--from`: the ref a
|
|
264
265
|
// branch starts at, and the ref `remove` checks a merge against.
|
|
265
266
|
// `dir` holds each worktree, inside the main checkout. `enforce: false` turns off the QC-015 hooks.
|
|
266
|
-
worktree: { install:
|
|
267
|
+
worktree: { install: null, base: "origin/main", dir: ".worktree", enforce: true },
|
|
267
268
|
|
|
268
269
|
// Names that must be registered scoped, never singleton.
|
|
269
270
|
scopedSuffixes: ["Repository", "Saga", "UnitOfWork", "UnitOfWorkFactory"],
|
|
@@ -432,20 +433,21 @@ export const defaults = {
|
|
|
432
433
|
rules: {
|
|
433
434
|
"no-comment-paragraph": true,
|
|
434
435
|
"name-the-pattern": false,
|
|
435
|
-
|
|
436
|
+
// Opt-in: a style or a domain policy of the reference stack, not a defect in any repository.
|
|
437
|
+
"no-promise-then": false,
|
|
436
438
|
"no-number-in-comment": true,
|
|
437
439
|
"no-cross-feature-internals": true,
|
|
438
|
-
"no-offset-pagination":
|
|
440
|
+
"no-offset-pagination": false,
|
|
439
441
|
"no-orchestration-in-trigger": true,
|
|
440
|
-
"no-status-literal":
|
|
442
|
+
"no-status-literal": false,
|
|
441
443
|
"scoped-repository": true,
|
|
442
444
|
"storage-only-in-resource": true,
|
|
443
445
|
"external-service-only-in-adapter": true,
|
|
444
446
|
"tenant-scoped-table": true,
|
|
445
|
-
"signal-last-param":
|
|
447
|
+
"signal-last-param": false,
|
|
446
448
|
"no-raw-fetch": true,
|
|
447
449
|
"no-sql-raw": true,
|
|
448
|
-
"ime-safe-key":
|
|
450
|
+
"ime-safe-key": false,
|
|
449
451
|
// A policy rule: a repository turns it on once its controls carry the pending prop.
|
|
450
452
|
"mutation-control-pending": false,
|
|
451
453
|
"registry-literal": true,
|
package/src/eslint/preset.mjs
CHANGED
|
@@ -77,13 +77,17 @@ function ruleOptions(config) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
// Rules on the style of a comment: a finding is advice, so it prints and never fails a change.
|
|
81
|
+
const ADVICE = new Set(["no-comment-paragraph", "no-number-in-comment", "no-supersession-trail"]);
|
|
82
|
+
|
|
80
83
|
function entries(config, names) {
|
|
81
84
|
const options = ruleOptions(config);
|
|
82
85
|
const out = {};
|
|
83
86
|
for (const name of names) {
|
|
84
87
|
if (!enabled(config.rules, name)) continue;
|
|
85
88
|
const given = options[name];
|
|
86
|
-
|
|
89
|
+
const level = ADVICE.has(name) ? "warn" : "error";
|
|
90
|
+
out[`qc/${name}`] = given && Object.keys(given).length > 0 ? [level, given] : level;
|
|
87
91
|
}
|
|
88
92
|
return out;
|
|
89
93
|
}
|
|
@@ -128,8 +132,9 @@ export function preset(options = {}) {
|
|
|
128
132
|
const max = (id) => gates[id]?.value;
|
|
129
133
|
const { tseslint, boundaries, sonarjs } = options.plugins ?? {};
|
|
130
134
|
|
|
131
|
-
//
|
|
132
|
-
|
|
135
|
+
// A disable comment is allowed, and one that disables nothing is an error. `qc lint` judges only the
|
|
136
|
+
// changed lines, so a new disable comment is part of the change a reviewer reads.
|
|
137
|
+
const blocks = [{ ignores: ignoresOf(config) }, { linterOptions: { reportUnusedDisableDirectives: "error" } }];
|
|
133
138
|
|
|
134
139
|
const base = {
|
|
135
140
|
files: ["**/*.{ts,tsx,mjs}"],
|
|
@@ -153,7 +153,7 @@ test("a session lifetime in code fails outside its reader, through the whole pre
|
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
test("the ime config reaches qc/ime-safe-key", () => {
|
|
156
|
-
const setting = emitted(preset({ config: config({ ime: { guards: ["isImeComposing"] } }) })).get("qc/ime-safe-key");
|
|
156
|
+
const setting = emitted(preset({ config: config({ ime: { guards: ["isImeComposing"] }, rules: { "ime-safe-key": true } }) })).get("qc/ime-safe-key");
|
|
157
157
|
assert.deepEqual(setting[1], { components: [], guards: ["isImeComposing"] });
|
|
158
158
|
});
|
|
159
159
|
|
|
@@ -175,18 +175,25 @@ test("the mutationControl config reaches qc/mutation-control-pending", () => {
|
|
|
175
175
|
assert.deepEqual(setting[1], { button: "Action", prop: "busy", handlers: ["onClick", "onSelect", "onConfirm"] });
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
-
test("the preset
|
|
178
|
+
test("the preset reports an unused disable comment in every file", () => {
|
|
179
179
|
const block = preset({ config: config() }).find((b) => b.linterOptions);
|
|
180
180
|
assert.ok(block, "no linterOptions block emitted");
|
|
181
181
|
assert.equal(block.files, undefined, "linterOptions must reach every file");
|
|
182
|
-
assert.deepEqual(block.linterOptions, {
|
|
182
|
+
assert.deepEqual(block.linterOptions, { reportUnusedDisableDirectives: "error" });
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
test("
|
|
186
|
-
const
|
|
187
|
-
assert.equal(byRule(
|
|
188
|
-
const
|
|
189
|
-
assert.ok(
|
|
185
|
+
test("a disable comment silences its rule, and one that silences nothing is an error", () => {
|
|
186
|
+
const used = lint("// eslint-disable-next-line qc/no-sql-raw\nawait db.execute(sql.raw(text));\n", RESOURCE);
|
|
187
|
+
assert.equal(byRule(used, "qc/no-sql-raw").length, 0);
|
|
188
|
+
const unused = lint("// eslint-disable-next-line qc/no-sql-raw\nconst a = 1;\n", RESOURCE);
|
|
189
|
+
assert.ok(unused.some((m) => m.ruleId === null && m.severity === 2 && /Unused eslint-disable/.test(m.message)), JSON.stringify(unused));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("a comment-style rule warns, and a rule of the reference stack is off until a repository turns it on", () => {
|
|
193
|
+
const rules = emitted(preset({ config: config() }));
|
|
194
|
+
for (const name of ["no-comment-paragraph", "no-number-in-comment", "no-supersession-trail"]) assert.equal([rules.get(`qc/${name}`)].flat()[0], "warn", name);
|
|
195
|
+
for (const name of ["no-offset-pagination", "no-status-literal", "no-promise-then", "signal-last-param", "ime-safe-key"]) assert.equal(rules.get(`qc/${name}`), undefined, name);
|
|
196
|
+
assert.equal([emitted(preset({ config: config({ rules: { "no-offset-pagination": true } }) })).get("qc/no-offset-pagination")].flat()[0], "error");
|
|
190
197
|
});
|
|
191
198
|
|
|
192
199
|
test("sql.raw fails, and sqlRaw.allow lets one reviewed file through", () => {
|
package/src/vale-style.test.mjs
CHANGED
|
@@ -101,7 +101,7 @@ test("init copies the Vale config and every rule where qc prose looks for them",
|
|
|
101
101
|
const log = console.log;
|
|
102
102
|
console.log = () => {};
|
|
103
103
|
try {
|
|
104
|
-
await runInit(load(dir));
|
|
104
|
+
await runInit(load(dir), ["--full"]);
|
|
105
105
|
assert.ok(existsSync(path.join(dir, ".vale/.vale.ini")));
|
|
106
106
|
for (const rule of Object.keys(rules)) assert.ok(existsSync(path.join(dir, ".vale/styles/Qc", `${rule}.yml`)), rule);
|
|
107
107
|
} finally {
|
|
@@ -112,7 +112,7 @@ test("init copies the Vale config and every rule where qc prose looks for them",
|
|
|
112
112
|
|
|
113
113
|
const HASH = "fbc2eb47d0b8c50220ed1a2c5c611fbe0904ed567d638143d482016a18fd2db0";
|
|
114
114
|
const TARBALL = "vale_3.9.1_Linux_64-bit.tar.gz";
|
|
115
|
-
const templateWorkflow = readFileSync(path.join(vale, "../github/workflows/
|
|
115
|
+
const templateWorkflow = readFileSync(path.join(vale, "../github/workflows/pr-policy.yml"), "utf8");
|
|
116
116
|
const kitWorkflow = readFileSync(path.resolve(vale, "../../../../.github/workflows/ci.yml"), "utf8");
|
|
117
117
|
|
|
118
118
|
/** @returns the `run` script of the step that installs Vale in `text`. */
|
|
@@ -121,7 +121,7 @@ function installStep(text) {
|
|
|
121
121
|
return steps.find((step) => /releases\/download/.test(step.run ?? ""))?.run ?? "";
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
test("the template
|
|
124
|
+
test("the PR policy template runs qc prose on a pull request, with a pinned Vale release", () => {
|
|
125
125
|
assert.match(templateWorkflow, /releases\/download\/v\d+\.\d+\.\d+\/vale_/);
|
|
126
126
|
assert.match(templateWorkflow, /npx qc prose --base "origin\/\$GITHUB_BASE_REF" --pr-body-event/);
|
|
127
127
|
});
|
|
@@ -151,8 +151,8 @@ test("the kit's own CI installs Vale on the ubuntu leg, so the real-Vale test ru
|
|
|
151
151
|
assert.ok(order < steps.findIndex((step) => step.run === "pnpm test"), "Vale is installed before the tests run");
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
-
test("the
|
|
155
|
-
const readme = readFileSync(path.resolve(vale, "../../../../
|
|
154
|
+
test("the reference and the enforcement page state that an alert lands on the line where a sentence starts", () => {
|
|
155
|
+
const readme = readFileSync(path.resolve(vale, "../../../../docs/reference.md"), "utf8");
|
|
156
156
|
const enforcement = readFileSync(path.join(vale, "../docs/enforcement.md"), "utf8");
|
|
157
157
|
for (const text of [readme, enforcement]) assert.match(text.replace(/\s+/g, " "), /alert lands on the line where the sentence or phrase starts, so an edit to a later line of it is not judged/);
|
|
158
158
|
});
|
package/templates/CLAUDE.md
CHANGED
|
@@ -20,12 +20,12 @@ undefined id, a missing doc path, or a reference to another repository fails the
|
|
|
20
20
|
|
|
21
21
|
## Commands
|
|
22
22
|
|
|
23
|
-
`qc init` added
|
|
23
|
+
`qc init` added `spec:check`. Add the rest as the repository grows them, and list
|
|
24
24
|
every one here — this table is what an agent reads instead of guessing.
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
pnpm spec:check # every structural gate (qc check)
|
|
28
|
-
|
|
28
|
+
npx qc feature <name> # scaffold a feature. Full domain name, never a code
|
|
29
29
|
npx qc check <file>... # the fast path a post-edit hook or a commit takes
|
|
30
30
|
npx qc config # print the configuration in force
|
|
31
31
|
```
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# A human is bound by exactly what binds an agent.
|
|
3
|
-
# Fast tier only: staged
|
|
4
|
-
# repository-wide gates
|
|
5
|
-
# instead of once per commit — see the pre-push hook.
|
|
3
|
+
# Fast tier only: the lint of the staged lines, the types, and each touched feature's own structure.
|
|
4
|
+
# The repository-wide gates run once per push instead of once per commit: see the pre-push hook.
|
|
6
5
|
set -euo pipefail
|
|
7
|
-
# Runs before the
|
|
8
|
-
# what kind of file it touches, so a commit of .tf/.yml/.md files is covered too.
|
|
6
|
+
# Runs before the file filter below, so a commit of .tf, .yml, or .md files is checked too.
|
|
9
7
|
npx qc work-order-check || exit 1
|
|
10
8
|
# The staged list is NUL-separated in a file, never in an argument: a large merge commit would
|
|
11
9
|
# pass the command-line limit of npx.cmd on Windows (8191 characters).
|
|
12
10
|
STAGED=$(mktemp)
|
|
13
11
|
trap 'rm -f "$STAGED"' EXIT
|
|
14
|
-
git diff --cached --name-only -z --diff-filter=ACM | grep -zE '\.(ts|tsx|mjs)$' > "$STAGED" || true
|
|
12
|
+
git diff --cached --name-only -z --diff-filter=ACM | grep -zE '\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$' > "$STAGED" || true
|
|
15
13
|
[ -s "$STAGED" ] || exit 0
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
npx tsc -b --pretty false
|
|
14
|
+
# Only the staged lines: a problem on a line this commit leaves alone never blocks it.
|
|
15
|
+
npx qc lint --staged
|
|
16
|
+
npx qc typecheck
|
|
20
17
|
npx qc check --files-from - < "$STAGED"
|
|
@@ -1,107 +1,40 @@
|
|
|
1
1
|
name: ci
|
|
2
2
|
on:
|
|
3
3
|
push:
|
|
4
|
-
# `edited` re-runs the prose check when a pull request body changes.
|
|
5
4
|
pull_request:
|
|
6
|
-
types: [opened, synchronize, reopened, edited]
|
|
7
5
|
|
|
8
6
|
jobs:
|
|
9
7
|
gates:
|
|
10
8
|
runs-on: ubuntu-latest
|
|
11
9
|
steps:
|
|
12
|
-
# Full history:
|
|
10
|
+
# Full history: `qc lint` judges the lines since the merge base.
|
|
13
11
|
- uses: actions/checkout@v5
|
|
14
12
|
with: { fetch-depth: 0 }
|
|
15
13
|
- uses: actions/setup-node@v5
|
|
16
|
-
with: { node-version
|
|
17
|
-
- run: corepack enable
|
|
18
|
-
- run: pnpm install --frozen-lockfile
|
|
14
|
+
with: { node-version: lts/* }
|
|
19
15
|
|
|
20
|
-
#
|
|
21
|
-
- run: npx qc check
|
|
22
|
-
|
|
23
|
-
# A pull request names the issue it closes, and the issue predates it.
|
|
24
|
-
- if: github.event_name == 'pull_request'
|
|
25
|
-
run: npx qc pr-check
|
|
26
|
-
env: { GH_TOKEN: "${{ github.token }}" }
|
|
27
|
-
|
|
28
|
-
# The lines a pull request adds, and its body, meet the prose style. Vale is a pinned release,
|
|
29
|
-
# and the download is checked against its published hash before it is unpacked.
|
|
30
|
-
- if: github.event_name == 'pull_request'
|
|
31
|
-
run: |
|
|
32
|
-
set -euo pipefail
|
|
33
|
-
cd "$RUNNER_TEMP"
|
|
34
|
-
curl -sSfL -O https://github.com/errata-ai/vale/releases/download/v3.9.1/vale_3.9.1_Linux_64-bit.tar.gz
|
|
35
|
-
echo "fbc2eb47d0b8c50220ed1a2c5c611fbe0904ed567d638143d482016a18fd2db0 vale_3.9.1_Linux_64-bit.tar.gz" | sha256sum -c -
|
|
36
|
-
tar -xzf vale_3.9.1_Linux_64-bit.tar.gz vale
|
|
37
|
-
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
|
|
38
|
-
- if: github.event_name == 'pull_request'
|
|
39
|
-
run: npx qc prose --base "origin/$GITHUB_BASE_REF" --pr-body-event
|
|
40
|
-
|
|
41
|
-
# Typecheck and lint as the stop gate runs them: a root script wins, else the installed tool.
|
|
42
|
-
# CI is the one check an agent cannot skip, so each step is on, and without its tool it says it skipped.
|
|
16
|
+
# Install with the package manager of the lockfile, and keep its name for the test step.
|
|
43
17
|
- run: |
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if node -e "process.exit(require('./package.json').scripts?.lint ? 0 : 1)"; then pnpm run lint
|
|
50
|
-
elif [ -x node_modules/.bin/eslint ]; then pnpm exec eslint . --max-warnings 0
|
|
51
|
-
else echo "::notice::lint skipped: no lint script and no eslint"
|
|
18
|
+
set -euo pipefail
|
|
19
|
+
if [ -f pnpm-lock.yaml ]; then corepack enable; pnpm install --frozen-lockfile; echo "PM=pnpm" >> "$GITHUB_ENV"
|
|
20
|
+
elif [ -f yarn.lock ]; then corepack enable; yarn install --immutable; echo "PM=yarn" >> "$GITHUB_ENV"
|
|
21
|
+
elif [ -f package-lock.json ]; then npm ci; echo "PM=npm" >> "$GITHUB_ENV"
|
|
22
|
+
else npm install; echo "PM=npm" >> "$GITHUB_ENV"
|
|
52
23
|
fi
|
|
53
|
-
- run: pnpm run --if-present dup:check
|
|
54
24
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- id: script
|
|
63
|
-
run: node -e "console.log('present=' + Boolean(require('./package.json').scripts?.['test:unit']))" >> "$GITHUB_OUTPUT"
|
|
64
|
-
- if: steps.script.outputs.present == 'true'
|
|
65
|
-
uses: actions/setup-node@v5
|
|
66
|
-
with: { node-version-file: package.json }
|
|
67
|
-
- if: steps.script.outputs.present == 'true'
|
|
68
|
-
run: corepack enable && pnpm install --frozen-lockfile
|
|
69
|
-
- if: steps.script.outputs.present == 'true'
|
|
70
|
-
run: pnpm test:unit --shard=${{ matrix.shard }}/${{ strategy.job-total }}
|
|
25
|
+
# The same three checks the hooks run. Each says when it has nothing to check.
|
|
26
|
+
- run: npx qc check
|
|
27
|
+
- run: npx qc typecheck
|
|
28
|
+
# Only the lines this change adds: a problem older than the change never fails it.
|
|
29
|
+
- run: npx qc lint --base "$BASE"
|
|
30
|
+
env:
|
|
31
|
+
BASE: ${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || 'HEAD^' }}
|
|
71
32
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
- uses: actions/checkout@v5
|
|
78
|
-
- id: script
|
|
79
|
-
run: node -e "console.log('present=' + Boolean(require('./package.json').scripts?.['test:integration']))" >> "$GITHUB_OUTPUT"
|
|
80
|
-
- if: steps.script.outputs.present == 'true'
|
|
81
|
-
uses: actions/setup-node@v5
|
|
82
|
-
with: { node-version-file: package.json }
|
|
83
|
-
- if: steps.script.outputs.present == 'true'
|
|
84
|
-
run: corepack enable && pnpm install --frozen-lockfile
|
|
85
|
-
- if: steps.script.outputs.present == 'true'
|
|
86
|
-
run: pnpm test:integration --shard=${{ matrix.shard }}/${{ strategy.job-total }}
|
|
33
|
+
# The repository's own tests, when it has a test script.
|
|
34
|
+
- run: |
|
|
35
|
+
if node -e "process.exit(require('./package.json').scripts?.test ? 0 : 1)"; then "$PM" run test
|
|
36
|
+
else echo "::notice::tests skipped: no test script"
|
|
37
|
+
fi
|
|
87
38
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
e2e:
|
|
91
|
-
runs-on: ubuntu-latest
|
|
92
|
-
steps:
|
|
93
|
-
- uses: actions/checkout@v5
|
|
94
|
-
with: { fetch-depth: 0 }
|
|
95
|
-
- id: script
|
|
96
|
-
run: node -e "const s = require('./package.json').scripts ?? {}; console.log('present=' + Boolean(s.e2e && s['e2e:affected']))" >> "$GITHUB_OUTPUT"
|
|
97
|
-
- if: steps.script.outputs.present == 'true'
|
|
98
|
-
uses: actions/setup-node@v5
|
|
99
|
-
with: { node-version-file: package.json }
|
|
100
|
-
- if: steps.script.outputs.present == 'true'
|
|
101
|
-
run: corepack enable && pnpm install --frozen-lockfile
|
|
102
|
-
- if: steps.script.outputs.present == 'true'
|
|
103
|
-
run: pnpm exec playwright install --with-deps
|
|
104
|
-
- if: steps.script.outputs.present == 'true' && github.event_name == 'pull_request'
|
|
105
|
-
run: pnpm e2e:affected "origin/$GITHUB_BASE_REF"
|
|
106
|
-
- if: steps.script.outputs.present == 'true' && github.event_name != 'pull_request'
|
|
107
|
-
run: pnpm e2e
|
|
39
|
+
# More checks are opt-in, one step each: `npx qc pr-check` (a pull request names an earlier
|
|
40
|
+
# issue) and `npx qc prose` (Vale on the docs a change adds). docs/enforcement.md lists them.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: pr-policy
|
|
2
|
+
on:
|
|
3
|
+
# `edited` runs the checks again when a pull request body changes.
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize, reopened, edited]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
policy:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v5
|
|
12
|
+
with: { fetch-depth: 0 }
|
|
13
|
+
- uses: actions/setup-node@v5
|
|
14
|
+
with: { node-version: lts/* }
|
|
15
|
+
- run: |
|
|
16
|
+
set -euo pipefail
|
|
17
|
+
if [ -f pnpm-lock.yaml ]; then corepack enable; pnpm install --frozen-lockfile
|
|
18
|
+
elif [ -f yarn.lock ]; then corepack enable; yarn install --immutable
|
|
19
|
+
elif [ -f package-lock.json ]; then npm ci
|
|
20
|
+
else npm install
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# A pull request names the issue it closes, and the issue predates it.
|
|
24
|
+
- run: npx qc pr-check
|
|
25
|
+
env: { GH_TOKEN: "${{ github.token }}" }
|
|
26
|
+
|
|
27
|
+
# The lines a pull request adds, and its body, meet the prose style. Vale is a pinned release,
|
|
28
|
+
# and the download is checked against its published hash before it is unpacked.
|
|
29
|
+
- run: |
|
|
30
|
+
set -euo pipefail
|
|
31
|
+
cd "$RUNNER_TEMP"
|
|
32
|
+
curl -sSfL -O https://github.com/errata-ai/vale/releases/download/v3.9.1/vale_3.9.1_Linux_64-bit.tar.gz
|
|
33
|
+
echo "fbc2eb47d0b8c50220ed1a2c5c611fbe0904ed567d638143d482016a18fd2db0 vale_3.9.1_Linux_64-bit.tar.gz" | sha256sum -c -
|
|
34
|
+
tar -xzf vale_3.9.1_Linux_64-bit.tar.gz vale
|
|
35
|
+
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
|
|
36
|
+
- run: npx qc prose --base "origin/$GITHUB_BASE_REF" --pr-body-event
|