@starci/eslint-canon-be 3.18.4 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs-view.d.ts +5 -0
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/schema-authority.js +66 -2
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { checkerScope } from './required-files.mjs';
|
|
2
|
-
import { allowsFile } from '../allows.mjs';
|
|
3
|
-
import { locateDeclaration } from '../slots.mjs';
|
|
4
|
-
import { DEFAULT_ENVIRONMENT, STACKS_DIRECTORY, STATEFUL_KINDS, namesOfService, readStack } from '../../lib/stack-services.mjs';
|
|
5
|
-
import { unwrapEach } from './ast-walks.mjs';
|
|
6
|
-
import { hasAnyFlag, nameText, sourceLocation } from '../../lib/ts-ast.mjs';
|
|
7
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
8
|
-
/**
|
|
9
|
-
* R47 `test-world-files` (BE_TEST_TOPOLOGY). Judgements over the test world, read through slots, the repository's own
|
|
10
|
-
* stack definition (`.starcistacks/<env>`, scripts/lib/stack-services.mjs) and the world's declaration
|
|
11
|
-
* (`test-world.config.ts`, read in the shape @starci/test-world defines), never through a path or a name list:
|
|
12
|
-
*
|
|
13
|
-
* 1. Files. `src/tests/world/` is the only test infrastructure location, and it holds only what its slot `allows`
|
|
14
|
-
* (knowledge/hfs/slots.yaml be.tests.world: global-setup.ts, global-teardown.ts, use-test-world.ts, and fakes/; kit/ is
|
|
15
|
-
* its own slot, be.tests.world.kit) plus files at its root whose role suffix is in ruleParams.be.suffixes
|
|
16
|
-
* (`stripe.client.ts`, `checkout.contracts.ts`, `test-world.config.ts`, ...). Every tracked file below the world root is
|
|
17
|
-
* matched by the slot's own entries through `allowsFile`.
|
|
18
|
-
* 2. The declaration. `test-world.config.ts` declares the world in a named form R89 allows: the destructured export
|
|
19
|
-
* `export const { useTestWorld, useSandbox } = defineTestWorld({ ... })`, or the typed form
|
|
20
|
-
* `const world: TestWorldApi = defineTestWorld({ ... })` whose `useTestWorld` and `useSandbox` are exported consts typed from
|
|
21
|
-
* `TestWorldApi` (a `const` initialized by a `defineTestWorld(<object literal>)` call). A config without it (a default export, or a declaration the machine cannot
|
|
22
|
-
* read) is refused: the world it declares could not be judged.
|
|
23
|
-
* 3. Fakes against the stack (owner refinement 2026-09-30). Every service the stack declares runs real in the world; a fake
|
|
24
|
-
* (a `fakes/<provider>/` folder, or a `fakes` entry of the declaration such as `smtp: smtpFake()`) is a network-edge fake
|
|
25
|
-
* of an external SaaS the team does not operate. A fake of a stack service (its own name, its image repository or a
|
|
26
|
-
* well-known alias of the image) is refused, except the one owner-approved exception: a stack service that is stateless
|
|
27
|
-
* compute needing special hardware or an external model (GPU inference, a self-hosted embedding model) whose `stacks` entry
|
|
28
|
-
* declares it faked: `stacks: { "<stack service>": { fakedBy: "<fake>", reason: "<non-empty>" } }`. A stack service of a
|
|
29
|
-
* stateful kind (database, cache, identity, storage, mail, queue, search) or with a persistent volume is never accepted, and
|
|
30
|
-
* an entry that names a stack service or a fake (a `fakes` entry or a `fakes/` folder) that does not exist, or has no
|
|
31
|
-
* reason, is refused as stale or empty. The declaration's `stack` (`".starcistacks/<env>"`) names the stack environment the
|
|
32
|
-
* world runs (default `dev`); the machine reads the literal object of the declaration through the TypeScript AST and
|
|
33
|
-
* nothing else of it.
|
|
34
|
-
*/
|
|
35
|
-
export const TEST_WORLD_FILES_RULE_IDS = ['BE_TEST_TOPOLOGY'];
|
|
36
|
-
const RULE = 'BE_TEST_TOPOLOGY';
|
|
37
|
-
const WORLD_SLOT = 'be.tests.world';
|
|
38
|
-
const FAKES_DIRECTORY = 'fakes/';
|
|
39
|
-
const CONFIG_FILE = 'test-world.config.ts';
|
|
40
|
-
const DEFINE = 'defineTestWorld';
|
|
41
|
-
const NAMED_FORM = `export const { useTestWorld, useSandbox } = ${DEFINE}({ ... })`;
|
|
42
|
-
const TYPED_FORM = `const world: TestWorldApi = ${DEFINE}({ ... })` + ' with export const useTestWorld / useSandbox typed from it';
|
|
43
|
-
const defaultEnvironment = DEFAULT_ENVIRONMENT;
|
|
44
|
-
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
45
|
-
const unwrap = (ts, node) => unwrapEach(ts, node, [ts.isParenthesizedExpression, ts.isAsExpression, ts.isSatisfiesExpression]);
|
|
46
|
-
const propertyOf = (ts, literal, key) => literal.properties.find((property) => ts.isPropertyAssignment(property) && nameText(ts, property.name) === key)?.initializer ?? null;
|
|
47
|
-
const isExported = (ts, statement) => (statement.modifiers ?? []).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
48
|
-
/** The object literal of `defineTestWorld(<object literal>)`, or null. */
|
|
49
|
-
function defineLiteral(ts, expression) {
|
|
50
|
-
const call = unwrap(ts, expression);
|
|
51
|
-
if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression) || call.expression.text !== DEFINE)
|
|
52
|
-
return null;
|
|
53
|
-
const [first] = call.arguments;
|
|
54
|
-
const literal = first ? unwrap(ts, first) : null;
|
|
55
|
-
return literal && ts.isObjectLiteralExpression(literal) ? literal : null;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The declaration of the world: the object literal of a top-level `const` initialized by `defineTestWorld({ ... })`, or null. The config
|
|
59
|
-
* exports `useTestWorld` and `useSandbox` either by destructuring that call (the original form) or, typed, from the world the call
|
|
60
|
-
* built: `const world: TestWorldApi = defineTestWorld({ ... })` with `export const useTestWorld: TestWorldApi["useTestWorld"] = world.useTestWorld`.
|
|
61
|
-
* Both are read; a world no exported name reaches is refused by the caller.
|
|
62
|
-
*/
|
|
63
|
-
function configLiteral(ts, sourceFile) {
|
|
64
|
-
for (const statement of sourceFile.statements) {
|
|
65
|
-
if (!ts.isVariableStatement(statement))
|
|
66
|
-
continue;
|
|
67
|
-
if (!hasAnyFlag(statement.declarationList.flags, ts.NodeFlags.Const))
|
|
68
|
-
continue;
|
|
69
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
70
|
-
const literal = declaration.initializer ? defineLiteral(ts, declaration.initializer) : null;
|
|
71
|
-
if (literal && (isExported(ts, statement) || exportsWorld(ts, sourceFile)))
|
|
72
|
-
return literal;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
/** Whether the file exports both `useTestWorld` and `useSandbox` as consts (the typed form re-exports them from the built world). */
|
|
78
|
-
function exportsWorld(ts, sourceFile) {
|
|
79
|
-
const exported = new Set();
|
|
80
|
-
for (const statement of sourceFile.statements) {
|
|
81
|
-
if (!ts.isVariableStatement(statement) || !isExported(ts, statement))
|
|
82
|
-
continue;
|
|
83
|
-
for (const declaration of statement.declarationList.declarations)
|
|
84
|
-
if (ts.isIdentifier(declaration.name))
|
|
85
|
-
exported.add(declaration.name.text);
|
|
86
|
-
}
|
|
87
|
-
return exported.has('useTestWorld') && exported.has('useSandbox');
|
|
88
|
-
}
|
|
89
|
-
/** `stack` as the environment it names: the last segment of `".starcistacks/<env>"`; null when absent or not a literal. */
|
|
90
|
-
function environmentOf(ts, literal) {
|
|
91
|
-
const node = literal ? propertyOf(ts, literal, 'stack') : null;
|
|
92
|
-
const value = node ? unwrap(ts, node) : null;
|
|
93
|
-
if (!value || !ts.isStringLiteralLike(value))
|
|
94
|
-
return null;
|
|
95
|
-
return value.text.split(/[\\/]+/u).filter(Boolean).findLast(Boolean) ?? null;
|
|
96
|
-
}
|
|
97
|
-
/** The keys of the declaration's `fakes` object literal, with their positions. */
|
|
98
|
-
function fakeEntriesOf(ts, sourceFile, literal) {
|
|
99
|
-
const node = literal ? propertyOf(ts, literal, 'fakes') : null;
|
|
100
|
-
const value = node ? unwrap(ts, node) : null;
|
|
101
|
-
if (!value || !ts.isObjectLiteralExpression(value))
|
|
102
|
-
return [];
|
|
103
|
-
return value.properties
|
|
104
|
-
.map(property => ({ name: nameText(ts, property.name), ...sourceLocation(sourceFile, property) }))
|
|
105
|
-
.filter((entry) => Boolean(entry.name));
|
|
106
|
-
}
|
|
107
|
-
/** The `fakedBy` entry of one `stacks` property, or null when the property does not declare one. */
|
|
108
|
-
function fakedByEntry(ts, sourceFile, property) {
|
|
109
|
-
if (!ts.isPropertyAssignment(property))
|
|
110
|
-
return null;
|
|
111
|
-
const body = unwrap(ts, property.initializer);
|
|
112
|
-
if (!body || !ts.isObjectLiteralExpression(body))
|
|
113
|
-
return null;
|
|
114
|
-
const fake = propertyOf(ts, body, 'fakedBy');
|
|
115
|
-
if (!fake)
|
|
116
|
-
return null;
|
|
117
|
-
const reason = propertyOf(ts, body, 'reason');
|
|
118
|
-
return {
|
|
119
|
-
service: nameText(ts, property.name),
|
|
120
|
-
fake: ts.isStringLiteralLike(fake) ? fake.text : '',
|
|
121
|
-
reason: reason && ts.isStringLiteralLike(reason) ? reason.text.trim() : '',
|
|
122
|
-
...sourceLocation(sourceFile, property),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/** The `stacks` entries that declare `fakedBy`: [{service, fake, reason, line, column}]; a value the reader cannot read statically has an empty fake and reason. */
|
|
126
|
-
function fakedByOf(ts, sourceFile, literal) {
|
|
127
|
-
const node = literal ? propertyOf(ts, literal, 'stacks') : null;
|
|
128
|
-
const value = node ? unwrap(ts, node) : null;
|
|
129
|
-
if (!value || !ts.isObjectLiteralExpression(value))
|
|
130
|
-
return [];
|
|
131
|
-
return value.properties.map(property => fakedByEntry(ts, sourceFile, property)).filter((entry) => entry !== null);
|
|
132
|
-
}
|
|
133
|
-
function registerFakeProvider(fakeProviders, relative, file) {
|
|
134
|
-
if (!relative.startsWith(FAKES_DIRECTORY))
|
|
135
|
-
return;
|
|
136
|
-
const [provider, ...rest] = relative.slice(FAKES_DIRECTORY.length).split('/');
|
|
137
|
-
if (provider !== undefined && rest.length > 0 && !fakeProviders.has(provider))
|
|
138
|
-
fakeProviders.set(provider, file);
|
|
139
|
-
}
|
|
140
|
-
function isRoleFileAtRoot(relative, suffixes) {
|
|
141
|
-
const parts = relative.slice(0, -'.ts'.length).split('.');
|
|
142
|
-
return !relative.includes('/') && parts.length >= 2 && parts.every(part => KEBAB.test(part)) && suffixes.includes(parts.at(-1) ?? '');
|
|
143
|
-
}
|
|
144
|
-
function collectWorldFiles(resolver, tree, suffixes, violations) {
|
|
145
|
-
const fakeProviders = new Map();
|
|
146
|
-
let worldRoot = null;
|
|
147
|
-
let files = 0;
|
|
148
|
-
for (const file of [...tree.files].sort(byCodeUnit)) {
|
|
149
|
-
if (!file.endsWith('.ts'))
|
|
150
|
-
continue;
|
|
151
|
-
const verdict = allowsFile(resolver, file);
|
|
152
|
-
if (verdict?.slot !== WORLD_SLOT)
|
|
153
|
-
continue;
|
|
154
|
-
files += 1;
|
|
155
|
-
worldRoot ??= file.slice(0, file.length - verdict.relative.length);
|
|
156
|
-
registerFakeProvider(fakeProviders, verdict.relative, file);
|
|
157
|
-
if (verdict.allowed || isRoleFileAtRoot(verdict.relative, suffixes))
|
|
158
|
-
continue;
|
|
159
|
-
violations.push({
|
|
160
|
-
ruleId: RULE, path: file, line: 1, column: 1,
|
|
161
|
-
message: `${file} is not allowed in the test world; src/tests/world/ holds only ${verdict.allows.join(', ')} and role-suffixed files (<name>.<role>.ts) at its root. Move it to fakes/ or kit/ (be.tests.world.kit), give it a role suffix, or delete it.`,
|
|
162
|
-
slot: verdict.slot,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return { fakeProviders, worldRoot, files };
|
|
166
|
-
}
|
|
167
|
-
function worldDeclaration(graph, ts, worldRoot, violations) {
|
|
168
|
-
const configPath = worldRoot === null ? null : `${worldRoot}${CONFIG_FILE}`;
|
|
169
|
-
const configFile = configPath === null ? null : graph.files.get(configPath) ?? null;
|
|
170
|
-
const literal = configFile ? configLiteral(ts, configFile.sourceFile) : null;
|
|
171
|
-
if (configFile && !literal) {
|
|
172
|
-
violations.push({
|
|
173
|
-
ruleId: RULE, path: configPath, line: 1, column: 1, slot: WORLD_SLOT,
|
|
174
|
-
message: `${configPath} declares no world the machine can read. Declare it in the named form \`${NAMED_FORM}\` or the typed form \`${TYPED_FORM}\` (a const of a ${DEFINE} call with an object literal, imported from @starci/test-world); a default export is refused by R89 and is not read.`,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return { configPath, configFile, literal };
|
|
178
|
-
}
|
|
179
|
-
function stackServices(config, environments) {
|
|
180
|
-
const services = [];
|
|
181
|
-
for (const environment of environments) {
|
|
182
|
-
let stack = null;
|
|
183
|
-
// The stack is the app root's .starcistacks: the side folder the machine judges reads its app's (locateDeclaration).
|
|
184
|
-
try {
|
|
185
|
-
stack = readStack({ root: locateDeclaration(config.root).appRoot, environment });
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
stack = null;
|
|
189
|
-
}
|
|
190
|
-
for (const service of stack?.services ?? [])
|
|
191
|
-
if (service.role !== 'service' && !services.some(known => known.name === service.name))
|
|
192
|
-
services.push({ ...service, environment });
|
|
193
|
-
}
|
|
194
|
-
return services;
|
|
195
|
-
}
|
|
196
|
-
function statefulWhy(service) {
|
|
197
|
-
if (STATEFUL_KINDS.has(service.kind))
|
|
198
|
-
return `a ${service.kind} holds data the app reads back`;
|
|
199
|
-
return service.persistent ? 'the stack gives it a persistent volume' : null;
|
|
200
|
-
}
|
|
201
|
-
function reportDeclaredFakeProblems(declared, services, fakeProviders, fakeEntries, configPath, stackHint, violations) {
|
|
202
|
-
for (const entry of declared) {
|
|
203
|
-
const service = services.find(candidate => candidate.name === entry.service);
|
|
204
|
-
const problems = [];
|
|
205
|
-
if (!service)
|
|
206
|
-
problems.push(`${stackHint} declares no service ${entry.service}`);
|
|
207
|
-
else if (statefulWhy(service))
|
|
208
|
-
problems.push(`${service.name} is stateful (${statefulWhy(service)}) and always runs real`);
|
|
209
|
-
if (!fakeProviders.has(entry.fake) && !fakeEntries.some(fake => fake.name === entry.fake))
|
|
210
|
-
problems.push(`there is no fakes entry and no fakes/${entry.fake || '<fake>'}/ folder of that name`);
|
|
211
|
-
if (entry.reason === '')
|
|
212
|
-
problems.push('the reason is empty');
|
|
213
|
-
if (problems.length > 0) {
|
|
214
|
-
violations.push({
|
|
215
|
-
ruleId: RULE, path: configPath, line: entry.line, column: entry.column, slot: WORLD_SLOT,
|
|
216
|
-
message: `${configPath} declares ${entry.service} as faked by ${entry.fake || '(no fake)'}, but ${problems.join('; ')}. The exception covers only stateless compute that needs special hardware or an external model, with a reason; everything else in the stack runs real.`,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function worldFakes(fakeProviders, fakeEntries, configPath) {
|
|
222
|
-
return [
|
|
223
|
-
...[...fakeProviders].map(([provider, file]) => ({ name: provider, path: file, line: 1, column: 1, what: `fakes/${provider}/` })),
|
|
224
|
-
...fakeEntries.filter(entry => !fakeProviders.has(entry.name)).map(entry => ({ name: entry.name, path: configPath, line: entry.line, column: entry.column, what: `the fakes entry ${entry.name}` })),
|
|
225
|
-
].sort((a, b) => a.name.localeCompare(b.name));
|
|
226
|
-
}
|
|
227
|
-
function reportServiceFakes(fakes, services, declared, configPath, stackHint, violations) {
|
|
228
|
-
for (const fake of fakes) {
|
|
229
|
-
const service = services.find(candidate => namesOfService(candidate).includes(fake.name));
|
|
230
|
-
if (!service)
|
|
231
|
-
continue;
|
|
232
|
-
if (declared.some(entry => entry.service === service.name && entry.fake === fake.name))
|
|
233
|
-
continue; // judged on its stacks entry above
|
|
234
|
-
const why = statefulWhy(service);
|
|
235
|
-
let reason = `${service.name} is stateful (${why}), so no exception applies. `;
|
|
236
|
-
if (!why) {
|
|
237
|
-
const worldConfig = configPath ?? `${CONFIG_FILE} in the world`;
|
|
238
|
-
reason = `Only stateless compute that needs special hardware or an external model may be faked, and only when ${worldConfig} declares it in its stacks entry ({ fakedBy, reason }). `;
|
|
239
|
-
}
|
|
240
|
-
violations.push({
|
|
241
|
-
ruleId: RULE, path: fake.path, line: fake.line, column: fake.column, slot: WORLD_SLOT,
|
|
242
|
-
message: `${fake.what} fakes ${service.name} (${service.image}), which ${stackHint} declares: a service of the repository's own stack runs real in the test world. ${reason}Delete the fake and let the world run the real service; fakes are otherwise only for external SaaS the team does not operate.`,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
export function checkTestWorldFiles(input) {
|
|
247
|
-
const { config, graph, ts, resolver, tree } = checkerScope(input);
|
|
248
|
-
const suffixes = graph.resolver.ruleParams()?.suffixes ?? [];
|
|
249
|
-
const violations = [];
|
|
250
|
-
const { fakeProviders, worldRoot, files } = collectWorldFiles(resolver, tree, suffixes, violations);
|
|
251
|
-
const { configPath, configFile, literal } = worldDeclaration(graph, ts, worldRoot, violations);
|
|
252
|
-
const environments = [(literal ? environmentOf(ts, literal) : null) ?? defaultEnvironment];
|
|
253
|
-
const services = stackServices(config, environments);
|
|
254
|
-
const stackHint = `${STACKS_DIRECTORY}/${environments.join(', ')}`;
|
|
255
|
-
const worldSource = configFile?.sourceFile;
|
|
256
|
-
const declared = literal && worldSource ? fakedByOf(ts, worldSource, literal) : [];
|
|
257
|
-
const fakeEntries = literal && worldSource ? fakeEntriesOf(ts, worldSource, literal) : [];
|
|
258
|
-
reportDeclaredFakeProblems(declared, services, fakeProviders, fakeEntries, configPath, stackHint, violations);
|
|
259
|
-
// Every fake the world runs: the repository's fakes/<provider>/ folders and the fakes entries of the declaration.
|
|
260
|
-
const fakes = worldFakes(fakeProviders, fakeEntries, configPath);
|
|
261
|
-
reportServiceFakes(fakes, services, declared, configPath, stackHint, violations);
|
|
262
|
-
return { violations, coverage: { status: 'checked', files } };
|
|
263
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
2
|
-
import { dirname, relative } from 'node:path';
|
|
3
|
-
import { isBoundsExport } from './contract-bounds.mjs';
|
|
4
|
-
import { registryListImport, registrySlot } from './entity-registry.mjs';
|
|
5
|
-
/**
|
|
6
|
-
* HFS checks 1 and 2 (knowledge/hfs/slots.yaml `tiers`):
|
|
7
|
-
* 1. the tier direction matrix: every import, re-export and type-only import between two owners must go from a tier to
|
|
8
|
-
* a tier its `mayImport` lists (BE_TIER_DIRECTION / FE_TIER_DIRECTION); a backend feature importing another feature
|
|
9
|
-
* is the one direction with its own code (BE_FEATURE_IMPORTS_FEATURE, R28), never BE_TIER_DIRECTION, and a feature of one trigger
|
|
10
|
-
* kind (slot field `trigger`: api, webhooks, realtime, saga, reactors, jobs, cli) importing a feature of another is
|
|
11
|
-
* BE_KIND_ISOLATION, whose fix is the event bus,
|
|
12
|
-
* an app never imports another app (BE_SERVICE_ISOLATION / FE_APP_ISOLATION), and a component layer imports only the layers after it;
|
|
13
|
-
* the entity registry naming a capability's `<c>Entities` from its public entry is the one platform-to-domain edge (entity-registry.mjs);
|
|
14
|
-
* 2. owner cycles: a strongly connected component of the owner graph, type-only imports included (ARCH_OWNER_CYCLE), the entity
|
|
15
|
-
* registry counted as a unit of its own,
|
|
16
|
-
* reported with the cycle path and the import that closes each hop.
|
|
17
|
-
* Importing inside one owner is always allowed; the public-entry rule stays with owners.mjs (ARCH_OWNER_EXPORT_BYPASS).
|
|
18
|
-
*/
|
|
19
|
-
export const TIER_RULE_IDS = ['BE_TIER_DIRECTION', 'BE_FEATURE_IMPORTS_FEATURE', 'BE_KIND_ISOLATION', 'BE_SERVICE_ISOLATION', 'FE_TIER_DIRECTION', 'FE_APP_ISOLATION', 'ARCH_OWNER_CYCLE'];
|
|
20
|
-
function tierDirectionText({ fromTier, toTier, mayImport, kindRestriction, fromKind, toKind }) {
|
|
21
|
-
if (!kindRestriction)
|
|
22
|
-
return `a ${fromTier} may import only ${mayImport.join(', ') || 'nothing'}; it imports a ${toTier}`;
|
|
23
|
-
const source = fromKind ?? 'no folder kind';
|
|
24
|
-
const target = toKind ?? 'no folder kind';
|
|
25
|
-
return `a ${fromTier} may import ${toTier} owners only from kinds ${kindRestriction.from.join(', ')} to kinds ${kindRestriction.to.join(', ')}; it imports ${source} -> ${target}`;
|
|
26
|
-
}
|
|
27
|
-
const REASON_TEXT = {
|
|
28
|
-
tierDirection: tierDirectionText,
|
|
29
|
-
layerOrder: ({ fromLayer, toLayer }) => `a ${fromLayer} component may import only the layers after it; it imports a ${toLayer}`,
|
|
30
|
-
crossApp: ({ from, to }) => `app ${from} imports app ${to}; apps never import each other, shared code is a packages/<pkg> slot`,
|
|
31
|
-
};
|
|
32
|
-
/** Strongly connected components (Tarjan, iterative) of `adjacency` (Map<node, Set<node>>); components of one node are dropped. */
|
|
33
|
-
function startTraversal(state, adjacency, node) {
|
|
34
|
-
const at = state.counter;
|
|
35
|
-
state.counter += 1;
|
|
36
|
-
state.index.set(node, at);
|
|
37
|
-
state.low.set(node, at);
|
|
38
|
-
state.stack.push(node);
|
|
39
|
-
state.onStack.add(node);
|
|
40
|
-
state.work.push({ node, iterator: adjacency.get(node)[Symbol.iterator]() });
|
|
41
|
-
}
|
|
42
|
-
function visitTarget(state, adjacency, frame, target) {
|
|
43
|
-
if (!adjacency.has(target))
|
|
44
|
-
return;
|
|
45
|
-
if (!state.index.has(target)) {
|
|
46
|
-
startTraversal(state, adjacency, target);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (state.onStack.has(target))
|
|
50
|
-
state.low.set(frame.node, Math.min(state.low.get(frame.node), state.index.get(target)));
|
|
51
|
-
}
|
|
52
|
-
function closeComponent(state, frame) {
|
|
53
|
-
const component = [];
|
|
54
|
-
let member;
|
|
55
|
-
do {
|
|
56
|
-
member = state.stack.pop();
|
|
57
|
-
state.onStack.delete(member);
|
|
58
|
-
component.push(member);
|
|
59
|
-
} while (member !== frame.node);
|
|
60
|
-
if (component.length > 1)
|
|
61
|
-
state.result.push(component);
|
|
62
|
-
}
|
|
63
|
-
function finishFrame(state, frame) {
|
|
64
|
-
state.work.pop();
|
|
65
|
-
if (state.work.length) {
|
|
66
|
-
const parent = state.work.at(-1).node;
|
|
67
|
-
state.low.set(parent, Math.min(state.low.get(parent), state.low.get(frame.node)));
|
|
68
|
-
}
|
|
69
|
-
if (state.low.get(frame.node) === state.index.get(frame.node))
|
|
70
|
-
closeComponent(state, frame);
|
|
71
|
-
}
|
|
72
|
-
function stronglyConnected(adjacency) {
|
|
73
|
-
const state = { counter: 0, index: new Map(), low: new Map(), onStack: new Set(), stack: [], result: [], work: [] };
|
|
74
|
-
for (const start of adjacency.keys()) {
|
|
75
|
-
if (state.index.has(start))
|
|
76
|
-
continue;
|
|
77
|
-
startTraversal(state, adjacency, start);
|
|
78
|
-
for (let frame = state.work.at(-1); frame; frame = state.work.at(-1)) {
|
|
79
|
-
const next = frame.iterator.next();
|
|
80
|
-
if (next.done) {
|
|
81
|
-
finishFrame(state, frame);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
visitTarget(state, adjacency, frame, next.value);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return state.result;
|
|
88
|
-
}
|
|
89
|
-
/** A shortest cycle through `origin` inside `members`, as a node path that starts and ends at origin. */
|
|
90
|
-
function cycleThrough(adjacency, members, origin) {
|
|
91
|
-
const queue = [[origin]];
|
|
92
|
-
const seen = new Set();
|
|
93
|
-
while (queue.length) {
|
|
94
|
-
const trail = queue.shift();
|
|
95
|
-
for (const next of adjacency.get(trail.at(-1)) ?? []) {
|
|
96
|
-
if (!members.has(next))
|
|
97
|
-
continue;
|
|
98
|
-
if (next === origin)
|
|
99
|
-
return [...trail, origin];
|
|
100
|
-
if (seen.has(next))
|
|
101
|
-
continue;
|
|
102
|
-
seen.add(next);
|
|
103
|
-
queue.push([...trail, next]);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return [origin, origin];
|
|
107
|
-
}
|
|
108
|
-
/** The trigger kind (slot field `trigger`) of the owner that holds `file`, or null when its owner's slot names none. */
|
|
109
|
-
const triggerOf = (resolver, file) => {
|
|
110
|
-
const owner = resolver.ownerOf(file);
|
|
111
|
-
return owner ? (resolver.slot(owner.slot)?.trigger ?? null) : null;
|
|
112
|
-
};
|
|
113
|
-
function reportReasonedTierViolation(graph, edge, answer, tierRule, counts, violations) {
|
|
114
|
-
// reason: importAllowed carries the details of REASON_TEXT's reasons (tierDirection, layerOrder, crossApp) as the TierVerdict fields; any other reason returns below
|
|
115
|
-
const verdict = answer;
|
|
116
|
-
const reason = verdict.reason ?? '';
|
|
117
|
-
const describe = REASON_TEXT[reason];
|
|
118
|
-
if (verdict.allowed || !describe)
|
|
119
|
-
return;
|
|
120
|
-
counts[reason] = (counts[reason] ?? 0) + 1;
|
|
121
|
-
const featureToFeature = graph.profile === 'be' && verdict.reason === 'tierDirection' && verdict.fromTier === 'feature' && verdict.toTier === 'feature';
|
|
122
|
-
const fromKind = featureToFeature ? triggerOf(graph.resolver, edge.from) : null;
|
|
123
|
-
const toKind = featureToFeature ? triggerOf(graph.resolver, edge.to) : null;
|
|
124
|
-
const crossKind = fromKind !== null && toKind !== null && fromKind !== toKind;
|
|
125
|
-
let ruleId = tierRule;
|
|
126
|
-
if (featureToFeature)
|
|
127
|
-
ruleId = 'BE_FEATURE_IMPORTS_FEATURE';
|
|
128
|
-
if (crossKind)
|
|
129
|
-
ruleId = 'BE_KIND_ISOLATION';
|
|
130
|
-
if (verdict.reason === 'crossApp')
|
|
131
|
-
ruleId = graph.profile === 'be' ? 'BE_SERVICE_ISOLATION' : 'FE_APP_ISOLATION';
|
|
132
|
-
const typeOnly = edge.runtime ? '' : ' (type-only imports count)';
|
|
133
|
-
const message = crossKind
|
|
134
|
-
? `${edge.from} -> ${edge.to}: a ${fromKind} feature imports a ${toKind} feature; no kind imports another, every cross-kind call is an event published with eventBus.publish(event, tx) from a domain service${typeOnly}.`
|
|
135
|
-
: `${edge.from} -> ${edge.to}: ${describe(verdict)}${typeOnly}.`;
|
|
136
|
-
violations.push({
|
|
137
|
-
ruleId,
|
|
138
|
-
path: edge.from, line: edge.line, column: edge.column,
|
|
139
|
-
specifier: edge.specifier, resolvedPath: edge.to, typeOnly: !edge.runtime,
|
|
140
|
-
fromTier: verdict.fromTier ?? null, toTier: verdict.toTier ?? null,
|
|
141
|
-
message,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
/** A public API entry may expose generated contract data without exposing operations to a hook. */
|
|
145
|
-
function contractMetadataEdge(graph, ts, edge, verdict) {
|
|
146
|
-
if (graph.profile !== 'fe' || verdict.reason !== 'tierDirection')
|
|
147
|
-
return false;
|
|
148
|
-
const from = graph.files.get(edge.from);
|
|
149
|
-
const to = graph.files.get(edge.to);
|
|
150
|
-
if (from?.tier !== 'hooks' || to?.tier !== 'transport' || to.slot !== 'fe.modules.api' || !to.owner || to.owner.slot !== 'fe.modules' || to.owner.bindings.capability !== 'api')
|
|
151
|
-
return false;
|
|
152
|
-
// The tier verdict precedes private-entry checks, so prove both app isolation and the owner entry here.
|
|
153
|
-
const fromApp = graph.resolver.classifyPath(edge.from).bindings?.app;
|
|
154
|
-
const toApp = graph.resolver.classifyPath(edge.to).bindings?.app;
|
|
155
|
-
if (!fromApp || fromApp !== toApp || edge.to !== `${to.owner.root}/index.ts`)
|
|
156
|
-
return false;
|
|
157
|
-
const declaration = edge.edge.declaration;
|
|
158
|
-
let names;
|
|
159
|
-
if (ts.isImportDeclaration(declaration)) {
|
|
160
|
-
const clause = declaration.importClause;
|
|
161
|
-
if (!clause || clause.name || !clause.namedBindings || !ts.isNamedImports(clause.namedBindings))
|
|
162
|
-
return false;
|
|
163
|
-
names = clause.namedBindings.elements.map(item => (item.propertyName ?? item.name).text);
|
|
164
|
-
}
|
|
165
|
-
else if (ts.isExportDeclaration(declaration)) {
|
|
166
|
-
if (!declaration.exportClause || !ts.isNamedExports(declaration.exportClause))
|
|
167
|
-
return false;
|
|
168
|
-
names = declaration.exportClause.elements.map(item => (item.propertyName ?? item.name).text);
|
|
169
|
-
}
|
|
170
|
-
else
|
|
171
|
-
return false;
|
|
172
|
-
const apiOwner = to.owner;
|
|
173
|
-
const dirnameOfEntry = dirname(to.abs);
|
|
174
|
-
const ownsGenerated = (file) => {
|
|
175
|
-
const rel = `${apiOwner.root}/${relative(dirnameOfEntry, file).replaceAll('\\', '/')}`;
|
|
176
|
-
const classified = graph.resolver.classifyPath(rel);
|
|
177
|
-
const owner = graph.resolver.ownerOf(rel);
|
|
178
|
-
return classified.status === 'owned' && classified.slot === 'fe.transport.generated' &&
|
|
179
|
-
owner?.slot === apiOwner.slot && owner.root === apiOwner.root;
|
|
180
|
-
};
|
|
181
|
-
return names.length > 0 && names.every(name => isBoundsExport(ts, to.abs, name, ownsGenerated));
|
|
182
|
-
}
|
|
183
|
-
function inspectTierEdge(graph, ts, edge, tierRule, counts, violations, coverage) {
|
|
184
|
-
const verdict = graph.resolver.importAllowed(edge.from, edge.to);
|
|
185
|
-
if (verdict.reason === 'unowned' || verdict.reason?.startsWith('slot')) {
|
|
186
|
-
coverage.unclassifiedEdges += 1;
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
coverage.edgesChecked += 1;
|
|
190
|
-
if (verdict.reason === 'tierDirection' && (registryListImport(graph.resolver, edge) || contractMetadataEdge(graph, ts, edge, verdict)))
|
|
191
|
-
return;
|
|
192
|
-
reportReasonedTierViolation(graph, edge, verdict, tierRule, counts, violations);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* The cycle unit of a file: its owner unit, except the entity registry (entity-registry.mjs), which is a unit of its own. It sits in
|
|
196
|
-
* platform/database but is composition-level by role (it imports every capability's `<c>Entities`), so it never closes a cycle
|
|
197
|
-
* among capabilities through the owner it lives in.
|
|
198
|
-
*/
|
|
199
|
-
const cycleUnit = (graph, resolver, rel) => (registrySlot(resolver, rel) ? `entity-registry:${rel}` : graph.unit(rel));
|
|
200
|
-
function ownerAdjacency(graph, resolver) {
|
|
201
|
-
const adjacency = new Map();
|
|
202
|
-
const witness = new Map();
|
|
203
|
-
for (const edge of graph.edges) {
|
|
204
|
-
const a = cycleUnit(graph, resolver, edge.from);
|
|
205
|
-
const b = cycleUnit(graph, resolver, edge.to);
|
|
206
|
-
if (!a || !b || a === b)
|
|
207
|
-
continue;
|
|
208
|
-
if (resolver.tierOf(edge.from) === 'none' || resolver.tierOf(edge.to) === 'none')
|
|
209
|
-
continue;
|
|
210
|
-
if (!adjacency.has(a))
|
|
211
|
-
adjacency.set(a, new Set());
|
|
212
|
-
if (!adjacency.has(b))
|
|
213
|
-
adjacency.set(b, new Set());
|
|
214
|
-
adjacency.get(a).add(b);
|
|
215
|
-
if (!witness.has(`${a}\0${b}`))
|
|
216
|
-
witness.set(`${a}\0${b}`, edge);
|
|
217
|
-
}
|
|
218
|
-
return { adjacency, witness };
|
|
219
|
-
}
|
|
220
|
-
function addOwnerCycleViolations(adjacency, witness, violations) {
|
|
221
|
-
const components = stronglyConnected(adjacency);
|
|
222
|
-
for (const component of components) {
|
|
223
|
-
const members = new Set(component);
|
|
224
|
-
const origin = [...component].sort(byCodeUnit)[0];
|
|
225
|
-
const cycle = cycleThrough(adjacency, members, origin);
|
|
226
|
-
const hops = cycle.slice(0, -1).map((unit, i) => witness.get(`${unit}\0${cycle[i + 1]}`));
|
|
227
|
-
const label = (unit) => unit.slice(unit.indexOf(':') + 1) || unit;
|
|
228
|
-
const first = hops[0];
|
|
229
|
-
const connectedOwners = component.length > cycle.length - 1 ? ` (strongly connected with ${component.length} owners)` : '';
|
|
230
|
-
violations.push({
|
|
231
|
-
ruleId: 'ARCH_OWNER_CYCLE',
|
|
232
|
-
path: first.from, line: first.line, column: first.column,
|
|
233
|
-
cycle: cycle.map(label),
|
|
234
|
-
cycleImports: hops.map((hop) => ({ path: hop.from, line: hop.line, specifier: hop.specifier, typeOnly: !hop.runtime })),
|
|
235
|
-
componentSize: component.length,
|
|
236
|
-
message: `Owner cycle: ${cycle.map(label).join(' -> ')}${connectedOwners}; type-only imports count.`,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return components.length;
|
|
240
|
-
}
|
|
241
|
-
export function checkTiers(graph, ts) {
|
|
242
|
-
const { resolver, profile } = graph;
|
|
243
|
-
const violations = [];
|
|
244
|
-
const tierRule = profile === 'be' ? 'BE_TIER_DIRECTION' : 'FE_TIER_DIRECTION';
|
|
245
|
-
const coverage = { edgesChecked: 0, unclassifiedEdges: 0 };
|
|
246
|
-
const counts = { tierDirection: 0, layerOrder: 0, crossApp: 0 };
|
|
247
|
-
for (const edge of graph.edges)
|
|
248
|
-
inspectTierEdge(graph, ts, edge, tierRule, counts, violations, coverage);
|
|
249
|
-
// Owner cycles: nodes are owner units, edges the imports between two distinct units.
|
|
250
|
-
const { adjacency, witness } = ownerAdjacency(graph, resolver);
|
|
251
|
-
const cycles = addOwnerCycleViolations(adjacency, witness, violations);
|
|
252
|
-
return {
|
|
253
|
-
violations,
|
|
254
|
-
coverage: { status: 'checked', ...coverage, ownerUnits: adjacency.size, cycles, ...counts },
|
|
255
|
-
};
|
|
256
|
-
}
|