architecture-harness 0.15.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 +14 -6
- package/src/cli/dispatch-guard.test.mjs +37 -0
- package/src/cli/dispatch-reminder.mjs +26 -12
- package/src/cli/dispatch-reminder.test.mjs +43 -0
- package/src/cli/dispatch-slot.mjs +151 -36
- package/src/cli/dispatch-slot.test.mjs +160 -11
- package/src/cli/dispatch.mjs +25 -7
- package/src/cli/dispatch.test.mjs +55 -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 +87 -4
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "architecture-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"eslint-plugin-boundaries": ">=5",
|
|
58
58
|
"eslint-plugin-sonarjs": ">=3",
|
|
59
59
|
"@commitlint/lint": ">=19",
|
|
60
|
-
"@commitlint/config-conventional": ">=19"
|
|
60
|
+
"@commitlint/config-conventional": ">=19",
|
|
61
|
+
"yaml": ">=2"
|
|
61
62
|
},
|
|
62
63
|
"peerDependenciesMeta": {
|
|
63
64
|
"@typescript-eslint/eslint-plugin": {
|
|
@@ -77,6 +78,9 @@
|
|
|
77
78
|
},
|
|
78
79
|
"@commitlint/config-conventional": {
|
|
79
80
|
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"yaml": {
|
|
83
|
+
"optional": true
|
|
80
84
|
}
|
|
81
85
|
},
|
|
82
86
|
"devDependencies": {
|
|
@@ -87,6 +91,7 @@
|
|
|
87
91
|
"eslint": "^9",
|
|
88
92
|
"eslint-plugin-boundaries": "^5",
|
|
89
93
|
"eslint-plugin-sonarjs": "^3",
|
|
90
|
-
"typescript": "^5"
|
|
94
|
+
"typescript": "^5",
|
|
95
|
+
"yaml": "^2.9.1"
|
|
91
96
|
}
|
|
92
97
|
}
|
|
@@ -12,6 +12,7 @@ import { commandWords, gitCall, segmentsOf } from "./shell-command.mjs";
|
|
|
12
12
|
|
|
13
13
|
const HOOK_SCRIPTS = [
|
|
14
14
|
"work-order-guard.mjs", "budget-guard.mjs", "bash-edit-guard.mjs", "worktree-isolation.mjs", "pre-edit-guard.sh",
|
|
15
|
+
"report-stop.mjs", "plan-stop.mjs", "merge-guard.mjs", "issue-gate.mjs", "controller-guard.mjs",
|
|
15
16
|
];
|
|
16
17
|
const NO_VERIFY = "--no-verify";
|
|
17
18
|
// The shortest prefix git could still expand to `--no-verify`.
|
|
@@ -26,11 +27,17 @@ const VALUE_OPTIONS = new Set([
|
|
|
26
27
|
const COMMIT_VALUE_FLAGS = new Set(["m", "F", "C", "c", "t"]);
|
|
27
28
|
|
|
28
29
|
/** The parser for each guarded tool. */
|
|
29
|
-
const PARSERS = { Bash: segmentsOf, PowerShell: powershellSegments };
|
|
30
|
-
/**
|
|
31
|
-
const
|
|
30
|
+
export const PARSERS = { Bash: segmentsOf, PowerShell: powershellSegments };
|
|
31
|
+
/** A POSIX shell reads a command line from `-c`, alone or in a cluster of short flags: `-lc`, `-ic`, `-lic`, `-cl`. */
|
|
32
|
+
const POSIX_COMMAND_FLAG = /^-[A-Za-z]*c[A-Za-z]*$/;
|
|
33
|
+
const POWERSHELL_COMMAND_FLAG = /^-(c|command)$/i;
|
|
34
|
+
/** The shells whose `-c` or `-Command` argument is a command line of its own, the flag that names it, and the parser that reads it. */
|
|
35
|
+
const NESTED = Object.fromEntries([
|
|
36
|
+
...["bash", "sh", "zsh", "dash", "ksh"].map((name) => [name, { flag: POSIX_COMMAND_FLAG, parse: segmentsOf }]),
|
|
37
|
+
...["pwsh", "powershell"].map((name) => [name, { flag: POWERSHELL_COMMAND_FLAG, parse: powershellSegments }]),
|
|
38
|
+
]);
|
|
32
39
|
|
|
33
|
-
const programName = (word) => path.basename(word ?? "").toLowerCase().replace(/\.exe$/, "");
|
|
40
|
+
export const programName = (word) => path.basename(word ?? "").toLowerCase().replace(/\.exe$/, "");
|
|
34
41
|
const isNoVerify = (arg) => arg.length >= NO_VERIFY_MIN && NO_VERIFY.startsWith(arg);
|
|
35
42
|
|
|
36
43
|
/** True when a commit or push names `--no-verify`, or a commit names `-n` alone or in a flag cluster. */
|
|
@@ -75,12 +82,20 @@ function runsTests(segment) {
|
|
|
75
82
|
return [program, ...args].some((word) => programName(word) === "vitest");
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
85
|
+
/**
|
|
86
|
+
* @returns the command line a shell runs from `-c` or `-Command`, or that `eval` runs from its words joined with spaces,
|
|
87
|
+
* with its parser, or null.
|
|
88
|
+
*/
|
|
89
|
+
export function nestedCommand(segment) {
|
|
80
90
|
const [program, ...args] = commandWords(segment);
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
const name = programName(program);
|
|
92
|
+
if (name === "eval") return args.length > 0 ? { command: args.join(" "), parse: segmentsOf } : null;
|
|
93
|
+
const shell = Object.hasOwn(NESTED, name) ? NESTED[name] : null;
|
|
94
|
+
const at = shell ? args.findIndex((arg) => shell.flag.test(arg)) : -1;
|
|
95
|
+
if (at === -1) return null;
|
|
96
|
+
// A POSIX shell takes the first word after its flags as the command line, so `-c -- 'cmd'` and `-c +x 'cmd'` still find it.
|
|
97
|
+
const command = shell.parse === segmentsOf ? args.slice(at + 1).find((arg) => !/^[-+]/.test(arg)) : args[at + 1];
|
|
98
|
+
return command === undefined ? null : { command, parse: shell.parse };
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
const REASONS = {
|
|
@@ -90,7 +105,7 @@ const REASONS = {
|
|
|
90
105
|
hooksPath:
|
|
91
106
|
"`-c core.hooksPath=` points git away from the installed hooks, so the gates never run. Remove it.",
|
|
92
107
|
script:
|
|
93
|
-
"a hand run of a hook script writes a lease under a made-up session id, and that lease blocks later " +
|
|
108
|
+
"a hand run of a hook script writes a lease or a ledger record under a made-up session id, and that lease blocks later " +
|
|
94
109
|
"edits in the worktree for hours. Test a hook only through its own suite (`node --test`), in temporary folders.",
|
|
95
110
|
};
|
|
96
111
|
|
|
@@ -42,6 +42,31 @@ test("a commit or push that skips the git hooks is denied", (t) => {
|
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
test("git commit --no-verify inside bash -lc, env, sudo, and an if block is refused", (t) => {
|
|
46
|
+
const ws = workspace(t);
|
|
47
|
+
for (const command of [
|
|
48
|
+
`bash -lc 'git commit --no-verify -m x'`,
|
|
49
|
+
`bash -ic "git commit -n -m x"`,
|
|
50
|
+
`sh -c 'git push --no-verify'`,
|
|
51
|
+
`env git commit -n -m x`,
|
|
52
|
+
`env -i HOME=/h git commit --no-verify -m x`,
|
|
53
|
+
`sudo -u ci git push --no-verify`,
|
|
54
|
+
`command git commit -n -m x`,
|
|
55
|
+
`timeout 60 git commit --no-verify -m x`,
|
|
56
|
+
`eval 'git commit --no-verify -m x'`,
|
|
57
|
+
`eval git commit -n -m x`,
|
|
58
|
+
`if true; then git commit --no-verify -m x; fi`,
|
|
59
|
+
`if git diff --quiet; then git push --no-verify; fi`,
|
|
60
|
+
`env bash -lc 'if true; then git commit -n -m x; fi'`,
|
|
61
|
+
`sudo env git -c core.hooksPath=/dev/null commit -m x`,
|
|
62
|
+
]) {
|
|
63
|
+
assert.match(reasonOf(decide(bash(ws.adopted, command))) ?? "", /skips the git hooks|core\.hooksPath/, command);
|
|
64
|
+
}
|
|
65
|
+
for (const command of [`bash -lc 'git commit -m x'`, `env git status`, `if true; then git commit -m x; fi`, `eval 'git log'`]) {
|
|
66
|
+
assert.equal(decide(bash(ws.adopted, command)), null, command);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
45
70
|
test("a git call that points core.hooksPath elsewhere is denied", (t) => {
|
|
46
71
|
const ws = workspace(t);
|
|
47
72
|
for (const command of ["git -c core.hooksPath=/dev/null commit -m x", "git -c core.hookspath= push"]) {
|
|
@@ -58,6 +83,11 @@ test("a hand run of a hook script is denied, and the reason names the lease", (t
|
|
|
58
83
|
"node.exe src/cli/worktree-isolation.mjs",
|
|
59
84
|
"bash hooks/pre-edit-guard.sh",
|
|
60
85
|
"./hooks/pre-edit-guard.sh < input.json",
|
|
86
|
+
"node packages/qc-harness/src/cli/report-stop.mjs < stop.json",
|
|
87
|
+
"node ./merge-guard.mjs",
|
|
88
|
+
"node src/cli/issue-gate.mjs",
|
|
89
|
+
"node src/cli/plan-stop.mjs",
|
|
90
|
+
"node src/cli/controller-guard.mjs",
|
|
61
91
|
]) {
|
|
62
92
|
assert.match(reasonOf(decide(bash(ws.adopted, command))) ?? "", /writes a lease/, command);
|
|
63
93
|
}
|
|
@@ -11,16 +11,20 @@ import { fileURLToPath } from "node:url";
|
|
|
11
11
|
import { promisify } from "node:util";
|
|
12
12
|
import { load } from "../config.mjs";
|
|
13
13
|
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
14
|
+
import { isControllerPath } from "./controller-guard.mjs";
|
|
14
15
|
import { ignoredPaths } from "./ignored-paths.mjs";
|
|
15
16
|
import * as powershell from "./powershell-command.mjs";
|
|
16
17
|
import * as posix from "./shell-command.mjs";
|
|
17
18
|
import { isAllowed } from "./work-order-guard.mjs";
|
|
18
19
|
import { MANIFEST_FILE, readManifest } from "./work-order-manifest.mjs";
|
|
20
|
+
import { nativePath } from "./workflow-place.mjs";
|
|
21
|
+
import { workflowAt } from "./workflow-settings.mjs";
|
|
19
22
|
import { OFF, isolationSettings } from "./worktree-isolation.mjs";
|
|
20
23
|
|
|
21
24
|
const execFileAsync = promisify(execFile);
|
|
22
25
|
const slashed = (file) => file.split(path.sep).join("/");
|
|
23
26
|
const MAX_LISTED = 40;
|
|
27
|
+
const CONTROLLER_RULE = "outside the controller paths";
|
|
24
28
|
|
|
25
29
|
/** The paths `git status --porcelain -z` names, with both sides of a rename. */
|
|
26
30
|
export function changedPaths(porcelain) {
|
|
@@ -46,8 +50,7 @@ const native = (dir) => {
|
|
|
46
50
|
|
|
47
51
|
/** A directory as the command wrote it, resolved the way the shell would, or null when it does not exist. */
|
|
48
52
|
function resolveDir(cwd, dir) {
|
|
49
|
-
|
|
50
|
-
if (process.platform === "win32") spelled = spelled.replace(/^\/([A-Za-z])(?=\/|$)/, "$1:");
|
|
53
|
+
const spelled = nativePath(dir.replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
51
54
|
const absolute = path.resolve(cwd, spelled);
|
|
52
55
|
return existsSync(absolute) ? absolute : null;
|
|
53
56
|
}
|
|
@@ -73,7 +76,7 @@ async function gitFacts(root) {
|
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
/** @returns each changed path in one checkout that breaks a rule, with the rules it breaks. */
|
|
76
|
-
async function findingsIn(root, manifest, projectRoot) {
|
|
79
|
+
async function findingsIn(root, manifest, projectRoot, isMainSession) {
|
|
77
80
|
let settings = null;
|
|
78
81
|
try {
|
|
79
82
|
settings = isolationSettings(load(root).swarm);
|
|
@@ -81,7 +84,15 @@ async function findingsIn(root, manifest, projectRoot) {
|
|
|
81
84
|
// A config error is the edit guard's to name; this guard judges the declaration alone.
|
|
82
85
|
}
|
|
83
86
|
const guardsBranch = settings !== null && settings.require !== OFF;
|
|
84
|
-
|
|
87
|
+
let controllerPaths = null;
|
|
88
|
+
if (isMainSession) {
|
|
89
|
+
try {
|
|
90
|
+
controllerPaths = workflowAt(root)?.review.controllerPaths ?? null;
|
|
91
|
+
} catch {
|
|
92
|
+
// A config error is the controller guard's to name.
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!manifest && !guardsBranch && !controllerPaths) return [];
|
|
85
96
|
|
|
86
97
|
let facts;
|
|
87
98
|
try {
|
|
@@ -98,6 +109,11 @@ async function findingsIn(root, manifest, projectRoot) {
|
|
|
98
109
|
add(rel, `outside the work order's declared paths (${MANIFEST_FILE}: ${patterns.join(", ")})`);
|
|
99
110
|
}
|
|
100
111
|
}
|
|
112
|
+
if (controllerPaths) {
|
|
113
|
+
for (const rel of facts.changed.filter((changed) => !isControllerPath(changed, controllerPaths))) {
|
|
114
|
+
add(rel, `${CONTROLLER_RULE} (${controllerPaths.join(", ")}), which the main session edits while swarm.dispatch is on`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
101
117
|
if (guardsBranch && settings.protectedBranches.includes(facts.branch)) {
|
|
102
118
|
const candidates = facts.changed.filter((rel) => !(settings.allow.length > 0 && isAllowed(rel, settings.allow)));
|
|
103
119
|
const ignored = await ignoredPaths(root, candidates);
|
|
@@ -126,7 +142,8 @@ export async function report(call, projectRoot) {
|
|
|
126
142
|
// The edit guard names a manifest that does not parse.
|
|
127
143
|
}
|
|
128
144
|
const findings = [];
|
|
129
|
-
|
|
145
|
+
const isMainSession = !(typeof call.agent_id === "string" && call.agent_id !== "");
|
|
146
|
+
for (const root of checkoutsOf(cwd, command, dialect)) findings.push(...(await findingsIn(root, manifest, project, isMainSession)));
|
|
130
147
|
if (findings.length === 0) return null;
|
|
131
148
|
|
|
132
149
|
const listed = findings.slice(0, MAX_LISTED).map((line) => `- ${line}`);
|
|
@@ -137,8 +154,12 @@ export async function report(call, projectRoot) {
|
|
|
137
154
|
additionalContext: [
|
|
138
155
|
"Bash edit guard: the checkout holds uncommitted changes that the swarm rules do not allow.",
|
|
139
156
|
...listed,
|
|
140
|
-
|
|
141
|
-
"
|
|
157
|
+
...(findings.some((line) => line.includes(CONTROLLER_RULE))
|
|
158
|
+
? ["Dispatch an implementer for a change outside the controller paths. Revert a change only if you made it by mistake. The guard does not revert anything."]
|
|
159
|
+
: [
|
|
160
|
+
"Revert a change only if your work order made it and should not have. " +
|
|
161
|
+
"For any other change, stop and tell the orchestrator. The guard does not revert anything.",
|
|
162
|
+
]),
|
|
142
163
|
].join("\n"),
|
|
143
164
|
},
|
|
144
165
|
};
|
|
@@ -108,6 +108,30 @@ test("a checkout with no isolation and no work order is silent", async (t) => {
|
|
|
108
108
|
assert.equal(await report(bash(ws.plain, "node x.mjs"), ws.plain), null);
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
+
test("while swarm.dispatch is on, a main-session shell write outside the controller paths is reported, and a subagent's is not", async (t) => {
|
|
112
|
+
const ws = workspace(t);
|
|
113
|
+
writeFileSync(path.join(ws.plain, "qc.config.json"), JSON.stringify({ swarm: { dispatch: {} } }));
|
|
114
|
+
ws.put(ws.plain, "src/a.ts");
|
|
115
|
+
ws.put(ws.plain, "docs/b.md");
|
|
116
|
+
const call = bash(ws.plain, "sed -i 's/a/b/' src/a.ts");
|
|
117
|
+
const output = await report(call, ws.plain);
|
|
118
|
+
assert.equal(output.hookSpecificOutput.hookEventName, "PostToolUse");
|
|
119
|
+
const text = contextOf(output);
|
|
120
|
+
assert.match(text, /src\/a\.ts: outside the controller paths \(docs\/\*\*, /);
|
|
121
|
+
assert.doesNotMatch(text, /docs\/b\.md/);
|
|
122
|
+
assert.match(text, /dispatch an implementer/i);
|
|
123
|
+
assert.doesNotMatch(text, /work order|orchestrator/);
|
|
124
|
+
assert.equal(await report({ ...call, agent_id: "agent-1" }, ws.plain), null);
|
|
125
|
+
assert.equal(await report(bash(ws.plain, "cat src/a.ts"), ws.plain), null);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("with swarm.dispatch off, a shell write breaks no controller rule", async (t) => {
|
|
129
|
+
const ws = workspace(t);
|
|
130
|
+
writeFileSync(path.join(ws.plain, "qc.config.json"), JSON.stringify({ swarm: {} }));
|
|
131
|
+
ws.put(ws.plain, "src/a.ts");
|
|
132
|
+
assert.equal(await report(bash(ws.plain, "sed -i 's/a/b/' src/a.ts"), ws.plain), null);
|
|
133
|
+
});
|
|
134
|
+
|
|
111
135
|
test("porcelain output names each changed path, and both sides of a rename", () => {
|
|
112
136
|
const status = [" M src/a.ts", "?? docs/new file.md", "R lib/new.ts", "lib/old.ts", ""].join("\u0000");
|
|
113
137
|
assert.deepEqual(changedPaths(status), ["src/a.ts", "docs/new file.md", "lib/new.ts", "lib/old.ts"]);
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { load } from "../config.mjs";
|
|
8
|
+
import { runCheck } from "./check.mjs";
|
|
9
|
+
|
|
10
|
+
const THRESHOLDS = { gates: { coverage: { value: 70, unit: "percent", comparator: "min", match: ["coverage threshold"] } } };
|
|
11
|
+
const VERSIONS = { libraries: { node: { label: "Node.js", version: "24" } } };
|
|
12
|
+
const LIFETIMES = { lifetimes: { accesstoken: { value: 15, unit: "minutes", match: ["access token lifetime"] } } };
|
|
13
|
+
const RULES = new Set(["threshold-literal", "version-literal", "stale-annotated-number", "unknown-token", "registry-literal"]);
|
|
14
|
+
|
|
15
|
+
/** A git repository holding the registries, one doc and a config. A file set to `null` is left out. */
|
|
16
|
+
function fixture({ registryLiteral, doc, files = {} }) {
|
|
17
|
+
const dir = mkdtempSync(path.join(tmpdir(), "qc-registries-"));
|
|
18
|
+
execFileSync("git", ["init", "-q"], { cwd: dir });
|
|
19
|
+
const all = {
|
|
20
|
+
"package.json": '{"name":"t","private":true,"type":"module"}',
|
|
21
|
+
"quality-thresholds.json": JSON.stringify(THRESHOLDS),
|
|
22
|
+
"versions.json": JSON.stringify(VERSIONS),
|
|
23
|
+
"session-lifetimes.json": JSON.stringify(LIFETIMES),
|
|
24
|
+
"qc.config.json": JSON.stringify({
|
|
25
|
+
docs: { root: "docs", decisions: "docs/decisions.md", enforcement: "docs/enforcement.md" },
|
|
26
|
+
featureRoots: [],
|
|
27
|
+
gates: { "registry-literal": true },
|
|
28
|
+
...(registryLiteral === undefined ? {} : { registryLiteral }),
|
|
29
|
+
}),
|
|
30
|
+
"docs/a.md": doc,
|
|
31
|
+
...files,
|
|
32
|
+
};
|
|
33
|
+
for (const [file, contents] of Object.entries(all)) {
|
|
34
|
+
if (contents === null) continue;
|
|
35
|
+
mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
|
|
36
|
+
writeFileSync(path.join(dir, file), contents);
|
|
37
|
+
}
|
|
38
|
+
return dir;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function problemsOf(options) {
|
|
42
|
+
const dir = fixture(options);
|
|
43
|
+
try {
|
|
44
|
+
const { problems } = await runCheck(load(dir));
|
|
45
|
+
return problems.filter((problem) => RULES.has(problem.rule));
|
|
46
|
+
} finally {
|
|
47
|
+
rmSync(dir, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const rulesOf = (problems) => problems.map((problem) => problem.rule);
|
|
52
|
+
const ttl = { path: "session-lifetimes.json", key: "lifetimes", prefix: "ttl" };
|
|
53
|
+
|
|
54
|
+
test("no registries set: the thresholds and the versions apply", async () => {
|
|
55
|
+
const bare = await problemsOf({ doc: "The coverage threshold is 70%.\n\nRuns on Node.js 24." });
|
|
56
|
+
assert.deepEqual(rulesOf(bare).sort(), ["threshold-literal", "version-literal"]);
|
|
57
|
+
const annotated = await problemsOf({ doc: "The coverage threshold is 70 <!-- q:coverage -->%.\n\nNode.js 24 <!-- ver:node -->." });
|
|
58
|
+
assert.deepEqual(annotated, []);
|
|
59
|
+
const stale = await problemsOf({ doc: "Node.js 25 <!-- v:node -->." });
|
|
60
|
+
assert.deepEqual(rulesOf(stale), ["stale-annotated-number"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("a ttl item keeps the threshold registry, and catches a stale and an unknown ttl id", async () => {
|
|
64
|
+
const registryLiteral = { registries: [ttl] };
|
|
65
|
+
const bare = await problemsOf({ registryLiteral, doc: "The coverage threshold is 70%.\n\nThe access token lifetime is 15 minutes." });
|
|
66
|
+
assert.deepEqual(rulesOf(bare), ["threshold-literal", "threshold-literal"]);
|
|
67
|
+
assert.match(bare.map((problem) => problem.detail).join("\n"), /\{\{ttl:accesstoken\}\}/);
|
|
68
|
+
const stale = await problemsOf({ registryLiteral, doc: "Access token lifetime 20 <!-- ttl:accesstoken --> minutes.\n\nSee 1 <!-- ttl:nope -->." });
|
|
69
|
+
assert.deepEqual(rulesOf(stale), ["stale-annotated-number", "unknown-token"]);
|
|
70
|
+
const clean = await problemsOf({ registryLiteral, doc: "Access token lifetime 15 <!-- ttl:accesstoken --> minutes." });
|
|
71
|
+
assert.deepEqual(clean, []);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("an item with the path of a default overrides it", async () => {
|
|
75
|
+
const registryLiteral = { registries: [{ path: "quality-thresholds.json", key: "gates", prefix: "thr" }] };
|
|
76
|
+
assert.deepEqual(await problemsOf({ registryLiteral, doc: "The coverage threshold is 70 <!-- thr:coverage -->%." }), []);
|
|
77
|
+
const old = await problemsOf({ registryLiteral, doc: "The coverage threshold is 70 <!-- q:coverage -->%." });
|
|
78
|
+
assert.deepEqual(rulesOf(old), ["threshold-literal"]);
|
|
79
|
+
// The versions default stays.
|
|
80
|
+
const version = await problemsOf({ registryLiteral, doc: "Node.js 25 <!-- ver:node -->." });
|
|
81
|
+
assert.deepEqual(rulesOf(version), ["stale-annotated-number"]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("a malformed item is a problem at qc.config.json, and the rest still run", async () => {
|
|
85
|
+
const registries = [
|
|
86
|
+
{ path: "session-lifetimes.json" },
|
|
87
|
+
{ path: "session-lifetimes.json", key: "lifetimes", prefix: "bad prefix" },
|
|
88
|
+
{ path: "session-lifetimes.json", key: "lifetimes", prefix: "" },
|
|
89
|
+
{ path: "session-lifetimes.json", key: "lifetimes", prefix: ["ok", 3] },
|
|
90
|
+
{ path: "session-lifetimes.json", key: "lifetimes", prefix: "ttl", valueKey: 5 },
|
|
91
|
+
{ path: "session-lifetimes.json", key: "lifetimes", prefix: "ttl", unitKey: {} },
|
|
92
|
+
"text",
|
|
93
|
+
];
|
|
94
|
+
const problems = await problemsOf({ registryLiteral: { registries }, doc: "The coverage threshold is 70%." });
|
|
95
|
+
const config = problems.filter((problem) => problem.rule === "registry-literal");
|
|
96
|
+
assert.equal(config.length, registries.length);
|
|
97
|
+
assert.ok(config.every((problem) => problem.path === "qc.config.json"));
|
|
98
|
+
assert.deepEqual(rulesOf(problems.filter((problem) => problem.rule !== "registry-literal")), ["threshold-literal"]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("registries that is not a list is a problem", async () => {
|
|
102
|
+
const problems = await problemsOf({ registryLiteral: { registries: ttl }, doc: "Nothing here." });
|
|
103
|
+
assert.deepEqual(rulesOf(problems), ["registry-literal"]);
|
|
104
|
+
assert.equal(problems[0].path, "qc.config.json");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("a listed registry that is missing, unreadable or without its key is a problem", async () => {
|
|
108
|
+
const missing = await problemsOf({ registryLiteral: { registries: [{ ...ttl, path: "nope.json" }] }, doc: "Nothing here." });
|
|
109
|
+
assert.deepEqual(rulesOf(missing), ["registry-literal"]);
|
|
110
|
+
assert.match(missing[0].detail, /nope\.json/);
|
|
111
|
+
const broken = await problemsOf({ registryLiteral: { registries: [ttl] }, doc: "Nothing here.", files: { "session-lifetimes.json": "{" } });
|
|
112
|
+
assert.deepEqual(rulesOf(broken), ["registry-literal"]);
|
|
113
|
+
const noKey = await problemsOf({ registryLiteral: { registries: [{ ...ttl, key: "other" }] }, doc: "Nothing here." });
|
|
114
|
+
assert.deepEqual(rulesOf(noKey), ["registry-literal"]);
|
|
115
|
+
const notObject = await problemsOf({
|
|
116
|
+
registryLiteral: { registries: [ttl] },
|
|
117
|
+
doc: "Nothing here.",
|
|
118
|
+
files: { "session-lifetimes.json": '{"lifetimes":[]}' },
|
|
119
|
+
});
|
|
120
|
+
assert.deepEqual(rulesOf(notObject), ["registry-literal"]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("a default registry whose file is absent stays silent", async () => {
|
|
124
|
+
const problems = await problemsOf({ doc: "Nothing here.", files: { "versions.json": null, "quality-thresholds.json": null } });
|
|
125
|
+
assert.deepEqual(problems, []);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("a default registry whose file is unreadable is a problem", async () => {
|
|
129
|
+
const problems = await problemsOf({ doc: "Nothing here.", files: { "versions.json": "{" } });
|
|
130
|
+
assert.deepEqual(rulesOf(problems), ["registry-literal"]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("two registries that share a prefix are a problem", async () => {
|
|
134
|
+
const problems = await problemsOf({ registryLiteral: { registries: [{ ...ttl, prefix: ["ttl", "q"] }] }, doc: "Nothing here." });
|
|
135
|
+
assert.deepEqual(rulesOf(problems), ["registry-literal"]);
|
|
136
|
+
assert.match(problems[0].detail, /'q'/);
|
|
137
|
+
assert.equal(problems[0].path, "qc.config.json");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const READER_RULES = new Set(["missing-reader", "silent-reader"]);
|
|
141
|
+
|
|
142
|
+
async function readerProblems(files, registryLiteral) {
|
|
143
|
+
const dir = fixture({ registryLiteral, doc: "Nothing here.", files });
|
|
144
|
+
try {
|
|
145
|
+
const { problems } = await runCheck(load(dir));
|
|
146
|
+
return problems.filter((problem) => READER_RULES.has(problem.rule));
|
|
147
|
+
} finally {
|
|
148
|
+
rmSync(dir, { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const lifetimes = (readers) => JSON.stringify({ lifetimes: { accesstoken: { value: 15, unit: "minutes", readers } } });
|
|
153
|
+
const thresholdsWith = (readers) => JSON.stringify({ gates: { coverage: { value: 70, unit: "percent", comparator: "min", readers } } });
|
|
154
|
+
|
|
155
|
+
test("registry-readers: a ttl entry naming a missing reader fails", async () => {
|
|
156
|
+
const problems = await readerProblems({ "session-lifetimes.json": lifetimes(["src/auth.ts"]) }, { registries: [ttl] });
|
|
157
|
+
assert.deepEqual(problems.map((problem) => [problem.rule, problem.path]), [["missing-reader", "src/auth.ts"]]);
|
|
158
|
+
assert.match(problems[0].detail, /accesstoken/);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("registry-readers: a ttl reader that does not name its entry fails, and one that does passes", async () => {
|
|
162
|
+
const silent = await readerProblems(
|
|
163
|
+
{ "session-lifetimes.json": lifetimes(["src/auth.ts"]), "src/auth.ts": "export const x = 1;\n" },
|
|
164
|
+
{ registries: [ttl] },
|
|
165
|
+
);
|
|
166
|
+
assert.deepEqual(silent.map((problem) => [problem.rule, problem.path]), [["silent-reader", "src/auth.ts"]]);
|
|
167
|
+
const named = await readerProblems(
|
|
168
|
+
{ "session-lifetimes.json": lifetimes(["src/auth.ts"]), "src/auth.ts": 'export const t = ttl("accesstoken");\n' },
|
|
169
|
+
{ registries: [ttl] },
|
|
170
|
+
);
|
|
171
|
+
assert.deepEqual(named, []);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("registry-readers: the thresholds cases are unchanged", async () => {
|
|
175
|
+
const missing = await readerProblems({ "quality-thresholds.json": thresholdsWith(["src/cov.ts"]) });
|
|
176
|
+
assert.deepEqual(missing.map((problem) => [problem.rule, problem.path]), [["missing-reader", "src/cov.ts"]]);
|
|
177
|
+
const silent = await readerProblems({ "quality-thresholds.json": thresholdsWith(["src/cov.ts"]), "src/cov.ts": "export {};\n" });
|
|
178
|
+
assert.deepEqual(silent.map((problem) => problem.rule), ["silent-reader"]);
|
|
179
|
+
const named = await readerProblems({ "quality-thresholds.json": thresholdsWith(["src/cov.ts"]), "src/cov.ts": "gates.coverage\n" });
|
|
180
|
+
assert.deepEqual(named, []);
|
|
181
|
+
});
|