| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- import { describe, expect, test } from "bun:test"
- import { writeSessionOutput } from "@/cli/cmd/run/stream"
- import type { FooterApi, FooterEvent, StreamCommit } from "@/cli/cmd/run/types"
- function footer() {
- const events: FooterEvent[] = []
- const commits: StreamCommit[] = []
- const api: FooterApi = {
- isClosed: false,
- onPrompt: () => () => {},
- onClose: () => () => {},
- event: (next) => {
- events.push(next)
- },
- append: (next) => {
- commits.push(next)
- },
- idle: () => Promise.resolve(),
- close: () => {},
- destroy: () => {},
- }
- return { api, events, commits }
- }
- describe("run stream bridge", () => {
- test("forwards commits in order", () => {
- const out = footer()
- const commits: StreamCommit[] = [
- { kind: "assistant", text: "one", phase: "progress", source: "assistant", partID: "a" },
- { kind: "tool", text: "two", phase: "final", source: "tool", partID: "b", tool: "bash" },
- ]
- writeSessionOutput(
- {
- footer: out.api,
- },
- {
- commits,
- },
- )
- expect(out.commits).toEqual(commits)
- })
- test("defaults status patches to running phase", () => {
- const out = footer()
- writeSessionOutput(
- {
- footer: out.api,
- },
- {
- commits: [],
- footer: {
- patch: {
- status: "assistant responding",
- },
- },
- },
- )
- expect(out.events).toEqual([
- {
- type: "stream.patch",
- patch: {
- phase: "running",
- status: "assistant responding",
- },
- },
- ])
- })
- test("forwards footer view updates as stream.view events", () => {
- const out = footer()
- writeSessionOutput(
- {
- footer: out.api,
- },
- {
- commits: [],
- footer: {
- view: {
- type: "prompt",
- },
- },
- },
- )
- expect(out.events).toEqual([
- {
- type: "stream.view",
- view: {
- type: "prompt",
- },
- },
- ])
- })
- test("forwards subagent footer snapshots as stream.subagent events", () => {
- const out = footer()
- writeSessionOutput(
- {
- footer: out.api,
- },
- {
- commits: [],
- footer: {
- subagent: {
- tabs: [
- {
- sessionID: "child-1",
- partID: "part-1",
- callID: "call-1",
- label: "Explore",
- description: "Scan reducer paths",
- status: "running",
- lastUpdatedAt: 1,
- },
- ],
- details: {
- "child-1": {
- sessionID: "child-1",
- commits: [],
- },
- },
- permissions: [],
- questions: [],
- },
- },
- },
- )
- expect(out.events).toEqual([
- {
- type: "stream.subagent",
- state: {
- tabs: [
- {
- sessionID: "child-1",
- partID: "part-1",
- callID: "call-1",
- label: "Explore",
- description: "Scan reducer paths",
- status: "running",
- lastUpdatedAt: 1,
- },
- ],
- details: {
- "child-1": {
- sessionID: "child-1",
- commits: [],
- },
- },
- permissions: [],
- questions: [],
- },
- },
- ])
- })
- })
|