architecture-harness 0.18.2 → 0.19.1

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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/src/cli/bash-command-guard.mjs +60 -11
  3. package/src/cli/bash-command-guard.test.mjs +66 -0
  4. package/src/cli/check-input.mjs +24 -0
  5. package/src/cli/check.mjs +2 -2
  6. package/src/cli/cli.test.mjs +50 -1
  7. package/src/cli/dispatch-guard.test.mjs +6 -23
  8. package/src/cli/dispatch-reminder.mjs +3 -3
  9. package/src/cli/dispatch-reminder.test.mjs +15 -10
  10. package/src/cli/dispatch.mjs +4 -3
  11. package/src/cli/dispatch.test.mjs +25 -17
  12. package/src/cli/explore-guard.mjs +11 -87
  13. package/src/cli/explore-guard.test.mjs +34 -97
  14. package/src/cli/explore-hint.mjs +3 -3
  15. package/src/cli/explore-hint.test.mjs +14 -5
  16. package/src/cli/init.mjs +12 -0
  17. package/src/cli/merge-guard.mjs +4 -0
  18. package/src/cli/merge-guard.test.mjs +21 -2
  19. package/src/cli/plugin-agents.test.mjs +4 -4
  20. package/src/cli/powershell-command.mjs +1 -1
  21. package/src/cli/qc.mjs +9 -4
  22. package/src/cli/workflow-hooks.test.mjs +1 -0
  23. package/src/cli/worktree-gate.mjs +117 -0
  24. package/src/cli/worktree-gate.test.mjs +152 -0
  25. package/src/cli/worktree-settings.mjs +27 -0
  26. package/src/cli/worktree.mjs +60 -21
  27. package/src/cli/worktree.test.mjs +106 -7
  28. package/src/config.mjs +19 -13
  29. package/src/eslint/preset.mjs +2 -2
  30. package/src/eslint/preset.test.mjs +4 -2
  31. package/src/gates/sql-identifiers.mjs +11 -3
  32. package/src/gates/sql-identifiers.test.mjs +39 -0
  33. package/templates/.jscpd.json +1 -0
  34. package/templates/docs/decisions.md +1 -0
  35. package/templates/docs/enforcement.md +10 -0
  36. package/templates/githooks/pre-commit +8 -6
@@ -2,7 +2,7 @@
2
2
  // Thresholds are imported, never restated — quality-thresholds.json is their one home.
3
3
 
4
4
  import qc from "./index.mjs";
5
- import { enabled, load, readerEntries, thresholds } from "../config.mjs";
5
+ import { enabled, ignoresOf, load, readerEntries, thresholds } from "../config.mjs";
6
6
  import { literalRegistries } from "../registries.mjs";
7
7
 
8
8
  /**
@@ -129,7 +129,7 @@ export function preset(options = {}) {
129
129
  const { tseslint, boundaries, sonarjs } = options.plugins ?? {};
130
130
 
131
131
  // No file carries its own exemption: a rule is switched off in config, where a reviewer sees it.
132
- const blocks = [{ ignores: config.ignores }, { linterOptions: { noInlineConfig: true, reportUnusedDisableDirectives: "error" } }];
132
+ const blocks = [{ ignores: ignoresOf(config) }, { linterOptions: { noInlineConfig: true, reportUnusedDisableDirectives: "error" } }];
133
133
 
134
134
  const base = {
135
135
  files: ["**/*.{ts,tsx,mjs}"],
@@ -74,9 +74,11 @@ test("the tooling block turns every qc rule off, so a gate can name what it bans
74
74
  }
75
75
  });
76
76
 
77
- test("ignores come from the config", () => {
77
+ test("ignores come from the config, and a repository list of its own still skips the worktree folder", () => {
78
78
  const blocks = preset({ config: config({ ignores: ["**/generated/**"] }) });
79
- assert.deepEqual(blocks[0].ignores, ["**/generated/**"]);
79
+ assert.deepEqual(blocks[0].ignores, ["**/generated/**", ".worktree/**"]);
80
+ const moved = preset({ config: config({ ignores: [], worktree: { dir: "trees/" } }) });
81
+ assert.deepEqual(moved[0].ignores, ["trees/**"]);
80
82
  });
81
83
 
82
84
  test("the layer block is emitted only when a boundaries plugin is supplied", () => {
@@ -128,11 +128,19 @@ const EXEMPT = /\/\/\s*tenant-predicate:\s*exempt\s*—\s*(.+)/;
128
128
  // A migration file is `<sequence>_<slug>.sql`; the slug names the feature that owns it.
129
129
  const MIGRATION_FILE = /^\d+_(.+)\.sql$/;
130
130
 
131
+ // One pass, left to right: a template literal, a quoted string with escapes, or a comment. A comment
132
+ // is matched to be skipped, so an apostrophe in one opens no string.
133
+ const LITERAL = /`([^`]*)`|'((?:[^'\\\n]|\\.)*)'|"((?:[^"\\\n]|\\.)*)"|\/\/[^\n]*|\/\*[\s\S]*?\*\//g;
134
+ const TEMPLATE_STATEMENT = /\b(select|insert into|update|delete from)\b/i;
135
+ // A quoted string needs the whole shape: a UI label such as "select a folder" opens with a keyword too.
136
+ const QUOTED_STATEMENT = /\bselect\b[^]*\bfrom\b|\binsert\s+into\b|\bupdate\b[^]*\bset\b|\bdelete\s+from\b/i;
137
+
131
138
  function statements(source) {
132
139
  const found = [];
133
- for (const match of source.matchAll(/`([^`]*)`/g)) {
134
- const body = match[1];
135
- if (!/\b(select|insert into|update|delete from)\b/i.test(body)) continue;
140
+ for (const match of source.matchAll(LITERAL)) {
141
+ const body = match[1] ?? match[2] ?? match[3];
142
+ if (body === undefined) continue;
143
+ if (!(match[1] === undefined ? QUOTED_STATEMENT : TEMPLATE_STATEMENT).test(body)) continue;
136
144
  const preamble = source.slice(Math.max(0, match.index - 400), match.index);
137
145
  const lastLines = preamble.split("\n").slice(-4).join("\n");
138
146
  found.push({
@@ -6,6 +6,7 @@ import {
6
6
  declaredColumns,
7
7
  migrationNames,
8
8
  schemaTables,
9
+ sqlStatements,
9
10
  tableOwners,
10
11
  usedIdentifiers,
11
12
  } from "./sql-identifiers.mjs";
@@ -189,6 +190,44 @@ test("a migration filename with an underscore names a hyphenated feature", () =>
189
190
  assert.equal(owners.get("projects"), "identity-tenancy");
190
191
  });
191
192
 
193
+ const crossFeature = (source) => {
194
+ const owners = tableOwners([{ file: "0002_projects.sql", sql: ddl }]);
195
+ return checkSqlIdentifiers(declaredColumns([ddl]), [{ path: "r.ts", source, feature: "pins" }], owners);
196
+ };
197
+
198
+ test("a double-quoted statement reading another feature's table is named", () => {
199
+ const problems = crossFeature('const q = "select id from projects where tenant_id = $1";');
200
+ assert.deepEqual(problems.map((problem) => problem.rule), ["cross-feature-table"]);
201
+ });
202
+
203
+ test("a single-quoted statement reading another feature's table is named", () => {
204
+ const problems = crossFeature("const q = 'select id from projects where tenant_id = $1';");
205
+ assert.deepEqual(problems.map((problem) => problem.rule), ["cross-feature-table"]);
206
+ });
207
+
208
+ test("an escaped quote inside a quoted statement does not end it", () => {
209
+ const problems = crossFeature(`const q = "select id from projects where code = \\"x\\" and tenant_id = $1";`);
210
+ assert.deepEqual(problems.map((problem) => problem.rule), ["cross-feature-table"]);
211
+ });
212
+
213
+ test("a UI label that starts with a SQL keyword is not a statement", () => {
214
+ const source = `const label = "select a folder"; const hint = 'update your profile'; const cta = "delete the folder";`;
215
+ assert.deepEqual(sqlStatements(source), []);
216
+ assert.deepEqual(crossFeature(source), []);
217
+ });
218
+
219
+ test("an apostrophe in a comment opens no string", () => {
220
+ const source = `// don't read it
221
+ const q = "select id from projects where tenant_id = $1";`;
222
+ assert.equal(sqlStatements(source).length, 1);
223
+ });
224
+
225
+ test("the exemption comment above a quoted statement is kept", () => {
226
+ const source = `// tenant-predicate: exempt — a share is found by its secret
227
+ const q = "select id from projects where code = $1";`;
228
+ assert.equal(sqlStatements(source)[0].exemption, "a share is found by its secret");
229
+ });
230
+
192
231
  test("a recursive common table expression binds its own name", () => {
193
232
  const tables = declaredColumns([ddl]);
194
233
  const source = resource(
@@ -5,6 +5,7 @@
5
5
  "reporters": ["console"],
6
6
  "ignore": [
7
7
  "**/node_modules/**",
8
+ "**/.worktree/**",
8
9
  "**/dist/**",
9
10
  "**/*.test.*",
10
11
  "**/*.generated.*",
@@ -70,3 +70,4 @@ portable ones; delete any that do not apply and add your own rather than renumbe
70
70
  | QC-007 | A rule that cannot name its check is deleted or converted into one | `docs/enforcement.md` carries the map |
71
71
  | QC-008 | A change is rewritten in place, as if it had always been that way | No supersession trail, no deprecation note, no "what this replaces". The repository states what is true now; git holds the history |
72
72
  | QC-010 | Headless-first command and saga architecture | Every multi-step workflow is an executable pipeline or command callable headlessly without a browser. UI components are thin presenters invoking these workflows. Headless tests verify state transitions, idempotency, and compensations |
73
+ | QC-015 | A worktree lives in `.worktree/<name>` inside the main checkout, and a merged pull request leaves no worktree and no branch | `qc worktree add` makes each worktree there, and git ignores the folder. A `git worktree add` to another path is refused. A turn that merged a pull request ends only after the worktree, the local branch, and the remote branch of its head are gone. A merged pull request at the branch tip proves a squash merge. `worktree.enforce: false` turns the hooks off. A test run inside `.worktree/<name>/` can resolve a missing dependency from the `node_modules` of the main checkout, which hides it, so CI in a clean checkout is the dependency check |
@@ -72,6 +72,16 @@ recorded.
72
72
  | The controller edits only its own paths | `controller-guard.mjs` |
73
73
  | A plan task names its files, a test step, and a commit step, within the budget | `qc plan-check`, and `plan-stop.mjs` |
74
74
 
75
+ ## Worktrees — QC-015
76
+
77
+ These hooks are on wherever `qc.config.json` is. `"worktree": { "enforce": false }` turns them off.
78
+
79
+ | Rule | Check |
80
+ |---|---|
81
+ | A worktree is one folder directly under `worktree.dir` of the main checkout | `bash-command-guard.mjs`, on `PreToolUse` of `Bash` and `PowerShell` |
82
+ | A pull request this session merged leaves no worktree, local branch, or remote branch on its head | `worktree-gate.mjs`, on `Stop`, from the merge record of `merge-guard.mjs` |
83
+ | A squash-merged branch is deleted | `qc worktree remove`, on a merged pull request whose head is the branch at its tip |
84
+
75
85
  ## File length
76
86
 
77
87
  A block is one file, and the gate is `filelength` in `quality-thresholds.json`. Blanks and comments
@@ -7,12 +7,14 @@ set -euo pipefail
7
7
  # Runs before the extension filter below: a work order's own branch is checked regardless of
8
8
  # what kind of file it touches, so a commit of .tf/.yml/.md files is covered too.
9
9
  npx qc work-order-check || exit 1
10
- STAGED=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|mjs)$' || true)
11
- [ -z "$STAGED" ] && exit 0
10
+ # The staged list is NUL-separated in a file, never in an argument: a large merge commit would
11
+ # pass the command-line limit of npx.cmd on Windows (8191 characters).
12
+ STAGED=$(mktemp)
13
+ trap 'rm -f "$STAGED"' EXIT
14
+ git diff --cached --name-only -z --diff-filter=ACM | grep -zE '\.(ts|tsx|mjs)$' > "$STAGED" || true
15
+ [ -s "$STAGED" ] || exit 0
12
16
  # `--no-warn-ignored`: a staged file the config ignores is a decision, not a finding, and
13
17
  # without it a generated file turns "I ignored that" into a warning that fails the gate.
14
- npx eslint $STAGED --max-warnings 0 --no-warn-ignored
18
+ xargs -0 -n 20 npx eslint --max-warnings 0 --no-warn-ignored < "$STAGED"
15
19
  npx tsc -b --pretty false
16
- for file in $STAGED; do
17
- npx qc check "$file"
18
- done
20
+ npx qc check --files-from - < "$STAGED"