@telorun/analyzer 0.64.0 → 0.65.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.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The one renderer for AJV validation failures.
3
+ *
4
+ * Browser-safe and re-imported by the kernel — the split `buildEvalPaths` and
5
+ * the redaction path parser already use — so a failure is phrased identically
6
+ * under `telo check` and at runtime. Three implementations used to answer this
7
+ * (the analyzer's keyword prose, the kernel's raw `instancePath + message`
8
+ * join, and observed state's own inline variant), so a developer who fixed what
9
+ * the analyzer told them met a different sentence describing the same thing.
10
+ *
11
+ * UNION REDUCTION is the second half. A union must attempt every branch, and
12
+ * AJV cannot know which one was intended — `discriminator: true` works only
13
+ * against an explicit OpenAPI-style discriminator property, which would mean
14
+ * changing what every module's authors write. So branch selection is a
15
+ * reporting concern and lives here.
16
+ *
17
+ * It narrows the error SET, never just the sentence: every consumer maps the
18
+ * surviving errors to manifest paths to anchor a diagnostic, so reducing at the
19
+ * prose layer alone would move the soup out of the message and into the
20
+ * problems list, one entry per branch on a different line.
21
+ *
22
+ * Selection is made from the ERRORS ALONE, never from the schema. A branch
23
+ * whose discriminating key is present emits no complaint at the union's own
24
+ * instancePath; one whose key is absent says `required`, and one that forbids a
25
+ * key the value carries says `additionalProperties`. That is the whole signal,
26
+ * and reading it off the errors is what lets reduction work across a `$ref`
27
+ * into another registered schema, where navigating to the branch subschema
28
+ * would mean re-implementing AJV's resolution.
29
+ */
30
+ /** An AJV error object. Structurally typed — the analyzer and the kernel hand
31
+ * over errors from their own AJV instances. */
32
+ export interface AjvErrorLike {
33
+ keyword?: string;
34
+ instancePath?: string;
35
+ schemaPath?: string;
36
+ message?: string;
37
+ params?: Record<string, any>;
38
+ data?: unknown;
39
+ }
40
+ /** A schema validation issue with a dotted-path pointer to the offending field. */
41
+ export interface SchemaIssue {
42
+ message: string;
43
+ /** Dotted path to the field (e.g. "config.handler"). Empty string means root. */
44
+ path: string;
45
+ }
46
+ export declare function formatSingleError(err: AjvErrorLike): string;
47
+ /**
48
+ * Replace each failing union with the errors of the branch the author plainly
49
+ * meant, recursively, outside in.
50
+ *
51
+ * Attribution runs to the DEEPEST occurrence that could own an error, which is
52
+ * what keeps a container's own complaint apart from its child's when both carry
53
+ * the same `schemaPath`. An occurrence reached through a branch becomes a
54
+ * candidate branch of its own — it raised nothing at the parent's node, so it is
55
+ * plausible exactly when the value really did take that shape and fail further
56
+ * in, and reducing it recursively is what stops an inner union's alternatives
57
+ * from surviving inside the outer one's selection.
58
+ */
59
+ export declare function reduceSchemaErrors(errors: AjvErrorLike[] | null | undefined): AjvErrorLike[];
60
+ /** Converts an AJV error to a dotted path compatible with PositionIndex keys.
61
+ * e.g. instancePath "/config/routes/0/handler" → "config.routes[0].handler"
62
+ * For "required" keyword errors, appends the missing property to the parent path. */
63
+ export declare function ajvErrorToPath(err: AjvErrorLike): string;
64
+ /** Reduced, path-anchored issues — what a diagnostic list is built from. */
65
+ export declare function schemaIssues(errors: AjvErrorLike[] | null | undefined): SchemaIssue[];
66
+ /** Reduced, rendered as one sentence — what a thrown runtime error carries. */
67
+ export declare function formatAjvErrors(errors: AjvErrorLike[] | null | undefined): string;
68
+ //# sourceMappingURL=schema-error-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-error-report.d.ts","sourceRoot":"","sources":["../src/schema-error-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;gDACgD;AAChD,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;CACd;AAWD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAe3D;AAkGD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,EAAE,CAsF5F;AAqHD;;sFAEsF;AACtF,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAaxD;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,EAAE,CAKrF;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIjF"}
@@ -0,0 +1,356 @@
1
+ /**
2
+ * The one renderer for AJV validation failures.
3
+ *
4
+ * Browser-safe and re-imported by the kernel — the split `buildEvalPaths` and
5
+ * the redaction path parser already use — so a failure is phrased identically
6
+ * under `telo check` and at runtime. Three implementations used to answer this
7
+ * (the analyzer's keyword prose, the kernel's raw `instancePath + message`
8
+ * join, and observed state's own inline variant), so a developer who fixed what
9
+ * the analyzer told them met a different sentence describing the same thing.
10
+ *
11
+ * UNION REDUCTION is the second half. A union must attempt every branch, and
12
+ * AJV cannot know which one was intended — `discriminator: true` works only
13
+ * against an explicit OpenAPI-style discriminator property, which would mean
14
+ * changing what every module's authors write. So branch selection is a
15
+ * reporting concern and lives here.
16
+ *
17
+ * It narrows the error SET, never just the sentence: every consumer maps the
18
+ * surviving errors to manifest paths to anchor a diagnostic, so reducing at the
19
+ * prose layer alone would move the soup out of the message and into the
20
+ * problems list, one entry per branch on a different line.
21
+ *
22
+ * Selection is made from the ERRORS ALONE, never from the schema. A branch
23
+ * whose discriminating key is present emits no complaint at the union's own
24
+ * instancePath; one whose key is absent says `required`, and one that forbids a
25
+ * key the value carries says `additionalProperties`. That is the whole signal,
26
+ * and reading it off the errors is what lets reduction work across a `$ref`
27
+ * into another registered schema, where navigating to the branch subschema
28
+ * would mean re-implementing AJV's resolution.
29
+ */
30
+ const UNION_KEYWORDS = new Set(["anyOf", "oneOf"]);
31
+ /** Keywords a branch raises at the union's OWN instancePath when the value is
32
+ * not of that branch's shape at all — as opposed to being that shape and wrong
33
+ * further in. These are what make a branch implausible. */
34
+ const SHAPE_KEYWORDS = new Set(["required", "type", "additionalProperties", "enum", "const"]);
35
+ /* ------------------------------------------------------------------ prose */
36
+ export function formatSingleError(err) {
37
+ const p = err.instancePath || "/";
38
+ const params = err.params ?? {};
39
+ switch (err.keyword) {
40
+ case "additionalProperties":
41
+ return `${p} must NOT have additional properties ('${params.additionalProperty}' is not allowed)`;
42
+ case "required":
43
+ return `${p} is missing required property '${params.missingProperty}'`;
44
+ case "enum":
45
+ return `${p} ${err.message ?? "is invalid"} (${params.allowedValues?.join(" | ")})`;
46
+ case "type":
47
+ return `${p} must be ${params.type}${describeActual(err)}`;
48
+ default:
49
+ return `${p} ${err.message ?? "is invalid"}`;
50
+ }
51
+ }
52
+ /** ` (got string)`, or nothing when the value is not in hand. AJV carries
53
+ * `data` only under `verbose`, and a reducer that navigated the root value
54
+ * would have to be given it at every call site; an absent actual type is worth
55
+ * less than a wrong one. */
56
+ function describeActual(err) {
57
+ if (!("data" in err))
58
+ return "";
59
+ const d = err.data;
60
+ if (d === null)
61
+ return " (got null)";
62
+ if (Array.isArray(d))
63
+ return " (got array)";
64
+ return ` (got ${typeof d})`;
65
+ }
66
+ /* -------------------------------------------------------------- reduction */
67
+ /** The branch index a `schemaPath` sits under, for a union whose own schemaPath
68
+ * is `unionPath` (`…/anyOf`): a child is `…/anyOf/<i>/…` and nothing else can
69
+ * collide with it. */
70
+ function branchIndexUnder(unionPath, schemaPath) {
71
+ if (!schemaPath || !schemaPath.startsWith(unionPath + "/"))
72
+ return undefined;
73
+ const rest = schemaPath.slice(unionPath.length + 1);
74
+ const slash = rest.indexOf("/");
75
+ const head = slash === -1 ? rest : rest.slice(0, slash);
76
+ const index = Number(head);
77
+ return Number.isInteger(index) ? index : undefined;
78
+ }
79
+ function instanceDepth(path) {
80
+ if (!path)
81
+ return 0;
82
+ return path.split("/").filter((s) => s !== "").length;
83
+ }
84
+ /**
85
+ * How the alternatives at a union node are described, one phrase each.
86
+ *
87
+ * Read off the complaints made at the union's own node, and deliberately ONE
88
+ * PHRASE PER MISSING KEY rather than one per error group. AJV inlines most
89
+ * `$ref` branches and reports them all under the same bare `schemaPath`, so
90
+ * several branches are genuinely indistinguishable in the error set — joining
91
+ * their keys into a single phrase would read as one alternative demanding all
92
+ * of them, which is a claim about the schema that is simply false. Listing them
93
+ * separately under-specifies a branch that requires two keys at once, and each
94
+ * clause is still a true necessary condition; asserting a conjunction that does
95
+ * not exist is not.
96
+ */
97
+ function describeAlternatives(errors, unionInstancePath) {
98
+ const own = errors.filter((e) => (e.instancePath || "") === unionInstancePath);
99
+ const phrases = [];
100
+ for (const e of own) {
101
+ if (e.keyword === "required")
102
+ phrases.push(`one with '${e.params?.missingProperty}'`);
103
+ else if (e.keyword === "type")
104
+ phrases.push(`a ${e.params?.type}`);
105
+ else if (e.keyword === "enum") {
106
+ phrases.push(`one of ${e.params?.allowedValues?.join(" | ")}`);
107
+ }
108
+ }
109
+ return phrases.length > 0 ? phrases : ["another shape"];
110
+ }
111
+ /** Is this branch a plausible reading of the value — does it accept the value's
112
+ * shape at the union node itself, and only disagree further in? */
113
+ function isPlausible(errors, unionInstancePath) {
114
+ return !errors.some((e) => (e.instancePath || "") === unionInstancePath && SHAPE_KEYWORDS.has(e.keyword ?? ""));
115
+ }
116
+ function isUnder(child, parent) {
117
+ return parent === "" ? child !== "" : child.startsWith(parent + "/");
118
+ }
119
+ /** The value path one level up, or undefined at the root. `""` is the root, so
120
+ * a non-empty path with no separator has the root as its parent. */
121
+ function parentPath(path) {
122
+ if (path === "")
123
+ return undefined;
124
+ const cut = path.lastIndexOf("/");
125
+ return cut <= 0 ? "" : path.slice(0, cut);
126
+ }
127
+ /**
128
+ * Replace each failing union with the errors of the branch the author plainly
129
+ * meant, recursively, outside in.
130
+ *
131
+ * Attribution runs to the DEEPEST occurrence that could own an error, which is
132
+ * what keeps a container's own complaint apart from its child's when both carry
133
+ * the same `schemaPath`. An occurrence reached through a branch becomes a
134
+ * candidate branch of its own — it raised nothing at the parent's node, so it is
135
+ * plausible exactly when the value really did take that shape and fail further
136
+ * in, and reducing it recursively is what stops an inner union's alternatives
137
+ * from surviving inside the outer one's selection.
138
+ */
139
+ export function reduceSchemaErrors(errors) {
140
+ if (!errors || errors.length === 0)
141
+ return [];
142
+ const occurrences = errors
143
+ .filter((e) => UNION_KEYWORDS.has(e.keyword ?? "") && typeof e.schemaPath === "string")
144
+ .map((e) => ({
145
+ error: e,
146
+ schemaPath: e.schemaPath,
147
+ instancePath: e.instancePath || "",
148
+ owned: [],
149
+ children: [],
150
+ }));
151
+ if (occurrences.length === 0)
152
+ return errors;
153
+ // The VALUE NODE is the claim, not the schemaPath. A branch written as a
154
+ // `$ref` is reported by AJV under the TARGET's schemaPath — and AJV inlines
155
+ // some of them, reporting several branches under one identical path — so
156
+ // nothing in such an error points back at the union that dispatched to it. A
157
+ // large union is written exactly that way, a branch per `$defs` entry, so
158
+ // claiming by schemaPath alone would leave the biggest unions unreduced.
159
+ //
160
+ // Indexed by instancePath rather than scanned: an error is claimed by the
161
+ // DEEPEST occurrence enclosing it, which is found by walking that error's own
162
+ // path upwards — bounded by the path's depth instead of by the number of
163
+ // unions. The scan this replaced was O(errors × occurrences), and both grow
164
+ // with nesting depth on a recursive shape, on a path the editor runs per
165
+ // keystroke.
166
+ const byPath = new Map();
167
+ const isOccurrence = new Set();
168
+ for (const o of occurrences) {
169
+ isOccurrence.add(o.error);
170
+ // Several unions can occur at ONE value node (a union inside a union
171
+ // branch); the first is kept, and the rest nest under it below.
172
+ if (!byPath.has(o.instancePath))
173
+ byPath.set(o.instancePath, o);
174
+ }
175
+ /** The nearest occurrence at or above `path`, excluding `path` itself when
176
+ * `strict` — which is how an occurrence finds its parent rather than itself. */
177
+ const enclosing = (path, strict) => {
178
+ let current = strict ? parentPath(path) : path;
179
+ while (current !== undefined) {
180
+ const hit = byPath.get(current);
181
+ if (hit)
182
+ return hit;
183
+ current = parentPath(current);
184
+ }
185
+ return undefined;
186
+ };
187
+ const owner = new Map();
188
+ for (const err of errors) {
189
+ if (isOccurrence.has(err))
190
+ continue;
191
+ const best = enclosing(err.instancePath || "", false);
192
+ if (best) {
193
+ best.owned.push(err);
194
+ owner.set(err, best);
195
+ }
196
+ }
197
+ // Nest occurrences the same way: an occurrence deeper in the value was reached
198
+ // through some branch of the nearest one enclosing it.
199
+ const roots = [];
200
+ for (const o of occurrences) {
201
+ const parent = o === byPath.get(o.instancePath)
202
+ ? enclosing(o.instancePath, true)
203
+ : byPath.get(o.instancePath);
204
+ if (parent && parent !== o)
205
+ parent.children.push(o);
206
+ else
207
+ roots.push(o);
208
+ }
209
+ const replaced = new Map();
210
+ for (const root of roots)
211
+ replaced.set(root.error, resolveOccurrence(root));
212
+ const out = [];
213
+ for (const err of errors) {
214
+ const replacement = replaced.get(err);
215
+ if (replacement) {
216
+ out.push(...replacement);
217
+ continue;
218
+ }
219
+ // Everything an occurrence owns is spoken for by whichever branch survived,
220
+ // and a nested occurrence is carried inside its parent's selection.
221
+ if (owner.has(err))
222
+ continue;
223
+ if (occurrences.some((o) => o.error === err))
224
+ continue;
225
+ out.push(err);
226
+ }
227
+ return out;
228
+ }
229
+ /** Groups one union's complaints into candidate readings of the value.
230
+ *
231
+ * The branch INDEX is used wherever the error carries it. It does not when the
232
+ * branch is a `$ref` — AJV reports under the target's schemaPath — so the
233
+ * fallback groups by the VALUE NODE each complaint is about: everything said
234
+ * about the union node itself is one candidate (those are the branches that
235
+ * rejected the value's shape outright), and each child node complained about is
236
+ * its own. That is the same question asked of the data instead of the schema,
237
+ * and it is what the ordering below actually reads. */
238
+ function groupCandidates(occurrence) {
239
+ const byIndex = new Map();
240
+ const byNode = new Map();
241
+ for (const err of occurrence.owned) {
242
+ const index = branchIndexUnder(occurrence.schemaPath, err.schemaPath);
243
+ const bucket = index === undefined
244
+ ? mapBucket(byNode, childSegment(err.instancePath || "", occurrence.instancePath))
245
+ : mapBucket(byIndex, index);
246
+ bucket.push(err);
247
+ }
248
+ return [...byIndex]
249
+ .map(([index, errs]) => ({ index, errors: errs, nested: false }))
250
+ .concat([...byNode].map(([, errs]) => ({ index: Number.MAX_SAFE_INTEGER, errors: errs, nested: false })))
251
+ .concat(occurrence.children.map((child) => ({
252
+ index: Number.POSITIVE_INFINITY,
253
+ errors: resolveOccurrence(child),
254
+ nested: true,
255
+ })));
256
+ }
257
+ function mapBucket(map, key) {
258
+ const existing = map.get(key);
259
+ if (existing)
260
+ return existing;
261
+ const created = [];
262
+ map.set(key, created);
263
+ return created;
264
+ }
265
+ /** The first value-path segment below `parent`, or "" for the node itself. */
266
+ function childSegment(instancePath, parent) {
267
+ if (!isUnder(instancePath, parent))
268
+ return "";
269
+ const rest = instancePath.slice(parent.length + 1);
270
+ const slash = rest.indexOf("/");
271
+ return slash === -1 ? rest : rest.slice(0, slash);
272
+ }
273
+ function resolveOccurrence(occurrence) {
274
+ const candidates = groupCandidates(occurrence);
275
+ // `oneOf` matching SEVERAL branches emits the union error with no branch
276
+ // errors at all — nothing was rejected, so there is no branch to select.
277
+ if (candidates.length === 0)
278
+ return [occurrence.error];
279
+ const plausible = candidates.filter((c) => c.nested || isPlausible(c.errors, occurrence.instancePath));
280
+ if (plausible.length === 0) {
281
+ return [alternativesError(candidates, occurrence)];
282
+ }
283
+ // Deepest agreement first — a branch that matched further into the value is
284
+ // the one the author was writing — then the fewest complaints, then the
285
+ // declaration order, so the choice is stable.
286
+ plausible.sort((a, b) => {
287
+ const depth = maxDepth(b.errors) - maxDepth(a.errors);
288
+ if (depth !== 0)
289
+ return depth;
290
+ if (a.errors.length !== b.errors.length)
291
+ return a.errors.length - b.errors.length;
292
+ return a.index - b.index;
293
+ });
294
+ const winner = plausible[0];
295
+ return winner.nested ? winner.errors : reduceSchemaErrors(winner.errors);
296
+ }
297
+ function maxDepth(errors) {
298
+ let max = 0;
299
+ for (const e of errors)
300
+ max = Math.max(max, instanceDepth(e.instancePath));
301
+ return max;
302
+ }
303
+ /** One error anchored at the union node, listing what could have gone there.
304
+ * The honest fallback: a confident wrong message is worse than the
305
+ * concatenation this replaces, so when no branch is a plausible reading the
306
+ * reader is told what the alternatives are rather than shown one branch's
307
+ * complaints as if it were the intended one. */
308
+ function alternativesError(candidates, occurrence) {
309
+ const seen = new Set();
310
+ const described = [];
311
+ for (const text of describeAlternatives(candidates.flatMap((c) => c.errors), occurrence.instancePath)) {
312
+ if (seen.has(text))
313
+ continue;
314
+ seen.add(text);
315
+ described.push(text);
316
+ }
317
+ return {
318
+ ...occurrence.error,
319
+ instancePath: occurrence.instancePath,
320
+ message: `matches no alternative — expected ${described.join(", or ")}`,
321
+ };
322
+ }
323
+ /* --------------------------------------------------------------- rendering */
324
+ /** Converts an AJV error to a dotted path compatible with PositionIndex keys.
325
+ * e.g. instancePath "/config/routes/0/handler" → "config.routes[0].handler"
326
+ * For "required" keyword errors, appends the missing property to the parent path. */
327
+ export function ajvErrorToPath(err) {
328
+ const instancePath = err.instancePath ?? "";
329
+ const parts = instancePath.split("/").filter((p) => p !== "");
330
+ let result = "";
331
+ for (const part of parts) {
332
+ if (/^\d+$/.test(part))
333
+ result += `[${part}]`;
334
+ else
335
+ result += result ? `.${part}` : part;
336
+ }
337
+ if (err.keyword === "required" && err.params?.missingProperty) {
338
+ const missing = err.params.missingProperty;
339
+ result += result ? `.${missing}` : missing;
340
+ }
341
+ return result;
342
+ }
343
+ /** Reduced, path-anchored issues — what a diagnostic list is built from. */
344
+ export function schemaIssues(errors) {
345
+ return reduceSchemaErrors(errors).map((err) => ({
346
+ message: formatSingleError(err),
347
+ path: ajvErrorToPath(err),
348
+ }));
349
+ }
350
+ /** Reduced, rendered as one sentence — what a thrown runtime error carries. */
351
+ export function formatAjvErrors(errors) {
352
+ const reduced = reduceSchemaErrors(errors);
353
+ if (reduced.length === 0)
354
+ return "Unknown schema error";
355
+ return reduced.map(formatSingleError).join("; ");
356
+ }
@@ -1,3 +1,3 @@
1
1
  /** The surface generation this analyzer implements. */
2
- export declare const TELO_SURFACE_VERSION = "0.80.0";
2
+ export declare const TELO_SURFACE_VERSION = "0.82.0";
3
3
  //# sourceMappingURL=telo-version.d.ts.map
@@ -5,4 +5,4 @@
5
5
  // its release identity, this is the scale a module's `requires.telo` range is
6
6
  // written against, and every kernel in every language reports the same scale.
7
7
  /** The surface generation this analyzer implements. */
8
- export const TELO_SURFACE_VERSION = "0.80.0";
8
+ export const TELO_SURFACE_VERSION = "0.82.0";
@@ -1,4 +1,6 @@
1
1
  import type { ResourceManifest } from "@telorun/sdk";
2
+ import type { ExternalSchemaResolver } from "./schema-compat.js";
3
+ import type { SchemaIssue } from "./schema-error-report.js";
2
4
  import { type AnalysisDiagnostic } from "./types.js";
3
5
  /** Minimal view of a definition needed to validate an inline resource's config. */
4
6
  export interface InlineDefinitionLookup {
@@ -6,6 +8,21 @@ export interface InlineDefinitionLookup {
6
8
  schema?: Record<string, any>;
7
9
  } | undefined;
8
10
  }
11
+ /**
12
+ * The validator this pass checks an inline resource's config with, and the
13
+ * resolver that lets both it and the stand-in walk see through a named shape.
14
+ *
15
+ * Passed in rather than reached for: the module-level AJV this used has no
16
+ * registered shapes, so a kind whose `schema:` references one compiled nowhere
17
+ * and every inline declaration of it was silently unchecked — while the
18
+ * identical resource written standalone was checked, and the kernel rejected
19
+ * both at boot. Two validators answering one question is what allowed that, so
20
+ * the caller supplies the one that holds the shapes.
21
+ */
22
+ export interface InlineConfigValidator {
23
+ validate(data: unknown, schema: Record<string, any>): SchemaIssue[];
24
+ external: ExternalSchemaResolver;
25
+ }
9
26
  /**
10
27
  * Validates inline resources nested inside a resource body against their kind's
11
28
  * config schema. The per-resource walk in `analyze()` validates a resource's
@@ -28,5 +45,9 @@ export interface InlineDefinitionLookup {
28
45
  */
29
46
  export declare function validateNestedInlineResources(manifest: ResourceManifest, rootSchema: Record<string, any>, lookupDefinition: InlineDefinitionLookup,
30
47
  /** Needed to resolve a `telo#Type` field a value slot is validated against. */
31
- allManifests?: Record<string, any>[]): AnalysisDiagnostic[];
48
+ allManifests: Record<string, any>[],
49
+ /** REQUIRED, and deliberately not defaulted: a default would be a second
50
+ * validator answering the same question, and omitting it would silently stop
51
+ * checking rather than fail. */
52
+ validator: InlineConfigValidator): AnalysisDiagnostic[];
32
53
  //# sourceMappingURL=validate-nested-inline.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-nested-inline.d.ts","sourceRoot":"","sources":["../src/validate-nested-inline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQrD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKzE,mFAAmF;AACnF,MAAM,WAAW,sBAAsB;IACrC,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,SAAS,CAAC;CAC9D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,gBAAgB,EAAE,sBAAsB;AACxC,+EAA+E;AAC/E,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAO,GACvC,kBAAkB,EAAE,CA6HtB"}
1
+ {"version":3,"file":"validate-nested-inline.d.ts","sourceRoot":"","sources":["../src/validate-nested-inline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKzE,mFAAmF;AACnF,MAAM,WAAW,sBAAsB;IACrC,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,SAAS,CAAC;CAC9D;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,WAAW,EAAE,CAAC;IACpE,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,gBAAgB,EAAE,sBAAsB;AACxC,+EAA+E;AAC/E,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;AACnC;;iCAEiC;AACjC,SAAS,EAAE,qBAAqB,GAC/B,kBAAkB,EAAE,CAiItB"}
@@ -1,5 +1,5 @@
1
1
  import { collectRefs, isInlineResource } from "./reference-field-map.js";
2
- import { collectProperties, resolveRef, substituteCelFields, validateAgainstSchema, } from "./schema-compat.js";
2
+ import { collectProperties, resolveRef, substituteCelFields } from "./schema-compat.js";
3
3
  import { DiagnosticSeverity } from "./types.js";
4
4
  import { collectValueSchemaIssues } from "./validate-value-schema.js";
5
5
  const SOURCE = "telo-analyzer";
@@ -25,7 +25,11 @@ const SOURCE = "telo-analyzer";
25
25
  */
26
26
  export function validateNestedInlineResources(manifest, rootSchema, lookupDefinition,
27
27
  /** Needed to resolve a `telo#Type` field a value slot is validated against. */
28
- allManifests = []) {
28
+ allManifests,
29
+ /** REQUIRED, and deliberately not defaulted: a default would be a second
30
+ * validator answering the same question, and omitting it would silently stop
31
+ * checking rather than fail. */
32
+ validator) {
29
33
  const diagnostics = [];
30
34
  const resource = { kind: manifest.kind, name: manifest.metadata?.name };
31
35
  const filePath = manifest.metadata?.source;
@@ -70,14 +74,18 @@ allManifests = []) {
70
74
  ? inline.metadata
71
75
  : {};
72
76
  const data = { ...inline, metadata: { name: "__inline__", ...existingMeta } };
73
- const substituted = substituteCelFields(data, effectiveSchema, effectiveSchema);
74
- // The same two passes the top-level resource loop runs, so a kind's
75
- // guarantees don't depend on whether the author wrote it standalone or
76
- // inline (under a step's `invoke:`, or in a `with:` scope). `data` carries
77
- // the synthesized metadata; `x-telo-value-schema-from` reads sibling fields
78
- // off the resource, which are present either way.
77
+ const substituted = substituteCelFields(data, effectiveSchema, effectiveSchema, {
78
+ external: validator.external,
79
+ });
80
+ // The same two passes the top-level resource loop runs, on the same
81
+ // validator, so a kind's guarantees don't depend on whether the author wrote
82
+ // it standalone or inline (under a step's `invoke:`, or in a `with:` scope)
83
+ // — and CLAUDE.md mandates inline for a single-use resource, so inline is
84
+ // the common shape rather than the exception. `data` carries the synthesized
85
+ // metadata; `x-telo-value-schema-from` reads sibling fields off the
86
+ // resource, which are present either way.
79
87
  const inlineIssues = [
80
- ...validateAgainstSchema(substituted, effectiveSchema),
88
+ ...validator.validate(substituted, effectiveSchema),
81
89
  ...collectValueSchemaIssues(data, schema, allManifests),
82
90
  ];
83
91
  for (const issue of inlineIssues) {
@@ -1,5 +1,5 @@
1
1
  import { resolveContract } from "./invocation-contract.js";
2
- import { checkSchemaCompatibility, navigateSchemaToExprPath, substituteCelFields, validateAgainstSchema, } from "./schema-compat.js";
2
+ import { checkSchemaCompatibility, navigateSchemaToExprPath, substituteCelFields, } from "./schema-compat.js";
3
3
  import { plainChainOf } from "@telorun/templating";
4
4
  import { isLiveSlot, valueTypeOf } from "@telorun/sdk";
5
5
  import { manifestFragmentOf } from "./manifest-schemas.js";
@@ -166,7 +166,15 @@ function checkCallSite(site, ctx) {
166
166
  // findings (missing required, unknown property) are located at the
167
167
  // container and survive the filter.
168
168
  const celPaths = new Set();
169
- const substituted = substituteCelFields(values, contract.schema, undefined, (p) => celPaths.add(p));
169
+ const substituted = substituteCelFields(values, contract.schema, undefined, {
170
+ onSubstitute: (p) => celPaths.add(p),
171
+ // A contract may name a shape declared elsewhere. Both halves need the
172
+ // resolver or they disagree about the same slot: the stand-in walk hands
173
+ // its expressions a typeless value, and the check below compiles nothing
174
+ // at all — so a step's arguments went unchecked against exactly the
175
+ // contracts that describe them most precisely.
176
+ external: (ref) => defs.schemaForId(ref),
177
+ });
170
178
  // The type-argument check, at the one site where a produced value's schema
171
179
  // meets a consuming slot's. A CEL leaf's placeholder says nothing about
172
180
  // what the expression yields, so AJV above is silent here by design — and
@@ -238,7 +246,7 @@ function checkCallSite(site, ctx) {
238
246
  });
239
247
  }
240
248
  }
241
- for (const issue of validateAgainstSchema(substituted, contract.schema)) {
249
+ for (const issue of defs.validateResourceConfig(substituted, contract.schema)) {
242
250
  if (celPaths.has(issue.path))
243
251
  continue;
244
252
  // A missing-required issue names the property that ISN'T there, so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/analyzer",
3
- "version": "0.64.0",
3
+ "version": "0.65.0",
4
4
  "description": "Telo Analyzer - Static manifest validator for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -49,7 +49,7 @@
49
49
  "@types/node": "^20.0.0",
50
50
  "typescript": "^5.0.0",
51
51
  "vitest": "^2.1.8",
52
- "@telorun/sdk": "0.80.0"
52
+ "@telorun/sdk": "0.82.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@telorun/sdk": "*"
package/src/analyzer.ts CHANGED
@@ -1476,6 +1476,17 @@ export class StaticAnalyzer {
1476
1476
  diagnostics.push(...validateIncludePlacement(allManifests));
1477
1477
  }
1478
1478
  resolveSchemaTypeRefs(allManifests, aliases, aliasesByModule);
1479
+ // ...and over the manifests the DEFINITION REGISTRY holds, which are not
1480
+ // these. `normalizeInlineResources` deep-clones — that clone is the
1481
+ // analyzer's immutability boundary — while `defs.register` ran before it, on
1482
+ // the originals. So a kind whose `schema:` references a named shape kept the
1483
+ // authored `telo://Self/<Type>` spelling everywhere the registry is read,
1484
+ // which is where a resource's configuration is validated: the schema failed
1485
+ // to compile, the failure was swallowed, and `telo check` reported nothing
1486
+ // about a resource the kernel then rejected at boot. The pass is idempotent
1487
+ // — a canonical id parses as no authority and is left alone — so running it
1488
+ // over both is the whole repair.
1489
+ resolveSchemaTypeRefs(manifests, aliases, aliasesByModule);
1479
1490
 
1480
1491
  // Trusted-input fast path: when the caller has already attested that
1481
1492
  // this exact manifest set passes analysis (e.g. via the kernel's
@@ -1765,8 +1776,13 @@ export class StaticAnalyzer {
1765
1776
  for (const slot of collectCelValueSlots(m, schema, "")) {
1766
1777
  celReturnSlots.push({ manifest: m, resource, filePath, ...slot });
1767
1778
  }
1768
- // Phase 2+3: AJV on substituted data — CEL fields replaced with typed placeholders
1769
- const ajvIssues = validateAgainstSchema(substituteCelFields(m, schema), schema);
1779
+ // Phase 2+3: AJV on substituted data — CEL fields replaced with typed
1780
+ // placeholders. Through the REGISTRY, so a kind whose schema references
1781
+ // a shape declared elsewhere is checked on the instance that holds it.
1782
+ const ajvIssues = defs.validateResourceConfig(
1783
+ substituteCelFields(m, schema, undefined, { external: (ref) => defs.schemaForId(ref) }),
1784
+ schema,
1785
+ );
1770
1786
  // Phase 4: value slots that must satisfy a type declared elsewhere on
1771
1787
  // the resource (`x-telo-value-schema-from`) — e.g. every row of a
1772
1788
  // decision table against its declared `outputType`, so a mistyped branch
@@ -1879,6 +1895,10 @@ export class StaticAnalyzer {
1879
1895
  return viaRoot ? defs.resolve(viaRoot) : undefined;
1880
1896
  },
1881
1897
  allManifests as Record<string, any>[],
1898
+ {
1899
+ validate: (data, target) => defs.validateResourceConfig(data, target),
1900
+ external: (ref) => defs.schemaForId(ref),
1901
+ },
1882
1902
  ),
1883
1903
  );
1884
1904
  }