@telorun/analyzer 0.70.0 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/analysis-registry.d.ts.map +1 -1
  2. package/dist/analysis-registry.js +4 -5
  3. package/dist/analyzer.d.ts.map +1 -1
  4. package/dist/analyzer.js +92 -10
  5. package/dist/call-graph.d.ts.map +1 -1
  6. package/dist/call-graph.js +10 -4
  7. package/dist/catch-scope.d.ts +72 -0
  8. package/dist/catch-scope.d.ts.map +1 -0
  9. package/dist/catch-scope.js +102 -0
  10. package/dist/cel-scope-query.d.ts +14 -0
  11. package/dist/cel-scope-query.d.ts.map +1 -1
  12. package/dist/cel-scope-query.js +36 -6
  13. package/dist/definition-registry.d.ts.map +1 -1
  14. package/dist/definition-registry.js +3 -4
  15. package/dist/deprecation.d.ts +21 -0
  16. package/dist/deprecation.d.ts.map +1 -0
  17. package/dist/deprecation.js +26 -0
  18. package/dist/flatten-for-analyzer.d.ts +2 -2
  19. package/dist/flatten-for-analyzer.d.ts.map +1 -1
  20. package/dist/flatten-for-analyzer.js +1 -1
  21. package/dist/index.d.ts +5 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +3 -2
  24. package/dist/manifest-visitor.d.ts +17 -1
  25. package/dist/manifest-visitor.d.ts.map +1 -1
  26. package/dist/manifest-visitor.js +16 -4
  27. package/dist/migrations/report.d.ts +1 -1
  28. package/dist/migrations/report.d.ts.map +1 -1
  29. package/dist/migrations/report.js +5 -0
  30. package/dist/module-alias-scope.d.ts +65 -0
  31. package/dist/module-alias-scope.d.ts.map +1 -0
  32. package/dist/module-alias-scope.js +25 -0
  33. package/dist/{zone-module-documents.d.ts → module-documents.d.ts} +11 -7
  34. package/dist/module-documents.d.ts.map +1 -0
  35. package/dist/ref-sentinel-target.d.ts +38 -0
  36. package/dist/ref-sentinel-target.d.ts.map +1 -0
  37. package/dist/ref-sentinel-target.js +13 -0
  38. package/dist/ref-slot.d.ts +15 -0
  39. package/dist/ref-slot.d.ts.map +1 -1
  40. package/dist/ref-slot.js +7 -0
  41. package/dist/resolve-schema-type-refs.d.ts.map +1 -1
  42. package/dist/resolve-schema-type-refs.js +2 -1
  43. package/dist/resolve-throws-union.d.ts +47 -2
  44. package/dist/resolve-throws-union.d.ts.map +1 -1
  45. package/dist/resolve-throws-union.js +199 -20
  46. package/dist/resolve-zone-requirements.d.ts +3 -3
  47. package/dist/resolve-zone-requirements.d.ts.map +1 -1
  48. package/dist/resolve-zone-requirements.js +12 -12
  49. package/dist/schema-compat.d.ts.map +1 -1
  50. package/dist/schema-compat.js +13 -1
  51. package/dist/schema-error-report.d.ts.map +1 -1
  52. package/dist/schema-error-report.js +48 -4
  53. package/dist/schema-keywords.d.ts.map +1 -1
  54. package/dist/schema-keywords.js +3 -1
  55. package/dist/schema-walk.d.ts +27 -0
  56. package/dist/schema-walk.d.ts.map +1 -1
  57. package/dist/schema-walk.js +44 -0
  58. package/dist/telo-version.d.ts +1 -1
  59. package/dist/telo-version.js +1 -1
  60. package/dist/template-body.d.ts.map +1 -1
  61. package/dist/template-body.js +2 -4
  62. package/dist/types.d.ts +20 -3
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/types.js +11 -0
  65. package/dist/validate-identifier-names.d.ts +2 -2
  66. package/dist/validate-identifier-names.d.ts.map +1 -1
  67. package/dist/validate-identifier-names.js +22 -7
  68. package/dist/validate-invocation-contract.d.ts +5 -0
  69. package/dist/validate-invocation-contract.d.ts.map +1 -1
  70. package/dist/validate-invocation-contract.js +114 -3
  71. package/dist/validate-logging.d.ts.map +1 -1
  72. package/dist/validate-logging.js +2 -2
  73. package/dist/validate-ref-slots.d.ts +1 -1
  74. package/dist/validate-ref-slots.d.ts.map +1 -1
  75. package/dist/validate-ref-slots.js +34 -0
  76. package/dist/validate-references.d.ts +16 -5
  77. package/dist/validate-references.d.ts.map +1 -1
  78. package/dist/validate-references.js +57 -15
  79. package/dist/validate-resource-inputs.d.ts +1 -26
  80. package/dist/validate-resource-inputs.d.ts.map +1 -1
  81. package/dist/validate-resource-inputs.js +12 -2
  82. package/dist/validate-schema-type-refs.d.ts.map +1 -1
  83. package/dist/validate-schema-type-refs.js +2 -1
  84. package/dist/validate-throws-coverage.d.ts +5 -1
  85. package/dist/validate-throws-coverage.d.ts.map +1 -1
  86. package/dist/validate-throws-coverage.js +241 -86
  87. package/package.json +3 -3
  88. package/src/analysis-registry.ts +4 -5
  89. package/src/analyzer.ts +115 -11
  90. package/src/call-graph.ts +9 -3
  91. package/src/catch-scope.ts +157 -0
  92. package/src/cel-scope-query.ts +45 -8
  93. package/src/definition-registry.ts +3 -6
  94. package/src/deprecation.ts +36 -0
  95. package/src/flatten-for-analyzer.ts +3 -3
  96. package/src/index.ts +10 -3
  97. package/src/manifest-visitor.ts +30 -5
  98. package/src/migrations/report.ts +5 -1
  99. package/src/module-alias-scope.ts +94 -0
  100. package/src/{zone-module-documents.ts → module-documents.ts} +10 -6
  101. package/src/ref-sentinel-target.ts +46 -0
  102. package/src/ref-slot.ts +19 -0
  103. package/src/resolve-schema-type-refs.ts +2 -1
  104. package/src/resolve-throws-union.ts +253 -20
  105. package/src/resolve-zone-requirements.ts +14 -14
  106. package/src/schema-compat.ts +13 -0
  107. package/src/schema-error-report.ts +50 -6
  108. package/src/schema-keywords.ts +4 -1
  109. package/src/schema-walk.ts +56 -0
  110. package/src/telo-version.ts +1 -1
  111. package/src/template-body.ts +2 -5
  112. package/src/types.ts +21 -3
  113. package/src/validate-identifier-names.ts +28 -9
  114. package/src/validate-invocation-contract.ts +128 -2
  115. package/src/validate-logging.ts +2 -3
  116. package/src/validate-ref-slots.ts +41 -1
  117. package/src/validate-references.ts +74 -14
  118. package/src/validate-resource-inputs.ts +26 -3
  119. package/src/validate-schema-type-refs.ts +2 -1
  120. package/src/validate-throws-coverage.ts +344 -92
  121. package/dist/zone-module-documents.d.ts.map +0 -1
  122. /package/dist/{zone-module-documents.js → module-documents.js} +0 -0
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { HostVersions } from "./requires-block.js";
2
2
 
3
- import type { ZoneModuleDocuments } from "./zone-module-documents.js";
3
+ import type { ModuleDocuments } from "./module-documents.js";
4
4
  /** Matches LSP DiagnosticSeverity values exactly.
5
5
  * https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticSeverity */
6
6
  export const DiagnosticSeverity = {
@@ -11,6 +11,19 @@ export const DiagnosticSeverity = {
11
11
  } as const;
12
12
  export type DiagnosticSeverity = (typeof DiagnosticSeverity)[keyof typeof DiagnosticSeverity];
13
13
 
14
+ /** Matches LSP DiagnosticTag values exactly.
15
+ * https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticTag
16
+ *
17
+ * Declared whole rather than trimmed to what Telo emits today, for the reason
18
+ * the severity ladder above is: it is someone else's closed vocabulary, and a
19
+ * partial copy of one is what drifts. `Unnecessary` (rendered faded) has an
20
+ * obvious future consumer in the unused-declaration checks. */
21
+ export const DiagnosticTag = {
22
+ Unnecessary: 1,
23
+ Deprecated: 2,
24
+ } as const;
25
+ export type DiagnosticTag = (typeof DiagnosticTag)[keyof typeof DiagnosticTag];
26
+
14
27
  /** Default entry-point filename when a directory is given instead of a file. */
15
28
  export const DEFAULT_MANIFEST_FILENAME = "telo.yaml";
16
29
 
@@ -70,6 +83,11 @@ export interface AnalysisDiagnostic {
70
83
  /** e.g. "telo-analyzer" */
71
84
  source?: string;
72
85
  message: string;
86
+ /** What KIND of thing this is, orthogonal to how loudly it asks to be dealt
87
+ * with. A deprecation is warning-grade *and* a deprecation; severity alone
88
+ * can only say the first, which is why an editor renders a deprecated symbol
89
+ * struck through rather than merely yellow. */
90
+ tags?: DiagnosticTag[];
73
91
  /** Telo-specific extras such as { resource: { kind, name }, path } */
74
92
  data?: unknown;
75
93
  }
@@ -142,10 +160,10 @@ export interface AnalysisOptions {
142
160
  /** Imported libraries' FULL document sets, for the zone stage's per-library
143
161
  * export derivation — the flattened analysis view forwards only each
144
162
  * library's export surface, never its internal dispatch chain. Collected
145
- * from a LoadedGraph via `collectZoneModuleDocuments`. Omitting it skips
163
+ * from a LoadedGraph via `collectModuleDocuments`. Omitting it skips
146
164
  * the derivation (the under-approximating direction — the runtime check
147
165
  * remains the enforcement). */
148
- moduleDocuments?: ZoneModuleDocuments[];
166
+ moduleDocuments?: ModuleDocuments[];
149
167
  /** When true, `analyze()` runs the state-mutating setup (module identity /
150
168
  * alias / definition registration plus `normalizeInlineResources`) but
151
169
  * skips every diagnostic-producing pass — per-resource validation, the
@@ -1,8 +1,13 @@
1
- import type { ResourceManifest } from "@telorun/sdk";
1
+ import type { ResourceDefinition, ResourceManifest } from "@telorun/sdk";
2
2
 
3
- import type { AliasResolver } from "./alias-resolver.js";
3
+ import {
4
+ moduleScopedDefResolver,
5
+ type AliasResolver,
6
+ type ModuleScopes,
7
+ } from "./alias-resolver.js";
4
8
  import type { CallGraph } from "./call-graph.js";
5
9
  import type { DefinitionRegistry } from "./definition-registry.js";
10
+ import { inheritedCapability, type DefResolver } from "./extends-resolution.js";
6
11
  import {
7
12
  TYPE_LEVEL_DOC_KINDS,
8
13
  checkName,
@@ -44,8 +49,10 @@ export function validateIdentifierNames(
44
49
  aliases: AliasResolver,
45
50
  rootModules: Set<string>,
46
51
  graph: CallGraph,
52
+ scopes: ModuleScopes,
47
53
  ): AnalysisDiagnostic[] {
48
54
  const out: AnalysisDiagnostic[] = [];
55
+ const resolveDef = moduleScopedDefResolver<ResourceDefinition>(registry, aliases, scopes);
49
56
 
50
57
  for (const manifest of manifests) {
51
58
  const metadata = manifest.metadata as Record<string, unknown> | undefined;
@@ -65,7 +72,7 @@ export function validateIdentifierNames(
65
72
  const ownModule = metadata?.module as string | undefined;
66
73
  if (ownModule && !rootModules.has(ownModule)) continue;
67
74
 
68
- const level = levelFor(manifest, registry, aliases);
75
+ const level = levelFor(manifest, resolveDef, ownModule);
69
76
  push(out, checkName(name, level, surfaceFor(manifest.kind)), {
70
77
  kind: manifest.kind,
71
78
  name,
@@ -126,20 +133,32 @@ export function validateIdentifierNames(
126
133
  * a resource. Capability-driven rather than by kind name, so no resource kind
127
134
  * is hardcoded here.
128
135
  *
136
+ * **The capability is the INHERITED one**, not the leaf declaration. Capability
137
+ * is inherited and immutable along `extends` — a kind omits it to take its
138
+ * ancestor's — so reading the leaf answers `undefined` for every kind that does,
139
+ * and the fallback then calls a type a value. That is not hypothetical: it is
140
+ * exactly `Type.JsonSchema`, a pure alias of the built-in (`extends:
141
+ * Telo.JsonSchema`, no `capability:` of its own), so a shape declared through
142
+ * the deprecated spelling was reported as miscased while the identical
143
+ * declaration written as `kind: Telo.JsonSchema` was not. Renaming on that
144
+ * report is worse than the warning: `extends:` between two named shapes is not a
145
+ * reference slot, so the inheritance edge does not move with the name.
146
+ *
129
147
  * An unresolvable kind falls back to value level — the honest default, since
130
148
  * `UNDEFINED_KIND` already reports the real problem and guessing type level
131
149
  * would stack a case error on top of it.
132
150
  */
133
151
  function levelFor(
134
152
  manifest: ResourceManifest,
135
- registry: DefinitionRegistry,
136
- aliases: AliasResolver,
153
+ resolveDef: DefResolver & { in(kind: string, module?: string): ResourceDefinition | undefined },
154
+ ownModule: string | undefined,
137
155
  ): NameLevel {
138
156
  if (TYPE_LEVEL_DOC_KINDS.has(manifest.kind as string)) return "type";
139
- // The root resolver is the right one unconditionally: every manifest
140
- // reaching here belongs to a root module, the others having been skipped.
141
- const canonical = aliases.resolveKind(manifest.kind as string) ?? (manifest.kind as string);
142
- return registry.resolve(canonical)?.capability === "Telo.Type" ? "type" : "value";
157
+ // The top-level lookup is in the module that WROTE the `kind:` — a root one,
158
+ // the others having been skipped above while the chain walk re-scopes at
159
+ // every hop, since an `extends` alias belongs to the file declaring it.
160
+ const def = resolveDef.in(manifest.kind as string, ownModule);
161
+ return inheritedCapability(def, resolveDef) === "Telo.Type" ? "type" : "value";
143
162
  }
144
163
 
145
164
  /** The noun phrase a diagnostic uses as its subject. */
@@ -2,13 +2,17 @@ import type { ResourceDefinition, ResourceManifest } from "@telorun/sdk";
2
2
  import type { AliasResolver } from "./alias-resolver.js";
3
3
  import type { DefinitionRegistry } from "./definition-registry.js";
4
4
  import {
5
+ ancestorChain,
5
6
  type ContractDirection,
6
7
  type DefResolver,
7
8
  effectiveContractField,
8
9
  mappingFieldFor,
9
10
  needsContractMapping,
10
11
  } from "./extends-resolution.js";
12
+ import { resolveTypeFieldToSchema } from "./validate-cel-context.js";
13
+ import { moduleAliasScope } from "./module-alias-scope.js";
11
14
  import { buildReferenceFieldMap, isRefEntry } from "./reference-field-map.js";
15
+ import { checkSchemaCompatibility } from "./schema-compat.js";
12
16
  import { DiagnosticSeverity, type AnalysisDiagnostic } from "./types.js";
13
17
 
14
18
  const SOURCE = "telo-analyzer";
@@ -29,6 +33,11 @@ const SOURCE = "telo-analyzer";
29
33
  * whose input contract is now `inputType:`.
30
34
  * - CONTRACT_TYPE_NOT_FOUND: a contract names a type that is not declared in
31
35
  * scope, so every call through it would fail at dispatch.
36
+ * - CONTRACT_NOT_SUBSTITUTABLE: a definition replaces an ancestor's contract
37
+ * with a shape that cannot stand in for it. The one check nothing else makes:
38
+ * contracts resolve to the nearest declaration in BOTH halves, so a child that
39
+ * declares its own is compared against its abstract by neither the analyzer
40
+ * nor dispatch.
32
41
  *
33
42
  * Deliberately NOT diagnosed: an input that is neither `required:` nor
34
43
  * defaulted. It is indistinguishable from a genuinely optional one — `Ai.Text`
@@ -45,8 +54,7 @@ export function validateInvocationContract(
45
54
  ): AnalysisDiagnostic[] {
46
55
  const diagnostics: AnalysisDiagnostic[] = [];
47
56
  const resolveDef: DefResolver = (kind, from) => {
48
- const module = (from?.metadata as { module?: string } | undefined)?.module;
49
- const scope = (module ? aliasesByModule.get(module) : undefined) ?? aliases;
57
+ const scope = moduleAliasScope(from?.metadata, aliases, aliasesByModule);
50
58
  return registry.resolve(kind) ?? registry.resolve(scope.resolveKind(kind) ?? kind);
51
59
  };
52
60
 
@@ -73,6 +81,7 @@ export function validateInvocationContract(
73
81
  if (m.kind === "Telo.Definition" || m.kind === "Telo.Abstract") {
74
82
  checkMappingRequired(m, resource, filePath, resolveDef, diagnostics);
75
83
  checkContractResolves(m, md, manifests, resource, filePath, diagnostics);
84
+ checkAncestorSubstitutability(m, md, manifests, resource, filePath, resolveDef, diagnostics);
76
85
  continue;
77
86
  }
78
87
 
@@ -360,6 +369,123 @@ function namedTypeReference(value: unknown): string | undefined {
360
369
  return typeof ref.name === "string" ? ref.name : undefined;
361
370
  }
362
371
 
372
+ /**
373
+ * A REPLACING CONTRACT MUST STILL STAND IN FOR THE ONE IT REPLACES.
374
+ *
375
+ * Contracts resolve to the NEAREST declaration and never merge, which is right —
376
+ * a call signature is not additive, and a backend narrowing `status` to the
377
+ * states it actually has could not express that through a merge. But the
378
+ * consequence is that an abstract's contract binds only the children that
379
+ * declare none of their own: a child that declares one is checked against
380
+ * nothing, statically or at dispatch, since `resolveBoundContract` stops at the
381
+ * same nearest declaration. So an abstract could state a floor every
382
+ * implementation must answer with (`Durable.Run`'s `runId` / `status`, the
383
+ * identity every later question about a run is asked by) and have that floor hold
384
+ * for exactly the implementations that declared nothing — while the real ones,
385
+ * which all declare their own, escaped it. A slot typed by the abstract would
386
+ * then be typed by a promise nothing kept.
387
+ *
388
+ * The rule is substitutability, and its direction differs per contract because
389
+ * one is produced and the other consumed:
390
+ *
391
+ * - `outputType` is COVARIANT — a consumer written against the ancestor reads
392
+ * the ancestor's shape, so the child's output must be acceptable where the
393
+ * ancestor's is declared. Dropping a required property is what breaks it.
394
+ * - `inputType` is CONTRAVARIANT — a caller written against the ancestor sends
395
+ * the ancestor's shape, so the ancestor's input must be acceptable where the
396
+ * child's is declared. Requiring an input the ancestor never mentions is what
397
+ * breaks it: no such caller could satisfy it.
398
+ *
399
+ * **Only an ABSTRACT ancestor's contract is a contract**, and that narrowing is a
400
+ * decision rather than an oversight. Extending a CONCRETE kind is how a friendlier
401
+ * schema is put over an existing controller — `base:` reshapes its config and
402
+ * `inputs:` / `result:` translate its call signature — so a child there is
403
+ * SUPPOSED to present different inputs, and demanding substitutability would
404
+ * reject the pattern the standard library and every custom-kind example are built
405
+ * on. An abstract has no implementation to reshape: extending one is a claim to
406
+ * BE the thing, its contract is written for implementors, and a slot typed by it
407
+ * is polymorphic by construction — which is exactly where an unkept promise has
408
+ * nowhere to be caught.
409
+ *
410
+ * A direction the child BRIDGES (`inputs:` for inputs, `result:` for outputs) is
411
+ * skipped for the same reason one hop down: the mapping is the author saying the
412
+ * shapes differ deliberately and are translated.
413
+ *
414
+ * The comparison is {@link checkSchemaCompatibility}, which reports only DEFINITE
415
+ * mismatches — a union, an absent `type`, an undeclared argument all read as
416
+ * compatible — so narrowing a value's type, adding an optional property or
417
+ * restricting an enum stays legal, which is the whole point of letting a child
418
+ * replace the contract at all.
419
+ */
420
+ function checkAncestorSubstitutability(
421
+ m: ResourceManifest,
422
+ md: Record<string, unknown>,
423
+ manifests: ResourceManifest[],
424
+ resource: { kind: string; name: string },
425
+ filePath: string | undefined,
426
+ resolveDef: DefResolver,
427
+ diagnostics: AnalysisDiagnostic[],
428
+ ): void {
429
+ const def = m as unknown as ResourceDefinition;
430
+
431
+ for (const direction of ["inputType", "outputType"] as ContractDirection[]) {
432
+ const own = md[direction];
433
+ if (own === undefined || own === null) continue;
434
+ // A declared bridge says the shapes differ on purpose and are translated.
435
+ if (md[mappingFieldFor(direction)] != null) continue;
436
+
437
+ // The nearest ANCESTOR that declares it — the contract this one replaces.
438
+ // Walking past self is the whole question: `contractDeclarer` would answer
439
+ // "this one", which is what nothing checks.
440
+ const ancestor = ancestorChain(def, resolveDef).find((a) => {
441
+ const inherited = (a as unknown as Record<string, unknown>)[direction];
442
+ return inherited !== undefined && inherited !== null;
443
+ });
444
+ if (!ancestor || ancestor.kind !== "Telo.Abstract") continue;
445
+ const inherited = (ancestor as unknown as Record<string, unknown>)[direction];
446
+
447
+ // The WHOLE manifest set, which is what `analyzerContractScope`'s
448
+ // `typeManifestsFor` hands `resolveContract` — so this resolves a named type
449
+ // exactly as the resolver the kernel binds with does. Filtering to the
450
+ // declaring module looked more careful and was strictly worse: a contract
451
+ // naming a shape from a shared module resolved to nothing, and an
452
+ // unresolvable side is skipped, so the check silently switched itself off for
453
+ // precisely the libraries that factor their shapes out. Nothing else caught
454
+ // it either — `CONTRACT_TYPE_NOT_FOUND` finds the type through its own global
455
+ // fallback, so such a kind passed `telo check` with no diagnostic at all.
456
+ const ownSchema = resolveTypeFieldToSchema(own, manifests);
457
+ const ancestorSchema = resolveTypeFieldToSchema(inherited, manifests);
458
+ // An unresolvable side says nothing about compatibility; CONTRACT_TYPE_NOT_FOUND
459
+ // is what reports a contract that names a type nothing declares.
460
+ if (!ownSchema || !ancestorSchema) continue;
461
+
462
+ const { compatible, issues } =
463
+ direction === "outputType"
464
+ ? checkSchemaCompatibility(ownSchema, ancestorSchema)
465
+ : checkSchemaCompatibility(ancestorSchema, ownSchema);
466
+ if (compatible) continue;
467
+
468
+ const ancestorName = `${(ancestor.metadata as { module?: string } | undefined)?.module ?? ""}.${
469
+ ancestor.metadata?.name ?? "?"
470
+ }`.replace(/^\./, "");
471
+ const why =
472
+ direction === "outputType"
473
+ ? `every caller that holds this through '${ancestorName}' reads the shape that kind declares`
474
+ : `a caller that holds this through '${ancestorName}' sends the shape that kind declares`;
475
+ diagnostics.push({
476
+ severity: DiagnosticSeverity.Error,
477
+ code: "CONTRACT_NOT_SUBSTITUTABLE",
478
+ source: SOURCE,
479
+ message:
480
+ `${m.kind}/${resource.name}: \`${direction}\` replaces the one declared by '${ancestorName}' ` +
481
+ `with a shape that cannot stand in for it — ${issues.join("; ")}. Contracts replace rather ` +
482
+ `than merge, so nothing re-checks this at dispatch: ${why}. Restate the fields ` +
483
+ `'${ancestorName}' declares, or drop \`${direction}\` to inherit the contract unchanged.`,
484
+ data: { resource, filePath, path: direction },
485
+ });
486
+ }
487
+ }
488
+
363
489
  /** A child that inherits its controller and REPLACES a contract must bridge it:
364
490
  * contracts resolve to the nearest declaration and never merge, so the
365
491
  * inherited controller only understands its own shape. Without the mapping the
@@ -3,6 +3,7 @@ import type { AliasResolver } from "./alias-resolver.js";
3
3
  import type { DefinitionRegistry } from "./definition-registry.js";
4
4
  import { parseRedactionPath, RedactionPathError } from "./redaction-path.js";
5
5
  import { DiagnosticSeverity, type AnalysisDiagnostic } from "./types.js";
6
+ import { moduleAliasScope } from "./module-alias-scope.js";
6
7
 
7
8
  const SOURCE = "telo-analyzer";
8
9
 
@@ -124,9 +125,7 @@ function isSinkKind(
124
125
  ): boolean {
125
126
  if (typeof manifest.kind !== "string") return false;
126
127
  if (manifest.kind === "Telo.ConsoleSink" || manifest.kind === "Telo.FileSink") return true;
127
- const ownModule = (manifest.metadata as { module?: string } | undefined)?.module;
128
- const resolver =
129
- (ownModule ? aliasesByModule?.get(ownModule) : undefined) ?? aliases;
128
+ const resolver = moduleAliasScope(manifest.metadata, aliases, aliasesByModule);
130
129
  const canonical = resolver.resolveKind(manifest.kind) ?? manifest.kind;
131
130
  return registry.resolve(canonical)?.capability === "Telo.Sink";
132
131
  }
@@ -38,7 +38,9 @@ export interface RefSlotIssue {
38
38
  | "X_TELO_REF_MISSING_USE"
39
39
  | "X_TELO_REF_MISSING_KIND"
40
40
  | "X_TELO_REF_USE_CONFLICT"
41
- | "X_TELO_REF_DYNAMIC_SELECTOR";
41
+ | "X_TELO_REF_DYNAMIC_SELECTOR"
42
+ | "X_TELO_REF_UNKNOWN_KEY"
43
+ | "X_TELO_REF_INVALID_THROWS_THROUGH";
42
44
  /** The definition (schema issues) or resource (selector issues) at fault. */
43
45
  manifest: ResourceManifest;
44
46
  /** Schema path of the slot (schema issues) or concrete value path of the
@@ -140,9 +142,47 @@ function checkAnnotation(
140
142
  }
141
143
  }
142
144
 
145
+ // `throwsThrough` is read as `=== true`, so anything else is silently absent —
146
+ // and absent means the declaring resource's catch scope stops enclosing what
147
+ // it holds, so every route under it starts reporting UNCOVERED_THROW_CODE with
148
+ // nothing naming the cause. The same failure `X_TELO_REF_INVALID_USE` exists
149
+ // to prevent, one key over.
150
+ if (obj.throwsThrough !== undefined && typeof obj.throwsThrough !== "boolean") {
151
+ issues.push({
152
+ code: "X_TELO_REF_INVALID_THROWS_THROUGH",
153
+ manifest,
154
+ path,
155
+ message:
156
+ `x-telo-ref at '${path}' declares 'throwsThrough: ${JSON.stringify(obj.throwsThrough)}', ` +
157
+ `which is not a boolean. Only 'true' declares that throws from this slot's target ` +
158
+ `surface through the declaring resource; anything else reads as absent, which ` +
159
+ `silently stops its catch list from enclosing what it holds.`,
160
+ });
161
+ }
162
+
163
+ // Closed, for the reason the token sets are: a misspelled key is indexed by
164
+ // nothing and read by nothing, so it validates, ships, and does exactly what
165
+ // omitting it would.
166
+ for (const key of Object.keys(obj)) {
167
+ if (REF_ANNOTATION_KEYS.has(key)) continue;
168
+ issues.push({
169
+ code: "X_TELO_REF_UNKNOWN_KEY",
170
+ manifest,
171
+ path,
172
+ message:
173
+ `x-telo-ref at '${path}' declares unrecognized key '${key}'. Known keys: ` +
174
+ `${[...REF_ANNOTATION_KEYS].sort().join(", ")}. An unrecognized key is read by nothing, ` +
175
+ `so it has exactly the effect of leaving it out.`,
176
+ });
177
+ }
178
+
143
179
  return declaredUses(use);
144
180
  }
145
181
 
182
+ /** Every key the structured `x-telo-ref` form accepts — the write side of
183
+ * `readRefSlot`'s read side. Adding one belongs in both. */
184
+ const REF_ANNOTATION_KEYS = new Set(["kind", "use", "inputs", "throwsThrough"]);
185
+
146
186
  /** True when a node is a reference slot: it carries `x-telo-ref` directly or on
147
187
  * an `anyOf`/`oneOf` branch. */
148
188
  function carriesRefAnnotation(obj: Record<string, unknown>): boolean {
@@ -14,6 +14,8 @@ import { resolveTypeFieldToSchema } from "./validate-cel-context.js";
14
14
  import { DiagnosticSeverity, type AnalysisDiagnostic, type AnalysisContext } from "./types.js";
15
15
  import type { AliasResolver } from "./alias-resolver.js";
16
16
  import type { DefinitionRegistry } from "./definition-registry.js";
17
+ import { moduleAliasScope } from "./module-alias-scope.js";
18
+ import { isInjectedDeclaration } from "./resource-input.js";
17
19
 
18
20
  const SOURCE = "telo-analyzer";
19
21
 
@@ -27,20 +29,31 @@ const SOURCE = "telo-analyzer";
27
29
  *
28
30
  * A value satisfies the slot when it transitively extends the target kind, or —
29
31
  * for a CONCRETE target — IS that kind; `getByExtends` is the same transitive
30
- * subtype index for both, and an abstract is satisfied only by an implementer,
31
- * never by the abstract itself (which is non-instantiable). Accepts a constraint
32
- * that resolves to nothing, and an abstract with no loaded implementations:
33
- * partial context, where a rejection would be a guess.
32
+ * subtype index for both. Accepts a constraint that resolves to nothing, and an
33
+ * abstract with no loaded implementations: partial context, where a rejection
34
+ * would be a guess.
35
+ *
36
+ * An abstract is satisfied only by an implementer, never by the abstract itself,
37
+ * because a resource declared `kind: <some abstract>` is refused at `create()`
38
+ * and reported as `ABSTRACT_KIND_INSTANTIATED` at its declaration — so accepting
39
+ * it here would leave the reference sites silent about a manifest that cannot
40
+ * run. `isDeclaration` is the ONE exception and it is not an instance: a
41
+ * library's `resources:` entry is constrained by kind alone, so its kind-only
42
+ * stand-in routinely IS an abstract (`connection: {kind: Sql.Connection}`), and
43
+ * every use of that name inside the library is a reference to it.
34
44
  */
35
45
  export function kindSatisfies(
36
46
  resolved: string,
37
47
  targetKind: string,
38
48
  registry: DefinitionRegistry,
49
+ /** The referent is a kind-only stand-in for a `resources:` entry rather than a
50
+ * resource anything instantiates, so identity satisfies an abstract slot. */
51
+ isDeclaration = false,
39
52
  ): boolean {
40
53
  const canonical = registry.resolveRef(targetKind) ?? targetKind;
41
54
  const targetDef = registry.resolve(canonical);
42
55
  if (!targetDef) return true;
43
- if (targetDef.kind !== "Telo.Abstract" && resolved === canonical) return true;
56
+ if ((targetDef.kind !== "Telo.Abstract" || isDeclaration) && resolved === canonical) return true;
44
57
  const subtypes = registry.getByExtends(canonical);
45
58
  if (subtypes.some((d) => `${d.metadata.module}.${d.metadata.name}` === resolved)) return true;
46
59
  // Leniency is about the CANDIDATE, not about the population, and it is the
@@ -70,6 +83,8 @@ function checkKind(
70
83
  entry: RefFieldEntry,
71
84
  registry: DefinitionRegistry,
72
85
  aliases: AliasResolver,
86
+ /** See {@link kindSatisfies}: the referent is a `resources:` stand-in. */
87
+ isDeclaration = false,
73
88
  ): string[] {
74
89
  const resolved = aliases.resolveKind(kind) ?? kind;
75
90
  // A qualified kind whose prefix names no import in this scope is a bad NAME
@@ -92,7 +107,7 @@ function checkKind(
92
107
  if (!targetKind) return [];
93
108
  const targetDef = registry.resolve(targetKind);
94
109
  if (!targetDef) return [];
95
- if (!unknownAlias && kindSatisfies(resolved, targetKind, registry)) return [];
110
+ if (!unknownAlias && kindSatisfies(resolved, targetKind, registry, isDeclaration)) return [];
96
111
  const subtypes = registry.getByExtends(targetKind);
97
112
  const subtypeKinds = new Set(subtypes.map((d) => `${d.metadata.module}.${d.metadata.name}`));
98
113
  if (targetDef.kind === "Telo.Abstract") {
@@ -335,7 +350,13 @@ export function validateReferences(
335
350
  });
336
351
  return;
337
352
  }
338
- const kindErrors = checkKind(target.kind as string, entry, registry, aliases);
353
+ const kindErrors = checkKind(
354
+ target.kind as string,
355
+ entry,
356
+ registry,
357
+ aliases,
358
+ isInjectedDeclaration(target),
359
+ );
339
360
  if (kindErrors.length > 0) {
340
361
  diagnostics.push({
341
362
  severity: DiagnosticSeverity.Error,
@@ -385,7 +406,18 @@ export function validateReferences(
385
406
  }
386
407
 
387
408
  // 2. Kind check
388
- const kindErrors = checkKind(refVal.kind, entry, registry, aliases);
409
+ const objectTarget =
410
+ typeof refVal.name === "string"
411
+ ? (visibleScopeManifests.find((m) => m.metadata?.name === refVal.name) ??
412
+ byName.get(refVal.name))
413
+ : undefined;
414
+ const kindErrors = checkKind(
415
+ refVal.kind,
416
+ entry,
417
+ registry,
418
+ aliases,
419
+ isInjectedDeclaration(objectTarget),
420
+ );
389
421
  if (kindErrors.length > 0) {
390
422
  diagnostics.push({
391
423
  severity: DiagnosticSeverity.Error,
@@ -484,9 +516,7 @@ export function validateReferences(
484
516
  const resolvedResourceKind = aliases.resolveKind(r.kind) ?? r.kind;
485
517
  const resourceDef =
486
518
  registry.resolve(r.kind) ?? registry.resolve(resolvedResourceKind);
487
- const owningModule = (resourceDef?.metadata as { module?: string } | undefined)?.module;
488
- const ownerScope =
489
- (owningModule ? aliasesByModule?.get(owningModule) : undefined) ?? aliases;
519
+ const ownerScope = moduleAliasScope(resourceDef?.metadata, aliases, aliasesByModule);
490
520
 
491
521
  const targetKind = ownerScope.resolveKind(anchorName);
492
522
  if (!targetKind) {
@@ -532,14 +562,44 @@ export function validateReferences(
532
562
 
533
563
  for (const { value: fieldValue, path: concretePath } of resolveFieldEntries(r, fieldPath)) {
534
564
  if (fieldValue == null) continue;
535
- const issues = registry.validateWithRefs(fieldValue, subSchema as Record<string, any>);
565
+ // CEL leaves become schema-shaped placeholders first, exactly as the
566
+ // sibling-ref branch below does and for the same reason: a slot
567
+ // anchored at a shared value-shape is overwhelmingly written as
568
+ // expressions, so validating it raw reports every one of them as a
569
+ // type error and the check fires only on the literal case nobody
570
+ // writes. Omitting it here made one annotation mean two different
571
+ // things depending on which branch resolved it — a `when:` typed
572
+ // `boolean` accepted a `!cel` at a route's inline slot and rejected
573
+ // the identical expression at a slot anchored on the carrier that
574
+ // declares that very shape.
575
+ const substituted = substituteCelFields(
576
+ fieldValue,
577
+ subSchema as Record<string, any>,
578
+ );
579
+ // Anchored at the offending node INSIDE the value, not at the slot:
580
+ // a `returns:` list is an array of entries, and reporting every one
581
+ // of its issues on the `returns:` line puts three diagnostics on one
582
+ // line and none on the entry that is wrong.
583
+ const issues = registry.validateResourceConfig(
584
+ substituted,
585
+ subSchema as Record<string, any>,
586
+ );
536
587
  for (const issue of issues) {
537
588
  diagnostics.push({
538
589
  severity: DiagnosticSeverity.Error,
539
590
  code: "DEPENDENT_SCHEMA_MISMATCH",
540
591
  source: SOURCE,
541
- message: `${resourceLabel}: '${concretePath}' does not match schema from '${anchorName}${jsonPointer}': ${issue}`,
542
- data: { resource: resourceData, filePath, path: concretePath },
592
+ message: `${resourceLabel}: '${concretePath}' does not match schema from '${anchorName}${jsonPointer}': ${issue.message}`,
593
+ data: {
594
+ resource: resourceData,
595
+ filePath,
596
+ // An index-first sub-path (`[0].content`) joins with no dot.
597
+ path: !issue.path
598
+ ? concretePath
599
+ : issue.path.startsWith("[")
600
+ ? `${concretePath}${issue.path}`
601
+ : `${concretePath}.${issue.path}`,
602
+ },
543
603
  });
544
604
  }
545
605
  }
@@ -3,7 +3,11 @@ import { isRefSentinel } from "@telorun/templating";
3
3
  import type { AliasResolver } from "./alias-resolver.js";
4
4
  import type { DefinitionRegistry } from "./definition-registry.js";
5
5
  import { findDynamicLeaf } from "./resource-rule.js";
6
- import { readResourceInputs, readSuppliedResources } from "./resource-input.js";
6
+ import {
7
+ isInjectedDeclaration,
8
+ readResourceInputs,
9
+ readSuppliedResources,
10
+ } from "./resource-input.js";
7
11
  import { type AnalysisDiagnostic, DiagnosticSeverity } from "./types.js";
8
12
 
9
13
  const SOURCE = "telo-analyzer";
@@ -38,6 +42,9 @@ type RequiredResources = Record<string, string>;
38
42
  *
39
43
  * Browser-safe.
40
44
  */
45
+ const declaringModule = (m: ResourceManifest): string | undefined =>
46
+ (m.metadata as { module?: string } | undefined)?.module;
47
+
41
48
  export function validateResourceInputs(
42
49
  manifests: ResourceManifest[],
43
50
  registry: DefinitionRegistry,
@@ -46,7 +53,11 @@ export function validateResourceInputs(
46
53
  /** Kind acceptance, transitively — the `checkKind` rule `validate-references`
47
54
  * applies at an ordinary ref slot, passed in rather than re-derived so the
48
55
  * two cannot disagree about what satisfies a constraint. */
49
- acceptsKind: (suppliedKind: string, requiredKind: string) => boolean,
56
+ acceptsKind: (
57
+ suppliedKind: string,
58
+ requiredKind: string,
59
+ suppliedIsDeclaration: boolean,
60
+ ) => boolean,
50
61
  ): AnalysisDiagnostic[] {
51
62
  const out: AnalysisDiagnostic[] = [];
52
63
 
@@ -220,7 +231,19 @@ export function validateResourceInputs(
220
231
  const suppliedKind = (value as { kind?: unknown }).kind;
221
232
  if (typeof suppliedKind !== "string") continue;
222
233
  const canonical = aliases.resolveKind(suppliedKind) ?? suppliedKind;
223
- if (acceptsKind(canonical, entry)) continue;
234
+ // A library forwarding an input it was itself handed supplies a kind-only
235
+ // stand-in, whose kind is routinely the abstract the target declares. That
236
+ // is identity against an abstract, which an ordinary reference is refused
237
+ // — the referent there would be a resource nothing can instantiate, while
238
+ // here it is another declaration.
239
+ const suppliedName = (value as { name?: unknown }).name;
240
+ const supplied =
241
+ typeof suppliedName === "string"
242
+ ? manifests.find(
243
+ (c) => c.metadata?.name === suppliedName && isOwn(declaringModule(c)),
244
+ )
245
+ : undefined;
246
+ if (acceptsKind(canonical, entry, isInjectedDeclaration(supplied))) continue;
224
247
  out.push({
225
248
  severity: DiagnosticSeverity.Error,
226
249
  code: "RESOURCE_INPUT_KIND_MISMATCH",
@@ -3,6 +3,7 @@ import { canonicalTypeSchemaId, parseTeloTypeRef } from "@telorun/sdk";
3
3
  import type { AliasResolver } from "./alias-resolver.js";
4
4
  import type { DefinitionRegistry } from "./definition-registry.js";
5
5
  import { DiagnosticSeverity, type AnalysisDiagnostic } from "./types.js";
6
+ import { moduleAliasScope } from "./module-alias-scope.js";
6
7
 
7
8
  const SOURCE = "telo-analyzer";
8
9
  const SCHEMA_FIELDS = ["schema", "inputType", "outputType"] as const;
@@ -38,7 +39,7 @@ export function validateSchemaTypeRefs(
38
39
  // Only validate refs authored in a root module's scope; imported defs are
39
40
  // validated against their own library when it's analyzed as a root.
40
41
  if (ownModule && !rootModules.has(ownModule)) continue;
41
- const resolver = (ownModule ? aliasesByModule.get(ownModule) : undefined) ?? aliases;
42
+ const resolver = moduleAliasScope(m.metadata, aliases, aliasesByModule);
42
43
  const filePath = (m.metadata as { source?: string } | undefined)?.source;
43
44
  const label = `${m.kind}/${name}`;
44
45