@starci/eslint-canon-be 3.5.0 → 3.6.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 (198) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +13 -2
  3. package/dist/ambient-id.d.ts +9 -0
  4. package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
  5. package/dist/app-composition.d.ts +21 -0
  6. package/{app-composition.mjs → dist/app-composition.js} +396 -300
  7. package/dist/async-discipline.d.ts +9 -0
  8. package/dist/async-discipline.js +77 -0
  9. package/dist/authorization.d.ts +12 -0
  10. package/{authorization.mjs → dist/authorization.js} +53 -59
  11. package/dist/boundary-schema.d.ts +15 -0
  12. package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
  13. package/dist/builders.d.ts +21 -0
  14. package/{builders.mjs → dist/builders.js} +162 -146
  15. package/dist/cli.d.ts +15 -0
  16. package/{cli.mjs → dist/cli.js} +97 -82
  17. package/dist/comments.d.ts +52 -0
  18. package/dist/comments.js +412 -0
  19. package/dist/config-owner.d.ts +24 -0
  20. package/{config-owner.mjs → dist/config-owner.js} +256 -219
  21. package/dist/connections.d.ts +12 -0
  22. package/{connections.mjs → dist/connections.js} +138 -140
  23. package/dist/cookies.d.ts +9 -0
  24. package/{cookies.mjs → dist/cookies.js} +58 -58
  25. package/dist/cqrs.d.ts +27 -0
  26. package/{cqrs.mjs → dist/cqrs.js} +341 -282
  27. package/dist/data-access.d.ts +50 -0
  28. package/{data-access.mjs → dist/data-access.js} +238 -243
  29. package/dist/default-deny.d.ts +15 -0
  30. package/{default-deny.mjs → dist/default-deny.js} +103 -88
  31. package/dist/e2e-flow.d.ts +25 -0
  32. package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
  33. package/dist/edge-hardening.d.ts +10 -0
  34. package/dist/edge-hardening.js +173 -0
  35. package/dist/error-handling.d.ts +21 -0
  36. package/{error-handling.mjs → dist/error-handling.js} +289 -239
  37. package/dist/event-bus.d.ts +14 -0
  38. package/{event-bus.mjs → dist/event-bus.js} +146 -129
  39. package/dist/feature-thin.d.ts +12 -0
  40. package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
  41. package/dist/function-budget.d.ts +7 -0
  42. package/{function-budget.mjs → dist/function-budget.js} +24 -27
  43. package/dist/health-ready.d.ts +10 -0
  44. package/dist/health-ready.js +703 -0
  45. package/dist/idempotency.d.ts +10 -0
  46. package/{idempotency.mjs → dist/idempotency.js} +296 -226
  47. package/dist/index.d.ts +54 -0
  48. package/{index.mjs → dist/index.js} +91 -109
  49. package/dist/infra-owner.d.ts +18 -0
  50. package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
  51. package/dist/injection.d.ts +30 -0
  52. package/{injection.mjs → dist/injection.js} +397 -344
  53. package/dist/input-bounds.d.ts +15 -0
  54. package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
  55. package/dist/jobs.d.ts +17 -0
  56. package/{jobs.mjs → dist/jobs.js} +116 -99
  57. package/dist/jwt-alg.d.ts +6 -0
  58. package/dist/jwt-alg.js +49 -0
  59. package/dist/lib/app-roles.d.ts +25 -0
  60. package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
  61. package/dist/lib/ast.d.ts +40 -0
  62. package/dist/lib/ast.js +100 -0
  63. package/dist/lib/client-idempotency.d.ts +3 -0
  64. package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
  65. package/dist/lib/config.d.ts +36 -0
  66. package/{lib/config.mjs → dist/lib/config.js} +24 -27
  67. package/dist/lib/db-writes.d.ts +29 -0
  68. package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
  69. package/dist/lib/declared.d.ts +77 -0
  70. package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
  71. package/dist/lib/doors.d.ts +50 -0
  72. package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
  73. package/dist/lib/edition.d.ts +25 -0
  74. package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
  75. package/dist/lib/entity-writes.d.ts +7 -0
  76. package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
  77. package/dist/lib/hfs-view.d.ts +127 -0
  78. package/dist/lib/hfs-view.js +1 -0
  79. package/dist/lib/hfs.d.ts +34 -0
  80. package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
  81. package/dist/lib/import-source.d.ts +63 -0
  82. package/dist/lib/import-source.js +134 -0
  83. package/dist/lib/path.d.ts +8 -0
  84. package/{lib/path.mjs → dist/lib/path.js} +4 -7
  85. package/dist/lib/persistence.d.ts +115 -0
  86. package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
  87. package/dist/lib/ports.d.ts +70 -0
  88. package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
  89. package/dist/lib/rule.d.ts +31 -0
  90. package/dist/lib/rule.js +2 -0
  91. package/dist/lib/runtime-root.d.ts +4 -0
  92. package/dist/lib/runtime-root.js +10 -0
  93. package/dist/lib/schema-values.d.ts +13 -0
  94. package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
  95. package/dist/lib/specifier.d.ts +12 -0
  96. package/dist/lib/specifier.js +29 -0
  97. package/dist/lib/subject-values.d.ts +4 -0
  98. package/dist/lib/subject-values.js +61 -0
  99. package/dist/lib/transactions.d.ts +18 -0
  100. package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
  101. package/dist/lib/transport-slots.d.ts +17 -0
  102. package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
  103. package/dist/lib/types.d.ts +96 -0
  104. package/dist/lib/types.js +150 -0
  105. package/dist/lib/unit-spec.d.ts +48 -0
  106. package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
  107. package/dist/lib/webhook-ack.d.ts +4 -0
  108. package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
  109. package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
  110. package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
  111. package/dist/lib/webhook-handoff-intake.d.ts +4 -0
  112. package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
  113. package/dist/lib/webhook-handoff.d.ts +15 -0
  114. package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
  115. package/dist/lib/webhook-verifiers.d.ts +20 -0
  116. package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
  117. package/dist/lib/why.d.ts +9 -0
  118. package/{lib/why.mjs → dist/lib/why.js} +6 -6
  119. package/dist/log-safety.d.ts +20 -0
  120. package/dist/log-safety.js +308 -0
  121. package/dist/module-layering.d.ts +42 -0
  122. package/dist/module-layering.js +257 -0
  123. package/dist/module-shape.d.ts +47 -0
  124. package/{module-shape.mjs → dist/module-shape.js} +278 -236
  125. package/dist/naming.d.ts +49 -0
  126. package/dist/naming.js +246 -0
  127. package/dist/observability.d.ts +25 -0
  128. package/dist/observability.js +245 -0
  129. package/dist/operations.d.ts +23 -0
  130. package/{operations.mjs → dist/operations.js} +410 -332
  131. package/dist/project-graph.d.ts +9 -0
  132. package/{project-graph.mjs → dist/project-graph.js} +8 -13
  133. package/dist/projections.d.ts +11 -0
  134. package/{projections.mjs → dist/projections.js} +60 -57
  135. package/dist/query-safety.d.ts +21 -0
  136. package/{query-safety.mjs → dist/query-safety.js} +92 -108
  137. package/dist/realtime.d.ts +15 -0
  138. package/{realtime.mjs → dist/realtime.js} +108 -106
  139. package/dist/resilience.d.ts +15 -0
  140. package/dist/resilience.js +319 -0
  141. package/dist/schema-authority.d.ts +15 -0
  142. package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
  143. package/dist/service-deps.d.ts +17 -0
  144. package/{service-deps.mjs → dist/service-deps.js} +133 -130
  145. package/dist/service-isolation.d.ts +8 -0
  146. package/dist/service-isolation.js +76 -0
  147. package/dist/size-budget.d.ts +9 -0
  148. package/{size-budget.mjs → dist/size-budget.js} +27 -27
  149. package/dist/sonar-parity.d.ts +5 -0
  150. package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
  151. package/dist/spec-no-skip.d.ts +9 -0
  152. package/dist/spec-no-skip.js +81 -0
  153. package/dist/spec-quality.d.ts +10 -0
  154. package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
  155. package/dist/suppression.d.ts +26 -0
  156. package/{suppression.mjs → dist/suppression.js} +30 -45
  157. package/dist/temporal.d.ts +9 -0
  158. package/{temporal.mjs → dist/temporal.js} +75 -65
  159. package/dist/test-world.d.ts +28 -0
  160. package/{test-world.mjs → dist/test-world.js} +102 -83
  161. package/dist/testing.d.ts +51 -0
  162. package/dist/testing.js +368 -0
  163. package/dist/third-party-owner.d.ts +8 -0
  164. package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
  165. package/dist/transport.d.ts +24 -0
  166. package/{transport.mjs → dist/transport.js} +279 -240
  167. package/dist/type-safety.d.ts +25 -0
  168. package/dist/type-safety.js +297 -0
  169. package/dist/unit-spec.d.ts +30 -0
  170. package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
  171. package/dist/uploads.d.ts +9 -0
  172. package/{uploads.mjs → dist/uploads.js} +62 -54
  173. package/dist/user-copy.d.ts +9 -0
  174. package/{user-copy.mjs → dist/user-copy.js} +76 -67
  175. package/dist/webhooks.d.ts +16 -0
  176. package/{webhooks.mjs → dist/webhooks.js} +243 -231
  177. package/package.json +23 -8
  178. package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
  179. package/runtime/scripts/hfs/repo-identity.mjs +5 -4
  180. package/async-discipline.mjs +0 -83
  181. package/comments.mjs +0 -416
  182. package/edge-hardening.mjs +0 -139
  183. package/health-ready.mjs +0 -539
  184. package/jwt-alg.mjs +0 -45
  185. package/lib/ast.mjs +0 -88
  186. package/lib/import-source.mjs +0 -104
  187. package/lib/specifier.mjs +0 -27
  188. package/lib/subject-values.mjs +0 -55
  189. package/lib/types.mjs +0 -133
  190. package/log-safety.mjs +0 -303
  191. package/module-layering.mjs +0 -270
  192. package/naming.mjs +0 -251
  193. package/observability.mjs +0 -241
  194. package/resilience.mjs +0 -304
  195. package/service-isolation.mjs +0 -75
  196. package/spec-no-skip.mjs +0 -85
  197. package/testing.mjs +0 -384
  198. package/type-safety.mjs +0 -323
@@ -15,55 +15,56 @@
15
15
  * owner (like an app's `main.ts` and `platform`), and its readiness polling, deadlines and fake servers measure real
16
16
  * elapsed time against real processes, which a `FakeClock` cannot drive. A spec is not the world: specs stay refused.
17
17
  */
18
- import { hfsOf, inTestWorld } from "./lib/hfs.mjs"
19
- import { isOwnedBy } from "./lib/ports.mjs"
20
-
18
+ import { hfsOf, inTestWorld } from "./lib/hfs.js";
19
+ import { isOwnedBy } from "./lib/ports.js";
21
20
  /** The globals that carry an ambient reading, and the member of each that reads it (`null`: any member). */
22
- const AMBIENT = Object.freeze({ Date: "now", performance: "now", process: "hrtime", Temporal: "Now" })
23
-
21
+ const AMBIENT = Object.freeze({ Date: "now", performance: "now", process: "hrtime", Temporal: "Now" });
24
22
  /** Modules whose import of one of the globals above is the same ambient object (`node:perf_hooks` `performance`). */
25
- const AMBIENT_MODULES = new Set(["node:perf_hooks", "perf_hooks", "node:process", "process", "@js-temporal/polyfill", "temporal-polyfill"])
26
-
23
+ const AMBIENT_MODULES = new Set(["node:perf_hooks", "perf_hooks", "node:process", "process", "@js-temporal/polyfill", "temporal-polyfill"]);
27
24
  /** Modules whose named export IS an ambient reader (`import { hrtime } from "node:process"`). */
28
- const AMBIENT_EXPORTS = Object.freeze({ "node:process": ["hrtime"], process: ["hrtime"] })
29
-
25
+ const AMBIENT_EXPORTS = Object.freeze({ "node:process": ["hrtime"], process: ["hrtime"] });
26
+ /** The name an import specifier imports (an identifier or a string-literal export name). */
27
+ const importedName = (imported) => (imported.type === "Identifier" ? imported.name : imported.value);
30
28
  /** The variable a name resolves to from `node`'s scope, or null when it is a global. */
31
29
  const variableOf = (context, node, name) => {
32
- let scope = (context.sourceCode || context.getSourceCode()).getScope(node)
30
+ let scope = (context.sourceCode || context.getSourceCode()).getScope(node);
33
31
  while (scope) {
34
- const found = scope.set.get(name)
35
- if (found) return found
36
- scope = scope.upper
32
+ const found = scope.set.get(name);
33
+ if (found)
34
+ return found;
35
+ scope = scope.upper;
37
36
  }
38
- return null
39
- }
40
-
37
+ return null;
38
+ };
41
39
  /** Whether the root is the ambient global (or an import of it), not a local of the same name. */
42
40
  const isAmbientRoot = (context, root) => {
43
- if (!Object.hasOwn(AMBIENT, root.name)) return false
44
- if (root.viaGlobalThis) return true
45
- const variable = variableOf(context, root.node, root.name)
46
- if (!variable || variable.defs.length === 0) return true
47
- return variable.defs.every((def) => def.type === "ImportBinding" && AMBIENT_MODULES.has(def.parent.source.value))
48
- }
49
-
41
+ if (!Object.hasOwn(AMBIENT, root.name))
42
+ return false;
43
+ if (root.viaGlobalThis)
44
+ return true;
45
+ const variable = variableOf(context, root.node, root.name);
46
+ if (!variable || variable.defs.length === 0)
47
+ return true;
48
+ return variable.defs.every((def) => def.type === "ImportBinding" && def.parent.type === "ImportDeclaration" && AMBIENT_MODULES.has(def.parent.source.value));
49
+ };
50
50
  /** The property name of a non-computed or string-literal member access, else null. */
51
51
  const memberName = (node) => {
52
- if (!node.computed && node.property.type === "Identifier") return node.property.name
53
- if (node.computed && node.property.type === "Literal" && typeof node.property.value === "string") return node.property.value
54
- return null
55
- }
56
-
52
+ if (!node.computed && node.property.type === "Identifier")
53
+ return node.property.name;
54
+ if (node.computed && node.property.type === "Literal" && typeof node.property.value === "string")
55
+ return node.property.value;
56
+ return null;
57
+ };
57
58
  /** `globalThis.Date` and `Date` are the same root: `{ name, node, viaGlobalThis }`, or null when the node is neither. */
58
59
  const rootIdentifier = (node) => {
59
- if (node.type === "Identifier") return { name: node.name, node, viaGlobalThis: false }
60
+ if (node.type === "Identifier")
61
+ return { name: node.name, node, viaGlobalThis: false };
60
62
  if (node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "globalThis") {
61
- const name = memberName(node)
62
- return name ? { name, node, viaGlobalThis: true } : null
63
+ const name = memberName(node);
64
+ return name ? { name, node, viaGlobalThis: true } : null;
63
65
  }
64
- return null
65
- }
66
-
66
+ return null;
67
+ };
67
68
  /** Only `platform/clock` reads the ambient clock. */
68
69
  export const noAmbientClock = {
69
70
  meta: {
@@ -76,61 +77,70 @@ export const noAmbientClock = {
76
77
  },
77
78
  },
78
79
  create(context) {
79
- const hfs = hfsOf(context)
80
- const filename = context.filename || context.getFilename()
81
- if (isOwnedBy(hfs, filename, "platform", "clock") || inTestWorld(hfs, filename)) return {}
80
+ const hfs = hfsOf(context);
81
+ const filename = context.filename || context.getFilename();
82
+ if (isOwnedBy(hfs, filename, "platform", "clock") || inTestWorld(hfs, filename))
83
+ return {};
82
84
  const reportRoot = (node, root, member) => {
83
- if (!isAmbientRoot(context, root)) return
84
- const wanted = AMBIENT[root.name]
85
- if (member === wanted) context.report({ node, messageId: "now", data: { call: `${root.name}.${member}` } })
86
- }
85
+ if (!isAmbientRoot(context, root))
86
+ return;
87
+ const wanted = AMBIENT[root.name];
88
+ if (member === wanted)
89
+ context.report({ node, messageId: "now", data: { call: `${root.name}.${member}` } });
90
+ };
87
91
  return {
88
92
  MemberExpression(node) {
89
- const member = memberName(node)
90
- const root = rootIdentifier(node.object)
91
- if (!root || member === null) return
93
+ const member = memberName(node);
94
+ const root = rootIdentifier(node.object);
95
+ if (!root || member === null)
96
+ return;
92
97
  // `process.hrtime.bigint` is the same reader one member deeper: it is reported by the inner `process.hrtime`.
93
- reportRoot(node, root, member)
98
+ reportRoot(node, root, member);
94
99
  },
95
100
  VariableDeclarator(node) {
96
101
  // `const { now } = Date` and `const { hrtime } = process` read the clock through a destructured alias.
97
- if (node.id.type !== "ObjectPattern" || !node.init) return
98
- const root = rootIdentifier(node.init)
99
- if (!root) return
102
+ if (node.id.type !== "ObjectPattern" || !node.init)
103
+ return;
104
+ const root = rootIdentifier(node.init);
105
+ if (!root)
106
+ return;
100
107
  for (const property of node.id.properties) {
101
- if (property.type !== "Property" || property.computed) continue
102
- const key = property.key.type === "Identifier" ? property.key.name : property.key.value
103
- if (typeof key === "string") reportRoot(property, root, key)
108
+ if (property.type !== "Property" || property.computed)
109
+ continue;
110
+ const key = property.key.type === "Identifier" ? property.key.name : property.key.value;
111
+ if (typeof key === "string")
112
+ reportRoot(property, root, key);
104
113
  }
105
114
  },
106
115
  ImportDeclaration(node) {
107
- const banned = AMBIENT_EXPORTS[node.source.value]
108
- if (!banned) return
116
+ const banned = AMBIENT_EXPORTS[node.source.value];
117
+ if (!banned)
118
+ return;
109
119
  for (const specifier of node.specifiers) {
110
- if (specifier.type === "ImportSpecifier" && banned.includes(specifier.imported.name ?? specifier.imported.value)) {
111
- context.report({ node: specifier, messageId: "now", data: { call: `${specifier.imported.name ?? specifier.imported.value} from ${node.source.value}` } })
120
+ if (specifier.type === "ImportSpecifier" && banned.includes(importedName(specifier.imported))) {
121
+ context.report({ node: specifier, messageId: "now", data: { call: `${importedName(specifier.imported)} from ${node.source.value}` } });
112
122
  }
113
123
  }
114
124
  },
115
125
  NewExpression(node) {
116
- const root = rootIdentifier(node.callee)
117
- if (root && root.name === "Date" && isAmbientRoot(context, root) && node.arguments.length === 0) context.report({ node, messageId: "date" })
126
+ const root = rootIdentifier(node.callee);
127
+ if (root && root.name === "Date" && isAmbientRoot(context, root) && node.arguments.length === 0)
128
+ context.report({ node, messageId: "date" });
118
129
  },
119
130
  CallExpression(node) {
120
131
  // `Date()` called as a function returns the current time as a string: the same ambient read.
121
- const root = rootIdentifier(node.callee)
122
- if (root && root.name === "Date" && isAmbientRoot(context, root) && node.arguments.length === 0) context.report({ node, messageId: "date" })
132
+ const root = rootIdentifier(node.callee);
133
+ if (root && root.name === "Date" && isAmbientRoot(context, root) && node.arguments.length === 0)
134
+ context.report({ node, messageId: "date" });
123
135
  },
124
- }
136
+ };
125
137
  },
126
- }
127
-
138
+ };
128
139
  /** The rule this law contributes to the plugin. */
129
140
  export const rules = {
130
141
  "no-ambient-clock": noAmbientClock,
131
- }
132
-
142
+ };
133
143
  /** Starts at error: no baseline exists, and the repositories' fix lanes clear the debt with a Clock codemod. */
134
144
  export const recommended = {
135
145
  "starci-be/no-ambient-clock": "error",
136
- }
146
+ };
@@ -0,0 +1,28 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /**
3
+ * The world is the only infrastructure location. Refused in fixtures, integration, e2e and contract specs: importing a
4
+ * migration (a class declared in a `be.persistence` `migrations/` file, or a value whose type is an array of them) or
5
+ * anything the cli app declares; importing typeorm's `DataSource` or a testcontainers package; calling
6
+ * `runMigrations`/`synchronize`/`dropDatabase`/`createSchema`... on a typeorm receiver; constructing a container; writing
7
+ * `process.env`. Migration behaviour is tested by the e2e world.
8
+ */
9
+ export declare const testsInfraOnlyInWorld: RuleModule;
10
+ /**
11
+ * Nothing under `src/tests/` overrides the DI container: the repository's own services run real (`world.infra.<service>`) and
12
+ * external SaaS are network-edge fakes of the world (`world.fake.<provider>`), so our integrations' signing, parsing and retry code runs. Refused: `.override*(`, a provider
13
+ * object with `useValue`, and `jest.mock(`.
14
+ */
15
+ export declare const testsNoOverride: RuleModule;
16
+ /**
17
+ * The world an integration spec (`{ modules }`, with real peer apps beside them as `apps` when its client calls another app of
18
+ * ours) or an e2e spec (`{ apps }`, never `modules`) asks for; every such spec asks for one.
19
+ */
20
+ export declare const testWorldShape: RuleModule;
21
+ /** The rules this law contributes to the plugin. */
22
+ export declare const rules: {
23
+ "tests-infra-only-in-world": RuleModule;
24
+ "tests-no-override": RuleModule;
25
+ "test-world-shape": RuleModule;
26
+ };
27
+ /** Every rule of this law ships at `error`. */
28
+ export declare const recommended: Recommended;
@@ -17,23 +17,23 @@
17
17
  *
18
18
  * Receivers and origins are judged by type and by the slot of their declaring file, never by name.
19
19
  */
20
- import { hfsOf } from "./lib/hfs.mjs"
21
- import { inCli } from "./lib/persistence.mjs"
22
- import { isPackageType, typeOrigins } from "./lib/types.mjs"
23
-
20
+ import { hfsOf } from "./lib/hfs.js";
21
+ import { inCli } from "./lib/persistence.js";
22
+ import { isPackageType, typed, typeOrigins } from "./lib/types.js";
23
+ import { nameOrValue } from "./lib/ast.js";
24
24
  /** Every test slot under `src/tests/` except the world, where the infrastructure lives. */
25
- const OUTSIDE_WORLD = new Set(["be.tests.fixtures", "be.tests.integration", "be.tests.e2e", "be.tests.contract"])
25
+ const OUTSIDE_WORLD = new Set(["be.tests.fixtures", "be.tests.integration", "be.tests.e2e", "be.tests.contract"]);
26
26
  /** Every test slot under `src/tests/`. */
27
- const UNDER_TESTS = new Set([...OUTSIDE_WORLD, "be.tests.world"])
28
-
29
- const SCHEMA_CALLS = new Set(["runMigrations", "undoLastMigration", "synchronize", "dropDatabase", "createSchema", "showMigrations"])
30
- const TYPEORM_RECEIVERS = ["DataSource", "QueryRunner", "EntityManager"]
31
- const CONTAINER_PACKAGES = /^(?:testcontainers|@testcontainers\/[a-z0-9-]+)$/
27
+ const UNDER_TESTS = new Set([...OUTSIDE_WORLD, "be.tests.world"]);
28
+ const SCHEMA_CALLS = new Set(["runMigrations", "undoLastMigration", "synchronize", "dropDatabase", "createSchema", "showMigrations"]);
29
+ const TYPEORM_RECEIVERS = ["DataSource", "QueryRunner", "EntityManager"];
30
+ const CONTAINER_PACKAGES = /^(?:testcontainers|@testcontainers\/[a-z0-9-]+)$/;
32
31
  /** `process.env` itself (the global `process`). */
33
- const isProcessEnv = (node) => node?.type === "MemberExpression" && !node.computed && node.object.type === "Identifier" && node.object.name === "process" && node.property.name === "env"
32
+ const isProcessEnv = (node) => node?.type === "MemberExpression" && !node.computed && node.object.type === "Identifier" && node.object.name === "process" && node.property.name === "env";
34
33
  /** A member of `process.env`. */
35
- const isEnvMember = (node) => node?.type === "MemberExpression" && isProcessEnv(node.object)
36
-
34
+ const isEnvMember = (node) => node?.type === "MemberExpression" && isProcessEnv(node.object);
35
+ /** Whether the checker says a type is an array or a tuple (both are type references). */
36
+ const isArrayOrTuple = (checker, type) => Boolean(checker.isArrayType?.(type) || checker.isTupleType?.(type));
37
37
  /**
38
38
  * The world is the only infrastructure location. Refused in fixtures, integration, e2e and contract specs: importing a
39
39
  * migration (a class declared in a `be.persistence` `migrations/` file, or a value whose type is an array of them) or
@@ -54,57 +54,67 @@ export const testsInfraOnlyInWorld = {
54
54
  },
55
55
  },
56
56
  create(context) {
57
- const hfs = hfsOf(context)
58
- const filename = context.filename || context.getFilename()
59
- if (!OUTSIDE_WORLD.has(hfs.slotOf(filename))) return {}
60
- const isMigrationDecl = (file) => hfs.slotOf(file) === "be.persistence" && /\/migrations\/[^/]+$/.test(hfs.relative(file))
61
- const fromMigrate = (file) => inCli(hfs, file)
57
+ const hfs = hfsOf(context);
58
+ const filename = context.filename || context.getFilename();
59
+ if (!OUTSIDE_WORLD.has(hfs.slotOf(filename)))
60
+ return {};
61
+ const isMigrationDecl = (file) => hfs.slotOf(file) === "be.persistence" && /\/migrations\/[^/]+$/.test(hfs.relative(file));
62
+ const fromMigrate = (file) => inCli(hfs, file);
62
63
  const migrationTyped = (node) => {
63
- const services = context.sourceCode.parserServices
64
- const checker = services.program.getTypeChecker()
65
- const tsNode = services.esTreeNodeToTSNodeMap.get(node)
66
- if (!tsNode) return false
67
- let type = checker.getTypeAtLocation(tsNode)
68
- if (checker.isArrayType?.(type) || checker.isTupleType?.(type)) type = checker.getTypeArguments(type)[0] ?? type
69
- const parts = type?.isUnion?.() ? type.types : [type]
70
- return parts.some((part) => (part?.getSymbol?.()?.getDeclarations?.() ?? []).some((d) => isMigrationDecl(String(d.getSourceFile().fileName))))
71
- }
64
+ const { checker, toTs } = typed(context);
65
+ const tsNode = toTs(node);
66
+ if (!tsNode)
67
+ return false;
68
+ let type = checker.getTypeAtLocation(tsNode);
69
+ if (isArrayOrTuple(checker, type))
70
+ type = checker.getTypeArguments(type)[0] ?? type;
71
+ const parts = type?.isUnion?.() ? type.types : [type];
72
+ return parts.some((part) => (part?.getSymbol?.()?.getDeclarations?.() ?? []).some((d) => isMigrationDecl(String(d.getSourceFile().fileName))));
73
+ };
72
74
  return {
73
75
  ImportDeclaration(node) {
74
- const source = String(node.source.value)
75
- if (CONTAINER_PACKAGES.test(source)) return context.report({ node, messageId: "infra" })
76
- if (source === "typeorm" && node.specifiers.some((s) => s.type === "ImportSpecifier" && (s.imported.name ?? s.imported.value) === "DataSource")) return context.report({ node, messageId: "infra" })
76
+ const source = String(node.source.value);
77
+ if (CONTAINER_PACKAGES.test(source))
78
+ return context.report({ node, messageId: "infra" });
79
+ if (source === "typeorm" && node.specifiers.some((s) => s.type === "ImportSpecifier" && nameOrValue(s.imported) === "DataSource"))
80
+ return context.report({ node, messageId: "infra" });
77
81
  for (const specifier of node.specifiers) {
78
- const origins = typeOrigins(context, specifier.local)
79
- if (origins.some((o) => isMigrationDecl(o.file) || fromMigrate(o.file)) || migrationTyped(specifier.local)) return context.report({ node: specifier, messageId: "migration" })
82
+ const origins = typeOrigins(context, specifier.local);
83
+ if (origins.some((o) => isMigrationDecl(o.file) || fromMigrate(o.file)) || migrationTyped(specifier.local))
84
+ return context.report({ node: specifier, messageId: "migration" });
80
85
  }
81
- return undefined
86
+ return undefined;
82
87
  },
83
88
  CallExpression(node) {
84
- const callee = node.callee
89
+ const callee = node.callee;
85
90
  if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.object.name === "Object" && callee.property.name === "assign") {
86
- if (isProcessEnv(node.arguments[0])) context.report({ node, messageId: "env" })
87
- return
91
+ if (isProcessEnv(node.arguments[0]))
92
+ context.report({ node, messageId: "env" });
93
+ return;
88
94
  }
89
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier") return
90
- if (!SCHEMA_CALLS.has(callee.property.name)) return
91
- if (TYPEORM_RECEIVERS.some((name) => isPackageType(context, callee.object, name, "typeorm"))) context.report({ node, messageId: "call", data: { name: callee.property.name } })
95
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
96
+ return;
97
+ if (!SCHEMA_CALLS.has(callee.property.name))
98
+ return;
99
+ if (TYPEORM_RECEIVERS.some((name) => isPackageType(context, callee.object, name, "typeorm")))
100
+ context.report({ node, messageId: "call", data: { name: callee.property.name } });
92
101
  },
93
102
  NewExpression(node) {
94
- if (typeOrigins(context, node.callee).some((o) => o.module && CONTAINER_PACKAGES.test(o.module))) context.report({ node, messageId: "infra" })
103
+ if (typeOrigins(context, node.callee).some((o) => o.module && CONTAINER_PACKAGES.test(o.module)))
104
+ context.report({ node, messageId: "infra" });
95
105
  },
96
106
  AssignmentExpression(node) {
97
- if (isEnvMember(node.left)) context.report({ node, messageId: "env" })
107
+ if (isEnvMember(node.left))
108
+ context.report({ node, messageId: "env" });
98
109
  },
99
110
  UnaryExpression(node) {
100
- if (node.operator === "delete" && isEnvMember(node.argument)) context.report({ node, messageId: "env" })
111
+ if (node.operator === "delete" && isEnvMember(node.argument))
112
+ context.report({ node, messageId: "env" });
101
113
  },
102
- }
114
+ };
103
115
  },
104
- }
105
-
106
- const OVERRIDES = new Set(["overrideProvider", "overrideModule", "overrideGuard", "overrideInterceptor", "overrideFilter", "overridePipe"])
107
-
116
+ };
117
+ const OVERRIDES = new Set(["overrideProvider", "overrideModule", "overrideGuard", "overrideInterceptor", "overrideFilter", "overridePipe"]);
108
118
  /**
109
119
  * Nothing under `src/tests/` overrides the DI container: the repository's own services run real (`world.infra.<service>`) and
110
120
  * external SaaS are network-edge fakes of the world (`world.fake.<provider>`), so our integrations' signing, parsing and retry code runs. Refused: `.override*(`, a provider
@@ -120,29 +130,34 @@ export const testsNoOverride = {
120
130
  },
121
131
  },
122
132
  create(context) {
123
- if (!UNDER_TESTS.has(hfsOf(context).slotOf(context.filename || context.getFilename()))) return {}
133
+ if (!UNDER_TESTS.has(hfsOf(context).slotOf(context.filename || context.getFilename())))
134
+ return {};
124
135
  return {
125
136
  CallExpression(node) {
126
- const callee = node.callee
127
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier") return
128
- if (OVERRIDES.has(callee.property.name)) context.report({ node, messageId: "override", data: { what: callee.property.name } })
129
- else if (callee.object.type === "Identifier" && callee.object.name === "jest" && callee.property.name === "mock") context.report({ node, messageId: "override", data: { what: "jest.mock" } })
137
+ const callee = node.callee;
138
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
139
+ return;
140
+ if (OVERRIDES.has(callee.property.name))
141
+ context.report({ node, messageId: "override", data: { what: callee.property.name } });
142
+ else if (callee.object.type === "Identifier" && callee.object.name === "jest" && callee.property.name === "mock")
143
+ context.report({ node, messageId: "override", data: { what: "jest.mock" } });
130
144
  },
131
145
  Property(node) {
132
- const key = node.key.type === "Identifier" ? node.key.name : node.key.value
133
- if (key !== "useValue" || node.parent.type !== "ObjectExpression") return
134
- if (node.parent.properties.some((p) => p.type === "Property" && (p.key.name ?? p.key.value) === "provide")) context.report({ node, messageId: "override", data: { what: "useValue" } })
146
+ const key = node.key.type === "Identifier" ? node.key.name : "value" in node.key ? node.key.value : undefined;
147
+ if (key !== "useValue" || node.parent.type !== "ObjectExpression")
148
+ return;
149
+ if (node.parent.properties.some((p) => p.type === "Property" && nameOrValue(p.key) === "provide"))
150
+ context.report({ node, messageId: "override", data: { what: "useValue" } });
135
151
  },
136
- }
152
+ };
137
153
  },
138
- }
139
-
154
+ };
140
155
  /** The name of a property key written as an identifier or a literal (`{ apps }`, `{ "apps": ... }`, `{ ["apps"]: ... }`); null for any computed expression. */
141
156
  const plainKey = (property) => {
142
- if (property.key.type === "Literal") return String(property.key.value)
143
- return property.key.type === "Identifier" && !property.computed ? property.key.name : null
144
- }
145
-
157
+ if (property.key.type === "Literal")
158
+ return String(property.key.value);
159
+ return property.key.type === "Identifier" && !property.computed ? property.key.name : null;
160
+ };
146
161
  /**
147
162
  * The world an integration spec (`{ modules }`, with real peer apps beside them as `apps` when its client calls another app of
148
163
  * ours) or an e2e spec (`{ apps }`, never `modules`) asks for; every such spec asks for one.
@@ -160,42 +175,46 @@ export const testWorldShape = {
160
175
  },
161
176
  },
162
177
  create(context) {
163
- const slot = hfsOf(context).slotOf(context.filename || context.getFilename())
164
- const wants = slot === "be.tests.integration" ? "modules" : slot === "be.tests.e2e" ? "apps" : null
165
- if (!wants) return {}
166
- let seen = false
178
+ const slot = hfsOf(context).slotOf(context.filename || context.getFilename());
179
+ const wants = slot === "be.tests.integration" ? "modules" : slot === "be.tests.e2e" ? "apps" : null;
180
+ if (!wants)
181
+ return {};
182
+ let seen = false;
167
183
  return {
168
184
  CallExpression(node) {
169
- if (node.callee.type !== "Identifier" || node.callee.name !== "useTestWorld") return
170
- seen = true
171
- const options = node.arguments[0]
172
- if (options?.type !== "ObjectExpression") return context.report({ node, messageId: "literal" })
173
- const keys = []
185
+ if (node.callee.type !== "Identifier" || node.callee.name !== "useTestWorld")
186
+ return;
187
+ seen = true;
188
+ const options = node.arguments[0];
189
+ if (options?.type !== "ObjectExpression")
190
+ return context.report({ node, messageId: "literal" });
191
+ const keys = [];
174
192
  for (const property of options.properties) {
175
- const key = property.type === "Property" ? plainKey(property) : null
176
- if (key === null) return context.report({ node: property, messageId: "literal" })
177
- keys.push(key)
193
+ const key = property.type === "Property" ? plainKey(property) : null;
194
+ if (key === null)
195
+ return context.report({ node: property, messageId: "literal" });
196
+ keys.push(key);
178
197
  }
179
- const refused = wants === "modules" ? !keys.includes("modules") : !keys.includes("apps") || keys.includes("modules")
180
- if (refused) context.report({ node, messageId: wants })
198
+ const refused = wants === "modules" ? !keys.includes("modules") : !keys.includes("apps") || keys.includes("modules");
199
+ if (refused)
200
+ context.report({ node, messageId: wants });
181
201
  },
182
202
  "Program:exit"(node) {
183
- if (!seen) context.report({ node, loc: { line: 1, column: 0 }, messageId: "missing" })
203
+ if (!seen)
204
+ context.report({ node, loc: { line: 1, column: 0 }, messageId: "missing" });
184
205
  },
185
- }
206
+ };
186
207
  },
187
- }
188
-
208
+ };
189
209
  /** The rules this law contributes to the plugin. */
190
210
  export const rules = {
191
211
  "tests-infra-only-in-world": testsInfraOnlyInWorld,
192
212
  "tests-no-override": testsNoOverride,
193
213
  "test-world-shape": testWorldShape,
194
- }
195
-
214
+ };
196
215
  /** Every rule of this law ships at `error`. */
197
216
  export const recommended = {
198
217
  "starci-be/tests-infra-only-in-world": "error",
199
218
  "starci-be/tests-no-override": "error",
200
219
  "starci-be/test-world-shape": "error",
201
- }
220
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The rules that hold `knowledge/patterns/be/test.yaml` (catalog R47 `BE_TEST_TOPOLOGY` and R48 `BE_SPEC_QUALITY`).
3
+ *
4
+ * MOST OF THAT LAW IS NOT MACHINE-CHECKABLE, and pretending otherwise would be worse than checking nothing. No rule
5
+ * can tell whether a file represents a business flow, whether the unhappy path it covers drags a critical flow
6
+ * behind it, or whether the decision branches are covered - those are read by a person. What a rule CAN see is a
7
+ * shape that is wrong on its face regardless of intent:
8
+ *
9
+ * - a spec whose every assertion is about a call rather than a result (`no-call-only-spec`);
10
+ * - a unit spec of anything but a service, a service with no `<name>.service.spec.ts` beside it, a service spec with no
11
+ * service beside it, and a file of a kind the convention bans (`.test.ts`, `.int-spec.ts`, `.harness-spec.ts`)
12
+ * (`unit-test-colocated`);
13
+ * - an e2e that never reads persisted state back, and an e2e that reaches a model provider
14
+ * (`e2e-asserts-persisted-state`, `no-model-call-in-e2e`);
15
+ * - an e2e filename that names an API shape instead of a business flow (`no-api-shaped-e2e-filename`);
16
+ * - a model stub that returns a bare marker instead of a payload the production parser can parse
17
+ * (`no-marker-model-stub`).
18
+ *
19
+ * Every path question is asked of the slot manifest (`hfsOf(context)`): a rule never tests a path with a regular
20
+ * expression. A file name is a role vocabulary of the slots (`*.spec.ts`, `*.e2e-spec.ts`, `*.handler.ts`) and is read
21
+ * from the basename. A state read is recognised by the TYPE of the receiver (`EntityManager`, `DataSource`,
22
+ * `QueryRunner` of `typeorm`), never by its variable name.
23
+ */
24
+ import type { Recommended, RuleModule } from "./lib/rule.js";
25
+ /** A spec whose every assertion is about a call restates the source instead of testing it. */
26
+ export declare const noCallOnlySpec: RuleModule;
27
+ /**
28
+ * Unit specs are for services only: every `<name>.service.ts` has its `<name>.service.spec.ts` beside it, every unit spec is
29
+ * one of those, and there are no kinds of test file beyond `spec`, `e2e-spec`, `integration-spec` and `contract-spec`.
30
+ */
31
+ export declare const unitTestColocated: RuleModule;
32
+ /** An end-to-end spec that never reads state back proves only that the server replied. */
33
+ export declare const e2eAssertsPersistedState: RuleModule;
34
+ /** An e2e never calls a model; only a contract spec (`src/tests/contract/`, suffix `.contract-spec.ts`) may reach a provider. */
35
+ export declare const noModelCallInE2e: RuleModule;
36
+ /** An e2e file is one business flow; the filename may not be an API-shape noun wearing its clothes. */
37
+ export declare const noApiShapedE2eFilename: RuleModule;
38
+ /** The world's default model stub returns a payload the production parser can actually parse. */
39
+ export declare const noMarkerModelStub: RuleModule;
40
+ /** The rules this law contributes to the plugin. */
41
+ /** The rules this law contributes to the plugin. */
42
+ export declare const rules: {
43
+ "no-call-only-spec": RuleModule;
44
+ "unit-test-colocated": RuleModule;
45
+ "e2e-asserts-persisted-state": RuleModule;
46
+ "no-model-call-in-e2e": RuleModule;
47
+ "no-api-shaped-e2e-filename": RuleModule;
48
+ "no-marker-model-stub": RuleModule;
49
+ };
50
+ /** Every rule of this law ships at `error`. */
51
+ export declare const recommended: Recommended;