botsTaskStreamBroadcast.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { describe, expect, it } from "vitest";
  2. import { BOT_TASK_STREAM_BROADCAST_CHANNEL } from "@zcode/shared";
  3. import { resolveBotTaskStreamBroadcast } from "../src/root/botsTaskStreamBroadcast.js";
  4. import type { WindowTabState } from "../src/store/tabStore.js";
  5. const tabs: WindowTabState[] = [
  6. {
  7. id: "tab-1",
  8. kind: "workspace",
  9. label: "repo",
  10. workspacePath: "/repo",
  11. workspaceIdentity: "ssh://host/repo",
  12. },
  13. ];
  14. describe("bot task stream broadcast", () => {
  15. it("accepts stream events for an open workspace", () => {
  16. const stream = resolveBotTaskStreamBroadcast(
  17. {
  18. channel: BOT_TASK_STREAM_BROADCAST_CHANNEL,
  19. payload: {
  20. workspacePath: "/repo",
  21. workspaceIdentity: "ssh://host/repo",
  22. taskId: "task-1",
  23. updatedAt: 1,
  24. event: {
  25. type: "agent_message_chunk",
  26. taskId: "task-1",
  27. traceId: "trace-1",
  28. content: "hello",
  29. },
  30. },
  31. },
  32. tabs,
  33. );
  34. expect(stream?.event).toMatchObject({
  35. type: "agent_message_chunk",
  36. content: "hello",
  37. });
  38. });
  39. it("rejects stream events whose task id does not match the envelope", () => {
  40. const stream = resolveBotTaskStreamBroadcast(
  41. {
  42. channel: BOT_TASK_STREAM_BROADCAST_CHANNEL,
  43. payload: {
  44. workspacePath: "/repo",
  45. workspaceIdentity: "ssh://host/repo",
  46. taskId: "task-1",
  47. updatedAt: 1,
  48. event: {
  49. type: "agent_message_chunk",
  50. taskId: "other-task",
  51. traceId: "trace-1",
  52. content: "hello",
  53. },
  54. },
  55. },
  56. tabs,
  57. );
  58. expect(stream).toBeNull();
  59. });
  60. });