botsService.help.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { describe, expect, it } from "vitest";
  2. import * as f from "./botsService.fixtures.js";
  3. const actor = {
  4. provider: "webhook" as const,
  5. botId: "webhook-1",
  6. providerUserId: "user-1",
  7. chatType: "private" as const,
  8. };
  9. describe("botsService help", () => {
  10. it("shows command help after binding succeeds", async () => {
  11. const repo = f.createMemoryRepo(f.baseConfig);
  12. const service = f.createBotsService({
  13. credentialService: f.createCredentialService({ "secret-1": "secret" }),
  14. legacyTaskService: f.createLegacyTaskService(),
  15. repo: repo as never,
  16. });
  17. const code = await service.createBindCode({ botId: "webhook-1" });
  18. const replies = await service.handleInboundMessage({
  19. botId: "webhook-1",
  20. text: `/bind ${code.code}`,
  21. actor,
  22. });
  23. expect(replies[0]?.text).toBe(
  24. [
  25. "绑定成功。发送 **/帮助** 查看可用命令。",
  26. "",
  27. "ZCode 机器人命令:",
  28. "**/帮助** — 查看这份说明",
  29. "**/状态** — 查看工作区、模型和任务状态",
  30. "/新建 或 /clear — 开始新的任务草稿",
  31. "**/项目** — 切换工作区",
  32. "**/模型** — 切换模型",
  33. "**/模式** — 切换运行模式",
  34. "**/思考** — 切换思考级别",
  35. "**/回复** — 切换回复详细程度",
  36. "**/bind <code>** — 绑定当前聊天",
  37. ].join("\n"),
  38. );
  39. service.disposeAll();
  40. });
  41. it("returns concise Chinese command help for /帮助", async () => {
  42. const repo = f.createMemoryRepo(f.baseConfig);
  43. const service = f.createBotsService({
  44. credentialService: f.createCredentialService({ "secret-1": "secret" }),
  45. legacyTaskService: f.createLegacyTaskService(),
  46. repo: repo as never,
  47. });
  48. const code = await service.createBindCode({ botId: "webhook-1" });
  49. await service.handleInboundMessage({
  50. botId: "webhook-1",
  51. text: `/bind ${code.code}`,
  52. actor,
  53. });
  54. const replies = await service.handleInboundMessage({
  55. botId: "webhook-1",
  56. text: "/帮助",
  57. actor,
  58. });
  59. expect(replies[0]?.text).toBe(
  60. [
  61. "ZCode 机器人命令:",
  62. "**/帮助** — 查看这份说明",
  63. "**/状态** — 查看工作区、模型和任务状态",
  64. "/新建 或 /clear — 开始新的任务草稿",
  65. "**/项目** — 切换工作区",
  66. "**/模型** — 切换模型",
  67. "**/模式** — 切换运行模式",
  68. "**/思考** — 切换思考级别",
  69. "**/回复** — 切换回复详细程度",
  70. "**/bind <code>** — 绑定当前聊天",
  71. ].join("\n"),
  72. );
  73. service.disposeAll();
  74. });
  75. it("returns English command help with new or clear wording", async () => {
  76. const repo = f.createMemoryRepo(f.baseConfig);
  77. const service = f.createBotsService({
  78. credentialService: f.createCredentialService({ "secret-1": "secret" }),
  79. legacyTaskService: f.createLegacyTaskService(),
  80. repo: repo as never,
  81. settingService: f.createSettingService({
  82. locale: "en-US",
  83. lastWorkspaceSession: [
  84. {
  85. kind: "remote",
  86. workspacePath: "/tmp/workspace",
  87. workspaceIdentity: "ssh://host/tmp/workspace",
  88. },
  89. ],
  90. }),
  91. });
  92. const code = await service.createBindCode({ botId: "webhook-1" });
  93. await service.handleInboundMessage({
  94. botId: "webhook-1",
  95. text: `/bind ${code.code}`,
  96. actor,
  97. });
  98. const replies = await service.handleInboundMessage({
  99. botId: "webhook-1",
  100. text: "/help",
  101. actor,
  102. });
  103. expect(replies[0]?.text).toContain("/new or /clear — Start a new task draft");
  104. service.disposeAll();
  105. });
  106. });