@starci/eslint-canon-be 3.18.4 → 3.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/comments.js +1 -1
  4. package/dist/explicit-surface.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/jwt-alg.js +1 -1
  7. package/dist/lib/edition.d.ts +1 -1
  8. package/dist/lib/edition.js +1 -1
  9. package/dist/lib/hfs-view.d.ts +5 -0
  10. package/dist/lib/hfs.d.ts +0 -6
  11. package/dist/lib/hfs.js +7 -5
  12. package/dist/lib/runtime-root.d.ts +6 -1
  13. package/dist/lib/runtime-root.js +8 -2
  14. package/dist/lib/subject-values.js +1 -1
  15. package/dist/module-layering.js +2 -2
  16. package/dist/project-graph.js +1 -1
  17. package/dist/schema-authority.js +66 -2
  18. package/dist/third-party-owner.js +1 -1
  19. package/package.json +3 -1
  20. package/runtime/bundle.json +1 -190
  21. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  22. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  23. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  24. package/runtime/config.example.yaml +0 -194
  25. package/runtime/engine/by-code-unit.mjs +0 -12
  26. package/runtime/engine/config.mjs +0 -461
  27. package/runtime/engine/invalid-config.mjs +0 -15
  28. package/runtime/engine/model-config.mjs +0 -112
  29. package/runtime/engine/orca-config.mjs +0 -34
  30. package/runtime/engine/plain-object.mjs +0 -5
  31. package/runtime/engine/release-config.mjs +0 -32
  32. package/runtime/engine/removed-vocabulary.mjs +0 -27
  33. package/runtime/engine/resources-config.mjs +0 -59
  34. package/runtime/engine/runtime-root.mjs +0 -138
  35. package/runtime/engine/secrets.mjs +0 -202
  36. package/runtime/engine/sonar-config.mjs +0 -24
  37. package/runtime/engine/temp-root.mjs +0 -26
  38. package/runtime/engine/yaml.mjs +0 -161
  39. package/runtime/knowledge/grammars/index.yaml +0 -114
  40. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  41. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  42. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  43. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  44. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  45. package/runtime/knowledge/sonar-gate.yaml +0 -151
  46. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  47. package/runtime/modules/models/registry.yaml +0 -221
  48. package/runtime/modules/models/runtimes.yaml +0 -556
  49. package/runtime/modules/models/tiers.yaml +0 -66
  50. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  51. package/runtime/scripts/api/git/config-get.mjs +0 -9
  52. package/runtime/scripts/api/git/diff.mjs +0 -4
  53. package/runtime/scripts/api/git/lib.mjs +0 -80
  54. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  55. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  56. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  57. package/runtime/scripts/api/git/remote.mjs +0 -4
  58. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  59. package/runtime/scripts/api/git/show.mjs +0 -5
  60. package/runtime/scripts/api/git/tag.mjs +0 -4
  61. package/runtime/scripts/hfs/allows.mjs +0 -77
  62. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  63. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  64. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  65. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  66. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  67. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  68. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  69. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  70. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  71. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  72. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  73. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  74. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  75. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  76. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  77. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  78. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  79. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  80. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  81. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  82. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  83. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  84. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  85. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  86. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  87. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  88. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  89. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  90. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  91. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  92. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  93. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  94. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  95. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  96. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  97. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  98. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  99. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  100. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  101. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  102. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  103. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  104. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  105. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  106. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  107. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  108. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  109. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  110. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  111. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  112. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  113. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  114. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  115. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  116. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  117. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  118. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  119. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  120. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  121. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  122. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  123. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  124. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  125. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  126. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  127. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  128. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  129. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  130. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  132. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  133. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  134. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  135. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  136. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  137. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  138. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  139. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  140. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  141. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  142. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  143. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  144. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  145. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  146. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  147. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  148. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  149. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  150. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  151. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  152. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  153. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  154. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  155. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  156. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  157. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  158. package/runtime/scripts/hfs/param-names.mjs +0 -13
  159. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  160. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  161. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  162. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  163. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  164. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  165. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  166. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  167. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  168. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  169. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  170. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  171. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  172. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  173. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  174. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  175. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  176. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  177. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  178. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  179. package/runtime/scripts/hfs/slots.mjs +0 -306
  180. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  181. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  182. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  183. package/runtime/scripts/hfs/view.mjs +0 -180
  184. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  185. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  186. package/runtime/scripts/lib/env.mjs +0 -18
  187. package/runtime/scripts/lib/event-contract.mjs +0 -102
  188. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  189. package/runtime/scripts/lib/git.mjs +0 -35
  190. package/runtime/scripts/lib/glob.mjs +0 -32
  191. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  192. package/runtime/scripts/lib/i18n.mjs +0 -82
  193. package/runtime/scripts/lib/in-order.mjs +0 -90
  194. package/runtime/scripts/lib/json-clone.mjs +0 -70
  195. package/runtime/scripts/lib/json.mjs +0 -44
  196. package/runtime/scripts/lib/language.mjs +0 -233
  197. package/runtime/scripts/lib/list.mjs +0 -26
  198. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  199. package/runtime/scripts/lib/package-at.mjs +0 -62
  200. package/runtime/scripts/lib/path-key.mjs +0 -124
  201. package/runtime/scripts/lib/read-text.mjs +0 -47
  202. package/runtime/scripts/lib/regex.mjs +0 -3
  203. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  204. package/runtime/scripts/lib/same-text.mjs +0 -4
  205. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  206. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  207. package/runtime/scripts/lib/stack-services.mjs +0 -191
  208. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  209. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  210. package/runtime/scripts/lib/walk.mjs +0 -45
  211. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,185 +0,0 @@
1
- import path from 'node:path';
2
- import { normalizedSymbol } from './ast-walks.mjs';
3
- export const keyOf = (ts, property) => (ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) ? property.name.text : null;
4
- const exported = (ts, statement) => statement.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
5
- /** The directly defined functions among the declarations of an exported variable statement; other values are not callable. */
6
- function callableVariables(ts, statement) {
7
- const names = [];
8
- for (const declaration of statement.declarationList.declarations) {
9
- const initializer = declaration.initializer;
10
- if (ts.isIdentifier(declaration.name) && initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)))
11
- names.push(declaration.name.text);
12
- }
13
- return names;
14
- }
15
- /** The callable exports of one statement: an overload signature has no body and collapses into its implementation. */
16
- function callableExports(ts, statement) {
17
- if (!exported(ts, statement))
18
- return [];
19
- if (ts.isFunctionDeclaration(statement))
20
- return statement.name && statement.body ? [statement.name.text] : [];
21
- return ts.isVariableStatement(statement) ? callableVariables(ts, statement) : [];
22
- }
23
- /** Named value re-exports count only when the checker resolves an actual function implementation. */
24
- function callableReexports(ts, checker, statement) {
25
- if (!ts.isExportDeclaration(statement) || statement.isTypeOnly || !statement.exportClause || !ts.isNamedExports(statement.exportClause))
26
- return [];
27
- return statement.exportClause.elements.filter(element => !element.isTypeOnly && (normalizedSymbol(ts, checker, element.name)?.declarations ?? []).some(declaration => {
28
- if (declaration.getSourceFile().isDeclarationFile)
29
- return false;
30
- if (ts.isFunctionDeclaration(declaration))
31
- return Boolean(declaration.body);
32
- return ts.isVariableDeclaration(declaration) && Boolean(declaration.initializer
33
- && (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)));
34
- })).map(element => element.name.text);
35
- }
36
- /**
37
- * The callable subset of a function subject's exports, including named re-exports resolved to real implementations. Constants,
38
- * enums, objects, type-only exports and bodyless declarations do not count; a class or a default-export assignment keeps the
39
- * class-provider check (null), as does a module with no callable export.
40
- */
41
- export function functionSubjectExports(ts, sourceFile, checker) {
42
- const names = [];
43
- for (const statement of sourceFile.statements) {
44
- if (ts.isClassDeclaration(statement) || ts.isExportAssignment(statement))
45
- return null;
46
- for (const name of [...callableExports(ts, statement), ...callableReexports(ts, checker, statement)])
47
- if (!names.includes(name))
48
- names.push(name);
49
- }
50
- return names.length ? names : null;
51
- }
52
- const decoratorsOf = (ts, node) => (ts.canHaveDecorators(node) ? ts.getDecorators(node) ?? [] : []);
53
- /** A value object: an undecorated class whose constructor parameters carry no injection token, so Nest never builds it. */
54
- function isValueObjectClass(ts, declaration) {
55
- if (decoratorsOf(ts, declaration).length > 0)
56
- return false;
57
- const constructors = declaration.members.filter((member) => ts.isConstructorDeclaration(member));
58
- return constructors.every(constructor => constructor.parameters.every(parameter => decoratorsOf(ts, parameter).length === 0));
59
- }
60
- /** The names of the value-object classes a module exports, or null when it exports a class that is not one (or none). */
61
- export function valueObjectSubjects(ts, sourceFile) {
62
- const classes = sourceFile.statements.filter((statement) => ts.isClassDeclaration(statement) && Boolean(statement.name) && exported(ts, statement));
63
- if (!classes.length || !classes.every(declaration => isValueObjectClass(ts, declaration)))
64
- return null;
65
- return classes.map(declaration => declaration.name.text);
66
- }
67
- /** The value of one literal object property. */
68
- export const propertyValue = (ts, object, key) => {
69
- const property = object.properties.find(item => keyOf(ts, item) === key);
70
- return property && ts.isPropertyAssignment(property) ? property.initializer : null;
71
- };
72
- /** A literal value object maps every exported function to its real sibling import. */
73
- function realFunctions(ts, value, names, imports, rel, serviceRel) {
74
- if (!value || !ts.isObjectLiteralExpression(value) || value.properties.length !== names.length)
75
- return false;
76
- const remaining = new Set(names);
77
- for (const property of value.properties) {
78
- const key = keyOf(ts, property);
79
- const identifier = ts.isShorthandPropertyAssignment(property) ? property.name : ts.isPropertyAssignment(property) ? property.initializer : undefined;
80
- if (key === null || !remaining.delete(key) || !identifier || !ts.isIdentifier(identifier))
81
- return false;
82
- const binding = imports.get(identifier.text);
83
- if (!binding || binding.name !== key || !binding.module.startsWith('.'))
84
- return false;
85
- const target = path.posix.normalize(path.posix.join(path.posix.dirname(rel), binding.module)).replace(/\.[cm]?[jt]s$/u, '');
86
- if (target !== serviceRel.replace(/\.ts$/u, ''))
87
- return false;
88
- }
89
- return remaining.size === 0;
90
- }
91
- /** Every node satisfying a predicate, within one spec. */
92
- function matchingNodes(ts, root, predicate) {
93
- const found = [];
94
- const visit = (node) => {
95
- if (predicate(node))
96
- found.push(node);
97
- ts.forEachChild(node, visit);
98
- };
99
- visit(root);
100
- return found;
101
- }
102
- /** The declared variable initialized by an expression, including its await and call chain. */
103
- function initializedVariable(ts, expression) {
104
- let cursor = expression;
105
- let compiled = false;
106
- let awaited = false;
107
- while (cursor.parent && (ts.isAwaitExpression(cursor.parent) || ts.isPropertyAccessExpression(cursor.parent) || ts.isCallExpression(cursor.parent))) {
108
- cursor = cursor.parent;
109
- if (ts.isAwaitExpression(cursor))
110
- awaited = true;
111
- if (ts.isCallExpression(cursor) && ts.isPropertyAccessExpression(cursor.expression) && cursor.expression.name.text === 'compile')
112
- compiled = true;
113
- }
114
- if (!compiled || !awaited)
115
- return null;
116
- const declaration = cursor.parent;
117
- return declaration && ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) ? declaration.name.text : null;
118
- }
119
- /** The subject variable receiving module.get, whether declared there or assigned in beforeEach. */
120
- function retrievedVariable(ts, call) {
121
- let cursor = call;
122
- while (cursor.parent && (ts.isAwaitExpression(cursor.parent) || ts.isParenthesizedExpression(cursor.parent)))
123
- cursor = cursor.parent;
124
- const parent = cursor.parent;
125
- if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name))
126
- return parent.name.text;
127
- if (parent && ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(parent.left))
128
- return parent.left.text;
129
- return null;
130
- }
131
- /** The `.text` of a node's `name`, when the node has an identifier-like name. */
132
- function nameTextOf(node) {
133
- // reason: a loose compiler-API node; only declarations carry a `name`, and its `.text` is read when it is a string
134
- const name = node?.name;
135
- return typeof name?.text === 'string' ? name.text : undefined;
136
- }
137
- /** A helper returning the retrieved subject is followed to the variable receiving its result. */
138
- function retrievedSubjects(ts, read, sourceFile) {
139
- const direct = retrievedVariable(ts, read);
140
- if (direct)
141
- return [direct];
142
- if (!read.parent || !ts.isReturnStatement(read.parent))
143
- return [];
144
- let helper = read.parent;
145
- while (helper.parent && !ts.isFunctionLike(helper))
146
- helper = helper.parent;
147
- const name = nameTextOf(helper) ?? nameTextOf(helper.parent);
148
- if (!name)
149
- return [];
150
- return matchingNodes(ts, sourceFile, node => ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === name)
151
- .map(node => retrievedVariable(ts, node)).filter((variable) => Boolean(variable));
152
- }
153
- /** The same compiled module retrieves the matching token and its result actually calls a subject function. */
154
- function retrievedSubjectUsed(ts, call, token, names) {
155
- const moduleName = initializedVariable(ts, call);
156
- if (!moduleName)
157
- return false;
158
- const sourceFile = call.getSourceFile();
159
- const reads = matchingNodes(ts, sourceFile, node => {
160
- if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
161
- return false;
162
- const member = node.expression;
163
- const first = node.arguments[0];
164
- return ts.isIdentifier(member.expression) && member.expression.text === moduleName && member.name.text === 'get'
165
- && node.arguments.length === 1 && first !== undefined && ts.isIdentifier(first) && first.text === token.text;
166
- });
167
- return reads.some(read => {
168
- const subjects = retrievedSubjects(ts, read, sourceFile);
169
- return matchingNodes(ts, sourceFile, node => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)
170
- && ts.isIdentifier(node.expression.expression) && subjects.includes(node.expression.expression.text) && names.includes(node.expression.name.text)).length > 0;
171
- });
172
- }
173
- /** A pure function service has exactly one real subject value provider, retrieved and exercised through Nest. */
174
- export function checkFunctionSubject({ ts, rel, serviceRel, imports, call, list, names, report }) {
175
- const provider = list.elements[0];
176
- const shape = provider && ts.isObjectLiteralExpression(provider) && provider.properties.length === 2;
177
- const token = shape ? propertyValue(ts, provider, 'provide') : null;
178
- const value = shape ? propertyValue(ts, provider, 'useValue') : null;
179
- if (list.elements.length !== 1 || !token || !ts.isIdentifier(token) || !realFunctions(ts, value, names, imports, rel, serviceRel)) {
180
- report(provider ?? list, `${rel}: a function-only subject needs exactly one { provide: TOKEN, useValue: { ...realFunctions } } provider containing every callable export imported from ./${path.posix.basename(serviceRel, '.ts')}.`);
181
- return;
182
- }
183
- if (!retrievedSubjectUsed(ts, call, token, names))
184
- report(list, `${rel}: retrieve the function subject with moduleRef.get(TOKEN) from this compiled testing module and exercise a function on the returned subject.`);
185
- }
@@ -1,77 +0,0 @@
1
- import { canonical } from './config.mjs';
2
- import { relativePath } from './typescript.mjs';
3
- /**
4
- * The file and owner graph the HFS architecture checks share. Every production source file the TypeScript context
5
- * loaded becomes a node classified by the slot manifest (config.hfs is the resolver of scripts/hfs/slots.mjs);
6
- * every import, re-export and type-only import between two of them becomes an edge. Nothing here judges: the checks
7
- * in tiers.mjs, reachability.mjs, dead-exports.mjs, required-files.mjs and clones.mjs read it.
8
- *
9
- * graph.profile 'be' | 'fe'
10
- * graph.resolver the slot resolver (config.hfs)
11
- * graph.files Map<rel, {abs, rel, slot, status, tier, owner, sourceFile}> owner: {slot, root, bindings} | null
12
- * graph.edges [{from, to, runtime, line, column, specifier, reexport, edge}] (rel paths, both in graph.files)
13
- * graph.unit(rel) the owner unit key ("<slot>:<root>") of a file: its owner, else its slot instance
14
- * graph.ownerRoots Map<unitKey, {slot, root, tier}> of every owner instance that holds a graph file
15
- * graph.abs(file) the repository-relative path of an absolute file the graph holds, else null
16
- */
17
- // Every production source file the TypeScript context loaded, as a graph.files node keyed by its repository-relative path.
18
- const collectFiles = (config, context, resolver) => {
19
- const files = new Map();
20
- const absolute = new Map();
21
- for (const sourceFile of context.files) {
22
- const file = canonical(sourceFile.fileName);
23
- const rel = relativePath(config.root, file);
24
- if (rel.startsWith('..'))
25
- continue;
26
- const classified = resolver.classifyPath(rel);
27
- files.set(rel, {
28
- abs: file,
29
- rel,
30
- slot: classified.slot ?? null,
31
- status: classified.status,
32
- tier: classified.slot ? resolver.tierOf(rel) : null,
33
- owner: classified.slot ? resolver.ownerOf(rel) : null,
34
- sourceFile,
35
- });
36
- absolute.set(file, rel);
37
- }
38
- return { files, absolute };
39
- };
40
- // Every import, re-export and type-only import between two graphed files, as rel-path edges.
41
- const collectEdges = (context, absolute) => {
42
- const edges = [];
43
- for (const [file, list] of context.edges) {
44
- const from = absolute.get(file);
45
- if (!from)
46
- continue;
47
- for (const edge of list) {
48
- const to = absolute.get(edge.to);
49
- if (!to || to === from)
50
- continue;
51
- edges.push({ from, to, runtime: edge.runtime, line: edge.line, column: edge.column, specifier: edge.specifier, reexport: Boolean(edge.reexport), edge });
52
- }
53
- }
54
- return edges;
55
- };
56
- export function buildHfsGraph(config, context) {
57
- const resolver = config.hfs;
58
- const { files, absolute } = collectFiles(config, context, resolver);
59
- const edges = collectEdges(context, absolute);
60
- const unit = (rel) => {
61
- const node = files.get(rel);
62
- if (!node)
63
- return null;
64
- if (node.owner)
65
- return `${node.owner.slot}:${node.owner.root}`;
66
- const classified = resolver.classifyPath(rel);
67
- return classified.slot ? `${classified.slot}:${classified.root}` : null;
68
- };
69
- const ownerRoots = new Map();
70
- for (const node of files.values())
71
- if (node.owner) {
72
- const key = `${node.owner.slot}:${node.owner.root}`;
73
- if (!ownerRoots.has(key))
74
- ownerRoots.set(key, { slot: node.owner.slot, root: node.owner.root, tier: resolver.slot(node.owner.slot)?.tier ?? '' }); // the owner slot came from resolver.ownerOf, so the manifest holds it
75
- }
76
- return { profile: resolver.repo.profile, resolver, files, edges, unit, ownerRoots, abs: (file) => absolute.get(file) ?? null };
77
- }
@@ -1,394 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { lsFiles } from '../../api/git/ls-files.mjs'; import { revParseQuery } from '../../api/git/rev-parse-query.mjs'; import { configGet } from '../../api/git/config-get.mjs'; import { gitOutputOf } from '../../lib/git.mjs';
4
- import { braceVariants } from '../../lib/glob.mjs';
5
- import { hooksDirState } from '../../lib/git-hooks-dir.mjs';
6
- import { createSlotResolver, loadSlotManifest, openHfs } from '../slots.mjs';
7
- import { isFeTestPath } from '../rules/fe-no-tests.mjs';
8
- import { byCodeUnit } from '../../lib/list.mjs';
9
- import { checkRepoPresentationImpl } from './presentation.mjs';
10
- import { e2eInAutomaticGate, testTreesOutOfDefaultProgram } from './automatic-gates.mjs';
11
- /**
12
- * HFS repository-tree check (knowledge/hfs/README.md): every StarCi repository is an
13
- * apps/<app>/ monorepo on npm with a fixed root-entry allowlist; backend composition lives in
14
- * apps/<app>/src and shared source under src/{features,modules,tests} with the three module tiers
15
- * domain/platform/integrations; frontend source lives only under apps/<app>/src. The judged tree is
16
- * the tracked one (`git ls-files` from the target root); a target outside a work tree falls back to
17
- * the filesystem view so fixtures and un-tracked checkouts are judged the same way.
18
- */
19
-
20
- export const HFS_RULE_IDS = [
21
- 'BE_TEST_TOPOLOGY',
22
- 'HFS_APPS_REQUIRED',
23
- 'HFS_APP_LAYOUT_INVALID',
24
- 'HFS_E2E_IN_AUTOMATIC_GATE',
25
- 'HFS_HOOKS_NOT_INSTALLED',
26
- 'HFS_HOOKS_PATH_REDIRECTED',
27
- 'HFS_MODULE_TIER_INVALID',
28
- 'HFS_PACKAGE_MANAGER_MIXED',
29
- 'HFS_README_BADGE_NOT_LIVE',
30
- 'HFS_README_DESCRIPTION_INVALID',
31
- 'HFS_README_DEVELOPMENT_INCOMPLETE',
32
- 'HFS_README_PRIVATE_URL',
33
- 'HFS_README_SECTION_MISSING',
34
- 'HFS_README_SECTION_ORDER',
35
- 'HFS_README_TITLE_INVALID',
36
- 'HFS_README_WORK_POINTER_MISSING',
37
- 'HFS_ROOT_ENTRY_FORBIDDEN',
38
- 'HFS_ROOT_ENTRY_MISSING',
39
- 'HFS_ROOT_MARKDOWN_FORBIDDEN',
40
- 'HFS_ROOT_SRC_FORBIDDEN_FE',
41
- 'HFS_SRC_LAYOUT_INVALID',
42
- 'HFS_STACKS_IN_SIDE',
43
- 'HFS_WORK_IN_FE',
44
- ];
45
-
46
- const NON_NPM_ENTRIES = new Set(['pnpm-lock.yaml', 'pnpm-workspace.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb']);
47
- const HUSKY_HOOKS_PATH = /^\.husky(?:\/_)?\/?$/u;
48
- /** The folders of a back end's src/ the slot manifest knows (features, modules, tests, assets): read from the be slot paths, never listed here. */
49
- const backendSrcChildrenOf = resolver => new Set(resolver.slots().filter(slot => slot.profiles.includes('be')).flatMap(slot => braceVariants(slot.path)).map(variant => /^src\/([a-z][a-z-]*)\//.exec(variant)?.[1]).filter(Boolean));
50
- const moduleTiersOf = resolver => new Set(resolver.slots().filter(slot => slot.profiles.includes('be')).flatMap(slot => braceVariants(slot.path)).map(variant => /^src\/modules\/([a-z][a-z-]*)\//.exec(variant)?.[1]).filter(Boolean)); // the folders of src/modules/ the slot manifest knows (domain, platform, integrations, events, queues, projections)
51
- // Owner test layout 2026-09-30: unit `<name>.spec.ts`, integration, e2e and contract by folder and suffix; int-spec and harness-spec stay banned.
52
- const UNSUPPORTED_TEST_SUFFIX = /\.(?:int|harness)-spec\.[cm]?[jt]sx?$/u;
53
- const UNSUPPORTED_TEST_FOLDER = /^src\/tests\/(?:harness|live|e2e\/live)(?:\/|$)/u;
54
- const JEST_CONFIG_PREFIX = /^jest[.-]/u;
55
- const JEST_CONFIG_SUFFIX = /(?:config\.[cm]?[jt]s|\.json)$/u;
56
- const JEST_LANE_PREFIX = /^jest-(?:e2e|int|harness)/u;
57
- /** A per-lane jest config file name: the last path segment is `jest[.-]...config.<ext>`, `jest[.-]....json` or `jest-<lane>...`. */
58
- const isExtraTestConfig = file => {
59
- const base = file.slice(file.lastIndexOf('/') + 1);
60
- return (JEST_CONFIG_PREFIX.test(base) && JEST_CONFIG_SUFFIX.test(base.slice('jest-'.length))) || JEST_LANE_PREFIX.test(base);
61
- };
62
- const NODE_ENTRIES_SKIPPED = new Set(['node_modules', '.git']);
63
-
64
- /** The slot resolver of a side folder: the caller's, else the side view its app's hfs.json declares, else the profile's slots with no app declared. */
65
- function resolverOf(root, profile, given) {
66
- if (given) return given;
67
- try { return openHfs({ repoRoot: root }); } catch { /* an invalid hfs.json is HFS_DECLARATION_INVALID's finding, judged elsewhere */ }
68
- return createSlotResolver(loadSlotManifest(), { profile, side: profile, apps: [], optionalSlots: [], connections: [], reads: [] });
69
- }
70
-
71
- /**
72
- * The first path segment of every slot of the scope that may exist: the root entries of a side (contracts/, docs/, src/ ...) or of
73
- * the app (be/, fe/, .github/ ...). `scope` is the profile whose slots count (the app resolver answers for the sides too).
74
- */
75
- function slotRootEntries(resolver, scope) {
76
- const roots = new Set(scope === 'app' ? [] : ['apps']);
77
- for (const slot of resolver.slots()) {
78
- if (slot.presence === 'forbidden' || !slot.profiles.includes(scope)) continue;
79
- for (const variant of braceVariants(slot.path)) {
80
- const first = variant.split('/')[0];
81
- if (first && !/[*?<%]/u.test(first)) roots.add(first);
82
- }
83
- }
84
- return roots;
85
- }
86
-
87
- /** The root entries the scope's required slots name (the first segment of every required path of the scope): hfs.json, be/, .starcistacks/ ... */
88
- function requiredRootEntries(resolver) {
89
- return new Set(resolver.requiredPaths().paths.filter((entry) => !entry.side).map((entry) => entry.path.split('/')[0]));
90
- }
91
-
92
- /** The folders directly below src/tests/ that the be.tests.* slots declare (world, fixtures, integration, e2e, contract). */
93
- function slotTestChildren(resolver) {
94
- const children = new Set();
95
- for (const slot of resolver.slots()) {
96
- for (const variant of braceVariants(slot.path)) {
97
- const match = /^src\/tests\/([^/*?<]+)\//u.exec(variant);
98
- if (match) children.add(match[1]);
99
- }
100
- }
101
- return children;
102
- }
103
-
104
- /**
105
- * Whether the given root is the top level of its own Git work tree. An example under a runtime clone is a directory of
106
- * that clone, not a work tree of its own: the clone's hooks and root are not the example's. A directory outside any work
107
- * tree is not a top level either.
108
- */
109
- function ownsGitTopLevel(root) {
110
- try {
111
- const top = gitOutputOf(revParseQuery(['--show-toplevel'], { cwd: root }), 'git rev-parse --show-toplevel').trim();
112
- const same = (a, b) => (process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b);
113
- return same(fs.realpathSync(path.resolve(top)), fs.realpathSync(path.resolve(root)));
114
- } catch {
115
- return false;
116
- }
117
- }
118
-
119
- /**
120
- * The hooks of the checked root: core.hooksPath stays husky's (HFS_HOOKS_PATH_REDIRECTED), and the folder it names holds
121
- * installed hooks in this checkout (HFS_HOOKS_NOT_INSTALLED, scripts/lib/git-hooks-dir.mjs). An unset key judges nothing: a CI
122
- * checkout installs without hooks. A directory that is not the top level of its own work tree has no hooks of its own: the
123
- * check is not applicable there.
124
- */
125
- function hooksPathNotRedirected({ root, finding }) {
126
- if (!ownsGitTopLevel(root)) return { status: 'not-applicable', reason: 'the checked root is not the top level of its own Git work tree, so it has no hooks of its own' };
127
- const set = configGet(root, 'core.hooksPath', { local: true });
128
- if (!set.ok) return { status: 'checked' }; // key not set: nothing is redirected
129
- const value = String(set.stdout ?? '').trim();
130
- if (!value) return { status: 'checked' };
131
- if (!HUSKY_HOOKS_PATH.test(value.replaceAll('\\', '/'))) {
132
- finding('HFS_HOOKS_PATH_REDIRECTED', '.git/config', `core.hooksPath is set to ${value} in this clone. Unset it (git config --local --unset core.hooksPath) and let husky own the hooks; a redirected path skips the pre-commit and pre-push gates.`);
133
- return { status: 'checked' };
134
- }
135
- const hooks = hooksDirState(root, value);
136
- if (hooks.state !== 'installed') {
137
- const what = { missing: 'does not exist', empty: 'holds no installed hook (husky never ran here)', unreadable: `cannot be read (${hooks.error})` }[hooks.state];
138
- finding('HFS_HOOKS_NOT_INSTALLED', value, `core.hooksPath is ${value}, but that folder ${what} in this checkout, so git runs no pre-commit or pre-push gate and a commit skips lint and specs. Install the hooks before committing: run \`starci npm ci\` at the app root (it runs the app's hook installer \`npm run prepare\` even when lifecycle scripts are ignored), or \`npm run prepare\`; an install with --ignore-scripts alone never installs them.`);
139
- }
140
- return { status: 'checked', hooks: hooks.state };
141
- }
142
-
143
- /** The tracked paths under the given root, relative to it: the pathspec keeps a nested directory from listing the paths of its enclosing clone. */
144
- function gitPaths(root) {
145
- try {
146
- // An empty index is still a Git tree. Falling back to disk in that case would count
147
- // untracked build output as repository content.
148
- gitOutputOf(revParseQuery(['--is-inside-work-tree'], { cwd: root }), 'git rev-parse --is-inside-work-tree');
149
- const out = gitOutputOf(lsFiles(['--cached', '-z', '--', '.'], { cwd: root, maxBuffer: 256 * 1024 * 1024 }), 'git ls-files');
150
- return out.split('\0').filter(Boolean);
151
- } catch {
152
- return null;
153
- }
154
- }
155
-
156
- function fsHasDir(root, relative) {
157
- try { return fs.statSync(path.join(root, ...relative.split('/'))).isDirectory(); } catch { return false; }
158
- }
159
-
160
- function fsHasFile(root, relative) {
161
- try { return fs.statSync(path.join(root, ...relative.split('/'))).isFile(); } catch { return false; }
162
- }
163
-
164
- function fsChildren(root, relative) {
165
- try {
166
- return fs.readdirSync(path.join(root, ...relative.split('/')), { withFileTypes: true })
167
- .map(entry => entry.name);
168
- } catch {
169
- return [];
170
- }
171
- }
172
-
173
- function fsFiles(root, relative = '') {
174
- const out = [];
175
- for (const name of fsChildren(root, relative || '.')) {
176
- if (NODE_ENTRIES_SKIPPED.has(name)) continue;
177
- const child = relative ? `${relative}/${name}` : name;
178
- if (fsHasDir(root, child)) out.push(...fsFiles(root, child));
179
- else out.push(child);
180
- }
181
- return out;
182
- }
183
-
184
- /** The tree view of a list of tracked paths (posix, root-relative): what the git view answers, for a list already in hand. */
185
- export function trackedTreeView(tracked) {
186
- const files = new Set(tracked);
187
- return {
188
- source: 'git',
189
- top: [...new Set(tracked.map(file => file.split('/')[0]))],
190
- children: dir => {
191
- const prefix = `${dir}/`;
192
- const names = new Set();
193
- for (const file of tracked) if (file.startsWith(prefix)) names.add(file.slice(prefix.length).split('/')[0]);
194
- return [...names];
195
- },
196
- hasDir: dir => tracked.some(file => file.startsWith(`${dir}/`)),
197
- hasFile: file => files.has(file),
198
- files: () => tracked,
199
- };
200
- }
201
-
202
- /** Uniform tree view: top entries plus children(dir)/hasDir/hasFile answers over posix relatives. */
203
- function treeView(root) {
204
- const tracked = gitPaths(root);
205
- if (tracked !== null) return trackedTreeView(tracked);
206
- return {
207
- source: 'fs',
208
- top: fsChildren(root, '.'),
209
- children: dir => fsChildren(root, dir),
210
- hasDir: dir => fsHasDir(root, dir),
211
- hasFile: file => fsHasFile(root, file),
212
- files: () => fsFiles(root),
213
- };
214
- }
215
-
216
- /** Presentation checks shared by the product HFS gate and this runtime's own standalone gate. */
217
- export function checkRepoPresentation({ root, runtime = false, tree = treeView(root), profile = 'app', edition = 'full' }) {
218
- return checkRepoPresentationImpl({ root, runtime, tree, profile, edition, nonNpmEntries: NON_NPM_ENTRIES });
219
- }
220
- function checkSideRootEntry(state, entry) {
221
- const { profile, frontend, backend, allowed, finding } = state;
222
- if (NON_NPM_ENTRIES.has(entry) || /\.md$/iu.test(entry)) return;
223
- if (entry === '.starcistacks') { finding('HFS_STACKS_IN_SIDE', entry, `The ${profile} side must not hold .starcistacks; stack declarations and sealed custody live in the app root .starcistacks.`); return; }
224
- if (frontend && !backend) {
225
- if (entry === '.starciwork') { finding('HFS_WORK_IN_FE', entry, 'The fe side must not hold a .starciwork tree; Work records live in the app root .starciwork.'); return; }
226
- if (entry === 'src') { finding('HFS_ROOT_SRC_FORBIDDEN_FE', entry, 'The fe side keeps source only under apps/<app>/src; the fe/src/ tree must move.'); return; }
227
- if (isFeTestPath(entry) || isFeTestPath(`${entry}/x`)) return;
228
- }
229
- if (!allowed.has(entry)) finding('HFS_ROOT_ENTRY_FORBIDDEN', entry, `Root entry ${entry} of the ${profile} side is not in the slots of the ${profile} side.`);
230
- }
231
-
232
- function checkSideRootEntries(state) {
233
- // The README, the hooks, the workflows and the scripts are the app root's (checkAppRoot); a side folder is judged as the old
234
- // repository root it stands for, less those.
235
- for (const entry of [...state.tree.top].sort(byCodeUnit)) checkSideRootEntry(state, entry);
236
- }
237
-
238
- function checkRequiredRootEntries(state) {
239
- for (const entry of [...requiredRootEntries(state.resolver)].sort(byCodeUnit)) {
240
- if (entry === 'apps') continue;
241
- if (!state.tree.top.includes(entry)) state.finding('HFS_ROOT_ENTRY_MISSING', entry, `The ${state.profile} side requires root entry ${entry}.`);
242
- }
243
- }
244
-
245
- function missingBackendFiles(state, app) {
246
- const { tree, resolver } = state;
247
- const missing = [];
248
- // A back-end app must hold exactly what the slot of its kind requires (each kind's slot names its own requires).
249
- for (const required of resolver.requiredFiles(`apps/${app}/src/main.ts`)) {
250
- const directory = required.endsWith('/');
251
- if (!(directory ? tree.hasDir(required.slice(0, -1)) : tree.hasFile(required))) missing.push(required.slice(`apps/${app}/`.length));
252
- }
253
- return missing;
254
- }
255
-
256
- function missingFrontendFiles(state, app) {
257
- const { tree, resolver } = state;
258
- const missing = [];
259
- // next-env.d.ts is generated by Next and commonly ignored by Git; it is not
260
- // a reliable tracked-tree input.
261
- // A front-end app holds the files its slot requires at its own root (next.config.ts, tsconfig.json, ...; it has no package.json).
262
- for (const required of resolver.requiredFiles(`apps/${app}/next.config.ts`).filter(entry => !entry.slice(`apps/${app}/`.length).includes('/'))) {
263
- if (!tree.hasFile(required)) missing.push(required.slice(`apps/${app}/`.length));
264
- }
265
- return missing;
266
- }
267
-
268
- function checkApplicationRequiredFiles(state, app) {
269
- const { tree, backend, frontend, finding } = state;
270
- if (!tree.hasDir(`apps/${app}`)) {
271
- finding('HFS_APP_LAYOUT_INVALID', `apps/${app}`, `Application entry apps/${app} must be a directory.`);
272
- return;
273
- }
274
- const missing = [];
275
- if (!tree.hasDir(`apps/${app}/src`)) missing.push('src/');
276
- if (backend) missing.push(...missingBackendFiles(state, app));
277
- if (frontend) missing.push(...missingFrontendFiles(state, app));
278
- if (missing.length) finding('HFS_APP_LAYOUT_INVALID', `apps/${app}`, `Application apps/${app} lacks ${missing.join(', ')} required by the HFS app layout.`);
279
- }
280
-
281
- function checkApplications(state) {
282
- const { tree, finding } = state;
283
- const apps = tree.children('apps').sort(byCodeUnit);
284
- if (!tree.hasDir('apps') || apps.length === 0)
285
- finding('HFS_APPS_REQUIRED', 'apps', 'Every HFS repository is an apps/<app>/ monorepo; apps/ must hold at least one application.');
286
- for (const app of apps) checkApplicationRequiredFiles(state, app);
287
- return apps;
288
- }
289
-
290
- function checkBackendSourceLayout(state) {
291
- if (!state.backend) return;
292
- const { tree, resolver, finding } = state;
293
- const srcChildren = backendSrcChildrenOf(resolver);
294
- const srcList = [...srcChildren].sort(byCodeUnit).map(name => name + '/').join(', ');
295
- for (const child of tree.children('src').sort(byCodeUnit)) {
296
- if (!srcChildren.has(child))
297
- finding('HFS_SRC_LAYOUT_INVALID', `src/${child}`, `Backend src/ holds only ${srcList}; ${child} must move to its owner.`);
298
- }
299
- for (const tier of tree.children('src/modules').sort(byCodeUnit)) {
300
- if (!moduleTiersOf(resolver).has(tier))
301
- finding('HFS_MODULE_TIER_INVALID', `src/modules/${tier}`, `Module tier ${tier} is not one of ${[...moduleTiersOf(resolver)].sort(byCodeUnit).join(', ')}.`);
302
- }
303
- const testChildren = slotTestChildren(resolver);
304
- for (const child of tree.children('src/tests').sort(byCodeUnit)) {
305
- // A file directly below src/tests/ that a slot owns (src/tests/tsconfig.json, be.tool-config) is that slot's, not a stray folder.
306
- if (!testChildren.has(child) && resolver.classifyPath(`src/tests/${child}`).status !== 'owned')
307
- finding('HFS_SRC_LAYOUT_INVALID', `src/tests/${child}`, `Backend src/tests/ holds only ${[...testChildren].join(', ')} and the files a slot owns there; ${child} must move.`);
308
- }
309
- }
310
-
311
- function checkTestTopology(state) {
312
- // Test kinds and folders that do not exist: int-spec, harness-spec, src/tests/harness and live/;
313
- // a backend spec sits by its kind (beside its subject, or under src/tests/{integration,e2e,contract}/).
314
- for (const file of state.tree.files()) {
315
- if (state.backend && state.profile === 'be' && UNSUPPORTED_TEST_SUFFIX.test(file))
316
- state.finding('BE_TEST_TOPOLOGY', file, `${file} uses an unsupported test kind. Only unit *.spec.ts, *.integration-spec.ts, *.e2e-spec.ts and *.contract-spec.ts exist, each in its own folder under src/tests/.`);
317
- else if (state.backend && state.profile === 'be' && UNSUPPORTED_TEST_FOLDER.test(file))
318
- state.finding('BE_TEST_TOPOLOGY', file, `${file} sits in an unsupported test folder. Unit specs sit beside their subject, flows go under src/tests/e2e/<area>/ and test infrastructure under src/tests/world/.`);
319
- else if (state.backend && state.profile === 'be' && file.startsWith('src/tests/') && isExtraTestConfig(file))
320
- state.finding('BE_TEST_TOPOLOGY', file, `${file} is a per-lane test config. One root jest.config.js declares exactly the unit, integration, e2e and contract projects.`);
321
- }
322
- }
323
-
324
- export function checkHfs(config) {
325
- const kinds = config.kinds ?? [];
326
- const backend = kinds.includes('backend');
327
- const frontend = kinds.includes('frontend');
328
- if (!backend && !frontend) return { violations: [], coverage: { status: 'not-applicable' } };
329
- const tree = treeView(config.root);
330
- const violations = [];
331
- const finding = (ruleId, entry, message) => violations.push({ ruleId, path: entry, line: 1, column: 1, message });
332
- const profile = backend ? 'be' : 'fe';
333
- const resolver = resolverOf(config.root, profile, config.hfs);
334
- const state = { config, tree, violations, finding, backend, frontend, profile, resolver, allowed: slotRootEntries(resolver, profile) };
335
- checkSideRootEntries(state);
336
- checkRequiredRootEntries(state);
337
- const apps = checkApplications(state);
338
- checkBackendSourceLayout(state);
339
- checkTestTopology(state);
340
- if (backend) testTreesOutOfDefaultProgram({ root: config.root, tree, finding });
341
- return {
342
- violations,
343
- coverage: { status: 'checked', source: tree.source, rootEntries: tree.top.length, apps, ruleIds: [...HFS_RULE_IDS] },
344
- };
345
- }
346
-
347
- /**
348
- * The HFS tree check of the app root (`resolver` is the app's): the README, the root entries the app-root slots allow and require,
349
- * the automatic gates (hooks, the root scripts they call, the workflows) and the hooks path. `starci app check` runs it once per app; the
350
- * machine runs checkHfs once per side folder.
351
- */
352
- export function checkAppRoot({ root, resolver, tree = treeView(root) }) {
353
- const violations = [];
354
- const finding = (ruleId, entry, message) => violations.push({ ruleId, path: entry, line: 1, column: 1, message });
355
- violations.push(...checkRepoPresentation({ root, tree, profile: 'app', edition: resolver.repo?.edition ?? 'full' }).violations);
356
- const allowed = slotRootEntries(resolver, 'app');
357
- for (const entry of [...tree.top].sort(byCodeUnit)) {
358
- if (NON_NPM_ENTRIES.has(entry) || /\.md$/iu.test(entry)) continue;
359
- if (!allowed.has(entry)) finding('HFS_ROOT_ENTRY_FORBIDDEN', entry, `Root entry ${entry} is not in the slots of the app root.`);
360
- }
361
- for (const entry of [...requiredRootEntries(resolver)].sort(byCodeUnit)) {
362
- if (entry === 'README.md' || entry === '.gitattributes') continue; // checkRepoPresentation reports these two
363
- if (!tree.top.includes(entry)) finding('HFS_ROOT_ENTRY_MISSING', entry, `The app root requires root entry ${entry}.`);
364
- }
365
- const jestConfig = resolver.sides ? `be/${[...braceVariants(resolver.slot('be.tool-config').path)].find(file => file.startsWith('jest.config.'))}` : null;
366
- e2eInAutomaticGate({ root, tree, jestConfig, finding });
367
- const hooksPath = hooksPathNotRedirected({ root, finding });
368
- return { violations, coverage: { status: 'checked', source: tree.source, hooksPath, rootEntries: tree.top.length } };
369
- }
370
-
371
- /** Keep tree findings visible even when the TypeScript architecture config is invalid. */
372
- export function checkHfsWithoutConfig(repositoryRoot) {
373
- let root;
374
- try { root = fs.realpathSync(path.resolve(repositoryRoot)); } catch {
375
- return { violations: [], coverage: { status: 'unavailable', reason: 'repository root is unavailable' } };
376
- }
377
- let kinds = [];
378
- try {
379
- const opened = openHfs({ repoRoot: root });
380
- // The app root is judged by checkAppRoot; a side folder by its side's tree check.
381
- if (opened.repo.profile === 'app') return checkAppRoot({ root, resolver: opened });
382
- if (opened.repo.profile === 'be') kinds = ['backend'];
383
- else if (opened.repo.profile === 'fe') kinds = ['frontend'];
384
- } catch { /* A malformed hfs.json remains an HFS_DECLARATION_INVALID error. */ }
385
- if (!kinds.length) {
386
- try {
387
- const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
388
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
389
- if (deps['@nestjs/core']) kinds.push('backend');
390
- if (deps.next) kinds.push('frontend');
391
- } catch { /* The architecture error still reports the missing input. */ }
392
- }
393
- return checkHfs({ root, kinds });
394
- }