fix(runtime): restrict system miniapp registration
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { CoreAppRegistry } from "@/runtime/app-management/app-registry";
|
||||||
|
|
||||||
|
describe("CoreAppRegistry SDK v1 kind policy", () => {
|
||||||
|
it("keeps Interact as the only system MiniApp", () => {
|
||||||
|
const registry = new CoreAppRegistry();
|
||||||
|
expect(registry.get("chat")?.kind).toBe("system");
|
||||||
|
expect(() => registry.install({
|
||||||
|
app_scope: "other-system", kind: "system", enabled: true, default_eligible: false, recovery: false,
|
||||||
|
manifest: { app_scope: "other-system", version: "1.0.0", permissions: [], tools: [] },
|
||||||
|
})).toThrow("Only the Interact system MiniApp");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -16,6 +16,7 @@ import type { JsonObject } from "@/runtime/protocol/lineup-v1";
|
|||||||
|
|
||||||
export type AppScope = "chat" | "app-registry" | "settings" | "runtime" | (string & {});
|
export type AppScope = "chat" | "app-registry" | "settings" | "runtime" | (string & {});
|
||||||
export type MiniAppKind = "system" | "bundled";
|
export type MiniAppKind = "system" | "bundled";
|
||||||
|
const SYSTEM_APP_SCOPE: AppScope = "chat";
|
||||||
|
|
||||||
export type AppToolDefinition = {
|
export type AppToolDefinition = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -134,6 +135,7 @@ export class CoreAppRegistry {
|
|||||||
|
|
||||||
private register(record: CoreAppRecordInput): void {
|
private register(record: CoreAppRecordInput): void {
|
||||||
if (!isAppScope(record.app_scope) || record.manifest.app_scope !== record.app_scope) throw new Error("Core App Registry received an invalid app_scope.");
|
if (!isAppScope(record.app_scope) || record.manifest.app_scope !== record.app_scope) throw new Error("Core App Registry received an invalid app_scope.");
|
||||||
|
if (record.kind === "system" && record.app_scope !== SYSTEM_APP_SCOPE) throw new Error("Only the Interact system MiniApp may use kind=system in SDK v1.");
|
||||||
if (this.apps.has(record.app_scope)) throw new Error(`Core App Registry has duplicate app_scope: ${record.app_scope}`);
|
if (this.apps.has(record.app_scope)) throw new Error(`Core App Registry has duplicate app_scope: ${record.app_scope}`);
|
||||||
if (!isManifest(record.manifest)) throw new Error(`Core App Registry has an invalid manifest: ${record.app_scope}`);
|
if (!isManifest(record.manifest)) throw new Error(`Core App Registry has an invalid manifest: ${record.app_scope}`);
|
||||||
this.apps.set(record.app_scope, copyRecord(record));
|
this.apps.set(record.app_scope, copyRecord(record));
|
||||||
|
|||||||
Reference in New Issue
Block a user