useBotBroadcastEffects.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { describe, expect, it, vi } from "vitest";
  2. import type { ZCodeConfigOption } from "@zcode/shared";
  3. import {
  4. shouldRefreshBotTaskList,
  5. shouldMirrorBotTaskStreamToStore,
  6. syncBotTaskConfigOptionsToStore,
  7. } from "../src/root/useBotBroadcastEffects.js";
  8. describe("useBotBroadcastEffects", () => {
  9. it("refreshes created events even when task meta exists", () => {
  10. expect(shouldRefreshBotTaskList("created", true)).toBe(true);
  11. });
  12. it("keeps incremental-only handling for non-created events with task meta", () => {
  13. expect(shouldRefreshBotTaskList("updated", true)).toBe(false);
  14. expect(shouldRefreshBotTaskList("completed", true)).toBe(false);
  15. expect(shouldRefreshBotTaskList("error", true)).toBe(false);
  16. });
  17. it("mirrors active remote bot stream because ChatView may not subscribe to bot runtime", () => {
  18. expect(
  19. shouldMirrorBotTaskStreamToStore({
  20. activeTaskId: "task-1",
  21. taskId: "task-1",
  22. workspaceIdentity: "remote:docker:demo:/workspace/demo",
  23. }),
  24. ).toBe(true);
  25. });
  26. it("keeps skipping active local bot stream to avoid duplicate normal ZCode Agent subscription writes", () => {
  27. expect(
  28. shouldMirrorBotTaskStreamToStore({
  29. activeTaskId: "task-1",
  30. taskId: "task-1",
  31. }),
  32. ).toBe(false);
  33. });
  34. it("syncs bot config options through the task config bucket", () => {
  35. const configOptions: ZCodeConfigOption[] = [
  36. {
  37. id: "runtime_mode",
  38. category: "mode",
  39. type: "select",
  40. currentValue: "plan",
  41. options: [
  42. { value: "default", name: "Default" },
  43. { value: "plan", name: "Plan" },
  44. ],
  45. },
  46. ];
  47. const zcodeSessionStore = {
  48. setTaskConfigOptions: vi.fn(),
  49. };
  50. syncBotTaskConfigOptionsToStore({
  51. zcodeSessionStore,
  52. workspacePath: "/repo",
  53. workspaceIdentity: "ssh://host/repo",
  54. taskId: "task-1",
  55. configOptions,
  56. });
  57. expect(zcodeSessionStore.setTaskConfigOptions).toHaveBeenCalledWith(
  58. "/repo",
  59. "task-1",
  60. configOptions,
  61. "ssh://host/repo",
  62. );
  63. });
  64. });