@starci/eslint-canon-be 3.8.20 → 3.9.2

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 (164) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -5,7 +5,6 @@ import { DEFAULT_ENVIRONMENT, STACKS_DIRECTORY, STATEFUL_KINDS, namesOfService,
5
5
  import { unwrapEach } from './ast-walks.mjs';
6
6
  import { hasAnyFlag, nameText, sourceLocation } from '../../lib/ts-ast.mjs';
7
7
  import { byCodeUnit } from '../../lib/list.mjs';
8
-
9
8
  /**
10
9
  * R47 `test-world-files` (BE_TEST_TOPOLOGY). Judgements over the test world, read through slots, the repository's own
11
10
  * stack definition (`.starcistacks/<env>`, scripts/lib/stack-services.mjs) and the world's declaration
@@ -33,7 +32,6 @@ import { byCodeUnit } from '../../lib/list.mjs';
33
32
  * nothing else of it.
34
33
  */
35
34
  export const TEST_WORLD_FILES_RULE_IDS = ['BE_TEST_TOPOLOGY'];
36
-
37
35
  const RULE = 'BE_TEST_TOPOLOGY';
38
36
  const WORLD_SLOT = 'be.tests.world';
39
37
  const FAKES_DIRECTORY = 'fakes/';
@@ -42,193 +40,205 @@ const DEFINE = 'defineTestWorld';
42
40
  const NAMED_FORM = `export const { useTestWorld, useSandbox } = ${DEFINE}({ ... })`;
43
41
  const defaultEnvironment = DEFAULT_ENVIRONMENT;
44
42
  const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
45
-
46
43
  const unwrap = (ts, node) => unwrapEach(ts, node, [ts.isParenthesizedExpression, ts.isAsExpression, ts.isSatisfiesExpression]);
47
- const propertyOf = (ts, literal, key) => literal.properties.find(property => ts.isPropertyAssignment(property) && nameText(ts, property.name) === key)?.initializer ?? null;
44
+ const propertyOf = (ts, literal, key) => literal.properties.find((property) => ts.isPropertyAssignment(property) && nameText(ts, property.name) === key)?.initializer ?? null;
48
45
  const isExported = (ts, statement) => (statement.modifiers ?? []).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
49
-
50
46
  /** The object literal of `defineTestWorld(<object literal>)`, or null. */
51
47
  function defineLiteral(ts, expression) {
52
- const call = unwrap(ts, expression);
53
- if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression) || call.expression.text !== DEFINE) return null;
54
- const [first] = call.arguments;
55
- const literal = first ? unwrap(ts, first) : null;
56
- return literal && ts.isObjectLiteralExpression(literal) ? literal : null;
48
+ const call = unwrap(ts, expression);
49
+ if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression) || call.expression.text !== DEFINE)
50
+ return null;
51
+ const [first] = call.arguments;
52
+ const literal = first ? unwrap(ts, first) : null;
53
+ return literal && ts.isObjectLiteralExpression(literal) ? literal : null;
57
54
  }
58
-
59
55
  /** The declaration of the world: the object literal of an exported `const` initialized by `defineTestWorld({ ... })`, or null. */
60
56
  function configLiteral(ts, sourceFile) {
61
- for (const statement of sourceFile.statements) {
62
- if (!ts.isVariableStatement(statement) || !isExported(ts, statement)) continue;
63
- if (!hasAnyFlag(statement.declarationList.flags, ts.NodeFlags.Const)) continue;
64
- for (const declaration of statement.declarationList.declarations) {
65
- const literal = declaration.initializer ? defineLiteral(ts, declaration.initializer) : null;
66
- if (literal) return literal;
57
+ for (const statement of sourceFile.statements) {
58
+ if (!ts.isVariableStatement(statement) || !isExported(ts, statement))
59
+ continue;
60
+ if (!hasAnyFlag(statement.declarationList.flags, ts.NodeFlags.Const))
61
+ continue;
62
+ for (const declaration of statement.declarationList.declarations) {
63
+ const literal = declaration.initializer ? defineLiteral(ts, declaration.initializer) : null;
64
+ if (literal)
65
+ return literal;
66
+ }
67
67
  }
68
- }
69
- return null;
68
+ return null;
70
69
  }
71
-
72
70
  /** `stack` as the environment it names: the last segment of `".starcistacks/<env>"`; null when absent or not a literal. */
73
71
  function environmentOf(ts, literal) {
74
- const node = literal ? propertyOf(ts, literal, 'stack') : null;
75
- const value = node ? unwrap(ts, node) : null;
76
- if (!value || !ts.isStringLiteralLike(value)) return null;
77
- return value.text.split(/[\\/]+/u).filter(Boolean).findLast(Boolean) ?? null;
72
+ const node = literal ? propertyOf(ts, literal, 'stack') : null;
73
+ const value = node ? unwrap(ts, node) : null;
74
+ if (!value || !ts.isStringLiteralLike(value))
75
+ return null;
76
+ return value.text.split(/[\\/]+/u).filter(Boolean).findLast(Boolean) ?? null;
78
77
  }
79
-
80
78
  /** The keys of the declaration's `fakes` object literal, with their positions. */
81
79
  function fakeEntriesOf(ts, sourceFile, literal) {
82
- const node = literal ? propertyOf(ts, literal, 'fakes') : null;
83
- const value = node ? unwrap(ts, node) : null;
84
- if (!value || !ts.isObjectLiteralExpression(value)) return [];
85
- return value.properties
86
- .map(property => ({ name: nameText(ts, property.name), ...sourceLocation(sourceFile, property) }))
87
- .filter(entry => entry.name);
88
- }
89
-
80
+ const node = literal ? propertyOf(ts, literal, 'fakes') : null;
81
+ const value = node ? unwrap(ts, node) : null;
82
+ if (!value || !ts.isObjectLiteralExpression(value))
83
+ return [];
84
+ return value.properties
85
+ .map(property => ({ name: nameText(ts, property.name), ...sourceLocation(sourceFile, property) }))
86
+ .filter((entry) => Boolean(entry.name));
87
+ }
90
88
  /** The `fakedBy` entry of one `stacks` property, or null when the property does not declare one. */
91
89
  function fakedByEntry(ts, sourceFile, property) {
92
- if (!ts.isPropertyAssignment(property)) return null;
93
- const body = unwrap(ts, property.initializer);
94
- if (!body || !ts.isObjectLiteralExpression(body)) return null;
95
- const fake = propertyOf(ts, body, 'fakedBy');
96
- if (!fake) return null;
97
- const reason = propertyOf(ts, body, 'reason');
98
- return {
99
- service: nameText(ts, property.name),
100
- fake: ts.isStringLiteralLike(fake) ? fake.text : '',
101
- reason: reason && ts.isStringLiteralLike(reason) ? reason.text.trim() : '',
102
- ...sourceLocation(sourceFile, property),
103
- };
104
- }
105
-
90
+ if (!ts.isPropertyAssignment(property))
91
+ return null;
92
+ const body = unwrap(ts, property.initializer);
93
+ if (!body || !ts.isObjectLiteralExpression(body))
94
+ return null;
95
+ const fake = propertyOf(ts, body, 'fakedBy');
96
+ if (!fake)
97
+ return null;
98
+ const reason = propertyOf(ts, body, 'reason');
99
+ return {
100
+ service: nameText(ts, property.name),
101
+ fake: ts.isStringLiteralLike(fake) ? fake.text : '',
102
+ reason: reason && ts.isStringLiteralLike(reason) ? reason.text.trim() : '',
103
+ ...sourceLocation(sourceFile, property),
104
+ };
105
+ }
106
106
  /** The `stacks` entries that declare `fakedBy`: [{service, fake, reason, line, column}]; a value the reader cannot read statically has an empty fake and reason. */
107
107
  function fakedByOf(ts, sourceFile, literal) {
108
- const node = literal ? propertyOf(ts, literal, 'stacks') : null;
109
- const value = node ? unwrap(ts, node) : null;
110
- if (!value || !ts.isObjectLiteralExpression(value)) return [];
111
- return value.properties.map(property => fakedByEntry(ts, sourceFile, property)).filter(Boolean);
108
+ const node = literal ? propertyOf(ts, literal, 'stacks') : null;
109
+ const value = node ? unwrap(ts, node) : null;
110
+ if (!value || !ts.isObjectLiteralExpression(value))
111
+ return [];
112
+ return value.properties.map(property => fakedByEntry(ts, sourceFile, property)).filter((entry) => entry !== null);
112
113
  }
113
-
114
114
  function registerFakeProvider(fakeProviders, relative, file) {
115
- if (!relative.startsWith(FAKES_DIRECTORY)) return;
116
- const [provider, ...rest] = relative.slice(FAKES_DIRECTORY.length).split('/');
117
- if (rest.length > 0 && !fakeProviders.has(provider)) fakeProviders.set(provider, file);
115
+ if (!relative.startsWith(FAKES_DIRECTORY))
116
+ return;
117
+ const [provider, ...rest] = relative.slice(FAKES_DIRECTORY.length).split('/');
118
+ if (provider !== undefined && rest.length > 0 && !fakeProviders.has(provider))
119
+ fakeProviders.set(provider, file);
118
120
  }
119
-
120
121
  function isRoleFileAtRoot(relative, suffixes) {
121
- const parts = relative.slice(0, -'.ts'.length).split('.');
122
- return !relative.includes('/') && parts.length >= 2 && parts.every(part => KEBAB.test(part)) && suffixes.includes(parts.at(-1));
122
+ const parts = relative.slice(0, -'.ts'.length).split('.');
123
+ return !relative.includes('/') && parts.length >= 2 && parts.every(part => KEBAB.test(part)) && suffixes.includes(parts.at(-1) ?? '');
123
124
  }
124
-
125
125
  function collectWorldFiles(resolver, tree, suffixes, violations) {
126
- const fakeProviders = new Map();
127
- let worldRoot = null;
128
- let files = 0;
129
- for (const file of [...tree.files].sort(byCodeUnit)) {
130
- if (!file.endsWith('.ts')) continue;
131
- const verdict = allowsFile(resolver, file);
132
- if (verdict?.slot !== WORLD_SLOT) continue;
133
- files += 1;
134
- worldRoot ??= file.slice(0, file.length - verdict.relative.length);
135
- registerFakeProvider(fakeProviders, verdict.relative, file);
136
- if (verdict.allowed || isRoleFileAtRoot(verdict.relative, suffixes)) continue;
137
- violations.push({
138
- ruleId: RULE, path: file, line: 1, column: 1,
139
- message: `${file} is not allowed in the test world; src/tests/world/ holds only ${verdict.allows.join(', ')} and role-suffixed files (<name>.<role>.ts) at its root. Move it to fakes/ or kit/ (be.tests.world.kit), give it a role suffix, or delete it.`,
140
- slot: verdict.slot,
141
- });
142
- }
143
- return { fakeProviders, worldRoot, files };
144
- }
145
-
146
- function worldDeclaration(config, graph, ts, worldRoot, violations) {
147
- const configPath = worldRoot === null ? null : `${worldRoot}${CONFIG_FILE}`;
148
- const configFile = configPath === null ? null : graph.files.get(configPath) ?? null;
149
- const literal = configFile ? configLiteral(ts, configFile.sourceFile) : null;
150
- if (configFile && !literal) {
151
- violations.push({
152
- ruleId: RULE, path: configPath, line: 1, column: 1, slot: WORLD_SLOT,
153
- message: `${configPath} declares no world the machine can read. Declare it in the one named form \`${NAMED_FORM}\` (an exported const of a ${DEFINE} call with an object literal, imported from @starci/test-world); a default export is refused by R89 and is not read.`,
154
- });
155
- }
156
- return { configPath, configFile, literal };
157
- }
158
-
126
+ const fakeProviders = new Map();
127
+ let worldRoot = null;
128
+ let files = 0;
129
+ for (const file of [...tree.files].sort(byCodeUnit)) {
130
+ if (!file.endsWith('.ts'))
131
+ continue;
132
+ const verdict = allowsFile(resolver, file);
133
+ if (verdict?.slot !== WORLD_SLOT)
134
+ continue;
135
+ files += 1;
136
+ worldRoot ??= file.slice(0, file.length - verdict.relative.length);
137
+ registerFakeProvider(fakeProviders, verdict.relative, file);
138
+ if (verdict.allowed || isRoleFileAtRoot(verdict.relative, suffixes))
139
+ continue;
140
+ violations.push({
141
+ ruleId: RULE, path: file, line: 1, column: 1,
142
+ message: `${file} is not allowed in the test world; src/tests/world/ holds only ${verdict.allows.join(', ')} and role-suffixed files (<name>.<role>.ts) at its root. Move it to fakes/ or kit/ (be.tests.world.kit), give it a role suffix, or delete it.`,
143
+ slot: verdict.slot,
144
+ });
145
+ }
146
+ return { fakeProviders, worldRoot, files };
147
+ }
148
+ function worldDeclaration(graph, ts, worldRoot, violations) {
149
+ const configPath = worldRoot === null ? null : `${worldRoot}${CONFIG_FILE}`;
150
+ const configFile = configPath === null ? null : graph.files.get(configPath) ?? null;
151
+ const literal = configFile ? configLiteral(ts, configFile.sourceFile) : null;
152
+ if (configFile && !literal) {
153
+ violations.push({
154
+ ruleId: RULE, path: configPath, line: 1, column: 1, slot: WORLD_SLOT,
155
+ message: `${configPath} declares no world the machine can read. Declare it in the one named form \`${NAMED_FORM}\` (an exported const of a ${DEFINE} call with an object literal, imported from @starci/test-world); a default export is refused by R89 and is not read.`,
156
+ });
157
+ }
158
+ return { configPath, configFile, literal };
159
+ }
159
160
  function stackServices(config, environments) {
160
- const services = [];
161
- for (const environment of environments) {
162
- let stack = null;
163
- // The stack is the app root's .starcistacks: the side folder the machine judges reads its app's (locateDeclaration).
164
- try { stack = readStack({ root: locateDeclaration(config.root).appRoot, environment }); } catch { stack = null; }
165
- for (const service of stack?.services ?? []) if (service.role !== 'service' && !services.some(known => known.name === service.name)) services.push({ ...service, environment });
166
- }
167
- return services;
168
- }
169
-
161
+ const services = [];
162
+ for (const environment of environments) {
163
+ let stack = null;
164
+ // The stack is the app root's .starcistacks: the side folder the machine judges reads its app's (locateDeclaration).
165
+ try {
166
+ stack = readStack({ root: locateDeclaration(config.root).appRoot, environment });
167
+ }
168
+ catch {
169
+ stack = null;
170
+ }
171
+ for (const service of stack?.services ?? [])
172
+ if (service.role !== 'service' && !services.some(known => known.name === service.name))
173
+ services.push({ ...service, environment });
174
+ }
175
+ return services;
176
+ }
170
177
  function statefulWhy(service) {
171
- if (STATEFUL_KINDS.has(service.kind)) return `a ${service.kind} holds data the app reads back`;
172
- return service.persistent ? 'the stack gives it a persistent volume' : null;
178
+ if (STATEFUL_KINDS.has(service.kind))
179
+ return `a ${service.kind} holds data the app reads back`;
180
+ return service.persistent ? 'the stack gives it a persistent volume' : null;
173
181
  }
174
-
175
182
  function reportDeclaredFakeProblems(declared, services, fakeProviders, fakeEntries, configPath, stackHint, violations) {
176
- for (const entry of declared) {
177
- const service = services.find(candidate => candidate.name === entry.service);
178
- const problems = [];
179
- if (!service) problems.push(`${stackHint} declares no service ${entry.service}`);
180
- else if (statefulWhy(service)) problems.push(`${service.name} is stateful (${statefulWhy(service)}) and always runs real`);
181
- if (!fakeProviders.has(entry.fake) && !fakeEntries.some(fake => fake.name === entry.fake)) problems.push(`there is no fakes entry and no fakes/${entry.fake || '<fake>'}/ folder of that name`);
182
- if (entry.reason === '') problems.push('the reason is empty');
183
- if (problems.length > 0) {
184
- violations.push({
185
- ruleId: RULE, path: configPath, line: entry.line, column: entry.column, slot: WORLD_SLOT,
186
- message: `${configPath} declares ${entry.service} as faked by ${entry.fake || '(no fake)'}, but ${problems.join('; ')}. The exception covers only stateless compute that needs special hardware or an external model, with a reason; everything else in the stack runs real.`,
187
- });
183
+ for (const entry of declared) {
184
+ const service = services.find(candidate => candidate.name === entry.service);
185
+ const problems = [];
186
+ if (!service)
187
+ problems.push(`${stackHint} declares no service ${entry.service}`);
188
+ else if (statefulWhy(service))
189
+ problems.push(`${service.name} is stateful (${statefulWhy(service)}) and always runs real`);
190
+ if (!fakeProviders.has(entry.fake) && !fakeEntries.some(fake => fake.name === entry.fake))
191
+ problems.push(`there is no fakes entry and no fakes/${entry.fake || '<fake>'}/ folder of that name`);
192
+ if (entry.reason === '')
193
+ problems.push('the reason is empty');
194
+ if (problems.length > 0) {
195
+ violations.push({
196
+ ruleId: RULE, path: configPath, line: entry.line, column: entry.column, slot: WORLD_SLOT,
197
+ message: `${configPath} declares ${entry.service} as faked by ${entry.fake || '(no fake)'}, but ${problems.join('; ')}. The exception covers only stateless compute that needs special hardware or an external model, with a reason; everything else in the stack runs real.`,
198
+ });
199
+ }
188
200
  }
189
- }
190
201
  }
191
-
192
202
  function worldFakes(fakeProviders, fakeEntries, configPath) {
193
- return [
194
- ...[...fakeProviders].map(([provider, file]) => ({ name: provider, path: file, line: 1, column: 1, what: `fakes/${provider}/` })),
195
- ...fakeEntries.filter(entry => !fakeProviders.has(entry.name)).map(entry => ({ name: entry.name, path: configPath, line: entry.line, column: entry.column, what: `the fakes entry ${entry.name}` })),
196
- ].sort((a, b) => a.name.localeCompare(b.name));
203
+ return [
204
+ ...[...fakeProviders].map(([provider, file]) => ({ name: provider, path: file, line: 1, column: 1, what: `fakes/${provider}/` })),
205
+ ...fakeEntries.filter(entry => !fakeProviders.has(entry.name)).map(entry => ({ name: entry.name, path: configPath, line: entry.line, column: entry.column, what: `the fakes entry ${entry.name}` })),
206
+ ].sort((a, b) => a.name.localeCompare(b.name));
197
207
  }
198
-
199
208
  function reportServiceFakes(fakes, services, declared, configPath, stackHint, violations) {
200
- for (const fake of fakes) {
201
- const service = services.find(candidate => namesOfService(candidate).includes(fake.name));
202
- if (!service) continue;
203
- if (declared.some(entry => entry.service === service.name && entry.fake === fake.name)) continue; // judged on its stacks entry above
204
- const why = statefulWhy(service);
205
- let reason = `${service.name} is stateful (${why}), so no exception applies. `;
206
- if (!why) {
207
- const worldConfig = configPath ?? `${CONFIG_FILE} in the world`;
208
- reason = `Only stateless compute that needs special hardware or an external model may be faked, and only when ${worldConfig} declares it in its stacks entry ({ fakedBy, reason }). `;
209
+ for (const fake of fakes) {
210
+ const service = services.find(candidate => namesOfService(candidate).includes(fake.name));
211
+ if (!service)
212
+ continue;
213
+ if (declared.some(entry => entry.service === service.name && entry.fake === fake.name))
214
+ continue; // judged on its stacks entry above
215
+ const why = statefulWhy(service);
216
+ let reason = `${service.name} is stateful (${why}), so no exception applies. `;
217
+ if (!why) {
218
+ const worldConfig = configPath ?? `${CONFIG_FILE} in the world`;
219
+ reason = `Only stateless compute that needs special hardware or an external model may be faked, and only when ${worldConfig} declares it in its stacks entry ({ fakedBy, reason }). `;
220
+ }
221
+ violations.push({
222
+ ruleId: RULE, path: fake.path, line: fake.line, column: fake.column, slot: WORLD_SLOT,
223
+ message: `${fake.what} fakes ${service.name} (${service.image}), which ${stackHint} declares: a service of the repository's own stack runs real in the test world. ${reason}Delete the fake and let the world run the real service; fakes are otherwise only for external SaaS the team does not operate.`,
224
+ });
209
225
  }
210
- violations.push({
211
- ruleId: RULE, path: fake.path, line: fake.line, column: fake.column, slot: WORLD_SLOT,
212
- message: `${fake.what} fakes ${service.name} (${service.image}), which ${stackHint} declares: a service of the repository's own stack runs real in the test world. ${reason}Delete the fake and let the world run the real service; fakes are otherwise only for external SaaS the team does not operate.`,
213
- });
214
- }
215
226
  }
216
-
217
227
  export function checkTestWorldFiles(input) {
218
- const { config, graph, ts, resolver, tree } = checkerScope(input);
219
- const { suffixes } = resolver.ruleParams();
220
- const violations = [];
221
- const { fakeProviders, worldRoot, files } = collectWorldFiles(resolver, tree, suffixes, violations);
222
- const { configPath, configFile, literal } = worldDeclaration(config, graph, ts, worldRoot, violations);
223
- const environments = [(literal ? environmentOf(ts, literal) : null) ?? defaultEnvironment];
224
- const services = stackServices(config, environments);
225
- const stackHint = `${STACKS_DIRECTORY}/${environments.join(', ')}`;
226
- const declared = literal ? fakedByOf(ts, configFile.sourceFile, literal) : [];
227
- const fakeEntries = literal ? fakeEntriesOf(ts, configFile.sourceFile, literal) : [];
228
- reportDeclaredFakeProblems(declared, services, fakeProviders, fakeEntries, configPath, stackHint, violations);
229
-
230
- // Every fake the world runs: the repository's fakes/<provider>/ folders and the fakes entries of the declaration.
231
- const fakes = worldFakes(fakeProviders, fakeEntries, configPath);
232
- reportServiceFakes(fakes, services, declared, configPath, stackHint, violations);
233
- return { violations, coverage: { status: 'checked', files } };
228
+ const { config, graph, ts, resolver, tree } = checkerScope(input);
229
+ const suffixes = graph.resolver.ruleParams()?.suffixes ?? [];
230
+ const violations = [];
231
+ const { fakeProviders, worldRoot, files } = collectWorldFiles(resolver, tree, suffixes, violations);
232
+ const { configPath, configFile, literal } = worldDeclaration(graph, ts, worldRoot, violations);
233
+ const environments = [(literal ? environmentOf(ts, literal) : null) ?? defaultEnvironment];
234
+ const services = stackServices(config, environments);
235
+ const stackHint = `${STACKS_DIRECTORY}/${environments.join(', ')}`;
236
+ const worldSource = configFile?.sourceFile;
237
+ const declared = literal && worldSource ? fakedByOf(ts, worldSource, literal) : [];
238
+ const fakeEntries = literal && worldSource ? fakeEntriesOf(ts, worldSource, literal) : [];
239
+ reportDeclaredFakeProblems(declared, services, fakeProviders, fakeEntries, configPath, stackHint, violations);
240
+ // Every fake the world runs: the repository's fakes/<provider>/ folders and the fakes entries of the declaration.
241
+ const fakes = worldFakes(fakeProviders, fakeEntries, configPath);
242
+ reportServiceFakes(fakes, services, declared, configPath, stackHint, violations);
243
+ return { violations, coverage: { status: 'checked', files } };
234
244
  }