feat(studio): add thirteen presets and preview reviewed proposals
Quality / quality (ubuntu-latest) (push) Failing after 10m52s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-10-19 14:51:03 +05:30
1 parent ba752e556d
commit c765d76a06
12 files changed
+331 -19

No files matched your search

@@ -202,6 +202,51 @@ test("provider adapter uses bounded patches, compact capabilities and one repair
expect(context).toContain("Repair these diagnostics");
});
test("empty drafts require flat typed tokens and reject nested color groups before repair", async () => {
const system = {
schemaVersion: 1 as const,
id: "empty",
name: "Empty",
version: "1.0.0",
tokens: {},
};
let calls = 0;
const batch = await generateDesigns(await request("directions", [], system), {
provider: {
name: "fixture",
async generate(_prompt, options) {
calls++;
expect(options!.system).toContain("Token maps are FLAT");
expect(options!.system).toContain("COMPLETE token object");
return {
provider: "fixture",
value: JSON.stringify({
alternatives: ["#002FA7", "#00642C", "#A32957"].map((color, index) => ({
name: `Direction ${index}`,
rationale: "A distinct brand color.",
patch: [
calls === 1
? set("/tokens/color", { primary: { type: "color", value: color } })
: set("/tokens/color.primary", {
type: "color",
value: color,
legacy: "color-primary",
}),
],
})),
}),
};
},
},
});
expect(calls).toBe(2);
expect(batch.alternatives).toHaveLength(3);
expect(batch.diagnostics).toEqual([]);
for (const alternative of batch.alternatives)
expect(validateDesignSystem(alternative.system)).toEqual([]);
expect(system.tokens).toEqual({});
});
test("provider invalid parts and lock violations cannot survive bounded repair", async () => {
let calls = 0;
const provider: GenerationProvider = {
@@ -0,0 +1,35 @@
import { expect, test } from "bun:test";
import {
CORE_DESIGN_SYSTEMS,
validateDesignSystem,
compileDesignSystem,
} from "@wrnexus/design-system";
import { STUDIO_PRESETS } from "../src/presets.ts";
import { studioHtml } from "../src/shell.ts";
import { StudioSession } from "../src/session.ts";
test("thirteen distinct Studio presets validate and compile both modes without changing core presets", () => {
expect(Object.keys(STUDIO_PRESETS)).toHaveLength(13);
expect(Object.keys(CORE_DESIGN_SYSTEMS)).toEqual(["square", "soft", "angular"]);
const signatures = new Set<string>();
for (const [id, system] of Object.entries(STUDIO_PRESETS)) {
expect(system.id).toBe(id);
expect(validateDesignSystem(system)).toEqual([]);
expect(studioHtml).toContain(`<option value="${id}">${system.name}</option>`);
signatures.add(JSON.stringify([system.tokens, system.modes]));
for (const mode of ["light", "dark"])
expect(() => compileDesignSystem(system, { mode })).not.toThrow();
}
expect(signatures.size).toBe(13);
});
test("choosing a new preset stays undoable and never mutates the catalog", () => {
const session = new StudioSession(STUDIO_PRESETS.square);
const original = JSON.stringify(STUDIO_PRESETS.swiss);
session.replace(STUDIO_PRESETS.swiss!, "Selected Swiss");
session.edit(JSON.stringify({ ...session.valid, name: "My Swiss" }));
expect(JSON.stringify(STUDIO_PRESETS.swiss)).toBe(original);
session.undo();
session.undo();
expect(session.valid.id).toBe("square");
});
+2 -1
View File
@@ -8,6 +8,7 @@ import { CORE_DESIGN_SYSTEMS } from "../../design-system/src/index.ts";
import { resolveThemeConfig } from "../../styles/src/theme.ts";
import { designRevision } from "../src/decisions.ts";
import { DEFAULT_DESIGN_BRIEF } from "../src/generation.ts";
import { STUDIO_PRESETS } from "../src/presets.ts";
const root = mkdtempSync(join(tmpdir(), "wrn-studio-test-"));
afterAll(() => rmSync(root, { recursive: true, force: true }));
@@ -139,7 +140,7 @@ test("server serves a browser bundle, rejects cross-origin, invalid, oversized a
});
test("all presets generate isolated real component previews with light/dark and responsive/RTL controls", async () => {
for (const system of Object.values(CORE_DESIGN_SYSTEMS))
for (const system of Object.values(STUDIO_PRESETS))
for (const mode of ["light", "dark"]) {
const result = await send("/api/preview", { system, mode, direction: "rtl" });
expect(result.status).toBe(200);