architecture-harness 0.6.0 → 0.8.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 +1 -1
- package/src/cli/bash-edit-guard.mjs +161 -0
- package/src/cli/bash-edit-guard.test.mjs +98 -0
- package/src/cli/budget-counter.mjs +40 -0
- package/src/cli/budget-counter.test.mjs +35 -0
- package/src/cli/budget-guard.mjs +56 -0
- package/src/cli/budget-guard.test.mjs +90 -0
- package/src/cli/budget.mjs +74 -0
- package/src/cli/budget.test.mjs +79 -0
- package/src/cli/check.mjs +197 -174
- package/src/cli/checkout-root.mjs +16 -0
- package/src/cli/cli.test.mjs +79 -0
- package/src/cli/decisions.mjs +5 -6
- package/src/cli/ignored-paths.mjs +29 -0
- package/src/cli/ignored-paths.test.mjs +44 -0
- package/src/cli/qc.mjs +10 -2
- package/src/cli/repo-files.mjs +69 -0
- package/src/cli/repo-files.test.mjs +78 -0
- package/src/cli/shell-command.mjs +211 -0
- package/src/cli/shell-command.test.mjs +95 -0
- package/src/cli/work-order-guard.mjs +19 -21
- package/src/cli/work-order-guard.test.mjs +18 -0
- package/src/cli/work-order-manifest.mjs +14 -0
- package/src/cli/worktree-isolation.mjs +3 -1
- package/src/cli/worktree-isolation.test.mjs +13 -0
- package/src/cli/worktree.mjs +145 -0
- package/src/cli/worktree.test.mjs +110 -0
- package/src/config.mjs +6 -0
- package/src/gates/english-source.mjs +13 -9
- package/src/gates/english-source.test.mjs +19 -1
- package/src/gates/test-mirror.mjs +22 -9
- package/src/gates/test-mirror.test.mjs +34 -0
- package/src/glob.mjs +12 -0
- package/templates/CLAUDE.md +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Test path mirror:
|
|
2
|
-
//
|
|
1
|
+
// Test path mirror: a test lives in its root's tests folder at its source's path, never in src. A folder
|
|
2
|
+
// root matches a source folder, for a block test that spans files; a testOnly root names no source.
|
|
3
3
|
|
|
4
4
|
const TEST_SUFFIX = /\.test\.[cm]?[jt]sx?$/;
|
|
5
5
|
const SOURCE_EXTENSION = /\.[cm]?[jt]sx?$/;
|
|
@@ -7,21 +7,23 @@ const SOURCE_EXTENSION = /\.[cm]?[jt]sx?$/;
|
|
|
7
7
|
const folder = (value) => value.replace(/\/+$/, "");
|
|
8
8
|
const holds = (dir, file) => file.startsWith(`${dir}/`);
|
|
9
9
|
const named = (value) => typeof value === "string" && folder(value) !== "";
|
|
10
|
+
const MATCHES = ["file", "folder"];
|
|
10
11
|
|
|
11
12
|
/** The roots as clean folders, or the problems that name each malformed one. */
|
|
12
13
|
function readRoots(roots) {
|
|
13
14
|
if (!Array.isArray(roots)) {
|
|
14
|
-
const detail = `testMirror.roots must be a list of { src, tests, testOnly? }, got ${JSON.stringify(roots)}`;
|
|
15
|
+
const detail = `testMirror.roots must be a list of { src, tests, match?, testOnly? }, got ${JSON.stringify(roots)}`;
|
|
15
16
|
return { valid: [], problems: [{ path: "qc.config.json", rule: "invalid-mirror-root", detail }] };
|
|
16
17
|
}
|
|
17
18
|
const valid = [];
|
|
18
19
|
const problems = [];
|
|
19
20
|
roots.forEach((root, index) => {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const match = root?.match ?? "file";
|
|
22
|
+
if (named(root?.src) && named(root?.tests) && MATCHES.includes(match)) {
|
|
23
|
+
valid.push({ src: folder(root.src), tests: folder(root.tests), match, testOnly: root.testOnly === true });
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
|
-
const detail = `testMirror.roots[${index}] needs a src folder
|
|
26
|
+
const detail = `testMirror.roots[${index}] needs a src folder, a tests folder, and a match of ${MATCHES.join(" or ")}, got ${JSON.stringify(root)}`;
|
|
25
27
|
problems.push({ path: "qc.config.json", rule: "invalid-mirror-root", detail });
|
|
26
28
|
});
|
|
27
29
|
return { valid, problems };
|
|
@@ -33,13 +35,20 @@ export function mirrorFolders(roots) {
|
|
|
33
35
|
return [...new Set(valid.flatMap((root) => [root.src, root.tests]))];
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
function judge(testFile, root, srcStems) {
|
|
38
|
+
function judge(testFile, root, srcStems, srcFolders) {
|
|
37
39
|
if (!holds(root.tests, testFile)) {
|
|
38
40
|
const detail = `${testFile}: a test in ${root.src}/ lives in ${root.tests}/, at the path that mirrors its source`;
|
|
39
41
|
return { path: testFile, rule: "unmirrored-test", detail };
|
|
40
42
|
}
|
|
41
43
|
if (root.testOnly) return null;
|
|
42
44
|
const stem = testFile.slice(root.tests.length + 1).replace(TEST_SUFFIX, "");
|
|
45
|
+
if (root.match === "folder") {
|
|
46
|
+
const within = stem.includes("/") ? stem.slice(0, stem.lastIndexOf("/")) : "";
|
|
47
|
+
const sourceFolder = within ? `${root.src}/${within}` : root.src;
|
|
48
|
+
if (srcFolders.has(sourceFolder)) return null;
|
|
49
|
+
const detail = `${testFile}: no source folder at ${sourceFolder} for this test in ${root.tests}/`;
|
|
50
|
+
return { path: testFile, rule: "orphaned-test", detail };
|
|
51
|
+
}
|
|
43
52
|
const source = `${root.src}/${stem}`;
|
|
44
53
|
if (srcStems.has(source) || srcStems.has(`${source}/index`)) return null;
|
|
45
54
|
const detail = `${testFile}: no source at ${source} or ${source}/index for this test in ${root.tests}/`;
|
|
@@ -52,15 +61,19 @@ function judge(testFile, root, srcStems) {
|
|
|
52
61
|
*
|
|
53
62
|
* @param {string[]} testFiles repository-relative paths of the test files
|
|
54
63
|
* @param {string[]} srcFiles repository-relative paths of the source files
|
|
55
|
-
* @param {{src: string, tests: string, testOnly?: boolean}[]} roots `testMirror.roots`
|
|
64
|
+
* @param {{src: string, tests: string, match?: "file" | "folder", testOnly?: boolean}[]} roots `testMirror.roots`
|
|
56
65
|
* @returns {{path: string, rule: string, detail: string}[]}
|
|
57
66
|
*/
|
|
58
67
|
export function checkTestMirror(testFiles, srcFiles, roots) {
|
|
59
68
|
const { valid, problems } = readRoots(roots);
|
|
60
69
|
const srcStems = new Set(srcFiles.map((file) => file.replace(SOURCE_EXTENSION, "")));
|
|
70
|
+
const srcFolders = new Set();
|
|
71
|
+
for (const file of srcFiles) {
|
|
72
|
+
for (let at = file.lastIndexOf("/"); at > 0; at = file.lastIndexOf("/", at - 1)) srcFolders.add(file.slice(0, at));
|
|
73
|
+
}
|
|
61
74
|
for (const testFile of testFiles) {
|
|
62
75
|
const root = valid.find((each) => holds(each.tests, testFile)) ?? valid.find((each) => holds(each.src, testFile));
|
|
63
|
-
const problem = root ? judge(testFile, root, srcStems) : null;
|
|
76
|
+
const problem = root ? judge(testFile, root, srcStems, srcFolders) : null;
|
|
64
77
|
if (problem) problems.push(problem);
|
|
65
78
|
}
|
|
66
79
|
return problems;
|
|
@@ -92,3 +92,37 @@ test("a root without a src and a tests folder is a problem that names its key, n
|
|
|
92
92
|
assert.deepEqual(verdict(problems), [{ path: "qc.config.json", rule: "invalid-mirror-root" }]);
|
|
93
93
|
assert.ok(problems[0].detail.includes("testMirror.roots[0]"), problems[0].detail);
|
|
94
94
|
});
|
|
95
|
+
|
|
96
|
+
const BACKEND_BY_FOLDER = [{ src: "backend/src", tests: "backend/tests", match: "folder" }];
|
|
97
|
+
const BACKEND_SOURCES = ["backend/src/features/audit-log/schema.ts", "backend/src/features/audit-log/shared/queries.ts"];
|
|
98
|
+
|
|
99
|
+
test("a folder root accepts a block test whose folder mirrors a source folder", () => {
|
|
100
|
+
const problems = checkTestMirror(["backend/tests/features/audit-log/record.test.ts"], BACKEND_SOURCES, BACKEND_BY_FOLDER);
|
|
101
|
+
assert.deepEqual(problems, []);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("a folder root refuses a test whose folder mirrors no source folder", () => {
|
|
105
|
+
const problems = checkTestMirror(["backend/tests/features/gone/record.test.ts"], BACKEND_SOURCES, BACKEND_BY_FOLDER);
|
|
106
|
+
assert.equal(problems.length, 1);
|
|
107
|
+
assert.equal(problems[0].rule, "orphaned-test");
|
|
108
|
+
assert.match(problems[0].detail, /backend\/src\/features\/gone/);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("a folder root still refuses a test left beside its source in src", () => {
|
|
112
|
+
const problems = checkTestMirror(["backend/src/features/audit-log/record.test.ts"], BACKEND_SOURCES, BACKEND_BY_FOLDER);
|
|
113
|
+
assert.equal(problems[0].rule, "unmirrored-test");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("a file root still refuses the same block test, and file is the default", () => {
|
|
117
|
+
for (const roots of [[{ src: "backend/src", tests: "backend/tests", match: "file" }], [{ src: "backend/src", tests: "backend/tests" }]]) {
|
|
118
|
+
const problems = checkTestMirror(["backend/tests/features/audit-log/record.test.ts"], BACKEND_SOURCES, roots);
|
|
119
|
+
assert.equal(problems.length, 1);
|
|
120
|
+
assert.equal(problems[0].rule, "orphaned-test");
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("a match value other than file or folder is an invalid root", () => {
|
|
125
|
+
const problems = checkTestMirror([], BACKEND_SOURCES, [{ src: "backend/src", tests: "backend/tests", match: "stem" }]);
|
|
126
|
+
assert.equal(problems.length, 1);
|
|
127
|
+
assert.equal(problems[0].rule, "invalid-mirror-root");
|
|
128
|
+
});
|
package/src/glob.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A fragment: the one glob matcher. The work-order guard, the English gate and the file lister
|
|
2
|
+
// all read globs from qc.config.json, so they must agree on what a glob matches.
|
|
3
|
+
|
|
4
|
+
/** `**` crosses folders and `*` stays inside one. Every other character is literal. */
|
|
5
|
+
export function globToRegExp(glob) {
|
|
6
|
+
const body = glob
|
|
7
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
8
|
+
.replace(/\*\*/g, "\u0000")
|
|
9
|
+
.replace(/\*/g, "[^/]*")
|
|
10
|
+
.replace(/\u0000/g, ".*");
|
|
11
|
+
return new RegExp(`^${body}$`);
|
|
12
|
+
}
|
package/templates/CLAUDE.md
CHANGED
|
@@ -26,7 +26,7 @@ every one here — this table is what an agent reads instead of guessing.
|
|
|
26
26
|
```bash
|
|
27
27
|
pnpm spec:check # every structural gate (qc check)
|
|
28
28
|
pnpm gen:feature <name> # scaffold a feature. Full domain name, never a code
|
|
29
|
-
npx qc check <file
|
|
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
|
```
|
|
32
32
|
|