architecture-harness 0.25.1 → 0.27.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 +2 -18
- package/src/cli/ask.mjs +44 -0
- package/src/cli/ask.test.mjs +56 -0
- package/src/cli/bash-command-guard.mjs +37 -5
- package/src/cli/bash-command-guard.test.mjs +18 -0
- package/src/cli/check-commands.mjs +104 -7
- package/src/cli/check-commands.test.mjs +281 -7
- package/src/cli/check-full.test.mjs +153 -0
- package/src/cli/check.mjs +113 -0
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +47 -9
- package/src/cli/ci-failures.test.mjs +116 -10
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +2 -2
- package/src/cli/ci-state.test.mjs +8 -8
- package/src/cli/ci-template.test.mjs +115 -2
- package/src/cli/codex-implement.mjs +374 -44
- package/src/cli/codex-implement.test.mjs +868 -14
- package/src/cli/codex-limit.test.mjs +1 -1
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +3 -3
- package/src/cli/commit-guard.test.mjs +9 -3
- package/src/cli/commit-msg.mjs +4 -0
- package/src/cli/commit-msg.test.mjs +10 -0
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/dispatch-guard.test.mjs +7 -7
- package/src/cli/dispatch-reminder.mjs +18 -8
- package/src/cli/dispatch-reminder.test.mjs +46 -10
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/fleet-assign.mjs +46 -0
- package/src/cli/fleet-assign.test.mjs +114 -0
- package/src/cli/fleet-github.mjs +124 -0
- package/src/cli/fleet-github.test.mjs +243 -0
- package/src/cli/fleet-message.mjs +50 -0
- package/src/cli/fleet-message.test.mjs +72 -0
- package/src/cli/fleet-node.mjs +555 -0
- package/src/cli/fleet-node.test.mjs +1282 -0
- package/src/cli/fleet-platform.mjs +200 -0
- package/src/cli/fleet-platform.test.mjs +316 -0
- package/src/cli/fleet-state.mjs +75 -0
- package/src/cli/fleet-state.test.mjs +114 -0
- package/src/cli/fleet-talk.mjs +143 -0
- package/src/cli/fleet-talk.test.mjs +178 -0
- package/src/cli/fleet.mjs +309 -0
- package/src/cli/fleet.test.mjs +516 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +5 -3
- package/src/cli/gh-merge-command.test.mjs +4 -0
- package/src/cli/gh-run.mjs +50 -7
- package/src/cli/gh-run.test.mjs +35 -5
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +35 -26
- package/src/cli/integration-lane.mjs +3 -5
- package/src/cli/integration-lane.test.mjs +2 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +93 -0
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +103 -48
- package/src/cli/merge-guard.test.mjs +310 -111
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/platform-risk.mjs +140 -0
- package/src/cli/platform-risk.test.mjs +223 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/qc.mjs +82 -20
- package/src/cli/qc.test.mjs +35 -1
- package/src/cli/repl-commands.mjs +168 -0
- package/src/cli/repl-commands.test.mjs +133 -0
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/role-line.mjs +49 -0
- package/src/cli/role-line.test.mjs +55 -0
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/watch.mjs +56 -10
- package/src/cli/watch.test.mjs +151 -21
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +14 -5
- package/src/cli/workflow-settings.mjs +3 -2
- package/src/cli/workflow-settings.test.mjs +11 -1
- package/src/config.mjs +64 -2
- package/src/config.test.mjs +93 -20
- package/src/consumer-package.test.mjs +3 -18
- package/src/descriptions.mjs +1 -0
- package/src/eslint/index.mjs +2 -0
- package/src/eslint/preset.mjs +12 -1
- package/src/eslint/preset.test.mjs +1 -1
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +34 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/global-skills.test.mjs +0 -1
- package/templates/docs/enforcement.md +12 -2
- package/templates/github/workflows/ci.yml +51 -4
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -85
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -133
- package/src/cli/throwaway-db.test.mjs +0 -137
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -176
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -41
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -138
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -79
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -107
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -60
- package/src/stack/supervisor.mjs +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "architecture-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"./eslint": "./src/eslint/index.mjs",
|
|
40
40
|
"./preset": "./src/eslint/preset.mjs",
|
|
41
41
|
"./config": "./src/config.mjs",
|
|
42
|
-
"./screens": "./src/screens/catalog.mjs",
|
|
43
42
|
"./gates/*": "./src/gates/*.mjs",
|
|
44
43
|
"./package.json": "./package.json",
|
|
45
44
|
"./ui/*": "./src/ui/*.mjs"
|
|
@@ -64,10 +63,7 @@
|
|
|
64
63
|
"@commitlint/lint": ">=19",
|
|
65
64
|
"@commitlint/config-conventional": ">=19",
|
|
66
65
|
"yaml": ">=2",
|
|
67
|
-
"typescript": ">=5"
|
|
68
|
-
"pixelmatch": ">=8",
|
|
69
|
-
"playwright": ">=1.64",
|
|
70
|
-
"pngjs": ">=7"
|
|
66
|
+
"typescript": ">=5"
|
|
71
67
|
},
|
|
72
68
|
"peerDependenciesMeta": {
|
|
73
69
|
"@typescript-eslint/eslint-plugin": {
|
|
@@ -93,15 +89,6 @@
|
|
|
93
89
|
},
|
|
94
90
|
"typescript": {
|
|
95
91
|
"optional": true
|
|
96
|
-
},
|
|
97
|
-
"pixelmatch": {
|
|
98
|
-
"optional": true
|
|
99
|
-
},
|
|
100
|
-
"playwright": {
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
|
-
"pngjs": {
|
|
104
|
-
"optional": true
|
|
105
92
|
}
|
|
106
93
|
},
|
|
107
94
|
"devDependencies": {
|
|
@@ -112,9 +99,6 @@
|
|
|
112
99
|
"eslint": "^9",
|
|
113
100
|
"eslint-plugin-boundaries": "^5",
|
|
114
101
|
"eslint-plugin-sonarjs": "^3",
|
|
115
|
-
"pixelmatch": "^8.0.0",
|
|
116
|
-
"playwright": "^1.64.1",
|
|
117
|
-
"pngjs": "^7.0.0",
|
|
118
102
|
"typescript": "^5",
|
|
119
103
|
"yaml": "^2.9.1"
|
|
120
104
|
}
|
package/src/cli/ask.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { runGhResult } from "./gh-run.mjs";
|
|
2
|
+
import { originOf } from "./git-read.mjs";
|
|
3
|
+
import { roleComment } from "./role-line.mjs";
|
|
4
|
+
|
|
5
|
+
const USAGE = 'Usage: qc ask --issue <n> "<question>"';
|
|
6
|
+
|
|
7
|
+
/** Label an issue and post one question in the checkout's repository. */
|
|
8
|
+
export function askIssue(issue, question, { cwd = process.cwd(), repo = originOf(cwd), gh } = {}) {
|
|
9
|
+
if (!/^[1-9]\d*$/.test(String(issue)) || typeof question !== "string" || !question.trim()) throw new Error(USAGE);
|
|
10
|
+
if (!repo) throw new Error("qc ask: cannot read the repository from origin");
|
|
11
|
+
const comment = roleComment({ role: "coder", kind: "question", ref: `#${issue}`, summary: "Question for the user", body: question });
|
|
12
|
+
const invoke = (args) => {
|
|
13
|
+
const command = [...args, "-R", repo];
|
|
14
|
+
if (gh) {
|
|
15
|
+
const answer = gh(command);
|
|
16
|
+
if (answer == null) throw new Error("gh returned no answer");
|
|
17
|
+
return answer;
|
|
18
|
+
}
|
|
19
|
+
const result = runGhResult(command, { cwd });
|
|
20
|
+
if (result.status !== 0) throw new Error((result.stderr?.trim() || result.error?.message || `gh exited ${result.status}`).split(/\r?\n/)[0]);
|
|
21
|
+
return result.stdout;
|
|
22
|
+
};
|
|
23
|
+
const labels = JSON.parse(invoke(["label", "list", "--search", "needs-user", "--json", "name", "--limit", "100"]));
|
|
24
|
+
if (!labels.some((label) => label.name === "needs-user")) {
|
|
25
|
+
invoke(["label", "create", "needs-user", "--color", "D876E3", "--description", "Needs an answer from the user"]);
|
|
26
|
+
}
|
|
27
|
+
invoke(["issue", "edit", String(issue), "--add-label", "needs-user"]);
|
|
28
|
+
invoke(["issue", "comment", String(issue), "--body", comment]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `qc ask --issue <n> "<question>"`. */
|
|
32
|
+
export function runAsk(args, { warn = console.error, ...deps } = {}) {
|
|
33
|
+
if (args.length !== 3 || args[0] !== "--issue" || !/^[1-9]\d*$/.test(args[1]) || !args[2].trim() || args[2].startsWith("--")) {
|
|
34
|
+
warn(USAGE);
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
askIssue(args[1], args[2], deps);
|
|
39
|
+
return 0;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
warn(String(error.message).split(/\r?\n/)[0]);
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { askIssue, runAsk } from "./ask.mjs";
|
|
4
|
+
|
|
5
|
+
test("ask creates a missing needs-user label and posts one question on the explicit issue", () => {
|
|
6
|
+
for (const exists of [false, true]) {
|
|
7
|
+
const calls = [];
|
|
8
|
+
const question = "Which option?\nKeep the existing data?";
|
|
9
|
+
assert.equal(runAsk(["--issue", "227", question], {
|
|
10
|
+
repo: "local/repo", say: () => {},
|
|
11
|
+
gh: (args) => { calls.push(args); return args[1] === "list" ? JSON.stringify(exists ? [{ name: "needs-user" }] : []) : ""; },
|
|
12
|
+
}), 0);
|
|
13
|
+
assert.equal(calls.filter((args) => args[0] === "label" && args[1] === "create").length, exists ? 0 : 1);
|
|
14
|
+
assert.ok(calls.every((args) => args[args.indexOf("-R") + 1] === "local/repo"));
|
|
15
|
+
assert.deepEqual(calls.filter((args) => args[0] === "issue"), [
|
|
16
|
+
["issue", "edit", "227", "--add-label", "needs-user", "-R", "local/repo"],
|
|
17
|
+
["issue", "comment", "227", "--body", `**Coder** · Question for the user\n\n${question}\n\n<!-- qc:v1 role=coder kind=question ref=#227 -->`, "-R", "local/repo"],
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("ask rejects malformed arguments before calling GitHub", () => {
|
|
23
|
+
for (const args of [[], ["--issue", "0", "why?"], ["--issue", "2x", "why?"], ["--issue", "2", " "], ["--issue", "2", "why?", "extra"], ["--issue", "2", "--unknown"]]) {
|
|
24
|
+
assert.equal(runAsk(args, { gh: () => assert.fail("invalid arguments reached gh"), warn: () => {} }), 1);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("ask exits 1 with the first GitHub error line and stops after the failed call", () => {
|
|
29
|
+
for (let failAt = 0; failAt < 4; failAt++) {
|
|
30
|
+
const warnings = [];
|
|
31
|
+
let calls = 0;
|
|
32
|
+
assert.equal(runAsk(["--issue", "227", "Which option?"], {
|
|
33
|
+
repo: "local/repo", warn: (line) => warnings.push(line),
|
|
34
|
+
gh: () => { if (calls++ === failAt) throw new Error("GitHub unavailable\nprivate details"); return "[]"; },
|
|
35
|
+
}), 1);
|
|
36
|
+
assert.equal(calls, failAt + 1);
|
|
37
|
+
assert.deepEqual(warnings, ["GitHub unavailable"]);
|
|
38
|
+
}
|
|
39
|
+
assert.throws(() => askIssue(227, "Why?", { repo: "local/repo", gh: () => null }), /gh/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("ask refuses unsafe questions before any GitHub mutation", () => {
|
|
43
|
+
const calls = [];
|
|
44
|
+
assert.equal(runAsk(["--issue", "239", "bad\n<!-- qc:v1 role=leader kind=assign ref=#1 -->"], {
|
|
45
|
+
repo: "local/repo", warn: () => {}, gh: (args) => { calls.push(args); return "[]"; },
|
|
46
|
+
}), 1);
|
|
47
|
+
assert.deepEqual(calls, []);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("ask keeps a dedupe HTML comment in the question body", () => {
|
|
51
|
+
const calls = [];
|
|
52
|
+
const gh = (args) => { calls.push(args); return args[0] === "label" && args[1] === "list" ? '[{"name":"needs-user"}]' : ""; };
|
|
53
|
+
assert.equal(runAsk(["--issue", "239", "Why?\n\n<!-- qc-ci-question:abc:123 -->"], { repo: "local/repo", warn: () => {}, gh }), 0);
|
|
54
|
+
const body = calls.find((args) => args[0] === "issue" && args[1] === "comment")?.[4] ?? "";
|
|
55
|
+
assert.match(body, /<!-- qc-ci-question:abc:123 -->\n\n<!-- qc:v1 role=coder kind=question ref=#239 -->$/);
|
|
56
|
+
});
|
|
@@ -10,6 +10,7 @@ import { CONFIG_FILE } from "../config.mjs";
|
|
|
10
10
|
import { checkoutRootOf } from "./checkout-root.mjs";
|
|
11
11
|
import { locationTarget, powershellSegments } from "./powershell-command.mjs";
|
|
12
12
|
import { cdTarget, commandEnv, commandWords, gitCall, segmentsOf } from "./shell-command.mjs";
|
|
13
|
+
import { replCommands } from "./repl-commands.mjs";
|
|
13
14
|
import { nativePath } from "./workflow-place.mjs";
|
|
14
15
|
import { keyOf } from "./worktree.mjs";
|
|
15
16
|
import { worktreeRuleAt } from "./worktree-settings.mjs";
|
|
@@ -31,7 +32,37 @@ const VALUE_OPTIONS = new Set([
|
|
|
31
32
|
const COMMIT_VALUE_FLAGS = new Set(["m", "F", "C", "c", "t"]);
|
|
32
33
|
|
|
33
34
|
/** The parser for each guarded tool. */
|
|
34
|
-
export const PARSERS = { Bash: segmentsOf, PowerShell: powershellSegments };
|
|
35
|
+
export const PARSERS = { Bash: segmentsOf, PowerShell: powershellSegments, REPL: segmentsOf };
|
|
36
|
+
|
|
37
|
+
/** Run each extracted command in order, preserving async checks and naming the first REPL denial. */
|
|
38
|
+
export function guardCommands(call, check) {
|
|
39
|
+
const parse = PARSERS[call.tool_name];
|
|
40
|
+
if (!parse) return null;
|
|
41
|
+
if (call.tool_name !== "REPL") {
|
|
42
|
+
const command = call.tool_input?.command;
|
|
43
|
+
return typeof command === "string" ? check(command, parse) : null;
|
|
44
|
+
}
|
|
45
|
+
const commands = replCommands(call.tool_input?.code);
|
|
46
|
+
const notes = [];
|
|
47
|
+
function next(at) {
|
|
48
|
+
if (at === commands.length) return notes.length ? {
|
|
49
|
+
hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: notes.join(" ") },
|
|
50
|
+
} : null;
|
|
51
|
+
const command = commands[at];
|
|
52
|
+
const finish = (output) => {
|
|
53
|
+
const specific = output?.hookSpecificOutput;
|
|
54
|
+
if (specific?.permissionDecision === "deny") return {
|
|
55
|
+
...output,
|
|
56
|
+
hookSpecificOutput: { ...specific, permissionDecisionReason: `REPL command ${JSON.stringify(command)}: ${specific.permissionDecisionReason}` },
|
|
57
|
+
};
|
|
58
|
+
if (specific?.additionalContext) notes.push(specific.additionalContext);
|
|
59
|
+
return next(at + 1);
|
|
60
|
+
};
|
|
61
|
+
const output = check(command, parse);
|
|
62
|
+
return output instanceof Promise ? output.then(finish) : finish(output);
|
|
63
|
+
}
|
|
64
|
+
return next(0);
|
|
65
|
+
}
|
|
35
66
|
/** The directory a segment moves to, read the way each parser's shell reads it. */
|
|
36
67
|
const MOVES = new Map([[segmentsOf, cdTarget], [powershellSegments, locationTarget]]);
|
|
37
68
|
/** The options of `git worktree add` whose value is the next word. */
|
|
@@ -265,11 +296,12 @@ function folderAt(dir) {
|
|
|
265
296
|
return checkoutRootOf(dir) === null ? undefined : (worktreeRuleAt(dir)?.folder ?? null);
|
|
266
297
|
}
|
|
267
298
|
|
|
268
|
-
/** The verdict on one Bash or
|
|
299
|
+
/** The verdict on one Bash, PowerShell or REPL call. @returns the hook output, or null to let the call run with no message. */
|
|
269
300
|
export function decide(call) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
301
|
+
return guardCommands(call, (command, parse) => decideCommand(call, command, parse));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function decideCommand(call, command, parse) {
|
|
273
305
|
const cwd = call.cwd ?? process.cwd();
|
|
274
306
|
const root = checkoutRootOf(cwd);
|
|
275
307
|
if (!root || !existsSync(path.join(root, CONFIG_FILE))) return null;
|
|
@@ -487,3 +487,21 @@ test("a variable in a path of a command that adds no worktree, or in the worktre
|
|
|
487
487
|
assert.equal(decide(bash(ws.plain, "cd $K && git worktree add ../x")), null, "a repository with no qc.config.json is not guarded");
|
|
488
488
|
assert.equal(decide(bash(ws.adopted, `git -C ${plain} worktree add ../x`)), null);
|
|
489
489
|
});
|
|
490
|
+
|
|
491
|
+
test("REPL shell forms use the Bash rules and name the first refused command", (t) => {
|
|
492
|
+
const ws = workspace(t);
|
|
493
|
+
const repl = (code) => ({ ...bash(ws.adopted, "git status"), tool_name: "REPL", tool_input: { code } });
|
|
494
|
+
for (const code of ['$`git commit --no-verify`', '$("git commit --no-verify")',
|
|
495
|
+
'tools.Bash({ command: "git commit --no-verify" })', '$`git commit --no-verify`; $`broken']) {
|
|
496
|
+
const reason = reasonOf(decide(repl(code)));
|
|
497
|
+
assert.match(reason ?? "", /skips the git hooks/, code);
|
|
498
|
+
assert.match(reason, /git commit --no-verify/, code);
|
|
499
|
+
}
|
|
500
|
+
const first = reasonOf(decide(repl('$`git status`; $`git commit --no-verify`; $`git push --no-verify`')));
|
|
501
|
+
assert.match(first ?? "", /git commit --no-verify/);
|
|
502
|
+
assert.doesNotMatch(first, /git push --no-verify/);
|
|
503
|
+
for (const code of ['const answer = 42;', '$`git status`; $("git diff")']) {
|
|
504
|
+
assert.equal(decide(repl(code)), null, code);
|
|
505
|
+
}
|
|
506
|
+
assert.equal(decide({ ...repl(''), tool_input: { command: "git commit --no-verify" } }), null);
|
|
507
|
+
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// A pipeline that runs repository commands after the architecture checks pass.
|
|
2
2
|
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { repoFiles } from "./repo-files.mjs";
|
|
3
6
|
import { execFileSync } from "node:child_process";
|
|
4
7
|
import { spawnCommand as spawn } from "./spawn-command.mjs";
|
|
5
8
|
|
|
@@ -38,7 +41,7 @@ function commandWords(command) {
|
|
|
38
41
|
return words;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
export function changedFiles(root, base, sincePush, command = "qc e2e") {
|
|
44
|
+
export function changedFiles(root, base, sincePush, command = "qc e2e", affected = false) {
|
|
42
45
|
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
43
46
|
let ref = base;
|
|
44
47
|
if (sincePush) {
|
|
@@ -61,7 +64,7 @@ export function changedFiles(root, base, sincePush, command = "qc e2e") {
|
|
|
61
64
|
console.log(`WARN merge base with ${ref} is unavailable; running ${command} without file arguments`);
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
64
|
-
return git("diff", "--cached", "--name-only", "-z", "--no-renames", "--diff-filter=d", mergeBase, "--").split("\0").filter(Boolean);
|
|
67
|
+
return git("diff", "--cached", "--name-only", "-z", "--no-renames", ...(affected ? [] : ["--diff-filter=d"]), mergeBase, "--").split("\0").filter(Boolean);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export async function runCommand(root, command, files = []) {
|
|
@@ -79,13 +82,13 @@ export async function runCommand(root, command, files = []) {
|
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
export async function runCheckCommands(config, { sincePush = false } = {}) {
|
|
83
|
-
const { commands
|
|
85
|
+
export async function runCheckCommands(config, { sincePush = false, affected = false, base = config.check.base } = {}) {
|
|
86
|
+
const { commands } = config.check;
|
|
84
87
|
const related = sincePush ? config.check.sincePush ?? config.check.related : config.check.related;
|
|
85
|
-
if (related !== null) {
|
|
86
|
-
const files = changedFiles(config.root, base, sincePush, "related tests");
|
|
88
|
+
if (affected || related !== null) {
|
|
89
|
+
const files = changedFiles(config.root, base, sincePush, "related tests", affected);
|
|
87
90
|
if (files === null || files.length > 0) {
|
|
88
|
-
const code = await runCommand(config.root, related, files ?? []);
|
|
91
|
+
const code = related !== null ? await runCommand(config.root, related, files ?? []) : await affectedTests(config.root, files);
|
|
89
92
|
if (code !== 0) return code;
|
|
90
93
|
}
|
|
91
94
|
}
|
|
@@ -95,3 +98,97 @@ export async function runCheckCommands(config, { sincePush = false } = {}) {
|
|
|
95
98
|
}
|
|
96
99
|
return 0;
|
|
97
100
|
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async function affectedTests(root, changed) {
|
|
104
|
+
const selected = changed === null ? null : await importingTests(root, changed);
|
|
105
|
+
if (selected?.length && selected.join(" ").length < 24000) return runCommand(root, `"${process.execPath}" --test`, selected);
|
|
106
|
+
const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
|
|
107
|
+
if (!pkg.scripts?.test) { console.log("SKIP no test script"); return 0; }
|
|
108
|
+
const manager = existsSync(path.join(root, "pnpm-lock.yaml")) ? "pnpm" : existsSync(path.join(root, "yarn.lock")) ? "yarn" : "npm";
|
|
109
|
+
return runCommand(root, `${manager} test`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const extension = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
113
|
+
const isTest = (file) => /\.test\.(?:[cm]?[jt]s|[jt]sx)$/.test(file);
|
|
114
|
+
const inSuite = (file) => /^packages\/qc-harness\/src\/.+\.test\.mjs$/.test(file) || file === "evals/agents/run.test.mjs";
|
|
115
|
+
|
|
116
|
+
async function testGraph(root) {
|
|
117
|
+
const allFiles = await repoFiles(root);
|
|
118
|
+
const files = allFiles.filter((file) => extension.test(file));
|
|
119
|
+
const known = new Set(files), readers = new Map(), uncertainFiles = new Set();
|
|
120
|
+
const testTexts = new Map();
|
|
121
|
+
for (const file of files) {
|
|
122
|
+
const text = readFileSync(path.join(root, file), "utf8");
|
|
123
|
+
if (inSuite(file)) testTexts.set(file, text);
|
|
124
|
+
let uncertain = false;
|
|
125
|
+
const add = (value) => {
|
|
126
|
+
if (/\\|\$\{/.test(value)) { uncertain = true; return; }
|
|
127
|
+
if (value.startsWith(".")) {
|
|
128
|
+
const target = path.posix.normalize(path.posix.join(path.posix.dirname(file), value));
|
|
129
|
+
if (!known.has(target)) uncertain = true;
|
|
130
|
+
else readers.set(target, [...(readers.get(target) ?? []), file]);
|
|
131
|
+
} else if (!value.startsWith("node:")) uncertain = true;
|
|
132
|
+
};
|
|
133
|
+
// Retain original matches when comment stripping misreads regexes or nested templates.
|
|
134
|
+
const stripped = text.replace(/(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, (token) => token.startsWith("/") ? " " : token);
|
|
135
|
+
for (const source of new Set([text, stripped])) {
|
|
136
|
+
for (const match of source.matchAll(/\b(?:import|from)\s*(["'`])((?:\\[\s\S]|(?!\1)[^\\\r\n])*)\1/g)) add(match[2]);
|
|
137
|
+
for (const match of source.matchAll(/\b(?:import|require)\s*\(\s*/g)) {
|
|
138
|
+
const literal = /^(["'`])((?:\\[\s\S]|(?!\1)[^\\\r\n])*)\1\s*(?=[,)])/.exec(source.slice(match.index + match[0].length));
|
|
139
|
+
if (literal) add(literal[2]);
|
|
140
|
+
else uncertain = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (uncertain) uncertainFiles.add(file);
|
|
144
|
+
}
|
|
145
|
+
return { allFiles, files, known, readers, testTexts, uncertainFiles };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function coveringTests(file, { known, readers, testTexts }, namedTests) {
|
|
149
|
+
const seen = new Set([file]), queue = [file], covered = new Set();
|
|
150
|
+
const sibling = file.replace(extension, (suffix) => `.test${suffix}`);
|
|
151
|
+
if (known.has(sibling) && inSuite(sibling)) covered.add(sibling);
|
|
152
|
+
for (const next of queue) {
|
|
153
|
+
if (isTest(next) && inSuite(next)) covered.add(next);
|
|
154
|
+
const basename = path.posix.basename(next);
|
|
155
|
+
if (namedTests && !namedTests.has(basename)) {
|
|
156
|
+
const matches = new Set();
|
|
157
|
+
for (const [test, text] of testTexts) if (text.includes(basename)) matches.add(test);
|
|
158
|
+
namedTests.set(basename, matches);
|
|
159
|
+
}
|
|
160
|
+
for (const test of namedTests?.get(basename) ?? []) covered.add(test);
|
|
161
|
+
for (const reader of readers.get(next) ?? []) if (!seen.has(reader)) { seen.add(reader); queue.push(reader); }
|
|
162
|
+
}
|
|
163
|
+
return covered;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Certain coverage only: uncertain loaders belong to the conservative check runner. */
|
|
167
|
+
export async function testsCovering(root, paths) {
|
|
168
|
+
const graph = await testGraph(root);
|
|
169
|
+
const result = new Map();
|
|
170
|
+
for (const entry of paths) {
|
|
171
|
+
const file = path.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/$/, "");
|
|
172
|
+
const children = graph.allFiles.filter((candidate) => file === "." || candidate.startsWith(`${file}/`));
|
|
173
|
+
for (const target of children.length ? children : [file]) {
|
|
174
|
+
result.set(target, [...coveringTests(target, graph)].sort());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function importingTests(root, changed) {
|
|
181
|
+
if (changed.some((file) => !file.startsWith("packages/qc-harness/src/") || !extension.test(file) || !existsSync(path.join(root, file)))) return null;
|
|
182
|
+
try {
|
|
183
|
+
const graph = await testGraph(root);
|
|
184
|
+
const tests = new Set(graph.files.filter((file) => /^packages\/qc-harness\/src\/gates\/[^/]+\.test\.mjs$/.test(file)));
|
|
185
|
+
const namedTests = new Map();
|
|
186
|
+
// Unknown loaders can read any changed module; cover their readers too, or run the full suite.
|
|
187
|
+
for (const file of new Set([...changed, ...graph.uncertainFiles])) {
|
|
188
|
+
const covered = coveringTests(file, graph, namedTests);
|
|
189
|
+
if (!covered.size) return null;
|
|
190
|
+
for (const test of covered) tests.add(test);
|
|
191
|
+
}
|
|
192
|
+
return [...tests].sort();
|
|
193
|
+
} catch { return null; }
|
|
194
|
+
}
|