@ontrails/warden 1.0.0-beta.2 → 1.0.0-beta.21

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 (249) hide show
  1. package/CHANGELOG.md +497 -6
  2. package/README.md +77 -26
  3. package/bin/warden.ts +50 -0
  4. package/package.json +27 -5
  5. package/src/adapter-check.ts +136 -0
  6. package/src/ast.ts +28 -0
  7. package/src/cli.ts +1374 -103
  8. package/src/command.ts +953 -0
  9. package/src/config.ts +184 -0
  10. package/src/draft.ts +22 -0
  11. package/src/drift.ts +106 -22
  12. package/src/fix.ts +120 -0
  13. package/src/formatters.ts +79 -9
  14. package/src/guide.ts +245 -0
  15. package/src/index.ts +206 -14
  16. package/src/project-context.ts +163 -0
  17. package/src/resolve.ts +530 -0
  18. package/src/rules/activation-orphan.ts +97 -0
  19. package/src/rules/ast.ts +3176 -85
  20. package/src/rules/circular-refs.ts +154 -0
  21. package/src/rules/composes-declarations.ts +704 -0
  22. package/src/rules/context-no-surface-types.ts +68 -8
  23. package/src/rules/contour-exists.ts +251 -0
  24. package/src/rules/contour-ids.ts +15 -0
  25. package/src/rules/dead-internal-trail.ts +154 -0
  26. package/src/rules/draft-file-marking.ts +160 -0
  27. package/src/rules/draft-visible-debt.ts +87 -0
  28. package/src/rules/error-mapping-completeness.ts +288 -0
  29. package/src/rules/example-valid.ts +401 -0
  30. package/src/rules/fires-declarations.ts +758 -0
  31. package/src/rules/implementation-returns-result.ts +1265 -95
  32. package/src/rules/incomplete-accessor-for-standard-op.ts +272 -0
  33. package/src/rules/incomplete-crud.ts +580 -0
  34. package/src/rules/index.ts +219 -18
  35. package/src/rules/intent-propagation.ts +127 -0
  36. package/src/rules/layer-field-name-drift.ts +96 -0
  37. package/src/rules/metadata.ts +654 -0
  38. package/src/rules/missing-reconcile.ts +98 -0
  39. package/src/rules/missing-visibility.ts +110 -0
  40. package/src/rules/no-destructured-compose.ts +192 -0
  41. package/src/rules/no-dev-permit-in-source.ts +99 -0
  42. package/src/rules/no-direct-implementation-call.ts +7 -7
  43. package/src/rules/no-legacy-layer-imports.ts +211 -0
  44. package/src/rules/no-native-error-result.ts +111 -0
  45. package/src/rules/no-redundant-result-error-wrap.ts +331 -0
  46. package/src/rules/no-retired-cross-vocabulary.ts +194 -0
  47. package/src/rules/no-sync-result-assumption.ts +1134 -99
  48. package/src/rules/no-throw-in-detour-recover.ts +225 -0
  49. package/src/rules/no-throw-in-implementation.ts +10 -9
  50. package/src/rules/no-top-level-surface.ts +389 -0
  51. package/src/rules/on-references-exist.ts +194 -0
  52. package/src/rules/orphaned-signal.ts +150 -0
  53. package/src/rules/owner-projection-parity.ts +146 -0
  54. package/src/rules/permit-governance.ts +25 -0
  55. package/src/rules/public-export-example-coverage.ts +553 -0
  56. package/src/rules/public-internal-deep-imports.ts +517 -0
  57. package/src/rules/public-output-schema.ts +29 -0
  58. package/src/rules/public-union-output-discriminants.ts +150 -0
  59. package/src/rules/read-intent-fires.ts +187 -0
  60. package/src/rules/reference-exists.ts +98 -0
  61. package/src/rules/registry-names.ts +145 -0
  62. package/src/rules/resolved-import-boundary.ts +146 -0
  63. package/src/rules/resource-declarations.ts +704 -0
  64. package/src/rules/resource-exists.ts +179 -0
  65. package/src/rules/resource-id-grammar.ts +65 -0
  66. package/src/rules/resource-mock-coverage.ts +115 -0
  67. package/src/rules/scan.ts +38 -25
  68. package/src/rules/scheduled-destroy-intent.ts +44 -0
  69. package/src/rules/signal-graph-coaching.ts +191 -0
  70. package/src/rules/specs.ts +9 -5
  71. package/src/rules/static-resource-accessor-preference.ts +657 -0
  72. package/src/rules/surface-facet-coherence.ts +370 -0
  73. package/src/rules/trail-versioning-source.ts +1094 -0
  74. package/src/rules/trail-versioning-topo.ts +172 -0
  75. package/src/rules/types.ts +270 -6
  76. package/src/rules/unmaterialized-activation-source.ts +84 -0
  77. package/src/rules/unreachable-detour-shadowing.ts +344 -0
  78. package/src/rules/valid-describe-refs.ts +160 -32
  79. package/src/rules/valid-detour-contract.ts +78 -0
  80. package/src/rules/warden-export-symmetry.ts +533 -0
  81. package/src/rules/warden-rules-use-ast.ts +996 -0
  82. package/src/rules/webhook-route-collision.ts +243 -0
  83. package/src/trails/activation-orphan.trail.ts +84 -0
  84. package/src/trails/circular-refs.trail.ts +29 -0
  85. package/src/trails/composes-declarations.trail.ts +22 -0
  86. package/src/trails/context-no-surface-types.trail.ts +21 -0
  87. package/src/trails/contour-exists.trail.ts +21 -0
  88. package/src/trails/dead-internal-trail.trail.ts +26 -0
  89. package/src/trails/deprecation-without-guidance.trail.ts +21 -0
  90. package/src/trails/draft-file-marking.trail.ts +16 -0
  91. package/src/trails/draft-visible-debt.trail.ts +16 -0
  92. package/src/trails/error-mapping-completeness.trail.ts +29 -0
  93. package/src/trails/example-valid.trail.ts +25 -0
  94. package/src/trails/fires-declarations.trail.ts +23 -0
  95. package/src/trails/fork-without-preserved-blaze.trail.ts +31 -0
  96. package/src/trails/implementation-returns-result.trail.ts +20 -0
  97. package/src/trails/incomplete-accessor-for-standard-op.trail.ts +76 -0
  98. package/src/trails/incomplete-crud.trail.ts +39 -0
  99. package/src/trails/index.ts +78 -0
  100. package/src/trails/intent-propagation.trail.ts +30 -0
  101. package/src/trails/layer-field-name-drift.trail.ts +39 -0
  102. package/src/trails/marker-schema-unsupported.trail.ts +23 -0
  103. package/src/trails/missing-reconcile.trail.ts +33 -0
  104. package/src/trails/missing-visibility.trail.ts +22 -0
  105. package/src/trails/no-destructured-compose.trail.ts +44 -0
  106. package/src/trails/no-dev-permit-in-source.trail.ts +16 -0
  107. package/src/trails/no-direct-implementation-call.trail.ts +16 -0
  108. package/src/trails/no-legacy-layer-imports.trail.ts +41 -0
  109. package/src/trails/no-native-error-result.trail.ts +18 -0
  110. package/src/trails/no-redundant-result-error-wrap.trail.ts +55 -0
  111. package/src/trails/no-retired-cross-vocabulary.trail.ts +42 -0
  112. package/src/trails/no-sync-result-assumption.trail.ts +19 -0
  113. package/src/trails/no-throw-in-detour-recover.trail.ts +24 -0
  114. package/src/trails/no-throw-in-implementation.trail.ts +20 -0
  115. package/src/trails/no-top-level-surface.trail.ts +43 -0
  116. package/src/trails/on-references-exist.trail.ts +21 -0
  117. package/src/trails/orphaned-signal.trail.ts +36 -0
  118. package/src/trails/owner-projection-parity.trail.ts +26 -0
  119. package/src/trails/pending-force.trail.ts +21 -0
  120. package/src/trails/permit-governance.trail.ts +51 -0
  121. package/src/trails/prefer-schema-inference.trail.ts +21 -0
  122. package/src/trails/public-export-example-coverage.trail.ts +16 -0
  123. package/src/trails/public-internal-deep-imports.trail.ts +94 -0
  124. package/src/trails/public-output-schema.trail.ts +55 -0
  125. package/src/trails/public-union-output-discriminants.trail.ts +33 -0
  126. package/src/trails/read-intent-fires.trail.ts +20 -0
  127. package/src/trails/reference-exists.trail.ts +25 -0
  128. package/src/trails/resolved-import-boundary.trail.ts +109 -0
  129. package/src/trails/resource-declarations.trail.ts +25 -0
  130. package/src/trails/resource-exists.trail.ts +27 -0
  131. package/src/trails/resource-id-grammar.trail.ts +39 -0
  132. package/src/trails/resource-mock-coverage.trail.ts +40 -0
  133. package/src/trails/run.ts +162 -0
  134. package/src/trails/scheduled-destroy-intent.trail.ts +56 -0
  135. package/src/trails/schema.ts +194 -0
  136. package/src/trails/signal-graph-coaching.trail.ts +77 -0
  137. package/src/trails/static-resource-accessor-preference.trail.ts +25 -0
  138. package/src/trails/surface-facet-coherence.trail.ts +25 -0
  139. package/src/trails/topo.ts +6 -0
  140. package/src/trails/unmaterialized-activation-source.trail.ts +72 -0
  141. package/src/trails/unreachable-detour-shadowing.trail.ts +45 -0
  142. package/src/trails/valid-describe-refs.trail.ts +18 -0
  143. package/src/trails/valid-detour-contract.trail.ts +71 -0
  144. package/src/trails/version-gap.trail.ts +35 -0
  145. package/src/trails/version-pinned-compose.trail.ts +23 -0
  146. package/src/trails/version-without-examples.trail.ts +38 -0
  147. package/src/trails/warden-export-symmetry.trail.ts +16 -0
  148. package/src/trails/warden-rules-use-ast.trail.ts +45 -0
  149. package/src/trails/webhook-route-collision.trail.ts +50 -0
  150. package/src/trails/wrap-rule.ts +213 -0
  151. package/src/workspaces.ts +238 -0
  152. package/.turbo/turbo-build.log +0 -1
  153. package/.turbo/turbo-lint.log +0 -3
  154. package/.turbo/turbo-typecheck.log +0 -1
  155. package/dist/cli.d.ts +0 -46
  156. package/dist/cli.d.ts.map +0 -1
  157. package/dist/cli.js +0 -221
  158. package/dist/cli.js.map +0 -1
  159. package/dist/drift.d.ts +0 -26
  160. package/dist/drift.d.ts.map +0 -1
  161. package/dist/drift.js +0 -27
  162. package/dist/drift.js.map +0 -1
  163. package/dist/formatters.d.ts +0 -29
  164. package/dist/formatters.d.ts.map +0 -1
  165. package/dist/formatters.js +0 -87
  166. package/dist/formatters.js.map +0 -1
  167. package/dist/index.d.ts +0 -26
  168. package/dist/index.d.ts.map +0 -1
  169. package/dist/index.js +0 -26
  170. package/dist/index.js.map +0 -1
  171. package/dist/rules/ast.d.ts +0 -41
  172. package/dist/rules/ast.d.ts.map +0 -1
  173. package/dist/rules/ast.js +0 -163
  174. package/dist/rules/ast.js.map +0 -1
  175. package/dist/rules/context-no-surface-types.d.ts +0 -12
  176. package/dist/rules/context-no-surface-types.d.ts.map +0 -1
  177. package/dist/rules/context-no-surface-types.js +0 -96
  178. package/dist/rules/context-no-surface-types.js.map +0 -1
  179. package/dist/rules/implementation-returns-result.d.ts +0 -13
  180. package/dist/rules/implementation-returns-result.d.ts.map +0 -1
  181. package/dist/rules/implementation-returns-result.js +0 -231
  182. package/dist/rules/implementation-returns-result.js.map +0 -1
  183. package/dist/rules/index.d.ts +0 -22
  184. package/dist/rules/index.d.ts.map +0 -1
  185. package/dist/rules/index.js +0 -41
  186. package/dist/rules/index.js.map +0 -1
  187. package/dist/rules/no-direct-impl-in-route.d.ts +0 -12
  188. package/dist/rules/no-direct-impl-in-route.d.ts.map +0 -1
  189. package/dist/rules/no-direct-impl-in-route.js +0 -46
  190. package/dist/rules/no-direct-impl-in-route.js.map +0 -1
  191. package/dist/rules/no-direct-implementation-call.d.ts +0 -12
  192. package/dist/rules/no-direct-implementation-call.d.ts.map +0 -1
  193. package/dist/rules/no-direct-implementation-call.js +0 -39
  194. package/dist/rules/no-direct-implementation-call.js.map +0 -1
  195. package/dist/rules/no-sync-result-assumption.d.ts +0 -6
  196. package/dist/rules/no-sync-result-assumption.d.ts.map +0 -1
  197. package/dist/rules/no-sync-result-assumption.js +0 -98
  198. package/dist/rules/no-sync-result-assumption.js.map +0 -1
  199. package/dist/rules/no-throw-in-detour-target.d.ts +0 -12
  200. package/dist/rules/no-throw-in-detour-target.d.ts.map +0 -1
  201. package/dist/rules/no-throw-in-detour-target.js +0 -87
  202. package/dist/rules/no-throw-in-detour-target.js.map +0 -1
  203. package/dist/rules/no-throw-in-implementation.d.ts +0 -9
  204. package/dist/rules/no-throw-in-implementation.d.ts.map +0 -1
  205. package/dist/rules/no-throw-in-implementation.js +0 -34
  206. package/dist/rules/no-throw-in-implementation.js.map +0 -1
  207. package/dist/rules/prefer-schema-inference.d.ts +0 -7
  208. package/dist/rules/prefer-schema-inference.d.ts.map +0 -1
  209. package/dist/rules/prefer-schema-inference.js +0 -86
  210. package/dist/rules/prefer-schema-inference.js.map +0 -1
  211. package/dist/rules/scan.d.ts +0 -8
  212. package/dist/rules/scan.d.ts.map +0 -1
  213. package/dist/rules/scan.js +0 -32
  214. package/dist/rules/scan.js.map +0 -1
  215. package/dist/rules/specs.d.ts +0 -29
  216. package/dist/rules/specs.d.ts.map +0 -1
  217. package/dist/rules/specs.js +0 -192
  218. package/dist/rules/specs.js.map +0 -1
  219. package/dist/rules/structure.d.ts +0 -13
  220. package/dist/rules/structure.d.ts.map +0 -1
  221. package/dist/rules/structure.js +0 -142
  222. package/dist/rules/structure.js.map +0 -1
  223. package/dist/rules/types.d.ts +0 -52
  224. package/dist/rules/types.d.ts.map +0 -1
  225. package/dist/rules/types.js +0 -2
  226. package/dist/rules/types.js.map +0 -1
  227. package/dist/rules/valid-describe-refs.d.ts +0 -7
  228. package/dist/rules/valid-describe-refs.d.ts.map +0 -1
  229. package/dist/rules/valid-describe-refs.js +0 -51
  230. package/dist/rules/valid-describe-refs.js.map +0 -1
  231. package/dist/rules/valid-detour-refs.d.ts +0 -6
  232. package/dist/rules/valid-detour-refs.d.ts.map +0 -1
  233. package/dist/rules/valid-detour-refs.js +0 -116
  234. package/dist/rules/valid-detour-refs.js.map +0 -1
  235. package/src/__tests__/cli.test.ts +0 -198
  236. package/src/__tests__/drift.test.ts +0 -74
  237. package/src/__tests__/formatters.test.ts +0 -157
  238. package/src/__tests__/implementation-returns-result.test.ts +0 -75
  239. package/src/__tests__/no-direct-implementation-call.test.ts +0 -83
  240. package/src/__tests__/no-sync-result-assumption.test.ts +0 -85
  241. package/src/__tests__/no-throw-in-detour-target.test.ts +0 -78
  242. package/src/__tests__/prefer-schema-inference.test.ts +0 -84
  243. package/src/__tests__/rules.test.ts +0 -188
  244. package/src/__tests__/valid-describe-refs.test.ts +0 -60
  245. package/src/rules/no-direct-impl-in-route.ts +0 -77
  246. package/src/rules/no-throw-in-detour-target.ts +0 -150
  247. package/src/rules/valid-detour-refs.ts +0 -187
  248. package/tsconfig.json +0 -9
  249. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,76 @@
1
+ import { resource, Result, topo, trail } from '@ontrails/core';
2
+ import { z } from 'zod';
3
+
4
+ import { incompleteAccessorForStandardOp } from '../rules/incomplete-accessor-for-standard-op.js';
5
+ import { wrapTopoRule } from './wrap-rule.js';
6
+
7
+ type Accessor = Readonly<Record<string, (...args: unknown[]) => unknown>>;
8
+ type Connection = Readonly<Record<string, Accessor>>;
9
+
10
+ const noop = (): undefined => undefined;
11
+
12
+ const buildResource = (id: string, contourName: string, accessor: Accessor) =>
13
+ resource<Connection>(id, {
14
+ create: () => Result.ok({ [contourName]: accessor }),
15
+ mock: () => ({ [contourName]: accessor }),
16
+ });
17
+
18
+ const buildCrudTrail = (
19
+ trailId: string,
20
+ resourceValue: ReturnType<typeof buildResource>
21
+ ) =>
22
+ trail(trailId, {
23
+ blaze: () => Result.ok({ ok: true }),
24
+ input: z.object({}),
25
+ output: z.object({ ok: z.boolean() }),
26
+ pattern: 'crud',
27
+ resources: [resourceValue],
28
+ });
29
+
30
+ const cleanResource = buildResource('store.note.clean', 'note', {
31
+ insert: noop,
32
+ });
33
+ const warningResource = buildResource('store.note.warn', 'note', {
34
+ upsert: noop,
35
+ });
36
+
37
+ const cleanTopo = topo('trl-269-clean', {
38
+ noteCreate: buildCrudTrail('note.create', cleanResource),
39
+ noteResource: cleanResource,
40
+ });
41
+
42
+ const warningTopo = topo('trl-269-warning', {
43
+ noteCreate: buildCrudTrail('note.create', warningResource),
44
+ noteResource: warningResource,
45
+ });
46
+
47
+ export const incompleteAccessorForStandardOpTrail = wrapTopoRule({
48
+ examples: [
49
+ {
50
+ expected: { diagnostics: [] },
51
+ input: {
52
+ topo: cleanTopo,
53
+ },
54
+ name: 'Preferred accessors keep CRUD trails quiet',
55
+ },
56
+ {
57
+ expected: {
58
+ diagnostics: [
59
+ {
60
+ filePath: '<topo>',
61
+ line: 1,
62
+ message:
63
+ 'Trail "note.create" (crud.create): resource "store.note.warn" accessor "note" is missing preferred method "insert"; falls back to "upsert"',
64
+ rule: 'incomplete-accessor-for-standard-op',
65
+ severity: 'warn',
66
+ },
67
+ ],
68
+ },
69
+ input: {
70
+ topo: warningTopo,
71
+ },
72
+ name: 'Fallback-only create accessors emit a warning',
73
+ },
74
+ ],
75
+ rule: incompleteAccessorForStandardOp,
76
+ });
@@ -0,0 +1,39 @@
1
+ import { incompleteCrud } from '../rules/incomplete-crud.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const incompleteCrudTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ sourceCode: `import { Result, resource } from '@ontrails/core';
11
+ import { store } from '@ontrails/store';
12
+ import { crud } from '@ontrails/store/trails';
13
+ import { z } from 'zod';
14
+
15
+ const db = store({
16
+ notes: {
17
+ identity: 'id',
18
+ schema: z.object({
19
+ id: z.string(),
20
+ title: z.string(),
21
+ }),
22
+ },
23
+ });
24
+
25
+ const notesResource = resource('db.notes', {
26
+ create: () => Result.ok({}),
27
+ mock: () => ({}),
28
+ });
29
+
30
+ const [createNote, readNote, updateNote, deleteNote, listNote] = crud(
31
+ db.tables.notes,
32
+ notesResource
33
+ );`,
34
+ },
35
+ name: 'Full CRUD coverage stays quiet',
36
+ },
37
+ ],
38
+ rule: incompleteCrud,
39
+ });
@@ -0,0 +1,78 @@
1
+ export { activationOrphanTrail } from './activation-orphan.trail.js';
2
+ export { circularRefsTrail } from './circular-refs.trail.js';
3
+ export { contourExistsTrail } from './contour-exists.trail.js';
4
+ export { contextNoSurfaceTypesTrail } from './context-no-surface-types.trail.js';
5
+ export { composesDeclarationsTrail } from './composes-declarations.trail.js';
6
+ export { deadInternalTrailTrail } from './dead-internal-trail.trail.js';
7
+ export { deprecationWithoutGuidanceTrail } from './deprecation-without-guidance.trail.js';
8
+ export { draftFileMarkingTrail } from './draft-file-marking.trail.js';
9
+ export { draftVisibleDebtTrail } from './draft-visible-debt.trail.js';
10
+ export { errorMappingCompletenessTrail } from './error-mapping-completeness.trail.js';
11
+ export { exampleValidTrail } from './example-valid.trail.js';
12
+ export { firesDeclarationsTrail } from './fires-declarations.trail.js';
13
+ export { forkWithoutPreservedBlazeTrail } from './fork-without-preserved-blaze.trail.js';
14
+ export { implementationReturnsResultTrail } from './implementation-returns-result.trail.js';
15
+ export { incompleteAccessorForStandardOpTrail } from './incomplete-accessor-for-standard-op.trail.js';
16
+ export { incompleteCrudTrail } from './incomplete-crud.trail.js';
17
+ export { intentPropagationTrail } from './intent-propagation.trail.js';
18
+ export { layerFieldNameDriftTrail } from './layer-field-name-drift.trail.js';
19
+ export { markerSchemaUnsupportedTrail } from './marker-schema-unsupported.trail.js';
20
+ export { missingVisibilityTrail } from './missing-visibility.trail.js';
21
+ export { missingReconcileTrail } from './missing-reconcile.trail.js';
22
+ export { onReferencesExistTrail } from './on-references-exist.trail.js';
23
+ export { noDevPermitInSourceTrail } from './no-dev-permit-in-source.trail.js';
24
+ export { noDestructuredComposeTrail } from './no-destructured-compose.trail.js';
25
+ export { noLegacyLayerImportsTrail } from './no-legacy-layer-imports.trail.js';
26
+ export { noDirectImplementationCallTrail } from './no-direct-implementation-call.trail.js';
27
+ export { noNativeErrorResultTrail } from './no-native-error-result.trail.js';
28
+ export { noRedundantResultErrorWrapTrail } from './no-redundant-result-error-wrap.trail.js';
29
+ export { noRetiredCrossVocabularyTrail } from './no-retired-cross-vocabulary.trail.js';
30
+ export { noSyncResultAssumptionTrail } from './no-sync-result-assumption.trail.js';
31
+ export { noThrowInDetourRecoverTrail } from './no-throw-in-detour-recover.trail.js';
32
+ export { noThrowInImplementationTrail } from './no-throw-in-implementation.trail.js';
33
+ export { noTopLevelSurfaceTrail } from './no-top-level-surface.trail.js';
34
+ export { orphanedSignalTrail } from './orphaned-signal.trail.js';
35
+ export { ownerProjectionParityTrail } from './owner-projection-parity.trail.js';
36
+ export { pendingForceTrail } from './pending-force.trail.js';
37
+ export { permitGovernanceTrail } from './permit-governance.trail.js';
38
+ export { preferSchemaInferenceTrail } from './prefer-schema-inference.trail.js';
39
+ export { publicExportExampleCoverageTrail } from './public-export-example-coverage.trail.js';
40
+ export { publicInternalDeepImportsTrail } from './public-internal-deep-imports.trail.js';
41
+ export { publicOutputSchemaTrail } from './public-output-schema.trail.js';
42
+ export { publicUnionOutputDiscriminantsTrail } from './public-union-output-discriminants.trail.js';
43
+ export { readIntentFiresTrail } from './read-intent-fires.trail.js';
44
+ export { referenceExistsTrail } from './reference-exists.trail.js';
45
+ export { resolvedImportBoundaryTrail } from './resolved-import-boundary.trail.js';
46
+ export { resourceDeclarationsTrail } from './resource-declarations.trail.js';
47
+ export { resourceIdGrammarTrail } from './resource-id-grammar.trail.js';
48
+ export { resourceExistsTrail } from './resource-exists.trail.js';
49
+ export { resourceMockCoverageTrail } from './resource-mock-coverage.trail.js';
50
+ export { scheduledDestroyIntentTrail } from './scheduled-destroy-intent.trail.js';
51
+ export { signalGraphCoachingTrail } from './signal-graph-coaching.trail.js';
52
+ export { staticResourceAccessorPreferenceTrail } from './static-resource-accessor-preference.trail.js';
53
+ export { surfaceFacetCoherenceTrail } from './surface-facet-coherence.trail.js';
54
+ export { unmaterializedActivationSourceTrail } from './unmaterialized-activation-source.trail.js';
55
+ export { unreachableDetourShadowingTrail } from './unreachable-detour-shadowing.trail.js';
56
+ export { validDetourContractTrail } from './valid-detour-contract.trail.js';
57
+ export { validDescribeRefsTrail } from './valid-describe-refs.trail.js';
58
+ export { versionGapTrail } from './version-gap.trail.js';
59
+ export { versionPinnedComposeTrail } from './version-pinned-compose.trail.js';
60
+ export { versionWithoutExamplesTrail } from './version-without-examples.trail.js';
61
+ export { wardenExportSymmetryTrail } from './warden-export-symmetry.trail.js';
62
+ export { wardenRulesUseAstTrail } from './warden-rules-use-ast.trail.js';
63
+ export { webhookRouteCollisionTrail } from './webhook-route-collision.trail.js';
64
+
65
+ export {
66
+ diagnosticSchema,
67
+ projectAwareRuleInput,
68
+ ruleInput,
69
+ ruleOutput,
70
+ topoAwareRuleInput,
71
+ } from './schema.js';
72
+ export type {
73
+ ProjectAwareRuleInput,
74
+ RuleInput,
75
+ RuleOutput,
76
+ TopoAwareRuleInput,
77
+ } from './schema.js';
78
+ export { wrapRule, wrapTopoRule } from './wrap-rule.js';
@@ -0,0 +1,30 @@
1
+ import { intentPropagation } from '../rules/intent-propagation.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const intentPropagationTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ knownTrailIds: ['entity.read', 'entity.lookup'],
11
+ sourceCode: `trail('entity.read', {
12
+ intent: 'read',
13
+ composes: ['entity.lookup'],
14
+ blaze: async (_input, ctx) => ctx.compose('entity.lookup', {}),
15
+ });
16
+
17
+ trail('entity.lookup', {
18
+ intent: 'read',
19
+ blaze: async () => Result.ok({}),
20
+ });`,
21
+ trailIntentsById: {
22
+ 'entity.lookup': 'read',
23
+ 'entity.read': 'read',
24
+ },
25
+ },
26
+ name: 'Read trails may compose other read trails',
27
+ },
28
+ ],
29
+ rule: intentPropagation,
30
+ });
@@ -0,0 +1,39 @@
1
+ import { layerFieldNameDrift } from '../rules/layer-field-name-drift.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const layerFieldNameDriftTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'packages/cli/src/build.ts',
10
+ sourceCode: `import { LAYER_FIELD_RESERVED_NAMES } from '@ontrails/core';
11
+
12
+ const collides = LAYER_FIELD_RESERVED_NAMES.has('all');
13
+ `,
14
+ },
15
+ name: 'Allows shared core reserved-name set',
16
+ },
17
+ {
18
+ expected: {
19
+ diagnostics: [
20
+ {
21
+ filePath: 'packages/cli/src/build.ts',
22
+ line: 1,
23
+ message:
24
+ 'layer-field-name-drift: surface-local reserved name set "META_FLAG_CANDIDATES" can make layer input fields project differently across surfaces. Import LAYER_FIELD_RESERVED_NAMES from @ontrails/core instead.',
25
+ rule: 'layer-field-name-drift',
26
+ severity: 'error',
27
+ },
28
+ ],
29
+ },
30
+ input: {
31
+ filePath: 'packages/cli/src/build.ts',
32
+ sourceCode: `const META_FLAG_CANDIDATES = new Set(['all']);
33
+ `,
34
+ },
35
+ name: 'Flags surface-local reserved-name sets',
36
+ },
37
+ ],
38
+ rule: layerFieldNameDrift,
39
+ });
@@ -0,0 +1,23 @@
1
+ import { markerSchemaUnsupported } from '../rules/trail-versioning-source.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const markerSchemaUnsupportedTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'src/trails/versioned.ts',
10
+ sourceCode: `
11
+ trail('versioned.schema', {
12
+ version: 2,
13
+ input: z.object({ name: z.string() }),
14
+ output: z.object({ message: z.string() }),
15
+ blaze: async () => Result.ok({ message: 'ok' }),
16
+ });
17
+ `,
18
+ },
19
+ name: 'Stable marker-compatible schemas pass',
20
+ },
21
+ ],
22
+ rule: markerSchemaUnsupported,
23
+ });
@@ -0,0 +1,33 @@
1
+ import { missingReconcile } from '../rules/missing-reconcile.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const missingReconcileTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ // Composite keys: `${storeBinding}:${tableName}` so two stores with
10
+ // the same table name don't collide.
11
+ crudTableIds: ['definition:notes'],
12
+ filePath: 'clean.ts',
13
+ knownTrailIds: ['notes.reconcile'],
14
+ reconcileTableIds: ['definition:notes'],
15
+ sourceCode: `import { store } from '@ontrails/store';
16
+ import { z } from 'zod';
17
+
18
+ const definition = store({
19
+ notes: {
20
+ identity: 'id',
21
+ schema: z.object({
22
+ id: z.string(),
23
+ title: z.string(),
24
+ }),
25
+ versioned: true,
26
+ },
27
+ });`,
28
+ },
29
+ name: 'Versioned CRUD tables stay clean when reconcile exists',
30
+ },
31
+ ],
32
+ rule: missingReconcile,
33
+ });
@@ -0,0 +1,22 @@
1
+ import { missingVisibility } from '../rules/missing-visibility.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const missingVisibilityTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ composeTargetTrailIds: ['entity.resolve'],
10
+ filePath: 'clean.ts',
11
+ knownTrailIds: ['entity.resolve'],
12
+ sourceCode: `trail('entity.resolve', {
13
+ visibility: 'internal',
14
+ composeInput: z.object({ forkedFrom: z.string() }),
15
+ blaze: async () => Result.ok({}),
16
+ });`,
17
+ },
18
+ name: 'Composition-only trails stay quiet when already internal',
19
+ },
20
+ ],
21
+ rule: missingVisibility,
22
+ });
@@ -0,0 +1,44 @@
1
+ import { noDestructuredCompose } from '../rules/no-destructured-compose.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noDestructuredComposeTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ sourceCode: `trail("entity.onboard", {
11
+ composes: ["entity.create"],
12
+ blaze: async (input, ctx) => ctx.compose("entity.create", input),
13
+ });`,
14
+ },
15
+ name: 'Clean blaze using ctx.compose directly',
16
+ },
17
+ {
18
+ expected: {
19
+ diagnostics: [
20
+ {
21
+ filePath: 'destructured.ts',
22
+ line: 4,
23
+ message:
24
+ 'Trail "entity.onboard" destructures compose from the blaze context. Use ctx.compose(...) directly so composition stays visible and Warden can recognize composed Result values.',
25
+ rule: 'no-destructured-compose',
26
+ severity: 'warn',
27
+ },
28
+ ],
29
+ },
30
+ input: {
31
+ filePath: 'destructured.ts',
32
+ sourceCode: `trail("entity.onboard", {
33
+ composes: ["entity.create"],
34
+ blaze: async (input, ctx) => {
35
+ const { compose } = ctx;
36
+ return compose("entity.create", input);
37
+ },
38
+ });`,
39
+ },
40
+ name: 'Warns when compose is destructured from the blaze context',
41
+ },
42
+ ],
43
+ rule: noDestructuredCompose,
44
+ });
@@ -0,0 +1,16 @@
1
+ import { noDevPermitInSource } from '../rules/no-dev-permit-in-source.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noDevPermitInSourceTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'apps/example/src/cli.ts',
10
+ sourceCode: `import { tokenPreset } from '@ontrails/cli';\n`,
11
+ },
12
+ name: 'Source files without --dev-permit are clean',
13
+ },
14
+ ],
15
+ rule: noDevPermitInSource,
16
+ });
@@ -0,0 +1,16 @@
1
+ import { noDirectImplementationCall } from '../rules/no-direct-implementation-call.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noDirectImplementationCallTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ sourceCode: `const data = await ctx.compose("entity.show", { id: "1" });`,
11
+ },
12
+ name: 'Clean code using ctx.compose instead of .blaze()',
13
+ },
14
+ ],
15
+ rule: noDirectImplementationCall,
16
+ });
@@ -0,0 +1,41 @@
1
+ import { noLegacyLayerImports } from '../rules/no-legacy-layer-imports.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noLegacyLayerImportsTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'apps/example/src/cli.ts',
10
+ sourceCode: `import { tokenPreset } from '@ontrails/cli';\n`,
11
+ },
12
+ name: 'Source files without legacy layer references are clean',
13
+ },
14
+ {
15
+ expected: {
16
+ diagnostics: [
17
+ {
18
+ filePath: 'apps/example/src/cli.ts',
19
+ fix: {
20
+ class: 'term-rewrite',
21
+ reason:
22
+ "Legacy layer 'authLayer' was removed in TRL-475; Permit enforcement is intrinsic to executeTrail. Removal has no mechanical replacement, so it needs human migration.",
23
+ safety: 'review',
24
+ },
25
+ line: 1,
26
+ message:
27
+ "Legacy layer 'authLayer' was removed in TRL-475. Permit enforcement is intrinsic to executeTrail. See docs/adr/0043-layer-evolution.md.",
28
+ rule: 'no-legacy-layer-imports',
29
+ severity: 'error',
30
+ },
31
+ ],
32
+ },
33
+ input: {
34
+ filePath: 'apps/example/src/cli.ts',
35
+ sourceCode: `import { authLayer } from '@ontrails/permits';\n`,
36
+ },
37
+ name: 'Legacy layer imports produce migration diagnostics',
38
+ },
39
+ ],
40
+ rule: noLegacyLayerImports,
41
+ });
@@ -0,0 +1,18 @@
1
+ import { noNativeErrorResult } from '../rules/no-native-error-result.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noNativeErrorResultTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'entity.ts',
10
+ sourceCode: `import { InternalError, Result } from "@ontrails/core";
11
+
12
+ export const load = () => Result.err(new InternalError("failed"));`,
13
+ },
14
+ name: 'Specific TrailsError subclasses stay clean',
15
+ },
16
+ ],
17
+ rule: noNativeErrorResult,
18
+ });
@@ -0,0 +1,55 @@
1
+ import { noRedundantResultErrorWrap } from '../rules/no-redundant-result-error-wrap.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noRedundantResultErrorWrapTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'entity.ts',
10
+ sourceCode: `import { Result, trail } from "@ontrails/core";
11
+
12
+ trail("entity.load", {
13
+ blaze: async (input, ctx) => {
14
+ const loaded = await ctx.compose("entity.fetch", input);
15
+ if (loaded.isErr()) {
16
+ return loaded;
17
+ }
18
+ return Result.ok(loaded.value);
19
+ },
20
+ });`,
21
+ },
22
+ name: 'Existing Result values pass through directly',
23
+ },
24
+ {
25
+ expected: {
26
+ diagnostics: [
27
+ {
28
+ filePath: 'entity.ts',
29
+ line: 7,
30
+ message:
31
+ 'Trail "entity.load": Result.err(loaded.error) re-wraps a Result that already carries that error. Return loaded directly to preserve the original Result boundary.',
32
+ rule: 'no-redundant-result-error-wrap',
33
+ severity: 'warn',
34
+ },
35
+ ],
36
+ },
37
+ input: {
38
+ filePath: 'entity.ts',
39
+ sourceCode: `import { Result, trail } from "@ontrails/core";
40
+
41
+ trail("entity.load", {
42
+ blaze: async (input, ctx) => {
43
+ const loaded = await ctx.compose("entity.fetch", input);
44
+ if (loaded.isErr()) {
45
+ return Result.err(loaded.error);
46
+ }
47
+ return Result.ok(loaded.value);
48
+ },
49
+ });`,
50
+ },
51
+ name: 'Warns when an existing Result error is re-wrapped',
52
+ },
53
+ ],
54
+ rule: noRedundantResultErrorWrap,
55
+ });
@@ -0,0 +1,42 @@
1
+ import { noRetiredCrossVocabulary } from '../rules/no-retired-cross-vocabulary.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noRetiredCrossVocabularyTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'apps/example/src/trails/play.ts',
10
+ sourceCode: 'export const play = trail("play", { composes: [] });\n',
11
+ },
12
+ name: 'Source files using compose vocabulary are clean',
13
+ },
14
+ {
15
+ expected: {
16
+ diagnostics: [
17
+ {
18
+ filePath: 'apps/example/src/trails/play.ts',
19
+ fix: {
20
+ class: 'term-rewrite',
21
+ edits: [{ end: 43, replacement: 'composes', start: 36 }],
22
+ reason:
23
+ "Retired composition vocabulary 'crosses' has a mechanical beta.19 replacement 'composes'.",
24
+ safety: 'safe',
25
+ },
26
+ line: 1,
27
+ message:
28
+ "Retired composition vocabulary 'crosses' should be 'composes' after the beta.19 compose cutover.",
29
+ rule: 'no-retired-cross-vocabulary',
30
+ severity: 'error',
31
+ },
32
+ ],
33
+ },
34
+ input: {
35
+ filePath: 'apps/example/src/trails/play.ts',
36
+ sourceCode: 'export const play = trail("play", { crosses: [] });\n',
37
+ },
38
+ name: 'Retired crosses declarations produce safe migration diagnostics',
39
+ },
40
+ ],
41
+ rule: noRetiredCrossVocabulary,
42
+ });
@@ -0,0 +1,19 @@
1
+ import { noSyncResultAssumption } from '../rules/no-sync-result-assumption.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noSyncResultAssumptionTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ sourceCode: `const result = await myTrail.blaze(input, ctx);
11
+ if (result.isOk()) {
12
+ console.log(result.value);
13
+ }`,
14
+ },
15
+ name: 'Properly awaited .blaze() call',
16
+ },
17
+ ],
18
+ rule: noSyncResultAssumption,
19
+ });
@@ -0,0 +1,24 @@
1
+ import { noThrowInDetourRecover } from '../rules/no-throw-in-detour-recover.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noThrowInDetourRecoverTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ sourceCode: `trail("entity.save", {
11
+ detours: [
12
+ {
13
+ on: ConflictError,
14
+ recover: async () => Result.ok({ recovered: true }),
15
+ },
16
+ ],
17
+ blaze: () => Result.err(new ConflictError("conflict")),
18
+ })`,
19
+ },
20
+ name: 'Detour recover without throw',
21
+ },
22
+ ],
23
+ rule: noThrowInDetourRecover,
24
+ });
@@ -0,0 +1,20 @@
1
+ import { noThrowInImplementation } from '../rules/no-throw-in-implementation.js';
2
+ import { wrapRule } from './wrap-rule.js';
3
+
4
+ export const noThrowInImplementationTrail = wrapRule({
5
+ examples: [
6
+ {
7
+ expected: { diagnostics: [] },
8
+ input: {
9
+ filePath: 'clean.ts',
10
+ sourceCode: `trail("entity.show", {
11
+ blaze: async (input, ctx) => {
12
+ return Result.ok({ name: "test" });
13
+ }
14
+ })`,
15
+ },
16
+ name: 'Clean implementation without throw',
17
+ },
18
+ ],
19
+ rule: noThrowInImplementation,
20
+ });