feat(kaak): refine voice dock visuals

This commit is contained in:
Corrupted ILLUSIA committed 2026-10-11 10:12:16 +08:00
1 parent 16df12e4b2
commit 13f4ddac4d
19 files changed
+4573 -3971

No files matched your search

+203 -201
View File
@@ -1,43 +1,43 @@
import assert from "node:assert/strict";
import { readFile, readdir } from "node:fs/promises";
import test from "node:test";
import {
getSkinLayoutComponents,
getSkinLayoutComponent,
parseSkinLayoutJson,
SKIN_LAYOUT_COMPONENTS,
validateSkinLayout,
canEditSkinLayoutComponent,
} from "./skin-layout.js";
async function vueSources(directory: URL): Promise<string[]> {
const files = (await readdir(directory, { recursive: true })).filter((file) => file.endsWith(".vue"));
return Promise.all(files.map((file) => readFile(new URL(file.replaceAll("\\", "/"), directory), "utf8")));
}
test("the stable layout registry covers public skin hooks and excludes the admin console", async () => {
const [webClient, demo, sharedComponents, skinSwitcher, languageSwitcher, admin, adminComponents] = await Promise.all([
readFile(new URL("../../web/src/views/WebClient.vue", import.meta.url), "utf8"),
readFile(new URL("../../web/src/views/DemoView.vue", import.meta.url), "utf8"),
vueSources(new URL("../../web/src/components/web-client/", import.meta.url)),
readFile(new URL("../../web/src/components/SkinSwitcher.vue", import.meta.url), "utf8"),
readFile(new URL("../../web/src/components/LanguageSwitcher.vue", import.meta.url), "utf8"),
readFile(new URL("../../web/src/views/AdminView.vue", import.meta.url), "utf8"),
vueSources(new URL("../../web/src/components/admin/", import.meta.url)),
]);
const publicSource = [webClient, demo, ...sharedComponents, skinSwitcher, languageSwitcher].join("\n");
const publicParts = new Set([...publicSource.matchAll(/data-ws-part="([^"]+)"/g)].map((match) => match[1]));
const interactiveParts = new Set<string>();
for (const match of publicSource.matchAll(/<[A-Za-z][\w.-]*\b[^>]*>/gs)) {
const attributes = match[0];
const part = attributes.match(/\bdata-ws-part="([^"]+)"/)?.[1];
if (!part) continue;
const isNativeControl = /^<(?:button|a|input|select|textarea)\b/i.test(attributes);
const hasButtonRole = /\brole="button"/.test(attributes);
const keyboardAction = /@keydown\.(?:enter|space)\b/.test(attributes);
const dragAction = /@(?:dragstart|dragover|dragleave|drop)\b|:draggable=/.test(attributes);
if (isNativeControl || hasButtonRole || keyboardAction || dragAction) interactiveParts.add(part);
}
import assert from "node:assert/strict";
import { readFile, readdir } from "node:fs/promises";
import test from "node:test";
import {
getSkinLayoutComponents,
getSkinLayoutComponent,
parseSkinLayoutJson,
SKIN_LAYOUT_COMPONENTS,
validateSkinLayout,
canEditSkinLayoutComponent,
} from "./skin-layout.js";
async function vueSources(directory: URL): Promise<string[]> {
const files = (await readdir(directory, { recursive: true })).filter((file) => file.endsWith(".vue"));
return Promise.all(files.map((file) => readFile(new URL(file.replaceAll("\\", "/"), directory), "utf8")));
}
test("the stable layout registry covers public skin hooks and excludes the admin console", async () => {
const [webClient, demo, sharedComponents, skinSwitcher, languageSwitcher, admin, adminComponents] = await Promise.all([
readFile(new URL("../../web/src/views/WebClient.vue", import.meta.url), "utf8"),
readFile(new URL("../../web/src/views/DemoView.vue", import.meta.url), "utf8"),
vueSources(new URL("../../web/src/components/web-client/", import.meta.url)),
readFile(new URL("../../web/src/components/SkinSwitcher.vue", import.meta.url), "utf8"),
readFile(new URL("../../web/src/components/LanguageSwitcher.vue", import.meta.url), "utf8"),
readFile(new URL("../../web/src/views/AdminView.vue", import.meta.url), "utf8"),
vueSources(new URL("../../web/src/components/admin/", import.meta.url)),
]);
const publicSource = [webClient, demo, ...sharedComponents, skinSwitcher, languageSwitcher].join("\n");
const publicParts = new Set([...publicSource.matchAll(/data-ws-part="([^"]+)"/g)].map((match) => match[1]));
const interactiveParts = new Set<string>();
for (const match of publicSource.matchAll(/<[A-Za-z][\w.-]*\b[^>]*>/gs)) {
const attributes = match[0];
const part = attributes.match(/\bdata-ws-part="([^"]+)"/)?.[1];
if (!part) continue;
const isNativeControl = /^<(?:button|a|input|select|textarea)\b/i.test(attributes);
const hasButtonRole = /\brole="button"/.test(attributes);
const keyboardAction = /@keydown\.(?:enter|space)\b/.test(attributes);
const dragAction = /@(?:dragstart|dragover|dragleave|drop)\b|:draggable=/.test(attributes);
if (isNativeControl || hasButtonRole || keyboardAction || dragAction) interactiveParts.add(part);
}
const registered = new Set(SKIN_LAYOUT_COMPONENTS.map((component) => component.selectorPart));
for (const part of publicParts) assert.ok(registered.has(part), "Unregistered public layout hook: " + part);
const micStatus = getSkinLayoutComponent("voice.member.mic-status", "voice");
@@ -45,165 +45,167 @@ test("the stable layout registry covers public skin hooks and excludes the admin
assert.equal(micStatus?.editable, true);
assert.ok(micStatus?.layoutModes.includes("visibility"));
for (const part of interactiveParts) {
const component = SKIN_LAYOUT_COMPONENTS.find((entry) => entry.id === part);
assert.ok(component, "Interactive public hook must have its own component metadata: " + part);
assert.ok(component.minTouchTarget >= 44, "Interactive public hook needs a 44px touch target: " + part);
assert.ok(component.minWidth >= 44 && component.minHeight >= 44, "Interactive public hook needs bounded minimum dimensions: " + part);
assert.ok(component.minScale >= 1, "Interactive public hook must not scale below its natural hit target: " + part);
}
assert.match(publicSource, /data-ws-part="demo\.voice-card"[\s\S]*?role="button"[\s\S]*?tabindex="0"[\s\S]*?@keydown\.enter[\s\S]*?@keydown\.space/);
assert.doesNotMatch([admin, ...adminComponents].join("\n"), /ws-skin-root|data-ws-page=/);
assert.ok(SKIN_LAYOUT_COMPONENTS.every((component) => !component.id.startsWith("admin.")));
});
test("valid layouts accept only bounded positions and safe visual tokens", () => {
const layout = validateSkinLayout({
schemaVersion: 1,
pages: {
home: {
desktop: {
"home.header": { x: -120, y: 40, scale: 1.25, order: -2, visible: true, foreground: "#aabbcc", radius: 16 },
"control.button": { background: "#010203", border: "#ffffff" },
},
mobile: { "home.join-card": { x: 8, scale: 0.9 } },
tablet: { "home.join-card": { width: 720, height: 460 } },
},
},
});
assert.equal(layout.pages.home?.desktop?.["home.header"]?.x, -120);
assert.equal(layout.pages.home?.desktop?.["home.header"]?.foreground, "#aabbcc");
assert.equal(layout.pages.home?.desktop?.["home.header"]?.order, -2);
assert.equal(layout.pages.home?.tablet?.["home.join-card"]?.width, 720);
assert.equal(getSkinLayoutComponents("home").some((component) => component.id === "home.join-card"), true);
assert.equal(getSkinLayoutComponents("voice").some((component) => component.id === "home.join-card"), false);
});
test("skin-authored component roots and nodes become independently editable layout parts", () => {
const maxRuntimeNodeId = `skin.voice.runtime_plugin_${"p".repeat(64)}__${"c".repeat(64)}.control-node-root-0`;
const dynamicIds = [
"skin.voice.toolbar",
"skin.voice.toolbar.node-root",
"skin.voice.toolbar.part-chat-list",
"skin.voice.toolbar.control-node-root-0",
"skin.voice.runtime_plugin_root_voice-toolbar",
"skin.voice.runtime_plugin_voice-surface__voice-ui",
"skin.voice.runtime_plugin_voice-surface__voice-ui.node-root",
"skin.voice.runtime_plugin_voice-surface__voice-ui.part-chat-list",
"skin.voice.runtime_plugin_voice-surface__voice-ui.control-part-join",
maxRuntimeNodeId,
];
const components = getSkinLayoutComponents("voice", dynamicIds);
assert.deepEqual(components.filter((component) => dynamicIds.includes(component.id)).map((component) => component.id), dynamicIds);
assert.ok(dynamicIds.every((id) => getSkinLayoutComponent(id, "voice")?.editable));
assert.equal(getSkinLayoutComponent("skin.home.toolbar", "voice"), undefined);
assert.equal(getSkinLayoutComponent("skin.voice.toolbar.node-root-onclick", "voice"), undefined);
const layout = validateSkinLayout({
schemaVersion: 1,
pages: { voice: { desktop: {
"skin.voice.toolbar": { x: 18, y: 12, visible: true },
"skin.voice.toolbar.node-root": { width: 720 },
"skin.voice.toolbar.part-chat-list": { visible: false },
"skin.voice.toolbar.control-node-root-0": { scale: 1, width: 60, height: 48 },
"skin.voice.runtime_plugin_root_voice-toolbar": { order: 2 },
"skin.voice.runtime_plugin_voice-surface__voice-ui": { width: 800 },
"skin.voice.runtime_plugin_voice-surface__voice-ui.part-chat-list": { visible: false },
"skin.voice.runtime_plugin_voice-surface__voice-ui.control-part-join": { width: 60, height: 48 },
} } },
});
assert.equal(layout.pages.voice?.desktop?.["skin.voice.toolbar.part-chat-list"]?.visible, false);
assert.equal(layout.pages.voice?.desktop?.["skin.voice.runtime_plugin_root_voice-toolbar"]?.order, 2);
assert.equal(layout.pages.voice?.desktop?.["skin.voice.runtime_plugin_voice-surface__voice-ui"]?.width, 800);
assert.equal(layout.pages.voice?.desktop?.["skin.voice.runtime_plugin_voice-surface__voice-ui.part-chat-list"]?.visible, false);
assert.equal(getSkinLayoutComponent("skin.voice.runtime_plugin_voice-surface__voice-ui.control-part-join")?.minTouchTarget, 44);
assert.equal(getSkinLayoutComponent(maxRuntimeNodeId)?.minTouchTarget, 44);
assert.equal(getSkinLayoutComponent("skin.voice.toolbar.control-node-root-0")?.minTouchTarget, 44);
assert.ok(getSkinLayoutComponent("skin.voice.toolbar.control-node-root-0")!.minScale >= 1);
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { voice: { desktop: { "skin.home.toolbar": { x: 0 } } } },
}));
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { voice: { desktop: { "skin.voice.toolbar.control-node-root-0": { scale: 0.8 } } } },
}));
});
test("layout validation fails closed for unknown pages, components, trusted notices, fields, and values", () => {
const invalidValues: unknown[] = [
{ schemaVersion: 2, pages: {} },
{ schemaVersion: 1, pages: { admin: { desktop: {} } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.not-registered": { x: 0 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.security-note": { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.security-note": { order: -1 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { app: { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { position: "fixed" } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { x: 2001 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { order: 101 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { width: 8 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "voice.connection-status": { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { background: "url(https://example.invalid)" } } } } },
];
for (const invalid of invalidValues) assert.throws(() => validateSkinLayout(invalid));
});
test("registered components carry accessibility, responsive, purpose, and data-scope metadata", () => {
assert.ok(SKIN_LAYOUT_COMPONENTS.length > 100);
for (const component of SKIN_LAYOUT_COMPONENTS) {
assert.ok(component.name.length > 0);
assert.notEqual(component.name, component.id, "registry names must be readable metadata rather than the ID repeated");
assert.ok(component.purpose.length > 0);
assert.ok(["core", "optional", "trusted-chrome"].includes(component.category));
if (component.editable) {
assert.deepEqual(component.allowedContainers, ["app"]);
assert.deepEqual(component.layoutModes, ["position", "size", "visibility", "appearance", "order"]);
assert.ok(component.minWidth > 0 && component.maxWidth >= component.minWidth);
assert.ok(component.minHeight > 0 && component.maxHeight >= component.minHeight);
assert.ok(component.minScale > 0 && component.maxScale >= component.minScale);
assert.ok(component.allowedStyleTokens.length > 0);
} else {
assert.deepEqual(component.allowedContainers, []);
assert.deepEqual(component.layoutModes, []);
assert.deepEqual(component.allowedStyleTokens, []);
}
assert.equal(component.keyboardBehavior, "host-native");
assert.equal(component.focusOrder, "host-dom");
assert.equal(component.accessibleNamePolicy, "preserve-host-name");
assert.ok(component.narrowScreenBehavior.length > 0);
assert.ok(component.dataSensitivity.length > 0);
}
const component = SKIN_LAYOUT_COMPONENTS.find((entry) => entry.id === part);
assert.ok(component, "Interactive public hook must have its own component metadata: " + part);
assert.ok(component.minTouchTarget >= 44, "Interactive public hook needs a 44px touch target: " + part);
assert.ok(component.minWidth >= 44 && component.minHeight >= 44, "Interactive public hook needs bounded minimum dimensions: " + part);
assert.ok(component.minScale >= 1, "Interactive public hook must not scale below its natural hit target: " + part);
}
assert.match(publicSource, /data-ws-part="demo\.voice-card"[\s\S]*?role="button"[\s\S]*?tabindex="0"[\s\S]*?@keydown\.enter[\s\S]*?@keydown\.space/);
assert.doesNotMatch([admin, ...adminComponents].join("\n"), /ws-skin-root|data-ws-page=/);
assert.ok(SKIN_LAYOUT_COMPONENTS.every((component) => !component.id.startsWith("admin.")));
});
test("valid layouts accept only bounded positions and safe visual tokens", () => {
const layout = validateSkinLayout({
schemaVersion: 1,
pages: {
home: {
desktop: {
"home.header": { x: -120, y: 40, scale: 1.25, order: -2, visible: true, foreground: "#aabbcc", radius: 16 },
"control.button": { background: "#010203", border: "#ffffff" },
},
mobile: { "home.join-card": { x: 8, scale: 0.9 } },
tablet: { "home.join-card": { width: 720, height: 460 } },
},
},
});
assert.equal(layout.pages.home?.desktop?.["home.header"]?.x, -120);
assert.equal(layout.pages.home?.desktop?.["home.header"]?.foreground, "#aabbcc");
assert.equal(layout.pages.home?.desktop?.["home.header"]?.order, -2);
assert.equal(layout.pages.home?.tablet?.["home.join-card"]?.width, 720);
assert.equal(getSkinLayoutComponents("home").some((component) => component.id === "home.join-card"), true);
assert.equal(getSkinLayoutComponents("voice").some((component) => component.id === "home.join-card"), false);
});
test("skin-authored component roots and nodes become independently editable layout parts", () => {
const maxRuntimeNodeId = `skin.voice.runtime_plugin_${"p".repeat(64)}__${"c".repeat(64)}.control-node-root-0`;
const dynamicIds = [
"skin.voice.toolbar",
"skin.voice.toolbar.node-root",
"skin.voice.toolbar.part-chat-list",
"skin.voice.toolbar.control-node-root-0",
"skin.voice.runtime_plugin_root_voice-toolbar",
"skin.voice.runtime_plugin_voice-surface__voice-ui",
"skin.voice.runtime_plugin_voice-surface__voice-ui.node-root",
"skin.voice.runtime_plugin_voice-surface__voice-ui.part-chat-list",
"skin.voice.runtime_plugin_voice-surface__voice-ui.control-part-join",
maxRuntimeNodeId,
];
const components = getSkinLayoutComponents("voice", dynamicIds);
assert.deepEqual(components.filter((component) => dynamicIds.includes(component.id)).map((component) => component.id), dynamicIds);
assert.ok(dynamicIds.every((id) => getSkinLayoutComponent(id, "voice")?.editable));
assert.equal(getSkinLayoutComponent("skin.home.toolbar", "voice"), undefined);
assert.equal(getSkinLayoutComponent("skin.voice.toolbar.node-root-onclick", "voice"), undefined);
const layout = validateSkinLayout({
schemaVersion: 1,
pages: { voice: { desktop: {
"skin.voice.toolbar": { x: 18, y: 12, visible: true },
"skin.voice.toolbar.node-root": { width: 720 },
"skin.voice.toolbar.part-chat-list": { visible: false },
"skin.voice.toolbar.control-node-root-0": { scale: 1, width: 60, height: 48 },
"skin.voice.runtime_plugin_root_voice-toolbar": { order: 2 },
"skin.voice.runtime_plugin_voice-surface__voice-ui": { width: 800 },
"skin.voice.runtime_plugin_voice-surface__voice-ui.part-chat-list": { visible: false },
"skin.voice.runtime_plugin_voice-surface__voice-ui.control-part-join": { width: 60, height: 48 },
} } },
});
assert.equal(layout.pages.voice?.desktop?.["skin.voice.toolbar.part-chat-list"]?.visible, false);
assert.equal(layout.pages.voice?.desktop?.["skin.voice.runtime_plugin_root_voice-toolbar"]?.order, 2);
assert.equal(layout.pages.voice?.desktop?.["skin.voice.runtime_plugin_voice-surface__voice-ui"]?.width, 800);
assert.equal(layout.pages.voice?.desktop?.["skin.voice.runtime_plugin_voice-surface__voice-ui.part-chat-list"]?.visible, false);
assert.equal(getSkinLayoutComponent("skin.voice.runtime_plugin_voice-surface__voice-ui.control-part-join")?.minTouchTarget, 44);
assert.equal(getSkinLayoutComponent(maxRuntimeNodeId)?.minTouchTarget, 44);
assert.equal(getSkinLayoutComponent("skin.voice.toolbar.control-node-root-0")?.minTouchTarget, 44);
assert.ok(getSkinLayoutComponent("skin.voice.toolbar.control-node-root-0")!.minScale >= 1);
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { voice: { desktop: { "skin.home.toolbar": { x: 0 } } } },
}));
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { voice: { desktop: { "skin.voice.toolbar.control-node-root-0": { scale: 0.8 } } } },
}));
});
test("layout validation fails closed for unknown pages, components, trusted notices, fields, and values", () => {
const invalidValues: unknown[] = [
{ schemaVersion: 2, pages: {} },
{ schemaVersion: 1, pages: { admin: { desktop: {} } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.not-registered": { x: 0 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.security-note": { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.security-note": { order: -1 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { app: { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { position: "fixed" } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { x: 2001 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { order: 101 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { width: 8 } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "voice.connection-status": { visible: false } } } } },
{ schemaVersion: 1, pages: { home: { desktop: { "home.header": { background: "url(https://example.invalid)" } } } } },
];
for (const invalid of invalidValues) assert.throws(() => validateSkinLayout(invalid));
});
test("registered components carry accessibility, responsive, purpose, and data-scope metadata", () => {
assert.ok(SKIN_LAYOUT_COMPONENTS.length > 100);
for (const component of SKIN_LAYOUT_COMPONENTS) {
assert.ok(component.name.length > 0);
assert.notEqual(component.name, component.id, "registry names must be readable metadata rather than the ID repeated");
assert.ok(component.purpose.length > 0);
assert.ok(["core", "optional", "trusted-chrome"].includes(component.category));
if (component.editable) {
assert.deepEqual(component.allowedContainers, ["app"]);
assert.deepEqual(component.layoutModes, ["position", "size", "visibility", "appearance", "order"]);
assert.ok(component.minWidth > 0 && component.maxWidth >= component.minWidth);
assert.ok(component.minHeight > 0 && component.maxHeight >= component.minHeight);
assert.ok(component.minScale > 0 && component.maxScale >= component.minScale);
assert.ok(component.allowedStyleTokens.length > 0);
} else {
assert.deepEqual(component.allowedContainers, []);
assert.deepEqual(component.layoutModes, []);
assert.deepEqual(component.allowedStyleTokens, []);
}
assert.equal(component.keyboardBehavior, "host-native");
assert.equal(component.focusOrder, "host-dom");
assert.equal(component.accessibleNamePolicy, "preserve-host-name");
assert.ok(component.narrowScreenBehavior.length > 0);
assert.ok(component.dataSensitivity.length > 0);
}
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.connect")?.minTouchTarget, 44);
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.feature")?.category, "optional");
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.security-note")?.category, "trusted-chrome");
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.identity-import.security")?.dataSensitivity, "identity");
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "demo.voice-card")?.minTouchTarget, 44);
});
test("trusted host components cannot be changed through a nested generic control", () => {
assert.equal(canEditSkinLayoutComponent("control.button", "home", ["home.form"]), true);
assert.equal(canEditSkinLayoutComponent("control.button", "home", ["home.identity-import.security"]), false);
assert.equal(canEditSkinLayoutComponent("control.button", "voice", ["voice.screen-share-error"]), false);
assert.equal(canEditSkinLayoutComponent("home.security-note", "home"), false);
});
test("touch controls cannot be shrunk below their registered hit-target bounds", () => {
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { home: { desktop: { "home.connect": { scale: 0.75 } } } },
}));
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { home: { desktop: { "control.button": { width: 20 } } } },
}));
assert.equal(validateSkinLayout({
schemaVersion: 1,
pages: { home: { desktop: { "home.feature": { width: 20, scale: 0.5 } } } },
}).pages.home?.desktop?.["home.feature"]?.width, 20);
});
test("layout JSON parsing rejects malformed and oversized documents", () => {
assert.throws(() => parseSkinLayoutJson("{"));
assert.throws(() => parseSkinLayoutJson(" ".repeat(128 * 1024 + 1)));
assert.deepEqual(parseSkinLayoutJson('{"schemaVersion":1,"pages":{}}'), { schemaVersion: 1, pages: {} });
});
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "control.range")?.minTouchTarget, 44);
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "control.checkbox")?.minTouchTarget, 44);
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.feature")?.category, "optional");
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.security-note")?.category, "trusted-chrome");
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "home.identity-import.security")?.dataSensitivity, "identity");
assert.equal(SKIN_LAYOUT_COMPONENTS.find((component) => component.id === "demo.voice-card")?.minTouchTarget, 44);
});
test("trusted host components cannot be changed through a nested generic control", () => {
assert.equal(canEditSkinLayoutComponent("control.button", "home", ["home.form"]), true);
assert.equal(canEditSkinLayoutComponent("control.button", "home", ["home.identity-import.security"]), false);
assert.equal(canEditSkinLayoutComponent("control.button", "voice", ["voice.screen-share-error"]), false);
assert.equal(canEditSkinLayoutComponent("home.security-note", "home"), false);
});
test("touch controls cannot be shrunk below their registered hit-target bounds", () => {
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { home: { desktop: { "home.connect": { scale: 0.75 } } } },
}));
assert.throws(() => validateSkinLayout({
schemaVersion: 1,
pages: { home: { desktop: { "control.button": { width: 20 } } } },
}));
assert.equal(validateSkinLayout({
schemaVersion: 1,
pages: { home: { desktop: { "home.feature": { width: 20, scale: 0.5 } } } },
}).pages.home?.desktop?.["home.feature"]?.width, 20);
});
test("layout JSON parsing rejects malformed and oversized documents", () => {
assert.throws(() => parseSkinLayoutJson("{"));
assert.throws(() => parseSkinLayoutJson(" ".repeat(128 * 1024 + 1)));
assert.deepEqual(parseSkinLayoutJson('{"schemaVersion":1,"pages":{}}'), { schemaVersion: 1, pages: {} });
});
+434 -419
View File
@@ -1,177 +1,185 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import {
parseSkinPluginDocument,
parseSkinPluginJson,
type SkinPluginDocument,
type SkinPluginNode,
} from "./skin-plugin.js";
function validDocument(): SkinPluginDocument {
return {
schemaVersion: 1,
components: [{
id: "channel-list",
name: "Channel list",
page: "voice",
accessibleName: "TeamSpeak channels",
permissions: ["session.channels.read", "session.channel.join"],
actions: {
join: { type: "voice.joinChannel", args: { channelId: "{{channel.id}}" } },
},
root: {
tag: "nav",
repeat: { path: "session.channels", as: "channel" },
children: [{
tag: "button",
attributes: { type: "button", "aria-label": "{{channel.name}}" },
events: { dblclick: "join" },
children: [{ text: "{{channel.name}}" }],
}],
},
}],
};
}
function errorCode(run: () => unknown, expected: string): void {
assert.throws(run, (error: unknown) => error instanceof Error
&& "code" in error && error.code === expected);
}
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import {
parseSkinPluginDocument,
parseSkinPluginJson,
type SkinPluginDocument,
type SkinPluginNode,
} from "./skin-plugin.js";
function validDocument(): SkinPluginDocument {
return {
schemaVersion: 1,
components: [{
id: "channel-list",
name: "Channel list",
page: "voice",
accessibleName: "TeamSpeak channels",
permissions: ["session.channels.read", "session.channel.join"],
actions: {
join: { type: "voice.joinChannel", args: { channelId: "{{channel.id}}" } },
},
root: {
tag: "nav",
repeat: { path: "session.channels", as: "channel" },
children: [{
tag: "button",
attributes: { type: "button", "aria-label": "{{channel.name}}" },
events: { dblclick: "join" },
children: [{ text: "{{channel.name}}" }],
}],
},
}],
};
}
function errorCode(run: () => unknown, expected: string): void {
assert.throws(run, (error: unknown) => error instanceof Error
&& "code" in error && error.code === expected);
}
test("skin plugin accepts a bounded channel list with a double-click host action", () => {
const parsed = parseSkinPluginDocument(validDocument());
assert.equal(parsed.schemaVersion, 1, "legacy documents retain their original capability boundary");
assert.equal(parsed.components[0].mode, "widget");
assert.equal(parsed.components[0].root.repeat?.path, "session.channels");
assert.equal(parsed.components[0].root.children?.[0].events?.dblclick, "join");
});
test("component schema v2 can replace a public page and compose trusted host widgets", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].mode = "surface";
document.components[0].permissions = ["ui.surface.replace"];
document.components[0].actions = {};
document.components[0].root = {
tag: "main",
className: "custom-voice-shell",
children: [
{ widget: "voice.channel-panel", part: "channels" },
{ widget: "voice.chat-panel" },
],
};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].mode, "surface");
assert.deepEqual(parsed.components[0].root.children?.map((node) => node.widget), ["voice.channel-panel", "voice.chat-panel"]);
assert.throws(() => parseSkinPluginDocument({ ...document, schemaVersion: 1 }), { code: "SKIN_PLUGIN_SCHEMA_UNSUPPORTED" });
});
test("page surfaces and stateful host widgets cannot be duplicated", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].mode = "surface";
document.components[0].permissions.push("ui.surface.replace");
document.components[0].root = { tag: "main", children: [{ widget: "voice.chat-panel" }] };
document.components.push({
...document.components[0],
id: "second-surface",
mode: "widget",
root: { tag: "section", children: [{ widget: "voice.chat-panel" }] },
});
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_WIDGET_DUPLICATE");
document.components[1].mode = "surface";
document.components[1].root.children = [{ widget: "voice.member-cards" }];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_SURFACE_DUPLICATE");
});
test("replacing a built-in public page requires an explicit user approval capability", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].mode = "surface";
document.components[0].permissions = [];
document.components[0].actions = {};
document.components[0].root = { tag: "main", children: [{ tag: "h1", children: [{ text: "Custom client" }] }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["ui.surface.replace"];
assert.deepEqual(parseSkinPluginDocument(document).components[0].permissions, ["ui.surface.replace"]);
});
test("custom surfaces can safely render and switch unified favorite and recent server entries", () => {
const document = validDocument();
document.components[0].permissions = ["servers.quickList.read", "servers.quickList.switch"];
document.components[0].actions = {
switch: { type: "quickServers.switch", args: { quickServerId: "{{server.id}}" } },
};
document.components[0].root = {
tag: "nav",
repeat: { path: "servers.quickList", as: "server" },
children: [{ tag: "button", events: { dblclick: "switch" }, children: [{ text: "{{server.label}}" }] }],
};
const parsed = parseSkinPluginDocument(document).components[0];
assert.equal(parsed.root.repeat?.path, "servers.quickList");
assert.equal(parsed.actions.switch.type, "quickServers.switch");
document.components[0].permissions = ["servers.quickList.read"];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
});
test("host widget references stay allowlisted and cannot be used on the demo page", () => {
const unknownWidget = validDocument();
unknownWidget.schemaVersion = 2;
unknownWidget.components[0].root = { tag: "main", children: [{ widget: "filesystem.read" as never }] };
errorCode(() => parseSkinPluginDocument(unknownWidget), "SKIN_PLUGIN_WIDGET_INVALID");
const demoWidget = validDocument();
demoWidget.schemaVersion = 2;
demoWidget.components[0].page = "demo";
demoWidget.components[0].root = { tag: "main", children: [{ widget: "voice.chat-panel" }] };
errorCode(() => parseSkinPluginDocument(demoWidget), "SKIN_PLUGIN_WIDGET_INVALID");
});
test("starting screen share from a skin host widget requires its own permission", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].root = { tag: "main", children: [{ widget: "voice.screen-share-start" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["voice.screenShare.control"];
document.components[0].actions = {};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].root.children?.[0].widget, "voice.screen-share-start");
});
test("schema v3 host audio controls require read and control permissions while v2 remains compatible", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].actions = {};
document.components[0].root = { tag: "main", children: [{ widget: "voice.audio-controls" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["audio.status.read", "audio.microphone.control"];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
const parsed = parseSkinPluginDocument(validDocument());
assert.equal(parsed.schemaVersion, 1, "legacy documents retain their original capability boundary");
assert.equal(parsed.components[0].mode, "widget");
assert.equal(parsed.components[0].root.repeat?.path, "session.channels");
assert.equal(parsed.components[0].root.children?.[0].events?.dblclick, "join");
});
test("component schema v2 can replace a public page and compose trusted host widgets", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].mode = "surface";
document.components[0].permissions = ["ui.surface.replace"];
document.components[0].actions = {};
document.components[0].root = {
tag: "main",
className: "custom-voice-shell",
children: [
{ widget: "voice.channel-panel", part: "channels" },
{ widget: "voice.chat-panel" },
],
};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].mode, "surface");
assert.deepEqual(parsed.components[0].root.children?.map((node) => node.widget), ["voice.channel-panel", "voice.chat-panel"]);
assert.throws(() => parseSkinPluginDocument({ ...document, schemaVersion: 1 }), { code: "SKIN_PLUGIN_SCHEMA_UNSUPPORTED" });
});
test("page surfaces and stateful host widgets cannot be duplicated", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].mode = "surface";
document.components[0].permissions.push("ui.surface.replace");
document.components[0].root = { tag: "main", children: [{ widget: "voice.chat-panel" }] };
document.components.push({
...document.components[0],
id: "second-surface",
mode: "widget",
root: { tag: "section", children: [{ widget: "voice.chat-panel" }] },
});
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_WIDGET_DUPLICATE");
document.components[1].mode = "surface";
document.components[1].root.children = [{ widget: "voice.member-cards" }];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_SURFACE_DUPLICATE");
});
test("replacing a built-in public page requires an explicit user approval capability", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].mode = "surface";
document.components[0].permissions = [];
document.components[0].actions = {};
document.components[0].root = { tag: "main", children: [{ tag: "h1", children: [{ text: "Custom client" }] }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["ui.surface.replace"];
assert.deepEqual(parseSkinPluginDocument(document).components[0].permissions, ["ui.surface.replace"]);
});
test("custom surfaces can safely render and switch unified favorite and recent server entries", () => {
const document = validDocument();
document.components[0].permissions = ["servers.quickList.read", "servers.quickList.switch"];
document.components[0].actions = {
switch: { type: "quickServers.switch", args: { quickServerId: "{{server.id}}" } },
};
document.components[0].root = {
tag: "nav",
repeat: { path: "servers.quickList", as: "server" },
children: [{ tag: "button", events: { dblclick: "switch" }, children: [{ text: "{{server.label}}" }] }],
};
const parsed = parseSkinPluginDocument(document).components[0];
assert.equal(parsed.root.repeat?.path, "servers.quickList");
assert.equal(parsed.actions.switch.type, "quickServers.switch");
document.components[0].permissions = ["servers.quickList.read"];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
});
test("host widget references stay allowlisted and cannot be used on the demo page", () => {
const unknownWidget = validDocument();
unknownWidget.schemaVersion = 2;
unknownWidget.components[0].root = { tag: "main", children: [{ widget: "filesystem.read" as never }] };
errorCode(() => parseSkinPluginDocument(unknownWidget), "SKIN_PLUGIN_WIDGET_INVALID");
const demoWidget = validDocument();
demoWidget.schemaVersion = 2;
demoWidget.components[0].page = "demo";
demoWidget.components[0].root = { tag: "main", children: [{ widget: "voice.chat-panel" }] };
errorCode(() => parseSkinPluginDocument(demoWidget), "SKIN_PLUGIN_WIDGET_INVALID");
});
test("starting screen share from a skin host widget requires its own permission", () => {
const document = validDocument();
document.schemaVersion = 2;
document.components[0].root = { tag: "main", children: [{ widget: "voice.screen-share-start" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["voice.screenShare.control"];
document.components[0].actions = {};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.components[0].root.children?.[0].widget, "voice.screen-share-start");
});
test("schema v3 host audio controls require read and control permissions while v2 remains compatible", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].actions = {};
document.components[0].root = { tag: "main", children: [{ widget: "voice.audio-controls" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["audio.status.read", "audio.microphone.control"];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions = ["audio.status.read", "audio.microphone.control", "audio.output.control"];
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].widget, "voice.audio-controls");
document.components[0].root.children![0] = { widget: "voice.audio-controls", options: { layout: "room-panel" } };
const roomPanel = parseSkinPluginDocument(document).components[0].root.children?.[0];
assert.equal(roomPanel?.widget, "voice.audio-controls");
assert.deepEqual(roomPanel?.options, { layout: "room-panel" });
const invalidLayout = structuredClone(document);
invalidLayout.components[0].root.children![0] = { widget: "voice.audio-controls", options: { layout: "custom" } as never };
errorCode(() => parseSkinPluginDocument(invalidLayout), "SKIN_PLUGIN_WIDGET_OPTIONS_INVALID");
const legacyDocument = structuredClone(document);
legacyDocument.schemaVersion = 2;
legacyDocument.components[0].permissions = [];
legacyDocument.components[0].root.children![0] = { widget: "voice.audio-controls" };
assert.equal(parseSkinPluginDocument(legacyDocument).components[0].root.children?.[0].widget, "voice.audio-controls");
});
});
test("schema v3 member cards require a separate permission to display cached profile pictures", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].actions = {};
document.components[0].permissions = ["session.members.read", "voice.screenShare.read", "voice.screenShare.control"];
document.components[0].root = { tag: "main", children: [{ widget: "voice.member-cards" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions.push("session.memberAvatars.read");
const document = validDocument();
document.schemaVersion = 3;
document.components[0].actions = {};
document.components[0].permissions = ["session.members.read", "voice.screenShare.read", "voice.screenShare.control"];
document.components[0].root = { tag: "main", children: [{ widget: "voice.member-cards" }] };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING");
document.components[0].permissions.push("session.memberAvatars.read");
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].widget, "voice.member-cards");
});
@@ -243,259 +251,266 @@ test("schema v3 trusted widgets can omit screen-share UI and request only the pe
misplacedOption.components[0].root.children![0] = { tag: "div", options: { screenShare: false } } as never;
errorCode(() => parseSkinPluginDocument(misplacedOption), "SKIN_PLUGIN_WIDGET_OPTIONS_INVALID");
});
test("KAAK v3 example declares the connection home and complete voice workspace", async () => {
const source = await readFile(new URL("../../docs/examples/kaak-voice/components.json", import.meta.url), "utf8");
const parsed = parseSkinPluginJson(source);
const home = parsed.components.find((component) => component.id === "kaak-home");
const workspace = parsed.components.find((component) => component.id === "kaak-workspace");
assert.ok(home);
assert.ok(workspace);
assert.equal(home.page, "home");
assert.equal(home.mode, "surface");
assert.deepEqual(home.permissions, ["ui.surface.replace"]);
assert.equal(home.root.children?.[1].children?.[3].widget, "home.connection-form");
assert.equal(workspace.page, "voice");
assert.equal(workspace.mode, "surface");
assert.ok(workspace.permissions.includes("session.channels.read"));
assert.ok(workspace.permissions.includes("session.members.read"));
assert.ok(workspace.permissions.includes("session.memberAvatars.read"));
assert.ok(workspace.permissions.includes("chat.channel.send"));
test("KAAK v3 example declares the connection home and complete voice workspace", async () => {
const source = await readFile(new URL("../../docs/examples/kaak-voice/components.json", import.meta.url), "utf8");
const parsed = parseSkinPluginJson(source);
const home = parsed.components.find((component) => component.id === "kaak-home");
const workspace = parsed.components.find((component) => component.id === "kaak-workspace");
assert.ok(home);
assert.ok(workspace);
assert.equal(home.page, "home");
assert.equal(home.mode, "surface");
assert.deepEqual(home.permissions, ["ui.surface.replace"]);
assert.equal(home.root.children?.[1].children?.[3].widget, "home.connection-form");
assert.equal(workspace.page, "voice");
assert.equal(workspace.mode, "surface");
assert.ok(workspace.permissions.includes("session.channels.read"));
assert.ok(workspace.permissions.includes("session.members.read"));
assert.ok(workspace.permissions.includes("session.memberAvatars.read"));
assert.ok(workspace.permissions.includes("chat.channel.send"));
assert.ok(workspace.permissions.includes("audio.microphone.control"));
assert.equal(workspace.actions["join-channel"].type, "voice.joinChannel");
assert.equal(workspace.actions["send-message"].type, "chat.sendMessage");
const nodes: SkinPluginNode[] = [];
const visit = (node: SkinPluginNode): void => {
nodes.push(node);
node.children?.forEach(visit);
};
visit(workspace.root);
assert.ok(workspace.permissions.includes("voice.screenShare.control"));
assert.ok(workspace.permissions.includes("voice.screenShare.read"));
assert.ok(workspace.permissions.includes("voice.screenShare.status.read"));
assert.equal(workspace.actions["stop-screen-share"].type, "voice.stopScreenShare");
assert.equal(workspace.actions["join-channel"].type, "voice.joinChannel");
assert.equal(workspace.actions["send-message"].type, "chat.sendMessage");
const nodes: SkinPluginNode[] = [];
const visit = (node: SkinPluginNode): void => {
nodes.push(node);
node.children?.forEach(visit);
};
visit(workspace.root);
assert.ok(nodes.some((node) => node.widget === "voice.audio-controls"));
assert.ok(nodes.some((node) => node.widget === "voice.member-cards"));
assert.ok(!nodes.some((node) => node.widget === "voice.screen-share-start"), "KOOK clone excludes screen sharing");
assert.ok(nodes.some((node) => node.repeat?.path === "session.channels" && node.children?.[0].events?.dblclick === "join-channel"));
assert.ok(!nodes.some((node) => node.repeat?.path === "session.members"), "member imagery stays inside the trusted host widget");
assert.ok(nodes.some((node) => node.tag === "input" && node.bindValue === "message"));
});
test("skin plugin binds form controls only to declared local state", () => {
const document = validDocument();
document.components[0].state = { search: "" };
document.components[0].root.children = [{
tag: "input",
bindValue: "search",
events: { input: "filter" },
}];
document.components[0].actions.filter = { type: "ui.setState", args: { key: "search", value: "{{state.search}}" } };
assert.equal(parseSkinPluginDocument(document).components[0].state?.search, "");
});
test("skin plugin rejects undeclared permissions, arbitrary paths, and executable markup", () => {
const missingPermission = validDocument();
missingPermission.components[0].permissions = ["session.channel.join"];
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const hiddenPath = validDocument();
hiddenPath.components[0].root.children![0].children = [{ text: "{{session.credentials.privateKey}}" }];
errorCode(() => parseSkinPluginDocument(hiddenPath), "SKIN_PLUGIN_BINDING_INVALID");
const executable = validDocument();
executable.components[0].root.children![0].attributes = { onclick: "alert(1)" };
errorCode(() => parseSkinPluginDocument(executable), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
const unsafeTag = validDocument();
unsafeTag.components[0].root.children![0].tag = "iframe";
errorCode(() => parseSkinPluginDocument(unsafeTag), "SKIN_PLUGIN_ELEMENT_INVALID");
const externalSvgPaint = validDocument();
externalSvgPaint.components[0].root.children![0].attributes = { fill: "url(https://example.invalid/payload.svg#paint)" };
errorCode(() => parseSkinPluginDocument(externalSvgPaint), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
const skinOwnedPopover = validDocument();
skinOwnedPopover.components[0].root.children![0].attributes = { popover: "manual" };
errorCode(() => parseSkinPluginDocument(skinOwnedPopover), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
const skinOwnedPopoverTrigger = validDocument();
skinOwnedPopoverTrigger.components[0].root.children![0].attributes = { popovertarget: "host-editor" };
errorCode(() => parseSkinPluginDocument(skinOwnedPopoverTrigger), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
});
test("skin plugin restricts repeated fields to the selected collection", () => {
const document = validDocument();
document.components[0].root.repeat = { path: "session.channels", as: "channel" };
document.components[0].root.children = [{ text: "{{channel.author}}" }];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_BINDING_INVALID");
});
test("skin plugins can repeat channel members only under a channel alias and with member permission", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions.push("session.members.read");
document.components[0].root.children = [{
tag: "ul",
children: [{
tag: "li",
repeat: { path: "channel.members", as: "member" },
children: [{ text: "{{channel.name}} — {{member.avatarInitial}} {{member.name}}" }],
}],
}];
const parsed = parseSkinPluginDocument(document);
const nestedMember = parsed.components[0].root.children?.[0].children?.[0];
assert.deepEqual(nestedMember?.repeat, { path: "channel.members", as: "member" });
assert.equal(nestedMember?.children?.[0]?.text, "{{channel.name}} — {{member.avatarInitial}} {{member.name}}");
const membersOnly = structuredClone(document);
membersOnly.components[0].root.children = [{
tag: "ul",
when: { path: "channel.members", empty: false },
children: [{ tag: "li", repeat: { path: "channel.members", as: "member" } }],
}];
const parsedCondition = parseSkinPluginDocument(membersOnly).components[0].root.children?.[0];
assert.deepEqual(parsedCondition?.when, { path: "channel.members", empty: false });
const missingConditionPermission = structuredClone(membersOnly);
missingConditionPermission.components[0].permissions = ["session.channels.read", "session.channel.join"];
missingConditionPermission.components[0].root.children![0].children = [];
errorCode(() => parseSkinPluginDocument(missingConditionPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const invalidNestedCondition = structuredClone(membersOnly);
invalidNestedCondition.components[0].root.children![0].when = { path: "channel.members" };
errorCode(() => parseSkinPluginDocument(invalidNestedCondition), "SKIN_PLUGIN_CONDITION_INVALID");
const missingPermission = structuredClone(document);
missingPermission.components[0].permissions = ["session.channels.read", "session.channel.join"];
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const outsideChannel = structuredClone(document);
outsideChannel.components[0].root.repeat = undefined;
outsideChannel.components[0].root.children = [{ tag: "ul", repeat: { path: "channel.members", as: "member" } }];
errorCode(() => parseSkinPluginDocument(outsideChannel), "SKIN_PLUGIN_REPEAT_INVALID");
});
test("skin plugins keep live typing local but can run host actions on committed changes", () => {
const document = validDocument();
const input = document.components[0].root.children![0];
input.events = { input: "join" };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_EVENT_INVALID");
input.events = { change: "join" };
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].events?.change, "join");
});
test("skin conditions can compare public repeated data with local component state", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].state = { selectedchannel: "" };
document.components[0].root.children![0].when = {
path: "state.selectedchannel",
equals: "{{channel.id}}",
};
const parsed = parseSkinPluginDocument(document);
assert.deepEqual(parsed.components[0].root.children?.[0].when, {
path: "state.selectedchannel",
equals: "{{channel.id}}",
});
const legacyDocument = structuredClone(document);
legacyDocument.schemaVersion = 2;
errorCode(() => parseSkinPluginDocument(legacyDocument), "SKIN_PLUGIN_SCHEMA_UNSUPPORTED");
document.components[0].root.children![0].when!.equals = "{{channel.address}}";
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_BINDING_INVALID");
});
test("schema v3 can render empty states only for permissioned public collections", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions.push("chat.channel.read");
document.components[0].root.children = [{
tag: "p",
when: { path: "chat.messages", empty: true },
children: [{ text: "No messages yet" }],
}];
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].when?.empty, true);
document.components[0].permissions.push("session.status.read");
document.components[0].root.children[0].when!.path = "session.status.serverLabel";
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_CONDITION_INVALID");
});
test("component schema v3 exposes composable interaction patterns and permission-gated voice actions", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions = [
"audio.microphone.control", "audio.output.control", "audio.status.read", "voice.disconnect", "voice.presence.write",
"voice.whisper.control", "voice.whisper.status.read", "voice.screenShare.control", "voice.screenShare.read", "voice.screenShare.status.read",
];
document.components[0].state = { menuopen: false, volume: 0.5, awaymessage: "" };
document.components[0].actions = {
"toggle-menu": { type: "ui.toggleState", args: { key: "menuopen" } },
microphone: { type: "voice.toggleMicrophone", args: {} },
speaker: { type: "voice.toggleOutputMute", args: {} },
volume: { type: "voice.setOutputVolume", args: { volume: "{{state.volume}}" } },
disconnect: { type: "voice.disconnect", args: {} },
away: { type: "voice.setAway", args: { away: true, message: "{{state.awaymessage}}" } },
whisper: { type: "voice.setWhisperActive", args: { active: true } },
"start-share": { type: "voice.startScreenShare", args: {} },
"stop-share": { type: "voice.stopScreenShare", args: {} },
"join-share": { type: "voice.joinScreenShare", args: { streamId: "{{share.streamId}}" } },
"leave-share": { type: "voice.leaveScreenShare", args: {} },
};
document.components[0].root = {
tag: "main",
attributes: { "data-layout": "room", "aria-label": "Custom voice page" },
children: [
{ tag: "button", events: { contextmenu: "toggle-menu", pointerenter: "toggle-menu" }, children: [{ text: "Menu" }] },
{ tag: "button", events: { click: "microphone" }, children: [{ text: "Microphone" }] },
{ tag: "button", events: { click: "speaker" }, children: [{ text: "Speaker" }] },
{ tag: "button", events: { click: "volume" }, children: [{ text: "Volume" }] },
{ tag: "button", events: { click: "disconnect" }, children: [{ text: "Disconnect" }] },
{ tag: "button", events: { click: "away" }, children: [{ text: "Away" }] },
{ tag: "button", events: { click: "whisper" }, children: [{ text: "Whisper" }] },
{ tag: "button", events: { click: "start-share" }, children: [{ text: "Share" }] },
{ tag: "button", events: { click: "stop-share" }, children: [{ text: "Stop sharing" }] },
{ tag: "div", repeat: { path: "screenShare.streams", as: "share" }, children: [
{ tag: "button", events: { click: "join-share" }, children: [{ text: "{{share.name}}" }] },
] },
{ tag: "button", events: { click: "leave-share" }, children: [{ text: "Leave share" }] },
],
};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.schemaVersion, 3);
assert.equal(parsed.components[0].root.children?.[0].events?.contextmenu, "toggle-menu");
assert.equal(parsed.components[0].actions["join-share"].type, "voice.joinScreenShare");
assert.equal(parsed.components[0].root.children?.[9].repeat?.path, "screenShare.streams");
const passiveVoiceControl = structuredClone(document);
passiveVoiceControl.components[0].root.children![0].events = { pointerenter: "microphone" };
errorCode(() => parseSkinPluginDocument(passiveVoiceControl), "SKIN_PLUGIN_EVENT_INVALID");
const missingPermission = structuredClone(document);
missingPermission.components[0].permissions = missingPermission.components[0].permissions.filter((item) => item !== "audio.microphone.control");
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const oldSchema = structuredClone(document);
oldSchema.schemaVersion = 2;
errorCode(() => parseSkinPluginDocument(oldSchema), "SKIN_PLUGIN_SCHEMA_UNSUPPORTED");
});
test("skin plugin JSON parser enforces a bounded document size and valid JSON", () => {
assert.throws(() => parseSkinPluginJson("{"));
assert.throws(() => parseSkinPluginJson(" ".repeat(256 * 1024 + 1)));
assert.equal(parseSkinPluginJson(JSON.stringify(validDocument())).components.length, 1);
});
test("skin plugin enforces each component's node and nesting limits", () => {
const broad = validDocument();
broad.components[0].root.children = Array.from({ length: 101 }, () => ({ text: "item" }));
errorCode(() => parseSkinPluginDocument(broad), "SKIN_PLUGIN_TREE_INVALID");
const tooMany = validDocument();
const branch = (depth: number): SkinPluginNode => depth === 0
? { tag: "span", children: [{ text: "item" }] }
: { tag: "span", children: Array.from({ length: 3 }, () => branch(depth - 1)) };
tooMany.components[0].root.children = Array.from({ length: 3 }, () => branch(5));
errorCode(() => parseSkinPluginDocument(tooMany), "SKIN_PLUGIN_COMPLEXITY_LIMIT");
});
assert.ok(nodes.some((node) => node.widget === "voice.audio-controls" && node.options?.layout === "room-panel"));
assert.ok(nodes.some((node) => node.widget === "voice.screen-share-start"), "the voice dock exposes WebSpeak screen sharing");
assert.ok(nodes.some((node) => node.widget === "voice.screen-share-player"), "the voice stage keeps WebSpeak's screen-share player");
assert.equal(nodes.find((node) => node.part === "screen-share-stop")?.events?.click, "stop-screen-share");
assert.ok(nodes.some((node) => node.repeat?.path === "session.channels" && node.children?.[0].events?.dblclick === "join-channel"));
assert.ok(!nodes.some((node) => node.repeat?.path === "session.members"), "member imagery stays inside the trusted host widget");
assert.ok(nodes.some((node) => node.tag === "input" && node.bindValue === "message"));
});
test("skin plugin binds form controls only to declared local state", () => {
const document = validDocument();
document.components[0].state = { search: "" };
document.components[0].root.children = [{
tag: "input",
bindValue: "search",
events: { input: "filter" },
}];
document.components[0].actions.filter = { type: "ui.setState", args: { key: "search", value: "{{state.search}}" } };
assert.equal(parseSkinPluginDocument(document).components[0].state?.search, "");
});
test("skin plugin rejects undeclared permissions, arbitrary paths, and executable markup", () => {
const missingPermission = validDocument();
missingPermission.components[0].permissions = ["session.channel.join"];
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const hiddenPath = validDocument();
hiddenPath.components[0].root.children![0].children = [{ text: "{{session.credentials.privateKey}}" }];
errorCode(() => parseSkinPluginDocument(hiddenPath), "SKIN_PLUGIN_BINDING_INVALID");
const executable = validDocument();
executable.components[0].root.children![0].attributes = { onclick: "alert(1)" };
errorCode(() => parseSkinPluginDocument(executable), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
const unsafeTag = validDocument();
unsafeTag.components[0].root.children![0].tag = "iframe";
errorCode(() => parseSkinPluginDocument(unsafeTag), "SKIN_PLUGIN_ELEMENT_INVALID");
const externalSvgPaint = validDocument();
externalSvgPaint.components[0].root.children![0].attributes = { fill: "url(https://example.invalid/payload.svg#paint)" };
errorCode(() => parseSkinPluginDocument(externalSvgPaint), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
const skinOwnedPopover = validDocument();
skinOwnedPopover.components[0].root.children![0].attributes = { popover: "manual" };
errorCode(() => parseSkinPluginDocument(skinOwnedPopover), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
const skinOwnedPopoverTrigger = validDocument();
skinOwnedPopoverTrigger.components[0].root.children![0].attributes = { popovertarget: "host-editor" };
errorCode(() => parseSkinPluginDocument(skinOwnedPopoverTrigger), "SKIN_PLUGIN_ATTRIBUTE_INVALID");
});
test("skin plugin restricts repeated fields to the selected collection", () => {
const document = validDocument();
document.components[0].root.repeat = { path: "session.channels", as: "channel" };
document.components[0].root.children = [{ text: "{{channel.author}}" }];
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_BINDING_INVALID");
});
test("skin plugins can repeat channel members only under a channel alias and with member permission", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions.push("session.members.read");
document.components[0].root.children = [{
tag: "ul",
children: [{
tag: "li",
repeat: { path: "channel.members", as: "member" },
children: [{ text: "{{channel.name}} — {{member.avatarInitial}} {{member.name}}" }],
}],
}];
const parsed = parseSkinPluginDocument(document);
const nestedMember = parsed.components[0].root.children?.[0].children?.[0];
assert.deepEqual(nestedMember?.repeat, { path: "channel.members", as: "member" });
assert.equal(nestedMember?.children?.[0]?.text, "{{channel.name}} — {{member.avatarInitial}} {{member.name}}");
const membersOnly = structuredClone(document);
membersOnly.components[0].root.children = [{
tag: "ul",
when: { path: "channel.members", empty: false },
children: [{ tag: "li", repeat: { path: "channel.members", as: "member" } }],
}];
const parsedCondition = parseSkinPluginDocument(membersOnly).components[0].root.children?.[0];
assert.deepEqual(parsedCondition?.when, { path: "channel.members", empty: false });
const missingConditionPermission = structuredClone(membersOnly);
missingConditionPermission.components[0].permissions = ["session.channels.read", "session.channel.join"];
missingConditionPermission.components[0].root.children![0].children = [];
errorCode(() => parseSkinPluginDocument(missingConditionPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const invalidNestedCondition = structuredClone(membersOnly);
invalidNestedCondition.components[0].root.children![0].when = { path: "channel.members" };
errorCode(() => parseSkinPluginDocument(invalidNestedCondition), "SKIN_PLUGIN_CONDITION_INVALID");
const missingPermission = structuredClone(document);
missingPermission.components[0].permissions = ["session.channels.read", "session.channel.join"];
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const outsideChannel = structuredClone(document);
outsideChannel.components[0].root.repeat = undefined;
outsideChannel.components[0].root.children = [{ tag: "ul", repeat: { path: "channel.members", as: "member" } }];
errorCode(() => parseSkinPluginDocument(outsideChannel), "SKIN_PLUGIN_REPEAT_INVALID");
});
test("skin plugins keep live typing local but can run host actions on committed changes", () => {
const document = validDocument();
const input = document.components[0].root.children![0];
input.events = { input: "join" };
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_EVENT_INVALID");
input.events = { change: "join" };
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].events?.change, "join");
});
test("skin conditions can compare public repeated data with local component state", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].state = { selectedchannel: "" };
document.components[0].root.children![0].when = {
path: "state.selectedchannel",
equals: "{{channel.id}}",
};
const parsed = parseSkinPluginDocument(document);
assert.deepEqual(parsed.components[0].root.children?.[0].when, {
path: "state.selectedchannel",
equals: "{{channel.id}}",
});
const legacyDocument = structuredClone(document);
legacyDocument.schemaVersion = 2;
errorCode(() => parseSkinPluginDocument(legacyDocument), "SKIN_PLUGIN_SCHEMA_UNSUPPORTED");
document.components[0].root.children![0].when!.equals = "{{channel.address}}";
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_BINDING_INVALID");
});
test("schema v3 can render empty states only for permissioned public collections", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions.push("chat.channel.read");
document.components[0].root.children = [{
tag: "p",
when: { path: "chat.messages", empty: true },
children: [{ text: "No messages yet" }],
}];
assert.equal(parseSkinPluginDocument(document).components[0].root.children?.[0].when?.empty, true);
document.components[0].permissions.push("session.status.read");
document.components[0].root.children[0].when!.path = "session.status.serverLabel";
errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_CONDITION_INVALID");
});
test("component schema v3 exposes composable interaction patterns and permission-gated voice actions", () => {
const document = validDocument();
document.schemaVersion = 3;
document.components[0].permissions = [
"audio.microphone.control", "audio.output.control", "audio.status.read", "voice.disconnect", "voice.presence.write",
"voice.whisper.control", "voice.whisper.status.read", "voice.screenShare.control", "voice.screenShare.read", "voice.screenShare.status.read",
];
document.components[0].state = { menuopen: false, volume: 0.5, awaymessage: "" };
document.components[0].actions = {
"toggle-menu": { type: "ui.toggleState", args: { key: "menuopen" } },
microphone: { type: "voice.toggleMicrophone", args: {} },
speaker: { type: "voice.toggleOutputMute", args: {} },
volume: { type: "voice.setOutputVolume", args: { volume: "{{state.volume}}" } },
disconnect: { type: "voice.disconnect", args: {} },
away: { type: "voice.setAway", args: { away: true, message: "{{state.awaymessage}}" } },
whisper: { type: "voice.setWhisperActive", args: { active: true } },
"start-share": { type: "voice.startScreenShare", args: {} },
"stop-share": { type: "voice.stopScreenShare", args: {} },
"join-share": { type: "voice.joinScreenShare", args: { streamId: "{{share.streamId}}" } },
"leave-share": { type: "voice.leaveScreenShare", args: {} },
};
document.components[0].root = {
tag: "main",
attributes: { "data-layout": "room", "aria-label": "Custom voice page" },
children: [
{ tag: "button", events: { contextmenu: "toggle-menu", pointerenter: "toggle-menu" }, children: [{ text: "Menu" }] },
{ tag: "button", events: { click: "microphone" }, children: [{ text: "Microphone" }] },
{ tag: "button", events: { click: "speaker" }, children: [{ text: "Speaker" }] },
{ tag: "button", events: { click: "volume" }, children: [{ text: "Volume" }] },
{ tag: "button", events: { click: "disconnect" }, children: [{ text: "Disconnect" }] },
{ tag: "button", events: { click: "away" }, children: [{ text: "Away" }] },
{ tag: "button", events: { click: "whisper" }, children: [{ text: "Whisper" }] },
{ tag: "button", events: { click: "start-share" }, children: [{ text: "Share" }] },
{ tag: "button", events: { click: "stop-share" }, children: [{ text: "Stop sharing" }] },
{ tag: "div", repeat: { path: "screenShare.streams", as: "share" }, children: [
{ tag: "button", events: { click: "join-share" }, children: [{ text: "{{share.name}}" }] },
] },
{ tag: "button", events: { click: "leave-share" }, children: [{ text: "Leave share" }] },
],
};
const parsed = parseSkinPluginDocument(document);
assert.equal(parsed.schemaVersion, 3);
assert.equal(parsed.components[0].root.children?.[0].events?.contextmenu, "toggle-menu");
assert.equal(parsed.components[0].actions["join-share"].type, "voice.joinScreenShare");
assert.equal(parsed.components[0].root.children?.[9].repeat?.path, "screenShare.streams");
const passiveVoiceControl = structuredClone(document);
passiveVoiceControl.components[0].root.children![0].events = { pointerenter: "microphone" };
errorCode(() => parseSkinPluginDocument(passiveVoiceControl), "SKIN_PLUGIN_EVENT_INVALID");
const missingPermission = structuredClone(document);
missingPermission.components[0].permissions = missingPermission.components[0].permissions.filter((item) => item !== "audio.microphone.control");
errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING");
const oldSchema = structuredClone(document);
oldSchema.schemaVersion = 2;
errorCode(() => parseSkinPluginDocument(oldSchema), "SKIN_PLUGIN_SCHEMA_UNSUPPORTED");
});
test("skin plugin JSON parser enforces a bounded document size and valid JSON", () => {
assert.throws(() => parseSkinPluginJson("{"));
assert.throws(() => parseSkinPluginJson(" ".repeat(256 * 1024 + 1)));
assert.equal(parseSkinPluginJson(JSON.stringify(validDocument())).components.length, 1);
});
test("skin plugin enforces each component's node and nesting limits", () => {
const broad = validDocument();
broad.components[0].root.children = Array.from({ length: 101 }, () => ({ text: "item" }));
errorCode(() => parseSkinPluginDocument(broad), "SKIN_PLUGIN_TREE_INVALID");
const tooMany = validDocument();
const branch = (depth: number): SkinPluginNode => depth === 0
? { tag: "span", children: [{ text: "item" }] }
: { tag: "span", children: Array.from({ length: 3 }, () => branch(depth - 1)) };
tooMany.components[0].root.children = Array.from({ length: 3 }, () => branch(5));
errorCode(() => parseSkinPluginDocument(tooMany), "SKIN_PLUGIN_COMPLEXITY_LIMIT");
});
+564 -558
View File
File diff suppressed because it is too large. Load diff