stream.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { describe, expect, test } from "bun:test"
  2. import { writeSessionOutput } from "@/cli/cmd/run/stream"
  3. import type { FooterApi, FooterEvent, StreamCommit } from "@/cli/cmd/run/types"
  4. function footer() {
  5. const events: FooterEvent[] = []
  6. const commits: StreamCommit[] = []
  7. const api: FooterApi = {
  8. isClosed: false,
  9. onPrompt: () => () => {},
  10. onQueuedRemove: () => () => {},
  11. onClose: () => () => {},
  12. event: (next) => {
  13. events.push(next)
  14. },
  15. append: (next) => {
  16. commits.push(next)
  17. },
  18. idle: () => Promise.resolve(),
  19. close: () => {},
  20. destroy: () => {},
  21. }
  22. return { api, events, commits }
  23. }
  24. describe("run stream bridge", () => {
  25. test("defaults status patches to running phase", () => {
  26. const out = footer()
  27. writeSessionOutput(
  28. {
  29. footer: out.api,
  30. },
  31. {
  32. commits: [],
  33. footer: {
  34. patch: {
  35. status: "assistant responding",
  36. },
  37. },
  38. },
  39. )
  40. expect(out.events).toEqual([
  41. {
  42. type: "stream.patch",
  43. patch: {
  44. phase: "running",
  45. status: "assistant responding",
  46. },
  47. },
  48. ])
  49. })
  50. })