@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/a0.test.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A0: the zero-new-capability authoring milestone — production-v3 profile
|
|
3
|
+
* judgment expressed entirely in the shipped Identity/Routing/Repetition
|
|
4
|
+
* vocabulary (T1 transparency + donation, routes, drops-with-record). No
|
|
5
|
+
* new primitive; every decision grounded in measured usage and recorded
|
|
6
|
+
* with fidelity.
|
|
7
|
+
*
|
|
8
|
+
* Fail-first: before this overlay the six compound families sat in the
|
|
9
|
+
* 67-unresolved ledger (alert 3, avatar 5, scroll-area 2, field 5,
|
|
10
|
+
* field-set 1, field-group 1 — eval-fixture.test.ts pins the 67), and the
|
|
11
|
+
* touched examples refused end-to-end (ex.order-detail-summary on
|
|
12
|
+
* 'avatar', ex.delete-project-confirmation on 'alert', …).
|
|
13
|
+
*
|
|
14
|
+
* The two honest losses, dropped WITH RECORD, never approximated:
|
|
15
|
+
* - alert-action holds component children; routing a sub's children to a
|
|
16
|
+
* slot is T4's mechanism — one production instance affected;
|
|
17
|
+
* - avatar-image is an EMPTY node (the contract declares no src/alt —
|
|
18
|
+
* the dspack#39 contract-gap class, named on the drop).
|
|
19
|
+
*/
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { describe, expect, it } from "vitest";
|
|
23
|
+
import { transformFromJson } from "./transform/index.js";
|
|
24
|
+
import { emitSurface } from "./targets/a2ui/surface.js";
|
|
25
|
+
import { loadProfile } from "./transform/profile-load.js";
|
|
26
|
+
import { SHADCN_V3_A0_PLANS, SHADCN_V3_A0_LABEL_ADDITIONS } from "./transform/shadcn-v2-respelling.js";
|
|
27
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
28
|
+
|
|
29
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
30
|
+
const contract = JSON.parse(readFileSync(repo("eval/shadcn-v3.dspack.json"), "utf8")) as DspackDoc & {
|
|
31
|
+
examples: Array<{ id: string; surface: DspackSurface }>;
|
|
32
|
+
};
|
|
33
|
+
const fixture = JSON.parse(readFileSync(repo("eval/shadcn-v3.eval.profile.json"), "utf8"));
|
|
34
|
+
|
|
35
|
+
/** The builder's A0 merge, hermetically: keep a family set, apply the overlay. */
|
|
36
|
+
const a0Profile = (keep: string[]) => {
|
|
37
|
+
const base = structuredClone(fixture) as Record<string, unknown> & {
|
|
38
|
+
components: Array<Record<string, unknown> & { dspackId: string; structural?: Record<string, unknown> }>;
|
|
39
|
+
};
|
|
40
|
+
base.components = base.components.map((plan) => {
|
|
41
|
+
const a0 = SHADCN_V3_A0_PLANS[plan.dspackId];
|
|
42
|
+
return a0 ? (structuredClone(a0) as typeof plan) : plan;
|
|
43
|
+
});
|
|
44
|
+
for (const [id, note] of Object.entries(SHADCN_V3_A0_LABEL_ADDITIONS)) {
|
|
45
|
+
const plan = base.components.find((c) => c.dspackId === id);
|
|
46
|
+
if (plan && !(plan.structural ?? {}).label) {
|
|
47
|
+
plan.structural = { ...(plan.structural ?? {}), label: { schema: { type: "string" }, description: note.description, synthNote: note.synthNote } };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const keepSet = new Set(keep);
|
|
51
|
+
base.intentionallyOmitted = base.components.filter((c) => !keepSet.has(c.dspackId)).map((c) => c.dspackId).sort();
|
|
52
|
+
base.components = base.components.filter((c) => keepSet.has(c.dspackId));
|
|
53
|
+
delete (base as Record<string, unknown>)["x-scaffold"];
|
|
54
|
+
return loadProfile(base);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const surfaceOf = (root: unknown, intent = "record-detail"): DspackSurface =>
|
|
58
|
+
({ dspackSurface: "0.1", system: contract.name as string, intent, root }) as DspackSurface;
|
|
59
|
+
|
|
60
|
+
/** Find the first subtree of a component in a worked example, verbatim. */
|
|
61
|
+
const fromExample = (exampleId: string, component: string): Record<string, unknown> => {
|
|
62
|
+
const ex = contract.examples.find((e) => e.id === exampleId)!;
|
|
63
|
+
let hit: Record<string, unknown> | undefined;
|
|
64
|
+
const walk = (n: Record<string, unknown>): void => {
|
|
65
|
+
if (hit) return;
|
|
66
|
+
if (n.component === component) { hit = n; return; }
|
|
67
|
+
for (const c of (n.children as Record<string, unknown>[] | undefined) ?? []) walk(c);
|
|
68
|
+
};
|
|
69
|
+
walk(ex.surface.root as unknown as Record<string, unknown>);
|
|
70
|
+
expect(hit, `${component} in ${exampleId}`).toBeDefined();
|
|
71
|
+
return structuredClone(hit!);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const firstInstance = (messages: unknown[], component: string): Record<string, unknown> => {
|
|
75
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
76
|
+
const inst = comps.find((c) => c.component === component);
|
|
77
|
+
expect(inst, `an emitted ${component}`).toBeDefined();
|
|
78
|
+
return inst!;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
describe("A0 — alert (routes over the shipped vocabulary)", () => {
|
|
82
|
+
it("the production delete-project alert emits {title, description}", () => {
|
|
83
|
+
const profile = a0Profile(["card", "alert", "badge", "button"]);
|
|
84
|
+
const { messages } = emitSurface(surfaceOf(fromExample("ex.delete-project-confirmation", "alert")), contract, { profile });
|
|
85
|
+
const alert = firstInstance(messages, "Alert");
|
|
86
|
+
expect(typeof alert.title).toBe("string");
|
|
87
|
+
expect((alert.title as string).length).toBeGreaterThan(0);
|
|
88
|
+
expect(typeof alert.description).toBe("string");
|
|
89
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
90
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("alert-action's loss is recorded, never silent: the flatten ledger marks it lossy and the coverage detail names T4", () => {
|
|
94
|
+
const profile = a0Profile(["card", "alert", "badge", "button"]);
|
|
95
|
+
const { messages, warnings, fidelity } = emitSurface(
|
|
96
|
+
surfaceOf(fromExample("ex.import-run-status", "alert")), contract, { profile });
|
|
97
|
+
firstInstance(messages, "Alert");
|
|
98
|
+
// Runtime record: the consumed subtree is ledgered lossy (the engine's
|
|
99
|
+
// consumesSubtree record — the action button is inside it).
|
|
100
|
+
expect(warnings.some((w) => w.code === "surface-composition-flattened")).toBe(true);
|
|
101
|
+
expect(fidelity.some((f) => f.kind === "flattened" && f.class === "lossy" && f.source.includes("alert"))).toBe(true);
|
|
102
|
+
// Documented judgment: the coverage ledger carries the drop reason,
|
|
103
|
+
// naming T4 as the mechanism the slot waits for.
|
|
104
|
+
const out = transformFromJson(contract, { profile });
|
|
105
|
+
const row = out.mapping.coverage.find((c) => c.id === "alert.alert-action");
|
|
106
|
+
expect(row?.disposition).toBe("mapped");
|
|
107
|
+
expect(row?.detail).toContain("T4");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("A0 — avatar", () => {
|
|
112
|
+
it("the production order-detail avatar emits {size, fallback}; the empty avatar-image drop names the contract gap", () => {
|
|
113
|
+
const profile = a0Profile(["card", "avatar", "badge"]);
|
|
114
|
+
const { messages, fidelity } = emitSurface(surfaceOf(fromExample("ex.order-detail-summary", "avatar")), contract, { profile });
|
|
115
|
+
const avatar = firstInstance(messages, "Avatar");
|
|
116
|
+
expect(avatar.fallback).toBe("AO");
|
|
117
|
+
expect(avatar.size).toBe("lg");
|
|
118
|
+
// The consumed subtree (with the empty avatar-image inside) is ledgered
|
|
119
|
+
// lossy; the drop's dspack#39 rationale lives on the coverage row.
|
|
120
|
+
expect(fidelity.some((f) => f.kind === "flattened" && f.class === "lossy")).toBe(true);
|
|
121
|
+
const out = transformFromJson(contract, { profile });
|
|
122
|
+
expect(out.mapping.coverage.find((c) => c.id === "avatar.avatar-image")?.detail).toContain("dspack#39");
|
|
123
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
124
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("A0 — scroll-area dissolves (T1 vocabulary, no instance)", () => {
|
|
129
|
+
it("children rise; scrollbar chrome drops with record", () => {
|
|
130
|
+
const profile = a0Profile(["card", "scroll-area", "badge"]);
|
|
131
|
+
const { messages } = emitSurface(
|
|
132
|
+
surfaceOf({
|
|
133
|
+
component: "card",
|
|
134
|
+
children: [{ component: "scroll-area", children: [{ component: "badge", text: "42 open" }] }],
|
|
135
|
+
}),
|
|
136
|
+
contract,
|
|
137
|
+
{ profile },
|
|
138
|
+
);
|
|
139
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
140
|
+
expect(comps.some((c) => c.component === "ScrollArea")).toBe(false);
|
|
141
|
+
expect(comps.some((c) => c.component === "Badge")).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("A0 — the corrected field family (dspack#40) emits end-to-end", () => {
|
|
146
|
+
it("the production notification-preferences field-set subtree: legend becomes text, groups dissolve, labels donate onto switches", () => {
|
|
147
|
+
const profile = a0Profile(["card", "field", "field-set", "field-group", "switch", "radio-group", "separator", "badge", "button"]);
|
|
148
|
+
const subtree = fromExample("ex.notification-preferences", "field-set");
|
|
149
|
+
const { messages, fidelity } = emitSurface(surfaceOf(subtree, "preference-settings"), contract, { profile });
|
|
150
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
151
|
+
// No wrapper survives.
|
|
152
|
+
for (const gone of ["FieldSet", "FieldGroup", "Field"]) {
|
|
153
|
+
expect(comps.some((c) => c.component === gone), `${gone} must not emit`).toBe(false);
|
|
154
|
+
}
|
|
155
|
+
// The legend text survives as a Text instance.
|
|
156
|
+
expect(comps.some((c) => c.component === "Text")).toBe(true);
|
|
157
|
+
// Every switch carries its donated label.
|
|
158
|
+
const switches = comps.filter((c) => c.component === "Switch");
|
|
159
|
+
expect(switches.length).toBeGreaterThan(0);
|
|
160
|
+
for (const sw of switches) expect(typeof sw.label).toBe("string");
|
|
161
|
+
// Donation provenance is ledgered.
|
|
162
|
+
expect(fidelity.some((f) => f.note?.includes("donated by 'field-label'"))).toBe(true);
|
|
163
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
164
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("a field's textarea and select receive the donated label (the invite-teammates shapes)", () => {
|
|
168
|
+
const profile = a0Profile(["card", "field", "field-set", "field-group", "textarea", "select", "badge"]);
|
|
169
|
+
const t = emitSurface(
|
|
170
|
+
surfaceOf({ component: "field", children: [{ component: "field-label", text: "Personal note" }, { component: "textarea", props: { rows: 3 } }] }),
|
|
171
|
+
contract, { profile });
|
|
172
|
+
expect(firstInstance(t.messages, "Textarea").label).toBe("Personal note");
|
|
173
|
+
|
|
174
|
+
const s = emitSurface(
|
|
175
|
+
surfaceOf({
|
|
176
|
+
component: "field",
|
|
177
|
+
children: [
|
|
178
|
+
{ component: "field-label", text: "Workspace role" },
|
|
179
|
+
{ component: "select", children: [{ component: "select-content", children: [{ component: "select-item", text: "Editor" }] }] },
|
|
180
|
+
],
|
|
181
|
+
}),
|
|
182
|
+
contract, { profile });
|
|
183
|
+
const sel = firstInstance(s.messages, "Select");
|
|
184
|
+
expect(sel.label).toBe("Workspace role");
|
|
185
|
+
expect(sel.options).toEqual([{ label: "Editor" }]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("A0 — shipped primitives compose: transparency inside a joined panel", () => {
|
|
190
|
+
it("a transparent scroll-area inside tabs-content dissolves instead of refusing (the ex.project-workspace-panels shape)", () => {
|
|
191
|
+
// Discovered by the A0 re-measurement: the T3 joined-children path fed
|
|
192
|
+
// raw children to emitNode, skipping the parent-style rewrite that
|
|
193
|
+
// dissolves transparent children — a composition bug between shipped
|
|
194
|
+
// primitives, fixed by mirroring the transparent-root host pattern.
|
|
195
|
+
const profile = a0Profile(["card", "tabs", "scroll-area", "badge"]);
|
|
196
|
+
const { messages } = emitSurface(
|
|
197
|
+
surfaceOf({
|
|
198
|
+
component: "tabs",
|
|
199
|
+
children: [
|
|
200
|
+
{ component: "tabs-list", children: [{ component: "tabs-trigger", id: "t1", text: "Overview" }] },
|
|
201
|
+
{ component: "tabs-content", id: "t1", children: [{ component: "scroll-area", children: [{ component: "badge", text: "42 open" }] }] },
|
|
202
|
+
],
|
|
203
|
+
}),
|
|
204
|
+
contract, { profile });
|
|
205
|
+
const comps = (messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
206
|
+
expect(comps.some((c) => c.component === "ScrollArea")).toBe(false);
|
|
207
|
+
const tabs = comps.find((c) => c.component === "Tabs")!;
|
|
208
|
+
const sections = tabs.sections as Array<{ child: string }>;
|
|
209
|
+
expect(sections).toHaveLength(1);
|
|
210
|
+
const badge = comps.find((c) => c.component === "Badge")!;
|
|
211
|
+
expect(sections[0].child).toBe(badge.id);
|
|
212
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
213
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("A0 — ledger and determinism", () => {
|
|
218
|
+
it("the six authored families derive zero unresolved subs", () => {
|
|
219
|
+
const profile = a0Profile(["card", "alert", "avatar", "scroll-area", "field", "field-set", "field-group", "switch", "badge", "button"]);
|
|
220
|
+
const out = transformFromJson(contract, { profile });
|
|
221
|
+
const unresolved = out.mapping.coverage.filter(
|
|
222
|
+
(c) => c.disposition === "unclassified" &&
|
|
223
|
+
["alert.", "avatar.", "scroll-area.", "field.", "field-set.", "field-group."].some((p) => c.id.startsWith(p)),
|
|
224
|
+
);
|
|
225
|
+
expect(unresolved).toEqual([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("emission is deterministic across runs", () => {
|
|
229
|
+
const profile = a0Profile(["card", "field", "field-set", "field-group", "switch", "badge"]);
|
|
230
|
+
const subtree = fromExample("ex.notification-preferences", "field-set");
|
|
231
|
+
const a = emitSurface(surfaceOf(subtree, "preference-settings"), contract, { profile });
|
|
232
|
+
const b = emitSurface(surfaceOf(subtree, "preference-settings"), contract, { profile });
|
|
233
|
+
expect(JSON.stringify([a.messages, a.warnings, a.fidelity])).toBe(JSON.stringify([b.messages, b.warnings, b.fidelity]));
|
|
234
|
+
});
|
|
235
|
+
});
|
package/src/eval-fixture.test.ts
CHANGED
|
@@ -5,14 +5,27 @@
|
|
|
5
5
|
* Supersedes the /tmp-only measurement recorded in 2aac076 ("29 subs under 6
|
|
6
6
|
* compounds, 1 unresolved"): that profile's nine extra compound plans carried
|
|
7
7
|
* judgment that did not survive the reboot. This fixture transplants only
|
|
8
|
-
* COMMITTED mapping evidence
|
|
9
|
-
* re-spelling
|
|
10
|
-
*
|
|
8
|
+
* COMMITTED mapping evidence — the six shipped plans in their byte-proven v2
|
|
9
|
+
* re-spelling, the T1 transparent-identity resolutions (src/t1.test.ts),
|
|
10
|
+
* the T2 item-mode collection plans (src/t2.test.ts), and the T3
|
|
11
|
+
* declared-join plans (src/t3.test.ts) — onto a mechanical
|
|
12
|
+
* scaffold of the pinned v3 contract, declares zero casualties, and lets
|
|
13
|
+
* every open decision show as open:
|
|
11
14
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* 104 sub-components under 21 mapped compounds (contract 3.2.0: the
|
|
16
|
+
* dspack#40 correction moved the field wrapper trio right-side-up —
|
|
17
|
+
* field keeps 5 inner parts; field-set and field-group are compounds
|
|
18
|
+
* of their own with 1 sub each, so the denominator moved 106 → 104)
|
|
19
|
+
* 86 resolved — the transplanted families (card 5, table 7,
|
|
20
|
+
* alert-dialog 8), T1's form family (6), T2's
|
|
21
|
+
* radio-group (1) and select (7), T3's tabs (3),
|
|
22
|
+
* the A0 authoring pass (alert 3, avatar 5,
|
|
23
|
+
* scroll-area 2, field 5, field-set 1, field-group 1),
|
|
24
|
+
* and T4 (dialog 7, sheet 7, popover 6,
|
|
25
|
+
* dropdown-menu 12 — the last measured as data-shaped)
|
|
26
|
+
* 18 unresolved — real, deliberate: accordion (3), breadcrumb (6),
|
|
27
|
+
* pagination (6), tooltip (3) — the T6/upstream and
|
|
28
|
+
* deferred-shape tail
|
|
16
29
|
*
|
|
17
30
|
* The v2 contract gate refusing this fixture against the v3 contract is not a
|
|
18
31
|
* failure; it is the fatal coverage gate doing on the production corpus
|
|
@@ -49,19 +62,19 @@ describe("the production-v3 evaluation fixture", () => {
|
|
|
49
62
|
expect(profile.casualtyComponents).toEqual([]);
|
|
50
63
|
});
|
|
51
64
|
|
|
52
|
-
it("the fatal coverage gate refuses it against the v3 contract:
|
|
65
|
+
it("the fatal coverage gate refuses it against the v3 contract: 18 unresolved decisions, each pathed", () => {
|
|
53
66
|
try {
|
|
54
67
|
transformFromJson(contract, { profile: loadProfile(structuredClone(fixtureJson)) });
|
|
55
|
-
expect.unreachable("
|
|
68
|
+
expect.unreachable("18 open representation decisions must refuse, not emit");
|
|
56
69
|
} catch (e) {
|
|
57
70
|
expect(e).toBeInstanceOf(ProfileContractError);
|
|
58
71
|
const issues = (e as ProfileContractError).issues;
|
|
59
|
-
expect(issues).toHaveLength(
|
|
72
|
+
expect(issues).toHaveLength(18);
|
|
60
73
|
expect(issues.every((i) => i.message.includes("unresolved"))).toBe(true);
|
|
61
74
|
}
|
|
62
75
|
});
|
|
63
76
|
|
|
64
|
-
it("derived coverage:
|
|
77
|
+
it("derived coverage: 104 subs, 86 resolved (transplants + T1-T4 + A0), 18 open", () => {
|
|
65
78
|
const profile = loadProfile(structuredClone(fixtureJson));
|
|
66
79
|
const byId = new Map(profile.components.map((p: ComponentPlan) => [p.dspackId, p]));
|
|
67
80
|
let resolved = 0;
|
|
@@ -82,8 +95,8 @@ describe("the production-v3 evaluation fixture", () => {
|
|
|
82
95
|
}
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
|
-
expect(resolved + unresolved).toBe(
|
|
86
|
-
expect(unresolved).toBe(
|
|
87
|
-
expect(Object.fromEntries(resolvedByCompound)).toEqual({ card: 5, table: 7, "alert-dialog": 8 });
|
|
98
|
+
expect(resolved + unresolved).toBe(104);
|
|
99
|
+
expect(unresolved).toBe(18);
|
|
100
|
+
expect(Object.fromEntries(resolvedByCompound)).toEqual({ card: 5, table: 7, "alert-dialog": 8, form: 6, "radio-group": 1, select: 7, tabs: 3, alert: 3, avatar: 5, "scroll-area": 2, field: 5, "field-set": 1, "field-group": 1, dialog: 7, sheet: 7, popover: 6, "dropdown-menu": 12 });
|
|
88
101
|
});
|
|
89
102
|
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layered dissolution contexts (emit#37, ratified 2026-08-07).
|
|
3
|
+
*
|
|
4
|
+
* A dissolving boundary shadows the enclosing compound contexts where they
|
|
5
|
+
* overlap, but does not erase them: dispositions remain available through
|
|
6
|
+
* the ancestor chain. This closes the seam the post-T4 Build matrix measured
|
|
7
|
+
* (eval/t4-build-matrix.json, preference-settings) — an outer compound's sub
|
|
8
|
+
* inside a transparent inner boundary.
|
|
9
|
+
*
|
|
10
|
+
* Fail-first (recorded on main d3aab9f, before the change): the shape below
|
|
11
|
+
* refused at emit with
|
|
12
|
+
*
|
|
13
|
+
* unknown component 'card-footer': not a mapped component of the '…' profile
|
|
14
|
+
*
|
|
15
|
+
* because T1 dissolution governed the inner boundary's subtree by ITS OWN
|
|
16
|
+
* model alone, so `card-footer` (a sub of the OUTER `card`) found no
|
|
17
|
+
* disposition in the inner `field` model and fell through to emitNode. The
|
|
18
|
+
* surface was S1/S2/S3-clean — spec v0.4 §5.1 accepts it (a `card` ancestor
|
|
19
|
+
* exists at any depth) — so this was purely an emitter seam.
|
|
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 } 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 profileOf = (keep: string[]) => {
|
|
36
|
+
const doc = structuredClone(fixture) as Record<string, unknown> & { components: Array<{ dspackId: string }> };
|
|
37
|
+
const keepSet = new Set(keep);
|
|
38
|
+
(doc as Record<string, unknown>).intentionallyOmitted = doc.components.filter((c) => !keepSet.has(c.dspackId)).map((c) => c.dspackId).sort();
|
|
39
|
+
doc.components = doc.components.filter((c) => keepSet.has(c.dspackId));
|
|
40
|
+
delete (doc as Record<string, unknown>)["x-scaffold"];
|
|
41
|
+
return loadProfile(doc);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const surfaceOf = (root: unknown, intent = "preference-settings"): DspackSurface =>
|
|
45
|
+
({ dspackSurface: "0.1", system: contract.name as string, intent, root }) as DspackSurface;
|
|
46
|
+
|
|
47
|
+
const instancesOf = (messages: unknown[]) =>
|
|
48
|
+
(messages[1] as { updateComponents: { components: Array<Record<string, unknown>> } }).updateComponents.components;
|
|
49
|
+
|
|
50
|
+
describe("layered dissolution: an outer compound's sub survives inside a dissolved inner boundary", () => {
|
|
51
|
+
const profile = profileOf(["card", "field", "field-set", "field-group", "switch", "button", "badge"]);
|
|
52
|
+
|
|
53
|
+
it("card-footer inside a transparent field resolves against card's model and its button rises", () => {
|
|
54
|
+
const { messages } = emitSurface(
|
|
55
|
+
surfaceOf({
|
|
56
|
+
component: "card",
|
|
57
|
+
children: [
|
|
58
|
+
{ component: "card-header", children: [{ component: "card-title", text: "Preferences" }] },
|
|
59
|
+
{
|
|
60
|
+
component: "card-content",
|
|
61
|
+
children: [
|
|
62
|
+
{
|
|
63
|
+
component: "field",
|
|
64
|
+
children: [
|
|
65
|
+
{ component: "field-label", text: "Weekly digest" },
|
|
66
|
+
{ component: "switch", props: { name: "digest" } },
|
|
67
|
+
{ component: "card-footer", children: [{ component: "button", text: "Save" }] },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
contract,
|
|
75
|
+
{ profile },
|
|
76
|
+
);
|
|
77
|
+
const comps = instancesOf(messages);
|
|
78
|
+
// No wrapper instance survives for any dissolved boundary.
|
|
79
|
+
for (const gone of ["Card_footer", "Field", "CardFooter", "CardHeader"]) {
|
|
80
|
+
expect(comps.some((c) => c.component === gone)).toBe(false);
|
|
81
|
+
}
|
|
82
|
+
// The field donated its label onto the switch (T1 still works through the layering).
|
|
83
|
+
const sw = comps.find((c) => c.component === "Switch")!;
|
|
84
|
+
expect(sw.label).toBe("Weekly digest");
|
|
85
|
+
// card-footer dissolved (card's disposition, reached through the ancestor
|
|
86
|
+
// chain) and its button rose as a real instance.
|
|
87
|
+
const button = comps.find((c) => c.component === "Button")!;
|
|
88
|
+
expect(button.child).toBeDefined();
|
|
89
|
+
// The whole thing is emittable and A3-valid.
|
|
90
|
+
const check = transformFromJson(contract, { profile, surface: { messages } });
|
|
91
|
+
expect(check.validation.gates.find((g) => g.name === "instance")?.pass).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("the inner boundary's own dispositions resolve first (innermost-first walk)", () => {
|
|
95
|
+
// Genuine same-id overlap between two frames is structurally impossible —
|
|
96
|
+
// sub-component ids are unique document-wide (enforced by S2), so the
|
|
97
|
+
// ratified "inner shadows outer" is defined but unreachable for real
|
|
98
|
+
// contracts. What IS observable is that the inner frame is consulted
|
|
99
|
+
// first: field-title inside a dissolved field takes FIELD's asText (h4),
|
|
100
|
+
// never a fallthrough to some outer default.
|
|
101
|
+
const { messages } = emitSurface(
|
|
102
|
+
surfaceOf({
|
|
103
|
+
component: "card",
|
|
104
|
+
children: [
|
|
105
|
+
{
|
|
106
|
+
component: "card-content",
|
|
107
|
+
children: [
|
|
108
|
+
{
|
|
109
|
+
component: "field",
|
|
110
|
+
children: [
|
|
111
|
+
{ component: "field-title", text: "Section" },
|
|
112
|
+
{ component: "switch", props: { name: "x" } },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
}),
|
|
119
|
+
contract,
|
|
120
|
+
{ profile },
|
|
121
|
+
);
|
|
122
|
+
const comps = instancesOf(messages);
|
|
123
|
+
const text = comps.find((c) => c.component === "Text" && c.text === "Section")!;
|
|
124
|
+
expect(text).toBeDefined();
|
|
125
|
+
expect(text.variant).toBe("h4"); // field's asText, not card's h3
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("determinism holds across the layered walk", () => {
|
|
129
|
+
const root = {
|
|
130
|
+
component: "card",
|
|
131
|
+
children: [
|
|
132
|
+
{ component: "card-content", children: [{ component: "field", children: [{ component: "field-label", text: "L" }, { component: "switch" }, { component: "card-footer", children: [{ component: "button", text: "Go" }] }] }] },
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
const a = emitSurface(surfaceOf(root), contract, { profile });
|
|
136
|
+
const b = emitSurface(surfaceOf(root), contract, { profile });
|
|
137
|
+
expect(JSON.stringify([a.messages, a.warnings, a.fidelity])).toBe(JSON.stringify([b.messages, b.warnings, b.fidelity]));
|
|
138
|
+
});
|
|
139
|
+
});
|
package/src/profile-v2.test.ts
CHANGED
|
@@ -354,10 +354,16 @@ describe("load-time refusal matrix (v2 grammar)", () => {
|
|
|
354
354
|
expect(out).toContain("one sub, one disposition");
|
|
355
355
|
});
|
|
356
356
|
|
|
357
|
-
it("unimplemented capability spellings are refused
|
|
358
|
-
// T1
|
|
359
|
-
|
|
357
|
+
it("unimplemented capability spellings are refused; T1's are now implemented with their own rules", () => {
|
|
358
|
+
// T1 landed: `transparent` is a real spelling — on THIS plan it refuses
|
|
359
|
+
// for its true reason (a transparent plan declares no catalog surface,
|
|
360
|
+
// and Widget declares structural slots), not because the grammar is
|
|
361
|
+
// closed to it.
|
|
362
|
+
expect(refusal({ transparent: true })).toContain("declares no catalog surface");
|
|
363
|
+
// `onto` remains INTERNAL vocabulary: donation is authored via
|
|
364
|
+
// transparent.donate blocks; a raw onto key on a route stays refused.
|
|
360
365
|
expect(refusal({ routes: [{ from: ["self.text"], to: "prop:label", onto: "control" }] })).not.toBe("LOADED");
|
|
366
|
+
// T3 joins have not landed and stay refused, never reinterpreted.
|
|
361
367
|
expect(refusal({ collects: [{ of: ["s"], into: "prop:items", shape: "records", field: "f", row: ["r"], cells: ["c"], joinOn: "id" }] })).not.toBe("LOADED");
|
|
362
368
|
});
|
|
363
369
|
});
|