@aestheticfunction/dspack-emit 0.4.1 → 0.6.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 +16 -6
- package/dist/cli.js +56 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/targets/a2ui/diagnostics.d.ts +110 -0
- package/dist/targets/a2ui/diagnostics.js +94 -0
- package/dist/targets/a2ui/surface.d.ts +28 -9
- package/dist/targets/a2ui/surface.js +1004 -222
- package/dist/transform/desugar.d.ts +32 -0
- package/dist/transform/desugar.js +156 -0
- package/dist/transform/emit.js +59 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/mapping.d.ts +0 -6
- package/dist/transform/mapping.js +66 -2
- package/dist/transform/model.d.ts +368 -0
- package/dist/transform/model.js +169 -0
- package/dist/transform/parse-v2.d.ts +109 -0
- package/dist/transform/parse-v2.js +479 -0
- package/dist/transform/profile-load.d.ts +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +608 -0
- package/dist/transform/profiles.d.ts +31 -1
- package/dist/transform/scaffold.d.ts +29 -12
- package/dist/transform/scaffold.js +91 -31
- package/dist/transform/shadcn-v2-respelling.d.ts +77 -0
- package/dist/transform/shadcn-v2-respelling.js +456 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +136 -0
- package/dist/types.d.ts +23 -0
- package/dist/validate/ajv.js +96 -25
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/a0.test.ts +235 -0
- package/src/byte-neutral.test.ts +246 -0
- package/src/cli.ts +60 -0
- package/src/dangling-ref.test.ts +118 -0
- package/src/desugar.test.ts +162 -0
- package/src/engine-boundary.test.ts +248 -0
- package/src/eval-fixture.test.ts +102 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +369 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +5 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/t1.test.ts +369 -0
- package/src/t2.test.ts +222 -0
- package/src/t3.test.ts +304 -0
- package/src/t4.test.ts +278 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +1468 -235
- package/src/transform/desugar.ts +194 -0
- package/src/transform/emit.ts +65 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/mapping.ts +60 -2
- package/src/transform/model.ts +427 -0
- package/src/transform/parse-v2.ts +608 -0
- package/src/transform/profile-load.ts +104 -22
- package/src/transform/profile-schema-v2.ts +608 -0
- package/src/transform/profile.v2.schema.json +600 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +475 -0
- package/src/transform/validate-v2.ts +174 -0
- package/src/types.ts +32 -0
- package/src/validate/ajv.ts +89 -26
- package/src/validate-v2.test.ts +173 -0
package/dist/validate/ajv.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* approach A2UI uses in specification/scripts/validate.py
|
|
4
4
|
* (draft 2020-12, strict:false, ajv-formats):
|
|
5
5
|
*
|
|
6
|
-
* 1. schema-compile + no-external-ref: ajv compiles the catalog AS a JSON
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* 1. schema-compile + no-external-ref: ajv compiles the catalog AS a JSON
|
|
7
|
+
* Schema, no `$ref` points outside it, and — because ajv defers ref
|
|
8
|
+
* resolution past compile() — every internal `$ref` is resolved by this
|
|
9
|
+
* gate itself, so a dangling pointer is a pathed finding here rather than
|
|
10
|
+
* a silent pass or a raw MissingRefError out of gate 3.
|
|
9
11
|
* 2. catalog-shape: the catalog validates against the version-specific
|
|
10
12
|
* a2ui-catalog.meta.<ver>.json (the literal "catalog schema" check; this is what
|
|
11
13
|
* makes v0.9.1 vs v1.0 conformance distinct — theme vs surfaceProperties).
|
|
@@ -36,6 +38,61 @@ function externalRefs(node, acc = []) {
|
|
|
36
38
|
}
|
|
37
39
|
return acc;
|
|
38
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Collect every INTERNAL `$ref` that does not resolve inside the catalog
|
|
43
|
+
* document, with the JSON path of the offending `$ref` keyword.
|
|
44
|
+
*
|
|
45
|
+
* This is what makes gate 1's documented guarantee true. ajv defers ref
|
|
46
|
+
* resolution past `compile()`, so a structural slot schema (or any other
|
|
47
|
+
* authored-schema channel) carrying `{$ref: "#/$defs/DoesNotExist"}` used to
|
|
48
|
+
* produce either all-gates-PASS (no instances checked) or a raw
|
|
49
|
+
* MissingRefError thrown out of gate 3 — pass-or-crash, never a finding.
|
|
50
|
+
* Resolving the pointers ourselves turns the whole class into a pathed gate
|
|
51
|
+
* failure at one boundary, for every channel at once.
|
|
52
|
+
*/
|
|
53
|
+
function danglingInternalRefs(root) {
|
|
54
|
+
const bad = [];
|
|
55
|
+
const resolves = (pointer) => {
|
|
56
|
+
if (pointer === "#" || pointer === "#/")
|
|
57
|
+
return true;
|
|
58
|
+
if (!pointer.startsWith("#/"))
|
|
59
|
+
return false; // #foo anchors are not used in our catalogs
|
|
60
|
+
let node = root;
|
|
61
|
+
for (const raw of pointer.slice(2).split("/")) {
|
|
62
|
+
const key = decodeURIComponent(raw).replaceAll("~1", "/").replaceAll("~0", "~");
|
|
63
|
+
if (Array.isArray(node)) {
|
|
64
|
+
const i = Number(key);
|
|
65
|
+
if (!Number.isInteger(i) || i < 0 || i >= node.length)
|
|
66
|
+
return false;
|
|
67
|
+
node = node[i];
|
|
68
|
+
}
|
|
69
|
+
else if (node && typeof node === "object" && key in node) {
|
|
70
|
+
node = node[key];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
const walk = (node, at) => {
|
|
79
|
+
if (Array.isArray(node)) {
|
|
80
|
+
node.forEach((n, i) => walk(n, `${at}/${i}`));
|
|
81
|
+
}
|
|
82
|
+
else if (node && typeof node === "object") {
|
|
83
|
+
for (const [k, v] of Object.entries(node)) {
|
|
84
|
+
if (k === "$ref" && typeof v === "string" && v.startsWith("#") && !resolves(v)) {
|
|
85
|
+
bad.push(`${at}/$ref: '${v}' does not resolve inside this catalog`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
walk(v, `${at}/${k}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
walk(root, "");
|
|
94
|
+
return bad;
|
|
95
|
+
}
|
|
39
96
|
/** Pull every component instance (object with string `component` + `id`) from a surface. */
|
|
40
97
|
export function extractInstances(surface, acc = []) {
|
|
41
98
|
if (Array.isArray(surface)) {
|
|
@@ -53,8 +110,9 @@ export function extractInstances(surface, acc = []) {
|
|
|
53
110
|
}
|
|
54
111
|
export function validateCatalog(catalog, version, surface) {
|
|
55
112
|
const gates = [];
|
|
56
|
-
// Gate 1 — schema compile + no external $ref.
|
|
113
|
+
// Gate 1 — schema compile + no external $ref + every internal $ref resolves.
|
|
57
114
|
const exts = externalRefs(catalog);
|
|
115
|
+
const dangling = danglingInternalRefs(catalog);
|
|
58
116
|
let compiled = false;
|
|
59
117
|
let compileErr = "";
|
|
60
118
|
try {
|
|
@@ -64,15 +122,18 @@ export function validateCatalog(catalog, version, surface) {
|
|
|
64
122
|
catch (e) {
|
|
65
123
|
compileErr = e instanceof Error ? e.message : String(e);
|
|
66
124
|
}
|
|
125
|
+
const selfContained = compiled && exts.length === 0 && dangling.length === 0;
|
|
67
126
|
gates.push({
|
|
68
127
|
name: "schema-compile + no-external-ref",
|
|
69
|
-
pass:
|
|
70
|
-
detail:
|
|
71
|
-
? "Catalog compiles as a draft-2020-12 JSON Schema
|
|
128
|
+
pass: selfContained,
|
|
129
|
+
detail: selfContained
|
|
130
|
+
? "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal and resolves."
|
|
72
131
|
: !compiled
|
|
73
132
|
? `ajv failed to compile the catalog as a schema: ${compileErr}`
|
|
74
|
-
:
|
|
75
|
-
|
|
133
|
+
: exts.length
|
|
134
|
+
? `Catalog contains external $refs: ${[...new Set(exts)].join(", ")}`
|
|
135
|
+
: `Catalog is not self-contained: ${dangling.length} internal $ref(s) do not resolve.`,
|
|
136
|
+
errors: exts.length ? [...new Set(exts)] : dangling.length ? dangling : undefined,
|
|
76
137
|
});
|
|
77
138
|
// Gate 2 — catalog shape.
|
|
78
139
|
const meta = catalogMetaSchemas[version];
|
|
@@ -86,33 +147,43 @@ export function validateCatalog(catalog, version, surface) {
|
|
|
86
147
|
: `Catalog violates the v${version} catalog-shape meta-schema.`,
|
|
87
148
|
errors: shapeOk ? undefined : (validateShape.errors ?? []).map(fmtErr),
|
|
88
149
|
});
|
|
89
|
-
// Gate 3 — instances (only if
|
|
150
|
+
// Gate 3 — instances (only if the catalog is usable and a surface was supplied).
|
|
90
151
|
if (surface !== undefined) {
|
|
91
|
-
if (!compiled) {
|
|
152
|
+
if (!compiled || dangling.length > 0) {
|
|
92
153
|
gates.push({
|
|
93
154
|
name: "instance",
|
|
94
155
|
pass: false,
|
|
95
|
-
detail:
|
|
156
|
+
detail: !compiled
|
|
157
|
+
? "Skipped: catalog did not compile, so instances cannot be checked."
|
|
158
|
+
: "Skipped: catalog is not self-contained (gate 1 lists the dangling $refs), so instances cannot be checked.",
|
|
96
159
|
});
|
|
97
160
|
}
|
|
98
161
|
else {
|
|
99
|
-
|
|
100
|
-
ajv.
|
|
101
|
-
const validateAny = ajv.getSchema(`${catalog.$id}#/$defs/anyComponent`);
|
|
102
|
-
const instances = extractInstances(surface);
|
|
162
|
+
// Belt and braces: gate 1 has already proven every ref resolves, but a
|
|
163
|
+
// raw ajv throw must never escape this function regardless.
|
|
103
164
|
const failures = [];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
165
|
+
let instances = [];
|
|
166
|
+
try {
|
|
167
|
+
const ajv = newAjv();
|
|
168
|
+
ajv.addSchema(catalog, catalog.$id);
|
|
169
|
+
const validateAny = ajv.getSchema(`${catalog.$id}#/$defs/anyComponent`);
|
|
170
|
+
instances = extractInstances(surface);
|
|
171
|
+
if (!validateAny) {
|
|
172
|
+
failures.push("Could not resolve #/$defs/anyComponent from the catalog.");
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
for (const inst of instances) {
|
|
176
|
+
if (!validateAny(inst)) {
|
|
177
|
+
const where = `${inst.component}#${inst.id}`;
|
|
178
|
+
for (const e of validateAny.errors ?? [])
|
|
179
|
+
failures.push(`${where}: ${fmtErr(e)}`);
|
|
180
|
+
}
|
|
113
181
|
}
|
|
114
182
|
}
|
|
115
183
|
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
failures.push(`instance validation could not run: ${e instanceof Error ? e.message : String(e)}`);
|
|
186
|
+
}
|
|
116
187
|
gates.push({
|
|
117
188
|
name: "instance",
|
|
118
189
|
pass: failures.length === 0,
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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 \u2014 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
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`every v1 surface-plan directive is byte-pinned > childProp with >1 children (synthesized Column wrap) 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"messages": "8b8cab6d6a82a062",
|
|
6
|
+
"warnings": "e7ecf1c3b9ae9c67",
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
exports[`every v1 surface-plan directive is byte-pinned > id deduplication (two nodes claiming one id) 1`] = `
|
|
11
|
+
{
|
|
12
|
+
"messages": "84c3037cea1b345f",
|
|
13
|
+
"warnings": "2388dab748ca28c0",
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
exports[`every v1 surface-plan directive is byte-pinned > subFlatten.transparent + asText (card sub-family) 1`] = `
|
|
18
|
+
{
|
|
19
|
+
"messages": "21c9f2503a3c6804",
|
|
20
|
+
"warnings": "9a339e10a151128b",
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`every v1 surface-plan directive is byte-pinned > subTable (table sub-family, header + body + caption) 1`] = `
|
|
25
|
+
{
|
|
26
|
+
"messages": "de1e3b6ace2afe42",
|
|
27
|
+
"warnings": "ac28b69e6cc4143b",
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
exports[`every v1 surface-plan directive is byte-pinned > subText + subButtonText + actionProp (alert-dialog) 1`] = `
|
|
32
|
+
{
|
|
33
|
+
"messages": "d8a53f6c7f146d20",
|
|
34
|
+
"warnings": "374a173b5dac258b",
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`every v1 surface-plan directive is byte-pinned > textChildProp + actionProp (button) 1`] = `
|
|
39
|
+
{
|
|
40
|
+
"messages": "d9112d8d356f5490",
|
|
41
|
+
"warnings": "9100e3b4d5c37463",
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`every v1 surface-plan directive is byte-pinned > textProp (input, badge) 1`] = `
|
|
46
|
+
{
|
|
47
|
+
"messages": "198c8534091323c8",
|
|
48
|
+
"warnings": "3268fc387e176c20",
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
exports[`surface emission is byte-stable > ex.delete-account-confirmation — messages and warnings 1`] = `
|
|
53
|
+
{
|
|
54
|
+
"id": "ex.delete-account-confirmation",
|
|
55
|
+
"messages": "f56b32c2b3b41df5",
|
|
56
|
+
"warnings": "fe908f24a7685bc7",
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
exports[`surface emission is byte-stable > ex.support-ticket-queue — messages and warnings 1`] = `
|
|
61
|
+
{
|
|
62
|
+
"id": "ex.support-ticket-queue",
|
|
63
|
+
"messages": "4545981a34db4240",
|
|
64
|
+
"warnings": "5c4de60aeae6c75a",
|
|
65
|
+
}
|
|
66
|
+
`;
|
package/src/a0.test.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A0: the zero-new-capability authoring milestone — production-v3 profile
|
|
3
|
+
* judgment expressed entirely in the shipped Identity/Routing/Repetition
|
|
4
|
+
* vocabulary (T1 transparency + donation, routes, drops-with-record). No
|
|
5
|
+
* new primitive; every decision grounded in measured usage and recorded
|
|
6
|
+
* with fidelity.
|
|
7
|
+
*
|
|
8
|
+
* Fail-first: before this overlay the six compound families sat in the
|
|
9
|
+
* 67-unresolved ledger (alert 3, avatar 5, scroll-area 2, field 5,
|
|
10
|
+
* field-set 1, field-group 1 — eval-fixture.test.ts pins the 67), and the
|
|
11
|
+
* touched examples refused end-to-end (ex.order-detail-summary on
|
|
12
|
+
* 'avatar', ex.delete-project-confirmation on 'alert', …).
|
|
13
|
+
*
|
|
14
|
+
* The two honest losses, dropped WITH RECORD, never approximated:
|
|
15
|
+
* - alert-action holds component children; routing a sub's children to a
|
|
16
|
+
* slot is T4's mechanism — one production instance affected;
|
|
17
|
+
* - avatar-image is an EMPTY node (the contract declares no src/alt —
|
|
18
|
+
* the dspack#39 contract-gap class, named on the drop).
|
|
19
|
+
*/
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { describe, expect, it } from "vitest";
|
|
23
|
+
import { transformFromJson } from "./transform/index.js";
|
|
24
|
+
import { emitSurface } from "./targets/a2ui/surface.js";
|
|
25
|
+
import { loadProfile } from "./transform/profile-load.js";
|
|
26
|
+
import { SHADCN_V3_A0_PLANS, SHADCN_V3_A0_LABEL_ADDITIONS } from "./transform/shadcn-v2-respelling.js";
|
|
27
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
28
|
+
|
|
29
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
30
|
+
const contract = JSON.parse(readFileSync(repo("eval/shadcn-v3.dspack.json"), "utf8")) as DspackDoc & {
|
|
31
|
+
examples: Array<{ id: string; surface: DspackSurface }>;
|
|
32
|
+
};
|
|
33
|
+
const fixture = JSON.parse(readFileSync(repo("eval/shadcn-v3.eval.profile.json"), "utf8"));
|
|
34
|
+
|
|
35
|
+
/** The builder's A0 merge, hermetically: keep a family set, apply the overlay. */
|
|
36
|
+
const a0Profile = (keep: string[]) => {
|
|
37
|
+
const base = structuredClone(fixture) as Record<string, unknown> & {
|
|
38
|
+
components: Array<Record<string, unknown> & { dspackId: string; structural?: Record<string, unknown> }>;
|
|
39
|
+
};
|
|
40
|
+
base.components = base.components.map((plan) => {
|
|
41
|
+
const a0 = SHADCN_V3_A0_PLANS[plan.dspackId];
|
|
42
|
+
return a0 ? (structuredClone(a0) as typeof plan) : plan;
|
|
43
|
+
});
|
|
44
|
+
for (const [id, note] of Object.entries(SHADCN_V3_A0_LABEL_ADDITIONS)) {
|
|
45
|
+
const plan = base.components.find((c) => c.dspackId === id);
|
|
46
|
+
if (plan && !(plan.structural ?? {}).label) {
|
|
47
|
+
plan.structural = { ...(plan.structural ?? {}), label: { schema: { type: "string" }, description: note.description, synthNote: note.synthNote } };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const keepSet = new Set(keep);
|
|
51
|
+
base.intentionallyOmitted = base.components.filter((c) => !keepSet.has(c.dspackId)).map((c) => c.dspackId).sort();
|
|
52
|
+
base.components = base.components.filter((c) => keepSet.has(c.dspackId));
|
|
53
|
+
delete (base as Record<string, unknown>)["x-scaffold"];
|
|
54
|
+
return loadProfile(base);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const surfaceOf = (root: unknown, intent = "record-detail"): DspackSurface =>
|
|
58
|
+
({ dspackSurface: "0.1", system: contract.name as string, intent, root }) as DspackSurface;
|
|
59
|
+
|
|
60
|
+
/** Find the first subtree of a component in a worked example, verbatim. */
|
|
61
|
+
const fromExample = (exampleId: string, component: string): Record<string, unknown> => {
|
|
62
|
+
const ex = contract.examples.find((e) => e.id === exampleId)!;
|
|
63
|
+
let hit: Record<string, unknown> | undefined;
|
|
64
|
+
const walk = (n: Record<string, unknown>): void => {
|
|
65
|
+
if (hit) return;
|
|
66
|
+
if (n.component === component) { hit = n; return; }
|
|
67
|
+
for (const c of (n.children as Record<string, unknown>[] | undefined) ?? []) walk(c);
|
|
68
|
+
};
|
|
69
|
+
walk(ex.surface.root as unknown as Record<string, unknown>);
|
|
70
|
+
expect(hit, `${component} in ${exampleId}`).toBeDefined();
|
|
71
|
+
return structuredClone(hit!);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const firstInstance = (messages: unknown[], component: string): Record<string, unknown> => {
|
|
75
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
76
|
+
const inst = comps.find((c) => c.component === component);
|
|
77
|
+
expect(inst, `an emitted ${component}`).toBeDefined();
|
|
78
|
+
return inst!;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
describe("A0 — alert (routes over the shipped vocabulary)", () => {
|
|
82
|
+
it("the production delete-project alert emits {title, description}", () => {
|
|
83
|
+
const profile = a0Profile(["card", "alert", "badge", "button"]);
|
|
84
|
+
const { messages } = emitSurface(surfaceOf(fromExample("ex.delete-project-confirmation", "alert")), contract, { profile });
|
|
85
|
+
const alert = firstInstance(messages, "Alert");
|
|
86
|
+
expect(typeof alert.title).toBe("string");
|
|
87
|
+
expect((alert.title as string).length).toBeGreaterThan(0);
|
|
88
|
+
expect(typeof alert.description).toBe("string");
|
|
89
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
90
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("alert-action's loss is recorded, never silent: the flatten ledger marks it lossy and the coverage detail names T4", () => {
|
|
94
|
+
const profile = a0Profile(["card", "alert", "badge", "button"]);
|
|
95
|
+
const { messages, warnings, fidelity } = emitSurface(
|
|
96
|
+
surfaceOf(fromExample("ex.import-run-status", "alert")), contract, { profile });
|
|
97
|
+
firstInstance(messages, "Alert");
|
|
98
|
+
// Runtime record: the consumed subtree is ledgered lossy (the engine's
|
|
99
|
+
// consumesSubtree record — the action button is inside it).
|
|
100
|
+
expect(warnings.some((w) => w.code === "surface-composition-flattened")).toBe(true);
|
|
101
|
+
expect(fidelity.some((f) => f.kind === "flattened" && f.class === "lossy" && f.source.includes("alert"))).toBe(true);
|
|
102
|
+
// Documented judgment: the coverage ledger carries the drop reason,
|
|
103
|
+
// naming T4 as the mechanism the slot waits for.
|
|
104
|
+
const out = transformFromJson(contract, { profile });
|
|
105
|
+
const row = out.mapping.coverage.find((c) => c.id === "alert.alert-action");
|
|
106
|
+
expect(row?.disposition).toBe("mapped");
|
|
107
|
+
expect(row?.detail).toContain("T4");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("A0 — avatar", () => {
|
|
112
|
+
it("the production order-detail avatar emits {size, fallback}; the empty avatar-image drop names the contract gap", () => {
|
|
113
|
+
const profile = a0Profile(["card", "avatar", "badge"]);
|
|
114
|
+
const { messages, fidelity } = emitSurface(surfaceOf(fromExample("ex.order-detail-summary", "avatar")), contract, { profile });
|
|
115
|
+
const avatar = firstInstance(messages, "Avatar");
|
|
116
|
+
expect(avatar.fallback).toBe("AO");
|
|
117
|
+
expect(avatar.size).toBe("lg");
|
|
118
|
+
// The consumed subtree (with the empty avatar-image inside) is ledgered
|
|
119
|
+
// lossy; the drop's dspack#39 rationale lives on the coverage row.
|
|
120
|
+
expect(fidelity.some((f) => f.kind === "flattened" && f.class === "lossy")).toBe(true);
|
|
121
|
+
const out = transformFromJson(contract, { profile });
|
|
122
|
+
expect(out.mapping.coverage.find((c) => c.id === "avatar.avatar-image")?.detail).toContain("dspack#39");
|
|
123
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
124
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("A0 — scroll-area dissolves (T1 vocabulary, no instance)", () => {
|
|
129
|
+
it("children rise; scrollbar chrome drops with record", () => {
|
|
130
|
+
const profile = a0Profile(["card", "scroll-area", "badge"]);
|
|
131
|
+
const { messages } = emitSurface(
|
|
132
|
+
surfaceOf({
|
|
133
|
+
component: "card",
|
|
134
|
+
children: [{ component: "scroll-area", children: [{ component: "badge", text: "42 open" }] }],
|
|
135
|
+
}),
|
|
136
|
+
contract,
|
|
137
|
+
{ profile },
|
|
138
|
+
);
|
|
139
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
140
|
+
expect(comps.some((c) => c.component === "ScrollArea")).toBe(false);
|
|
141
|
+
expect(comps.some((c) => c.component === "Badge")).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("A0 — the corrected field family (dspack#40) emits end-to-end", () => {
|
|
146
|
+
it("the production notification-preferences field-set subtree: legend becomes text, groups dissolve, labels donate onto switches", () => {
|
|
147
|
+
const profile = a0Profile(["card", "field", "field-set", "field-group", "switch", "radio-group", "separator", "badge", "button"]);
|
|
148
|
+
const subtree = fromExample("ex.notification-preferences", "field-set");
|
|
149
|
+
const { messages, fidelity } = emitSurface(surfaceOf(subtree, "preference-settings"), contract, { profile });
|
|
150
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
151
|
+
// No wrapper survives.
|
|
152
|
+
for (const gone of ["FieldSet", "FieldGroup", "Field"]) {
|
|
153
|
+
expect(comps.some((c) => c.component === gone), `${gone} must not emit`).toBe(false);
|
|
154
|
+
}
|
|
155
|
+
// The legend text survives as a Text instance.
|
|
156
|
+
expect(comps.some((c) => c.component === "Text")).toBe(true);
|
|
157
|
+
// Every switch carries its donated label.
|
|
158
|
+
const switches = comps.filter((c) => c.component === "Switch");
|
|
159
|
+
expect(switches.length).toBeGreaterThan(0);
|
|
160
|
+
for (const sw of switches) expect(typeof sw.label).toBe("string");
|
|
161
|
+
// Donation provenance is ledgered.
|
|
162
|
+
expect(fidelity.some((f) => f.note?.includes("donated by 'field-label'"))).toBe(true);
|
|
163
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
164
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("a field's textarea and select receive the donated label (the invite-teammates shapes)", () => {
|
|
168
|
+
const profile = a0Profile(["card", "field", "field-set", "field-group", "textarea", "select", "badge"]);
|
|
169
|
+
const t = emitSurface(
|
|
170
|
+
surfaceOf({ component: "field", children: [{ component: "field-label", text: "Personal note" }, { component: "textarea", props: { rows: 3 } }] }),
|
|
171
|
+
contract, { profile });
|
|
172
|
+
expect(firstInstance(t.messages, "Textarea").label).toBe("Personal note");
|
|
173
|
+
|
|
174
|
+
const s = emitSurface(
|
|
175
|
+
surfaceOf({
|
|
176
|
+
component: "field",
|
|
177
|
+
children: [
|
|
178
|
+
{ component: "field-label", text: "Workspace role" },
|
|
179
|
+
{ component: "select", children: [{ component: "select-content", children: [{ component: "select-item", text: "Editor" }] }] },
|
|
180
|
+
],
|
|
181
|
+
}),
|
|
182
|
+
contract, { profile });
|
|
183
|
+
const sel = firstInstance(s.messages, "Select");
|
|
184
|
+
expect(sel.label).toBe("Workspace role");
|
|
185
|
+
expect(sel.options).toEqual([{ label: "Editor" }]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("A0 — shipped primitives compose: transparency inside a joined panel", () => {
|
|
190
|
+
it("a transparent scroll-area inside tabs-content dissolves instead of refusing (the ex.project-workspace-panels shape)", () => {
|
|
191
|
+
// Discovered by the A0 re-measurement: the T3 joined-children path fed
|
|
192
|
+
// raw children to emitNode, skipping the parent-style rewrite that
|
|
193
|
+
// dissolves transparent children — a composition bug between shipped
|
|
194
|
+
// primitives, fixed by mirroring the transparent-root host pattern.
|
|
195
|
+
const profile = a0Profile(["card", "tabs", "scroll-area", "badge"]);
|
|
196
|
+
const { messages } = emitSurface(
|
|
197
|
+
surfaceOf({
|
|
198
|
+
component: "tabs",
|
|
199
|
+
children: [
|
|
200
|
+
{ component: "tabs-list", children: [{ component: "tabs-trigger", id: "t1", text: "Overview" }] },
|
|
201
|
+
{ component: "tabs-content", id: "t1", children: [{ component: "scroll-area", children: [{ component: "badge", text: "42 open" }] }] },
|
|
202
|
+
],
|
|
203
|
+
}),
|
|
204
|
+
contract, { profile });
|
|
205
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
206
|
+
expect(comps.some((c) => c.component === "ScrollArea")).toBe(false);
|
|
207
|
+
const tabs = comps.find((c) => c.component === "Tabs")!;
|
|
208
|
+
const sections = tabs.sections as Array<{ child: string }>;
|
|
209
|
+
expect(sections).toHaveLength(1);
|
|
210
|
+
const badge = comps.find((c) => c.component === "Badge")!;
|
|
211
|
+
expect(sections[0].child).toBe(badge.id);
|
|
212
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
213
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("A0 — ledger and determinism", () => {
|
|
218
|
+
it("the six authored families derive zero unresolved subs", () => {
|
|
219
|
+
const profile = a0Profile(["card", "alert", "avatar", "scroll-area", "field", "field-set", "field-group", "switch", "badge", "button"]);
|
|
220
|
+
const out = transformFromJson(contract, { profile });
|
|
221
|
+
const unresolved = out.mapping.coverage.filter(
|
|
222
|
+
(c) => c.disposition === "unclassified" &&
|
|
223
|
+
["alert.", "avatar.", "scroll-area.", "field.", "field-set.", "field-group."].some((p) => c.id.startsWith(p)),
|
|
224
|
+
);
|
|
225
|
+
expect(unresolved).toEqual([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("emission is deterministic across runs", () => {
|
|
229
|
+
const profile = a0Profile(["card", "field", "field-set", "field-group", "switch", "badge"]);
|
|
230
|
+
const subtree = fromExample("ex.notification-preferences", "field-set");
|
|
231
|
+
const a = emitSurface(surfaceOf(subtree, "preference-settings"), contract, { profile });
|
|
232
|
+
const b = emitSurface(surfaceOf(subtree, "preference-settings"), contract, { profile });
|
|
233
|
+
expect(JSON.stringify([a.messages, a.warnings, a.fidelity])).toBe(JSON.stringify([b.messages, b.warnings, b.fidelity]));
|
|
234
|
+
});
|
|
235
|
+
});
|