@aestheticfunction/dspack-emit 0.6.0 → 0.8.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 +23 -15
- package/dist/cli.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/targets/a2ui/surface.js +108 -4
- package/dist/transform/emit-v1_0.d.ts +45 -0
- package/dist/transform/emit-v1_0.js +190 -0
- package/dist/transform/emit.d.ts +6 -9
- package/dist/transform/emit.js +5 -44
- package/dist/transform/index.js +3 -1
- package/dist/types.d.ts +4 -0
- package/dist/validate/ajv.d.ts +26 -0
- package/dist/validate/ajv.js +150 -23
- package/dist/validate/meta/a2ui-v1_0.d.ts +9 -0
- package/dist/validate/meta/a2ui-v1_0.js +811 -0
- package/dist/validate/meta/catalog-meta.js +34 -21
- package/package.json +6 -2
- package/src/byte-neutral.test.ts +6 -3
- package/src/cli.ts +5 -2
- package/src/engine-boundary.test.ts +10 -0
- package/src/functions.test.ts +48 -1
- package/src/index.ts +1 -1
- package/src/instance-diagnostics.test.ts +194 -0
- package/src/profile-v2.test.ts +1 -1
- 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/transform/emit-v1_0.ts +215 -0
- package/src/transform/emit.ts +10 -54
- package/src/transform/index.ts +3 -1
- package/src/transform.test.ts +33 -1
- package/src/types.ts +4 -0
- package/src/v1_0-catalog.test.ts +267 -0
- package/src/validate/ajv.ts +169 -22
- package/src/validate/meta/a2ui-catalog.meta.1_0.json +67 -13
- package/src/validate/meta/a2ui-v1_0.ts +820 -0
- package/src/validate/meta/catalog-meta.ts +34 -21
- 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
|
@@ -83,11 +83,12 @@ export const catalogMetaSchemas = {
|
|
|
83
83
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
84
84
|
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v1_0.json",
|
|
85
85
|
"title": "A2UI catalog shape (v1.0)",
|
|
86
|
-
"description": "
|
|
86
|
+
"description": "dspack's own invariants for an A2UI v1.0 catalog, checked alongside the official catalog definition (fixtures/a2ui/catalog_definition.v1_0.json, pinned in fixtures/a2ui/PIN.md): it declares protocolVersion 1.0, carries neither the 0.9 theme nor the pre-release surfaceProperties, and never wraps a component in ComponentCommon, which the envelope composes.",
|
|
87
87
|
"type": "object",
|
|
88
88
|
"required": [
|
|
89
89
|
"$schema",
|
|
90
90
|
"$id",
|
|
91
|
+
"protocolVersion",
|
|
91
92
|
"catalogId",
|
|
92
93
|
"title",
|
|
93
94
|
"description",
|
|
@@ -95,6 +96,9 @@ export const catalogMetaSchemas = {
|
|
|
95
96
|
"$defs"
|
|
96
97
|
],
|
|
97
98
|
"properties": {
|
|
99
|
+
"protocolVersion": {
|
|
100
|
+
"const": "1.0"
|
|
101
|
+
},
|
|
98
102
|
"catalogId": {
|
|
99
103
|
"type": "string",
|
|
100
104
|
"format": "uri"
|
|
@@ -111,17 +115,23 @@ export const catalogMetaSchemas = {
|
|
|
111
115
|
"minProperties": 1,
|
|
112
116
|
"additionalProperties": {
|
|
113
117
|
"type": "object",
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
"not": {
|
|
119
|
+
"required": [
|
|
120
|
+
"allOf"
|
|
121
|
+
],
|
|
122
|
+
"properties": {
|
|
123
|
+
"allOf": {
|
|
124
|
+
"contains": {
|
|
125
|
+
"required": [
|
|
126
|
+
"$ref"
|
|
127
|
+
],
|
|
128
|
+
"properties": {
|
|
129
|
+
"$ref": {
|
|
130
|
+
"pattern": "ComponentCommon$"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
137
|
}
|
|
@@ -130,11 +140,20 @@ export const catalogMetaSchemas = {
|
|
|
130
140
|
"type": "object",
|
|
131
141
|
"required": [
|
|
132
142
|
"anyComponent",
|
|
133
|
-
"
|
|
143
|
+
"anyFunction"
|
|
134
144
|
],
|
|
135
145
|
"not": {
|
|
136
|
-
"
|
|
137
|
-
|
|
146
|
+
"anyOf": [
|
|
147
|
+
{
|
|
148
|
+
"required": [
|
|
149
|
+
"theme"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"required": [
|
|
154
|
+
"surfaceProperties"
|
|
155
|
+
]
|
|
156
|
+
}
|
|
138
157
|
]
|
|
139
158
|
},
|
|
140
159
|
"properties": {
|
|
@@ -143,12 +162,6 @@ export const catalogMetaSchemas = {
|
|
|
143
162
|
"required": [
|
|
144
163
|
"oneOf"
|
|
145
164
|
]
|
|
146
|
-
},
|
|
147
|
-
"surfaceProperties": {
|
|
148
|
-
"type": "object",
|
|
149
|
-
"required": [
|
|
150
|
-
"properties"
|
|
151
|
-
]
|
|
152
165
|
}
|
|
153
166
|
}
|
|
154
167
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
package/src/byte-neutral.test.ts
CHANGED
|
@@ -52,15 +52,18 @@ const CATALOGS: Record<string, string> = {
|
|
|
52
52
|
// only credible if authoring a profile as a file changes nothing.
|
|
53
53
|
"shadcn/ts/0.9.1": "7c1b72dfd83dde14",
|
|
54
54
|
"shadcn/json/0.9.1": "7c1b72dfd83dde14",
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// INTENTIONAL MOVE (P1a, A2UI 1.0 catalog conformance): the 1.0 catalog now follows the pinned upstream 1.0
|
|
56
|
+
// specification (src/transform/emit-v1_0.ts): protocolVersion, common_types references, flat components,
|
|
57
|
+
// anyFunction, no surfaceProperties. Every 0.9.1 pin above and below is unchanged.
|
|
58
|
+
"shadcn/ts/1.0": "4512c002e8e5d25b",
|
|
59
|
+
"shadcn/json/1.0": "4512c002e8e5d25b",
|
|
57
60
|
// INTENTIONAL MOVE (scaffold rewrite): the scaffold now emits the v2
|
|
58
61
|
// primitive language and derives children/text routes from the contract's
|
|
59
62
|
// worked examples, so scaffolded catalogs carry the slots the old scaffold
|
|
60
63
|
// omitted. The old digests described a scaffold that was surface-unusable
|
|
61
64
|
// for props-based contracts; these describe one that emits.
|
|
62
65
|
"astryx-scaffold/0.9.1": "ffb8fd24891bedfc",
|
|
63
|
-
"astryx-scaffold/1.0": "
|
|
66
|
+
"astryx-scaffold/1.0": "0e38fc1fed8f31ed", // INTENTIONAL MOVE (P1a), as for shadcn/1.0 above
|
|
64
67
|
};
|
|
65
68
|
|
|
66
69
|
const SURFACES: Record<string, string> = {
|
package/src/cli.ts
CHANGED
|
@@ -107,9 +107,12 @@ function parseArgs(argv: string[]): Args {
|
|
|
107
107
|
in: input!,
|
|
108
108
|
version: (version ?? "0.9.1") as A2uiVersion,
|
|
109
109
|
out: m.get("out") ?? "out",
|
|
110
|
-
// The sample-surface default is a repo-relative fixture
|
|
110
|
+
// The sample-surface default is a repo-relative fixture, one per A2UI
|
|
111
|
+
// version (the 1.0 sample is in 1.0 message form); external callers
|
|
111
112
|
// (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
|
|
112
|
-
surface:
|
|
113
|
+
surface:
|
|
114
|
+
m.get("surface") ??
|
|
115
|
+
(profile ? undefined : version === "1.0" ? "surface/settings-card.v1_0.surface.json" : "surface/settings-card.surface.json"),
|
|
113
116
|
profile,
|
|
114
117
|
emitSurface: m.get("emit-surface"),
|
|
115
118
|
strictCoverage: m.get("strict-coverage") === "true",
|
|
@@ -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"]);
|
package/src/functions.test.ts
CHANGED
|
@@ -111,8 +111,55 @@ const okSurface = (call: object) => ({
|
|
|
111
111
|
],
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
+
/** The same instance in the A2UI 1.0 spelling: the trait is `@checks`, a call is `{"@call": …}`. */
|
|
115
|
+
const okSurfaceV1_0 = (call: object) => ({
|
|
116
|
+
messages: [
|
|
117
|
+
{
|
|
118
|
+
updateComponents: {
|
|
119
|
+
surfaceId: "s",
|
|
120
|
+
components: [{ id: "root", component: "TextField", label: "Email", "@checks": [{ condition: call, message: "Required." }] }],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
|
|
114
126
|
describe("declared functions reach the catalog and constrain every call", () => {
|
|
115
|
-
|
|
127
|
+
it("the 1.0 catalog declares each function as a call-validation schema, and anyFunction lists them (a2ui 1.0)", () => {
|
|
128
|
+
const out = transformFromJson(doc, { profile: loadProfile(profileDoc()), a2uiVersion: "1.0" });
|
|
129
|
+
const catalog = out.catalog as unknown as {
|
|
130
|
+
functions?: Record<string, { returnType: string; properties: Record<string, { const?: string }>; required: string[] }>;
|
|
131
|
+
$defs: Record<string, { oneOf?: Array<{ $ref: string }> }>;
|
|
132
|
+
};
|
|
133
|
+
expect(Object.keys(catalog.functions ?? {})).toEqual(["checkRequired", "matchesRegexp"]);
|
|
134
|
+
expect(catalog.functions!.checkRequired.returnType).toBe("boolean");
|
|
135
|
+
expect(catalog.functions!.checkRequired.properties["@call"]).toEqual({ const: "checkRequired" });
|
|
136
|
+
expect(catalog.functions!.matchesRegexp.required).toEqual(["@call", "args"]);
|
|
137
|
+
expect(catalog.$defs.anyFunction?.oneOf).toEqual([{ $ref: "#/functions/checkRequired" }, { $ref: "#/functions/matchesRegexp" }]);
|
|
138
|
+
// 1.0 references the standard FunctionCall in common_types.json; the catalog carries no copy of it.
|
|
139
|
+
expect(Object.keys(catalog.$defs)).toEqual(["anyComponent", "anyFunction"]);
|
|
140
|
+
expect(out.validation.gates.find((g) => g.name === "schema-compile + no-external-ref")?.pass).toBe(true);
|
|
141
|
+
expect(out.validation.gates.find((g) => g.name === "catalog-shape")?.pass).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("1.0: a declared call passes, an undeclared one and a missing required argument are refused", () => {
|
|
145
|
+
const gate = (call: object) =>
|
|
146
|
+
transformFromJson(doc, { profile: loadProfile(profileDoc()), a2uiVersion: "1.0", surface: okSurfaceV1_0(call) }).validation.gates.find((g) => g.name === "instance")?.pass;
|
|
147
|
+
expect(gate({ "@call": "checkRequired" })).toBe(true);
|
|
148
|
+
expect(gate({ "@call": "matchesRegexp", args: { pattern: "^.+@.+$" } })).toBe(true);
|
|
149
|
+
expect(gate({ "@call": "checkVibes" })).toBe(false);
|
|
150
|
+
expect(gate({ "@call": "matchesRegexp" })).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("1.0 closes the 0.9.1 hole: with no functions declared, anyFunction admits no call at all", () => {
|
|
154
|
+
const bare = profileDoc();
|
|
155
|
+
delete bare.functions;
|
|
156
|
+
const out = transformFromJson(doc, { profile: loadProfile(bare), a2uiVersion: "1.0", surface: okSurfaceV1_0({ "@call": "checkVibes" }) });
|
|
157
|
+
expect((out.catalog as { $defs: Record<string, unknown> }).$defs.anyFunction).toEqual({ not: {} });
|
|
158
|
+
expect(out.validation.gates.find((g) => g.name === "catalog-shape")?.pass).toBe(true);
|
|
159
|
+
expect(out.validation.gates.find((g) => g.name === "instance")?.pass).toBe(false);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
for (const version of ["0.9.1"] as const) {
|
|
116
163
|
it(`the catalog carries the functions section and the call constraint (a2ui ${version})`, () => {
|
|
117
164
|
const out = transformFromJson(doc, { profile: loadProfile(profileDoc()), a2uiVersion: version });
|
|
118
165
|
const catalog = out.catalog as unknown as {
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { ProfileContractError, type ProfileContractIssue } from "./transform/val
|
|
|
12
12
|
export { ProfileParseError, type ParseIssue, type SurfaceV2 } from "./transform/parse-v2.js";
|
|
13
13
|
export type { SurfaceFidelityEntry } from "./types.js";
|
|
14
14
|
export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
|
|
15
|
-
export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
15
|
+
export { validateCatalog, extractInstances, catalogCompanionSchemas, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
16
16
|
export {
|
|
17
17
|
emitSurface,
|
|
18
18
|
slug,
|
|
@@ -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
|
+
});
|
package/src/profile-v2.test.ts
CHANGED
|
@@ -62,7 +62,7 @@ const VERSIONS: A2uiVersion[] = ["0.9.1", "1.0"];
|
|
|
62
62
|
/** The v1 pins this file must reproduce — same values as byte-neutral.test.ts. */
|
|
63
63
|
const V1_CATALOG_DIGESTS: Record<string, string> = {
|
|
64
64
|
"0.9.1": "7c1b72dfd83dde14",
|
|
65
|
-
"1.0": "
|
|
65
|
+
"1.0": "4512c002e8e5d25b", // moved with byte-neutral.test.ts (P1a, A2UI 1.0 catalog conformance)
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
describe("the v2 re-spelling emits byte-identically to the v1 profile", () => {
|
|
@@ -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", () => {
|