@aestheticfunction/dspack-emit 0.4.1 → 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 +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +430 -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 +96 -25
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -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 +5 -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 +104 -22
- package/src/transform/profile-schema-v2.ts +430 -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 +89 -26
- package/src/validate-v2.test.ts +173 -0
package/src/index.ts
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { transform, transformFromJson, type TransformOutput } from "./transform/index.js";
|
|
9
9
|
export { shadcnProfile, type Profile, type ComponentPlan, type SurfacePlanDirectives } from "./transform/profiles.js";
|
|
10
|
-
export { loadProfile, profileSchema, ProfileLoadError, type ProfileLoadIssue } from "./transform/profile-load.js";
|
|
10
|
+
export { loadProfile, profileSchema, profileSchemaV2, ProfileLoadError, type ProfileLoadIssue } from "./transform/profile-load.js";
|
|
11
|
+
export { ProfileContractError, type ProfileContractIssue } from "./transform/validate-v2.js";
|
|
12
|
+
export { ProfileParseError, type ParseIssue, type SurfaceV2 } from "./transform/parse-v2.js";
|
|
13
|
+
export type { SurfaceFidelityEntry } from "./types.js";
|
|
11
14
|
export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
|
|
12
15
|
export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
13
16
|
export {
|
package/src/profile-load.test.ts
CHANGED
|
@@ -103,12 +103,75 @@ describe("casualty refusal cites the authored reason", () => {
|
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
describe("a declared casualty cannot be consumed into a parent", () => {
|
|
107
|
+
/**
|
|
108
|
+
* The plan-lookup gate refuses a casualty emitted as its OWN node. A
|
|
109
|
+
* consuming strategy (subText / subButtonText / subTable / subFlatten)
|
|
110
|
+
* walks the subtree directly, so without an equivalent gate an author
|
|
111
|
+
* could fold a casualty's text into a parent prop and the authored
|
|
112
|
+
* refusal would vanish behind a warning. Consumption is how compounds
|
|
113
|
+
* carry their parts — never an escape hatch around "cannot represent".
|
|
114
|
+
*/
|
|
115
|
+
it("refuses a casualty folded in by a parent's subText, citing the authored reason", () => {
|
|
116
|
+
const withFold = {
|
|
117
|
+
...shadcnProfile,
|
|
118
|
+
components: shadcnProfile.components.map((plan) =>
|
|
119
|
+
plan.dspackId === "card"
|
|
120
|
+
? {
|
|
121
|
+
...plan,
|
|
122
|
+
surfacePlan: {
|
|
123
|
+
...(plan.surfacePlan ?? {}),
|
|
124
|
+
subText: { ...(plan.surfacePlan?.subText ?? {}), "dropdown-menu": "title" },
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
: plan,
|
|
128
|
+
),
|
|
129
|
+
};
|
|
130
|
+
const surface: DspackSurface = {
|
|
131
|
+
dspackSurface: "0.1",
|
|
132
|
+
system: shadcnDoc.name as string,
|
|
133
|
+
intent: "record-collection",
|
|
134
|
+
root: {
|
|
135
|
+
component: "card",
|
|
136
|
+
children: [{ component: "dropdown-menu", text: "Row actions" }],
|
|
137
|
+
},
|
|
138
|
+
} as DspackSurface;
|
|
139
|
+
try {
|
|
140
|
+
emitSurface(surface, shadcnDoc, { profile: withFold });
|
|
141
|
+
expect.unreachable("a consumed casualty must refuse, not fold silently");
|
|
142
|
+
} catch (e) {
|
|
143
|
+
expect(e).toBeInstanceOf(EmitSurfaceError);
|
|
144
|
+
const msg = (e as EmitSurfaceError).message;
|
|
145
|
+
expect(msg).toContain("declared casualty");
|
|
146
|
+
expect(msg).toContain("cannot be consumed into");
|
|
147
|
+
expect(msg).toContain("dropdown menu"); // the authored reason survives
|
|
148
|
+
// The refusal points at the casualty itself, not at the parent that
|
|
149
|
+
// would have consumed it — same locating precision as direct emission.
|
|
150
|
+
expect((e as EmitSurfaceError).path).toBe("$.root.children[0]");
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("still consumes ordinary sub-components (the gate is casualty-scoped)", () => {
|
|
155
|
+
const surface: DspackSurface = {
|
|
156
|
+
dspackSurface: "0.1",
|
|
157
|
+
system: shadcnDoc.name as string,
|
|
158
|
+
intent: "record-collection",
|
|
159
|
+
root: {
|
|
160
|
+
component: "card",
|
|
161
|
+
children: [{ component: "card-header", children: [{ component: "card-title", text: "Members" }] }],
|
|
162
|
+
},
|
|
163
|
+
} as DspackSurface;
|
|
164
|
+
const result = emitSurface(surface, shadcnDoc, { profile: shadcnProfile });
|
|
165
|
+
expect(JSON.stringify(result.messages)).toContain("Members");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
106
169
|
describe("scaffoldProfile", () => {
|
|
107
170
|
it("produces a loadProfile-valid profile from a bare contract", () => {
|
|
108
171
|
const { profile } = scaffoldProfile(astryxDoc, {
|
|
109
172
|
catalogIdBase: "https://example.test/catalogs/astryx-scaffold",
|
|
110
173
|
});
|
|
111
|
-
// The scaffold is itself a valid
|
|
174
|
+
// The scaffold is itself a valid v2 profile document.
|
|
112
175
|
const loaded = loadProfile(profile);
|
|
113
176
|
expect(loaded.catalogIdBase).toBe("https://example.test/catalogs/astryx-scaffold");
|
|
114
177
|
});
|
|
@@ -128,6 +191,41 @@ describe("scaffoldProfile", () => {
|
|
|
128
191
|
expect(notes.length).toBeGreaterThan(0);
|
|
129
192
|
});
|
|
130
193
|
|
|
194
|
+
it("a scaffold's unresolved decisions, once resolved, transform — the authoring loop closes", () => {
|
|
195
|
+
const { profile, notes } = scaffoldProfile(shadcnDoc, {
|
|
196
|
+
catalogIdBase: "https://example.test/catalogs/shadcn-scaffold",
|
|
197
|
+
});
|
|
198
|
+
// The scaffold names every decision it refused to make...
|
|
199
|
+
const pending = notes.filter((n) => n.note.startsWith("unresolved sub-component"));
|
|
200
|
+
expect(pending.length).toBeGreaterThanOrEqual(10);
|
|
201
|
+
const xs = (profile["x-scaffold"] as { unresolved: Record<string, string[]> }).unresolved;
|
|
202
|
+
expect(Object.keys(xs)).toEqual(expect.arrayContaining(["card", "table", "alert-dialog"]));
|
|
203
|
+
|
|
204
|
+
// ...and an author resolving ONE compound's subs makes that compound emit.
|
|
205
|
+
const components = profile.components as Array<Record<string, unknown>>;
|
|
206
|
+
const card = components.find((c) => c.dspackId === "card")!;
|
|
207
|
+
card.surface = {
|
|
208
|
+
routes: [{ from: ["children"], to: "slots:children" }],
|
|
209
|
+
subs: {
|
|
210
|
+
"card-header": "transparent",
|
|
211
|
+
"card-content": "transparent",
|
|
212
|
+
"card-footer": "transparent",
|
|
213
|
+
"card-title": { asText: "h3" },
|
|
214
|
+
"card-description": { asText: "caption" },
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
// The other compounds stay undecided, so transform still refuses — but no
|
|
218
|
+
// longer about card: its family is resolved and gone from the findings.
|
|
219
|
+
try {
|
|
220
|
+
transformFromJson(shadcnDoc, { profile: loadProfile(profile) });
|
|
221
|
+
expect.unreachable("table and alert-dialog are still undecided");
|
|
222
|
+
} catch (e) {
|
|
223
|
+
const issues = (e as { issues: Array<{ message: string }> }).issues;
|
|
224
|
+
expect(issues.some((i) => i.message.includes("of 'card'"))).toBe(false);
|
|
225
|
+
expect(issues.some((i) => i.message.includes("of 'table'"))).toBe(true);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
131
229
|
it("seeds enum props verbatim (identity projection, no valueMap)", () => {
|
|
132
230
|
const { profile } = scaffoldProfile(shadcnDoc, {
|
|
133
231
|
catalogIdBase: "https://example.test/catalogs/shadcn-scaffold",
|
|
@@ -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
|
+
});
|