@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.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/rules.yaml +6 -6
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- 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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
}
|