architecture-harness 0.29.4 → 0.29.6
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/lint-changed.mjs +2 -2
- package/src/cli/lint-changed.test.mjs +10 -0
- package/src/cli/pr-guard.mjs +2 -0
- package/src/cli/pr-guard.test.mjs +11 -3
- package/src/cli/tools.mjs +1 -1
- package/src/cli/tools.test.mjs +1 -1
- package/src/config.mjs +3 -1
package/package.json
CHANGED
package/src/cli/lint-changed.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
10
|
import { gitOut, gitStatusWithin } from "./git-read.mjs";
|
|
@@ -15,7 +15,7 @@ const CONFIG_NAMES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cj
|
|
|
15
15
|
/** True when a flat config sits in the folder of `file` or in any folder above it. */
|
|
16
16
|
function configAbove(file) {
|
|
17
17
|
for (let dir = path.dirname(file); ; dir = path.dirname(dir)) {
|
|
18
|
-
if (CONFIG_NAMES.some((name) =>
|
|
18
|
+
if (CONFIG_NAMES.some((name) => statSync(path.join(dir, name), { throwIfNoEntry: false })?.isFile())) return true;
|
|
19
19
|
if (path.dirname(dir) === dir) return false;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -116,6 +116,16 @@ test("a file with no ESLint config is skipped, and the lint passes", (t) => {
|
|
|
116
116
|
assert.doesNotMatch(nested.stdout, /lint skipped/);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
test("a directory named eslint.config.mjs above a changed file is skipped", (t) => {
|
|
120
|
+
const { root, qc } = repo(t);
|
|
121
|
+
rmSync(path.join(root, "eslint.config.mjs"));
|
|
122
|
+
mkdirSync(path.join(root, "eslint.config.mjs"));
|
|
123
|
+
writeFileSync(path.join(root, "src", "new.mjs"), "var fresh = 1;\nexport { fresh };\n");
|
|
124
|
+
const result = qc();
|
|
125
|
+
assert.equal(result.status, 0, result.stderr);
|
|
126
|
+
assert.match(result.stdout, /lint skipped 1 file\(s\) with no ESLint config/);
|
|
127
|
+
});
|
|
128
|
+
|
|
119
129
|
test("qc lint applies the baseline per file and rule up to the recorded count", (t) => {
|
|
120
130
|
const { root, qc } = repo(t);
|
|
121
131
|
writeFileSync(path.join(root, "eslint-suppressions.json"), JSON.stringify({ "src/old.mjs": { "no-var": { count: 1 } } }));
|
package/src/cli/pr-guard.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { checkoutRootOf } from "./checkout-root.mjs";
|
|
|
8
8
|
import { branchAt, originOf, repoOfSpelling } from "./git-read.mjs";
|
|
9
9
|
import { runGh } from "./gh-run.mjs";
|
|
10
10
|
import { readyProblems } from "./legs.mjs";
|
|
11
|
+
import { load } from "../config.mjs";
|
|
11
12
|
import { cdTarget, commandEnv, commandWords, segmentsOf } from "./shell-command.mjs";
|
|
12
13
|
|
|
13
14
|
const deny = (reason) => ({ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: reason } });
|
|
@@ -106,6 +107,7 @@ export function decidePr(call, { gh = runGh, problems = readyProblems } = {}) {
|
|
|
106
107
|
const options = { ...optionsOf(words.filter((_, i) => i !== group && i !== verbAt)), verb: words[verbAt] };
|
|
107
108
|
const root = checkoutRootOf(cwd);
|
|
108
109
|
if (!root || !existsSync(path.join(root, "qc.config.json"))) continue;
|
|
110
|
+
if (!load(root).ready.enforce) continue;
|
|
109
111
|
const origin = originOf(root);
|
|
110
112
|
if (!origin) continue;
|
|
111
113
|
const ghEnv = { ...settings(process.env), ...env, ...settings(commandEnv(segment)) };
|
|
@@ -15,7 +15,7 @@ function workspace(t) {
|
|
|
15
15
|
git("init", "-q");
|
|
16
16
|
git("checkout", "-qb", "feat/206-pr-guard");
|
|
17
17
|
git("remote", "add", "origin", "https://github.com/o/r.git");
|
|
18
|
-
writeFileSync(path.join(cwd, "qc.config.json"),
|
|
18
|
+
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ ready: { enforce: true } }));
|
|
19
19
|
return cwd;
|
|
20
20
|
}
|
|
21
21
|
const call = (cwd, command, extra = {}) => ({ cwd, tool_name: "Bash", hook_event_name: "PreToolUse", tool_input: { command }, ...extra });
|
|
@@ -29,6 +29,14 @@ test("create requires the controller and a draft", (t) => {
|
|
|
29
29
|
assert.equal(decidePr(call(cwd, "gh pr create --draft"), { gh: emptyGh }), null);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
test("the guard is off unless the repository sets ready.enforce", (t) => {
|
|
33
|
+
const cwd = workspace(t);
|
|
34
|
+
writeFileSync(path.join(cwd, "qc.config.json"), "{}");
|
|
35
|
+
for (const command of ["gh pr create", "gh pr ready 7"]) {
|
|
36
|
+
assert.equal(decidePr(call(cwd, command), { gh: () => assert.fail("no gh call when the guard is off") }), null);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
32
40
|
test("only Bash PreToolUse in a configured origin checkout is guarded", (t) => {
|
|
33
41
|
const cwd = workspace(t);
|
|
34
42
|
for (const command of ["echo 'gh pr create'", "gh pr view", "gh pr create -R other/repo", "GH_REPO=other/repo gh pr create"]) {
|
|
@@ -102,13 +110,13 @@ test("ready uses the ledger for the PR head even when the checkout head differs"
|
|
|
102
110
|
git("add", ".");
|
|
103
111
|
git("commit", "-qm", "base");
|
|
104
112
|
git("branch", "base");
|
|
105
|
-
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { platforms: ["linux", "windows"] } }));
|
|
113
|
+
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { enforce: true, platforms: ["linux", "windows"] } }));
|
|
106
114
|
writeFileSync(path.join(cwd, "risk.mjs"), "process.platform;\n");
|
|
107
115
|
git("add", ".");
|
|
108
116
|
git("commit", "-qm", "risk");
|
|
109
117
|
const head = git("rev-parse", "HEAD");
|
|
110
118
|
git("checkout", "-q", "base");
|
|
111
|
-
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { platforms: ["linux", "windows"] } }));
|
|
119
|
+
writeFileSync(path.join(cwd, "qc.config.json"), JSON.stringify({ check: { base: "base" }, ready: { enforce: true, platforms: ["linux", "windows"] } }));
|
|
112
120
|
const gh = () => JSON.stringify({ headRefOid: head });
|
|
113
121
|
assert.match(reason(decidePr(call(cwd, "gh pr ready 12"), { gh })), /linux, windows/);
|
|
114
122
|
appendLeg(cwd, { head, os: "linux", source: "local" });
|
package/src/cli/tools.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import path from "node:path";
|
|
|
6
6
|
const TOOLS = {
|
|
7
7
|
stack: { repo: "shawrylk/qc-stack", sha: "e34c270d92e3995b2e512f6eb690ea3cb0bc4699", bin: "qc-stack" },
|
|
8
8
|
screens: { repo: "shawrylk/qc-screens", sha: "886c303508f4406f397b2221b470115c3cb89589", bin: "qc-screens" },
|
|
9
|
-
"throwaway-db": { repo: "shawrylk/qc-throwaway-db", sha: "
|
|
9
|
+
"throwaway-db": { repo: "shawrylk/qc-throwaway-db", sha: "44c1a1189de893d1dbd181bbc2bea95cc6898dd3", bin: "qc-throwaway-db" },
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
/** Runs a pinned tool without passing its arguments through a shell. */
|
package/src/cli/tools.test.mjs
CHANGED
|
@@ -58,7 +58,7 @@ test("throwaway-db falls back to shell-free npx on POSIX and keeps the command s
|
|
|
58
58
|
const argv = ["--port", "auto", "--", "node", "script with spaces.mjs", "a&b"];
|
|
59
59
|
await runTool("throwaway-db", argv, options);
|
|
60
60
|
assert.deepEqual(calls, [["npx", ["--yes", "-p",
|
|
61
|
-
"github:shawrylk/qc-throwaway-db#
|
|
61
|
+
"github:shawrylk/qc-throwaway-db#44c1a1189de893d1dbd181bbc2bea95cc6898dd3", "qc-throwaway-db", ...argv,
|
|
62
62
|
], { stdio: "inherit", env: { PATH: "/bin", CUSTOM: "kept", npm_config_allow_git: "all" } }]]);
|
|
63
63
|
});
|
|
64
64
|
|
package/src/config.mjs
CHANGED
|
@@ -11,7 +11,8 @@ export const CONFIG_FILE = "qc.config.json";
|
|
|
11
11
|
export const defaults = {
|
|
12
12
|
commentWatch: true,
|
|
13
13
|
github: { configDirs: { shawrylk: "~/.config/gh-personal" } },
|
|
14
|
-
ready
|
|
14
|
+
// The PR guard (draft on create, platform legs before ready) runs only when a repository sets enforce.
|
|
15
|
+
ready: { enforce: false, platforms: ["linux"] },
|
|
15
16
|
checkpoint: { maxAgeMinutes: 30 },
|
|
16
17
|
post: { aiLabel: true },
|
|
17
18
|
ci: { requiredChecks: [] },
|
|
@@ -801,6 +802,7 @@ export function load(root = process.cwd()) {
|
|
|
801
802
|
config.ready.platforms.some((os) => !["linux", "windows", "darwin"].includes(os)) || new Set(config.ready.platforms).size !== config.ready.platforms.length) {
|
|
802
803
|
throw new TypeError("ready.platforms must be a non-empty array of distinct linux, windows and darwin platforms");
|
|
803
804
|
}
|
|
805
|
+
if (typeof config.ready.enforce !== "boolean") throw new TypeError("ready.enforce must be a boolean");
|
|
804
806
|
if (!isPlainObject(config.check)) throw new TypeError("check must be an object");
|
|
805
807
|
const { related, sincePush, e2e, commands, base } = config.check;
|
|
806
808
|
const command = (value) => typeof value === "string" && value.trim().length > 0;
|