stream.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { describe, expect, test } from "bun:test"
  2. import { writeSessionOutput } from "../../src/mini/stream"
  3. import { createFooterApiFixture } from "./fixture/footer-api"
  4. describe("run stream bridge", () => {
  5. test("defaults status patches to running phase", () => {
  6. const out = createFooterApiFixture()
  7. writeSessionOutput(
  8. {
  9. footer: out.api,
  10. },
  11. {
  12. commits: [],
  13. updates: [{ type: "stream.patch", patch: { status: "assistant responding" } }],
  14. },
  15. )
  16. expect(out.events).toEqual([
  17. {
  18. type: "stream.patch",
  19. patch: {
  20. phase: "running",
  21. status: "assistant responding",
  22. },
  23. },
  24. ])
  25. })
  26. test("delivers commits before ordered footer updates", () => {
  27. const out = createFooterApiFixture()
  28. writeSessionOutput(
  29. { footer: out.api },
  30. {
  31. commits: [{ kind: "assistant", source: "assistant", text: "answer", phase: "progress" }],
  32. updates: [
  33. { type: "stream.patch", patch: { phase: "idle", status: "" } },
  34. { type: "stream.subagent", state: { tabs: [], details: {}, permissions: [], forms: [] } },
  35. { type: "stream.view", view: { type: "prompt" } },
  36. ],
  37. },
  38. )
  39. expect(out.calls.map((call) => (call.type === "commit" ? "commit" : call.value.type))).toEqual([
  40. "commit",
  41. "stream.patch",
  42. "stream.subagent",
  43. "stream.view",
  44. ])
  45. })
  46. })