mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-10 14:28:38 +03:00
* refactor(channels): own setup and instance contracts * refactor(channels): isolate management contracts * refactor(channels): normalize activation contracts * fix(channels): enforce management contracts * refactor(channels): finish setup ownership migration * fix(channels): harden management contracts * fix(channels): enforce lazy loading and runtime ownership * fix(feishu): make multi-instance startup idempotent * fix(webui): render channel setup contracts cleanly * fix(feishu): stop websocket clients cleanly * fix(channels): enforce persistence and activation gates * fix(channels): preserve global feature action scope * fix(channels): apply defaults for single plugins * fix(channels): enforce management contract boundaries * refactor(feishu): remove identity helper indirection * fix(channels): preserve management setup contracts * refactor(channels): generalize instance settings UI * refactor(channels): package channel plugins with web UI metadata * refactor(channels): make built-ins self-contained packages * test(channels): colocate tests with channel packages * fix(dingtalk): use official brand icon * feat(channels): colocate webui translations * docs(channels): clarify plugin ownership * test(exec): remove output wait race * refactor(channels): unify plugin descriptors * fix(channels): enforce descriptor-owned contracts * refactor(channels): finish package-owned plugin setup * refactor(channels): use repository-owned packages only * fix(channels): self-describe dependencies and runtime state * fix(channels): warn about legacy entry points
79 lines
3.2 KiB
TypeScript
79 lines
3.2 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
channelUiContribution,
|
|
channelUiOwner,
|
|
channelUiPresentation,
|
|
registeredChannelUiContributions,
|
|
} from "@/channel-plugins/registry";
|
|
|
|
describe("channel UI contributions", () => {
|
|
it("selects channel-owned UI only through the backend manifest entry", () => {
|
|
expect(channelUiContribution("feishu", "webui/index.tsx")?.Panel).toBeTypeOf("function");
|
|
expect(channelUiContribution("weixin", "webui/index.tsx")?.ConnectFlow).toBeTypeOf("function");
|
|
expect(channelUiContribution("feishu", undefined)).toBeUndefined();
|
|
expect(channelUiContribution("feishu", "webui/missing.tsx")).toBeUndefined();
|
|
expect(channelUiContribution("missing", "webui/index.tsx")).toBeUndefined();
|
|
|
|
const registrations = registeredChannelUiContributions();
|
|
const channels = registrations.map((entry) => entry.channel);
|
|
expect(channels).toEqual(expect.arrayContaining(["feishu", "weixin"]));
|
|
expect(new Set(channels).size).toBe(channels.length);
|
|
expect(registrations.every((entry) => /^webui\/index\.tsx?$/.test(entry.webui))).toBe(true);
|
|
expect(channelUiContribution("slack", "webui/index.ts")?.presentation.displayName).toBe("Slack");
|
|
});
|
|
|
|
it("keeps aliases inside the owning channel contribution", () => {
|
|
expect(channelUiPresentation("lark")?.displayName).toBe("Lark");
|
|
expect(channelUiPresentation("wechat")?.displayName).toBe("WeChat");
|
|
expect(channelUiOwner("lark")).toBe("feishu");
|
|
expect(channelUiOwner("wechat")).toBe("weixin");
|
|
});
|
|
|
|
it("uses the DingTalk Open Platform brand mark", () => {
|
|
expect(channelUiPresentation("dingtalk")?.logoUrl).toBe(
|
|
"https://img.alicdn.com/imgextra/i3/O1CN01WMvMRG1ks3Ixc9x1v_!!6000000004738-55-tps-32-32.svg",
|
|
);
|
|
});
|
|
|
|
it("keeps the core setup panel independent of concrete channel plugins", () => {
|
|
const source = readFileSync(
|
|
resolve(process.cwd(), "src/components/settings/channels/ChannelSetupPanel.tsx"),
|
|
"utf8",
|
|
);
|
|
|
|
expect(source).not.toMatch(/feature\.name\s*===\s*["'](?:feishu|weixin)["']/);
|
|
expect(source).not.toMatch(/channel-plugins\/(?:feishu|weixin)/);
|
|
expect(source).not.toMatch(/(?:Feishu|Weixin)(?:AssistantsPanel|ConnectFlow)/);
|
|
});
|
|
|
|
it("discovers UI contributions only from channel-owned packages", () => {
|
|
const source = readFileSync(
|
|
resolve(process.cwd(), "src/channel-plugins/registry.ts"),
|
|
"utf8",
|
|
);
|
|
|
|
expect(source).toContain("../../../nanobot/channels/*/webui/**/*.{ts,tsx}");
|
|
expect(source).not.toContain('"./*/index.tsx"');
|
|
});
|
|
|
|
it("derives channel identity from the package directory", () => {
|
|
for (const channel of ["feishu", "weixin"]) {
|
|
const source = readFileSync(
|
|
resolve(process.cwd(), `../nanobot/channels/${channel}/webui/index.tsx`),
|
|
"utf8",
|
|
);
|
|
expect(source).not.toMatch(/\bchannel\s*:/);
|
|
}
|
|
});
|
|
|
|
it("includes channel-owned UI in Tailwind's production scan", () => {
|
|
const source = readFileSync(resolve(process.cwd(), "tailwind.config.js"), "utf8");
|
|
|
|
expect(source).toContain("../nanobot/channels/*/webui/**/*.{ts,tsx}");
|
|
});
|
|
});
|