@aestheticfunction/dspack-emit 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +5 -3
  2. package/dist/targets/a2ui/surface.js +580 -36
  3. package/dist/transform/mapping.js +21 -7
  4. package/dist/transform/model.d.ts +94 -1
  5. package/dist/transform/model.js +25 -4
  6. package/dist/transform/parse-v2.d.ts +55 -24
  7. package/dist/transform/parse-v2.js +176 -2
  8. package/dist/transform/profile-schema-v2.js +224 -46
  9. package/dist/transform/shadcn-v2-respelling.d.ts +65 -0
  10. package/dist/transform/shadcn-v2-respelling.js +407 -0
  11. package/dist/transform/validate-v2.js +39 -3
  12. package/dist/types.d.ts +5 -1
  13. package/dist/validate/ajv.d.ts +19 -0
  14. package/dist/validate/ajv.js +78 -13
  15. package/package.json +6 -2
  16. package/src/a0.test.ts +235 -0
  17. package/src/engine-boundary.test.ts +10 -0
  18. package/src/eval-fixture.test.ts +27 -14
  19. package/src/instance-diagnostics.test.ts +194 -0
  20. package/src/layered-dissolution.test.ts +139 -0
  21. package/src/profile-v2.test.ts +9 -3
  22. package/src/review-findings.test.ts +4 -1
  23. package/src/surface-emit.test.ts +43 -11
  24. package/src/surface-fidelity.test.ts +12 -0
  25. package/src/t1.test.ts +370 -0
  26. package/src/t2.test.ts +222 -0
  27. package/src/t3.test.ts +304 -0
  28. package/src/t4.test.ts +278 -0
  29. package/src/targets/a2ui/surface.ts +747 -72
  30. package/src/transform/mapping.ts +22 -6
  31. package/src/transform/model.ts +107 -5
  32. package/src/transform/parse-v2.ts +228 -17
  33. package/src/transform/profile-schema-v2.ts +224 -46
  34. package/src/transform/profile.v2.schema.json +224 -46
  35. package/src/transform/shadcn-v2-respelling.ts +414 -0
  36. package/src/transform/validate-v2.ts +39 -3
  37. package/src/types.ts +13 -1
  38. package/src/validate/ajv.ts +96 -12
  39. package/src/validate-v2.test.ts +1 -1
package/src/t2.test.ts ADDED
@@ -0,0 +1,222 @@
1
+ /**
2
+ * T2: homogeneous repeated sub-structure → data array (item-mode collection).
3
+ *
4
+ * Fail-first (captured before any code, /tmp/t2-failfirst.txt): the eval
5
+ * ledger carries radio-group-item and select's seven subs among its 80
6
+ * unresolved; the item-mode spelling was refused by the v2 grammar; and
7
+ * ex.notification-preferences refused end-to-end.
8
+ *
9
+ * The measured shapes that scoped this milestone:
10
+ * - `select-item` carries its label as its OWN text — the pure homogeneous
11
+ * shape, collected completely by T2;
12
+ * - `radio-group-item` carries ONLY its id; its label is a SIBLING `label`
13
+ * joined by htmlFor→id — a DECLARED KEY JOIN, which is T3's mechanism.
14
+ * T2 collects what each item itself carries ({value: self.id}) and the
15
+ * sibling labels are dropped WITH RECORD — the measured T3 frontier, not
16
+ * a T2 defect. Position-based pairing is banned by the ratified model.
17
+ * - Neither item declares a `value` prop in the contract (the example
18
+ * encodes value into ids by convention) — a contract-modeling gap noted
19
+ * for the taxonomy trail, not papered over here.
20
+ */
21
+ import { readFileSync } from "node:fs";
22
+ import { fileURLToPath } from "node:url";
23
+ import { describe, expect, it } from "vitest";
24
+ import { transformFromJson } from "./transform/index.js";
25
+ import { emitSurface } from "./targets/a2ui/surface.js";
26
+ import { loadProfile, ProfileLoadError } from "./transform/profile-load.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
+ const RG_T2_SURFACE = {
36
+ collects: [{ of: ["radio-group-item"], into: "prop:options", item: { value: "self.id" } }],
37
+ };
38
+ const SELECT_T2_SURFACE = {
39
+ collects: [{ of: ["select-item"], into: "prop:options", item: { label: "self.text" } }],
40
+ subs: {
41
+ "select-trigger": { drop: "the trigger renders from the bound value, not authored content" },
42
+ "select-value": { drop: "the visible value is runtime state derived from the selection" },
43
+ "select-label": { drop: "group headings are not carried by the flat options shape" },
44
+ "select-separator": { drop: "visual grouping chrome with no data meaning" },
45
+ },
46
+ };
47
+
48
+ /** Hermetic T2 profile: radio-group + select plans over the eval fixture base. */
49
+ const t2Profile = (mutate?: (doc: Record<string, unknown>) => void) => {
50
+ const base = structuredClone(fixture) as Record<string, unknown> & { components: Array<Record<string, unknown>> };
51
+ const pick = (id: string) => structuredClone(base.components.find((c) => c.dspackId === id)!);
52
+ const radioGroup = {
53
+ a2ui: "RadioGroup",
54
+ dspackId: "radio-group",
55
+ commons: ["ComponentCommon"],
56
+ structural: {
57
+ options: {
58
+ schema: { type: "array", items: { type: "object", properties: { value: { type: "string" }, label: { type: "string" } }, required: ["value"], additionalProperties: false } },
59
+ description: "The selectable options, one record per item.",
60
+ synthNote: "A2UI models repeated options as data on the group; dspack models them as repeated sub-components.",
61
+ },
62
+ },
63
+ propMap: { name: { a2ui: "name", kind: "string" }, defaultValue: { a2ui: "defaultValue", kind: "string" } },
64
+ required: ["options"],
65
+ surface: structuredClone(RG_T2_SURFACE),
66
+ };
67
+ const select = {
68
+ a2ui: "Select",
69
+ dspackId: "select",
70
+ commons: ["ComponentCommon"],
71
+ structural: {
72
+ options: {
73
+ schema: { type: "array", items: { type: "object", properties: { label: { type: "string" } }, required: ["label"], additionalProperties: false } },
74
+ description: "The selectable options.",
75
+ synthNote: "A2UI models repeated options as data on the control.",
76
+ },
77
+ },
78
+ propMap: { defaultValue: { a2ui: "defaultValue", kind: "string" } },
79
+ required: ["options"],
80
+ surface: structuredClone(SELECT_T2_SURFACE),
81
+ };
82
+ const doc: Record<string, unknown> & { components: Array<Record<string, unknown>> } = {
83
+ ...base,
84
+ components: [pick("card"), radioGroup, select],
85
+ };
86
+ delete (doc as Record<string, unknown>)["x-scaffold"];
87
+ mutate?.(doc);
88
+ return loadProfile(doc);
89
+ };
90
+
91
+ const surfaceOf = (root: unknown): DspackSurface =>
92
+ ({ dspackSurface: "0.1", system: contract.name as string, intent: "preference-settings", root }) as DspackSurface;
93
+
94
+ /** The production notification-preferences radio-group, verbatim shape. */
95
+ const RG_SURFACE = {
96
+ component: "radio-group",
97
+ props: { name: "digest", defaultValue: "monday" },
98
+ children: [
99
+ { component: "radio-group-item", id: "digest-monday" },
100
+ { component: "label", props: { htmlFor: "digest-monday" }, text: "Monday morning" },
101
+ { component: "radio-group-item", id: "digest-friday" },
102
+ { component: "label", props: { htmlFor: "digest-friday" }, text: "Friday afternoon" },
103
+ ],
104
+ };
105
+
106
+ describe("T2 grammar and gates", () => {
107
+ it("the item-mode spelling loads (the fail-first refusal, inverted)", () => {
108
+ expect(t2Profile().language).toBe("v2");
109
+ });
110
+
111
+ it("mixing item-mode and table-mode keys refuses", () => {
112
+ expect(() =>
113
+ t2Profile((doc) => {
114
+ const rg = (doc.components as Array<Record<string, unknown>>).find((c) => c.dspackId === "radio-group")!;
115
+ rg.surface = { collects: [{ of: ["radio-group-item"], into: "prop:options", item: { value: "self.id" }, shape: "flat", row: ["x"], cells: ["y"] }] };
116
+ }),
117
+ ).toThrowError(ProfileLoadError);
118
+ });
119
+
120
+ it("item fields are item-local: a sub() read refuses at the item field's path", () => {
121
+ // The schema's closed item-selector pattern fires first (self.text |
122
+ // self.id | self.props.<prop>); the parse layer carries the same rule
123
+ // with a T3-naming message as defense-in-depth behind it.
124
+ try {
125
+ t2Profile((doc) => {
126
+ const rg = (doc.components as Array<Record<string, unknown>>).find((c) => c.dspackId === "radio-group")!;
127
+ rg.surface = { collects: [{ of: ["radio-group-item"], into: "prop:options", item: { label: "sub(label).text" } }] };
128
+ });
129
+ expect.unreachable("a join read must refuse");
130
+ } catch (e) {
131
+ const issues = (e as ProfileLoadError).issues;
132
+ expect(issues.some((i) => i.path.includes("/item/label") || i.path.includes("collects"))).toBe(true);
133
+ expect(issues.map((i) => i.message).join("\n")).toContain("pattern");
134
+ }
135
+ });
136
+ });
137
+
138
+ describe("T2 collects the measured shapes", () => {
139
+ it("select: the pure homogeneous shape collects completely", () => {
140
+ const s = surfaceOf({
141
+ component: "select",
142
+ props: { defaultValue: "all" },
143
+ children: [
144
+ {
145
+ component: "select-content",
146
+ children: [
147
+ { component: "select-item", text: "All roles" },
148
+ { component: "select-item", text: "Admins" },
149
+ { component: "select-item", text: "Editors" },
150
+ ],
151
+ },
152
+ ],
153
+ });
154
+ const { messages } = emitSurface(s, contract, { profile: t2Profile() });
155
+ const [sel] = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } })
156
+ .updateComponents.components;
157
+ expect(sel.component).toBe("Select");
158
+ expect(sel.options).toEqual([{ label: "All roles" }, { label: "Admins" }, { label: "Editors" }]);
159
+ const check = transformFromJson(contract, { profile: t2Profile(), surface: { messages } });
160
+ expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
161
+ });
162
+
163
+ it("radio-group: items collect what they carry; sibling labels are the recorded T3 frontier", () => {
164
+ const { messages, warnings, fidelity } = emitSurface(surfaceOf(RG_SURFACE), contract, { profile: t2Profile() });
165
+ const [rg] = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } })
166
+ .updateComponents.components;
167
+ expect(rg.component).toBe("RadioGroup");
168
+ expect(rg.name).toBe("digest");
169
+ expect(rg.options).toEqual([{ value: "digest-monday" }, { value: "digest-friday" }]);
170
+
171
+ // The htmlFor-joined sibling labels are dropped WITH RECORD, naming T3.
172
+ const labelDrops = warnings.filter((w) => w.code === "surface-sub-dropped" && w.message.includes("'label'"));
173
+ expect(labelDrops).toHaveLength(2);
174
+ expect(labelDrops[0].message).toContain("T3");
175
+ expect(fidelity.filter((f) => f.kind === "dropped" && f.source.includes("label"))).toHaveLength(2);
176
+
177
+ // Each collected record is ledgered with its source item.
178
+ const collected = fidelity.filter((f) => f.kind === "moved" && f.note?.includes("item record"));
179
+ expect(collected).toHaveLength(2);
180
+ expect(collected[0].source).toContain("radio-group-item");
181
+
182
+ const check = transformFromJson(contract, { profile: t2Profile(), surface: { messages } });
183
+ expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
184
+ });
185
+
186
+ it("emission is deterministic across runs", () => {
187
+ const a = emitSurface(surfaceOf(RG_SURFACE), contract, { profile: t2Profile() });
188
+ const b = emitSurface(surfaceOf(RG_SURFACE), contract, { profile: t2Profile() });
189
+ expect(JSON.stringify([a.messages, a.warnings, a.fidelity])).toBe(JSON.stringify([b.messages, b.warnings, b.fidelity]));
190
+ });
191
+
192
+ it("an item missing its field omits it, and A3 arbitrates — never synthesis", () => {
193
+ const s = surfaceOf({
194
+ component: "radio-group",
195
+ children: [{ component: "radio-group-item" }], // no id at all
196
+ });
197
+ const { messages } = emitSurface(s, contract, { profile: t2Profile() });
198
+ const [rg] = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } })
199
+ .updateComponents.components;
200
+ expect(rg.options).toEqual([{}]);
201
+ // The record schema requires `value`, so A3 refuses the emission.
202
+ const check = transformFromJson(contract, { profile: t2Profile(), surface: { messages } });
203
+ expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(false);
204
+ });
205
+
206
+ it("derived coverage resolves both families through the collects", () => {
207
+ const out = (() => {
208
+ try {
209
+ return transformFromJson(contract, { profile: t2Profile() });
210
+ } catch {
211
+ return undefined;
212
+ }
213
+ })();
214
+ // The hermetic profile passes the contract gate (card + both T2 plans).
215
+ expect(out).toBeDefined();
216
+ const unresolved = out!.mapping.coverage.filter(
217
+ (c) => c.disposition === "unclassified" && (c.id.startsWith("radio-group.") || c.id.startsWith("select.")),
218
+ );
219
+ expect(unresolved).toEqual([]);
220
+ expect(out!.mapping.coverage.find((c) => c.id === "radio-group.radio-group-item")?.detail).toContain("collected");
221
+ });
222
+ });
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
+ });