@aestheticfunction/dspack-emit 0.5.0 → 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/dist/targets/a2ui/surface.js +474 -34
- package/dist/transform/mapping.js +21 -7
- package/dist/transform/model.d.ts +94 -1
- package/dist/transform/model.js +25 -4
- package/dist/transform/parse-v2.d.ts +55 -24
- package/dist/transform/parse-v2.js +176 -2
- package/dist/transform/profile-schema-v2.js +224 -46
- package/dist/transform/shadcn-v2-respelling.d.ts +65 -0
- package/dist/transform/shadcn-v2-respelling.js +407 -0
- package/dist/transform/validate-v2.js +39 -3
- package/dist/types.d.ts +5 -1
- 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 +1 -1
- package/src/a0.test.ts +235 -0
- package/src/eval-fixture.test.ts +27 -14
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-v2.test.ts +9 -3
- 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/surface.ts +625 -70
- package/src/transform/mapping.ts +22 -6
- package/src/transform/model.ts +107 -5
- package/src/transform/parse-v2.ts +228 -17
- package/src/transform/profile-schema-v2.ts +224 -46
- package/src/transform/profile.v2.schema.json +224 -46
- package/src/transform/shadcn-v2-respelling.ts +414 -0
- package/src/transform/validate-v2.ts +39 -3
- package/src/types.ts +13 -1
- package/src/validate-v2.test.ts +1 -1
package/src/t3.test.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3: declared key joins for repeated groups.
|
|
3
|
+
*
|
|
4
|
+
* Fail-first (/tmp/t3-failfirst.txt): the T2 suite pins the production
|
|
5
|
+
* radio-group emitting {value}-only options with its htmlFor-joined labels
|
|
6
|
+
* DROPPED with record; the join spelling was refused by the v2 grammar; and
|
|
7
|
+
* tabs' three subs sat in the 72-unresolved eval ledger.
|
|
8
|
+
*
|
|
9
|
+
* The join is DECLARED, never inferred: left family, joined family, a key
|
|
10
|
+
* from each side, fields from the joined side, cardinality. No positions,
|
|
11
|
+
* no nearest-sibling, no similarity. Every correctness edge refuses:
|
|
12
|
+
* missing keys, duplicate keys on either side, zero counterparts (unless
|
|
13
|
+
* declared optional), dangling counterparts. Provenance names item,
|
|
14
|
+
* counterpart, key, and destination in the ledger.
|
|
15
|
+
*
|
|
16
|
+
* Two measured shapes prove the model generalizes:
|
|
17
|
+
* - radio-group: item.id ↔ label.props.htmlFor (scalar joined field);
|
|
18
|
+
* - tabs: trigger.id ↔ content.id (the worked example joins on ids, though
|
|
19
|
+
* the contract also declares `value` on both), with the ratified
|
|
20
|
+
* SLOT-VALUED joined field — content children emit as instances and the
|
|
21
|
+
* record carries the reference. Repetition's slot field, not T4 routing.
|
|
22
|
+
*/
|
|
23
|
+
import { readFileSync } from "node:fs";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
import { describe, expect, it } from "vitest";
|
|
26
|
+
import { transformFromJson } from "./transform/index.js";
|
|
27
|
+
import { emitSurface, EmitSurfaceError } from "./targets/a2ui/surface.js";
|
|
28
|
+
import { loadProfile } from "./transform/profile-load.js";
|
|
29
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
30
|
+
|
|
31
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
32
|
+
const contract = JSON.parse(readFileSync(repo("eval/shadcn-v3.dspack.json"), "utf8")) as DspackDoc & {
|
|
33
|
+
examples: Array<{ id: string; surface: DspackSurface }>;
|
|
34
|
+
};
|
|
35
|
+
const fixture = JSON.parse(readFileSync(repo("eval/shadcn-v3.eval.profile.json"), "utf8"));
|
|
36
|
+
|
|
37
|
+
const RG_T3_SURFACE = {
|
|
38
|
+
collects: [
|
|
39
|
+
{
|
|
40
|
+
of: ["radio-group-item"],
|
|
41
|
+
into: "prop:options",
|
|
42
|
+
item: { value: "self.id" },
|
|
43
|
+
join: { with: ["label"], on: { left: "self.id", right: "self.props.htmlFor" }, fields: { label: "self.text" } },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const TABS_T3_SURFACE = {
|
|
49
|
+
collects: [
|
|
50
|
+
{
|
|
51
|
+
of: ["tabs-trigger"],
|
|
52
|
+
into: "prop:sections",
|
|
53
|
+
item: { title: "self.text", value: "self.id" },
|
|
54
|
+
join: { with: ["tabs-content"], on: { left: "self.id", right: "self.id" }, fields: { child: "children" } },
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const t3Profile = (mutate?: (doc: Record<string, unknown>) => void) => {
|
|
60
|
+
const base = structuredClone(fixture) as Record<string, unknown> & { components: Array<Record<string, unknown>> };
|
|
61
|
+
const pick = (id: string) => structuredClone(base.components.find((c) => c.dspackId === id)!);
|
|
62
|
+
const radioGroup = pick("radio-group");
|
|
63
|
+
radioGroup.surface = structuredClone(RG_T3_SURFACE);
|
|
64
|
+
(radioGroup.structural as Record<string, { schema: Record<string, unknown> }>).options.schema = {
|
|
65
|
+
type: "array",
|
|
66
|
+
items: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: { value: { type: "string" }, label: { type: "string" } },
|
|
69
|
+
required: ["value", "label"],
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const tabs = {
|
|
74
|
+
a2ui: "Tabs",
|
|
75
|
+
dspackId: "tabs",
|
|
76
|
+
commons: ["ComponentCommon"],
|
|
77
|
+
structural: {
|
|
78
|
+
sections: {
|
|
79
|
+
schema: {
|
|
80
|
+
type: "array",
|
|
81
|
+
items: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: { title: { type: "string" }, value: { type: "string" }, child: { $ref: "#/$defs/ComponentId" } },
|
|
84
|
+
required: ["title", "child"],
|
|
85
|
+
additionalProperties: false,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
description: "The tab sections: a title and the panel it reveals.",
|
|
89
|
+
synthNote: "A2UI models paired trigger/panel families as one array of {title, child} records (T3 declared join).",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
propMap: { defaultValue: { a2ui: "defaultValue", kind: "string" } },
|
|
93
|
+
required: ["sections"],
|
|
94
|
+
surface: structuredClone(TABS_T3_SURFACE),
|
|
95
|
+
// tabs-list is walked through on the way to the triggers it wraps.
|
|
96
|
+
};
|
|
97
|
+
const doc: Record<string, unknown> & { components: Array<Record<string, unknown>> } = {
|
|
98
|
+
...base,
|
|
99
|
+
components: [pick("card"), pick("badge"), radioGroup, tabs],
|
|
100
|
+
};
|
|
101
|
+
delete (doc as Record<string, unknown>)["x-scaffold"];
|
|
102
|
+
mutate?.(doc);
|
|
103
|
+
return loadProfile(doc);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const surfaceOf = (root: unknown): DspackSurface =>
|
|
107
|
+
({ dspackSurface: "0.1", system: contract.name as string, intent: "preference-settings", root }) as DspackSurface;
|
|
108
|
+
|
|
109
|
+
/** The production notification-preferences radio-group, verbatim shape. */
|
|
110
|
+
const RG_SURFACE = {
|
|
111
|
+
component: "radio-group",
|
|
112
|
+
props: { name: "digest", defaultValue: "monday" },
|
|
113
|
+
children: [
|
|
114
|
+
{ component: "radio-group-item", id: "digest-monday" },
|
|
115
|
+
{ component: "label", props: { htmlFor: "digest-monday" }, text: "Monday morning" },
|
|
116
|
+
{ component: "radio-group-item", id: "digest-friday" },
|
|
117
|
+
{ component: "label", props: { htmlFor: "digest-friday" }, text: "Friday afternoon" },
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const emit = (root: unknown, profile = t3Profile()) => emitSurface(surfaceOf(root), contract, { profile });
|
|
122
|
+
const firstInstance = (r: { messages: unknown[] }) =>
|
|
123
|
+
(r.messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components[0];
|
|
124
|
+
|
|
125
|
+
describe("T3 joins the production radio-group", () => {
|
|
126
|
+
it("options carry BOTH value and label; no label is dropped once the join is configured", () => {
|
|
127
|
+
const r = emit(RG_SURFACE);
|
|
128
|
+
const rg = firstInstance(r);
|
|
129
|
+
expect(rg.options).toEqual([
|
|
130
|
+
{ value: "digest-monday", label: "Monday morning" },
|
|
131
|
+
{ value: "digest-friday", label: "Friday afternoon" },
|
|
132
|
+
]);
|
|
133
|
+
expect(r.warnings.filter((w) => w.code === "surface-sub-dropped" && w.message.includes("'label'"))).toHaveLength(0);
|
|
134
|
+
|
|
135
|
+
// Provenance: each counterpart ledgered as joined, naming the key.
|
|
136
|
+
const joined = r.fidelity.filter((f) => f.kind === "joined");
|
|
137
|
+
expect(joined).toHaveLength(2);
|
|
138
|
+
expect(joined[0].source).toContain("label");
|
|
139
|
+
expect(joined[0].note).toContain("digest-monday");
|
|
140
|
+
expect(joined[0].class).toBe("maps-cleanly");
|
|
141
|
+
|
|
142
|
+
// A1-A3: the emitted instance validates against the generated catalog.
|
|
143
|
+
const check = transformFromJson(contract, { profile: t3Profile(), surface: { messages: r.messages } });
|
|
144
|
+
expect(check.validation.pass).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("emission is deterministic across runs", () => {
|
|
148
|
+
const a = emit(RG_SURFACE);
|
|
149
|
+
const b = emit(RG_SURFACE);
|
|
150
|
+
expect(JSON.stringify([a.messages, a.warnings, a.fidelity])).toBe(JSON.stringify([b.messages, b.warnings, b.fidelity]));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("T3 correctness edges — every one refuses", () => {
|
|
155
|
+
const rg = (children: unknown[]) => ({ component: "radio-group", children });
|
|
156
|
+
|
|
157
|
+
it("zero counterparts refuses (exactly-one is the default)", () => {
|
|
158
|
+
expect(() => emit(rg([{ component: "radio-group-item", id: "a" }]))).toThrowError(/no counterpart/);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("optional: true relaxes zero counterparts to an omitted field, arbitrated by A3", () => {
|
|
162
|
+
const profile = t3Profile((doc) => {
|
|
163
|
+
const plan = (doc.components as Array<Record<string, unknown>>).find((c) => c.dspackId === "radio-group")!;
|
|
164
|
+
((plan.surface as typeof RG_T3_SURFACE).collects[0].join as Record<string, unknown>).optional = true;
|
|
165
|
+
});
|
|
166
|
+
const r = emit(rg([{ component: "radio-group-item", id: "a" }]), profile);
|
|
167
|
+
expect(firstInstance(r).options).toEqual([{ value: "a" }]);
|
|
168
|
+
// The record schema requires label, so A3 refuses — relocation, never synthesis.
|
|
169
|
+
const check = transformFromJson(contract, { profile, surface: { messages: r.messages } });
|
|
170
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("multiple counterparts for one key refuse (duplicate right keys)", () => {
|
|
174
|
+
expect(() =>
|
|
175
|
+
emit(
|
|
176
|
+
rg([
|
|
177
|
+
{ component: "radio-group-item", id: "a" },
|
|
178
|
+
{ component: "label", props: { htmlFor: "a" }, text: "One" },
|
|
179
|
+
{ component: "label", props: { htmlFor: "a" }, text: "Two" },
|
|
180
|
+
]),
|
|
181
|
+
),
|
|
182
|
+
).toThrowError(/duplicate right key 'a'/);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("duplicate left keys refuse", () => {
|
|
186
|
+
expect(() =>
|
|
187
|
+
emit(
|
|
188
|
+
rg([
|
|
189
|
+
{ component: "radio-group-item", id: "a" },
|
|
190
|
+
{ component: "radio-group-item", id: "a" },
|
|
191
|
+
{ component: "label", props: { htmlFor: "a" }, text: "One" },
|
|
192
|
+
]),
|
|
193
|
+
),
|
|
194
|
+
).toThrowError(/duplicate left key 'a'/);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("a missing left key refuses", () => {
|
|
198
|
+
expect(() =>
|
|
199
|
+
emit(rg([{ component: "radio-group-item" }, { component: "label", props: { htmlFor: "a" }, text: "One" }])),
|
|
200
|
+
).toThrowError(/carries no key/);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("a missing right key refuses", () => {
|
|
204
|
+
expect(() =>
|
|
205
|
+
emit(rg([{ component: "radio-group-item", id: "a" }, { component: "label", text: "Loose" }])),
|
|
206
|
+
).toThrowError(/carries no key/);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("a dangling counterpart refuses — unrelated siblings cannot satisfy a join", () => {
|
|
210
|
+
expect(() =>
|
|
211
|
+
emit(
|
|
212
|
+
rg([
|
|
213
|
+
{ component: "radio-group-item", id: "a" },
|
|
214
|
+
{ component: "label", props: { htmlFor: "a" }, text: "One" },
|
|
215
|
+
{ component: "label", props: { htmlFor: "elsewhere" }, text: "Points nowhere" },
|
|
216
|
+
]),
|
|
217
|
+
),
|
|
218
|
+
).toThrowError(/dangling counterpart/);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("a casualty inside the joined subtree still refuses (casualty enforcement is live)", () => {
|
|
222
|
+
const profile = t3Profile((doc) => {
|
|
223
|
+
(doc.casualtyComponents as unknown[]) = [
|
|
224
|
+
{ dspackId: "badge", attempted: "(none)", class: "cannot-represent", reason: "test casualty" },
|
|
225
|
+
];
|
|
226
|
+
(doc.components as Array<Record<string, unknown>>).splice(
|
|
227
|
+
(doc.components as Array<Record<string, unknown>>).findIndex((c) => c.dspackId === "badge"),
|
|
228
|
+
1,
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
const tabsSurface = {
|
|
232
|
+
component: "tabs",
|
|
233
|
+
children: [
|
|
234
|
+
{ component: "tabs-list", children: [{ component: "tabs-trigger", id: "t1", text: "Tab" }] },
|
|
235
|
+
{ component: "tabs-content", id: "t1", children: [{ component: "badge", text: "inside the panel" }] },
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
expect(() => emit(tabsSurface, profile)).toThrowError(/declared casualty/);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("T3 generalizes: tabs joins trigger ↔ content with a slot-valued field", () => {
|
|
243
|
+
const TABS_SURFACE = {
|
|
244
|
+
component: "tabs",
|
|
245
|
+
props: { defaultValue: "overview" },
|
|
246
|
+
children: [
|
|
247
|
+
{
|
|
248
|
+
component: "tabs-list",
|
|
249
|
+
children: [
|
|
250
|
+
{ component: "tabs-trigger", id: "overview", text: "Overview" },
|
|
251
|
+
{ component: "tabs-trigger", id: "activity", text: "Activity" },
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
{ component: "tabs-content", id: "overview", children: [{ component: "badge", text: "All systems go" }] },
|
|
255
|
+
{ component: "tabs-content", id: "activity", children: [{ component: "badge", text: "3 deploys today" }] },
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
it("sections carry {title, value, child}; panels emit as real instances", () => {
|
|
260
|
+
const r = emit(TABS_SURFACE);
|
|
261
|
+
const components = (r.messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } })
|
|
262
|
+
.updateComponents.components;
|
|
263
|
+
const tabs = components[0];
|
|
264
|
+
expect(tabs.component).toBe("Tabs");
|
|
265
|
+
const sections = tabs.sections as Array<Record<string, unknown>>;
|
|
266
|
+
expect(sections.map((s) => s.title)).toEqual(["Overview", "Activity"]);
|
|
267
|
+
expect(sections.map((s) => s.value)).toEqual(["overview", "activity"]);
|
|
268
|
+
// Each child is a reference to a REAL emitted instance.
|
|
269
|
+
for (const section of sections) {
|
|
270
|
+
const child = components.find((c) => c.id === section.child);
|
|
271
|
+
expect(child?.component).toBe("Badge");
|
|
272
|
+
}
|
|
273
|
+
expect(JSON.stringify(components)).toContain("All systems go");
|
|
274
|
+
|
|
275
|
+
const check = transformFromJson(contract, { profile: t3Profile(), surface: { messages: r.messages } });
|
|
276
|
+
expect(check.validation.pass).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("the join is keyed, not positional: shuffled content order still pairs correctly", () => {
|
|
280
|
+
const shuffled = structuredClone(TABS_SURFACE);
|
|
281
|
+
const kids = shuffled.children as Array<Record<string, unknown>>;
|
|
282
|
+
[kids[1], kids[2]] = [kids[2], kids[1]]; // activity panel now precedes overview's
|
|
283
|
+
const r = emit(shuffled);
|
|
284
|
+
const components = (r.messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } })
|
|
285
|
+
.updateComponents.components;
|
|
286
|
+
const sections = (components[0].sections as Array<Record<string, unknown>>);
|
|
287
|
+
const overview = sections.find((s) => s.value === "overview")!;
|
|
288
|
+
const panel = components.find((c) => c.id === overview.child);
|
|
289
|
+
expect(JSON.stringify(panel)).not.toContain("3 deploys");
|
|
290
|
+
const panelSubtree = components.filter((c) => c.id === overview.child || (panel && c.id === panel.children));
|
|
291
|
+
expect(JSON.stringify(panelSubtree)).toBeDefined();
|
|
292
|
+
const resolved = components.find((c) => c.id === overview.child);
|
|
293
|
+
expect(JSON.stringify(resolved)).toContain(String(overview.child));
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("derived coverage resolves the tabs family through the join", () => {
|
|
297
|
+
const out = transformFromJson(contract, { profile: t3Profile() });
|
|
298
|
+
const unresolved = out.mapping.coverage.filter(
|
|
299
|
+
(c) => c.disposition === "unclassified" && c.id.startsWith("tabs."),
|
|
300
|
+
);
|
|
301
|
+
expect(unresolved).toEqual([]);
|
|
302
|
+
expect(out.mapping.coverage.find((c) => c.id === "tabs.tabs-content")?.detail).toContain("joined");
|
|
303
|
+
});
|
|
304
|
+
});
|
package/src/t4.test.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T4: multi-slot compounds — `sub(x).children -> slot:name`.
|
|
3
|
+
*
|
|
4
|
+
* Fail-first (/tmp/t4-failfirst.txt, captured at main e21e0bf before any
|
|
5
|
+
* code): the spelling was refused by the v2 grammar ("must match pattern");
|
|
6
|
+
* the 50-unresolved ledger carried dialog 7 + sheet 7 + popover 6 +
|
|
7
|
+
* dropdown-menu 12; ex.invite-teammates-dialog and
|
|
8
|
+
* ex.customer-context-sheet refused end-to-end; and the containment
|
|
9
|
+
* re-baseline's overlay-task produced a fully lint-clean surface the
|
|
10
|
+
* emitter refused on unmapped 'dialog'.
|
|
11
|
+
*
|
|
12
|
+
* The primitive is ONE closed spelling: the ordered children of exactly one
|
|
13
|
+
* descendant instance of the named region become instances; the slot
|
|
14
|
+
* carries the reference (multi wraps in Column — T3's joined-children
|
|
15
|
+
* discipline). Regions have no fallback chains, one region feeds one slot,
|
|
16
|
+
* zero regions leave the destination absent for gate A3, several refuse.
|
|
17
|
+
* Claimed subs (text harvests, sibling slots) are skipped at any
|
|
18
|
+
* dissolution depth — their consumption is their own route's ledger line.
|
|
19
|
+
*
|
|
20
|
+
* The measured surprise, followed rather than the roadmap: dropdown-menu is
|
|
21
|
+
* DATA-shaped (a T2 collect + scalar text routes) and needs no slot at all.
|
|
22
|
+
*/
|
|
23
|
+
import { readFileSync } from "node:fs";
|
|
24
|
+
import { fileURLToPath } from "node:url";
|
|
25
|
+
import { describe, expect, it } from "vitest";
|
|
26
|
+
import { transformFromJson } from "./transform/index.js";
|
|
27
|
+
import { emitSurface, EmitSurfaceError } from "./targets/a2ui/surface.js";
|
|
28
|
+
import { loadProfile, ProfileLoadError } from "./transform/profile-load.js";
|
|
29
|
+
import { SHADCN_V3_T4_PLANS } from "./transform/shadcn-v2-respelling.js";
|
|
30
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
31
|
+
|
|
32
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
33
|
+
const contract = JSON.parse(readFileSync(repo("eval/shadcn-v3.dspack.json"), "utf8")) as DspackDoc & {
|
|
34
|
+
examples: Array<{ id: string; surface: DspackSurface }>;
|
|
35
|
+
};
|
|
36
|
+
const fixture = JSON.parse(readFileSync(repo("eval/shadcn-v3.eval.profile.json"), "utf8"));
|
|
37
|
+
|
|
38
|
+
const KEEP = ["card", "badge", "button", "input", "textarea", "select", "field", "field-set", "field-group", "scroll-area", "dialog", "sheet", "popover", "dropdown-menu"];
|
|
39
|
+
|
|
40
|
+
const t4Profile = (mutate?: (doc: Record<string, unknown>) => void) => {
|
|
41
|
+
const base = structuredClone(fixture) as Record<string, unknown> & {
|
|
42
|
+
components: Array<Record<string, unknown> & { dspackId: string }>;
|
|
43
|
+
};
|
|
44
|
+
base.components = base.components.map((plan) => {
|
|
45
|
+
const t4 = SHADCN_V3_T4_PLANS[plan.dspackId];
|
|
46
|
+
return t4 ? (structuredClone(t4) as typeof plan) : plan;
|
|
47
|
+
});
|
|
48
|
+
const keepSet = new Set(KEEP);
|
|
49
|
+
base.intentionallyOmitted = base.components.filter((c) => !keepSet.has(c.dspackId)).map((c) => c.dspackId).sort();
|
|
50
|
+
base.components = base.components.filter((c) => keepSet.has(c.dspackId));
|
|
51
|
+
delete (base as Record<string, unknown>)["x-scaffold"];
|
|
52
|
+
mutate?.(base);
|
|
53
|
+
return loadProfile(base);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const surfaceOf = (root: unknown, intent = "overlay-task"): DspackSurface =>
|
|
57
|
+
({ dspackSurface: "0.1", system: contract.name as string, intent, root }) as DspackSurface;
|
|
58
|
+
|
|
59
|
+
const emit = (root: unknown, profile = t4Profile()) => emitSurface(surfaceOf(root), contract, { profile });
|
|
60
|
+
|
|
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 instancesOf = (messages: unknown[]) =>
|
|
75
|
+
(messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
76
|
+
|
|
77
|
+
describe("T4 grammar and gates", () => {
|
|
78
|
+
it("the slot spelling loads (the fail-first refusal, inverted)", () => {
|
|
79
|
+
expect(t4Profile().language).toBe("v2");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("a region has no fallback chain: sub(a|b).children refuses", () => {
|
|
83
|
+
expect(() =>
|
|
84
|
+
t4Profile((doc) => {
|
|
85
|
+
const d = (doc.components as Array<Record<string, unknown>>).find((c) => c.dspackId === "dialog")!;
|
|
86
|
+
(d.surface as { routes: unknown[] }).routes = [{ from: ["sub(dialog-content|dialog-footer).children"], to: "slot:child" }];
|
|
87
|
+
}),
|
|
88
|
+
).toThrowError(ProfileLoadError);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("one region, one slot: the same sub sourcing two slot routes refuses", () => {
|
|
92
|
+
expect(() =>
|
|
93
|
+
t4Profile((doc) => {
|
|
94
|
+
const d = (doc.components as Array<Record<string, unknown>>).find((c) => c.dspackId === "dialog")!;
|
|
95
|
+
(d.surface as { routes: unknown[] }).routes = [
|
|
96
|
+
{ from: ["sub(dialog-content).children"], to: "slot:child" },
|
|
97
|
+
{ from: ["sub(dialog-content).children"], to: "slot:footer" },
|
|
98
|
+
];
|
|
99
|
+
}),
|
|
100
|
+
).toThrowError(ProfileLoadError);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("sub(x).children lands only in a slot: prop destination refuses", () => {
|
|
104
|
+
expect(() =>
|
|
105
|
+
t4Profile((doc) => {
|
|
106
|
+
const d = (doc.components as Array<Record<string, unknown>>).find((c) => c.dspackId === "dialog")!;
|
|
107
|
+
(d.surface as { routes: unknown[] }).routes = [{ from: ["sub(dialog-content).children"], to: "prop:title" }];
|
|
108
|
+
}),
|
|
109
|
+
).toThrowError(ProfileLoadError);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("T4 — dialog (the production invite-teammates shape, verbatim)", () => {
|
|
114
|
+
it("emits {title, description, triggerLabel, closeLabel, child, footer}; fields inside the slot dissolve and donate", () => {
|
|
115
|
+
const { messages, fidelity } = emit(fromExample("ex.invite-teammates-dialog", "dialog"));
|
|
116
|
+
const comps = instancesOf(messages);
|
|
117
|
+
const dialog = comps.find((c) => c.component === "Dialog")!;
|
|
118
|
+
expect(dialog.title).toBe("Invite people to Northwind");
|
|
119
|
+
expect(dialog.triggerLabel).toBe("Invite people");
|
|
120
|
+
expect(dialog.closeLabel).toBe("Cancel");
|
|
121
|
+
expect(typeof dialog.description).toBe("string");
|
|
122
|
+
|
|
123
|
+
// The body slot: two fields dissolve to Textarea + Select, each followed
|
|
124
|
+
// by its field-description as a Text caption — four instances,
|
|
125
|
+
// Column-wrapped, in reading order.
|
|
126
|
+
const body = comps.find((c) => c.id === dialog.child)!;
|
|
127
|
+
expect(body.component).toBe("Column");
|
|
128
|
+
const textarea = comps.find((c) => c.component === "Textarea")!;
|
|
129
|
+
const select = comps.find((c) => c.component === "Select")!;
|
|
130
|
+
expect(textarea.label).toBe("Email addresses");
|
|
131
|
+
expect(select.label).toBe("Role");
|
|
132
|
+
expect((select.options as unknown[]).length).toBe(3);
|
|
133
|
+
const bodyIds = body.children as string[];
|
|
134
|
+
expect(bodyIds).toHaveLength(4);
|
|
135
|
+
expect(bodyIds[0]).toBe(textarea.id);
|
|
136
|
+
expect(bodyIds[2]).toBe(select.id);
|
|
137
|
+
for (const i of [1, 3]) {
|
|
138
|
+
const t = comps.find((c) => c.id === bodyIds[i])!;
|
|
139
|
+
expect(t.component).toBe("Text");
|
|
140
|
+
expect(t.variant).toBe("caption");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The footer slot: close is a claimed text lift; the send button remains.
|
|
144
|
+
const footerRef = comps.find((c) => c.id === dialog.footer)!;
|
|
145
|
+
expect(footerRef.component).toBe("Button");
|
|
146
|
+
expect(footerRef.child).toBeDefined();
|
|
147
|
+
|
|
148
|
+
// No wrapper instance for header; the regions ledger as moved.
|
|
149
|
+
expect(comps.some((c) => c.component === "DialogHeader")).toBe(false);
|
|
150
|
+
expect(fidelity.some((f) => f.kind === "moved" && f.source.includes("dialog-content children"))).toBe(true);
|
|
151
|
+
|
|
152
|
+
const profile = t4Profile();
|
|
153
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
154
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("two instances of a region refuse: a slot names ONE region", () => {
|
|
158
|
+
expect(() =>
|
|
159
|
+
emit({
|
|
160
|
+
component: "dialog",
|
|
161
|
+
children: [
|
|
162
|
+
{ component: "dialog-content", children: [{ component: "dialog-title", text: "A" }] },
|
|
163
|
+
{ component: "dialog-content", children: [{ component: "badge", text: "B" }] },
|
|
164
|
+
],
|
|
165
|
+
}),
|
|
166
|
+
).toThrowError(/ONE region/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("an unclaimed direct child of a slot compound refuses — fail-closed, never approximated", () => {
|
|
170
|
+
expect(() =>
|
|
171
|
+
emit({
|
|
172
|
+
component: "dialog",
|
|
173
|
+
children: [
|
|
174
|
+
{ component: "dialog-content", children: [{ component: "dialog-title", text: "T" }] },
|
|
175
|
+
{ component: "badge", text: "stray" },
|
|
176
|
+
],
|
|
177
|
+
}),
|
|
178
|
+
).toThrowError(/no destination/);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("a casualty inside a slot still refuses (casualty enforcement is live inside regions)", () => {
|
|
182
|
+
const profile = t4Profile((doc) => {
|
|
183
|
+
(doc.casualtyComponents as unknown[]) = [
|
|
184
|
+
{ dspackId: "badge", attempted: "(none)", class: "cannot-represent", reason: "test casualty" },
|
|
185
|
+
];
|
|
186
|
+
(doc.components as Array<Record<string, unknown>>).splice(
|
|
187
|
+
(doc.components as Array<Record<string, unknown>>).findIndex((c) => c.dspackId === "badge"),
|
|
188
|
+
1,
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
expect(() =>
|
|
192
|
+
emit(
|
|
193
|
+
{
|
|
194
|
+
component: "dialog",
|
|
195
|
+
children: [
|
|
196
|
+
{ component: "dialog-content", children: [{ component: "dialog-title", text: "T" }, { component: "badge", text: "x" }] },
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
profile,
|
|
200
|
+
),
|
|
201
|
+
).toThrowError(/declared casualty/);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("T4 — sheet composes with shipped primitives (the customer-context shape, verbatim)", () => {
|
|
206
|
+
it("scroll-area DISSOLVES inside the body slot; cards emit; footer keeps the non-close action", () => {
|
|
207
|
+
const { messages } = emit(fromExample("ex.customer-context-sheet", "sheet"));
|
|
208
|
+
const comps = instancesOf(messages);
|
|
209
|
+
const sheet = comps.find((c) => c.component === "Sheet")!;
|
|
210
|
+
expect(sheet.title).toBe("Amara Okafor");
|
|
211
|
+
expect(sheet.triggerLabel).toBe("Customer context");
|
|
212
|
+
expect(sheet.closeLabel).toBe("Close");
|
|
213
|
+
expect(comps.some((c) => c.component === "ScrollArea")).toBe(false);
|
|
214
|
+
const body = comps.find((c) => c.id === sheet.child)!;
|
|
215
|
+
expect(body.component).toBe("Column");
|
|
216
|
+
expect((body.children as string[]).length).toBe(3);
|
|
217
|
+
for (const cid of body.children as string[]) {
|
|
218
|
+
expect(comps.find((c) => c.id === cid)!.component).toBe("Card");
|
|
219
|
+
}
|
|
220
|
+
const check = transformFromJson(contract, { profile: t4Profile(), surface: { messages } });
|
|
221
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("T4 — popover's measured empty body stays absent", () => {
|
|
226
|
+
it("emits {triggerLabel, title, description}; the child slot is absent and A3 accepts it", () => {
|
|
227
|
+
const { messages } = emit(fromExample("ex.usage-help-affordances", "popover"));
|
|
228
|
+
const comps = instancesOf(messages);
|
|
229
|
+
const pop = comps.find((c) => c.component === "Popover")!;
|
|
230
|
+
expect(pop.triggerLabel).toBe("How usage is measured");
|
|
231
|
+
expect(pop.title).toBe("How usage is measured");
|
|
232
|
+
expect(pop.child).toBeUndefined();
|
|
233
|
+
const check = transformFromJson(contract, { profile: t4Profile(), surface: { messages } });
|
|
234
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("T4 finding — dropdown-menu is data, not slots (measurement over roadmap)", () => {
|
|
239
|
+
it("the production workspace menu emits {triggerLabel, menuLabel, items}; the separator drops with record", () => {
|
|
240
|
+
const { messages, fidelity } = emit(fromExample("ex.workspace-members-directory", "dropdown-menu"));
|
|
241
|
+
const comps = instancesOf(messages);
|
|
242
|
+
const menu = comps.find((c) => c.component === "DropdownMenu")!;
|
|
243
|
+
expect(menu.triggerLabel).toBe("Member actions");
|
|
244
|
+
expect(menu.menuLabel).toBe("Selected members");
|
|
245
|
+
expect(menu.items).toEqual([
|
|
246
|
+
{ label: "Resend invitation" },
|
|
247
|
+
{ label: "Change role" },
|
|
248
|
+
{ label: "Export as CSV" },
|
|
249
|
+
]);
|
|
250
|
+
// The nested separator's loss rides the collect's flatten record (it is
|
|
251
|
+
// inside dropdown-menu-content, not a direct child); the authored drop
|
|
252
|
+
// reason lives on the coverage row — the same two-channel honesty as A0.
|
|
253
|
+
expect(fidelity.some((f) => f.kind === "flattened" && f.class === "lossy")).toBe(true);
|
|
254
|
+
const out = transformFromJson(contract, { profile: t4Profile() });
|
|
255
|
+
expect(out.mapping.coverage.find((c) => c.id === "dropdown-menu.dropdown-menu-separator")?.detail).toContain("divider");
|
|
256
|
+
const check = transformFromJson(contract, { profile: t4Profile(), surface: { messages } });
|
|
257
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("T4 — ledger and determinism", () => {
|
|
262
|
+
it("all four families derive zero unresolved subs", () => {
|
|
263
|
+
const out = transformFromJson(contract, { profile: t4Profile() });
|
|
264
|
+
const unresolved = out.mapping.coverage.filter(
|
|
265
|
+
(c) => c.disposition === "unclassified" &&
|
|
266
|
+
["dialog.", "sheet.", "popover.", "dropdown-menu."].some((p) => c.id.startsWith(p)),
|
|
267
|
+
);
|
|
268
|
+
expect(unresolved).toEqual([]);
|
|
269
|
+
expect(out.mapping.coverage.find((c) => c.id === "dialog.dialog-content")?.detail).toContain("slot");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("emission is deterministic across runs", () => {
|
|
273
|
+
const subtree = fromExample("ex.invite-teammates-dialog", "dialog");
|
|
274
|
+
const a = emit(subtree);
|
|
275
|
+
const b = emit(subtree);
|
|
276
|
+
expect(JSON.stringify([a.messages, a.warnings, a.fidelity])).toBe(JSON.stringify([b.messages, b.warnings, b.fidelity]));
|
|
277
|
+
});
|
|
278
|
+
});
|