@starci/eslint-canon-be 3.8.20 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -4,7 +4,6 @@ import { checkerScope } from './required-files.mjs';
4
4
  import { allowsFile } from '../allows.mjs';
5
5
  import { unwrapEach } from './ast-walks.mjs';
6
6
  import { byCodeUnit } from '../../lib/list.mjs';
7
-
8
7
  /**
9
8
  * R47 `contract-fixture-guard` (BE_CONTRACT_UNGUARDED). A fake at the network edge serves payload fixtures; a fixture drifts
10
9
  * from the real provider silently unless a sandbox contract spec compares them. So every `fakes/<provider>/` of the test
@@ -22,147 +21,157 @@ import { byCodeUnit } from '../../lib/list.mjs';
22
21
  * `fakes/<provider>/` folders are judged.
23
22
  */
24
23
  export const CONTRACT_FIXTURE_GUARD_RULE_IDS = ['BE_CONTRACT_UNGUARDED'];
25
-
26
24
  const RULE = 'BE_CONTRACT_UNGUARDED';
27
25
  const WORLD_SLOT = 'be.tests.world';
28
26
  const CONTRACT_SLOT = 'be.tests.contract';
29
27
  const FAKES_DIRECTORY = 'fakes/';
30
28
  const PAYLOADS = /^([^/]+)\/payloads\/[^/]+\.json$/u;
31
29
  const SHAPE_MATCHERS = new Set(['toEqual', 'toStrictEqual']);
32
-
33
30
  const unwrap = (ts, node) => unwrapEach(ts, node, [ts.isParenthesizedExpression, ts.isAsExpression, ts.isNonNullExpression, ts.isAwaitExpression]);
34
-
35
31
  /** Every node under `root`, itself included. */
36
32
  function walk(ts, root, visit) {
37
- const step = node => { visit(node); ts.forEachChild(node, step); };
38
- step(root);
33
+ const step = (node) => { visit(node); ts.forEachChild(node, step); };
34
+ step(root);
39
35
  }
40
-
41
36
  const importsFakesOf = (from, provider) => from.includes(`${FAKES_DIRECTORY}${provider}/`) || from.endsWith(`${FAKES_DIRECTORY}${provider}`);
42
-
43
37
  const shapeNamesOf = (ts, statement, helper) => {
44
- const named = statement.importClause?.namedBindings;
45
- if (!named || !ts.isNamedImports(named)) return [];
46
- return named.elements.filter(element => (element.propertyName ?? element.name).text === helper).map(element => element.name.text);
38
+ const named = statement.importClause?.namedBindings;
39
+ if (!named || !ts.isNamedImports(named))
40
+ return [];
41
+ return named.elements.filter(element => (element.propertyName ?? element.name).text === helper).map(element => element.name.text);
47
42
  };
48
-
49
43
  const importsOfSpec = (ts, sourceFile, helper, providers) => {
50
- const shapeNames = new Set();
51
- const referenced = new Set();
52
- for (const statement of sourceFile.statements) {
53
- if (!ts.isImportDeclaration(statement)) continue;
54
- const from = statement.moduleSpecifier.text;
55
- for (const provider of providers) if (importsFakesOf(from, provider)) referenced.add(provider);
56
- for (const name of shapeNamesOf(ts, statement, helper)) shapeNames.add(name);
57
- }
58
- return { shapeNames, referenced };
44
+ const shapeNames = new Set();
45
+ const referenced = new Set();
46
+ for (const statement of sourceFile.statements) {
47
+ if (!ts.isImportDeclaration(statement))
48
+ continue;
49
+ // The module specifier of an import declaration is a string literal by the grammar.
50
+ const from = statement.moduleSpecifier.text;
51
+ for (const provider of providers)
52
+ if (importsFakesOf(from, provider))
53
+ referenced.add(provider);
54
+ for (const name of shapeNamesOf(ts, statement, helper))
55
+ shapeNames.add(name);
56
+ }
57
+ return { shapeNames, referenced };
59
58
  };
60
-
61
59
  const callsShape = (ts, node, shapeNames) => {
62
- let found = false;
63
- walk(ts, node, inner => { if (ts.isCallExpression(inner) && ts.isIdentifier(inner.expression) && shapeNames.has(inner.expression.text)) found = true; });
64
- return found;
60
+ let found = false;
61
+ walk(ts, node, inner => { if (ts.isCallExpression(inner) && ts.isIdentifier(inner.expression) && shapeNames.has(inner.expression.text))
62
+ found = true; });
63
+ return found;
65
64
  };
66
-
67
65
  const TEST_BLOCKS = new Set(['describe', 'it', 'test']);
68
-
69
66
  const referenceProviders = (ts, node, providers, referenced) => {
70
- if (ts.isStringLiteralLike(node)) for (const provider of providers) if (node.text.includes(`${FAKES_DIRECTORY}${provider}/`)) referenced.add(provider);
71
- if (!ts.isCallExpression(node)) return;
72
- const named = ts.isIdentifier(node.expression) ? node.expression.text : null;
73
- for (const argument of node.arguments) {
74
- const value = unwrap(ts, argument);
75
- if (value && ts.isStringLiteralLike(value) && providers.has(value.text) && !TEST_BLOCKS.has(named)) referenced.add(value.text);
76
- }
67
+ if (ts.isStringLiteralLike(node))
68
+ for (const provider of providers)
69
+ if (node.text.includes(`${FAKES_DIRECTORY}${provider}/`))
70
+ referenced.add(provider);
71
+ if (!ts.isCallExpression(node))
72
+ return;
73
+ const named = ts.isIdentifier(node.expression) ? node.expression.text : null;
74
+ for (const argument of node.arguments) {
75
+ const value = unwrap(ts, argument);
76
+ if (value && ts.isStringLiteralLike(value) && providers.has(value.text) && !TEST_BLOCKS.has(named))
77
+ referenced.add(value.text);
78
+ }
77
79
  };
78
-
79
80
  /** The `expect(...)` call a shape matcher call hangs off (through `.not` / `.resolves`), or null. */
80
81
  const expectReceiverOf = (ts, callee) => {
81
- let receiver = unwrap(ts, callee.expression);
82
- while (receiver && ts.isPropertyAccessExpression(receiver)) receiver = unwrap(ts, receiver.expression);
83
- return receiver && ts.isCallExpression(receiver) && ts.isIdentifier(receiver.expression) && receiver.expression.text === 'expect' ? receiver : null;
82
+ let receiver = unwrap(ts, callee.expression);
83
+ while (receiver && ts.isPropertyAccessExpression(receiver))
84
+ receiver = unwrap(ts, receiver.expression);
85
+ return receiver && ts.isCallExpression(receiver) && ts.isIdentifier(receiver.expression) && receiver.expression.text === 'expect' ? receiver : null;
84
86
  };
85
-
86
87
  const comparesShapes = (ts, node, shapeNames) => {
87
- if (!ts.isCallExpression(node)) return false;
88
- const callee = node.expression;
89
- if (!ts.isPropertyAccessExpression(callee) || !SHAPE_MATCHERS.has(callee.name.text)) return false;
90
- const receiver = expectReceiverOf(ts, callee);
91
- if (!receiver) return false;
92
- const [actual] = receiver.arguments;
93
- const [expected] = node.arguments;
94
- return Boolean(actual && expected && callsShape(ts, actual, shapeNames) && callsShape(ts, expected, shapeNames));
88
+ if (!ts.isCallExpression(node))
89
+ return false;
90
+ const callee = node.expression;
91
+ if (!ts.isPropertyAccessExpression(callee) || !SHAPE_MATCHERS.has(callee.name.text))
92
+ return false;
93
+ const receiver = expectReceiverOf(ts, callee);
94
+ if (!receiver)
95
+ return false;
96
+ const [actual] = receiver.arguments;
97
+ const [expected] = node.arguments;
98
+ return Boolean(actual && expected && callsShape(ts, actual, shapeNames) && callsShape(ts, expected, shapeNames));
95
99
  };
96
-
97
100
  const referenceAndCompare = (ts, node, providers, referenced, shapeNames) => {
98
- referenceProviders(ts, node, providers, referenced);
99
- return comparesShapes(ts, node, shapeNames);
101
+ referenceProviders(ts, node, providers, referenced);
102
+ return comparesShapes(ts, node, shapeNames);
100
103
  };
101
-
102
104
  /** Facts one contract spec establishes: the providers whose fixtures it references and whether it compares shapes. */
103
105
  function readSpec(ts, sourceFile, helper, providers) {
104
- const { shapeNames, referenced } = importsOfSpec(ts, sourceFile, helper, providers);
105
- let compares = false;
106
- walk(ts, sourceFile, node => { if (referenceAndCompare(ts, node, providers, referenced, shapeNames)) compares = true; });
107
- return { referenced, compares };
106
+ const { shapeNames, referenced } = importsOfSpec(ts, sourceFile, helper, providers);
107
+ let compares = false;
108
+ walk(ts, sourceFile, node => { if (referenceAndCompare(ts, node, providers, referenced, shapeNames))
109
+ compares = true; });
110
+ return { referenced, compares };
108
111
  }
109
-
110
112
  /** The payload fixture a file of the world slot is, as `[provider, file]`, or null. */
111
113
  const payloadFixtureOf = (resolver, file) => {
112
- const verdict = allowsFile(resolver, file);
113
- if (verdict?.slot !== WORLD_SLOT || !verdict.relative.startsWith(FAKES_DIRECTORY)) return null;
114
- const match = PAYLOADS.exec(verdict.relative.slice(FAKES_DIRECTORY.length));
115
- return match ? [match[1], file] : null;
114
+ const verdict = allowsFile(resolver, file);
115
+ if (verdict?.slot !== WORLD_SLOT || !verdict.relative.startsWith(FAKES_DIRECTORY))
116
+ return null;
117
+ const match = PAYLOADS.exec(verdict.relative.slice(FAKES_DIRECTORY.length));
118
+ const provider = match?.[1];
119
+ return provider === undefined ? null : [provider, file];
116
120
  };
117
-
118
121
  const fixtureFilesOf = (tree, resolver) => {
119
- const fixtures = new Map(); // provider -> first payload fixture file
120
- const specs = new Map(); // provider -> [contract spec file]
121
- for (const file of [...tree.files].sort(byCodeUnit)) {
122
- const classified = resolver.classifyPath(file);
123
- if (classified.status !== 'owned') continue;
124
- if (classified.slot === CONTRACT_SLOT) {
125
- const provider = classified.bindings?.provider;
126
- if (provider && file.endsWith('.contract-spec.ts')) specs.set(provider, [...(specs.get(provider) ?? []), file]);
127
- continue;
122
+ const fixtures = new Map(); // provider -> first payload fixture file
123
+ const specs = new Map(); // provider -> [contract spec file]
124
+ for (const file of [...tree.files].sort(byCodeUnit)) {
125
+ const classified = resolver.classifyPath(file);
126
+ if (classified.status !== 'owned')
127
+ continue;
128
+ if (classified.slot === CONTRACT_SLOT) {
129
+ const provider = classified.bindings?.provider;
130
+ if (provider && file.endsWith('.contract-spec.ts'))
131
+ specs.set(provider, [...(specs.get(provider) ?? []), file]);
132
+ continue;
133
+ }
134
+ const fixture = classified.slot === WORLD_SLOT ? payloadFixtureOf(resolver, file) : null;
135
+ if (fixture && !fixtures.has(fixture[0]))
136
+ fixtures.set(...fixture);
128
137
  }
129
- const fixture = classified.slot === WORLD_SLOT ? payloadFixtureOf(resolver, file) : null;
130
- if (fixture && !fixtures.has(fixture[0])) fixtures.set(...fixture);
131
- }
132
- return { fixtures, specs };
138
+ return { fixtures, specs };
133
139
  };
134
-
135
140
  const guardedProvidersOf = (config, ts, contractShape, providers, specs) => {
136
- const guarded = new Set();
137
- for (const [provider, files] of specs) {
138
- for (const file of files) {
139
- const absolute = path.join(config.root, ...file.split('/'));
140
- if (!fs.existsSync(absolute)) continue;
141
- const sourceFile = ts.createSourceFile(absolute, fs.readFileSync(absolute, 'utf8'), ts.ScriptTarget.Latest, true); // the contract tree is outside the root program
142
- const facts = readSpec(ts, sourceFile, contractShape.helper, providers);
143
- if (facts.compares && facts.referenced.has(provider)) guarded.add(provider);
141
+ const guarded = new Set();
142
+ for (const [provider, files] of specs) {
143
+ for (const file of files) {
144
+ const absolute = path.join(config.root, ...file.split('/'));
145
+ if (!fs.existsSync(absolute))
146
+ continue;
147
+ const sourceFile = ts.createSourceFile(absolute, fs.readFileSync(absolute, 'utf8'), ts.ScriptTarget.Latest, true); // the contract tree is outside the root program
148
+ const facts = readSpec(ts, sourceFile, contractShape.helper, providers);
149
+ if (facts.compares && facts.referenced.has(provider))
150
+ guarded.add(provider);
151
+ }
144
152
  }
145
- }
146
- return guarded;
153
+ return guarded;
147
154
  };
148
-
149
155
  export function checkContractFixtureGuard(input) {
150
- const { config, ts, resolver, tree } = checkerScope(input);
151
- const { contractShape } = resolver.ruleParams();
152
- const violations = [];
153
- const { fixtures, specs } = fixtureFilesOf(tree, resolver);
154
- const providers = new Set(fixtures.keys());
155
- const guarded = guardedProvidersOf(config, ts, contractShape, providers, specs);
156
- for (const [provider, file] of [...fixtures].sort(([a], [b]) => a.localeCompare(b))) {
157
- if (guarded.has(provider)) continue;
158
- const has = specs.get(provider)?.length ?? 0;
159
- const why = has === 0
160
- ? `there is no src/tests/contract/${provider}/*.contract-spec.ts`
161
- : `none of the ${has} contract spec(s) under src/tests/contract/${provider}/ both references the ${provider} fixtures and asserts expect(${contractShape.helper}(real)).toEqual(${contractShape.helper}(fixture))`;
162
- violations.push({
163
- ruleId: RULE, path: file, line: 1, column: 1, slot: WORLD_SLOT,
164
- message: `fakes/${provider}/ serves payload fixtures but no contract spec guards them: ${why}. A fixture that is not compared with the real provider drifts silently; add the sandbox contract spec (the contract helper of the world skips it when the sandbox config is absent).`,
165
- });
166
- }
167
- return { violations, coverage: { status: 'checked', fixtureFakes: fixtures.size, contractSpecs: [...specs.values()].flat().length } };
156
+ const { config, ts, tree } = checkerScope(input);
157
+ const { resolver } = input.graph;
158
+ // reason: the machine runs this check on a back-end tree, whose scope resolver always carries rule parameters
159
+ const { contractShape } = resolver.ruleParams();
160
+ const violations = [];
161
+ const { fixtures, specs } = fixtureFilesOf(tree, resolver);
162
+ const providers = new Set(fixtures.keys());
163
+ const guarded = guardedProvidersOf(config, ts, contractShape, providers, specs);
164
+ for (const [provider, file] of [...fixtures].sort(([a], [b]) => a.localeCompare(b))) {
165
+ if (guarded.has(provider))
166
+ continue;
167
+ const has = specs.get(provider)?.length ?? 0;
168
+ const why = has === 0
169
+ ? `there is no src/tests/contract/${provider}/*.contract-spec.ts`
170
+ : `none of the ${has} contract spec(s) under src/tests/contract/${provider}/ both references the ${provider} fixtures and asserts expect(${contractShape.helper}(real)).toEqual(${contractShape.helper}(fixture))`;
171
+ violations.push({
172
+ ruleId: RULE, path: file, line: 1, column: 1, slot: WORLD_SLOT,
173
+ message: `fakes/${provider}/ serves payload fixtures but no contract spec guards them: ${why}. A fixture that is not compared with the real provider drifts silently; add the sandbox contract spec (the contract helper of the world skips it when the sandbox config is absent).`,
174
+ });
175
+ }
176
+ return { violations, coverage: { status: 'checked', fixtureFakes: fixtures.size, contractSpecs: [...specs.values()].flat().length } };
168
177
  }