footer.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { expect, test } from "bun:test"
  2. import { coalesceProgressCommit, resolveRunAgent } from "../../src/mini/footer"
  3. import type { RunAgent, StreamCommit } from "../../src/mini/types"
  4. function progress(input: Partial<StreamCommit> = {}): StreamCommit {
  5. return {
  6. kind: "tool",
  7. source: "tool",
  8. phase: "progress",
  9. text: "one",
  10. messageID: "msg_1",
  11. partID: "part_1",
  12. tool: "shell",
  13. toolState: "running",
  14. ...input,
  15. }
  16. }
  17. test("coalesces progress only within the same message and tool state", () => {
  18. expect(coalesceProgressCommit(progress(), progress({ messageID: "msg_2" }))).toBeUndefined()
  19. expect(coalesceProgressCommit(progress(), progress({ toolState: "completed" }))).toBeUndefined()
  20. expect(coalesceProgressCommit(progress(), progress({ text: "two", directory: "/latest" }))).toEqual(
  21. progress({ text: "onetwo", directory: "/latest" }),
  22. )
  23. })
  24. test("falls back only when no agent is selected", () => {
  25. const agents: RunAgent[] = [
  26. { id: "task", name: "Task", mode: "subagent", hidden: false },
  27. { id: "secret", name: "Secret", mode: "primary", hidden: true },
  28. { id: "build", name: "Build", mode: "primary", hidden: false },
  29. { id: "plan", name: "Plan", mode: "primary", hidden: false },
  30. ]
  31. expect(resolveRunAgent(agents, undefined)?.id).toBe("build")
  32. expect(resolveRunAgent(agents, "plan")?.id).toBe("plan")
  33. expect(resolveRunAgent(agents, "missing")).toBeUndefined()
  34. })