@aestheticfunction/dspack-emit 0.4.0 → 0.5.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 +566 -224
- 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 +50 -0
- package/dist/transform/model.d.ts +275 -0
- package/dist/transform/model.js +148 -0
- package/dist/transform/parse-v2.d.ts +78 -0
- package/dist/transform/parse-v2.js +305 -0
- package/dist/transform/profile-load.d.ts +8 -7
- package/dist/transform/profile-load.js +101 -24
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +430 -0
- package/dist/transform/profile-schema.d.ts +8 -0
- package/dist/transform/profile-schema.js +382 -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 +12 -0
- package/dist/transform/shadcn-v2-respelling.js +49 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +100 -0
- package/dist/types.d.ts +19 -0
- package/dist/validate/ajv.js +98 -29
- package/dist/validate/meta/catalog-meta.d.ts +10 -0
- package/dist/validate/meta/catalog-meta.js +157 -0
- package/package.json +3 -3
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/browser-boundary.test.ts +47 -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 +89 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +363 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +35 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +920 -242
- 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 +42 -0
- package/src/transform/model.ts +325 -0
- package/src/transform/parse-v2.ts +397 -0
- package/src/transform/profile-load.ts +107 -28
- package/src/transform/profile-schema-v2.ts +430 -0
- package/src/transform/profile-schema.ts +382 -0
- package/src/transform/profile.v2.schema.json +422 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +61 -0
- package/src/transform/validate-v2.ts +138 -0
- package/src/types.ts +20 -0
- package/src/validate/ajv.ts +91 -32
- package/src/validate/meta/catalog-meta.ts +167 -0
- package/src/validate-v2.test.ts +173 -0
- package/dist/transform/profile.v1.schema.json +0 -153
- 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
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile v2: the primitive language, proven against the v1 byte contract.
|
|
3
|
+
*
|
|
4
|
+
* The keystone assertion: the ENTIRE shadcn profile re-spelled in v2 —
|
|
5
|
+
* Identity / Route / Collect strings instead of the ten v1 directives —
|
|
6
|
+
* loads through the v2 dispatcher and emits BYTE-IDENTICALLY to the v1
|
|
7
|
+
* profile: same catalog digests (both A2UI versions), same messages, same
|
|
8
|
+
* warnings, for every pinned directive surface and worked example. v2 is
|
|
9
|
+
* not a new emitter; it is a new spelling for the same transformation.
|
|
10
|
+
*
|
|
11
|
+
* Also here: the version dispatcher's refusals, and the load-time refusal
|
|
12
|
+
* matrix for the v2 grammar — every way a v2 surface block can be wrong,
|
|
13
|
+
* refused with a pathed finding at load, before any emission runs.
|
|
14
|
+
*/
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
import { transformFromJson } from "./transform/index.js";
|
|
20
|
+
import { emitSurface } from "./targets/a2ui/surface.js";
|
|
21
|
+
import { loadProfile, ProfileLoadError } from "./transform/profile-load.js";
|
|
22
|
+
import { shadcnProfile, type ComponentPlan } from "./transform/profiles.js";
|
|
23
|
+
import { SHADCN_V2_SURFACES as V2_SURFACES } from "./transform/shadcn-v2-respelling.js";
|
|
24
|
+
import type { A2uiVersion, DspackDoc, DspackSurface } from "./types.js";
|
|
25
|
+
|
|
26
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
27
|
+
const doc = JSON.parse(readFileSync(repo("input/shadcn-ui.dspack.json"), "utf8")) as DspackDoc;
|
|
28
|
+
|
|
29
|
+
const digest = (value: unknown): string =>
|
|
30
|
+
createHash("sha256").update(JSON.stringify(value)).digest("hex").slice(0, 16);
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// The v2 re-spelling: every v1 directive the shadcn profile uses, as
|
|
34
|
+
// primitives. Hand-authored — this is what a v2 profile author would write.
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The v2 document, built from the TS profile so every non-surface field is
|
|
39
|
+
* identical by construction — the only authored difference is the language.
|
|
40
|
+
*/
|
|
41
|
+
function shadcnV2Document(): Record<string, unknown> {
|
|
42
|
+
const strip = (plan: ComponentPlan): Record<string, unknown> => {
|
|
43
|
+
const { surfacePlan: _v1, subCoverage: _prose, ...rest } = structuredClone(plan) as Record<string, unknown> & {
|
|
44
|
+
surfacePlan?: unknown;
|
|
45
|
+
subCoverage?: unknown;
|
|
46
|
+
};
|
|
47
|
+
const dspackId = (rest as { dspackId?: string }).dspackId;
|
|
48
|
+
if (dspackId && V2_SURFACES[dspackId]) rest.surface = V2_SURFACES[dspackId];
|
|
49
|
+
return rest;
|
|
50
|
+
};
|
|
51
|
+
const base = structuredClone(shadcnProfile) as unknown as Record<string, unknown>;
|
|
52
|
+
return {
|
|
53
|
+
profileVersion: "2",
|
|
54
|
+
...base,
|
|
55
|
+
components: shadcnProfile.components.map(strip),
|
|
56
|
+
synthesized: shadcnProfile.synthesized.map(strip),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const VERSIONS: A2uiVersion[] = ["0.9.1", "1.0"];
|
|
61
|
+
|
|
62
|
+
/** The v1 pins this file must reproduce — same values as byte-neutral.test.ts. */
|
|
63
|
+
const V1_CATALOG_DIGESTS: Record<string, string> = {
|
|
64
|
+
"0.9.1": "7c1b72dfd83dde14",
|
|
65
|
+
"1.0": "2dde439bbf643834",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
describe("the v2 re-spelling emits byte-identically to the v1 profile", () => {
|
|
69
|
+
const v2 = () => loadProfile(shadcnV2Document());
|
|
70
|
+
|
|
71
|
+
it("loads through the dispatcher and is stamped as the v2 language", () => {
|
|
72
|
+
const profile = v2();
|
|
73
|
+
expect(profile.language).toBe("v2");
|
|
74
|
+
expect(profile.catalogTitle).toBe(shadcnProfile.catalogTitle);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
for (const version of VERSIONS) {
|
|
78
|
+
it(`catalog digest equals the pinned v1 digest (a2ui ${version})`, () => {
|
|
79
|
+
const out = transformFromJson(doc, { profile: v2(), a2uiVersion: version });
|
|
80
|
+
expect(digest(out.catalog)).toBe(V1_CATALOG_DIGESTS[version]);
|
|
81
|
+
expect(out.validation.pass).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const surface = (root: unknown, intent = "record-collection"): DspackSurface =>
|
|
86
|
+
({ dspackSurface: "0.1", system: doc.name as string, intent, root }) as DspackSurface;
|
|
87
|
+
|
|
88
|
+
/** Every directive-exercising surface from the byte gate, plus the worked examples. */
|
|
89
|
+
const cases: Array<[string, DspackSurface]> = [
|
|
90
|
+
["textChild + action (button)", surface({ component: "button", text: "Save changes", props: { variant: "default" } })],
|
|
91
|
+
[
|
|
92
|
+
"self.text routes (input, badge)",
|
|
93
|
+
surface({
|
|
94
|
+
component: "card",
|
|
95
|
+
children: [
|
|
96
|
+
{ component: "input", text: "Email" },
|
|
97
|
+
{ component: "badge", text: "New", props: { variant: "secondary" } },
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"transparent + asText subs (card family)",
|
|
103
|
+
surface({
|
|
104
|
+
component: "card",
|
|
105
|
+
children: [
|
|
106
|
+
{
|
|
107
|
+
component: "card-header",
|
|
108
|
+
children: [
|
|
109
|
+
{ component: "card-title", text: "Members" },
|
|
110
|
+
{ component: "card-description", text: "Everyone with access." },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{ component: "card-content", text: "Three people." },
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"collects (table family)",
|
|
119
|
+
surface({
|
|
120
|
+
component: "table",
|
|
121
|
+
children: [
|
|
122
|
+
{ component: "table-caption", text: "Recent orders" },
|
|
123
|
+
{ component: "table-header", children: [{ component: "table-row", children: [{ component: "table-head", text: "Order" }, { component: "table-head", text: "Status" }] }] },
|
|
124
|
+
{
|
|
125
|
+
component: "table-body",
|
|
126
|
+
children: [
|
|
127
|
+
{ component: "table-row", children: [{ component: "table-cell", text: "#1001" }, { component: "table-cell", text: "Shipped" }] },
|
|
128
|
+
{ component: "table-row", children: [{ component: "table-cell", text: "#1002" }, { component: "table-cell", text: "Pending" }] },
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
}),
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
"consuming routes + label fallback (alert-dialog)",
|
|
136
|
+
surface(
|
|
137
|
+
{
|
|
138
|
+
component: "alert-dialog",
|
|
139
|
+
children: [
|
|
140
|
+
{ component: "alert-dialog-trigger", children: [{ component: "button", text: "Delete" }] },
|
|
141
|
+
{
|
|
142
|
+
component: "alert-dialog-content",
|
|
143
|
+
children: [
|
|
144
|
+
{ component: "alert-dialog-title", text: "Delete project?" },
|
|
145
|
+
{ component: "alert-dialog-description", text: "This cannot be undone." },
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
"destructive-action",
|
|
151
|
+
),
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
"wrap synthesis (>1 children in a slot)",
|
|
155
|
+
surface({
|
|
156
|
+
component: "card",
|
|
157
|
+
children: [
|
|
158
|
+
{ component: "badge", text: "One" },
|
|
159
|
+
{ component: "badge", text: "Two" },
|
|
160
|
+
],
|
|
161
|
+
}),
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
"id deduplication",
|
|
165
|
+
surface({
|
|
166
|
+
component: "card",
|
|
167
|
+
children: [
|
|
168
|
+
{ component: "badge", id: "tag", text: "One" },
|
|
169
|
+
{ component: "badge", id: "tag", text: "Two" },
|
|
170
|
+
],
|
|
171
|
+
}),
|
|
172
|
+
],
|
|
173
|
+
...((doc as unknown as { examples?: Array<{ id: string; surface: DspackSurface }> }).examples ?? []).map(
|
|
174
|
+
(e) => [`worked example ${e.id}`, e.surface] as [string, DspackSurface],
|
|
175
|
+
),
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
it.each(cases)("%s — identical messages and warnings", (_name, s) => {
|
|
179
|
+
const fromV1 = emitSurface(s, doc, { profile: shadcnProfile });
|
|
180
|
+
const fromV2 = emitSurface(s, doc, { profile: v2() });
|
|
181
|
+
expect(digest(fromV2.messages)).toBe(digest(fromV1.messages));
|
|
182
|
+
expect(digest(fromV2.warnings)).toBe(digest(fromV1.warnings));
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("the version dispatcher", () => {
|
|
187
|
+
const v1Doc = () => ({ profileVersion: "1", ...structuredClone(shadcnProfile) });
|
|
188
|
+
|
|
189
|
+
it("v1 documents keep loading exactly as before", () => {
|
|
190
|
+
const profile = loadProfile(v1Doc());
|
|
191
|
+
expect(profile.language).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("an unknown version refuses with a pathed finding naming the supported set", () => {
|
|
195
|
+
for (const bad of ["3", "2.0", 2, undefined, null]) {
|
|
196
|
+
const attempt = { ...v1Doc(), profileVersion: bad } as unknown;
|
|
197
|
+
try {
|
|
198
|
+
loadProfile(attempt);
|
|
199
|
+
expect.unreachable(`version ${JSON.stringify(bad)} must refuse`);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
expect(e).toBeInstanceOf(ProfileLoadError);
|
|
202
|
+
const issue = (e as ProfileLoadError).issues[0];
|
|
203
|
+
expect(issue.path).toBe("/profileVersion");
|
|
204
|
+
expect(issue.message).toContain('"1"');
|
|
205
|
+
expect(issue.message).toContain('"2"');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("one language per document: v1 syntax inside a v2 document refuses", () => {
|
|
211
|
+
const mixed = shadcnV2Document();
|
|
212
|
+
(mixed.components as Array<Record<string, unknown>>)[0].surfacePlan = { textProp: "child" };
|
|
213
|
+
expect(() => loadProfile(mixed)).toThrowError(ProfileLoadError);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("one language per document: v2 syntax inside a v1 document refuses", () => {
|
|
217
|
+
const mixed = v1Doc() as unknown as { components: Array<Record<string, unknown>> };
|
|
218
|
+
mixed.components[0].surface = { routes: [] };
|
|
219
|
+
expect(() => loadProfile(mixed)).toThrowError(ProfileLoadError);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe("load-time refusal matrix (v2 grammar)", () => {
|
|
224
|
+
/** A minimal valid v2 document with one plan whose surface block is under test. */
|
|
225
|
+
const docWith = (surface: unknown, plan: Partial<ComponentPlan> = {}): Record<string, unknown> => ({
|
|
226
|
+
profileVersion: "2",
|
|
227
|
+
catalogTitle: "t",
|
|
228
|
+
catalogDescription: "d",
|
|
229
|
+
catalogIdBase: "https://example.test/catalogs/x",
|
|
230
|
+
instructions: "",
|
|
231
|
+
primaryColorToken: { category: "color", name: "primary" },
|
|
232
|
+
surfaceSynthesis: { textComponent: "Text", textProp: "text", wrapComponent: "Column", wrapChildrenProp: "children" },
|
|
233
|
+
synthesized: [],
|
|
234
|
+
casualtyComponents: [],
|
|
235
|
+
components: [
|
|
236
|
+
{
|
|
237
|
+
a2ui: "Widget",
|
|
238
|
+
dspackId: "widget",
|
|
239
|
+
commons: ["ComponentCommon"],
|
|
240
|
+
structural: {
|
|
241
|
+
label: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
242
|
+
child: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
243
|
+
items: { schema: { type: "array" }, description: "d", synthNote: "s" },
|
|
244
|
+
go: { schema: { $ref: "#/$defs/Action" }, description: "d", synthNote: "s" },
|
|
245
|
+
},
|
|
246
|
+
required: [],
|
|
247
|
+
surface,
|
|
248
|
+
...plan,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const refusal = (surface: unknown, plan?: Partial<ComponentPlan>): string => {
|
|
254
|
+
try {
|
|
255
|
+
loadProfile(docWith(surface, plan));
|
|
256
|
+
return "LOADED";
|
|
257
|
+
} catch (e) {
|
|
258
|
+
if (e instanceof ProfileLoadError) return e.issues.map((i) => `${i.path}: ${i.message}`).join("\n");
|
|
259
|
+
throw e;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
it("a well-formed block loads", () => {
|
|
264
|
+
expect(
|
|
265
|
+
refusal({
|
|
266
|
+
routes: [
|
|
267
|
+
{ from: ["self.text"], to: "prop:label" },
|
|
268
|
+
{ from: ["children"], to: "slot:child" },
|
|
269
|
+
],
|
|
270
|
+
}),
|
|
271
|
+
).toBe("LOADED");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("an unknown selector refuses at its exact path", () => {
|
|
275
|
+
const out = refusal({ routes: [{ from: ["self.magic"], to: "prop:label" }] });
|
|
276
|
+
expect(out).toContain("/routes/0/from/0");
|
|
277
|
+
expect(out).toContain("pattern");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("an arbitrary JSON path is not a selector", () => {
|
|
281
|
+
expect(refusal({ routes: [{ from: ["$.children[0].text"], to: "prop:label" }] })).toContain("/from/0");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("a computed destination is refused by the grammar", () => {
|
|
285
|
+
expect(refusal({ routes: [{ from: ["self.text"], to: "prop:${name}" }] })).toContain("/to");
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("an undeclared destination refuses: inventing properties dies here, not at A3", () => {
|
|
289
|
+
const out = refusal({ routes: [{ from: ["self.text"], to: "prop:invented" }] });
|
|
290
|
+
expect(out).toContain("not declared by this plan");
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("selector/destination incompatibility refuses (action fed by text)", () => {
|
|
294
|
+
const out = refusal({ routes: [{ from: ["self.text"], to: "action:go" }] });
|
|
295
|
+
expect(out).toContain("cannot feed destination kind 'action'");
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("a fallback chain that mixes write phases refuses", () => {
|
|
299
|
+
const out = refusal({
|
|
300
|
+
routes: [{ from: ["sub(a).text", "self.props.label"], to: "prop:label" }],
|
|
301
|
+
});
|
|
302
|
+
expect(out).toContain("mixes write phases");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("a same-phase double-claim refuses; distinct-phase layering loads", () => {
|
|
306
|
+
const clash = refusal({
|
|
307
|
+
routes: [
|
|
308
|
+
{ from: ["sub(a).text"], to: "prop:label" },
|
|
309
|
+
{ from: ["sub(b).text"], to: "prop:label" },
|
|
310
|
+
],
|
|
311
|
+
});
|
|
312
|
+
expect(clash).toContain("same write phase");
|
|
313
|
+
const layered = refusal({
|
|
314
|
+
routes: [
|
|
315
|
+
{ from: ["self.props.label"], to: "prop:label" },
|
|
316
|
+
{ from: ["sub(a).text"], to: "prop:label" },
|
|
317
|
+
],
|
|
318
|
+
});
|
|
319
|
+
expect(layered).toBe("LOADED");
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("a second children route refuses (multi-slot arrives with T4)", () => {
|
|
323
|
+
const out = refusal({
|
|
324
|
+
routes: [
|
|
325
|
+
{ from: ["children"], to: "slot:child" },
|
|
326
|
+
{ from: ["children"], to: "slots:items" },
|
|
327
|
+
],
|
|
328
|
+
});
|
|
329
|
+
expect(out).toContain("T4");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("children routing plus subtree consumption is a contradiction and refuses", () => {
|
|
333
|
+
const out = refusal({
|
|
334
|
+
routes: [
|
|
335
|
+
{ from: ["sub(a).text"], to: "prop:label" },
|
|
336
|
+
{ from: ["children"], to: "slot:child" },
|
|
337
|
+
],
|
|
338
|
+
});
|
|
339
|
+
expect(out).toContain("contradictory");
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("a records collect without a field name refuses", () => {
|
|
343
|
+
const out = refusal({
|
|
344
|
+
collects: [{ of: ["sec"], into: "prop:items", shape: "records", row: ["row"], cells: ["cell"] }],
|
|
345
|
+
});
|
|
346
|
+
expect(out).toContain("field");
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("a sub with two dispositions refuses", () => {
|
|
350
|
+
const out = refusal({
|
|
351
|
+
routes: [{ from: ["sub(part).text"], to: "prop:label" }],
|
|
352
|
+
subs: { part: "transparent" },
|
|
353
|
+
});
|
|
354
|
+
expect(out).toContain("one sub, one disposition");
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("unimplemented capability spellings are refused by the schema, not reinterpreted", () => {
|
|
358
|
+
// T1 plan-level transparency, T1 donation, T3 joins — none parseable.
|
|
359
|
+
expect(refusal({ transparent: true })).not.toBe("LOADED");
|
|
360
|
+
expect(refusal({ routes: [{ from: ["self.text"], to: "prop:label", onto: "control" }] })).not.toBe("LOADED");
|
|
361
|
+
expect(refusal({ collects: [{ of: ["s"], into: "prop:items", shape: "records", field: "f", row: ["r"], cells: ["c"], joinOn: "id" }] })).not.toBe("LOADED");
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression pins for the adversarial review of the v2 foundation (workflow
|
|
3
|
+
* wf_1c1cc374-ced: 17 agents, 13 confirmed findings, 10 distinct defects —
|
|
4
|
+
* every one in the new v2/ledger surface, none in the byte-frozen v1 paths).
|
|
5
|
+
*
|
|
6
|
+
* Each test is named for its finding and failed against the pre-fix code.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { transformFromJson } from "./transform/index.js";
|
|
12
|
+
import { emitSurface } from "./targets/a2ui/surface.js";
|
|
13
|
+
import { loadProfile, ProfileLoadError } from "./transform/profile-load.js";
|
|
14
|
+
import { ProfileContractError } from "./transform/validate-v2.js";
|
|
15
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
16
|
+
|
|
17
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
18
|
+
const doc = JSON.parse(readFileSync(repo("input/shadcn-ui.dspack.json"), "utf8")) as DspackDoc;
|
|
19
|
+
|
|
20
|
+
const surface = (root: unknown, intent = "record-collection"): DspackSurface =>
|
|
21
|
+
({ dspackSurface: "0.1", system: doc.name as string, intent, root }) as DspackSurface;
|
|
22
|
+
|
|
23
|
+
const CARD_SUBS = {
|
|
24
|
+
"card-header": "transparent",
|
|
25
|
+
"card-content": "transparent",
|
|
26
|
+
"card-footer": "transparent",
|
|
27
|
+
"card-title": { asText: "h3" },
|
|
28
|
+
"card-description": { asText: "caption" },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const v2Doc = (
|
|
32
|
+
cardSurface: unknown,
|
|
33
|
+
opts: { collection?: "components" | "synthesized"; functions?: unknown } = {},
|
|
34
|
+
): Record<string, unknown> => {
|
|
35
|
+
const cardPlan = {
|
|
36
|
+
a2ui: "Card",
|
|
37
|
+
dspackId: "card",
|
|
38
|
+
commons: ["ComponentCommon"],
|
|
39
|
+
structural: {
|
|
40
|
+
child: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
41
|
+
label: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
42
|
+
extra: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
43
|
+
},
|
|
44
|
+
required: [],
|
|
45
|
+
...(cardSurface === undefined ? {} : { surface: cardSurface }),
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
profileVersion: "2",
|
|
49
|
+
catalogTitle: "t",
|
|
50
|
+
catalogDescription: "d",
|
|
51
|
+
catalogIdBase: "https://example.test/catalogs/x",
|
|
52
|
+
instructions: "",
|
|
53
|
+
primaryColorToken: { category: "color", name: "primary" },
|
|
54
|
+
surfaceSynthesis: { textComponent: "Text", textProp: "text", wrapComponent: "Column", wrapChildrenProp: "children" },
|
|
55
|
+
...(opts.functions ? { functions: opts.functions } : {}),
|
|
56
|
+
synthesized: [
|
|
57
|
+
{
|
|
58
|
+
a2ui: "Text",
|
|
59
|
+
commons: ["ComponentCommon"],
|
|
60
|
+
structural: { text: { schema: { type: "string" }, description: "d", synthNote: "s" } },
|
|
61
|
+
propMap: { variant: { a2ui: "variant", kind: "enum", targetEnum: ["body", "h3", "caption"] } },
|
|
62
|
+
required: ["text"],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
a2ui: "Column",
|
|
66
|
+
commons: ["ComponentCommon"],
|
|
67
|
+
structural: { children: { schema: { type: "array" }, description: "d", synthNote: "s" } },
|
|
68
|
+
required: ["children"],
|
|
69
|
+
},
|
|
70
|
+
...(opts.collection === "synthesized" ? [cardPlan] : []),
|
|
71
|
+
],
|
|
72
|
+
casualtyComponents: [],
|
|
73
|
+
components: opts.collection === "synthesized" ? [] : [cardPlan],
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
describe("the contract gate has no side doors (findings 1, 6, 8, 9)", () => {
|
|
78
|
+
it("a mapped compound in `synthesized` is validated exactly like one in `components`", () => {
|
|
79
|
+
const withBogusSub = {
|
|
80
|
+
routes: [{ from: ["sub(card-sidebar).text"], to: "prop:label" }],
|
|
81
|
+
subs: CARD_SUBS,
|
|
82
|
+
};
|
|
83
|
+
for (const collection of ["components", "synthesized"] as const) {
|
|
84
|
+
expect(
|
|
85
|
+
() => transformFromJson(doc, { profile: loadProfile(v2Doc(withBogusSub, { collection })) }),
|
|
86
|
+
collection,
|
|
87
|
+
).toThrowError(ProfileContractError);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("omitting the surface block is exactly as unresolved as `surface: {}`", () => {
|
|
92
|
+
for (const spelling of [undefined, {}]) {
|
|
93
|
+
try {
|
|
94
|
+
transformFromJson(doc, { profile: loadProfile(v2Doc(spelling)) });
|
|
95
|
+
expect.unreachable("a compound with undecided subs must refuse either way");
|
|
96
|
+
} catch (e) {
|
|
97
|
+
expect(e).toBeInstanceOf(ProfileContractError);
|
|
98
|
+
const issues = (e as ProfileContractError).issues;
|
|
99
|
+
expect(issues).toHaveLength(5);
|
|
100
|
+
expect(issues.every((i) => i.message.includes("unresolved"))).toBe(true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("an authored drop is warn-and-discard everywhere (finding 2)", () => {
|
|
107
|
+
it("a dropped sub on a non-collecting plan is skipped with its reason, not crashed", () => {
|
|
108
|
+
const profile = loadProfile(
|
|
109
|
+
v2Doc({
|
|
110
|
+
routes: [{ from: ["children"], to: "slot:child" }],
|
|
111
|
+
subs: { ...CARD_SUBS, "card-description": { drop: "descriptions are not carried here" } },
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
const { messages, warnings, fidelity } = emitSurface(
|
|
115
|
+
surface({
|
|
116
|
+
component: "card",
|
|
117
|
+
children: [
|
|
118
|
+
{ component: "card-description", text: "gone" },
|
|
119
|
+
{ component: "card-content", text: "kept" },
|
|
120
|
+
],
|
|
121
|
+
}),
|
|
122
|
+
doc,
|
|
123
|
+
{ profile },
|
|
124
|
+
);
|
|
125
|
+
expect(JSON.stringify(messages)).not.toContain("gone");
|
|
126
|
+
expect(JSON.stringify(messages)).toContain("kept");
|
|
127
|
+
const warn = warnings.find((w) => w.code === "surface-sub-dropped");
|
|
128
|
+
expect(warn?.message).toContain("descriptions are not carried here");
|
|
129
|
+
expect(fidelity.find((f) => f.origin === "drops.card-description")).toMatchObject({ kind: "dropped", class: "lossy" });
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("a renamed self-prop read does not suppress the prop's own projection (finding 3)", () => {
|
|
134
|
+
it("badge keeps its projected variant while the route writes the extra copy", () => {
|
|
135
|
+
// The contract's `badge` declares `variant`, so the renamed read
|
|
136
|
+
// (self.props.variant -> prop:extra) is gate-legal — and must not
|
|
137
|
+
// suppress the propMap projection of variant itself.
|
|
138
|
+
const withBadge = v2Doc({ routes: [{ from: ["children"], to: "slot:child" }], subs: CARD_SUBS });
|
|
139
|
+
(withBadge.components as Array<Record<string, unknown>>).push({
|
|
140
|
+
a2ui: "Badge",
|
|
141
|
+
dspackId: "badge",
|
|
142
|
+
commons: ["ComponentCommon"],
|
|
143
|
+
structural: {
|
|
144
|
+
label: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
145
|
+
extra: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
146
|
+
},
|
|
147
|
+
propMap: { variant: { a2ui: "variant", kind: "enum", targetEnum: ["default", "secondary", "destructive", "outline"] } },
|
|
148
|
+
required: [],
|
|
149
|
+
surface: {
|
|
150
|
+
routes: [
|
|
151
|
+
{ from: ["self.text"], to: "prop:label", overwrite: true },
|
|
152
|
+
{ from: ["self.props.variant"], to: "prop:extra" },
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
const { messages } = emitSurface(
|
|
157
|
+
surface({ component: "badge", text: "New", props: { variant: "outline" } }),
|
|
158
|
+
doc,
|
|
159
|
+
{ profile: loadProfile(withBadge) },
|
|
160
|
+
);
|
|
161
|
+
const [badge] = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } })
|
|
162
|
+
.updateComponents.components;
|
|
163
|
+
expect(badge.variant).toBe("outline"); // the projection survived
|
|
164
|
+
expect(badge.extra).toBe("outline"); // and the routed copy landed too
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("dead and contradictory spellings refuse at load (findings 4, 5, 13)", () => {
|
|
169
|
+
const refusal = (s: unknown): string => {
|
|
170
|
+
try {
|
|
171
|
+
loadProfile(v2Doc(s));
|
|
172
|
+
return "LOADED";
|
|
173
|
+
} catch (e) {
|
|
174
|
+
if (e instanceof ProfileLoadError) return e.issues.map((i) => `${i.path}: ${i.message}`).join("\n");
|
|
175
|
+
throw e;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
it("firstText cannot lead a route — it is a fallback selector", () => {
|
|
180
|
+
const out = refusal({ routes: [{ from: ["sub(card-title).firstText"], to: "prop:label" }], subs: CARD_SUBS });
|
|
181
|
+
expect(out).toContain("cannot lead a route");
|
|
182
|
+
// ...while the fallback position stays legal (card-title consumed by the
|
|
183
|
+
// route, so it carries no separate disposition).
|
|
184
|
+
const { "card-title": _consumed, ...rest } = CARD_SUBS;
|
|
185
|
+
expect(
|
|
186
|
+
refusal({
|
|
187
|
+
routes: [{ from: ["sub(card-title).label", "sub(card-title).firstText"], to: "prop:label" }],
|
|
188
|
+
subs: rest,
|
|
189
|
+
}),
|
|
190
|
+
).toBe("LOADED");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("a children route's destination is exclusive in both directions", () => {
|
|
194
|
+
const childrenFirst = refusal({
|
|
195
|
+
routes: [
|
|
196
|
+
{ from: ["children"], to: "slot:child" },
|
|
197
|
+
{ from: ["self.text"], to: "textChild:child" },
|
|
198
|
+
],
|
|
199
|
+
subs: CARD_SUBS,
|
|
200
|
+
});
|
|
201
|
+
expect(childrenFirst).toContain("children route");
|
|
202
|
+
const childrenSecond = refusal({
|
|
203
|
+
routes: [
|
|
204
|
+
{ from: ["self.text"], to: "textChild:child" },
|
|
205
|
+
{ from: ["children"], to: "slot:child" },
|
|
206
|
+
],
|
|
207
|
+
subs: CARD_SUBS,
|
|
208
|
+
});
|
|
209
|
+
expect(childrenSecond).toContain("first-wins");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("a collect cell source cannot also carry a disposition", () => {
|
|
213
|
+
const out = refusal({
|
|
214
|
+
collects: [
|
|
215
|
+
{ of: ["card-header"], into: "prop:label", shape: "flat", row: ["card-content"], cells: ["card-title"] },
|
|
216
|
+
],
|
|
217
|
+
subs: { "card-title": { drop: "also a cell — contradiction" }, "card-description": { asText: "caption" }, "card-footer": "transparent" },
|
|
218
|
+
});
|
|
219
|
+
expect(out).toContain("one sub, one disposition");
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe("the ledger never reports a discarded value as landed (findings 7, 11, 12)", () => {
|
|
224
|
+
it("a first-wins-skipped harvest ledgers as dropped/lossy, not moved", () => {
|
|
225
|
+
// The shipped v1 Table: authored caption prop beats the harvested one.
|
|
226
|
+
const { fidelity } = emitSurface(
|
|
227
|
+
surface({
|
|
228
|
+
component: "table",
|
|
229
|
+
props: { caption: "Authored" },
|
|
230
|
+
children: [{ component: "table-caption", text: "Harvested" }],
|
|
231
|
+
}),
|
|
232
|
+
doc,
|
|
233
|
+
{},
|
|
234
|
+
);
|
|
235
|
+
const discarded = fidelity.find((f) => f.kind === "dropped" && f.note?.includes("already written"));
|
|
236
|
+
expect(discarded).toBeDefined();
|
|
237
|
+
expect(discarded!.destination).toBe("(discarded)");
|
|
238
|
+
// And only ONE entry claims the caption landed.
|
|
239
|
+
expect(fidelity.filter((f) => f.destination === "caption")).toHaveLength(1);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("unrouted node text is a ledgered loss (warnings stay byte-frozen)", () => {
|
|
243
|
+
const { warnings, fidelity } = emitSurface(
|
|
244
|
+
surface({ component: "card", text: "orphaned words", children: [{ component: "badge", text: "x" }] }),
|
|
245
|
+
doc,
|
|
246
|
+
{},
|
|
247
|
+
);
|
|
248
|
+
// Warnings are byte-frozen: the discard appears in NO warning...
|
|
249
|
+
expect(warnings.every((w) => !w.message.includes("orphaned words"))).toBe(true);
|
|
250
|
+
// ...and in exactly one ledger entry.
|
|
251
|
+
const entry = fidelity.find((f) => f.note?.includes("no self.text route"));
|
|
252
|
+
expect(entry).toMatchObject({ kind: "dropped", class: "lossy", destination: "(discarded)" });
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("asText that destroys nested structure records flattened/lossy like the cell path", () => {
|
|
256
|
+
const { fidelity } = emitSurface(
|
|
257
|
+
surface({
|
|
258
|
+
component: "card",
|
|
259
|
+
children: [
|
|
260
|
+
{
|
|
261
|
+
component: "card-title",
|
|
262
|
+
children: [{ component: "badge", text: "Urgent" }],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
}),
|
|
266
|
+
doc,
|
|
267
|
+
{},
|
|
268
|
+
);
|
|
269
|
+
const loss = fidelity.find((f) => f.kind === "flattened" && f.source.includes("card-title"));
|
|
270
|
+
expect(loss).toMatchObject({ class: "lossy" });
|
|
271
|
+
expect(loss!.source).toContain("'badge'");
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe("function args are self-contained (finding 10)", () => {
|
|
276
|
+
it("a $ref inside declared args refuses at load with its path", () => {
|
|
277
|
+
try {
|
|
278
|
+
loadProfile(
|
|
279
|
+
v2Doc(
|
|
280
|
+
{ routes: [{ from: ["children"], to: "slot:child" }], subs: CARD_SUBS },
|
|
281
|
+
{ functions: { probe: { description: "d", returns: "boolean", args: { $ref: "#/$defs/DoesNotExist" } } } },
|
|
282
|
+
),
|
|
283
|
+
);
|
|
284
|
+
expect.unreachable("a $ref in function args must refuse");
|
|
285
|
+
} catch (e) {
|
|
286
|
+
expect(e).toBeInstanceOf(ProfileLoadError);
|
|
287
|
+
const issue = (e as ProfileLoadError).issues[0];
|
|
288
|
+
expect(issue.path).toBe("/functions/probe/args");
|
|
289
|
+
expect(issue.message).toContain("self-contained");
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drift gate for the schema mirrors. The .json files are the reviewable
|
|
3
|
+
* schema documents (docs/PROFILES.md and the README link them); the TS
|
|
4
|
+
* mirror modules are what the runtime imports, because the library surface
|
|
5
|
+
* must bundle for the browser without filesystem access. Both are committed,
|
|
6
|
+
* so this test is what keeps them the same document: a failure here means
|
|
7
|
+
* one side was edited without the other.
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { describe, expect, it } from "vitest";
|
|
12
|
+
import { catalogMetaSchemas } from "./validate/meta/catalog-meta.js";
|
|
13
|
+
import { profileSchema } from "./transform/profile-schema.js";
|
|
14
|
+
import { profileSchemaV2 } from "./transform/profile-schema-v2.js";
|
|
15
|
+
|
|
16
|
+
const doc = (rel: string): unknown =>
|
|
17
|
+
JSON.parse(readFileSync(fileURLToPath(new URL(rel, import.meta.url)), "utf8"));
|
|
18
|
+
|
|
19
|
+
describe("schema mirrors", () => {
|
|
20
|
+
it("catalog-meta mirror (0.9.1) equals a2ui-catalog.meta.0_9_1.json", () => {
|
|
21
|
+
expect(catalogMetaSchemas["0.9.1"]).toStrictEqual(doc("./validate/meta/a2ui-catalog.meta.0_9_1.json"));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("catalog-meta mirror (1.0) equals a2ui-catalog.meta.1_0.json", () => {
|
|
25
|
+
expect(catalogMetaSchemas["1.0"]).toStrictEqual(doc("./validate/meta/a2ui-catalog.meta.1_0.json"));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("profile-schema mirror equals profile.v1.schema.json", () => {
|
|
29
|
+
expect(profileSchema).toStrictEqual(doc("./transform/profile.v1.schema.json"));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("profile-schema-v2 mirror equals profile.v2.schema.json", () => {
|
|
33
|
+
expect(profileSchemaV2).toStrictEqual(doc("./transform/profile.v2.schema.json"));
|
|
34
|
+
});
|
|
35
|
+
});
|