bot-remote-disconnected.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import type { BotsConfigFile, BotsStateFile } from "@zcode/shared";
  2. import {
  3. createBotsServiceHarness,
  4. readBotSyntheticFixture,
  5. } from "#e2e/bots/helpers/bots-service-harness";
  6. describe("Bot remote workspace delivery E2E", () => {
  7. it("BOT-E2E-RW-01 rejects a disconnected remote workspace without reconnect or local fallback", async () => {
  8. const fixture = await readBotSyntheticFixture("remote-workspace-disconnected.json");
  9. expect(fixture).toMatchObject({ caseId: "BOT-E2E-RW-01", classification: "synthetic" });
  10. expect(fixture.syntheticReason.length).toBeGreaterThan(20);
  11. const config: BotsConfigFile = {
  12. version: 3,
  13. bots: [
  14. {
  15. id: "webhook-e2e",
  16. name: "Webhook E2E",
  17. provider: "webhook",
  18. enabled: true,
  19. webhookSecretRef: "webhook-secret-e2e",
  20. providerUserId: "user-e2e",
  21. allowedWorkspaces: ["*"],
  22. allowedCommands: {
  23. status: true,
  24. new: true,
  25. workspace: true,
  26. model: true,
  27. thoughtLevel: true,
  28. sandboxMode: true,
  29. approvalPolicy: true,
  30. reply: true,
  31. },
  32. currentOptions: {},
  33. replyMode: "assistant_changes",
  34. },
  35. ],
  36. };
  37. const state: BotsStateFile = {
  38. version: 3,
  39. bots: {
  40. "webhook-e2e": {
  41. botId: "webhook-e2e",
  42. workspacePath: "/workspace",
  43. workspaceIdentity: "remote:server:e2e-host:/workspace",
  44. workspaceId: "remote:server:e2e-host:/workspace",
  45. mode: "task",
  46. activeTaskId: "task-remote-e2e",
  47. updatedAt: Date.now(),
  48. },
  49. },
  50. };
  51. let isConnectedCalls = 0;
  52. let ensureConnectedCalls = 0;
  53. let remoteTaskServiceCalls = 0;
  54. const harness = createBotsServiceHarness({
  55. config,
  56. state,
  57. projectWorkspaces: [
  58. {
  59. kind: "remote",
  60. workspacePath: "/workspace",
  61. workspaceIdentity: "remote:server:e2e-host:/workspace",
  62. remoteSessionId: "remote-session-e2e",
  63. },
  64. ],
  65. remoteWorkspaceService: {
  66. isConnected: async (target: unknown) => {
  67. isConnectedCalls += 1;
  68. expect(target).toEqual({
  69. hostId: "remote:server:e2e-host",
  70. workspacePath: "/workspace",
  71. workspaceIdentity: "remote:server:e2e-host:/workspace",
  72. });
  73. return false;
  74. },
  75. ensureConnected: async () => {
  76. ensureConnectedCalls += 1;
  77. return { ok: true };
  78. },
  79. getZCodeTaskService: async () => {
  80. remoteTaskServiceCalls += 1;
  81. return harness.zcodeTaskService;
  82. },
  83. },
  84. });
  85. try {
  86. const replies = await harness.service.handleInboundMessage({
  87. botId: "webhook-e2e",
  88. text: "E2E_BOT_REMOTE_DISCONNECTED 请检查当前项目",
  89. actor: {
  90. provider: "webhook",
  91. botId: "webhook-e2e",
  92. providerUserId: "user-e2e",
  93. chatType: "private",
  94. },
  95. });
  96. expect(replies.map((reply) => reply.text)).toEqual([
  97. "当前远端项目 /workspace 未连接。请先发送 **/重连**,连接恢复后再重试。上一条请求未执行。",
  98. ]);
  99. expect(isConnectedCalls).toBe(1);
  100. expect(ensureConnectedCalls).toBe(0);
  101. expect(remoteTaskServiceCalls).toBe(0);
  102. expect(harness.createTaskCalls).toEqual([]);
  103. expect(harness.sendPromptCalls).toEqual([]);
  104. } finally {
  105. harness.service.disposeAll();
  106. }
  107. });
  108. });