@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.
- package/CHANGELOG.md +16 -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
|
@@ -8,60 +8,61 @@
|
|
|
8
8
|
// The check reads the tracked tree and the manifests only. One finding per path (a manifest: one per script or dependency), and it is
|
|
9
9
|
// the only finding of a test file: the slot check leaves these paths to it (isFeTestPath).
|
|
10
10
|
import { found, readJson } from './read.mjs';
|
|
11
|
-
|
|
12
11
|
export const FE_NO_TESTS = 'FE_NO_TESTS';
|
|
13
12
|
const SPEC_FILE = /(?:\.(?:spec|test)|-spec)\.[cm]?[jt]sx?$/;
|
|
14
13
|
const TEST_DIRECTORY = /(?:^|\/)(?:e2e|__tests__|__mocks__|test-support)\//;
|
|
15
14
|
const TEST_TOOL_FILE = /(?:^|\/)(?:(?:vitest|jest|playwright)\.[^/]+|cypress\.config\.[^/]+|tsconfig\.e2e\.json|e2e\.ya?ml)$/;
|
|
16
15
|
const TEST_SCRIPT_NAME = /^(?:pre|post)?test(?::|$)/;
|
|
17
|
-
const TEST_RUNNER_COMMAND_SOURCE = String.raw`(?:^|[\s&|;(])(?:npx\s+)?(?:vitest|jest|playwright|cypress|mocha)(?=$|[\s&|;)])|\bnode\s+(?:--\S+\s+)*--test\b`;
|
|
16
|
+
const TEST_RUNNER_COMMAND_SOURCE = String.raw `(?:^|[\s&|;(])(?:npx\s+)?(?:vitest|jest|playwright|cypress|mocha)(?=$|[\s&|;)])|\bnode\s+(?:--\S+\s+)*--test\b`;
|
|
18
17
|
const TEST_RUNNER_COMMAND = new RegExp(TEST_RUNNER_COMMAND_SOURCE);
|
|
19
|
-
const TEST_DEPENDENCY_SOURCE = String.raw`^(?:vitest|@vitest\/.+|playwright|playwright-core|@playwright\/.+|jest|@jest\/.+|ts-jest|babel-jest|@types\/jest|jest-[\w-]+|mocha|@types\/mocha|cypress|@testing-library\/.+|jsdom|@types\/jsdom|happy-dom|axe-core|@axe-core\/.+|vitest-axe|@starci\/(?:vitest|jest|playwright)-preset)$`;
|
|
18
|
+
const TEST_DEPENDENCY_SOURCE = String.raw `^(?:vitest|@vitest\/.+|playwright|playwright-core|@playwright\/.+|jest|@jest\/.+|ts-jest|babel-jest|@types\/jest|jest-[\w-]+|mocha|@types\/mocha|cypress|@testing-library\/.+|jsdom|@types\/jsdom|happy-dom|axe-core|@axe-core\/.+|vitest-axe|@starci\/(?:vitest|jest|playwright)-preset)$`;
|
|
20
19
|
const TEST_DEPENDENCY = new RegExp(TEST_DEPENDENCY_SOURCE);
|
|
21
20
|
export const DEPENDENCY_SECTIONS = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
22
|
-
|
|
23
21
|
/** True for a path FE_NO_TESTS owns: a spec file, a test directory or a test-tool file. */
|
|
24
22
|
export const isFeTestPath = (file) => SPEC_FILE.test(file) || TEST_DIRECTORY.test(file) || TEST_TOOL_FILE.test(file);
|
|
25
|
-
|
|
26
23
|
function testPathFinding(file) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
let what = 'test tooling';
|
|
25
|
+
if (SPEC_FILE.test(file))
|
|
26
|
+
what = 'a test file';
|
|
27
|
+
else if (TEST_DIRECTORY.test(file))
|
|
28
|
+
what = 'inside a test directory';
|
|
29
|
+
return found(FE_NO_TESTS, file, `${file} is ${what}; a front-end repository has no tests, no test tooling and no exception: delete it`);
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
function testDependencyFindings(file, pkg) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
const findings = [];
|
|
33
|
+
for (const section of DEPENDENCY_SECTIONS) {
|
|
34
|
+
for (const name of Object.keys(pkg[section] ?? {})) {
|
|
35
|
+
if (TEST_DEPENDENCY.test(name))
|
|
36
|
+
findings.push(found(FE_NO_TESTS, file, `${file} ${section} names ${name}, a test dependency; a front-end repository has no tests: delete the dependency`));
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
return findings;
|
|
39
|
+
return findings;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
41
|
function packageTestFindings(repoRoot, file) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
if (file !== 'package.json' && !file.endsWith('/package.json'))
|
|
43
|
+
return [];
|
|
44
|
+
if (file.includes('node_modules/'))
|
|
45
|
+
return [];
|
|
46
|
+
const pkg = readJson(repoRoot, file);
|
|
47
|
+
if (!pkg || typeof pkg !== 'object')
|
|
48
|
+
return [];
|
|
49
|
+
const findings = [];
|
|
50
|
+
for (const [name, command] of Object.entries(pkg.scripts ?? {})) {
|
|
51
|
+
if (TEST_SCRIPT_NAME.test(name) || TEST_RUNNER_COMMAND.test(String(command)))
|
|
52
|
+
findings.push(found(FE_NO_TESTS, file, `${file} script ${name} is a test script (${String(command).slice(0, 80)}); a front-end repository has no tests: delete the script`));
|
|
53
|
+
}
|
|
54
|
+
findings.push(...testDependencyFindings(file, pkg));
|
|
55
|
+
return findings;
|
|
54
56
|
}
|
|
55
|
-
|
|
56
57
|
/** The findings of R97 over the tracked paths `files` of a front-end repository at `repoRoot`. */
|
|
57
58
|
export function feNoTestsFindings({ repoRoot, files }) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const findings = [];
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
if (isFeTestPath(file)) {
|
|
62
|
+
findings.push(testPathFinding(file));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
findings.push(...packageTestFindings(repoRoot, file));
|
|
63
66
|
}
|
|
64
|
-
findings
|
|
65
|
-
}
|
|
66
|
-
return findings;
|
|
67
|
+
return findings;
|
|
67
68
|
}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
// read.mjs - what the tree checks of hfs-check.mjs share: one bounded text read and the shape of a finding.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
|
|
5
4
|
/** Files above this size are not read by a tree check (a tracked binary or a generated dump is no source of these laws). */
|
|
6
5
|
const MAX_READ_BYTES = 1024 * 1024;
|
|
7
|
-
|
|
8
6
|
/** The text of `rel` under `repoRoot`, or null when it is absent, unreadable, over MAX_READ_BYTES or binary. */
|
|
9
7
|
export function readText(repoRoot, rel) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
try {
|
|
9
|
+
const target = path.join(repoRoot, rel);
|
|
10
|
+
if (fs.statSync(target).size > MAX_READ_BYTES)
|
|
11
|
+
return null;
|
|
12
|
+
const text = fs.readFileSync(target, 'utf8');
|
|
13
|
+
return text.includes('\0') ? null : text;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
|
-
|
|
20
19
|
/** The JSON of `rel`, or null when it is absent or not JSON. */
|
|
21
20
|
export function readJson(repoRoot, rel) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const text = readText(repoRoot, rel);
|
|
22
|
+
if (text === null)
|
|
23
|
+
return null;
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(text);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
|
-
|
|
27
31
|
/** One error finding of `code` on `file`; `extra` carries the finding's own fields. */
|
|
28
32
|
export const found = (code, file, message, extra = {}) => ({ code, level: 'error', path: file, ...extra, message });
|
|
@@ -32,7 +32,7 @@ export function untrackedSecretFindings({ repoRoot, files, repo }) {
|
|
|
32
32
|
/**
|
|
33
33
|
* The findings of R06 for one tracked file that no forbidden slot claims: a secret by being (an env file, a key file), an `.enc` that is
|
|
34
34
|
* no sops envelope, or a line that matches a secret pattern. `text` is the file's text, or null when it cannot be read (binary, too
|
|
35
|
-
* large, absent). The whole-tree check reads the work tree and the commit hook (`starci app
|
|
35
|
+
* large, absent). The whole-tree check reads the work tree and the commit hook (`starci app check --staged`) reads the staged blob: one judgement.
|
|
36
36
|
*/
|
|
37
37
|
export function secretFileFindings({ file, text, manifestText }) {
|
|
38
38
|
const being = FORBIDDEN_FILES.find((rule) => rule.test(file));
|
|
@@ -6,24 +6,23 @@
|
|
|
6
6
|
// carries no spec, and a spec that guards one moves into a layer or goes. A file no slot owns (`tools/x.spec.ts`) is judged too, so the
|
|
7
7
|
// finding names the rule rather than only the missing slot. Which folder is a layer is read from the slot manifest, never spelled here.
|
|
8
8
|
import { found } from './read.mjs';
|
|
9
|
-
|
|
10
9
|
const SPEC_PLACEMENT = 'BE_SPEC_PLACEMENT';
|
|
11
10
|
const SPEC_FILE = /(?:\.(?:spec|test)|-spec)\.[cm]?[jt]sx?$/;
|
|
12
11
|
const TEST_SLOT_TESTS = new Set(['unit-beside', 'e2e']);
|
|
13
|
-
|
|
14
12
|
/** True for a file name that is a spec or a test. */
|
|
15
13
|
export const isSpecFile = (file) => SPEC_FILE.test(file);
|
|
16
|
-
|
|
17
14
|
/** The findings of R102 over the tracked paths `files` of a back-end repository; `resolver` names the slots. */
|
|
18
15
|
export function specPlacementFindings({ files, resolver }) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
const findings = [];
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
if (!isSpecFile(file) || file.includes('node_modules/'))
|
|
19
|
+
continue;
|
|
20
|
+
const classified = resolver.classifyPath(file);
|
|
21
|
+
const slot = classified.status === 'owned' ? resolver.slot(classified.slot) : null;
|
|
22
|
+
if (slot && TEST_SLOT_TESTS.has(slot.tests))
|
|
23
|
+
continue;
|
|
24
|
+
const where = slot ? `slot ${slot.id}` : 'no slot';
|
|
25
|
+
findings.push(found(SPEC_PLACEMENT, file, `${file} is a spec outside the test layers (${where}); a unit spec is <name>.service.spec.ts beside its service and an integration, e2e or contract spec sits under src/tests/{integration,e2e,contract}; an operational script or a tool carries no spec`));
|
|
26
|
+
}
|
|
27
|
+
return findings;
|
|
29
28
|
}
|
|
@@ -1,102 +1,97 @@
|
|
|
1
1
|
// slot-app-view.mjs - the resolver of a whole app: a root path is answered by the scope of the app root, a path below a side folder
|
|
2
2
|
// (be/, fe/) by that side's scope with the side prefixed back onto every path and root it returns. Only the declared `reads` cross sides.
|
|
3
3
|
// slots.mjs builds the scopes (`root` and `sides`, each a resolver of one scope) and hands them to appResolver.
|
|
4
|
-
import { APP_SCOPE, PROFILES } from './slot-manifest-shape.mjs';
|
|
4
|
+
import { APP_SCOPE, isSide, PROFILES } from './slot-manifest-shape.mjs';
|
|
5
5
|
import { cleanSlotPath } from './slot-path.mjs';
|
|
6
|
-
|
|
6
|
+
/** True for the view of a whole app (profile app), the one resolveRepoDeclaration builds with both sides. */
|
|
7
|
+
export const isAppRepo = (repo) => repo.sides !== undefined;
|
|
7
8
|
/** { side, rest } when `p` lies below a side folder, else null. */
|
|
8
9
|
function splitSide(input) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const p = cleanSlotPath(input);
|
|
11
|
+
const slash = p.indexOf('/');
|
|
12
|
+
const head = slash < 0 ? p : p.slice(0, slash);
|
|
13
|
+
return isSide(head) && slash > 0 ? { side: head, rest: p.slice(slash + 1) } : null;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
15
|
const under = (side, rel) => (rel ? `${side}/${rel}` : side);
|
|
16
|
-
|
|
17
16
|
function prefixed(side, c) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
return {
|
|
18
|
+
...c,
|
|
19
|
+
path: under(side, c.path),
|
|
20
|
+
side,
|
|
21
|
+
...(c.root !== undefined ? { root: under(side, c.root) } : {}),
|
|
22
|
+
...(c.nearest ? { nearest: { ...c.nearest, matchedPrefix: under(side, c.nearest.matchedPrefix), matchedDepth: c.nearest.matchedDepth + 1 } } : {}),
|
|
23
|
+
};
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
function classifyApp({ root, sides }, input) {
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const at = splitSide(input);
|
|
27
|
+
return at ? prefixed(at.side, sides[at.side].classifyPath(at.rest)) : root.classifyPath(input);
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
function ownerApp({ root, sides }, input) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const at = splitSide(input);
|
|
31
|
+
if (!at)
|
|
32
|
+
return root.ownerOf(input);
|
|
33
|
+
const owner = sides[at.side].ownerOf(at.rest);
|
|
34
|
+
return owner ? { ...owner, root: under(at.side, owner.root), side: at.side } : null;
|
|
37
35
|
}
|
|
38
|
-
|
|
39
36
|
/** Whether `toPath`, of the other side, lies below a path `fromSide` declares it reads. */
|
|
40
37
|
const readsPath = (repo, fromSide, toPath) => repo.sides[fromSide].reads.some((read) => `${cleanSlotPath(toPath)}/`.startsWith(read));
|
|
41
|
-
|
|
42
38
|
/** The verdict of an import from a side file to a path of the other side (or of the app root, `toSide` null): allowed only through a declared read. */
|
|
43
39
|
function sideCrossing(repo, fromSide, toSide, toPath) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
return readsPath(repo, fromSide, toPath)
|
|
41
|
+
? { allowed: true, reason: 'sideRead', fromSide, toSide }
|
|
42
|
+
: { allowed: false, reason: 'crossSide', fromSide, toSide, reads: repo.sides[fromSide].reads };
|
|
47
43
|
}
|
|
48
|
-
|
|
49
44
|
function importAllowedApp({ repo, root, sides }, fromPath, toPath) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
const from = splitSide(fromPath);
|
|
46
|
+
const to = splitSide(toPath);
|
|
47
|
+
// A side file may read an app-root path (db/types/) only through a declared read, exactly as it reads the other side.
|
|
48
|
+
if (from && from.side !== to?.side)
|
|
49
|
+
return sideCrossing(repo, from.side, to?.side ?? null, toPath);
|
|
50
|
+
if (from && to)
|
|
51
|
+
return sides[from.side].importAllowed(from.rest, to.rest);
|
|
52
|
+
return root.importAllowed(fromPath, toPath);
|
|
56
53
|
}
|
|
57
|
-
|
|
58
54
|
function requiredPathsApp({ root, sides }) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
const own = root.requiredPaths();
|
|
56
|
+
const paths = [...own.paths];
|
|
57
|
+
const minimums = [...own.minimums];
|
|
58
|
+
for (const side of PROFILES) {
|
|
59
|
+
const required = sides[side].requiredPaths();
|
|
60
|
+
paths.push(...required.paths.map((entry) => ({ ...entry, path: under(side, entry.path), side })));
|
|
61
|
+
minimums.push(...required.minimums.map((entry) => ({ ...entry, side })));
|
|
62
|
+
}
|
|
63
|
+
return { paths, minimums };
|
|
68
64
|
}
|
|
69
|
-
|
|
70
65
|
function slotEnabledApp({ root, sides }, slot) {
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
if (slot.profiles.includes(APP_SCOPE))
|
|
67
|
+
return root.slotEnabled(slot);
|
|
68
|
+
return PROFILES.some((side) => slot.profiles.includes(side) && sides[side].slotEnabled(slot));
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
/** The resolver of the app `repo`: `root` answers its root paths and `sides[side]` the paths below that side's folder. */
|
|
76
71
|
export function appResolver(repo, root, sides) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
72
|
+
const view = { repo, root, sides };
|
|
73
|
+
const allSlots = [...new Map([...root.slots(), ...PROFILES.flatMap((side) => sides[side].slots())].map((s) => [s.id, s])).values()];
|
|
74
|
+
const byId = new Map(allSlots.map((s) => [s.id, s]));
|
|
75
|
+
const classifyPath = (input) => classifyApp(view, input);
|
|
76
|
+
return Object.freeze({
|
|
77
|
+
repo,
|
|
78
|
+
sides: Object.freeze(sides),
|
|
79
|
+
/** The side of a path (be, fe) or null for a root path. */
|
|
80
|
+
sideOf: (input) => splitSide(input)?.side ?? null,
|
|
81
|
+
slot: (id) => byId.get(id) ?? null,
|
|
82
|
+
slots: () => allSlots,
|
|
83
|
+
slotEnabled: (slot) => slotEnabledApp(view, slot),
|
|
84
|
+
classifyPath,
|
|
85
|
+
slotOf: (p) => { const c = classifyPath(p); return c.slot ? byId.get(c.slot) : null; },
|
|
86
|
+
ownerOf: (input) => ownerApp(view, input),
|
|
87
|
+
tierOf: (input) => { const at = splitSide(input); return at ? sides[at.side].tierOf(at.rest) : root.tierOf(input); },
|
|
88
|
+
importAllowed: (fromPath, toPath) => importAllowedApp(view, fromPath, toPath),
|
|
89
|
+
requiredFiles: (input) => { const at = splitSide(input); return at ? sides[at.side].requiredFiles(at.rest).map((p) => under(at.side, p)) : root.requiredFiles(input); },
|
|
90
|
+
requiredPaths: () => requiredPathsApp(view),
|
|
91
|
+
trackingOf: (p) => classifyPath(p).tracking ?? null,
|
|
92
|
+
isTracked: (p) => classifyPath(p).tracking === 'tracked',
|
|
93
|
+
// The root has no tier and no rule parameters of its own; each side has them (sides.<side>.ruleParams()).
|
|
94
|
+
ruleParams: () => null,
|
|
95
|
+
allowedImports: () => null,
|
|
96
|
+
});
|
|
102
97
|
}
|
|
@@ -4,62 +4,66 @@ import { globExpression } from '../lib/glob.mjs';
|
|
|
4
4
|
import { declaredSlotEnabled } from './declaration-slots.mjs';
|
|
5
5
|
import { bestMatch, fillVars, matchVariants, nearestSlot } from './slot-match.mjs';
|
|
6
6
|
import { cleanSlotPath } from './slot-path.mjs';
|
|
7
|
-
|
|
8
7
|
/** Whether the repository of the scope holds the slot. */
|
|
9
8
|
export function slotEnabled(scope, slot) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
// A provider slot is gated by its provider in every edition: litePresence may lift it to required, but it still
|
|
10
|
+
// exists for this repository only while a connection declares the provider.
|
|
11
|
+
if (slot.provider !== undefined)
|
|
12
|
+
return declaredSlotEnabled(slot, scope.repo);
|
|
13
|
+
if (slot.presence !== 'opt-in')
|
|
14
|
+
return true;
|
|
15
|
+
return declaredSlotEnabled(slot, scope.repo);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
17
|
/** The folder kind of a file in its slot, from a named layer or kind folder. */
|
|
18
18
|
function kindOf({ variant, slot, root }, p) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const names = [...(slot.layers ?? []), ...(slot.kinds ?? [])];
|
|
20
|
+
if (!names.length)
|
|
21
|
+
return null;
|
|
22
|
+
const literal = variant.segments.find((segment) => names.includes(segment));
|
|
23
|
+
if (literal)
|
|
24
|
+
return literal;
|
|
25
|
+
const below = root ? p.slice(root.length + 1) : p;
|
|
26
|
+
return below.split('/').slice(0, -1).find((segment) => names.includes(segment)) ?? null;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
28
|
/** The role of a file in its slot: the entry of `roles` whose file name (variables filled from the path, `*` a wildcard inside the name) matches the file's name. */
|
|
28
29
|
function roleOf(slot, bindings, p) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const name = p.split('/').pop();
|
|
31
|
+
for (const [role, file] of Object.entries(slot.roles ?? {}))
|
|
32
|
+
if (globExpression(fillVars(file, bindings)).test(name))
|
|
33
|
+
return role;
|
|
34
|
+
return null;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
36
|
/**
|
|
35
37
|
* status: owned | forbidden (external slot) | not-enabled (opt-in slot the repository did not declare) | ambiguous
|
|
36
38
|
* (two slots of equal specificity; a manifest gap) | no-slot (code HFS_SLOT_UNDECLARED, with the nearest slot).
|
|
37
39
|
*/
|
|
38
40
|
export function classifyIn(scope, input) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
const p = cleanSlotPath(input);
|
|
42
|
+
const { hit, ambiguous } = bestMatch(matchVariants(scope, p));
|
|
43
|
+
if (ambiguous.length)
|
|
44
|
+
return { path: p, status: 'ambiguous', candidates: ambiguous };
|
|
45
|
+
if (!hit)
|
|
46
|
+
return { path: p, status: 'no-slot', code: 'HFS_SLOT_UNDECLARED', nearest: nearestSlot(scope.variants, p) };
|
|
47
|
+
const { slot, root, bindings } = hit;
|
|
48
|
+
const status = (slot.presence === 'forbidden' && 'forbidden') || (slotEnabled(scope, slot) ? 'owned' : 'not-enabled');
|
|
49
|
+
const kind = kindOf(hit, p);
|
|
50
|
+
const role = roleOf(slot, bindings, p);
|
|
51
|
+
return { path: p, status, slot: slot.id, root, bindings, ...(kind ? { kind } : {}), ...(role ? { role } : {}), presence: slot.presence, tracking: slot.tracked, ...(status === 'forbidden' ? { goesTo: slot.goesTo } : {}) };
|
|
48
52
|
}
|
|
49
|
-
|
|
50
53
|
/** The owner unit of `p`: the most specific owner slot instance containing it (a slot's own root when it owns nothing). */
|
|
51
54
|
export function ownerIn(scope, input) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const p = cleanSlotPath(input);
|
|
56
|
+
const { hit } = bestMatch(matchVariants(scope, p, (s) => s.owner === true));
|
|
57
|
+
return hit ? { slot: hit.slot.id, root: hit.root, bindings: hit.bindings } : null;
|
|
55
58
|
}
|
|
56
|
-
|
|
57
59
|
/** The tier of `p` in the direction matrix: its slot's tier, the owner's for an inheriting slot, none for an untiered one; null when no slot owns it. */
|
|
58
60
|
export function tierIn(scope, input) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
const c = classifyIn(scope, input);
|
|
62
|
+
if (!c.slot)
|
|
63
|
+
return null;
|
|
64
|
+
const tier = scope.byId.get(c.slot).tier;
|
|
65
|
+
if (tier !== 'inherit')
|
|
66
|
+
return tier;
|
|
67
|
+
const owner = ownerIn(scope, input);
|
|
68
|
+
return owner ? scope.byId.get(owner.slot).tier : 'none';
|
|
65
69
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// slot-errors.mjs - the shared refusal type for HFS manifest and declaration loaders.
|
|
2
2
|
export class HfsSlotsError extends Error {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
code;
|
|
4
|
+
details;
|
|
5
|
+
constructor(code, message, details = {}) {
|
|
6
|
+
super(`${code}: ${message}`);
|
|
7
|
+
this.name = 'HfsSlotsError';
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.details = details;
|
|
10
|
+
}
|
|
9
11
|
}
|
|
10
|
-
|
|
11
12
|
export const fail = (code, message, details) => { throw new HfsSlotsError(code, message, details); };
|