architecture-harness 0.16.0 → 0.18.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/budget-counter.mjs +25 -4
- package/src/cli/budget-guard.mjs +73 -4
- package/src/cli/budget-guard.test.mjs +111 -0
- package/src/cli/budget.mjs +3 -2
- 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/context-signal.mjs +92 -0
- package/src/cli/context-signal.test.mjs +99 -0
- 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 -4
- package/src/cli/dispatch-guard.test.mjs +5 -6
- package/src/cli/dispatch-reminder.mjs +19 -11
- package/src/cli/dispatch-reminder.test.mjs +32 -0
- package/src/cli/dispatch.mjs +23 -2
- package/src/cli/dispatch.test.mjs +39 -1
- package/src/cli/doctor.mjs +2 -1
- package/src/cli/explore-guard.mjs +2 -2
- package/src/cli/explore-hint.mjs +67 -7
- package/src/cli/explore-hint.test.mjs +104 -4
- 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/handoff-note.mjs +69 -0
- package/src/cli/handoff-note.test.mjs +71 -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 +138 -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 +105 -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 +22 -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 +266 -0
- package/src/cli/report-stop.test.mjs +471 -0
- package/src/cli/shell-command.mjs +81 -6
- package/src/cli/shell-command.test.mjs +101 -1
- package/src/cli/task-gate.mjs +179 -0
- package/src/cli/task-gate.test.mjs +507 -0
- package/src/cli/tokens.mjs +239 -0
- package/src/cli/tokens.test.mjs +286 -0
- package/src/cli/transcript-usage.mjs +135 -0
- package/src/cli/transcript-usage.test.mjs +129 -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 +99 -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
|
@@ -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
|
+
});
|
package/src/cli/check.mjs
CHANGED
|
@@ -15,13 +15,22 @@ import {
|
|
|
15
15
|
sqlStatements,
|
|
16
16
|
tableOwners,
|
|
17
17
|
} from "../gates/sql-identifiers.mjs";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
aliasMap,
|
|
20
|
+
checkExemptHelperCalls,
|
|
21
|
+
checkTenantPredicate,
|
|
22
|
+
exemptHelperCalls,
|
|
23
|
+
exemptions,
|
|
24
|
+
unresolvedHelperImports,
|
|
25
|
+
} from "../gates/tenant-predicate.mjs";
|
|
19
26
|
import { checkClaimedRequirements } from "../gates/claimed-requirements.mjs";
|
|
20
27
|
import { allowedPublicRoutes, checkPublicRoutes, declaredPublicRoutes } from "../gates/public-routes.mjs";
|
|
21
28
|
import { calledInternalRoutes, checkInternalRoutes, declaredInternalRoutes } from "../gates/internal-routes.mjs";
|
|
22
29
|
import { checkHeadlessPipelines } from "../gates/headless-sagas.mjs";
|
|
30
|
+
import { checkSagaKey } from "../gates/saga-key.mjs";
|
|
23
31
|
import { checkFeatureCommands, governedFeatures } from "../gates/feature-cli.mjs";
|
|
24
32
|
import { checkSagaTests, declaredSagas } from "../gates/saga-tests.mjs";
|
|
33
|
+
import { checkTenantIsolationTests, tenantFeatures } from "../gates/tenant-isolation-test.mjs";
|
|
25
34
|
import { checkGatesAreTested } from "../gates/gate-tests.mjs";
|
|
26
35
|
import { checkAuditAppendOnly } from "../gates/audit-append-only.mjs";
|
|
27
36
|
import { checkEnforcementMap } from "../gates/enforcement-map.mjs";
|
|
@@ -33,15 +42,20 @@ import { checkAdrFormat } from "../gates/adr-format.mjs";
|
|
|
33
42
|
import { checkConfigFloor } from "../gates/config-floor.mjs";
|
|
34
43
|
import { defaults } from "../config.mjs";
|
|
35
44
|
import { rules as lintRules } from "../eslint/index.mjs";
|
|
36
|
-
import { adrLog, enabled, readerEntries, thresholds } from "../config.mjs";
|
|
45
|
+
import { adrLog, enabled, readerEntries, requiredHooks, thresholds } from "../config.mjs";
|
|
37
46
|
import { checkRegistryReaders } from "../gates/registry-readers.mjs";
|
|
38
47
|
import { checkMigrationNumbers } from "../gates/migration-numbers.mjs";
|
|
39
48
|
import { checkRegistryLiteral } from "../gates/registry-literal.mjs";
|
|
49
|
+
import { literalRegistries } from "../registries.mjs";
|
|
40
50
|
import { checkThresholdRatchet } from "../gates/threshold-ratchet.mjs";
|
|
41
51
|
import { checkParity, placeholderSlices } from "../gates/parity.mjs";
|
|
42
52
|
import { checkIntegrationImports } from "../gates/integration-imports.mjs";
|
|
43
53
|
import { checkClosedSetWriters, matchedKeys } from "../gates/closed-set-writers.mjs";
|
|
44
54
|
import { checkDocClaims, parseDocClaims } from "../gates/doc-claims.mjs";
|
|
55
|
+
import { checkContractIdempotency, checkLedgerGrowth } from "../gates/contract-idempotency.mjs";
|
|
56
|
+
import { contractHistory } from "./contract-history.mjs";
|
|
57
|
+
import { contractOperations } from "../gates/contract-operations.mjs";
|
|
58
|
+
import { checkContractRoutes, declaredTriggerRoutes } from "../gates/contract-routes.mjs";
|
|
45
59
|
import { ratchetInputs } from "./registry-history.mjs";
|
|
46
60
|
import { hookDrift } from "./git-hooks.mjs";
|
|
47
61
|
import { repoFiles } from "./repo-files.mjs";
|
|
@@ -50,6 +64,8 @@ import { repoFiles } from "./repo-files.mjs";
|
|
|
50
64
|
const SKIP = /node_modules|\/dist\/|\.test\.[cm]?[jt]sx?$/;
|
|
51
65
|
const BUILD_OUTPUT = /node_modules|\/dist\//;
|
|
52
66
|
const TEST_FILE = /\.test\.[cm]?[jt]sx?$/;
|
|
67
|
+
// A file with none of these cannot import an exempt helper, alias it, or re-export it.
|
|
68
|
+
const MODULE_LINKS = /\bimport\b|\bexport\s*(?:\{|\*|default\b|(?:const|let|var)\b)/;
|
|
53
69
|
const SOURCE_EXTENSION = /\.([cm]?[jt]sx?)$/;
|
|
54
70
|
const CITABLE_EXTENSION = /\.(tsx?|mjs|md)$/;
|
|
55
71
|
const INFRA_EXTENSIONS = [".tf", ".sh", ".tfvars", ".tfvars.example", ".hcl", ".hcl.example"];
|
|
@@ -308,13 +324,30 @@ async function sqlAgreement(config, tree, taken, lines) {
|
|
|
308
324
|
if (declared.length > 0) lines.push(`OK schema ${declared.length} table(s), ${columns} column(s) in schema files, each named by a migration`);
|
|
309
325
|
}
|
|
310
326
|
if (enabled(config.gates, "tenant-predicate")) {
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
(
|
|
327
|
+
// A default also listed in `extraExemptHelpers` is one helper, so each call is judged once.
|
|
328
|
+
const helpers = [...config.tenantPredicate.exemptHelpers, ...config.tenantPredicate.extraExemptHelpers].filter(
|
|
329
|
+
(helper, at, all) => all.findIndex((first) => first.module === helper.module && first.name === helper.name) === at,
|
|
314
330
|
);
|
|
315
|
-
|
|
331
|
+
// A file with no import and no export list cannot reach a helper, and cannot be a barrel: the gate
|
|
332
|
+
// treats it as read, so a barrel that re-exports it is not an untraceable one. A helper's own
|
|
333
|
+
// module is always parsed, since it may export its helper under another name, or as its default.
|
|
334
|
+
const scanned = await sourceFiles(config, tree);
|
|
335
|
+
const isCaller = (file) =>
|
|
336
|
+
!TEST_FILE.test(file.path) && (MODULE_LINKS.test(file.contents) || helpers.some((helper) => helper.module === file.path));
|
|
337
|
+
const callers = scanned.filter(isCaller);
|
|
338
|
+
const leaves = new Set(scanned.filter((file) => !isCaller(file)).map((file) => file.path));
|
|
339
|
+
const tsconfig = posix(config.tenantPredicate.tsconfig);
|
|
340
|
+
const tsconfigText = tsconfig && tree.isFile(tsconfig) ? await read(path.join(config.root, tsconfig)) : null;
|
|
341
|
+
let aliases = [];
|
|
342
|
+
try {
|
|
343
|
+
aliases = tsconfigText === null ? [] : aliasMap(tsconfigText, path.posix.dirname(tsconfig).replace(/^\.$/, ""));
|
|
344
|
+
} catch (error) {
|
|
345
|
+
problems.push({ path: tsconfig, rule: "unresolved-helper-import", detail: `${error.message}, so no alias resolves` });
|
|
346
|
+
}
|
|
347
|
+
const helperOptions = { column: config.tenant.sqlColumn, identifier: config.tenant.column, aliases, leaves };
|
|
316
348
|
problems.push(
|
|
317
349
|
...checkTenantPredicate(scoped, owned, tenantOptions),
|
|
350
|
+
...unresolvedHelperImports(callers, helpers, helperOptions),
|
|
318
351
|
...checkExemptHelperCalls(callers, helpers, helperOptions),
|
|
319
352
|
);
|
|
320
353
|
const calls = exemptHelperCalls(callers, helpers, helperOptions).length;
|
|
@@ -466,6 +499,62 @@ async function docClaims(config, lines) {
|
|
|
466
499
|
return problems;
|
|
467
500
|
}
|
|
468
501
|
|
|
502
|
+
/** Every write of the composed contract names its idempotency key, or sits in the ledger. */
|
|
503
|
+
async function contractIdempotency(config, lines) {
|
|
504
|
+
const { contract } = config;
|
|
505
|
+
const { legacy, exemptDeleteById } = config.contractIdempotency;
|
|
506
|
+
const text = await read(path.join(config.root, contract));
|
|
507
|
+
if (text === null) return [];
|
|
508
|
+
let operations;
|
|
509
|
+
try {
|
|
510
|
+
operations = await contractOperations(text);
|
|
511
|
+
} catch (error) {
|
|
512
|
+
const rule = error.code === "CONTRACT_PEER_MISSING" ? "contract-reader-unavailable" : "unreadable-contract";
|
|
513
|
+
return [{ path: contract, rule, detail: error.message }];
|
|
514
|
+
}
|
|
515
|
+
const ledgerText = await read(path.join(config.root, legacy));
|
|
516
|
+
const ledger = parsedJson(ledgerText);
|
|
517
|
+
if (ledgerText !== null && !(Array.isArray(ledger) && ledger.every((id) => typeof id === "string"))) {
|
|
518
|
+
return [{ path: legacy, rule: "unreadable-ledger", detail: "the ledger is not a JSON array of operation-id strings" }];
|
|
519
|
+
}
|
|
520
|
+
const fields = config.idempotency.keys;
|
|
521
|
+
const problems = checkContractIdempotency(operations, ledger ?? [], { fields, exemptDeleteById, contract, ledger: legacy });
|
|
522
|
+
lines.push(`OK idempotency ${operations.length} operation(s), each write names its key or sits in the ${(ledger ?? []).length}-entry ledger`);
|
|
523
|
+
const history = await contractHistory(config.root, { base: config.ratchet.base, contract, legacy, fields, exemptDeleteById });
|
|
524
|
+
if (history.skip) {
|
|
525
|
+
lines.push("NOTE idempotency ledger growth skipped: " + history.skip);
|
|
526
|
+
} else if (history.unreadable) {
|
|
527
|
+
problems.push({ path: contract, rule: "unreadable-base-contract", detail: history.unreadable });
|
|
528
|
+
} else {
|
|
529
|
+
problems.push(...checkLedgerGrowth(ledger ?? [], history, operations, { ledger: legacy }));
|
|
530
|
+
}
|
|
531
|
+
return problems;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** A feature serves exactly the operations the composed contract lists. */
|
|
535
|
+
async function contractRouteAgreement(config, routes, lines) {
|
|
536
|
+
const { contract } = config;
|
|
537
|
+
const text = await read(path.join(config.root, contract));
|
|
538
|
+
if (text === null) return [];
|
|
539
|
+
let operations;
|
|
540
|
+
try {
|
|
541
|
+
operations = await contractOperations(text);
|
|
542
|
+
} catch (error) {
|
|
543
|
+
const rule = error.code === "CONTRACT_PEER_MISSING" ? "contract-reader-unavailable" : "unreadable-contract";
|
|
544
|
+
return [{ path: contract, rule, detail: error.message }];
|
|
545
|
+
}
|
|
546
|
+
const { exempt } = config.contractRoutes;
|
|
547
|
+
if (!Array.isArray(exempt)) {
|
|
548
|
+
return [{ path: "qc.config.json", rule: "malformed-exemption", detail: "contractRoutes.exempt must be an array of { method, path, why }" }];
|
|
549
|
+
}
|
|
550
|
+
const served = declaredTriggerRoutes(routes);
|
|
551
|
+
const problems = checkContractRoutes(served, operations, { contract, exempt });
|
|
552
|
+
if (problems.length === 0) {
|
|
553
|
+
lines.push(`OK contract ${served.length} route(s) and ${operations.length} operation(s) agree by method and path`);
|
|
554
|
+
}
|
|
555
|
+
return problems;
|
|
556
|
+
}
|
|
557
|
+
|
|
469
558
|
/**
|
|
470
559
|
* @param {object} config
|
|
471
560
|
* @param {string | string[]} [only] files to check on the fast path a hook takes; none is the full check
|
|
@@ -513,6 +602,12 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
513
602
|
if (enabled(config.gates, "headless-sagas")) {
|
|
514
603
|
problems.push(...checkHeadlessPipelines(contents, { block: config.saga.headlessBlock, viewModules: config.saga.viewModules }));
|
|
515
604
|
}
|
|
605
|
+
if (enabled(config.gates, "saga-key")) {
|
|
606
|
+
const rel = relativeTo(config.root);
|
|
607
|
+
const sources = contents.filter((file) => !TEST_FILE.test(file.path)).map((file) => ({ ...file, path: rel(file.path) }));
|
|
608
|
+
const { volatile, ledgerKey, throwawayLedgers } = config.idempotency;
|
|
609
|
+
problems.push(...checkSagaKey(sources, { runners: config.sagaKey.runners, key: config.sagaKey.key, volatile, ledgerKey, throwawayLedgers }));
|
|
610
|
+
}
|
|
516
611
|
if (enabled(config.gates, "feature-cli") && !perFile) {
|
|
517
612
|
const rel = relativeTo(config.root);
|
|
518
613
|
const relativeFeatures = features.map((feature) => ({ ...feature, feature: rel(feature.feature) }));
|
|
@@ -572,7 +667,7 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
572
667
|
}
|
|
573
668
|
|
|
574
669
|
if (enabled(config.gates, "registry-readers")) {
|
|
575
|
-
const entries =
|
|
670
|
+
const entries = literalRegistries(config).list.flatMap((registry) => readerEntries(registry.entries));
|
|
576
671
|
const readers = [...new Set(entries.flatMap((entry) => entry.readers))];
|
|
577
672
|
const sources = new Map(await Promise.all(readers.map(async (reader) => [reader, await read(path.join(config.root, reader))])));
|
|
578
673
|
problems.push(...checkRegistryReaders(entries, sources));
|
|
@@ -583,7 +678,9 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
583
678
|
const docs = await readEach(config.root, tree.under(config.docs.root).filter((file) => file.endsWith(".md")));
|
|
584
679
|
const libraries = parsedJson(await read(path.join(config.root, config.versions)))?.libraries ?? {};
|
|
585
680
|
const exempt = config.registryLiteral.exempt ?? adrLog(config);
|
|
586
|
-
|
|
681
|
+
const registries = literalRegistries(config);
|
|
682
|
+
problems.push(...checkRegistryLiteral(docs, { thresholds: thresholds(config), libraries, exempt, registries: registries.list }));
|
|
683
|
+
problems.push(...registries.problems);
|
|
587
684
|
if (docs.length > 0) lines.push(`OK literals ${docs.length} doc(s) carry a token, never a figure a registry owns`);
|
|
588
685
|
}
|
|
589
686
|
|
|
@@ -628,6 +725,19 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
628
725
|
lines.push(`OK sagas ${sagas.length} workflow(s), each named by a test that runs without a view`);
|
|
629
726
|
}
|
|
630
727
|
|
|
728
|
+
if (enabled(config.gates, "tenant-isolation-test")) {
|
|
729
|
+
const roots = config.featureRoots.map(posix);
|
|
730
|
+
const features = (await Promise.all(roots.map((root) => sourceFiles(config, tree, root)))).flat();
|
|
731
|
+
const isolation = {
|
|
732
|
+
helper: config.tenant.isolationHelper,
|
|
733
|
+
featureRoots: roots,
|
|
734
|
+
tableFactory: config.tenant.tableFactory,
|
|
735
|
+
column: config.tenant.column,
|
|
736
|
+
};
|
|
737
|
+
problems.push(...checkTenantIsolationTests(features, isolation));
|
|
738
|
+
lines.push(`OK tenancy ${tenantFeatures(features, isolation).length} feature(s) with tenant tables, each with a two-tenant test`);
|
|
739
|
+
}
|
|
740
|
+
|
|
631
741
|
if (enabled(config.gates, "gate-tests")) {
|
|
632
742
|
const own = await sourceFiles(config, tree, config.paths.checks);
|
|
633
743
|
problems.push(
|
|
@@ -669,6 +779,9 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
669
779
|
if (enabled(config.gates, "headless-sagas")) {
|
|
670
780
|
lines.push("OK headless pipelines are headless and triggers remain thin presenters");
|
|
671
781
|
}
|
|
782
|
+
if (enabled(config.gates, "saga-key")) {
|
|
783
|
+
lines.push("OK saga-key no saga runner takes a key minted at the call");
|
|
784
|
+
}
|
|
672
785
|
if (enabled(config.gates, "frontend-boundaries")) {
|
|
673
786
|
const platform = await platformFiles(config, tree);
|
|
674
787
|
if (platform.length > 0) {
|
|
@@ -704,7 +817,7 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
704
817
|
if (enabled(config.gates, "config-floor")) {
|
|
705
818
|
problems.push(...checkConfigFloor(defaults, config, { exemptions: config.floor.exemptions }));
|
|
706
819
|
lines.push("OK floor every check the kit ships on is in force, or names the decision that switched it off");
|
|
707
|
-
const hooks = hookDrift(config.root, config
|
|
820
|
+
const hooks = hookDrift(config.root, requiredHooks(config));
|
|
708
821
|
problems.push(...hooks.problems);
|
|
709
822
|
lines.push("OK hooks each git hook makes the calls hooks.required names");
|
|
710
823
|
for (const note of hooks.notes) lines.push(`NOTE hooks ${note}`);
|
|
@@ -756,5 +869,13 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
|
|
|
756
869
|
problems.push(...(await docClaims(config, lines)));
|
|
757
870
|
}
|
|
758
871
|
|
|
872
|
+
if (enabled(config.gates, "contract-idempotency")) {
|
|
873
|
+
problems.push(...(await contractIdempotency(config, lines)));
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
if (enabled(config.gates, "contract-routes")) {
|
|
877
|
+
problems.push(...(await contractRouteAgreement(config, routes, lines)));
|
|
878
|
+
}
|
|
879
|
+
|
|
759
880
|
return { problems, lines };
|
|
760
881
|
}
|
package/src/cli/cli.test.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { execFileSync } from "node:child_process";
|
|
|
4
4
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { load } from "../config.mjs";
|
|
7
|
+
import { load, requiredHooks } from "../config.mjs";
|
|
8
|
+
import { hookDrift } from "./git-hooks.mjs";
|
|
8
9
|
import { runInit } from "./init.mjs";
|
|
9
10
|
import { installHooks } from "./install-hooks.mjs";
|
|
10
11
|
import { runCheck } from "./check.mjs";
|
|
@@ -29,7 +30,7 @@ const quiet = (run) => {
|
|
|
29
30
|
test("init writes the documents the gates read", async () => {
|
|
30
31
|
const dir = repo();
|
|
31
32
|
await quiet(() => runInit(load(dir)));
|
|
32
|
-
for (const file of ["qc.config.json", "docs/decisions.md", "docs/enforcement.md", "docs/pagination.md", ".githooks/pre-commit", ".githooks/pre-push"]) {
|
|
33
|
+
for (const file of ["qc.config.json", "docs/decisions.md", "docs/enforcement.md", "docs/pagination.md", ".githooks/pre-commit", ".githooks/commit-msg", ".githooks/pre-push"]) {
|
|
33
34
|
assert.ok(existsSync(path.join(dir, file)), `${file} is missing`);
|
|
34
35
|
}
|
|
35
36
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -241,3 +242,215 @@ test("a clean mirror run names every root it judged", async () => {
|
|
|
241
242
|
assert.ok(line?.includes("frontend/tests") && line.includes("backend/tests"), `mirror line: ${line}`);
|
|
242
243
|
rmSync(dir, { recursive: true, force: true });
|
|
243
244
|
});
|
|
245
|
+
|
|
246
|
+
test("a fresh init repository with the default config passes the hooks check", async () => {
|
|
247
|
+
const dir = repo();
|
|
248
|
+
await quiet(() => runInit(load(dir)));
|
|
249
|
+
const config = load(dir);
|
|
250
|
+
assert.deepEqual(hookDrift(dir, requiredHooks(config)).problems, []);
|
|
251
|
+
rmSync(dir, { recursive: true, force: true });
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("a config with only extraExemptHelpers checks the kit defaults and the extra helper", async () => {
|
|
255
|
+
const dir = repo();
|
|
256
|
+
await quiet(() => runInit(load(dir)));
|
|
257
|
+
const config = JSON.parse(readFileSync(path.join(dir, "qc.config.json"), "utf8"));
|
|
258
|
+
config.tenantPredicate = {
|
|
259
|
+
extraExemptHelpers: [{ module: "backend/src/application/sql/bulk.ts", name: "insertMany", argument: 1 }],
|
|
260
|
+
};
|
|
261
|
+
write(dir, {
|
|
262
|
+
"qc.config.json": JSON.stringify(config),
|
|
263
|
+
"backend/src/application/orders.ts": [
|
|
264
|
+
'import { insertReturning } from "./sql/crud";',
|
|
265
|
+
'import { insertMany } from "./sql/bulk";',
|
|
266
|
+
"export function place(tx, v) {",
|
|
267
|
+
' insertReturning(tx, "orders", ["id"], v);',
|
|
268
|
+
' insertMany(tx, ["id"]);',
|
|
269
|
+
"}",
|
|
270
|
+
"",
|
|
271
|
+
].join("\n"),
|
|
272
|
+
});
|
|
273
|
+
const { problems } = await runCheck(load(dir));
|
|
274
|
+
const helperCalls = problems.filter((problem) => problem.rule === "unscoped-helper-call");
|
|
275
|
+
assert.equal(helperCalls.length, 2, "the default helper and the extra helper are each checked");
|
|
276
|
+
assert.match(helperCalls.map((problem) => problem.detail).join("\n"), /insertReturning/);
|
|
277
|
+
assert.match(helperCalls.map((problem) => problem.detail).join("\n"), /insertMany/);
|
|
278
|
+
assert.ok(!problems.some((problem) => problem.rule === "dropped-default-helper"), "appending drops no default");
|
|
279
|
+
rmSync(dir, { recursive: true, force: true });
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("a config whose exemptHelpers omits a default fails the check as dropped-default-helper", async () => {
|
|
283
|
+
const dir = repo();
|
|
284
|
+
await quiet(() => runInit(load(dir)));
|
|
285
|
+
const config = JSON.parse(readFileSync(path.join(dir, "qc.config.json"), "utf8"));
|
|
286
|
+
config.gates = { ...config.gates, "config-floor": true };
|
|
287
|
+
config.tenantPredicate = { exemptHelpers: [{ module: "backend/src/application/sql/crud.ts", name: "insertReturning", argument: 2 }] };
|
|
288
|
+
write(dir, { "qc.config.json": JSON.stringify(config) });
|
|
289
|
+
const { problems } = await runCheck(load(dir));
|
|
290
|
+
const dropped = problems.filter((problem) => problem.rule === "dropped-default-helper");
|
|
291
|
+
assert.equal(dropped.length, 1);
|
|
292
|
+
assert.match(dropped[0].detail, /updateVersionedRow/);
|
|
293
|
+
rmSync(dir, { recursive: true, force: true });
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("a default also listed in extraExemptHelpers gives one unscoped-helper-call per call", async () => {
|
|
297
|
+
const dir = repo();
|
|
298
|
+
await quiet(() => runInit(load(dir)));
|
|
299
|
+
const config = JSON.parse(readFileSync(path.join(dir, "qc.config.json"), "utf8"));
|
|
300
|
+
config.tenantPredicate = {
|
|
301
|
+
extraExemptHelpers: [{ module: "backend/src/application/sql/crud.ts", name: "insertReturning", argument: 2 }],
|
|
302
|
+
};
|
|
303
|
+
write(dir, {
|
|
304
|
+
"qc.config.json": JSON.stringify(config),
|
|
305
|
+
"backend/src/application/orders.ts": [
|
|
306
|
+
'import { insertReturning } from "./sql/crud";',
|
|
307
|
+
"export function place(tx, v) {",
|
|
308
|
+
' insertReturning(tx, "orders", ["id"], v);',
|
|
309
|
+
"}",
|
|
310
|
+
"",
|
|
311
|
+
].join("\n"),
|
|
312
|
+
});
|
|
313
|
+
const { problems } = await runCheck(load(dir));
|
|
314
|
+
assert.equal(problems.filter((problem) => problem.rule === "unscoped-helper-call").length, 1);
|
|
315
|
+
rmSync(dir, { recursive: true, force: true });
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// The tenant-predicate gate reads how a caller imports an exempt helper. These run the whole check,
|
|
319
|
+
// so the wiring in `check.mjs` (the tsconfig read, the alias map, the two rules) is under test too.
|
|
320
|
+
const HELPER_RULES = new Set(["unscoped-helper-call", "unresolved-helper-import"]);
|
|
321
|
+
const CRUD_SOURCE = "export function insertReturning() {}\n";
|
|
322
|
+
const helperProblems = (problems) => problems.filter((problem) => HELPER_RULES.has(problem.rule)).map(({ path: file, rule }) => ({ file, rule }));
|
|
323
|
+
|
|
324
|
+
async function helperRepo(files, config = {}) {
|
|
325
|
+
const dir = repo();
|
|
326
|
+
write(dir, { "qc.config.json": JSON.stringify({ featureRoots: ["backend/src/features"], ...config }), ...files });
|
|
327
|
+
return dir;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
test("check resolves an alias call through the tsconfig, and an unscoped one fails", async () => {
|
|
331
|
+
const dir = await helperRepo({
|
|
332
|
+
"tsconfig.json": '{ // a comment\n "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["backend/src/*"], }, }, }',
|
|
333
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
334
|
+
"backend/src/features/a/bad.ts": 'import { insertReturning } from "@/application/sql/crud.js";\ninsertReturning(tx, "a", ["id"], v);\n',
|
|
335
|
+
"backend/src/features/a/good.ts": 'import { insertReturning } from "@/application/sql/crud.js";\ninsertReturning(tx, "a", ["id", "tenant_id"], v);\n',
|
|
336
|
+
});
|
|
337
|
+
const { problems } = await runCheck(load(dir));
|
|
338
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/bad.ts", rule: "unscoped-helper-call" }]);
|
|
339
|
+
rmSync(dir, { recursive: true, force: true });
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("check fails a barrel import it cannot read, naming the file", async () => {
|
|
343
|
+
const dir = await helperRepo({
|
|
344
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
345
|
+
"backend/src/features/a/x.ts": 'import { insertReturning } from "../../application/sql/index.js";\n',
|
|
346
|
+
});
|
|
347
|
+
const { problems } = await runCheck(load(dir));
|
|
348
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/x.ts", rule: "unresolved-helper-import" }]);
|
|
349
|
+
rmSync(dir, { recursive: true, force: true });
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("check follows a renamed re-export in a barrel one level", async () => {
|
|
353
|
+
const dir = await helperRepo({
|
|
354
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
355
|
+
"backend/src/application/sql/index.ts": 'export { insertReturning as insertRow } from "./crud.js";\n',
|
|
356
|
+
"backend/src/features/a/x.ts": 'import { insertRow } from "../../application/sql/index.js";\ninsertRow(tx, "a", ["id"], v);\n',
|
|
357
|
+
});
|
|
358
|
+
const { problems } = await runCheck(load(dir));
|
|
359
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/x.ts", rule: "unscoped-helper-call" }]);
|
|
360
|
+
rmSync(dir, { recursive: true, force: true });
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test("check reports a tsconfig it cannot parse, at the tsconfig", async () => {
|
|
364
|
+
const dir = await helperRepo({
|
|
365
|
+
"tsconfig.json": "{ not json",
|
|
366
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
367
|
+
"backend/src/features/a/x.ts": 'import { insertReturning } from "@/application/sql/crud.js";\n',
|
|
368
|
+
});
|
|
369
|
+
const { problems } = await runCheck(load(dir));
|
|
370
|
+
assert.deepEqual(
|
|
371
|
+
helperProblems(problems).sort((a, b) => a.file.localeCompare(b.file)),
|
|
372
|
+
[
|
|
373
|
+
{ file: "backend/src/features/a/x.ts", rule: "unresolved-helper-import" },
|
|
374
|
+
{ file: "tsconfig.json", rule: "unresolved-helper-import" },
|
|
375
|
+
],
|
|
376
|
+
);
|
|
377
|
+
rmSync(dir, { recursive: true, force: true });
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("tenantPredicate.tsconfig points at the file that holds the paths, and its targets resolve from its folder", async () => {
|
|
381
|
+
const dir = await helperRepo(
|
|
382
|
+
{
|
|
383
|
+
"backend/tsconfig.json": '{ "compilerOptions": { "paths": { "@/*": ["src/*"] } } }',
|
|
384
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
385
|
+
"backend/src/features/a/x.ts": 'import { insertReturning } from "@/application/sql/crud.js";\ninsertReturning(tx, "a", ["id"], v);\n',
|
|
386
|
+
},
|
|
387
|
+
{ tenantPredicate: { tsconfig: "backend/tsconfig.json" } },
|
|
388
|
+
);
|
|
389
|
+
const { problems } = await runCheck(load(dir));
|
|
390
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/x.ts", rule: "unscoped-helper-call" }]);
|
|
391
|
+
rmSync(dir, { recursive: true, force: true });
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test("with the default tsconfig absent, an alias import fails closed", async () => {
|
|
395
|
+
const dir = await helperRepo({
|
|
396
|
+
"backend/tsconfig.json": '{ "compilerOptions": { "paths": { "@/*": ["src/*"] } } }',
|
|
397
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
398
|
+
"backend/src/features/a/x.ts": 'import { insertReturning } from "@/application/sql/crud.js";\n',
|
|
399
|
+
});
|
|
400
|
+
const { problems } = await runCheck(load(dir));
|
|
401
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/x.ts", rule: "unresolved-helper-import" }]);
|
|
402
|
+
rmSync(dir, { recursive: true, force: true });
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("check follows a helper renamed through two barrels", async () => {
|
|
406
|
+
const dir = await helperRepo({
|
|
407
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
408
|
+
"backend/src/application/sql/inner.ts": 'export { insertReturning as insertRow } from "./crud.js";\n',
|
|
409
|
+
"backend/src/application/sql/index.ts": 'export { insertRow as put } from "./inner.js";\n',
|
|
410
|
+
"backend/src/features/a/x.ts": 'import { put } from "../../application/sql/index.js";\nput(tx, "a", ["id"], v);\n',
|
|
411
|
+
});
|
|
412
|
+
const { problems } = await runCheck(load(dir));
|
|
413
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/x.ts", rule: "unscoped-helper-call" }]);
|
|
414
|
+
rmSync(dir, { recursive: true, force: true });
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test("check treats a scanned file with no import as read, and one outside the scanned roots as untraceable", async () => {
|
|
418
|
+
const dir = await helperRepo({
|
|
419
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
420
|
+
"backend/src/application/sql/plain.ts": "export const plain = 1;\n",
|
|
421
|
+
"backend/src/application/sql/index.ts": 'export { plain as p } from "./plain.js";\nexport { thing as t } from "../../../../vendor/lib.js";\n',
|
|
422
|
+
"backend/src/features/a/x.ts": 'import { p } from "../../application/sql/index.js";\n',
|
|
423
|
+
"backend/src/features/a/y.ts": 'import { t } from "../../application/sql/index.js";\n',
|
|
424
|
+
});
|
|
425
|
+
const { problems } = await runCheck(load(dir));
|
|
426
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/y.ts", rule: "unresolved-helper-import" }]);
|
|
427
|
+
rmSync(dir, { recursive: true, force: true });
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test("check follows a default export of a helper module that has no import or re-export", async () => {
|
|
431
|
+
const dir = await helperRepo({
|
|
432
|
+
"backend/src/application/sql/crud.ts": "export function insertReturning() {}\nexport default insertReturning;\n",
|
|
433
|
+
"backend/src/features/a/x.ts": 'import put from "../../application/sql/crud.js";\nput(tx, "a", ["id"], v);\n',
|
|
434
|
+
});
|
|
435
|
+
const { problems } = await runCheck(load(dir));
|
|
436
|
+
assert.deepEqual(helperProblems(problems), [{ file: "backend/src/features/a/x.ts", rule: "unscoped-helper-call" }]);
|
|
437
|
+
rmSync(dir, { recursive: true, force: true });
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test("check follows an export const alias, and fails a file that aliases the helper in its body", async () => {
|
|
441
|
+
const dir = await helperRepo({
|
|
442
|
+
"backend/src/application/sql/crud.ts": CRUD_SOURCE,
|
|
443
|
+
"backend/src/application/sql/index.ts": 'import { insertReturning } from "./crud.js";\nexport const insertRow = insertReturning;\n',
|
|
444
|
+
"backend/src/features/a/x.ts": 'import { insertRow } from "../../application/sql/index.js";\ninsertRow(tx, "a", ["id"], v);\n',
|
|
445
|
+
"backend/src/features/a/y.ts": 'import { insertReturning } from "../../application/sql/crud.js";\nconst f = insertReturning;\nf(tx, "a", ["id"], v);\n',
|
|
446
|
+
});
|
|
447
|
+
const { problems } = await runCheck(load(dir));
|
|
448
|
+
assert.deepEqual(
|
|
449
|
+
helperProblems(problems).sort((a, b) => a.file.localeCompare(b.file)),
|
|
450
|
+
[
|
|
451
|
+
{ file: "backend/src/features/a/x.ts", rule: "unscoped-helper-call" },
|
|
452
|
+
{ file: "backend/src/features/a/y.ts", rule: "unresolved-helper-import" },
|
|
453
|
+
],
|
|
454
|
+
);
|
|
455
|
+
rmSync(dir, { recursive: true, force: true });
|
|
456
|
+
});
|