botsDialogConfig.test.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { describe, expect, it } from "vitest";
  2. import type { BotConfig } from "@zcode/shared";
  3. import { ALL_BOT_WORKSPACES } from "@zcode/shared";
  4. import {
  5. BOT_REPLY_GRANULARITIES,
  6. getBotReplyGranularitiesForProvider,
  7. getBotReplyGranularityEntryForProvider,
  8. resolveBotProviderEntry,
  9. } from "../src/botsUi.js";
  10. import enUS from "../src/i18n/locales/en-US.js";
  11. import zhCN from "../src/i18n/locales/zh-CN.js";
  12. describe("BotsDialog config", () => {
  13. it("keeps reply granularity labels localized", () => {
  14. for (const granularity of BOT_REPLY_GRANULARITIES) {
  15. expect(enUS[granularity.labelId]).toBeTruthy();
  16. expect(zhCN[granularity.labelId]).toBeTruthy();
  17. expect(enUS[granularity.descriptionId]).toBeTruthy();
  18. expect(zhCN[granularity.descriptionId]).toBeTruthy();
  19. }
  20. });
  21. it("limits Feishu and Lark reply granularity to streaming cards", () => {
  22. expect(getBotReplyGranularitiesForProvider("feishu").map((item) => item.id)).toEqual([
  23. "streaming_card",
  24. ]);
  25. expect(getBotReplyGranularitiesForProvider("lark").map((item) => item.id)).toEqual([
  26. "streaming_card",
  27. ]);
  28. expect(getBotReplyGranularitiesForProvider("telegram").map((item) => item.id)).toEqual([
  29. "assistant_changes",
  30. "assistant_toolcalls_changes",
  31. "summary_changes",
  32. ]);
  33. expect(getBotReplyGranularityEntryForProvider("feishu", "assistant_changes").id).toBe(
  34. "streaming_card",
  35. );
  36. expect(getBotReplyGranularityEntryForProvider("telegram", "streaming_card").id).toBe(
  37. "assistant_changes",
  38. );
  39. });
  40. it("resolves remote-control bot entry to the first existing provider bot", () => {
  41. const bots: BotConfig[] = [
  42. createBot("feishu-later", "feishu"),
  43. createBot("telegram-first", "telegram"),
  44. createBot("telegram-second", "telegram"),
  45. ];
  46. expect(resolveBotProviderEntry(bots, "telegram")).toEqual({
  47. mode: "select",
  48. botId: "telegram-first",
  49. });
  50. });
  51. it("resolves remote-control bot entry to provider creation when no bot exists", () => {
  52. expect(resolveBotProviderEntry([createBot("weixin-one", "weixin")], "feishu")).toEqual({
  53. mode: "create",
  54. provider: "feishu",
  55. });
  56. });
  57. });
  58. function createBot(id: string, provider: BotConfig["provider"]): BotConfig {
  59. return {
  60. id,
  61. name: "",
  62. provider,
  63. enabled: true,
  64. allowedWorkspaces: [ALL_BOT_WORKSPACES],
  65. allowedCommands: {
  66. readFile: "always",
  67. writeFile: "ask",
  68. runCommand: "ask",
  69. },
  70. currentOptions: {},
  71. replyMode: "assistant_changes",
  72. };
  73. }