@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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract-facing validation: what a profile can only be wrong about against
|
|
3
|
+
* a contract, proven to refuse (v2) and proven NOT to change behaviour (v1).
|
|
4
|
+
*
|
|
5
|
+
* The enforcement decision this file records: derived sub-component coverage
|
|
6
|
+
* is fatal for v2 profiles at every entry, and report-plus-`--strict-coverage`
|
|
7
|
+
* for v1. Measured before enforcement (scripts/sub-coverage-report.mjs, the
|
|
8
|
+
* 2aac076 record): pinned shadcn v2.3.0, astryx and acme all derive zero
|
|
9
|
+
* unresolved subs — so the fatal gate refuses no shipped artifact, only
|
|
10
|
+
* future profiles with genuine gaps, which is the point.
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { describe, expect, it } from "vitest";
|
|
15
|
+
import { transformFromJson } from "./transform/index.js";
|
|
16
|
+
import { emitSurface } from "./targets/a2ui/surface.js";
|
|
17
|
+
import { loadProfile } from "./transform/profile-load.js";
|
|
18
|
+
import { ProfileContractError } from "./transform/validate-v2.js";
|
|
19
|
+
import { shadcnProfile } from "./transform/profiles.js";
|
|
20
|
+
import type { DspackDoc, DspackSurface } from "./types.js";
|
|
21
|
+
|
|
22
|
+
const repo = (p: string) => fileURLToPath(new URL(`../${p}`, import.meta.url));
|
|
23
|
+
const doc = JSON.parse(readFileSync(repo("input/shadcn-ui.dspack.json"), "utf8")) as DspackDoc;
|
|
24
|
+
|
|
25
|
+
/** A minimal v2 document whose one plan maps the contract's `card` compound. */
|
|
26
|
+
const v2Doc = (surface: unknown): Record<string, unknown> => ({
|
|
27
|
+
profileVersion: "2",
|
|
28
|
+
catalogTitle: "t",
|
|
29
|
+
catalogDescription: "d",
|
|
30
|
+
catalogIdBase: "https://example.test/catalogs/x",
|
|
31
|
+
instructions: "",
|
|
32
|
+
primaryColorToken: { category: "color", name: "primary" },
|
|
33
|
+
surfaceSynthesis: { textComponent: "Text", textProp: "text", wrapComponent: "Column", wrapChildrenProp: "children" },
|
|
34
|
+
synthesized: [
|
|
35
|
+
{
|
|
36
|
+
a2ui: "Text",
|
|
37
|
+
commons: ["ComponentCommon"],
|
|
38
|
+
structural: { text: { schema: { type: "string" }, description: "d", synthNote: "s" } },
|
|
39
|
+
propMap: { variant: { a2ui: "variant", kind: "enum", targetEnum: ["body", "h3", "caption"] } },
|
|
40
|
+
required: ["text"],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
a2ui: "Column",
|
|
44
|
+
commons: ["ComponentCommon"],
|
|
45
|
+
structural: { children: { schema: { type: "array" }, description: "d", synthNote: "s" } },
|
|
46
|
+
required: ["children"],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
casualtyComponents: [],
|
|
50
|
+
components: [
|
|
51
|
+
{
|
|
52
|
+
a2ui: "Card",
|
|
53
|
+
dspackId: "card",
|
|
54
|
+
commons: ["ComponentCommon"],
|
|
55
|
+
structural: {
|
|
56
|
+
child: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
57
|
+
label: { schema: { type: "string" }, description: "d", synthNote: "s" },
|
|
58
|
+
},
|
|
59
|
+
required: ["child"],
|
|
60
|
+
surface,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** The full card sub-family, resolved — the baseline that passes the gate. */
|
|
66
|
+
const RESOLVED = {
|
|
67
|
+
routes: [{ from: ["children"], to: "slot:child" }],
|
|
68
|
+
subs: {
|
|
69
|
+
"card-header": "transparent",
|
|
70
|
+
"card-content": "transparent",
|
|
71
|
+
"card-footer": "transparent",
|
|
72
|
+
"card-title": { asText: "h3" },
|
|
73
|
+
"card-description": { asText: "caption" },
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const refusal = (surface: unknown): string => {
|
|
78
|
+
try {
|
|
79
|
+
transformFromJson(doc, { profile: loadProfile(v2Doc(surface)) });
|
|
80
|
+
return "PASSED";
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (e instanceof ProfileContractError) return e.issues.map((i) => `${i.path}: ${i.message}`).join("\n");
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe("v2 contract validation refuses before emission", () => {
|
|
88
|
+
it("a fully resolved plan passes the gate", () => {
|
|
89
|
+
expect(refusal(RESOLVED)).toBe("PASSED");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("an unresolved sub-component refuses, naming the sub and the decision to make", () => {
|
|
93
|
+
const { subs } = structuredClone(RESOLVED) as { subs: Record<string, unknown> };
|
|
94
|
+
delete subs["card-footer"];
|
|
95
|
+
const out = refusal({ ...RESOLVED, subs });
|
|
96
|
+
expect(out).toContain("'card-footer' of 'card' is unresolved");
|
|
97
|
+
expect(out).toContain("route, collect, transparent, asText, or drop");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("a sub the contract does not declare refuses", () => {
|
|
101
|
+
const out = refusal({
|
|
102
|
+
...RESOLVED,
|
|
103
|
+
subs: { ...RESOLVED.subs, "card-sidebar": "transparent" },
|
|
104
|
+
});
|
|
105
|
+
expect(out).toContain("'card-sidebar' is not a declared sub-component of 'card'");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("reading an undeclared prop into a renamed destination refuses; the passthrough shape passes", () => {
|
|
109
|
+
const renamed = refusal({
|
|
110
|
+
...RESOLVED,
|
|
111
|
+
routes: [...RESOLVED.routes, { from: ["self.props.badge"], to: "prop:label" }],
|
|
112
|
+
});
|
|
113
|
+
expect(renamed).toContain("self.props.badge");
|
|
114
|
+
expect(renamed).toContain("not a same-named structural passthrough");
|
|
115
|
+
|
|
116
|
+
const passthrough = refusal({
|
|
117
|
+
...RESOLVED,
|
|
118
|
+
routes: [...RESOLVED.routes, { from: ["self.props.label"], to: "prop:label" }],
|
|
119
|
+
});
|
|
120
|
+
expect(passthrough).toBe("PASSED");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("emitSurface runs the same gate as transform", () => {
|
|
124
|
+
const { subs } = structuredClone(RESOLVED) as { subs: Record<string, unknown> };
|
|
125
|
+
delete subs["card-footer"];
|
|
126
|
+
const surface: DspackSurface = {
|
|
127
|
+
dspackSurface: "0.1",
|
|
128
|
+
system: doc.name as string,
|
|
129
|
+
intent: "record-collection",
|
|
130
|
+
root: { component: "card", children: [] },
|
|
131
|
+
} as unknown as DspackSurface;
|
|
132
|
+
expect(() => emitSurface(surface, doc, { profile: loadProfile(v2Doc({ ...RESOLVED, subs })) })).toThrowError(
|
|
133
|
+
ProfileContractError,
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("v1 behaviour is frozen: report, not refusal", () => {
|
|
139
|
+
it("a v1 profile with an unresolved sub still transforms — the gap lands in coverage", () => {
|
|
140
|
+
// The shipped card plan, its subFlatten stripped: card's five subs become
|
|
141
|
+
// unresolved. v1 must keep transforming (byte-frozen behaviour) while the
|
|
142
|
+
// coverage report says exactly what is missing.
|
|
143
|
+
const gappy = {
|
|
144
|
+
...structuredClone(shadcnProfile),
|
|
145
|
+
components: shadcnProfile.components.map((p) =>
|
|
146
|
+
p.dspackId === "card" ? { ...p, surfacePlan: { childProp: "child" } } : p,
|
|
147
|
+
),
|
|
148
|
+
};
|
|
149
|
+
const out = transformFromJson(doc, { profile: gappy });
|
|
150
|
+
const unresolved = out.mapping.coverage.filter(
|
|
151
|
+
(c) => c.disposition === "unclassified" && c.id.startsWith("card."),
|
|
152
|
+
);
|
|
153
|
+
expect(unresolved.map((c) => c.id).sort()).toEqual([
|
|
154
|
+
"card.card-content",
|
|
155
|
+
"card.card-description",
|
|
156
|
+
"card.card-footer",
|
|
157
|
+
"card.card-header",
|
|
158
|
+
"card.card-title",
|
|
159
|
+
]);
|
|
160
|
+
// And the strict-coverage contract: these are exactly what exit 3 keys on.
|
|
161
|
+
expect(out.mapping.warnings.some((w) => w.code === "unresolved-sub:card.card-title")).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("the shipped profiles derive zero unresolved subs — the measured gate behind enforcement", () => {
|
|
165
|
+
const out = transformFromJson(doc, { profile: shadcnProfile });
|
|
166
|
+
const unresolved = out.mapping.coverage.filter((c) => c.disposition === "unclassified");
|
|
167
|
+
expect(unresolved).toEqual([]);
|
|
168
|
+
// Derived sub rows exist and carry their classification.
|
|
169
|
+
const subRows = out.mapping.coverage.filter((c) => c.id.includes("."));
|
|
170
|
+
expect(subRows.length).toBeGreaterThanOrEqual(20);
|
|
171
|
+
expect(subRows.every((c) => c.disposition === "mapped" && c.detail)).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
});
|