@starci/eslint-canon-be 3.8.20 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +8 -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
@@ -6,7 +6,6 @@ import { treeOf } from './required-files.mjs';
6
6
  import { byCodeUnit } from '../../lib/list.mjs';
7
7
  import { importsOf } from '../../lib/ts-analysis.mjs';
8
8
  import { checkFunctionSubject, functionSubjectExports, keyOf as literalKey, valueObjectSubjects } from './function-spec-providers.mjs';
9
-
10
9
  /**
11
10
  * R48 `unit-spec-providers` (BE_SPEC_QUALITY), the unit test standard's rule 3: the unit spec of a service builds its
12
11
  * subject with `Test.createTestingModule({ providers: [...] })`, and that providers array EQUALS the constructor
@@ -26,115 +25,134 @@ import { checkFunctionSubject, functionSubjectExports, keyOf as literalKey, valu
26
25
  * `{ provide, useValue }`. Which double a `useValue` is, and whether other specs exist at all, are other rules' business.
27
26
  */
28
27
  export const UNIT_SPEC_PROVIDERS_RULE_IDS = ['BE_SPEC_QUALITY'];
29
-
30
28
  const RULE = 'BE_SPEC_QUALITY';
31
29
  const SPEC_ROOT = /^(?:src|apps)\//u;
32
-
33
30
  /** The `Test.createTestingModule(...)` calls of a spec. */
34
31
  function testingModules(ts, sourceFile) {
35
- const calls = [];
36
- const visit = node => {
37
- if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'createTestingModule') calls.push(node);
38
- ts.forEachChild(node, visit);
39
- };
40
- visit(sourceFile);
41
- return calls;
32
+ const calls = [];
33
+ const visit = (node) => {
34
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'createTestingModule')
35
+ calls.push(node);
36
+ ts.forEachChild(node, visit);
37
+ };
38
+ visit(sourceFile);
39
+ return calls;
42
40
  }
43
-
44
-
45
41
  function providerList(ts, call, rel, report) {
46
- const options = call.arguments[0];
47
- const property = options && ts.isObjectLiteralExpression(options) ? options.properties.find(item => literalKey(ts, item) === 'providers') : null;
48
- const list = property && ts.isPropertyAssignment(property) && ts.isArrayLiteralExpression(property.initializer) ? property.initializer : null;
49
- if (!list) report(call, `${rel}: Test.createTestingModule has no literal \`providers\` array; list the service and each constructor dependency there.`);
50
- return list;
42
+ const options = call.arguments[0];
43
+ const property = options && ts.isObjectLiteralExpression(options) ? options.properties.find(item => literalKey(ts, item) === 'providers') : null;
44
+ const list = property && ts.isPropertyAssignment(property) && ts.isArrayLiteralExpression(property.initializer) ? property.initializer : null;
45
+ if (!list)
46
+ report(call, `${rel}: Test.createTestingModule has no literal \`providers\` array; list the service and each constructor dependency there.`);
47
+ return list;
51
48
  }
52
-
53
49
  function readProviders(ts, list, rel, nameOf, report) {
54
- const provided = [];
55
- let readable = true;
56
- for (const element of list.elements) {
57
- if (ts.isIdentifier(element)) { provided.push({ name: nameOf(element), node: element, isClass: true }); continue; }
58
- if (ts.isObjectLiteralExpression(element)) {
59
- const keys = element.properties.map(item => literalKey(ts, item));
60
- const provide = element.properties.find(item => literalKey(ts, item) === 'provide');
61
- const value = provide && ts.isPropertyAssignment(provide) ? provide.initializer : null;
62
- if (keys.length === 2 && keys.includes('useValue') && value && ts.isIdentifier(value)) { provided.push({ name: nameOf(value), node: element, isClass: false }); continue; }
50
+ const provided = [];
51
+ let readable = true;
52
+ for (const element of list.elements) {
53
+ if (ts.isIdentifier(element)) {
54
+ provided.push({ name: nameOf(element), node: element, isClass: true });
55
+ continue;
56
+ }
57
+ if (ts.isObjectLiteralExpression(element)) {
58
+ const keys = element.properties.map(item => literalKey(ts, item));
59
+ const provide = element.properties.find(item => literalKey(ts, item) === 'provide');
60
+ const value = provide && ts.isPropertyAssignment(provide) ? provide.initializer : null;
61
+ if (keys.length === 2 && keys.includes('useValue') && value && ts.isIdentifier(value)) {
62
+ provided.push({ name: nameOf(value), node: element, isClass: false });
63
+ continue;
64
+ }
65
+ }
66
+ readable = false;
67
+ report(element, `${rel}: a provider is a class or \`{ provide: TOKEN, useValue: double }\` and nothing else (no useClass, useFactory, useExisting, spread or computed token).`);
63
68
  }
64
- readable = false;
65
- report(element, `${rel}: a provider is a class or \`{ provide: TOKEN, useValue: double }\` and nothing else (no useClass, useFactory, useExisting, spread or computed token).`);
66
- }
67
- return { provided, readable };
69
+ return { provided, readable };
68
70
  }
69
-
70
71
  function serviceClassFor(ts, rel, serviceRel, serviceFile, imports, list, report) {
71
- const first = list.elements[0];
72
- const serviceName = first && ts.isIdentifier(first) ? imports.get(first.text) : null;
73
- const target = serviceName ? path.posix.normalize(path.posix.join(path.posix.dirname(rel), serviceName.module)).replace(/\.[cm]?[jt]s$/u, '') : null;
74
- const serviceClass = serviceName && target === serviceRel.replace(/\.ts$/u, '')
75
- ? serviceFile.sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === serviceName.name) : null;
76
- if (!serviceClass) report(first ?? list, `${rel}: the first provider is the service under test, imported from ./${path.posix.basename(serviceRel, '.ts')}.`);
77
- return serviceClass ? { serviceClass, serviceName } : null;
72
+ const first = list.elements[0];
73
+ const serviceName = first && ts.isIdentifier(first) ? imports.get(first.text) : null;
74
+ const target = serviceName ? path.posix.normalize(path.posix.join(path.posix.dirname(rel), serviceName.module)).replace(/\.[cm]?[jt]s$/u, '') : null;
75
+ const serviceClass = serviceName && target === serviceRel.replace(/\.ts$/u, '')
76
+ ? serviceFile.sourceFile.statements.find((statement) => ts.isClassDeclaration(statement) && statement.name?.text === serviceName.name) : null;
77
+ if (!serviceClass)
78
+ report(first ?? list, `${rel}: the first provider is the service under test, imported from ./${path.posix.basename(serviceRel, '.ts')}.`);
79
+ return serviceClass ? { serviceClass, serviceName: serviceName } : null; // a class is found only when the service name resolved
78
80
  }
79
-
80
81
  function checkDependencies(kit, rel, service, serviceFile, list, provided, report) {
81
- const { serviceName, serviceClass } = service;
82
- const dependencies = constructorDependencies(kit, serviceFile, serviceClass);
83
- const expected = [];
84
- for (const dependency of dependencies) {
85
- if (dependency.kind === 'unresolved') {
86
- report(list, `${rel}: a constructor dependency of ${serviceName.name} cannot be resolved to a token (${dependency.reason}), so its provider cannot be checked; inject it through an exported Inject<Thing>() decorator or a class type.`);
87
- continue;
82
+ const { serviceName, serviceClass } = service;
83
+ const dependencies = constructorDependencies(kit, serviceFile, serviceClass);
84
+ const expected = [];
85
+ for (const dependency of dependencies) {
86
+ if (dependency.kind === 'unresolved') {
87
+ report(list, `${rel}: a constructor dependency of ${serviceName.name} cannot be resolved to a token (${dependency.reason}), so its provider cannot be checked; inject it through an exported Inject<Thing>() decorator or a class type.`);
88
+ continue;
89
+ }
90
+ expected.push(dependency.name);
88
91
  }
89
- expected.push(dependency.name);
90
- }
91
- const remaining = [...expected];
92
- for (const item of provided.slice(1)) {
93
- const index = remaining.indexOf(item.name);
94
- if (index === -1) report(item.node, `${rel}: ${item.name} is provided but is not a constructor dependency of ${serviceName.name}; a unit spec provides exactly what the constructor needs.`);
95
- else remaining.splice(index, 1);
96
- }
97
- for (const name of remaining) report(list, `${rel}: ${name} is a constructor dependency of ${serviceName.name} but is not provided; add \`{ provide: ${name}, useValue: double }\` (or the class itself) to the providers.`);
92
+ const remaining = [...expected];
93
+ for (const item of provided.slice(1)) {
94
+ const index = remaining.indexOf(item.name);
95
+ if (index === -1)
96
+ report(item.node, `${rel}: ${item.name} is provided but is not a constructor dependency of ${serviceName.name}; a unit spec provides exactly what the constructor needs.`);
97
+ else
98
+ remaining.splice(index, 1);
99
+ }
100
+ for (const name of remaining)
101
+ report(list, `${rel}: ${name} is a constructor dependency of ${serviceName.name} but is not provided; add \`{ provide: ${name}, useValue: double }\` (or the class itself) to the providers.`);
98
102
  }
99
-
100
103
  function checkTestingModule({ ts, kit, rel, serviceRel, serviceFile, imports, call, report }) {
101
- const list = providerList(ts, call, rel, report);
102
- if (!list) return;
103
- const names = functionSubjectExports(ts, serviceFile.sourceFile);
104
- if (names) return checkFunctionSubject({ ts, rel, serviceRel, imports, call, list, names, report });
105
- const nameOf = identifier => imports.get(identifier.text)?.name ?? identifier.text;
106
- const { provided, readable } = readProviders(ts, list, rel, nameOf, report);
107
- if (!readable) return;
108
- const service = serviceClassFor(ts, rel, serviceRel, serviceFile, imports, list, report);
109
- if (!service) return;
110
- checkDependencies(kit, rel, service, serviceFile, list, provided, report);
104
+ const list = providerList(ts, call, rel, report);
105
+ if (!list)
106
+ return;
107
+ const names = functionSubjectExports(ts, serviceFile.sourceFile);
108
+ if (names) {
109
+ checkFunctionSubject({ ts, rel, serviceRel, imports, call, list, names, report });
110
+ return;
111
+ }
112
+ const nameOf = (identifier) => imports.get(identifier.text)?.name ?? identifier.text;
113
+ const { provided, readable } = readProviders(ts, list, rel, nameOf, report);
114
+ if (!readable)
115
+ return;
116
+ const service = serviceClassFor(ts, rel, serviceRel, serviceFile, imports, list, report);
117
+ if (!service)
118
+ return;
119
+ checkDependencies(kit, rel, service, serviceFile, list, provided, report);
111
120
  }
112
-
113
121
  function checkServiceSpec({ config, graph, kit, ts, rel, violations }) {
114
- const abs = path.join(config.root, ...rel.split('/'));
115
- if (!fs.existsSync(abs)) return false;
116
- const sourceFile = ts.createSourceFile(abs, fs.readFileSync(abs, 'utf8'), ts.ScriptTarget.Latest, true);
117
- const report = (node, message) => violations.push({ ruleId: RULE, path: rel, ...kit.at(rel, sourceFile, node), message });
118
- const imports = importsOf(ts, sourceFile);
119
- const serviceRel = rel.replace(/\.spec\.ts$/u, '.ts');
120
- const serviceFile = graph.files.get(serviceRel);
121
- if (!serviceFile) { report(sourceFile, `${rel} has no ${path.posix.basename(serviceRel)} beside it; a service spec sits next to the service it tests.`); return true; }
122
- const modules = testingModules(ts, sourceFile);
123
- if (!modules.length && valueObjectSubjects(ts, serviceFile.sourceFile)) return true;
124
- if (!modules.length) { report(sourceFile, `${rel} never calls Test.createTestingModule({ providers: [...] }); build the service from a testing module holding exactly its constructor dependencies.`); return true; }
125
- for (const call of modules) checkTestingModule({ ts, kit, rel, serviceRel, serviceFile, imports, call, report });
126
- return true;
122
+ const abs = path.join(config.root, ...rel.split('/'));
123
+ if (!fs.existsSync(abs))
124
+ return false;
125
+ const sourceFile = ts.createSourceFile(abs, fs.readFileSync(abs, 'utf8'), ts.ScriptTarget.Latest, true);
126
+ const report = (node, message) => { violations.push({ ruleId: RULE, path: rel, ...kit.at(rel, sourceFile, node), message }); };
127
+ // importsOf stores every binding's specifier under moduleKey, which defaults to 'module'
128
+ const imports = new Map(Array.from(importsOf(ts, sourceFile), ([local, record]) => [local, { name: record.name, module: record.module }]));
129
+ const serviceRel = rel.replace(/\.spec\.ts$/u, '.ts');
130
+ const serviceFile = graph.files.get(serviceRel);
131
+ if (!serviceFile) {
132
+ report(sourceFile, `${rel} has no ${path.posix.basename(serviceRel)} beside it; a service spec sits next to the service it tests.`);
133
+ return true;
134
+ }
135
+ const modules = testingModules(ts, sourceFile);
136
+ if (!modules.length && valueObjectSubjects(ts, serviceFile.sourceFile))
137
+ return true;
138
+ if (!modules.length) {
139
+ report(sourceFile, `${rel} never calls Test.createTestingModule({ providers: [...] }); build the service from a testing module holding exactly its constructor dependencies.`);
140
+ return true;
141
+ }
142
+ for (const call of modules)
143
+ checkTestingModule({ ts, kit, rel, serviceRel, serviceFile, imports, call, report });
144
+ return true;
127
145
  }
128
-
129
146
  export function checkUnitSpecProviders(input) {
130
- const { config, graph } = input;
131
- const kit = machineKit(input);
132
- const { ts } = kit;
133
- const violations = [];
134
- let specs = 0;
135
- const tree = treeOf(config.root);
136
- for (const rel of [...tree.files].filter(file => SPEC_ROOT.test(file) && file.endsWith('.service.spec.ts')).sort(byCodeUnit)) {
137
- if (checkServiceSpec({ config, graph, kit, ts, rel, violations })) specs += 1;
138
- }
139
- return { violations, coverage: { status: 'checked', specs, files: graph.files.size } };
147
+ const { config, graph } = input;
148
+ const kit = machineKit(input);
149
+ const { ts } = kit;
150
+ const violations = [];
151
+ let specs = 0;
152
+ const tree = treeOf(config.root);
153
+ for (const rel of [...tree.files].filter(file => SPEC_ROOT.test(file) && file.endsWith('.service.spec.ts')).sort(byCodeUnit)) {
154
+ if (checkServiceSpec({ config, graph, kit, ts, rel, violations }))
155
+ specs += 1;
156
+ }
157
+ return { violations, coverage: { status: 'checked', specs, files: graph.files.size } };
140
158
  }
@@ -1,142 +1,179 @@
1
- // declaration-shape.mjs - the dependency-free hfs.json shape validation used by the HFS slot loader. Semantic checks
2
- // against a loaded manifest remain in slots.mjs; this module mirrors modules/schemas/hfs-repo.schema.yaml only.
3
1
  import { isPlainObject } from '../../engine/plain-object.mjs';
4
2
  import { APP_KIND, connectionShapeProblems, NAME, PACKAGE_NAME, RUNTIME_KIND, SLOT_ID } from './manifest-shape.mjs';
5
3
  import { dbFunctionsOk } from './rule-params-shape.mjs';
6
4
  import { kindShapeProblems, patternShapeProblems } from './declaration-slots.mjs';
7
5
  import { byCodeUnit } from '../lib/list.mjs';
8
-
9
6
  /** Shape problems of the optional hfs.json `db` block of a lite app: the environment variable naming its database, its image, forced RLS and its application role. */
10
7
  const isStringList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === 'string' && entry.trim());
11
-
12
8
  function dbBlockProblems(block) {
13
- if (block === undefined) return [];
14
- if (!isPlainObject(block)) return ['db must be an object'];
15
- const bad = [];
16
- for (const key of Object.keys(block)) if (!['urlEnv', 'image', 'forceRls', 'forceRlsExemptions', 'appRole'].includes(key)) bad.push(`db has unknown key ${key}`);
17
- if (block.urlEnv !== undefined && (typeof block.urlEnv !== 'string' || !/^[A-Z][A-Z0-9_]*$/.test(block.urlEnv))) bad.push('db.urlEnv must name an UPPER_CASE environment variable');
18
- if (block.image !== undefined && (typeof block.image !== 'string' || !/@sha256:[0-9a-f]{64}$/.test(block.image))) bad.push('db.image must be a digest-pinned image reference');
19
- if (block.forceRls !== undefined && !isStringList(block.forceRls)) bad.push('db.forceRls must be a list of strings');
20
- if (block.appRole !== undefined && (typeof block.appRole !== 'string' || !/^[a-z][a-z0-9_]*$/.test(block.appRole))) bad.push('db.appRole must name a role');
21
- if (block.forceRlsExemptions !== undefined && !Array.isArray(block.forceRlsExemptions)) bad.push('db.forceRlsExemptions must be a list of { table, reason }');
22
- return bad;
9
+ if (block === undefined)
10
+ return [];
11
+ if (!isPlainObject(block))
12
+ return ['db must be an object'];
13
+ const bad = [];
14
+ for (const key of Object.keys(block))
15
+ if (!['urlEnv', 'image', 'forceRls', 'forceRlsExemptions', 'appRole'].includes(key))
16
+ bad.push(`db has unknown key ${key}`);
17
+ if (block.urlEnv !== undefined && (typeof block.urlEnv !== 'string' || !/^[A-Z][A-Z0-9_]*$/.test(block.urlEnv)))
18
+ bad.push('db.urlEnv must name an UPPER_CASE environment variable');
19
+ if (block.image !== undefined && (typeof block.image !== 'string' || !/@sha256:[0-9a-f]{64}$/.test(block.image)))
20
+ bad.push('db.image must be a digest-pinned image reference');
21
+ if (block.forceRls !== undefined && !isStringList(block.forceRls))
22
+ bad.push('db.forceRls must be a list of strings');
23
+ if (block.appRole !== undefined && (typeof block.appRole !== 'string' || !/^[a-z][a-z0-9_]*$/.test(block.appRole)))
24
+ bad.push('db.appRole must name a role');
25
+ if (block.forceRlsExemptions !== undefined && !Array.isArray(block.forceRlsExemptions))
26
+ bad.push('db.forceRlsExemptions must be a list of { table, reason }');
27
+ return bad;
23
28
  }
24
-
25
29
  function appShapeProblems(apps, at, side, names) {
26
- const bad = [];
27
- if (!Array.isArray(apps) || !apps.length) {
28
- bad.push(`${at}.apps must list every ${side}/apps/<name> with its kind`);
30
+ const bad = [];
31
+ if (!Array.isArray(apps) || !apps.length) {
32
+ bad.push(`${at}.apps must list every ${side}/apps/<name> with its kind`);
33
+ return bad;
34
+ }
35
+ apps.forEach((app, index) => {
36
+ if (!isPlainObject(app) || !NAME.test(String(app.name)) || !NAME.test(String(app.kind)) || Object.keys(app).some((key) => key !== 'name' && key !== 'kind'))
37
+ bad.push(`${at}.apps[${index}] must be {name, kind}`);
38
+ else if (names.has(app.name))
39
+ bad.push(`app ${app.name} is declared twice (${names.get(app.name)} and ${side})`);
40
+ else
41
+ names.set(app.name, side);
42
+ });
29
43
  return bad;
30
- }
31
- apps.forEach((app, index) => {
32
- if (!isPlainObject(app) || !NAME.test(String(app.name)) || !NAME.test(String(app.kind)) || Object.keys(app).some((key) => key !== 'name' && key !== 'kind')) bad.push(`${at}.apps[${index}] must be {name, kind}`);
33
- else if (names.has(app.name)) bad.push(`app ${app.name} is declared twice (${names.get(app.name)} and ${side})`);
34
- else names.set(app.name, side);
35
- });
36
- return bad;
37
44
  }
38
-
39
45
  function connectionProblems(side, value) {
40
- const bad = [];
41
- if (side !== 'be') {
42
- bad.push('connections belong to the be side');
43
- return bad;
44
- }
45
- const list = Array.isArray(value.connections) ? value.connections : null;
46
- const shape = connectionShapeProblems(list, value.apps);
47
- if (shape.length) {
48
- bad.push(...shape);
46
+ const bad = [];
47
+ if (side !== 'be') {
48
+ bad.push('connections belong to the be side');
49
+ return bad;
50
+ }
51
+ const list = Array.isArray(value.connections) ? value.connections : null;
52
+ const shape = connectionShapeProblems(list, value.apps);
53
+ if (shape.length) {
54
+ bad.push(...shape);
55
+ return bad;
56
+ }
57
+ if (new Set(list.map((connection) => connection.name)).size !== list.length)
58
+ bad.push('connections names must be unique');
59
+ for (const a of list)
60
+ for (const b of list)
61
+ if (a !== b && `${b.envPrefix}_`.startsWith(`${a.envPrefix}_`))
62
+ bad.push(`connections ${a.name} and ${b.name} share env keys (${a.envPrefix}_ covers ${b.envPrefix}_)`);
49
63
  return bad;
50
- }
51
- if (new Set(list.map((connection) => connection.name)).size !== list.length) bad.push('connections names must be unique');
52
- for (const a of list) for (const b of list) if (a !== b && `${b.envPrefix}_`.startsWith(`${a.envPrefix}_`)) bad.push(`connections ${a.name} and ${b.name} share env keys (${a.envPrefix}_ covers ${b.envPrefix}_)`);
53
- return bad;
54
64
  }
55
-
56
65
  /** Whether a declared list is present but not a list of distinct entries that all satisfy `valid`. */
57
66
  const isBadUniqueList = (list, valid) => list !== undefined && (!Array.isArray(list) || !list.every((entry) => valid(entry)) || new Set(list).size !== list.length);
58
-
59
67
  function validExtraPackage(entry) {
60
- return isPlainObject(entry) && Object.keys(entry).every(key => key === 'name' || key === 'reason')
61
- && typeof entry.name === 'string' && entry.name.length <= 214 && PACKAGE_NAME.test(entry.name)
62
- && typeof entry.reason === 'string' && entry.reason.trim().length > 0;
68
+ return isPlainObject(entry) && Object.keys(entry).every(key => key === 'name' || key === 'reason')
69
+ && typeof entry.name === 'string' && entry.name.length <= 214 && PACKAGE_NAME.test(entry.name)
70
+ && typeof entry.reason === 'string' && entry.reason.trim().length > 0;
63
71
  }
64
-
65
72
  function extraPackageProblems(side, entries) {
66
- if (entries === undefined) return [];
67
- if (side !== 'fe') return ['extraPackages belong to the fe side'];
68
- if (!Array.isArray(entries) || !entries.every(validExtraPackage)) return ['sides.fe.extraPackages must be a list of {name, reason} with a package name and a nonempty reason'];
69
- return [];
73
+ if (entries === undefined)
74
+ return [];
75
+ if (side !== 'fe')
76
+ return ['extraPackages belong to the fe side'];
77
+ if (!Array.isArray(entries) || !entries.every(validExtraPackage))
78
+ return ['sides.fe.extraPackages must be a list of {name, reason} with a package name and a nonempty reason'];
79
+ return [];
70
80
  }
71
-
72
81
  function grammarProblems(side, grammar) {
73
- if (grammar === undefined) return [];
74
- if (side !== 'fe') return ['grammar belongs to the fe side'];
75
- return typeof grammar === 'string' && NAME.test(grammar) ? [] : ['sides.fe.grammar must name a Grammar family'];
82
+ if (grammar === undefined)
83
+ return [];
84
+ if (side !== 'fe')
85
+ return ['grammar belongs to the fe side'];
86
+ return typeof grammar === 'string' && NAME.test(grammar) ? [] : ['sides.fe.grammar must name a Grammar family'];
76
87
  }
77
-
78
88
  function declarationSideProblems(side, value, names) {
79
- const bad = [];
80
- const at = `sides.${side}`;
81
- if (!isPlainObject(value)) return [`${at} must be an object`];
82
- for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing', 'dbFunctions'].includes(key)) bad.push(`${at} has unknown key ${key}`);
83
- if (value.dbFunctions !== undefined && (side !== 'be' || !dbFunctionsOk(value.dbFunctions, { bare: true }))) bad.push(`${at}.dbFunctions belongs to the be side and lists {name, reason} database functions, each schema-qualified (schema.name, never pg_catalog) or a bare pg built-in of the canon's list, with unique names`);
84
- bad.push(...appShapeProblems(value.apps, at, side, names));
85
- if (isBadUniqueList(value.optionalSlots, (slot) => SLOT_ID.test(String(slot)))) bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
86
- if (value.backing !== undefined && side !== 'be') bad.push('backing belongs to the be side');
87
- else if (isBadUniqueList(value.backing, (name) => NAME.test(String(name)))) bad.push(`${at}.backing must be a unique list of backing service names`);
88
- bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
89
- if (isBadUniqueList(value.reads, (read) => typeof read === 'string' && read.length > 0)) bad.push(`${at}.reads must be a unique list of paths`);
90
- if (value.connections !== undefined) bad.push(...connectionProblems(side, value));
91
- bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar));
92
- return bad;
89
+ const bad = [];
90
+ const at = `sides.${side}`;
91
+ if (!isPlainObject(value))
92
+ return [`${at} must be an object`];
93
+ for (const key of Object.keys(value))
94
+ if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing', 'dbFunctions'].includes(key))
95
+ bad.push(`${at} has unknown key ${key}`);
96
+ if (value.dbFunctions !== undefined && (side !== 'be' || !dbFunctionsOk(value.dbFunctions, { bare: true })))
97
+ bad.push(`${at}.dbFunctions belongs to the be side and lists {name, reason} database functions, each schema-qualified (schema.name, never pg_catalog) or a bare pg built-in of the canon's list, with unique names`);
98
+ bad.push(...appShapeProblems(value.apps, at, side, names));
99
+ if (isBadUniqueList(value.optionalSlots, (slot) => SLOT_ID.test(String(slot))))
100
+ bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
101
+ if (value.backing !== undefined && side !== 'be')
102
+ bad.push('backing belongs to the be side');
103
+ else if (isBadUniqueList(value.backing, (name) => NAME.test(String(name))))
104
+ bad.push(`${at}.backing must be a unique list of backing service names`);
105
+ bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
106
+ if (isBadUniqueList(value.reads, (read) => typeof read === 'string' && read.length > 0))
107
+ bad.push(`${at}.reads must be a unique list of paths`);
108
+ if (value.connections !== undefined)
109
+ bad.push(...connectionProblems(side, value));
110
+ bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar));
111
+ return bad;
93
112
  }
94
-
95
113
  /** Product vocabulary is a declaration, never a switch for a rule. */
96
114
  function lexiconBlockProblems(lexicon) {
97
- if (lexicon === undefined) return [];
98
- if (!isPlainObject(lexicon)) return ['lexicon must be an object'];
99
- const bad = [];
100
- for (const key of Object.keys(lexicon)) if (key !== 'removed') bad.push(`lexicon has unknown key ${key}`);
101
- if (isBadUniqueList(lexicon.removed, (word) => typeof word === 'string' && word.trim().length > 0)) bad.push('lexicon.removed must be a unique list of nonempty words');
102
- return bad;
115
+ if (lexicon === undefined)
116
+ return [];
117
+ if (!isPlainObject(lexicon))
118
+ return ['lexicon must be an object'];
119
+ const bad = [];
120
+ for (const key of Object.keys(lexicon))
121
+ if (key !== 'removed')
122
+ bad.push(`lexicon has unknown key ${key}`);
123
+ if (isBadUniqueList(lexicon.removed, (word) => typeof word === 'string' && word.trim().length > 0))
124
+ bad.push('lexicon.removed must be a unique list of nonempty words');
125
+ return bad;
103
126
  }
104
-
105
127
  /** Front-end error reporting remains optional in both editions. */
106
128
  function observeBlockProblems(observe) {
107
- if (observe === undefined) return [];
108
- if (!isPlainObject(observe)) return ['observe must be an object'];
109
- const bad = [];
110
- for (const key of Object.keys(observe)) if (key !== 'reporter') bad.push(`observe has unknown key ${key}`);
111
- if (observe.reporter !== undefined && (typeof observe.reporter !== 'string' || !observe.reporter.trim())) bad.push('observe.reporter must name the optional error reporter');
112
- return bad;
129
+ if (observe === undefined)
130
+ return [];
131
+ if (!isPlainObject(observe))
132
+ return ['observe must be an object'];
133
+ const bad = [];
134
+ for (const key of Object.keys(observe))
135
+ if (key !== 'reporter')
136
+ bad.push(`observe has unknown key ${key}`);
137
+ if (observe.reporter !== undefined && (typeof observe.reporter !== 'string' || !observe.reporter.trim()))
138
+ bad.push('observe.reporter must name the optional error reporter');
139
+ return bad;
113
140
  }
114
-
115
141
  const DECLARATION_KEYS = new Set(['hfs', 'kind', 'project', 'edition', 'db', 'sides', 'browser', 'lexicon', 'observe']);
116
142
  const RUNTIME_DECLARATION_KEYS = new Set(['hfs', 'kind', 'project']);
117
-
118
143
  function productDeclarationProblems(declaration, profiles) {
119
- const bad = [];
120
- for (const key of Object.keys(declaration)) if (!DECLARATION_KEYS.has(key)) bad.push(`unknown key ${key}`);
121
- bad.push(...dbBlockProblems(declaration.db), ...lexiconBlockProblems(declaration.lexicon), ...observeBlockProblems(declaration.observe));
122
- if (declaration.browser !== undefined && declaration.browser !== true) bad.push('browser is `true` when the app has a browser journey (slot app.browser), and is left out otherwise');
123
- if (declaration.kind !== APP_KIND) bad.push(`kind must be ${APP_KIND} (a product is one app repository with a be and an fe side) or ${RUNTIME_KIND} (the StarCi runtime repository)`);
124
- if (!isPlainObject(declaration.sides) || Object.keys(declaration.sides).sort(byCodeUnit).join() !== profiles.join()) { bad.push('sides must declare exactly be and fe'); return bad; }
125
- const names = new Map();
126
- for (const side of profiles) bad.push(...declarationSideProblems(side, declaration.sides[side], names));
127
- return bad;
144
+ const bad = [];
145
+ for (const key of Object.keys(declaration))
146
+ if (!DECLARATION_KEYS.has(key))
147
+ bad.push(`unknown key ${key}`);
148
+ bad.push(...dbBlockProblems(declaration.db), ...lexiconBlockProblems(declaration.lexicon), ...observeBlockProblems(declaration.observe));
149
+ if (declaration.browser !== undefined && declaration.browser !== true)
150
+ bad.push('browser is `true` when the app has a browser journey (slot app.browser), and is left out otherwise');
151
+ if (declaration.kind !== APP_KIND)
152
+ bad.push(`kind must be ${APP_KIND} (a product is one app repository with a be and an fe side) or ${RUNTIME_KIND} (the StarCi runtime repository)`);
153
+ if (!isPlainObject(declaration.sides) || Object.keys(declaration.sides).sort(byCodeUnit).join() !== profiles.join()) {
154
+ bad.push('sides must declare exactly be and fe');
155
+ return bad;
156
+ }
157
+ const names = new Map();
158
+ for (const side of profiles)
159
+ bad.push(...declarationSideProblems(side, declaration.sides[side], names));
160
+ return bad;
128
161
  }
129
-
130
162
  /** Shape problems of a parsed hfs.json, in the words of modules/schemas/hfs-repo.schema.yaml. */
131
163
  export function declarationShapeProblems(declaration, profiles) {
132
- const bad = [];
133
- if (!isPlainObject(declaration)) return ['hfs.json is not an object'];
134
- if (!(Number.isInteger(declaration.hfs) && declaration.hfs >= 1)) bad.push('hfs must be the pinned manifest major (an integer, 1 or more)');
135
- if (!NAME.test(String(declaration.project))) bad.push('project must be a project name');
136
- if (declaration.kind === RUNTIME_KIND) {
137
- for (const key of Object.keys(declaration)) if (!RUNTIME_DECLARATION_KEYS.has(key)) bad.push(`unknown key ${key} (a runtime declaration is {hfs, kind, project})`);
164
+ const bad = [];
165
+ if (!isPlainObject(declaration))
166
+ return ['hfs.json is not an object'];
167
+ if (!(Number.isInteger(declaration.hfs) && declaration.hfs >= 1))
168
+ bad.push('hfs must be the pinned manifest major (an integer, 1 or more)');
169
+ if (!NAME.test(String(declaration.project)))
170
+ bad.push('project must be a project name');
171
+ if (declaration.kind === RUNTIME_KIND) {
172
+ for (const key of Object.keys(declaration))
173
+ if (!RUNTIME_DECLARATION_KEYS.has(key))
174
+ bad.push(`unknown key ${key} (a runtime declaration is {hfs, kind, project})`);
175
+ return bad;
176
+ }
177
+ bad.push(...productDeclarationProblems(declaration, profiles));
138
178
  return bad;
139
- }
140
- bad.push(...productDeclarationProblems(declaration, profiles));
141
- return bad;
142
179
  }