@aestheticfunction/dspack-emit 0.6.0 → 0.7.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.
- package/README.md +5 -3
- package/dist/targets/a2ui/surface.js +108 -4
- package/dist/validate/ajv.d.ts +19 -0
- package/dist/validate/ajv.js +78 -13
- package/package.json +6 -2
- package/src/engine-boundary.test.ts +10 -0
- package/src/instance-diagnostics.test.ts +194 -0
- package/src/review-findings.test.ts +4 -1
- package/src/surface-emit.test.ts +43 -11
- package/src/surface-fidelity.test.ts +12 -0
- package/src/t1.test.ts +9 -8
- package/src/targets/a2ui/surface.ts +124 -4
- package/src/validate/ajv.ts +96 -12
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +0 -39
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +0 -34
package/README.md
CHANGED
|
@@ -166,9 +166,11 @@ npm run transform -- --in input/shadcn-ui.dspack.json --a2ui-version 0.9.1 --out
|
|
|
166
166
|
|
|
167
167
|
emits `out/delete-account.surface.json` (createSurface with dspack-token theme +
|
|
168
168
|
updateComponents) and instance-validates it against the freshly generated catalog
|
|
169
|
-
(gate A3). Exit codes: `1` catalog gates failed, `
|
|
170
|
-
surface could not be emitted (unknown component /
|
|
171
|
-
|
|
169
|
+
(gate A3). Exit codes: `1` catalog gates failed, `2` usage or profile-load error,
|
|
170
|
+
`3` strict-coverage, `4` the surface could not be emitted (unknown component /
|
|
171
|
+
structure the profile cannot project), `5` `--strict-surface` (a surface emitted,
|
|
172
|
+
but with fidelity losses you asked to treat as failures — bare, or scoped as
|
|
173
|
+
`--strict-surface=lossy,synthesis-defaults`). The projection is data in the profile (`surfacePlan` directives in
|
|
172
174
|
`src/transform/profiles.ts`); the engine has no component-specific code.
|
|
173
175
|
|
|
174
176
|
**Honest scope:** compound composition flattens per the documented casualties in
|
|
@@ -41,6 +41,11 @@ export function emitSurface(surface, doc, options = {}) {
|
|
|
41
41
|
const rootId = rootPlan && surfaceModelOf(rootPlan).transparent
|
|
42
42
|
? emitter.emitTransparentRoot(surface.root, "$.root")
|
|
43
43
|
: emitter.emitNode(surface.root, "$.root");
|
|
44
|
+
// Every instance is assembled; refuse the whole emission if any of them
|
|
45
|
+
// could not validate against the catalog this surface names (required
|
|
46
|
+
// presence + enum membership — the observed defect class; gate A3 keeps
|
|
47
|
+
// full-schema rigor downstream).
|
|
48
|
+
emitter.refuseCatalogInvalid();
|
|
44
49
|
const surfaceId = options.surfaceId ?? slug(surface.intent);
|
|
45
50
|
const theme = { agentDisplayName: `${doc.name} via dspack` };
|
|
46
51
|
const primaryHex = primaryColor(doc, profile);
|
|
@@ -81,6 +86,14 @@ class SurfaceEmitter {
|
|
|
81
86
|
components = [];
|
|
82
87
|
diagnostics = new Diagnostics();
|
|
83
88
|
usedIds = new Set();
|
|
89
|
+
/**
|
|
90
|
+
* Evidence channel for the final catalog-validity guard: authored props
|
|
91
|
+
* dropped per EMITTED instance — either the prop had no A2UI projection at
|
|
92
|
+
* all, or its value had no projection and no default. Keyed by instance
|
|
93
|
+
* object so a later missing-required refusal can cite its cause. This is
|
|
94
|
+
* bookkeeping alongside the (byte-frozen) warnings, never a new warning.
|
|
95
|
+
*/
|
|
96
|
+
droppedProps = new Map();
|
|
84
97
|
constructor(profile, byDspackId) {
|
|
85
98
|
this.profile = profile;
|
|
86
99
|
this.byDspackId = byDspackId;
|
|
@@ -389,8 +402,9 @@ class SurfaceEmitter {
|
|
|
389
402
|
}
|
|
390
403
|
case "sub-text-lift": {
|
|
391
404
|
// Audited lift: relocation of text that exists, never synthesis. If
|
|
392
|
-
// nothing exists to lift the destination stays missing
|
|
393
|
-
//
|
|
405
|
+
// nothing exists to lift the destination stays missing — refused at
|
|
406
|
+
// emission by the final catalog-validity guard when it is required,
|
|
407
|
+
// arbitrated by gate A3 otherwise. Either way, no fabrication.
|
|
394
408
|
const lift = (n, inside) => {
|
|
395
409
|
const here = inside || selector.subs.includes(n.component);
|
|
396
410
|
if (here && n.text !== undefined && n.text !== "")
|
|
@@ -442,6 +456,7 @@ class SurfaceEmitter {
|
|
|
442
456
|
continue;
|
|
443
457
|
const pp = plan.propMap?.[prop];
|
|
444
458
|
if (!pp) {
|
|
459
|
+
this.recordDrop(instance, { prop, raw, component: node.component, path, reason: "no-projection" });
|
|
445
460
|
this.diagnostics.push({
|
|
446
461
|
code: "surface-prop-dropped",
|
|
447
462
|
message: `${path}: prop '${prop}' on '${node.component}' has no A2UI projection; dropped.`,
|
|
@@ -452,6 +467,7 @@ class SurfaceEmitter {
|
|
|
452
467
|
const mapped = pp.valueMap ? pp.valueMap[String(raw)] : undefined;
|
|
453
468
|
const value = pp.valueMap ? (mapped ?? pp.default) : raw;
|
|
454
469
|
if (value === undefined) {
|
|
470
|
+
this.recordDrop(instance, { prop, dest: pp.a2ui, raw, component: node.component, path, reason: "no-value" });
|
|
455
471
|
this.diagnostics.push({
|
|
456
472
|
code: "surface-prop-value-dropped",
|
|
457
473
|
message: `${path}: value '${String(raw)}' of prop '${prop}' has no projection and no default; dropped.`,
|
|
@@ -470,6 +486,92 @@ class SurfaceEmitter {
|
|
|
470
486
|
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
471
487
|
}
|
|
472
488
|
}
|
|
489
|
+
recordDrop(instance, entry) {
|
|
490
|
+
const list = this.droppedProps.get(instance);
|
|
491
|
+
if (list)
|
|
492
|
+
list.push(entry);
|
|
493
|
+
else
|
|
494
|
+
this.droppedProps.set(instance, [entry]);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Final guard (ratified 2026-08-10): never return a surface whose instances
|
|
498
|
+
* the emitted catalog itself refuses. Two checks per instance, against its
|
|
499
|
+
* own ComponentPlan:
|
|
500
|
+
*
|
|
501
|
+
* - every catalog-required prop carries a value (`plan.required` — the
|
|
502
|
+
* same list mapping.ts emits as `required: ["component", ...]`);
|
|
503
|
+
* - every propMap-projected prop with a `targetEnum` carries a member of
|
|
504
|
+
* that enum (without a valueMap the authored value passes through
|
|
505
|
+
* verbatim, so an off-vocabulary value used to land silently).
|
|
506
|
+
*
|
|
507
|
+
* On any violation the whole emission refuses with ONE aggregated message
|
|
508
|
+
* citing each violation and — where the node's recorded drop diagnostics
|
|
509
|
+
* recover it — the cause. This covers the observed defect class
|
|
510
|
+
* (required-presence + enum-membership); full-schema rigor stays gate A3's
|
|
511
|
+
* job, downstream, as defense in depth. Warnings and fidelity recording are
|
|
512
|
+
* untouched: a surface that emits, emits byte-identically to before.
|
|
513
|
+
*/
|
|
514
|
+
refuseCatalogInvalid() {
|
|
515
|
+
const byA2ui = new Map();
|
|
516
|
+
for (const plan of [...this.profile.components, ...this.profile.synthesized]) {
|
|
517
|
+
// Transparent plans dissolve at emission — no instance ever carries them.
|
|
518
|
+
if (!surfaceModelOf(plan).transparent)
|
|
519
|
+
byA2ui.set(plan.a2ui, plan);
|
|
520
|
+
}
|
|
521
|
+
const violations = [];
|
|
522
|
+
for (const inst of this.components) {
|
|
523
|
+
const plan = byA2ui.get(String(inst.component));
|
|
524
|
+
if (!plan)
|
|
525
|
+
continue; // no plan to check against: gate A3 arbitrates downstream
|
|
526
|
+
const where = `${inst.component}#${inst.id}`;
|
|
527
|
+
const drops = this.droppedProps.get(inst) ?? [];
|
|
528
|
+
for (const req of plan.required) {
|
|
529
|
+
if (inst[req] !== undefined)
|
|
530
|
+
continue;
|
|
531
|
+
violations.push(`${where}: required prop '${req}' has no value after emission${this.missingCause(plan, req, drops)}`);
|
|
532
|
+
}
|
|
533
|
+
for (const [src, pp] of Object.entries(plan.propMap ?? {})) {
|
|
534
|
+
if (!pp.targetEnum)
|
|
535
|
+
continue;
|
|
536
|
+
const value = inst[pp.a2ui];
|
|
537
|
+
if (value === undefined)
|
|
538
|
+
continue;
|
|
539
|
+
if (typeof value === "string" && pp.targetEnum.includes(value))
|
|
540
|
+
continue;
|
|
541
|
+
const cause = pp.valueMap ? "" : ` — authored 'props.${src}' passed through verbatim (this propMap declares no valueMap)`;
|
|
542
|
+
violations.push(`${where}: prop '${pp.a2ui}' value ${JSON.stringify(value)} is outside the catalog's enum (allowed: ${pp.targetEnum.join(", ")})${cause}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (violations.length > 0) {
|
|
546
|
+
throw new EmitSurfaceError(`refusing to emit: ${violations.length} instance value(s) would not validate against the emitted catalog ` +
|
|
547
|
+
`(gate A3 would refuse this surface downstream):\n` +
|
|
548
|
+
violations.map((v) => ` - ${v}`).join("\n"), "$");
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* The recoverable cause for a required prop with no value: the authored
|
|
553
|
+
* prop this node DID carry that was dropped (recorded at PropMap time),
|
|
554
|
+
* and/or where the plan's own routes expect the value to come from.
|
|
555
|
+
*/
|
|
556
|
+
missingCause(plan, req, drops) {
|
|
557
|
+
const model = surfaceModelOf(plan);
|
|
558
|
+
const feeders = model.routes.filter((r) => r.to.name === req);
|
|
559
|
+
const subs = [
|
|
560
|
+
...new Set(feeders.flatMap((r) => r.from.flatMap((s) => ("subs" in s ? [...s.subs] : [])))),
|
|
561
|
+
];
|
|
562
|
+
const source = subs.length > 0
|
|
563
|
+
? ` (${req} comes from the ${subs.map((s) => `'${s}'`).join(" / ")} sub-component${subs.length > 1 ? "s" : ""})`
|
|
564
|
+
: feeders.length > 0
|
|
565
|
+
? ` (${req} is fed by ${feeders.map((r) => r.from.map(describeSelector).join(" | ")).join(", ")})`
|
|
566
|
+
: "";
|
|
567
|
+
const drop = drops.find((d) => d.prop === req || d.dest === req);
|
|
568
|
+
if (!drop)
|
|
569
|
+
return source;
|
|
570
|
+
const why = drop.reason === "no-projection"
|
|
571
|
+
? `authored 'props.${drop.prop}' on '${drop.component}' has no A2UI projection`
|
|
572
|
+
: `authored 'props.${drop.prop}'=${JSON.stringify(drop.raw)} on '${drop.component}' has no projection for that value and no default`;
|
|
573
|
+
return ` — ${why}${source}`;
|
|
574
|
+
}
|
|
473
575
|
/**
|
|
474
576
|
* Refuse when a consumed subtree contains a component the profile declared a
|
|
475
577
|
* casualty. Consumption is how compounds fold their parts into props; it is
|
|
@@ -1073,8 +1175,10 @@ class SurfaceEmitter {
|
|
|
1073
1175
|
if (value !== undefined) {
|
|
1074
1176
|
pending.push({ prop: d.to.name, value, origin: d.origin, donorPath: `${path}${suffix}`, donorComponent });
|
|
1075
1177
|
}
|
|
1076
|
-
// Nothing to donate is not an error: the destination stays absent
|
|
1077
|
-
//
|
|
1178
|
+
// Nothing to donate is not an error: the destination stays absent —
|
|
1179
|
+
// refused at emission by the final catalog-validity guard when it is
|
|
1180
|
+
// required, arbitrated by gate A3 otherwise. Relocation, never
|
|
1181
|
+
// synthesis (the lift rule).
|
|
1078
1182
|
}
|
|
1079
1183
|
// The boundary's own text rises as body text unless a self.text
|
|
1080
1184
|
// donation claimed it (the plain transparent-sub behaviour otherwise).
|
package/dist/validate/ajv.d.ts
CHANGED
|
@@ -4,6 +4,25 @@ export interface GateResult {
|
|
|
4
4
|
pass: boolean;
|
|
5
5
|
detail: string;
|
|
6
6
|
errors?: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Structured per-instance evidence for gate 3 failures (advanced channel
|
|
9
|
+
* for downstream UIs). The strings in `errors` remain the primary
|
|
10
|
+
* user-facing form; this preserves ajv's keyword/params/schemaPath, which
|
|
11
|
+
* the strings deliberately compress.
|
|
12
|
+
*/
|
|
13
|
+
errorDetails?: Array<{
|
|
14
|
+
/** `component#id` — same prefix the string form carries. */
|
|
15
|
+
instance: string;
|
|
16
|
+
component: string;
|
|
17
|
+
id: string;
|
|
18
|
+
errors: Array<{
|
|
19
|
+
instancePath?: string;
|
|
20
|
+
schemaPath?: string;
|
|
21
|
+
keyword?: string;
|
|
22
|
+
params?: unknown;
|
|
23
|
+
message?: string;
|
|
24
|
+
}>;
|
|
25
|
+
}>;
|
|
7
26
|
}
|
|
8
27
|
export interface ValidationReport {
|
|
9
28
|
version: A2uiVersion;
|
package/dist/validate/ajv.js
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* a2ui-catalog.meta.<ver>.json (the literal "catalog schema" check; this is what
|
|
13
13
|
* makes v0.9.1 vs v1.0 conformance distinct — theme vs surfaceProperties).
|
|
14
14
|
* 3. instance: every component instance in the hand-authored surface validates
|
|
15
|
-
* against the catalog's own #/$defs/anyComponent
|
|
15
|
+
* against the catalog's own #/$defs/anyComponent — checked by manual
|
|
16
|
+
* discrimination (each instance against its own #/components/<name>
|
|
17
|
+
* branch), which is semantically equivalent and keeps every reported
|
|
18
|
+
* error inside the instance's own branch. See the gate 3 body.
|
|
16
19
|
*/
|
|
17
20
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
18
21
|
import addFormats from "ajv-formats";
|
|
@@ -162,22 +165,63 @@ export function validateCatalog(catalog, version, surface) {
|
|
|
162
165
|
// Belt and braces: gate 1 has already proven every ref resolves, but a
|
|
163
166
|
// raw ajv throw must never escape this function regardless.
|
|
164
167
|
const failures = [];
|
|
168
|
+
const errorDetails = [];
|
|
165
169
|
let instances = [];
|
|
166
170
|
try {
|
|
167
171
|
const ajv = newAjv();
|
|
168
172
|
ajv.addSchema(catalog, catalog.$id);
|
|
169
|
-
const validateAny = ajv.getSchema(`${catalog.$id}#/$defs/anyComponent`);
|
|
170
173
|
instances = extractInstances(surface);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
174
|
+
// Manual discrimination instead of the flat `#/$defs/anyComponent`
|
|
175
|
+
// oneOf. Semantically equivalent: every branch of the emitted
|
|
176
|
+
// anyComponent is `{$ref: "#/components/<name>"}` and each component
|
|
177
|
+
// schema pins `component: {const: <name>}` inside its allOf (and
|
|
178
|
+
// requires it), so an instance tagged component X can only ever match
|
|
179
|
+
// branch X — validating the instance against ITS OWN branch accepts
|
|
180
|
+
// and rejects exactly the same instances the oneOf does. What changes
|
|
181
|
+
// is the report: allErrors WITHIN the matching branch (rigor
|
|
182
|
+
// preserved, every genuine error surfaced) without echoing every
|
|
183
|
+
// other branch's const/required/unevaluatedProperties noise.
|
|
184
|
+
const admitted = Object.keys(catalog.components ?? {});
|
|
185
|
+
for (const inst of instances) {
|
|
186
|
+
const comp = String(inst.component);
|
|
187
|
+
const id = String(inst.id);
|
|
188
|
+
const where = `${comp}#${id}`;
|
|
189
|
+
if (!admitted.includes(comp)) {
|
|
190
|
+
failures.push(`${where}: component '${comp}' is not in this catalog (${admitted.length} components admitted)`);
|
|
191
|
+
errorDetails.push({
|
|
192
|
+
instance: where,
|
|
193
|
+
component: comp,
|
|
194
|
+
id,
|
|
195
|
+
errors: [
|
|
196
|
+
{
|
|
197
|
+
message: `component '${comp}' is not in this catalog`,
|
|
198
|
+
params: { admittedComponents: admitted },
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
});
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const validateBranch = ajv.getSchema(`${catalog.$id}#/components/${comp}`);
|
|
205
|
+
if (!validateBranch) {
|
|
206
|
+
failures.push(`${where}: could not resolve #/components/${comp} from the catalog.`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (!validateBranch(inst)) {
|
|
210
|
+
const errs = validateBranch.errors ?? [];
|
|
211
|
+
for (const e of errs)
|
|
212
|
+
failures.push(`${where}: ${fmtErr(e)}`);
|
|
213
|
+
errorDetails.push({
|
|
214
|
+
instance: where,
|
|
215
|
+
component: comp,
|
|
216
|
+
id,
|
|
217
|
+
errors: errs.map((e) => ({
|
|
218
|
+
instancePath: e.instancePath,
|
|
219
|
+
schemaPath: e.schemaPath,
|
|
220
|
+
keyword: e.keyword,
|
|
221
|
+
params: e.params,
|
|
222
|
+
message: e.message,
|
|
223
|
+
})),
|
|
224
|
+
});
|
|
181
225
|
}
|
|
182
226
|
}
|
|
183
227
|
}
|
|
@@ -191,11 +235,32 @@ export function validateCatalog(catalog, version, surface) {
|
|
|
191
235
|
? `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
|
|
192
236
|
: `${failures.length} instance validation error(s).`,
|
|
193
237
|
errors: failures.length ? failures : undefined,
|
|
238
|
+
...(errorDetails.length ? { errorDetails } : {}),
|
|
194
239
|
});
|
|
195
240
|
}
|
|
196
241
|
}
|
|
197
242
|
return { version, pass: gates.every((g) => g.pass), gates };
|
|
198
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* One ajv error as a user-facing line: instancePath + message, enriched from
|
|
246
|
+
* the error's params where they carry the actionable detail ajv's message
|
|
247
|
+
* omits — the allowed enum values, the expected const, or the name of the
|
|
248
|
+
* offending unevaluated/additional property.
|
|
249
|
+
*/
|
|
199
250
|
function fmtErr(e) {
|
|
200
|
-
|
|
251
|
+
const params = (e.params ?? {});
|
|
252
|
+
let out = `${e.instancePath || "(root)"} ${e.message ?? ""}`.trim();
|
|
253
|
+
if (e.keyword === "enum" && Array.isArray(params.allowedValues)) {
|
|
254
|
+
out += ` (allowed: ${params.allowedValues.map((v) => String(v)).join(", ")})`;
|
|
255
|
+
}
|
|
256
|
+
else if (e.keyword === "const" && "allowedValue" in params) {
|
|
257
|
+
out += ` (expected: ${JSON.stringify(params.allowedValue)})`;
|
|
258
|
+
}
|
|
259
|
+
else if (e.keyword === "unevaluatedProperties" && typeof params.unevaluatedProperty === "string") {
|
|
260
|
+
out += ` ('${params.unevaluatedProperty}')`;
|
|
261
|
+
}
|
|
262
|
+
else if (e.keyword === "additionalProperties" && typeof params.additionalProperty === "string") {
|
|
263
|
+
out += ` ('${params.additionalProperty}')`;
|
|
264
|
+
}
|
|
265
|
+
return out;
|
|
201
266
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "dspack emitters: compile a dspack design-system contract and dspack surfaces into protocol targets
|
|
5
|
+
"description": "dspack emitters: compile a dspack design-system contract and dspack surfaces into protocol targets — an A2UI catalog + surface messages (gates A1-A3) and json-render catalog/registry modules + specs (gates J1-J3).",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/aestheticfunction/dspack-emit.git"
|
|
10
|
+
},
|
|
7
11
|
"exports": {
|
|
8
12
|
".": {
|
|
9
13
|
"types": "./dist/index.d.ts",
|
|
@@ -143,10 +143,14 @@ describe("transformations keep their meaning", () => {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
it("first-write-wins: the first matching sub claims the destination", () => {
|
|
146
|
+
// The trigger keeps the AlertDialog instance catalog-valid
|
|
147
|
+
// (`triggerLabel` is required; emitSurface now refuses invalid
|
|
148
|
+
// instances) — the behaviour under test is the duplicated title.
|
|
146
149
|
const [dialog] = instances(
|
|
147
150
|
{
|
|
148
151
|
component: "alert-dialog",
|
|
149
152
|
children: [
|
|
153
|
+
{ component: "alert-dialog-trigger", children: [{ component: "button", text: "Open" }] },
|
|
150
154
|
{ component: "alert-dialog-content", children: [
|
|
151
155
|
{ component: "alert-dialog-title", text: "First" },
|
|
152
156
|
{ component: "alert-dialog-title", text: "Second" },
|
|
@@ -173,6 +177,9 @@ describe("transformations keep their meaning", () => {
|
|
|
173
177
|
});
|
|
174
178
|
|
|
175
179
|
it("collection: two header rows concatenate into one column list (v1 behaviour)", () => {
|
|
180
|
+
// A body row keeps the Table instance catalog-valid (`rows` is required;
|
|
181
|
+
// emitSurface now refuses invalid instances) — the behaviour under test
|
|
182
|
+
// is the header concatenation, which is unaffected.
|
|
176
183
|
const [table] = instances({
|
|
177
184
|
component: "table",
|
|
178
185
|
children: [
|
|
@@ -180,6 +187,9 @@ describe("transformations keep their meaning", () => {
|
|
|
180
187
|
{ component: "table-row", children: [{ component: "table-head", text: "A" }] },
|
|
181
188
|
{ component: "table-row", children: [{ component: "table-head", text: "B" }] },
|
|
182
189
|
] },
|
|
190
|
+
{ component: "table-body", children: [
|
|
191
|
+
{ component: "table-row", children: [{ component: "table-cell", text: "1" }] },
|
|
192
|
+
] },
|
|
183
193
|
],
|
|
184
194
|
});
|
|
185
195
|
expect(table.columns).toEqual(["A", "B"]);
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instance diagnostics — two ratified fixes, proven fail-first:
|
|
3
|
+
*
|
|
4
|
+
* Fix 1 (gate A3, src/validate/ajv.ts): gate 3 used to validate every
|
|
5
|
+
* instance against `#/$defs/anyComponent` — a flat oneOf over ALL catalog
|
|
6
|
+
* components — with allErrors, so ONE missing prop yielded an error per
|
|
7
|
+
* OTHER branch (their const/required/unevaluatedProperties failures), all
|
|
8
|
+
* prefixed with the instance's own component#id. Branch-aware validation
|
|
9
|
+
* reports only the instance's own branch (semantically equivalent: every
|
|
10
|
+
* branch pins `component: {const: <name>}`), enriches messages from ajv
|
|
11
|
+
* params (enum/const/unevaluated), and carries a structured `errorDetails`
|
|
12
|
+
* channel preserving keyword/params for downstream UIs.
|
|
13
|
+
*
|
|
14
|
+
* Fix 2 (emitSurface, src/targets/a2ui/surface.ts): the emitter could
|
|
15
|
+
* produce instances that cannot validate against the very catalog they
|
|
16
|
+
* name — a required prop silently dropped at projection (authored
|
|
17
|
+
* `props.title` with no propMap), or an enum value passed through verbatim
|
|
18
|
+
* when no valueMap exists. emitSurface now refuses with one aggregated,
|
|
19
|
+
* causal message instead of emitting a catalog-invalid surface. Full-schema
|
|
20
|
+
* rigor stays gate A3's job (defense in depth); this guard covers
|
|
21
|
+
* required-presence and enum-membership, the observed defect class.
|
|
22
|
+
*
|
|
23
|
+
* The fixture is a minimal inline contract + v2 profile with three mapped
|
|
24
|
+
* components carrying DISTINCT required props (label / title / caption) and
|
|
25
|
+
* one enum prop (tone) — so cross-branch noise, if any, is detectable by
|
|
26
|
+
* name.
|
|
27
|
+
*/
|
|
28
|
+
import { describe, expect, it } from "vitest";
|
|
29
|
+
import { transformFromJson } from "./transform/index.js";
|
|
30
|
+
import { loadProfile } from "./transform/profile-load.js";
|
|
31
|
+
import { emitSurface, EmitSurfaceError } from "./targets/a2ui/surface.js";
|
|
32
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
33
|
+
|
|
34
|
+
const contract: DspackDoc = {
|
|
35
|
+
dspack: "0.4",
|
|
36
|
+
name: "mini-kit",
|
|
37
|
+
description: "Minimal inline contract for instance diagnostics.",
|
|
38
|
+
tokens: { color: { values: { primary: { value: "#3366ff", type: "color" } } } },
|
|
39
|
+
components: {
|
|
40
|
+
"text-field": { name: "TextField", description: "Single-line text input." },
|
|
41
|
+
alert: {
|
|
42
|
+
name: "Alert",
|
|
43
|
+
description: "Callout whose title comes from its alert-title sub-component.",
|
|
44
|
+
composition: { subComponents: [{ id: "alert-title" }] },
|
|
45
|
+
},
|
|
46
|
+
chip: {
|
|
47
|
+
name: "Chip",
|
|
48
|
+
description: "Small status marker with a tone.",
|
|
49
|
+
props: { tone: { type: "enum", values: ["info", "warning"], description: "Visual tone." } },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** A v2 profile document mapping all three components. */
|
|
55
|
+
const profileDoc = (): Record<string, unknown> => ({
|
|
56
|
+
profileVersion: "2",
|
|
57
|
+
catalogTitle: "mini-kit — A2UI catalog",
|
|
58
|
+
catalogDescription: "Minimal catalog exercising branch-aware instance diagnostics.",
|
|
59
|
+
catalogIdBase: "https://example.test/catalogs/mini-kit",
|
|
60
|
+
instructions: "",
|
|
61
|
+
primaryColorToken: { category: "color", name: "primary" },
|
|
62
|
+
surfaceSynthesis: { textComponent: "Text", textProp: "text", wrapComponent: "Column", wrapChildrenProp: "children" },
|
|
63
|
+
synthesized: [],
|
|
64
|
+
casualtyComponents: [],
|
|
65
|
+
components: [
|
|
66
|
+
{
|
|
67
|
+
a2ui: "TextField",
|
|
68
|
+
dspackId: "text-field",
|
|
69
|
+
commons: ["ComponentCommon"],
|
|
70
|
+
structural: {
|
|
71
|
+
label: { schema: { type: "string" }, description: "The field label.", synthNote: "synthesized from node text" },
|
|
72
|
+
},
|
|
73
|
+
required: ["label"],
|
|
74
|
+
surface: { routes: [{ from: ["self.text"], to: "prop:label" }] },
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
a2ui: "Alert",
|
|
78
|
+
dspackId: "alert",
|
|
79
|
+
commons: ["ComponentCommon"],
|
|
80
|
+
structural: {
|
|
81
|
+
title: { schema: { type: "string" }, description: "The alert title.", synthNote: "from the alert-title sub-component" },
|
|
82
|
+
},
|
|
83
|
+
required: ["title"],
|
|
84
|
+
surface: { routes: [{ from: ["sub(alert-title).text"], to: "prop:title" }] },
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
a2ui: "Chip",
|
|
88
|
+
dspackId: "chip",
|
|
89
|
+
commons: ["ComponentCommon"],
|
|
90
|
+
structural: {
|
|
91
|
+
caption: { schema: { type: "string" }, description: "The chip caption.", synthNote: "synthesized from node text" },
|
|
92
|
+
},
|
|
93
|
+
// Deliberately NO valueMap: an authored tone passes through verbatim today.
|
|
94
|
+
propMap: { tone: { a2ui: "tone", kind: "enum", targetEnum: ["info", "warning"], description: "Visual tone." } },
|
|
95
|
+
required: ["caption"],
|
|
96
|
+
surface: { routes: [{ from: ["self.text"], to: "prop:caption" }] },
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const profile = () => loadProfile(profileDoc());
|
|
102
|
+
|
|
103
|
+
const surfaceOf = (root: unknown, intent = "diagnostics"): DspackSurface =>
|
|
104
|
+
({ dspackSurface: "0.1", system: "mini-kit", intent, root }) as DspackSurface;
|
|
105
|
+
|
|
106
|
+
const messagesWith = (...instances: Array<Record<string, unknown>>) => ({
|
|
107
|
+
messages: [{ version: "v0.9", updateComponents: { surfaceId: "s", components: instances } }],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const instanceGate = (surface: unknown) => {
|
|
111
|
+
const out = transformFromJson(contract, { profile: profile(), surface });
|
|
112
|
+
return out.validation.gates.find((g) => g.name === "instance")!;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
describe("gate A3 reports branch-scoped errors (fix 1)", () => {
|
|
116
|
+
it("an instance missing its ONE required prop gets own-branch errors only, not every other branch's noise", () => {
|
|
117
|
+
const gate = instanceGate(messagesWith({ id: "x", component: "TextField" }));
|
|
118
|
+
expect(gate.pass).toBe(false);
|
|
119
|
+
const errors = gate.errors ?? [];
|
|
120
|
+
// Branch-scoped: a handful of errors, not one per unrelated branch.
|
|
121
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
122
|
+
expect(errors.length).toBeLessThanOrEqual(4);
|
|
123
|
+
for (const e of errors) {
|
|
124
|
+
// Every error names the instance itself…
|
|
125
|
+
expect(e).toContain("TextField#x");
|
|
126
|
+
// …and NONE leak the other components' branches: their names or their
|
|
127
|
+
// required props must not appear in a report about a TextField.
|
|
128
|
+
expect(e).not.toMatch(/\bAlert\b|\bChip\b|'title'|'caption'|"title"|"caption"/);
|
|
129
|
+
}
|
|
130
|
+
// The genuine error is reported: label is missing.
|
|
131
|
+
expect(errors.join("\n")).toMatch(/label/);
|
|
132
|
+
// Structured evidence rides alongside, preserving ajv keyword/params.
|
|
133
|
+
expect(gate.errorDetails).toBeDefined();
|
|
134
|
+
const detail = gate.errorDetails!.find((d) => d.instance === "TextField#x")!;
|
|
135
|
+
expect(detail).toBeDefined();
|
|
136
|
+
expect(detail.component).toBe("TextField");
|
|
137
|
+
expect(detail.id).toBe("x");
|
|
138
|
+
const required = detail.errors.find((e) => e.keyword === "required");
|
|
139
|
+
expect(required).toBeDefined();
|
|
140
|
+
expect((required!.params as { missingProperty?: string }).missingProperty).toBe("label");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("an unknown component yields exactly ONE error naming it and the admitted count", () => {
|
|
144
|
+
const gate = instanceGate(messagesWith({ id: "z", component: "Zorp" }));
|
|
145
|
+
expect(gate.pass).toBe(false);
|
|
146
|
+
expect(gate.errors).toHaveLength(1);
|
|
147
|
+
expect(gate.errors![0]).toBe("Zorp#z: component 'Zorp' is not in this catalog (3 components admitted)");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("an enum violation names the allowed values (enriched from ajv params)", () => {
|
|
151
|
+
const gate = instanceGate(
|
|
152
|
+
messagesWith({ id: "c", component: "Chip", caption: "Beta", tone: "loud" }),
|
|
153
|
+
);
|
|
154
|
+
expect(gate.pass).toBe(false);
|
|
155
|
+
const joined = (gate.errors ?? []).join("\n");
|
|
156
|
+
expect(joined).toMatch(/allowed: info, warning/);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("emitSurface refuses catalog-invalid instances (fix 2)", () => {
|
|
161
|
+
it("a required prop left unset by a dropped authored prop refuses — with the cause", () => {
|
|
162
|
+
// Authored `props.title` has no propMap on 'alert' (title comes from the
|
|
163
|
+
// alert-title sub-component), so today the prop drops with a warning and
|
|
164
|
+
// the emitted Alert instance is missing its required `title`.
|
|
165
|
+
const s = surfaceOf({ component: "alert", props: { title: "Heads up" } });
|
|
166
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(EmitSurfaceError);
|
|
167
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(/required prop 'title'/);
|
|
168
|
+
// The refusal explains the cause: the authored prop had no projection,
|
|
169
|
+
// and the value was expected from the sub-component.
|
|
170
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(/props\.title/);
|
|
171
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(/alert-title/);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("an enum value outside the targetEnum refuses, naming the allowed values", () => {
|
|
175
|
+
// No valueMap on tone: the raw value would land verbatim on the instance
|
|
176
|
+
// and fail gate A3 downstream. Refuse at emission instead.
|
|
177
|
+
const s = surfaceOf({ component: "chip", text: "Beta", props: { tone: "loud" } });
|
|
178
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(EmitSurfaceError);
|
|
179
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(/tone/);
|
|
180
|
+
expect(() => emitSurface(s, contract, { profile: profile() })).toThrowError(/allowed: info, warning/);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("fixture sanity: valid surfaces emit and pass every gate (true before and after the fixes)", () => {
|
|
184
|
+
for (const root of [
|
|
185
|
+
{ component: "text-field", text: "Email" },
|
|
186
|
+
{ component: "alert", children: [{ component: "alert-title", text: "Heads up" }] },
|
|
187
|
+
{ component: "chip", text: "Beta", props: { tone: "info" } },
|
|
188
|
+
]) {
|
|
189
|
+
const { messages } = emitSurface(surfaceOf(root), contract, { profile: profile() });
|
|
190
|
+
const out = transformFromJson(contract, { profile: profile(), surface: { messages } });
|
|
191
|
+
expect(out.validation.pass, `gates for ${root.component}`).toBe(true);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -223,10 +223,13 @@ describe("dead and contradictory spellings refuse at load (findings 4, 5, 13)",
|
|
|
223
223
|
describe("the ledger never reports a discarded value as landed (findings 7, 11, 12)", () => {
|
|
224
224
|
it("a first-wins-skipped harvest ledgers as dropped/lossy, not moved", () => {
|
|
225
225
|
// The shipped v1 Table: authored caption prop beats the harvested one.
|
|
226
|
+
// columns/rows ride the same structuralPassthrough so the instance stays
|
|
227
|
+
// catalog-valid (both are required; emitSurface now refuses otherwise) —
|
|
228
|
+
// the first-wins dynamics under test concern only the caption.
|
|
226
229
|
const { fidelity } = emitSurface(
|
|
227
230
|
surface({
|
|
228
231
|
component: "table",
|
|
229
|
-
props: { caption: "Authored" },
|
|
232
|
+
props: { caption: "Authored", columns: ["A"], rows: [{ cells: ["1"] }] },
|
|
230
233
|
children: [{ component: "table-caption", text: "Harvested" }],
|
|
231
234
|
}),
|
|
232
235
|
doc,
|
package/src/surface-emit.test.ts
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* - Compound flattening lands the documented projection (title/description/
|
|
9
9
|
* cancelLabel/confirmLabel/triggerLabel + synthesized action).
|
|
10
10
|
* - Unknown components fail with a typed error (never silently dropped).
|
|
11
|
-
* - A CSR
|
|
12
|
-
* the gate
|
|
11
|
+
* - A CSR that would emit an instance missing a required prop REFUSES at
|
|
12
|
+
* emitSurface (with the cause); gate A3 stays non-vacuous for
|
|
13
|
+
* hand-authored surfaces — defense in depth, proven separately.
|
|
13
14
|
* - Emission is deterministic.
|
|
14
15
|
*/
|
|
15
16
|
import { readFileSync } from "node:fs";
|
|
@@ -111,16 +112,19 @@ describe("emitSurface: worked example (ex.delete-account-confirmation)", () => {
|
|
|
111
112
|
}
|
|
112
113
|
});
|
|
113
114
|
|
|
114
|
-
it("lift is relocation, never synthesis: a trigger with no text anywhere
|
|
115
|
+
it("lift is relocation, never synthesis: a trigger with no text anywhere refuses at emission", () => {
|
|
116
|
+
// Nothing exists to lift, so nothing is synthesized — and instead of
|
|
117
|
+
// emitting an AlertDialog missing its required `triggerLabel` for gate A3
|
|
118
|
+
// to refuse downstream, emitSurface now refuses the emission itself,
|
|
119
|
+
// naming the unfilled requirement and where the value should have come
|
|
120
|
+
// from. (Gate A3 keeps full-schema rigor for hand-authored surfaces — see
|
|
121
|
+
// the non-vacuity test below.)
|
|
115
122
|
const bare: DspackSurface = structuredClone(workedExample.surface);
|
|
116
123
|
const trigger = bare.root.children![0].children![0];
|
|
117
124
|
trigger.children = [{ component: "button", props: { variant: "destructive" }, children: [{ component: "badge" }] }];
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
expect(
|
|
121
|
-
expect(bareWarnings.map((w) => w.code)).not.toContain("surface-label-lifted");
|
|
122
|
-
const { validation } = transform(doc, "0.9.1", { messages: bareMessages });
|
|
123
|
-
expect(validation.gates.find((g) => g.name === "instance")!.pass).toBe(false); // A3 refuses, as before
|
|
125
|
+
expect(() => emitSurface(bare, doc)).toThrowError(EmitSurfaceError);
|
|
126
|
+
expect(() => emitSurface(bare, doc)).toThrowError(/required prop 'triggerLabel' has no value after emission/);
|
|
127
|
+
expect(() => emitSurface(bare, doc)).toThrowError(/alert-dialog-trigger/);
|
|
124
128
|
});
|
|
125
129
|
});
|
|
126
130
|
|
|
@@ -184,7 +188,7 @@ describe("emitSurface: failure modes", () => {
|
|
|
184
188
|
expect(() => emitSurface(bad, doc)).toThrowError(/does not match contract name/);
|
|
185
189
|
});
|
|
186
190
|
|
|
187
|
-
it("
|
|
191
|
+
it("emitSurface refuses an AlertDialog missing its title, with the sub-component cause", () => {
|
|
188
192
|
const missingTitle: DspackSurface = {
|
|
189
193
|
dspackSurface: "0.1",
|
|
190
194
|
system: "shadcn/ui",
|
|
@@ -205,10 +209,38 @@ describe("emitSurface: failure modes", () => {
|
|
|
205
209
|
],
|
|
206
210
|
},
|
|
207
211
|
};
|
|
208
|
-
|
|
212
|
+
expect(() => emitSurface(missingTitle, doc)).toThrowError(EmitSurfaceError);
|
|
213
|
+
expect(() => emitSurface(missingTitle, doc)).toThrowError(/required prop 'title' has no value after emission/);
|
|
214
|
+
expect(() => emitSurface(missingTitle, doc)).toThrowError(/alert-dialog-title/);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("gate A3 is non-vacuous: a hand-authored AlertDialog missing its title fails instance validation", () => {
|
|
218
|
+
// Defense in depth: the emitter's guard refuses upstream, but gate A3
|
|
219
|
+
// must still catch invalid instances that arrive without going through
|
|
220
|
+
// emitSurface at all — and its (now branch-scoped) errors must name the
|
|
221
|
+
// genuine problem.
|
|
222
|
+
const messages = [
|
|
223
|
+
{
|
|
224
|
+
version: "v0.9",
|
|
225
|
+
updateComponents: {
|
|
226
|
+
surfaceId: "s",
|
|
227
|
+
components: [
|
|
228
|
+
{
|
|
229
|
+
id: "root",
|
|
230
|
+
component: "AlertDialog",
|
|
231
|
+
triggerLabel: "Delete",
|
|
232
|
+
cancelLabel: "Cancel",
|
|
233
|
+
action: { event: { name: "delete", context: {} } },
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
];
|
|
209
239
|
const { validation } = transform(doc, "0.9.1", { messages });
|
|
210
240
|
const instance = validation.gates.find((g) => g.name === "instance")!;
|
|
211
241
|
expect(instance.pass).toBe(false);
|
|
212
242
|
expect((instance.errors ?? []).join("\n")).toMatch(/title/);
|
|
243
|
+
// And branch-scoped: no other component's branch leaks into the report.
|
|
244
|
+
for (const e of instance.errors ?? []) expect(e).toContain("AlertDialog#root");
|
|
213
245
|
});
|
|
214
246
|
});
|
|
@@ -78,10 +78,22 @@ describe("every transformation reports itself", () => {
|
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
it("collection records the gathered rows, per-cell flattening losses, and drops", () => {
|
|
81
|
+
// The header row keeps the Table instance catalog-valid (`columns` is
|
|
82
|
+
// required; emitSurface now refuses invalid instances) — the ledger
|
|
83
|
+
// behaviour under test lives in the body/footer handling.
|
|
81
84
|
const entries = fidelityOf({
|
|
82
85
|
component: "table",
|
|
83
86
|
children: [
|
|
84
87
|
{ component: "table-caption", text: "Orders" },
|
|
88
|
+
{
|
|
89
|
+
component: "table-header",
|
|
90
|
+
children: [
|
|
91
|
+
{
|
|
92
|
+
component: "table-row",
|
|
93
|
+
children: [{ component: "table-head", text: "Status" }, { component: "table-head", text: "Order" }],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
85
97
|
{
|
|
86
98
|
component: "table-body",
|
|
87
99
|
children: [
|
package/src/t1.test.ts
CHANGED
|
@@ -331,7 +331,11 @@ describe("T1 fail-closed boundaries", () => {
|
|
|
331
331
|
expect(lost).toBeDefined();
|
|
332
332
|
});
|
|
333
333
|
|
|
334
|
-
it("nothing to donate leaves the destination
|
|
334
|
+
it("nothing to donate leaves the destination unfilled and emission refuses — relocation, never synthesis", () => {
|
|
335
|
+
// No form-label exists, so no label is donated and NOTHING is synthesized
|
|
336
|
+
// in its place. The shipped TextField requires `label`, so instead of
|
|
337
|
+
// emitting an instance gate A3 would refuse downstream, emitSurface now
|
|
338
|
+
// refuses the emission itself, naming the unfilled requirement.
|
|
335
339
|
const s = surfaceOf({
|
|
336
340
|
component: "card",
|
|
337
341
|
children: [
|
|
@@ -346,13 +350,10 @@ describe("T1 fail-closed boundaries", () => {
|
|
|
346
350
|
},
|
|
347
351
|
],
|
|
348
352
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// The shipped TextField requires `label`, so A3 refuses the omission.
|
|
354
|
-
const check = transformFromJson(contract, { profile: t1Profile(), surface: { messages } });
|
|
355
|
-
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(false);
|
|
353
|
+
expect(() => emitSurface(s, contract, { profile: t1Profile() })).toThrowError(EmitSurfaceError);
|
|
354
|
+
expect(() => emitSurface(s, contract, { profile: t1Profile() })).toThrowError(
|
|
355
|
+
/required prop 'label' has no value after emission/,
|
|
356
|
+
);
|
|
356
357
|
});
|
|
357
358
|
|
|
358
359
|
it("a transparent plan emits no catalog entry, and coverage says so", () => {
|
|
@@ -118,6 +118,12 @@ export function emitSurface(
|
|
|
118
118
|
? emitter.emitTransparentRoot(surface.root, "$.root")
|
|
119
119
|
: emitter.emitNode(surface.root, "$.root");
|
|
120
120
|
|
|
121
|
+
// Every instance is assembled; refuse the whole emission if any of them
|
|
122
|
+
// could not validate against the catalog this surface names (required
|
|
123
|
+
// presence + enum membership — the observed defect class; gate A3 keeps
|
|
124
|
+
// full-schema rigor downstream).
|
|
125
|
+
emitter.refuseCatalogInvalid();
|
|
126
|
+
|
|
121
127
|
const surfaceId = options.surfaceId ?? slug(surface.intent);
|
|
122
128
|
const theme: Json = { agentDisplayName: `${doc.name} via dspack` };
|
|
123
129
|
const primaryHex = primaryColor(doc, profile);
|
|
@@ -177,6 +183,17 @@ class SurfaceEmitter {
|
|
|
177
183
|
readonly components: Json[] = [];
|
|
178
184
|
readonly diagnostics = new Diagnostics();
|
|
179
185
|
private readonly usedIds = new Set<string>();
|
|
186
|
+
/**
|
|
187
|
+
* Evidence channel for the final catalog-validity guard: authored props
|
|
188
|
+
* dropped per EMITTED instance — either the prop had no A2UI projection at
|
|
189
|
+
* all, or its value had no projection and no default. Keyed by instance
|
|
190
|
+
* object so a later missing-required refusal can cite its cause. This is
|
|
191
|
+
* bookkeeping alongside the (byte-frozen) warnings, never a new warning.
|
|
192
|
+
*/
|
|
193
|
+
private readonly droppedProps = new Map<
|
|
194
|
+
Json,
|
|
195
|
+
Array<{ prop: string; dest?: string; raw: unknown; component: string; path: string; reason: "no-projection" | "no-value" }>
|
|
196
|
+
>();
|
|
180
197
|
|
|
181
198
|
constructor(
|
|
182
199
|
private readonly profile: Profile,
|
|
@@ -591,8 +608,9 @@ class SurfaceEmitter {
|
|
|
591
608
|
|
|
592
609
|
case "sub-text-lift": {
|
|
593
610
|
// Audited lift: relocation of text that exists, never synthesis. If
|
|
594
|
-
// nothing exists to lift the destination stays missing
|
|
595
|
-
//
|
|
611
|
+
// nothing exists to lift the destination stays missing — refused at
|
|
612
|
+
// emission by the final catalog-validity guard when it is required,
|
|
613
|
+
// arbitrated by gate A3 otherwise. Either way, no fabrication.
|
|
596
614
|
const lift = (n: SurfaceNode, inside: boolean): { text: string; component: string } | undefined => {
|
|
597
615
|
const here = inside || selector.subs.includes(n.component);
|
|
598
616
|
if (here && n.text !== undefined && n.text !== "") return { text: n.text, component: n.component };
|
|
@@ -656,6 +674,7 @@ class SurfaceEmitter {
|
|
|
656
674
|
if (routedVerbatim.has(prop)) continue;
|
|
657
675
|
const pp = plan.propMap?.[prop];
|
|
658
676
|
if (!pp) {
|
|
677
|
+
this.recordDrop(instance, { prop, raw, component: node.component, path, reason: "no-projection" });
|
|
659
678
|
this.diagnostics.push(
|
|
660
679
|
{
|
|
661
680
|
code: "surface-prop-dropped",
|
|
@@ -676,6 +695,7 @@ class SurfaceEmitter {
|
|
|
676
695
|
const mapped = pp.valueMap ? pp.valueMap[String(raw)] : undefined;
|
|
677
696
|
const value = pp.valueMap ? (mapped ?? pp.default) : raw;
|
|
678
697
|
if (value === undefined) {
|
|
698
|
+
this.recordDrop(instance, { prop, dest: pp.a2ui, raw, component: node.component, path, reason: "no-value" });
|
|
679
699
|
this.diagnostics.push(
|
|
680
700
|
{
|
|
681
701
|
code: "surface-prop-value-dropped",
|
|
@@ -710,6 +730,104 @@ class SurfaceEmitter {
|
|
|
710
730
|
}
|
|
711
731
|
}
|
|
712
732
|
|
|
733
|
+
private recordDrop(
|
|
734
|
+
instance: Json,
|
|
735
|
+
entry: { prop: string; dest?: string; raw: unknown; component: string; path: string; reason: "no-projection" | "no-value" },
|
|
736
|
+
): void {
|
|
737
|
+
const list = this.droppedProps.get(instance);
|
|
738
|
+
if (list) list.push(entry);
|
|
739
|
+
else this.droppedProps.set(instance, [entry]);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Final guard (ratified 2026-08-10): never return a surface whose instances
|
|
744
|
+
* the emitted catalog itself refuses. Two checks per instance, against its
|
|
745
|
+
* own ComponentPlan:
|
|
746
|
+
*
|
|
747
|
+
* - every catalog-required prop carries a value (`plan.required` — the
|
|
748
|
+
* same list mapping.ts emits as `required: ["component", ...]`);
|
|
749
|
+
* - every propMap-projected prop with a `targetEnum` carries a member of
|
|
750
|
+
* that enum (without a valueMap the authored value passes through
|
|
751
|
+
* verbatim, so an off-vocabulary value used to land silently).
|
|
752
|
+
*
|
|
753
|
+
* On any violation the whole emission refuses with ONE aggregated message
|
|
754
|
+
* citing each violation and — where the node's recorded drop diagnostics
|
|
755
|
+
* recover it — the cause. This covers the observed defect class
|
|
756
|
+
* (required-presence + enum-membership); full-schema rigor stays gate A3's
|
|
757
|
+
* job, downstream, as defense in depth. Warnings and fidelity recording are
|
|
758
|
+
* untouched: a surface that emits, emits byte-identically to before.
|
|
759
|
+
*/
|
|
760
|
+
refuseCatalogInvalid(): void {
|
|
761
|
+
const byA2ui = new Map<string, ComponentPlan>();
|
|
762
|
+
for (const plan of [...this.profile.components, ...this.profile.synthesized]) {
|
|
763
|
+
// Transparent plans dissolve at emission — no instance ever carries them.
|
|
764
|
+
if (!surfaceModelOf(plan).transparent) byA2ui.set(plan.a2ui, plan);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const violations: string[] = [];
|
|
768
|
+
for (const inst of this.components) {
|
|
769
|
+
const plan = byA2ui.get(String(inst.component));
|
|
770
|
+
if (!plan) continue; // no plan to check against: gate A3 arbitrates downstream
|
|
771
|
+
const where = `${inst.component}#${inst.id}`;
|
|
772
|
+
const drops = this.droppedProps.get(inst) ?? [];
|
|
773
|
+
|
|
774
|
+
for (const req of plan.required) {
|
|
775
|
+
if (inst[req] !== undefined) continue;
|
|
776
|
+
violations.push(`${where}: required prop '${req}' has no value after emission${this.missingCause(plan, req, drops)}`);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
for (const [src, pp] of Object.entries(plan.propMap ?? {})) {
|
|
780
|
+
if (!pp.targetEnum) continue;
|
|
781
|
+
const value = inst[pp.a2ui];
|
|
782
|
+
if (value === undefined) continue;
|
|
783
|
+
if (typeof value === "string" && pp.targetEnum.includes(value)) continue;
|
|
784
|
+
const cause = pp.valueMap ? "" : ` — authored 'props.${src}' passed through verbatim (this propMap declares no valueMap)`;
|
|
785
|
+
violations.push(
|
|
786
|
+
`${where}: prop '${pp.a2ui}' value ${JSON.stringify(value)} is outside the catalog's enum (allowed: ${pp.targetEnum.join(", ")})${cause}`,
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (violations.length > 0) {
|
|
792
|
+
throw new EmitSurfaceError(
|
|
793
|
+
`refusing to emit: ${violations.length} instance value(s) would not validate against the emitted catalog ` +
|
|
794
|
+
`(gate A3 would refuse this surface downstream):\n` +
|
|
795
|
+
violations.map((v) => ` - ${v}`).join("\n"),
|
|
796
|
+
"$",
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* The recoverable cause for a required prop with no value: the authored
|
|
803
|
+
* prop this node DID carry that was dropped (recorded at PropMap time),
|
|
804
|
+
* and/or where the plan's own routes expect the value to come from.
|
|
805
|
+
*/
|
|
806
|
+
private missingCause(
|
|
807
|
+
plan: ComponentPlan,
|
|
808
|
+
req: string,
|
|
809
|
+
drops: Array<{ prop: string; dest?: string; raw: unknown; component: string; path: string; reason: "no-projection" | "no-value" }>,
|
|
810
|
+
): string {
|
|
811
|
+
const model = surfaceModelOf(plan);
|
|
812
|
+
const feeders = model.routes.filter((r) => r.to.name === req);
|
|
813
|
+
const subs = [
|
|
814
|
+
...new Set(feeders.flatMap((r) => r.from.flatMap((s) => ("subs" in s ? [...(s.subs as string[])] : [])))),
|
|
815
|
+
];
|
|
816
|
+
const source =
|
|
817
|
+
subs.length > 0
|
|
818
|
+
? ` (${req} comes from the ${subs.map((s) => `'${s}'`).join(" / ")} sub-component${subs.length > 1 ? "s" : ""})`
|
|
819
|
+
: feeders.length > 0
|
|
820
|
+
? ` (${req} is fed by ${feeders.map((r) => r.from.map(describeSelector).join(" | ")).join(", ")})`
|
|
821
|
+
: "";
|
|
822
|
+
const drop = drops.find((d) => d.prop === req || d.dest === req);
|
|
823
|
+
if (!drop) return source;
|
|
824
|
+
const why =
|
|
825
|
+
drop.reason === "no-projection"
|
|
826
|
+
? `authored 'props.${drop.prop}' on '${drop.component}' has no A2UI projection`
|
|
827
|
+
: `authored 'props.${drop.prop}'=${JSON.stringify(drop.raw)} on '${drop.component}' has no projection for that value and no default`;
|
|
828
|
+
return ` — ${why}${source}`;
|
|
829
|
+
}
|
|
830
|
+
|
|
713
831
|
/**
|
|
714
832
|
* Refuse when a consumed subtree contains a component the profile declared a
|
|
715
833
|
* casualty. Consumption is how compounds fold their parts into props; it is
|
|
@@ -1546,8 +1664,10 @@ class SurfaceEmitter {
|
|
|
1546
1664
|
if (value !== undefined) {
|
|
1547
1665
|
pending.push({ prop: d.to.name, value, origin: d.origin, donorPath: `${path}${suffix}`, donorComponent });
|
|
1548
1666
|
}
|
|
1549
|
-
// Nothing to donate is not an error: the destination stays absent
|
|
1550
|
-
//
|
|
1667
|
+
// Nothing to donate is not an error: the destination stays absent —
|
|
1668
|
+
// refused at emission by the final catalog-validity guard when it is
|
|
1669
|
+
// required, arbitrated by gate A3 otherwise. Relocation, never
|
|
1670
|
+
// synthesis (the lift rule).
|
|
1551
1671
|
}
|
|
1552
1672
|
|
|
1553
1673
|
// The boundary's own text rises as body text unless a self.text
|
package/src/validate/ajv.ts
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* a2ui-catalog.meta.<ver>.json (the literal "catalog schema" check; this is what
|
|
13
13
|
* makes v0.9.1 vs v1.0 conformance distinct — theme vs surfaceProperties).
|
|
14
14
|
* 3. instance: every component instance in the hand-authored surface validates
|
|
15
|
-
* against the catalog's own #/$defs/anyComponent
|
|
15
|
+
* against the catalog's own #/$defs/anyComponent — checked by manual
|
|
16
|
+
* discrimination (each instance against its own #/components/<name>
|
|
17
|
+
* branch), which is semantically equivalent and keeps every reported
|
|
18
|
+
* error inside the instance's own branch. See the gate 3 body.
|
|
16
19
|
*/
|
|
17
20
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
18
21
|
import addFormats from "ajv-formats";
|
|
@@ -24,6 +27,25 @@ export interface GateResult {
|
|
|
24
27
|
pass: boolean;
|
|
25
28
|
detail: string;
|
|
26
29
|
errors?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Structured per-instance evidence for gate 3 failures (advanced channel
|
|
32
|
+
* for downstream UIs). The strings in `errors` remain the primary
|
|
33
|
+
* user-facing form; this preserves ajv's keyword/params/schemaPath, which
|
|
34
|
+
* the strings deliberately compress.
|
|
35
|
+
*/
|
|
36
|
+
errorDetails?: Array<{
|
|
37
|
+
/** `component#id` — same prefix the string form carries. */
|
|
38
|
+
instance: string;
|
|
39
|
+
component: string;
|
|
40
|
+
id: string;
|
|
41
|
+
errors: Array<{
|
|
42
|
+
instancePath?: string;
|
|
43
|
+
schemaPath?: string;
|
|
44
|
+
keyword?: string;
|
|
45
|
+
params?: unknown;
|
|
46
|
+
message?: string;
|
|
47
|
+
}>;
|
|
48
|
+
}>;
|
|
27
49
|
}
|
|
28
50
|
|
|
29
51
|
export interface ValidationReport {
|
|
@@ -171,20 +193,64 @@ export function validateCatalog(
|
|
|
171
193
|
// Belt and braces: gate 1 has already proven every ref resolves, but a
|
|
172
194
|
// raw ajv throw must never escape this function regardless.
|
|
173
195
|
const failures: string[] = [];
|
|
196
|
+
const errorDetails: NonNullable<GateResult["errorDetails"]> = [];
|
|
174
197
|
let instances: Json[] = [];
|
|
175
198
|
try {
|
|
176
199
|
const ajv = newAjv();
|
|
177
200
|
ajv.addSchema(catalog as unknown as Json, catalog.$id);
|
|
178
|
-
const validateAny = ajv.getSchema(`${catalog.$id}#/$defs/anyComponent`);
|
|
179
201
|
instances = extractInstances(surface);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
202
|
+
// Manual discrimination instead of the flat `#/$defs/anyComponent`
|
|
203
|
+
// oneOf. Semantically equivalent: every branch of the emitted
|
|
204
|
+
// anyComponent is `{$ref: "#/components/<name>"}` and each component
|
|
205
|
+
// schema pins `component: {const: <name>}` inside its allOf (and
|
|
206
|
+
// requires it), so an instance tagged component X can only ever match
|
|
207
|
+
// branch X — validating the instance against ITS OWN branch accepts
|
|
208
|
+
// and rejects exactly the same instances the oneOf does. What changes
|
|
209
|
+
// is the report: allErrors WITHIN the matching branch (rigor
|
|
210
|
+
// preserved, every genuine error surfaced) without echoing every
|
|
211
|
+
// other branch's const/required/unevaluatedProperties noise.
|
|
212
|
+
const admitted = Object.keys(catalog.components ?? {});
|
|
213
|
+
for (const inst of instances) {
|
|
214
|
+
const comp = String(inst.component);
|
|
215
|
+
const id = String(inst.id);
|
|
216
|
+
const where = `${comp}#${id}`;
|
|
217
|
+
if (!admitted.includes(comp)) {
|
|
218
|
+
failures.push(
|
|
219
|
+
`${where}: component '${comp}' is not in this catalog (${admitted.length} components admitted)`,
|
|
220
|
+
);
|
|
221
|
+
errorDetails.push({
|
|
222
|
+
instance: where,
|
|
223
|
+
component: comp,
|
|
224
|
+
id,
|
|
225
|
+
errors: [
|
|
226
|
+
{
|
|
227
|
+
message: `component '${comp}' is not in this catalog`,
|
|
228
|
+
params: { admittedComponents: admitted },
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
});
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const validateBranch = ajv.getSchema(`${catalog.$id}#/components/${comp}`);
|
|
235
|
+
if (!validateBranch) {
|
|
236
|
+
failures.push(`${where}: could not resolve #/components/${comp} from the catalog.`);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (!validateBranch(inst)) {
|
|
240
|
+
const errs = validateBranch.errors ?? [];
|
|
241
|
+
for (const e of errs) failures.push(`${where}: ${fmtErr(e)}`);
|
|
242
|
+
errorDetails.push({
|
|
243
|
+
instance: where,
|
|
244
|
+
component: comp,
|
|
245
|
+
id,
|
|
246
|
+
errors: errs.map((e) => ({
|
|
247
|
+
instancePath: e.instancePath,
|
|
248
|
+
schemaPath: e.schemaPath,
|
|
249
|
+
keyword: e.keyword,
|
|
250
|
+
params: e.params as unknown,
|
|
251
|
+
message: e.message,
|
|
252
|
+
})),
|
|
253
|
+
});
|
|
188
254
|
}
|
|
189
255
|
}
|
|
190
256
|
} catch (e) {
|
|
@@ -198,6 +264,7 @@ export function validateCatalog(
|
|
|
198
264
|
? `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
|
|
199
265
|
: `${failures.length} instance validation error(s).`,
|
|
200
266
|
errors: failures.length ? failures : undefined,
|
|
267
|
+
...(errorDetails.length ? { errorDetails } : {}),
|
|
201
268
|
});
|
|
202
269
|
}
|
|
203
270
|
}
|
|
@@ -205,6 +272,23 @@ export function validateCatalog(
|
|
|
205
272
|
return { version, pass: gates.every((g) => g.pass), gates };
|
|
206
273
|
}
|
|
207
274
|
|
|
208
|
-
|
|
209
|
-
|
|
275
|
+
/**
|
|
276
|
+
* One ajv error as a user-facing line: instancePath + message, enriched from
|
|
277
|
+
* the error's params where they carry the actionable detail ajv's message
|
|
278
|
+
* omits — the allowed enum values, the expected const, or the name of the
|
|
279
|
+
* offending unevaluated/additional property.
|
|
280
|
+
*/
|
|
281
|
+
function fmtErr(e: { instancePath?: string; keyword?: string; params?: unknown; message?: string }): string {
|
|
282
|
+
const params = (e.params ?? {}) as Record<string, unknown>;
|
|
283
|
+
let out = `${e.instancePath || "(root)"} ${e.message ?? ""}`.trim();
|
|
284
|
+
if (e.keyword === "enum" && Array.isArray(params.allowedValues)) {
|
|
285
|
+
out += ` (allowed: ${(params.allowedValues as unknown[]).map((v) => String(v)).join(", ")})`;
|
|
286
|
+
} else if (e.keyword === "const" && "allowedValue" in params) {
|
|
287
|
+
out += ` (expected: ${JSON.stringify(params.allowedValue)})`;
|
|
288
|
+
} else if (e.keyword === "unevaluatedProperties" && typeof params.unevaluatedProperty === "string") {
|
|
289
|
+
out += ` ('${params.unevaluatedProperty}')`;
|
|
290
|
+
} else if (e.keyword === "additionalProperties" && typeof params.additionalProperty === "string") {
|
|
291
|
+
out += ` ('${params.additionalProperty}')`;
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
210
294
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v0_9_1.json",
|
|
4
|
-
"title": "A2UI catalog shape (v0.9.1)",
|
|
5
|
-
"description": "Structural invariants an A2UI v0.9.1 catalog must satisfy, derived from the checked-in basic catalog fixture. The version-distinguishing requirement is $defs.theme (with primaryColor).",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"required": ["$schema", "$id", "catalogId", "title", "description", "components", "$defs"],
|
|
8
|
-
"properties": {
|
|
9
|
-
"catalogId": { "type": "string", "format": "uri" },
|
|
10
|
-
"$id": { "type": "string", "format": "uri" },
|
|
11
|
-
"components": {
|
|
12
|
-
"type": "object",
|
|
13
|
-
"minProperties": 1,
|
|
14
|
-
"additionalProperties": {
|
|
15
|
-
"type": "object",
|
|
16
|
-
"required": ["allOf", "unevaluatedProperties"],
|
|
17
|
-
"properties": {
|
|
18
|
-
"allOf": { "type": "array", "minItems": 1 },
|
|
19
|
-
"unevaluatedProperties": { "const": false }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"$defs": {
|
|
24
|
-
"type": "object",
|
|
25
|
-
"required": ["anyComponent", "theme"],
|
|
26
|
-
"not": { "required": ["surfaceProperties"] },
|
|
27
|
-
"properties": {
|
|
28
|
-
"anyComponent": { "type": "object", "required": ["oneOf"] },
|
|
29
|
-
"theme": {
|
|
30
|
-
"type": "object",
|
|
31
|
-
"required": ["properties"],
|
|
32
|
-
"properties": {
|
|
33
|
-
"properties": { "type": "object", "required": ["primaryColor"] }
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v1_0.json",
|
|
4
|
-
"title": "A2UI catalog shape (v1.0)",
|
|
5
|
-
"description": "Structural invariants an A2UI v1.0 catalog must satisfy, derived from the checked-in basic catalog fixture. The version-distinguishing requirement is $defs.surfaceProperties (and the absence of $defs.theme).",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"required": ["$schema", "$id", "catalogId", "title", "description", "components", "$defs"],
|
|
8
|
-
"properties": {
|
|
9
|
-
"catalogId": { "type": "string", "format": "uri" },
|
|
10
|
-
"$id": { "type": "string", "format": "uri" },
|
|
11
|
-
"instructions": { "type": "string" },
|
|
12
|
-
"components": {
|
|
13
|
-
"type": "object",
|
|
14
|
-
"minProperties": 1,
|
|
15
|
-
"additionalProperties": {
|
|
16
|
-
"type": "object",
|
|
17
|
-
"required": ["allOf", "unevaluatedProperties"],
|
|
18
|
-
"properties": {
|
|
19
|
-
"allOf": { "type": "array", "minItems": 1 },
|
|
20
|
-
"unevaluatedProperties": { "const": false }
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"$defs": {
|
|
25
|
-
"type": "object",
|
|
26
|
-
"required": ["anyComponent", "surfaceProperties"],
|
|
27
|
-
"not": { "required": ["theme"] },
|
|
28
|
-
"properties": {
|
|
29
|
-
"anyComponent": { "type": "object", "required": ["oneOf"] },
|
|
30
|
-
"surfaceProperties": { "type": "object", "required": ["properties"] }
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|