mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): add validated runtime UI output bridge
This commit is contained in:
1 parent
7047d71678
commit
d137b41b5c
16 files changed
+443
-155
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
type SkinPluginHostWidget,
|
||||
type SkinPluginNode,
|
||||
} from "../../../src/shared/skin-plugin.js";
|
||||
import { parseSkinExtensionUiOutput } from "../../../src/shared/skin-extension-ui.js";
|
||||
import { approveSkinPluginComponents, getMissingSkinPluginApprovals, isSkinPluginComponentApproved, revokeSkinPluginApprovals } from "../services/skin-plugin-approval.js";
|
||||
|
||||
type Scalar = string | number | boolean;
|
||||
@@ -28,6 +29,7 @@ export default defineComponent({
|
||||
skinId: { type: String, required: true },
|
||||
skinVersion: { type: String, required: true },
|
||||
document: { type: Object as PropType<SkinPluginDocument>, required: true },
|
||||
extensionOutput: { type: String, default: null },
|
||||
page: { type: String as PropType<"home" | "voice" | "demo">, required: true },
|
||||
data: { type: Object as PropType<SafeContext>, required: true },
|
||||
assets: { type: Object as PropType<Record<string, Blob>>, required: true },
|
||||
@@ -46,8 +48,20 @@ export default defineComponent({
|
||||
const stateByComponent = reactive<Record<string, Record<string, Scalar>>>({});
|
||||
const objectUrls = new Map<string, string>();
|
||||
const validatedDocument = computed(() => {
|
||||
try { return parseSkinPluginDocument(props.document); }
|
||||
let document: SkinPluginDocument;
|
||||
try { document = parseSkinPluginDocument(props.document); }
|
||||
catch { return { schemaVersion: 2 as const, components: [] }; }
|
||||
if (!props.extensionOutput || document.schemaVersion !== 3) return document;
|
||||
try {
|
||||
const extensionDocument = parseSkinExtensionUiOutput(props.extensionOutput);
|
||||
return parseSkinPluginDocument({
|
||||
schemaVersion: 3,
|
||||
components: [...document.components, ...extensionDocument.components],
|
||||
});
|
||||
} catch {
|
||||
// Dynamic output is optional; an invalid or colliding result leaves the package UI intact.
|
||||
return document;
|
||||
}
|
||||
});
|
||||
const matchingComponents = computed(() => validatedDocument.value.components.filter((component) => component.page === props.page));
|
||||
const pendingApproval = computed(() => {
|
||||
@@ -66,7 +80,7 @@ export default defineComponent({
|
||||
const renderedComponents = computed(() => activeComponents.value.filter((component) =>
|
||||
component.mode !== "surface" || component !== surfaceCandidate.value || !surfaceSuppressed.value));
|
||||
|
||||
watch(() => [props.skinId, props.skinVersion, props.document, props.page], () => {
|
||||
watch(() => [props.skinId, props.skinVersion, props.document, props.extensionOutput, props.page], () => {
|
||||
denied.value = false;
|
||||
surfaceSuppressed.value = false;
|
||||
refresh.value += 1;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { createSSRApp } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import type { SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import {
|
||||
parseSkinExtensionUiOutput,
|
||||
SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES,
|
||||
SkinExtensionUiOutputError,
|
||||
} from "../../../src/shared/skin-extension-ui.js";
|
||||
import SkinPluginOutlet from "../components/SkinPluginOutlet.js";
|
||||
|
||||
function outputDocument(componentId = "runtime-ui", root?: Record<string, unknown>, permissions: string[] = [], actions: Record<string, unknown> = {}, state?: Record<string, unknown>): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 3,
|
||||
components: [{
|
||||
id: componentId,
|
||||
name: "Runtime UI",
|
||||
page: "voice",
|
||||
accessibleName: "Runtime UI",
|
||||
permissions,
|
||||
actions,
|
||||
...(state ? { state } : {}),
|
||||
root: root ?? { tag: "section", children: [{ text: "Generated by Wasm" }] },
|
||||
}],
|
||||
});
|
||||
}
|
||||
|
||||
function expectOutputError(source: string, code: string): void {
|
||||
assert.throws(() => parseSkinExtensionUiOutput(source), (error: unknown) =>
|
||||
error instanceof SkinExtensionUiOutputError && error.code === code);
|
||||
}
|
||||
|
||||
test("Wasm UI output uses the v3 schema and supports local-only interaction", () => {
|
||||
const document = parseSkinExtensionUiOutput(outputDocument("runtime-ui", {
|
||||
tag: "section",
|
||||
children: [
|
||||
{ tag: "button", attributes: { type: "button" }, events: { click: "toggle" }, children: [{ text: "Toggle" }] },
|
||||
{ tag: "p", when: { path: "state.open", equals: true }, children: [{ text: "Expanded" }] },
|
||||
],
|
||||
}, [], { toggle: { type: "ui.toggleState", args: { key: "open" } } }, { open: false }));
|
||||
|
||||
assert.equal(document.schemaVersion, 3);
|
||||
assert.equal(document.components[0].actions.toggle.type, "ui.toggleState");
|
||||
});
|
||||
|
||||
test("Wasm UI output rejects malformed, oversized, legacy, and capability-bearing documents", () => {
|
||||
expectOutputError("{", "SKIN_EXTENSION_UI_OUTPUT_JSON");
|
||||
expectOutputError(" ".repeat(SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES + 1), "SKIN_EXTENSION_UI_OUTPUT_SIZE");
|
||||
expectOutputError(JSON.stringify({ schemaVersion: 2, components: [{
|
||||
id: "runtime-ui", name: "Runtime UI", page: "voice", accessibleName: "Runtime UI", permissions: [], actions: {}, root: { tag: "section" },
|
||||
}] }), "SKIN_EXTENSION_UI_SCHEMA_UNSUPPORTED");
|
||||
expectOutputError(outputDocument("runtime-ui", undefined, ["session.status.read"]), "SKIN_EXTENSION_UI_CAPABILITY_UNSUPPORTED");
|
||||
expectOutputError(outputDocument("runtime-ui", undefined, [], { disconnect: { type: "voice.disconnect", args: {} } }), "SKIN_EXTENSION_UI_OUTPUT_SCHEMA");
|
||||
expectOutputError(outputDocument("runtime-ui", { widget: "voice.audio-controls" }), "SKIN_EXTENSION_UI_WIDGET_UNSUPPORTED");
|
||||
expectOutputError(outputDocument("runtime-ui", { tag: "p", text: "{{session.status.channelName}}" }), "SKIN_EXTENSION_UI_OUTPUT_SCHEMA");
|
||||
});
|
||||
|
||||
test("SkinPluginOutlet renders validated dynamic output and preserves package UI on collisions", 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: "Package UI" }] },
|
||||
}],
|
||||
};
|
||||
const props = {
|
||||
skinId: "community.test",
|
||||
skinVersion: "1.0.0",
|
||||
document,
|
||||
page: "voice" as const,
|
||||
data: {},
|
||||
assets: {},
|
||||
actions: {},
|
||||
};
|
||||
|
||||
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
|
||||
...props,
|
||||
extensionOutput: outputDocument("runtime-ui"),
|
||||
}));
|
||||
assert.match(html, /data-ws-plugin-component="base-ui"/);
|
||||
assert.match(html, /data-ws-plugin-component="runtime-ui"/);
|
||||
assert.match(html, /Generated by Wasm/);
|
||||
|
||||
const collisionHtml = await renderToString(createSSRApp(SkinPluginOutlet, {
|
||||
...props,
|
||||
extensionOutput: outputDocument("base-ui"),
|
||||
}));
|
||||
assert.match(collisionHtml, /data-ws-plugin-component="base-ui"/);
|
||||
assert.doesNotMatch(collisionHtml, /Generated by Wasm/);
|
||||
assert.match(collisionHtml, /Package UI/);
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import { SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES } from "../../../src/shared/skin-extension-ui.js";
|
||||
|
||||
export const SKIN_EXTENSION_WASM_SOURCE_LIMIT = 256 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_MEMORY_LIMIT_PAGES = 64;
|
||||
export const SKIN_EXTENSION_WASM_PAGE_BYTES = 64 * 1024;
|
||||
@@ -6,7 +8,7 @@ export const SKIN_EXTENSION_WASM_EXECUTION_LIMIT_MS = 100;
|
||||
export const SKIN_EXTENSION_WASM_MESSAGE_LIMIT = 32 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_STATUS_READ_LIMIT = 10;
|
||||
export const SKIN_EXTENSION_WASM_STATUS_BYTES_LIMIT = 512;
|
||||
export const SKIN_EXTENSION_WASM_UI_OUTPUT_LIMIT_BYTES = 16 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_UI_OUTPUT_LIMIT_BYTES = SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES;
|
||||
export const SKIN_EXTENSION_WASM_FUEL_LIMIT = 10_000_000n;
|
||||
export const SKIN_EXTENSION_WASM_INTERPRETER_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
|
||||
export const SKIN_EXTENSION_WASM_FUNCTION_LIMIT = 128;
|
||||
|
||||
@@ -368,8 +368,9 @@ test("the distributable KAAK v3 package validates end to end", async () => {
|
||||
const skin = await importSkinPack(file);
|
||||
assert.equal(skin.id, "community.kaak-voice");
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
assert.equal(skin.pluginData?.components[0].id, "kaak-room-sidebar");
|
||||
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-room-sidebar.channel-row"'));
|
||||
assert.deepEqual(skin.pluginData?.components.map((component) => component.id), ["kaak-channel-sidebar", "kaak-members-sidebar"]);
|
||||
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-channel-sidebar.channel-row"'));
|
||||
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-members-sidebar.member-row-content"'));
|
||||
});
|
||||
|
||||
test("the full voice surface example packages home, voice, and host-owned controls", async () => {
|
||||
|
||||
Reference in new issue
Block a user