feat(skin): widen bounded wasm ui output

This commit is contained in:
illusia committed 2026-10-10 15:53:49 +08:00
1 parent ab36825a56
commit c3810a177a
6 files changed
+253 -10

No files matched your search

@@ -26,6 +26,13 @@ function outputDocument(componentId = "runtime-ui", root?: Record<string, unknow
});
}
function generatedOutput(componentId = "runtime-ui", root: Record<string, unknown> = { tag: "main", children: [{ text: "Generated by Wasm" }] }): string {
return JSON.stringify({
schemaVersion: 4,
components: [{ id: componentId, name: "Runtime UI", page: "voice", accessibleName: "Runtime UI", root }],
});
}
function expectOutputError(source: string, code: string): void {
assert.throws(() => parseSkinExtensionUiOutput(source), (error: unknown) =>
error instanceof SkinExtensionUiOutputError && error.code === code);
@@ -56,6 +63,48 @@ test("Wasm UI output rejects malformed, oversized, legacy, and capability-bearin
expectOutputError(outputDocument("runtime-ui", { tag: "p", text: "{{session.status.channelName}}" }), "SKIN_EXTENSION_UI_OUTPUT_SCHEMA");
});
test("generated UI supports broad safe markup, ARIA/data attributes, and inert custom-element placeholders", () => {
const document = parseSkinExtensionUiOutput(generatedOutput("kook-rail", {
tag: "kook-server-rail",
attributes: { "aria-label": "Servers", "data-selected": "home", role: "navigation" },
children: [
{ tag: "a", attributes: { href: "#voice" }, children: [{ text: "Voice" }] },
{ tag: "button", attributes: { type: "button", "aria-pressed": true }, children: [{ text: "Home" }] },
],
}));
assert.equal(document.schemaVersion, 3);
assert.equal(document.components[0].root.tag, "kook-server-rail");
assert.equal(document.components[0].root.children?.[0].tag, "a");
assert.equal(document.components[0].root.children?.[1].tag, "button");
});
test("generated UI rejects executable elements, event handlers, and network/navigation sinks", () => {
expectOutputError(generatedOutput("runtime-ui", { tag: "script" }), "SKIN_EXTENSION_UI_ELEMENT_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "iframe" }), "SKIN_EXTENSION_UI_ELEMENT_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "button", attributes: { onclick: "run" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "img", attributes: { src: "https://example.invalid/a.png" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "a", attributes: { href: "https://example.invalid/" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { style: "display:none" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { mystery: "value" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { "data-ws-part": "spoofed" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
});
test("generated UI enforces component and per-node child limits", () => {
const tooManyComponents = JSON.stringify({
schemaVersion: 4,
components: Array.from({ length: 65 }, (_, index) => ({
id: `runtime-${index}`, name: "Runtime UI", page: "voice", accessibleName: "Runtime UI", root: { tag: "main" },
})),
});
const tooManyChildren = generatedOutput("runtime-ui", {
tag: "main",
children: Array.from({ length: 257 }, () => ({ text: "x" })),
});
expectOutputError(tooManyComponents, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA");
expectOutputError(tooManyChildren, "SKIN_EXTENSION_UI_COMPLEXITY_LIMIT");
});
test("SkinPluginOutlet renders validated dynamic output and preserves package UI on collisions", async () => {
const document: SkinPluginDocument = {
schemaVersion: 3,
@@ -96,6 +145,33 @@ test("SkinPluginOutlet renders validated dynamic output and preserves package UI
assert.match(collisionHtml, /Package UI/);
});
test("SkinPluginOutlet renders generated custom elements as inert host nodes", async () => {
const document: SkinPluginDocument = {
schemaVersion: 3,
components: [{
id: "base-ui",
name: "Base UI",
page: "voice",
accessibleName: "Base UI",
permissions: [],
actions: {},
root: { tag: "p", children: [{ text: "Base" }] },
}],
};
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
skinId: "community.test",
skinVersion: "1.0.0",
document,
extensionOutput: generatedOutput("kook-rail", { tag: "kook-server-rail", children: [{ text: "Server" }] }),
page: "voice",
data: {},
assets: {},
actions: {},
}));
assert.match(html, /<div[^>]*data-ws-generated-element="kook-server-rail"/);
assert.match(html, /Server/);
});
test("skin-authored DOM nodes expose independent layout parts and retain touch bounds for controls", async () => {
const document: SkinPluginDocument = {
schemaVersion: 3,