architecture-harness 0.4.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 +80 -0
- package/src/cli/check.mjs +535 -0
- package/src/cli/cli.test.mjs +120 -0
- package/src/cli/commit-attribution.mjs +68 -0
- package/src/cli/commit-attribution.test.mjs +47 -0
- package/src/cli/decisions.mjs +223 -0
- package/src/cli/doctor.mjs +135 -0
- package/src/cli/doctor.test.mjs +57 -0
- package/src/cli/init.mjs +98 -0
- package/src/cli/install-hooks.mjs +26 -0
- package/src/cli/qc.mjs +89 -0
- package/src/cli/scaffold.mjs +194 -0
- package/src/cli/sync-enforcement-map.mjs +28 -0
- package/src/cli/work-order-guard.mjs +0 -0
- package/src/cli/work-order-guard.test.mjs +79 -0
- package/src/cli/worktree-isolation.mjs +94 -0
- package/src/cli/worktree-isolation.test.mjs +82 -0
- package/src/config.mjs +338 -0
- package/src/config.test.mjs +59 -0
- package/src/decisions.mjs +198 -0
- package/src/decisions.test.mjs +183 -0
- package/src/descriptions.mjs +28 -0
- package/src/descriptions.test.mjs +27 -0
- package/src/enforcement-map.mjs +46 -0
- package/src/enforcement-map.test.mjs +60 -0
- package/src/eslint/index.mjs +37 -0
- package/src/eslint/options.mjs +53 -0
- package/src/eslint/preset.mjs +192 -0
- package/src/eslint/preset.test.mjs +96 -0
- package/src/eslint/rules/durable-idempotency-key.mjs +120 -0
- package/src/eslint/rules/external-service-only-in-adapter.mjs +52 -0
- package/src/eslint/rules/module-boundary.mjs +12 -0
- package/src/eslint/rules/name-the-pattern.mjs +111 -0
- package/src/eslint/rules/no-comment-paragraph.mjs +101 -0
- package/src/eslint/rules/no-cross-feature-internals.mjs +57 -0
- package/src/eslint/rules/no-number-in-comment.mjs +89 -0
- package/src/eslint/rules/no-offset-pagination.mjs +29 -0
- package/src/eslint/rules/no-orchestration-in-trigger.mjs +56 -0
- package/src/eslint/rules/no-promise-then.mjs +43 -0
- package/src/eslint/rules/no-promise-then.test.mjs +63 -0
- package/src/eslint/rules/no-raw-fetch.mjs +27 -0
- package/src/eslint/rules/no-status-literal.mjs +34 -0
- package/src/eslint/rules/no-supersession-trail.mjs +51 -0
- package/src/eslint/rules/scoped-repository.mjs +43 -0
- package/src/eslint/rules/signal-last-param.mjs +43 -0
- package/src/eslint/rules/storage-only-in-resource.mjs +52 -0
- package/src/eslint/rules/tenant-scoped-table.mjs +71 -0
- package/src/eslint/rules.test.mjs +627 -0
- package/src/gates/adr-format.mjs +87 -0
- package/src/gates/adr-format.test.mjs +54 -0
- package/src/gates/audit-append-only.mjs +34 -0
- package/src/gates/audit-append-only.test.mjs +36 -0
- package/src/gates/citations.mjs +93 -0
- package/src/gates/citations.test.mjs +115 -0
- package/src/gates/claimed-requirements.mjs +53 -0
- package/src/gates/claimed-requirements.test.mjs +60 -0
- package/src/gates/comment-style.mjs +76 -0
- package/src/gates/comment-style.test.mjs +46 -0
- package/src/gates/config-floor.mjs +68 -0
- package/src/gates/config-floor.test.mjs +52 -0
- package/src/gates/contract-compose.mjs +38 -0
- package/src/gates/contract-compose.test.mjs +40 -0
- package/src/gates/eight-blocks.mjs +223 -0
- package/src/gates/eight-blocks.test.mjs +359 -0
- package/src/gates/enforcement-map.mjs +62 -0
- package/src/gates/enforcement-map.test.mjs +41 -0
- package/src/gates/english-source.mjs +176 -0
- package/src/gates/english-source.test.mjs +122 -0
- package/src/gates/frontend-boundaries.mjs +154 -0
- package/src/gates/frontend-boundaries.test.mjs +72 -0
- package/src/gates/gate-tests.mjs +44 -0
- package/src/gates/gate-tests.test.mjs +41 -0
- package/src/gates/headless-sagas.mjs +54 -0
- package/src/gates/headless-sagas.test.mjs +71 -0
- package/src/gates/internal-routes.mjs +76 -0
- package/src/gates/internal-routes.test.mjs +53 -0
- package/src/gates/public-routes.mjs +67 -0
- package/src/gates/public-routes.test.mjs +38 -0
- package/src/gates/registry-agreement.mjs +37 -0
- package/src/gates/registry-agreement.test.mjs +36 -0
- package/src/gates/saga-tests.mjs +94 -0
- package/src/gates/saga-tests.test.mjs +92 -0
- package/src/gates/sql-identifiers.mjs +244 -0
- package/src/gates/sql-identifiers.test.mjs +197 -0
- package/src/gates/tenant-predicate.mjs +175 -0
- package/src/gates/tenant-predicate.test.mjs +161 -0
- package/src/gates/tenant-tables.mjs +65 -0
- package/src/gates/tenant-tables.test.mjs +56 -0
- package/src/gates/test-mirror.mjs +47 -0
- package/src/gates/test-mirror.test.mjs +31 -0
- package/src/index.mjs +9 -0
- package/templates/.jscpd.json +15 -0
- package/templates/CLAUDE.md +54 -0
- package/templates/decisions.examples.md +25 -0
- package/templates/docs/adr-template.md +58 -0
- package/templates/docs/architecture.md +179 -0
- package/templates/docs/decisions.md +72 -0
- package/templates/docs/enforcement.md +94 -0
- package/templates/docs/glossary.md +16 -0
- package/templates/docs/guards.md +23 -0
- package/templates/docs/pagination.md +113 -0
- package/templates/docs/performance.md +35 -0
- package/templates/docs/ui.md +32 -0
- package/templates/githooks/commit-msg +4 -0
- package/templates/githooks/pre-commit +18 -0
- package/templates/githooks/pre-push +6 -0
- package/templates/github/workflows/ci.yml +21 -0
- package/templates/qc.config.json +6 -0
- package/templates/quality-thresholds.json +114 -0
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { RuleTester } from "eslint";
|
|
2
|
+
import { rules } from "./index.mjs";
|
|
3
|
+
|
|
4
|
+
const tester = new RuleTester({
|
|
5
|
+
languageOptions: { ecmaVersion: 2023, sourceType: "module" },
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// Every rule is proven by a case that must fail. A gate that has never failed
|
|
9
|
+
// has never been tested. ADR-0032.
|
|
10
|
+
|
|
11
|
+
console.log("→", "no-number-in-comment");
|
|
12
|
+
tester.run("no-number-in-comment", rules["no-number-in-comment"], {
|
|
13
|
+
valid: [
|
|
14
|
+
{ code: "// docs/performance.md owns the budget\nconst a = 1;" },
|
|
15
|
+
{ code: "// ADR-0052 — the version check is the guard\nconst a = 1;" },
|
|
16
|
+
{ code: "// REQ-PHO-003\nconst a = 1;" },
|
|
17
|
+
{ code: "// uuidV7 is time-ordered\nconst a = 1;" },
|
|
18
|
+
{ code: "// the one place a caller resolves a name\nconst a = 1;" },
|
|
19
|
+
{ code: "// a hand-built `file://${argv[1]}` never matches on Windows\nconst a = 1;" },
|
|
20
|
+
],
|
|
21
|
+
invalid: [
|
|
22
|
+
{ code: "// retry up to 3 times\nconst a = 1;", errors: [{ messageId: "number" }] },
|
|
23
|
+
{ code: "/* budget is 16 ms */\nconst a = 1;", errors: [{ messageId: "number" }] },
|
|
24
|
+
{ code: "// retry up to three times\nconst a = 1;", errors: [{ messageId: "number" }] },
|
|
25
|
+
{ code: "/* budget is sixteen ms */\nconst a = 1;", errors: [{ messageId: "number" }] },
|
|
26
|
+
{ code: "// wait five seconds\nconst a = 1;", errors: [{ messageId: "number" }] },
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log("→", "no-comment-paragraph");
|
|
31
|
+
tester.run("no-comment-paragraph", rules["no-comment-paragraph"], {
|
|
32
|
+
valid: [
|
|
33
|
+
{ code: "// the one place a caller resolves a name\nconst a = 1;" },
|
|
34
|
+
{ code: "/** ADR-0052 — the version check is the guard */\nconst a = 1;" },
|
|
35
|
+
{ code: "// first thought\n\n// a second, separated by a blank line\nconst a = 1;" },
|
|
36
|
+
{ code: "const a = 1; // why this one\nconst b = 2; // why that one" },
|
|
37
|
+
{ code: "const a = 1; // why\n// and an own-line note\nconst b = 2;" },
|
|
38
|
+
{ code: "// returns early when the caller supplied no folder\nconst a = 1;" },
|
|
39
|
+
{ code: "/**\n * one line of why\n * @param {string} a\n * @returns {number}\n */\nconst a = 1;" },
|
|
40
|
+
{ code: "// the one error handler owns that mapping; no status is set here\nconst a = 1;" },
|
|
41
|
+
{ code: "// one\n// two\nconst a = 1;" },
|
|
42
|
+
{ code: "/**\n * one\n * two\n */\nconst a = 1;" },
|
|
43
|
+
{ code: "/**\n * one\n * two\n * @param {string} a\n */\nconst a = 1;" },
|
|
44
|
+
],
|
|
45
|
+
invalid: [
|
|
46
|
+
{ code: "// one\n// two\n// three\nconst a = 1;", errors: [{ messageId: "paragraph" }] },
|
|
47
|
+
{ code: "/**\n * one\n * two\n * three\n */\nconst a = 1;", errors: [{ messageId: "paragraph" }] },
|
|
48
|
+
{ code: "/**\n * one\n * two\n * three\n * @param {string} a\n */\nconst a = 1;", errors: [{ messageId: "paragraph" }] },
|
|
49
|
+
{
|
|
50
|
+
code: "// a wrapped sentence is two lines, but three lines is a decision\n// rather than a comment\n// and this is line three\nconst a = 1;",
|
|
51
|
+
errors: [{ messageId: "paragraph" }],
|
|
52
|
+
options: [{ decisions: "docs/decisions.md" }],
|
|
53
|
+
},
|
|
54
|
+
{ code: "// ==========\nconst a = 1;", errors: [{ messageId: "banner" }] },
|
|
55
|
+
{ code: "// const previous = read();\nconst a = 1;", errors: [{ messageId: "code" }] },
|
|
56
|
+
{ code: "// if (ready) {\nconst a = 1;", errors: [{ messageId: "code" }] },
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
console.log("→", "no-cross-feature-internals");
|
|
61
|
+
tester.run("no-cross-feature-internals", rules["no-cross-feature-internals"], {
|
|
62
|
+
valid: [
|
|
63
|
+
{ code: "import { pins } from '../pins/index.js';", filename: "/a/features/photos/pipeline.ts" },
|
|
64
|
+
{ code: "import { pins } from '../../pins/index.js';", filename: "/a/features/photos/slices/create.ts" },
|
|
65
|
+
{ code: "import { pins } from '../../pins';", filename: "/a/features/photos/slices/create.ts" },
|
|
66
|
+
{ code: "import { x } from './resource.js';", filename: "/a/features/photos/pipeline.ts" },
|
|
67
|
+
{ code: "import { y } from '../photos/resource.js';", filename: "/a/features/photos/pipeline.ts" },
|
|
68
|
+
],
|
|
69
|
+
invalid: [
|
|
70
|
+
{
|
|
71
|
+
code: "import { x } from '../pins/resource.js';",
|
|
72
|
+
filename: "/a/features/photos/pipeline.ts",
|
|
73
|
+
errors: [{ messageId: "internal" }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
code: "import { x } from '../../pins/shared/index.js';",
|
|
77
|
+
filename: "/a/features/photos/slices/create.ts",
|
|
78
|
+
errors: [{ messageId: "internal" }],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
code: "import { x } from '../../pins/slices/create-pin.js';",
|
|
82
|
+
filename: "/a/features/photos/slices/create.ts",
|
|
83
|
+
errors: [{ messageId: "internal" }],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
console.log("→", "storage-only-in-resource");
|
|
89
|
+
tester.run("storage-only-in-resource", rules["storage-only-in-resource"], {
|
|
90
|
+
valid: [{ code: "import { eq } from 'drizzle-orm';", filename: "/a/features/pins/resource.ts" }],
|
|
91
|
+
invalid: [
|
|
92
|
+
{
|
|
93
|
+
code: "import { eq } from 'drizzle-orm';",
|
|
94
|
+
filename: "/a/features/pins/pipeline.ts",
|
|
95
|
+
errors: [{ messageId: "misplaced" }],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
console.log("→", "no-raw-fetch");
|
|
101
|
+
tester.run("no-raw-fetch", rules["no-raw-fetch"], {
|
|
102
|
+
valid: [
|
|
103
|
+
{ code: "await fetch(url);", filename: "/a/platform/api-client.ts" },
|
|
104
|
+
{ code: "await client.get(path);", filename: "/a/features/pins/index.ts" },
|
|
105
|
+
],
|
|
106
|
+
invalid: [
|
|
107
|
+
{ code: "await fetch(url);", filename: "/a/features/pins/index.ts", errors: [{ messageId: "raw" }] },
|
|
108
|
+
{ code: "new URL(path);", filename: "/a/features/pins/index.ts", errors: [{ messageId: "raw" }] },
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
console.log("→", "no-status-literal");
|
|
113
|
+
tester.run("no-status-literal", rules["no-status-literal"], {
|
|
114
|
+
valid: ["throw new ConflictError();", "reply.status(status);"],
|
|
115
|
+
invalid: [{ code: "reply.status(409);", errors: [{ messageId: "literal" }] }],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
console.log("→", "storage-only-in-resource path");
|
|
119
|
+
tester.run("storage-only-in-resource", rules["storage-only-in-resource"], {
|
|
120
|
+
valid: [
|
|
121
|
+
{ code: 'import { Pool } from "pg";', filename: "backend/src/infrastructure/db/pg-pool.ts" },
|
|
122
|
+
{ code: 'import { drizzle } from "drizzle-orm";', filename: "backend/src/features/pins/resource.ts" },
|
|
123
|
+
],
|
|
124
|
+
invalid: [
|
|
125
|
+
{
|
|
126
|
+
code: 'import { Pool } from "pg";',
|
|
127
|
+
filename: "backend/src/features/pins/pipeline.ts",
|
|
128
|
+
errors: [{ messageId: "misplaced" }],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
code: 'import { Pool } from "pg";',
|
|
132
|
+
filename: "backend/src/infrastructure/http/router.ts",
|
|
133
|
+
errors: [{ messageId: "misplaced" }],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
console.log("→", "external-service-only-in-adapter");
|
|
139
|
+
tester.run("external-service-only-in-adapter", rules["external-service-only-in-adapter"], {
|
|
140
|
+
valid: [
|
|
141
|
+
{ code: 'import { S3Client } from "@aws-sdk/client-s3";', filename: "backend/src/adapters/cloud/aws/s3-gateway.ts" },
|
|
142
|
+
{ code: 'import { S3Client } from "@aws-sdk/client-s3";', filename: "backend/src/main.ts" },
|
|
143
|
+
{ code: 'import { SQSClient } from "@aws-sdk/client-sqs";', filename: "workers/media-process/src/entry.ts" },
|
|
144
|
+
{ code: 'import Stripe from "stripe";', filename: "backend/src/adapters/payments/stripe/gateway.ts" },
|
|
145
|
+
{ code: 'import { readFile } from "node:fs";', filename: "backend/src/features/pins/pipeline.ts" },
|
|
146
|
+
],
|
|
147
|
+
invalid: [
|
|
148
|
+
{
|
|
149
|
+
code: 'import { S3Client } from "@aws-sdk/client-s3";',
|
|
150
|
+
filename: "backend/src/features/pins/pipeline.ts",
|
|
151
|
+
errors: [{ messageId: "misplaced" }],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
code: 'import { S3Client } from "@aws-sdk/client-s3";',
|
|
155
|
+
filename: "workers/media-process/src/handle.ts",
|
|
156
|
+
errors: [{ messageId: "misplaced" }],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
code: 'import AWS from "aws-sdk";',
|
|
160
|
+
filename: "backend/src/features/photos/slices/upload.ts",
|
|
161
|
+
errors: [{ messageId: "misplaced" }],
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
code: 'import Stripe from "stripe";',
|
|
165
|
+
filename: "backend/src/features/billing/pipeline.ts",
|
|
166
|
+
errors: [{ messageId: "misplaced" }],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
code: 'import Stripe from "stripe";',
|
|
170
|
+
filename: "backend/src/features/billing/adapters/stripe-client.ts",
|
|
171
|
+
errors: [{ messageId: "misplaced" }],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
code: 'import Stripe from "@stripe/stripe-js";',
|
|
175
|
+
filename: "frontend/src/features/billing/pipeline.ts",
|
|
176
|
+
errors: [{ messageId: "misplaced" }],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
code: 'import twilio from "twilio";',
|
|
180
|
+
filename: "backend/src/features/notifications/slices/send-sms.ts",
|
|
181
|
+
errors: [{ messageId: "misplaced" }],
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
console.log("→", "no-offset-pagination");
|
|
187
|
+
tester.run("no-offset-pagination", rules["no-offset-pagination"], {
|
|
188
|
+
valid: ["const q = { limit, cursor };"],
|
|
189
|
+
invalid: [
|
|
190
|
+
{ code: "const q = { limit, offset };", errors: [{ messageId: "offset" }] },
|
|
191
|
+
{ code: "query.skip;", errors: [{ messageId: "offset" }] },
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
console.log("→", "scoped-repository");
|
|
196
|
+
tester.run("scoped-repository", rules["scoped-repository"], {
|
|
197
|
+
valid: ["register({ pinRepository: asClass(PinRepository).scoped() });"],
|
|
198
|
+
invalid: [
|
|
199
|
+
{
|
|
200
|
+
code: "register({ pinRepository: asClass(PinRepository).singleton() });",
|
|
201
|
+
errors: [{ messageId: "singleton" }],
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
code: "register({ analyzeSaga: asClass(AnalyzePhotoSaga).singleton() });",
|
|
205
|
+
errors: [{ messageId: "singleton" }],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
code: "register({ unitOfWorkFactory: asClass(PostgresUnitOfWorkFactory).singleton() });",
|
|
209
|
+
errors: [{ messageId: "singleton" }],
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
console.log("→", "signal-last-param");
|
|
215
|
+
tester.run("signal-last-param", rules["signal-last-param"], {
|
|
216
|
+
valid: [
|
|
217
|
+
"export async function load(id, signal) {}",
|
|
218
|
+
"export const load = async (id, signal) => {};",
|
|
219
|
+
"export function pure(id) {}",
|
|
220
|
+
],
|
|
221
|
+
invalid: [
|
|
222
|
+
{ code: "export async function load(id) {}", errors: [{ messageId: "missing" }] },
|
|
223
|
+
{ code: "export const load = async (id) => {};", errors: [{ messageId: "missing" }] },
|
|
224
|
+
],
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
console.log("→", "tenant-scoped-table");
|
|
228
|
+
tester.run("tenant-scoped-table", rules["tenant-scoped-table"], {
|
|
229
|
+
valid: [
|
|
230
|
+
"pgTable('pins', { id: uuid('id'), tenantId: uuid('tenant_id') });",
|
|
231
|
+
"index('pins_partition_idx').on(t.capturedAt, t.id)",
|
|
232
|
+
],
|
|
233
|
+
invalid: [
|
|
234
|
+
{ code: "pgTable('pins', { id: uuid('id') });", errors: [{ messageId: "missing" }] },
|
|
235
|
+
{ code: "index('pins_project_idx').on(t.projectId, t.id)", errors: [{ messageId: "indexOrder" }] },
|
|
236
|
+
],
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
console.log("→", "no-orchestration-in-trigger");
|
|
240
|
+
tester.run("no-orchestration-in-trigger", rules["no-orchestration-in-trigger"], {
|
|
241
|
+
valid: [
|
|
242
|
+
{ code: "async function handle() { await runJacicExportSaga(); }", filename: "/repo/frontend/src/features/pins/trigger.tsx" },
|
|
243
|
+
{ code: "function handle() { mutate(); }", filename: "/repo/frontend/src/features/pins/trigger.tsx" },
|
|
244
|
+
{ code: "async function a() { await f1(); }\nasync function b() { await f2(); }", filename: "/repo/frontend/src/features/pins/trigger.tsx" },
|
|
245
|
+
{ code: "async function saga() { await f1(); await f2(); }", filename: "/repo/frontend/src/features/pins/pipeline.ts" },
|
|
246
|
+
{ code: "it('works', async () => { await s1(); await s2(); });", filename: "/repo/frontend/src/features/pins/trigger.test.tsx" },
|
|
247
|
+
],
|
|
248
|
+
invalid: [
|
|
249
|
+
{
|
|
250
|
+
code: "async function handle() { await stepA(); await stepB(); }",
|
|
251
|
+
filename: "/repo/frontend/src/features/pins/trigger.tsx",
|
|
252
|
+
errors: [{ messageId: "orchestration" }],
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
code: "const handle = async () => { await stepA(); await stepB(); await stepC(); };",
|
|
256
|
+
filename: "/repo/frontend/src/features/pins/trigger.tsx",
|
|
257
|
+
errors: [{ messageId: "orchestration" }, { messageId: "orchestration" }],
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
console.log("all rule fixtures asserted");
|
|
263
|
+
|
|
264
|
+
tester.run("no-number-in-comment (layer names)", rules["no-number-in-comment"], {
|
|
265
|
+
valid: [
|
|
266
|
+
{ code: "// domain imports nothing\nconst a = 1;" },
|
|
267
|
+
{ code: "// adapters never imports Fastify\nconst a = 1;" },
|
|
268
|
+
{ code: "// WCAG 2.2 AA\nconst a = 1;" },
|
|
269
|
+
{ code: "// D8 — the renderer deviation\nconst a = 1;" },
|
|
270
|
+
],
|
|
271
|
+
invalid: [{ code: "// wait 500 ms\nconst a = 1;", errors: [{ messageId: "number" }] }],
|
|
272
|
+
});
|
|
273
|
+
console.log("layer-name fixtures asserted");
|
|
274
|
+
|
|
275
|
+
tester.run("no-number-in-comment (local decision ids)", rules["no-number-in-comment"], {
|
|
276
|
+
valid: [
|
|
277
|
+
{ code: "// QC-004 — the renderer\nconst a = 1;" },
|
|
278
|
+
{ code: "// QC-005 applies to this loop\nconst a = 1;" },
|
|
279
|
+
],
|
|
280
|
+
invalid: [{ code: "// budget is 16 ms\nconst a = 1;", errors: [{ messageId: "number" }] }],
|
|
281
|
+
});
|
|
282
|
+
console.log("local decision id fixtures asserted");
|
|
283
|
+
|
|
284
|
+
// --- Options ---
|
|
285
|
+
// A knob that is never exercised is a knob that does not work. Each case below
|
|
286
|
+
// proves the rule follows the config rather than the reference layout. ADR-0032.
|
|
287
|
+
|
|
288
|
+
console.log("→", "options: no-raw-fetch client");
|
|
289
|
+
tester.run("no-raw-fetch", rules["no-raw-fetch"], {
|
|
290
|
+
valid: [{ code: "fetch('/x');", filename: "/a/net/http.ts", options: [{ client: "net/http.ts" }] }],
|
|
291
|
+
invalid: [
|
|
292
|
+
{
|
|
293
|
+
code: "fetch('/x');",
|
|
294
|
+
filename: "/a/platform/api-client.ts",
|
|
295
|
+
options: [{ client: "net/http.ts" }],
|
|
296
|
+
errors: [{ messageId: "raw" }],
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
console.log("→", "options: no-cross-feature-internals featureDir");
|
|
302
|
+
tester.run("no-cross-feature-internals", rules["no-cross-feature-internals"], {
|
|
303
|
+
valid: [
|
|
304
|
+
{
|
|
305
|
+
code: "import { x } from '../pins/public.js';",
|
|
306
|
+
filename: "/a/modules/photos/flow.ts",
|
|
307
|
+
options: [{ featureDir: "modules", publicFile: "public" }],
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
invalid: [
|
|
311
|
+
{
|
|
312
|
+
code: "import { x } from '../pins/store.js';",
|
|
313
|
+
filename: "/a/modules/photos/flow.ts",
|
|
314
|
+
options: [{ featureDir: "modules", publicFile: "public" }],
|
|
315
|
+
errors: [{ messageId: "internal" }],
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
console.log("→", "options: storage-only-in-resource modules and files");
|
|
321
|
+
tester.run("storage-only-in-resource", rules["storage-only-in-resource"], {
|
|
322
|
+
valid: [
|
|
323
|
+
{
|
|
324
|
+
code: "import { x } from 'kysely';",
|
|
325
|
+
filename: "/a/features/pins/store.ts",
|
|
326
|
+
options: [{ modules: ["kysely"], resourceFiles: ["store.ts"], driverBinding: "" }],
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
invalid: [
|
|
330
|
+
{
|
|
331
|
+
code: "import { x } from 'kysely';",
|
|
332
|
+
filename: "/a/features/pins/resource.ts",
|
|
333
|
+
options: [{ modules: ["kysely"], resourceFiles: ["store.ts"], driverBinding: "" }],
|
|
334
|
+
errors: [{ messageId: "misplaced" }],
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
console.log("→", "options: external-service-only-in-adapter scopes, files and paths");
|
|
340
|
+
tester.run("external-service-only-in-adapter", rules["external-service-only-in-adapter"], {
|
|
341
|
+
valid: [
|
|
342
|
+
{
|
|
343
|
+
code: "import { Storage } from '@google-cloud/storage';",
|
|
344
|
+
filename: "/a/adapters/cloud/gcp/bucket.ts",
|
|
345
|
+
options: [{ scopes: ["@google-cloud"], allowedFiles: [], allowedPaths: ["adapters/cloud/"] }],
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
code: "import { Storage } from '@google-cloud/storage';",
|
|
349
|
+
filename: "/a/worker.ts",
|
|
350
|
+
options: [{ scopes: ["@google-cloud"], allowedFiles: ["worker.ts"], allowedPaths: [] }],
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
invalid: [
|
|
354
|
+
{
|
|
355
|
+
code: "import { Storage } from '@google-cloud/storage';",
|
|
356
|
+
filename: "/a/features/photos/pipeline.ts",
|
|
357
|
+
options: [{ scopes: ["@google-cloud"], allowedFiles: [], allowedPaths: ["adapters/cloud/"] }],
|
|
358
|
+
errors: [{ messageId: "misplaced" }],
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
console.log("→", "options: tenant-scoped-table column and factory");
|
|
364
|
+
tester.run("tenant-scoped-table", rules["tenant-scoped-table"], {
|
|
365
|
+
valid: [
|
|
366
|
+
{
|
|
367
|
+
code: "const t = table('pins', { orgId: uuid(), name: text() });",
|
|
368
|
+
options: [{ column: "orgId", tableFactory: "table" }],
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
invalid: [
|
|
372
|
+
{
|
|
373
|
+
code: "const t = table('pins', { tenantId: uuid(), name: text() });",
|
|
374
|
+
options: [{ column: "orgId", tableFactory: "table" }],
|
|
375
|
+
errors: [{ messageId: "missing" }],
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
console.log("→", "options: scoped-repository suffixes");
|
|
381
|
+
tester.run("scoped-repository", rules["scoped-repository"], {
|
|
382
|
+
valid: [{ code: "c.register(asClass(PinRepository).singleton());", options: [{ suffixes: ["Store"] }] }],
|
|
383
|
+
invalid: [
|
|
384
|
+
{
|
|
385
|
+
code: "c.register(asClass(PinStore).singleton());",
|
|
386
|
+
options: [{ suffixes: ["Store"] }],
|
|
387
|
+
errors: [{ messageId: "singleton" }],
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
console.log("→", "options: signal-last-param name");
|
|
393
|
+
tester.run("signal-last-param", rules["signal-last-param"], {
|
|
394
|
+
valid: [{ code: "export async function load(id, token) {}", options: [{ name: "token" }] }],
|
|
395
|
+
invalid: [
|
|
396
|
+
{
|
|
397
|
+
code: "export async function load(id, signal) {}",
|
|
398
|
+
options: [{ name: "token" }],
|
|
399
|
+
errors: [{ messageId: "missing" }],
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
console.log("→", "options: no-number-in-comment prefixes");
|
|
405
|
+
tester.run("no-number-in-comment", rules["no-number-in-comment"], {
|
|
406
|
+
valid: [{ code: "// RFC-0012 decided it\nconst a = 1;", options: [{ prefixes: ["RFC"] }] }],
|
|
407
|
+
invalid: [
|
|
408
|
+
{ code: "// ADR-0052 decided it\nconst a = 1;", options: [{ prefixes: ["RFC"], external: [] }], errors: [{ messageId: "number" }] },
|
|
409
|
+
],
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
console.log("→", "options: no-orchestration-in-trigger presenters");
|
|
413
|
+
tester.run("no-orchestration-in-trigger", rules["no-orchestration-in-trigger"], {
|
|
414
|
+
valid: [
|
|
415
|
+
{
|
|
416
|
+
code: "async function go() { await a(); await b(); }",
|
|
417
|
+
filename: "/a/frontend/src/features/pins/trigger.tsx",
|
|
418
|
+
options: [{ presenters: "ui/*/view" }],
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
invalid: [
|
|
422
|
+
{
|
|
423
|
+
code: "async function go() { await a(); await b(); }",
|
|
424
|
+
filename: "/a/ui/pins/view.tsx",
|
|
425
|
+
options: [{ presenters: "ui/*/view" }],
|
|
426
|
+
errors: [{ messageId: "orchestration" }],
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
console.log("→", "options: no-offset-pagination banned");
|
|
432
|
+
tester.run("no-offset-pagination", rules["no-offset-pagination"], {
|
|
433
|
+
valid: [{ code: "const q = { offset: 1 };", options: [{ banned: ["page"] }] }],
|
|
434
|
+
invalid: [{ code: "const q = { page: 1 };", options: [{ banned: ["page"] }], errors: [{ messageId: "offset" }] }],
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
console.log("→", "options: no-status-literal setters");
|
|
438
|
+
tester.run("no-status-literal", rules["no-status-literal"], {
|
|
439
|
+
valid: [{ code: "reply.status(404);", options: [{ setters: ["httpCode"] }] }],
|
|
440
|
+
invalid: [{ code: "reply.httpCode(404);", options: [{ setters: ["httpCode"] }], errors: [{ messageId: "literal" }] }],
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
console.log("every option asserted");
|
|
444
|
+
|
|
445
|
+
console.log("→", "durable-idempotency-key");
|
|
446
|
+
tester.run("durable-idempotency-key", rules["durable-idempotency-key"], {
|
|
447
|
+
valid: [
|
|
448
|
+
{ code: "const mutationId = row.id;" },
|
|
449
|
+
{ code: "const body = { mutationId: attempt.storedId };" },
|
|
450
|
+
{ code: "const other = Date.now();" },
|
|
451
|
+
{ code: "send({ requestedAt: Date.now() });" },
|
|
452
|
+
// Minted, bound, and persisted before it is ever sent — ADR-0050 done right.
|
|
453
|
+
{ code: "const operation = { mutationId: crypto.randomUUID() };\nqueue.push(operation);" },
|
|
454
|
+
{ code: "send({ mutationId: operation.mutationId });" },
|
|
455
|
+
],
|
|
456
|
+
invalid: [
|
|
457
|
+
{ code: "send({ mutationId: crypto.randomUUID() });", errors: [{ messageId: "volatile" }] },
|
|
458
|
+
{ code: "post(url, { clientMutationId: Date.now() });", errors: [{ messageId: "volatile" }] },
|
|
459
|
+
{ code: "api.create({ idempotencyKey: nanoid() });", errors: [{ messageId: "volatile" }] },
|
|
460
|
+
{ code: "send({ mutationId: stored ?? uuid() });", errors: [{ messageId: "volatile" }] },
|
|
461
|
+
{ code: "send({ mutationId: new Date().toISOString() });", errors: [{ messageId: "volatile" }] },
|
|
462
|
+
],
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
console.log("→", "no-supersession-trail");
|
|
466
|
+
tester.run("no-supersession-trail", rules["no-supersession-trail"], {
|
|
467
|
+
valid: [
|
|
468
|
+
{ code: "// the one place a caller resolves a name\nconst a = 1;" },
|
|
469
|
+
{ code: 'const label = "deprecated";' },
|
|
470
|
+
],
|
|
471
|
+
invalid: [
|
|
472
|
+
{ code: "// deprecated, use the new one\nconst a = 1;", errors: [{ messageId: "trail" }] },
|
|
473
|
+
{ code: "/* superseded by the slice anatomy */\nconst a = 1;", errors: [{ messageId: "trail" }] },
|
|
474
|
+
{ code: "// legacy path, kept for now\nconst a = 1;", errors: [{ messageId: "trail" }] },
|
|
475
|
+
{ code: "// this replaces the old runner\nconst a = 1;", errors: [{ messageId: "trail" }] },
|
|
476
|
+
{ code: "// formerly known as the ledger block\nconst a = 1;", errors: [{ messageId: "trail" }] },
|
|
477
|
+
],
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
console.log("→", "options: the new rules take their vocabulary from config");
|
|
481
|
+
tester.run("durable-idempotency-key", rules["durable-idempotency-key"], {
|
|
482
|
+
valid: [{ code: "send({ mutationId: ulid() });", options: [{ volatile: ["nanoid"] }] }],
|
|
483
|
+
invalid: [{ code: "send({ traceKey: ulid() });", options: [{ keys: ["traceKey"], volatile: ["ulid"] }], errors: [{ messageId: "volatile" }] }],
|
|
484
|
+
});
|
|
485
|
+
tester.run("no-supersession-trail", rules["no-supersession-trail"], {
|
|
486
|
+
valid: [{ code: "// deprecated\nconst a = 1;", options: [{ phrases: ["obsolete"] }] }],
|
|
487
|
+
invalid: [{ code: "// obsolete now\nconst a = 1;", options: [{ phrases: ["obsolete"] }], errors: [{ messageId: "trail" }] }],
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// The exemption that made this rule usable: a store thrown away at the end of the call
|
|
491
|
+
// has nothing to recognise a repeat in, so the key is disposable by design.
|
|
492
|
+
tester.run("durable-idempotency-key", rules["durable-idempotency-key"], {
|
|
493
|
+
valid: [
|
|
494
|
+
{ code: "runPipeline({ pipeline, mutationId: crypto.randomUUID(), ledger: new InMemoryPipelineLedger() });" },
|
|
495
|
+
],
|
|
496
|
+
invalid: [
|
|
497
|
+
{
|
|
498
|
+
code: "runPipeline({ pipeline, mutationId: crypto.randomUUID(), ledger: durableLedger });",
|
|
499
|
+
errors: [{ messageId: "volatile" }],
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
code: "runPipeline({ pipeline, mutationId: crypto.randomUUID(), ledger: new PostgresLedger() });",
|
|
503
|
+
errors: [{ messageId: "volatile" }],
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// `context.filename` is the OS separator — "\\" on Windows. Every rule that reads it must
|
|
509
|
+
// normalize before matching a forward-slash pattern, or every path-based exemption below
|
|
510
|
+
// silently never fires there. filenameOf() in options.mjs is the one place that normalizes.
|
|
511
|
+
console.log("→", "windows-style backslash filenames");
|
|
512
|
+
|
|
513
|
+
tester.run("no-cross-feature-internals (backslash path)", rules["no-cross-feature-internals"], {
|
|
514
|
+
valid: [{ code: "import { x } from '../pins/index.js';", filename: "a\\features\\pins\\index.ts" }],
|
|
515
|
+
invalid: [
|
|
516
|
+
{
|
|
517
|
+
code: "import { x } from '../pins/store.js';",
|
|
518
|
+
filename: "a\\features\\photos\\flow.ts",
|
|
519
|
+
errors: [{ messageId: "internal" }],
|
|
520
|
+
},
|
|
521
|
+
],
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
tester.run("no-orchestration-in-trigger (backslash path)", rules["no-orchestration-in-trigger"], {
|
|
525
|
+
valid: [{ code: "async function onClick() { await a(); }", filename: "frontend\\src\\features\\pins\\trigger.ts" }],
|
|
526
|
+
invalid: [
|
|
527
|
+
{
|
|
528
|
+
code: "async function onClick() { await a(); await b(); }",
|
|
529
|
+
filename: "frontend\\src\\features\\pins\\trigger.ts",
|
|
530
|
+
errors: [{ messageId: "orchestration" }],
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
tester.run("no-promise-then (backslash path)", rules["no-promise-then"], {
|
|
536
|
+
valid: [
|
|
537
|
+
{
|
|
538
|
+
code: "p.then(x);",
|
|
539
|
+
filename: "packages\\kernel\\src\\abortable.ts",
|
|
540
|
+
options: [{ allow: ["packages/kernel/src/abortable.ts"] }],
|
|
541
|
+
},
|
|
542
|
+
],
|
|
543
|
+
invalid: [
|
|
544
|
+
{
|
|
545
|
+
code: "p.then(x);",
|
|
546
|
+
filename: "backend\\src\\main.ts",
|
|
547
|
+
options: [{ allow: ["packages/kernel/src/abortable.ts"] }],
|
|
548
|
+
errors: [{ messageId: "chained" }],
|
|
549
|
+
},
|
|
550
|
+
],
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
tester.run("no-raw-fetch (backslash path)", rules["no-raw-fetch"], {
|
|
554
|
+
valid: [{ code: "fetch(url);", filename: "frontend\\src\\platform\\api-client.ts" }],
|
|
555
|
+
invalid: [{ code: "fetch(url);", filename: "frontend\\src\\features\\pins\\index.ts", errors: [{ messageId: "raw" }] }],
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
tester.run("storage-only-in-resource (backslash path)", rules["storage-only-in-resource"], {
|
|
559
|
+
valid: [{ code: "import { Pool } from 'pg';", filename: "backend\\src\\infrastructure\\db\\pg-pool.ts" }],
|
|
560
|
+
invalid: [
|
|
561
|
+
{ code: "import { Pool } from 'pg';", filename: "backend\\src\\features\\pins\\pipeline.ts", errors: [{ messageId: "misplaced" }] },
|
|
562
|
+
],
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
tester.run("external-service-only-in-adapter (backslash path)", rules["external-service-only-in-adapter"], {
|
|
566
|
+
valid: [
|
|
567
|
+
{ code: "import { S3Client } from '@aws-sdk/client-s3';", filename: "backend\\src\\main.ts" },
|
|
568
|
+
{ code: "import { S3Client } from '@aws-sdk/client-s3';", filename: "workers\\media-process\\src\\entry.ts" },
|
|
569
|
+
],
|
|
570
|
+
invalid: [
|
|
571
|
+
{
|
|
572
|
+
code: "import { S3Client } from '@aws-sdk/client-s3';",
|
|
573
|
+
filename: "backend\\src\\features\\photos\\pipeline.ts",
|
|
574
|
+
errors: [{ messageId: "misplaced" }],
|
|
575
|
+
},
|
|
576
|
+
],
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
console.log("→", "name-the-pattern");
|
|
580
|
+
tester.run("name-the-pattern", rules["name-the-pattern"], {
|
|
581
|
+
valid: [
|
|
582
|
+
{ code: "// Outbox: the ledger row and the write share one transaction.\nconst a = 1;" },
|
|
583
|
+
{ code: "// Keyset pagination — docs/pagination.md owns the cursor.\nconst a = 1;" },
|
|
584
|
+
{ code: "// Exponential backoff, capped.\nconst a = 1;" },
|
|
585
|
+
{
|
|
586
|
+
code:
|
|
587
|
+
"// The public surface, the only file another feature may import -- replayValues is " +
|
|
588
|
+
"published for the offline outbox to replay a queued write after reconnect.\nconst a = 1;",
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
code:
|
|
592
|
+
"// The client unit of work: a mutation and the keys its success invalidates. Headless, " +
|
|
593
|
+
"so a workflow runs without a view layer at all -- QC-010.\nconst a = 1;",
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
code:
|
|
597
|
+
"// This walks every folder in the tree and rebuilds the index from scratch, which is " +
|
|
598
|
+
"slow but correct, and nothing here is a named pattern anyone can look up.\nconst a = 1;",
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
code: "// Saga, explained at length for a human reader who has never met one before now.\nconst a = 1;",
|
|
602
|
+
options: [{ maxWords: 40 }],
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
invalid: [
|
|
606
|
+
{
|
|
607
|
+
code:
|
|
608
|
+
"// The outbox pattern works by writing the message into a table in the same " +
|
|
609
|
+
"transaction as the business row, then a relay polls that table and publishes each " +
|
|
610
|
+
"row, which guarantees at-least-once delivery.\nconst a = 1;",
|
|
611
|
+
errors: [{ messageId: "explained" }],
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
code:
|
|
615
|
+
"/* A circuit breaker is a proxy that counts failures, and once the count passes a " +
|
|
616
|
+
"threshold it opens and fails fast for a cooldown window before a trial request. */\nconst a = 1;",
|
|
617
|
+
errors: [{ messageId: "explained" }],
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
code:
|
|
621
|
+
"// We use a CRDT here. A CRDT is a data structure whose merge operation is " +
|
|
622
|
+
"commutative, associative and idempotent, so replicas converge without coordination " +
|
|
623
|
+
"between them at all.\nconst a = 1;",
|
|
624
|
+
errors: [{ messageId: "explained" }],
|
|
625
|
+
},
|
|
626
|
+
],
|
|
627
|
+
});
|