11import { describe , expect , test } from "bun:test"
2- import type { JsonValue , SessionMessageAssistant , SessionMessageAssistantTool , SessionMessageInfo } from "@opencode/client/promise"
2+ import type {
3+ JsonValue ,
4+ SessionMessageAssistant ,
5+ SessionMessageAssistantTool ,
6+ SessionMessageInfo ,
7+ } from "@opencode/client/promise"
38import {
49 childHref ,
510 childrenOf ,
@@ -58,14 +63,14 @@ describe("taskStatus", () => {
5863 expect ( taskStatus ( tool ( { status : "streaming" , input : "..." } ) ) ) . toBe ( "running" )
5964 } )
6065 test ( "completed parts are completed" , ( ) => {
61- expect (
62- taskStatus ( tool ( { status : "completed" , input : { } , content : [ { type : "text" , text : "done" } ] } ) ) ,
63- ) . toBe ( "completed" )
66+ expect ( taskStatus ( tool ( { status : "completed" , input : { } , content : [ { type : "text" , text : "done" } ] } ) ) ) . toBe (
67+ "completed" ,
68+ )
6469 } )
6570 test ( "aborted errors are cancelled" , ( ) => {
66- expect (
67- taskStatus ( tool ( { status : "error" , input : { } , error : { type : "aborted" , message : "stopped" } } ) ) ,
68- ) . toBe ( "cancelled" )
71+ expect ( taskStatus ( tool ( { status : "error" , input : { } , error : { type : "aborted" , message : "stopped" } } ) ) ) . toBe (
72+ "cancelled" ,
73+ )
6974 } )
7075 test ( "interrupted metadata is cancelled" , ( ) => {
7176 expect (
@@ -88,12 +93,17 @@ describe("partBackgrounded", () => {
8893 test ( "completed parts with a running metadata status are backgrounded" , ( ) => {
8994 expect (
9095 partBackgrounded (
91- tool ( { status : "completed" , input : { } , content : [ { type : "text" , text : "x" } ] , metadata : { status : "running" } } ) ,
96+ tool ( {
97+ status : "completed" ,
98+ input : { } ,
99+ content : [ { type : "text" , text : "x" } ] ,
100+ metadata : { status : "running" } ,
101+ } ) ,
92102 ) ,
93103 ) . toBe ( true )
94- expect (
95- partBackgrounded ( tool ( { status : "completed" , input : { } , content : [ { type : "text" , text : "x" } ] } ) ) ,
96- ) . toBe ( false )
104+ expect ( partBackgrounded ( tool ( { status : "completed" , input : { } , content : [ { type : "text" , text : "x" } ] } ) ) ) . toBe (
105+ false ,
106+ )
97107 expect ( partBackgrounded ( tool ( { status : "running" , input : { } , metadata : { } } ) ) ) . toBe ( false )
98108 } )
99109} )
@@ -159,7 +169,14 @@ describe("subagentTasks", () => {
159169 { id : "a" } ,
160170 )
161171
162- const notice = { id : "n1" , type : "synthetic" , metadata : { source : "subagent" , childID : "child" } , text : "" , time : { created : 2 } } as const
172+ const notice = {
173+ id : "n1" ,
174+ type : "synthetic" ,
175+ metadata : { source : "subagent" , childID : "child" } ,
176+ text : "" ,
177+ time : { created : 2 } ,
178+ } as const
179+
163180 expect ( subagentTasks ( [ completedMessage ( [ backgrounded ] ) ] ) . parts . has ( "child" ) ) . toBe ( true )
164181 expect ( subagentTasks ( [ completedMessage ( [ backgrounded ] ) , notice ] ) . parts . has ( "child" ) ) . toBe ( false )
165182 } )
@@ -193,16 +210,26 @@ describe("deriveStatus", () => {
193210 expect ( deriveStatus ( { part : "completed" , backgrounded : true , running : false , outcome : undefined } ) ) . toBe ( "busy" )
194211 } )
195212 test ( "the outcome settles everything else" , ( ) => {
196- expect ( deriveStatus ( { part : "completed" , backgrounded : true , running : false , outcome : "succeeded" } ) ) . toBe ( "completed" )
213+ expect ( deriveStatus ( { part : "completed" , backgrounded : true , running : false , outcome : "succeeded" } ) ) . toBe (
214+ "completed" ,
215+ )
197216 expect ( deriveStatus ( { part : "completed" , backgrounded : false , running : false , outcome : "failed" } ) ) . toBe ( "error" )
198217 expect ( deriveStatus ( { part : undefined , running : true , outcome : undefined , backgrounded : false } ) ) . toBe ( "busy" )
199- expect ( deriveStatus ( { part : "cancelled" , backgrounded : false , running : false , outcome : "succeeded" } ) ) . toBe ( "completed" )
218+ expect ( deriveStatus ( { part : "cancelled" , backgrounded : false , running : false , outcome : "succeeded" } ) ) . toBe (
219+ "completed" ,
220+ )
200221 } )
201222 test ( "terminal parts and outcomes fall through in order" , ( ) => {
202- expect ( deriveStatus ( { part : "completed" , backgrounded : false , running : false , outcome : undefined } ) ) . toBe ( "completed" )
203- expect ( deriveStatus ( { part : undefined , running : false , outcome : "interrupted" , backgrounded : false } ) ) . toBe ( "cancelled" )
223+ expect ( deriveStatus ( { part : "completed" , backgrounded : false , running : false , outcome : undefined } ) ) . toBe (
224+ "completed" ,
225+ )
226+ expect ( deriveStatus ( { part : undefined , running : false , outcome : "interrupted" , backgrounded : false } ) ) . toBe (
227+ "cancelled" ,
228+ )
204229 expect ( deriveStatus ( { part : undefined , running : false , outcome : "failed" , backgrounded : false } ) ) . toBe ( "error" )
205- expect ( deriveStatus ( { part : undefined , running : false , outcome : "succeeded" , backgrounded : false } ) ) . toBe ( "completed" )
230+ expect ( deriveStatus ( { part : undefined , running : false , outcome : "succeeded" , backgrounded : false } ) ) . toBe (
231+ "completed" ,
232+ )
206233 expect ( deriveStatus ( { part : undefined , running : false , outcome : undefined , backgrounded : false } ) ) . toBe ( "idle" )
207234 } )
208235} )
@@ -254,9 +281,27 @@ describe("formatting", () => {
254281
255282describe ( "sortAgents" , ( ) => {
256283 const sessions = [
257- { id : "a" , cost : 3 , tokens : { input : 1 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } , title : "Zulu" , time : { created : 1000 } } ,
258- { id : "b" , cost : 1 , tokens : { input : 9 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } , title : "Alpha" , time : { created : 3000 } } ,
259- { id : "c" , cost : 2 , tokens : { input : 5 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } , title : "Mike" , time : { created : 2000 } } ,
284+ {
285+ id : "a" ,
286+ cost : 3 ,
287+ tokens : { input : 1 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
288+ title : "Zulu" ,
289+ time : { created : 1000 } ,
290+ } ,
291+ {
292+ id : "b" ,
293+ cost : 1 ,
294+ tokens : { input : 9 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
295+ title : "Alpha" ,
296+ time : { created : 3000 } ,
297+ } ,
298+ {
299+ id : "c" ,
300+ cost : 2 ,
301+ tokens : { input : 5 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
302+ title : "Mike" ,
303+ time : { created : 2000 } ,
304+ } ,
260305 ]
261306
262307 const name = ( id : string ) => sessions . find ( ( session ) => session . id === id ) ?. title ?? id
@@ -294,7 +339,14 @@ describe("sortAgents", () => {
294339
295340describe ( "filterAgents" , ( ) => {
296341 const sessions = [
297- { id : "abc" , cost : 0 , tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } , title : "Explore auth" , time : { created : 1 } , model : { id : "m1" , providerID : "test" } } ,
342+ {
343+ id : "abc" ,
344+ cost : 0 ,
345+ tokens : { input : 0 , output : 0 , reasoning : 0 , cache : { read : 0 , write : 0 } } ,
346+ title : "Explore auth" ,
347+ time : { created : 1 } ,
348+ model : { id : "m1" , providerID : "test" } ,
349+ } ,
298350 ]
299351
300352 test ( "matches titles, models and ids case-insensitively" , ( ) => {
@@ -321,22 +373,24 @@ describe("clocks", () => {
321373} )
322374
323375describe ( "transcript detail" , ( ) => {
324- const activityPart = ( id : string , name : string , input : { [ x : string ] : JsonValue } , at : number ) => ( {
325- type : "tool" ,
326- id,
327- name,
328- state : { status : "completed" , input, content : [ { type : "text" , text : "x" } ] } ,
329- time : { created : at , completed : at } ,
330- } ) satisfies SessionMessageAssistantTool
376+ const activityPart = ( id : string , name : string , input : { [ x : string ] : JsonValue } , at : number ) =>
377+ ( {
378+ type : "tool" ,
379+ id,
380+ name,
381+ state : { status : "completed" , input, content : [ { type : "text" , text : "x" } ] } ,
382+ time : { created : at , completed : at } ,
383+ } ) satisfies SessionMessageAssistantTool
331384
332- const assistantMessage = ( id : string , content : SessionMessageAssistant [ "content" ] , at : number , done : boolean ) => ( {
333- id,
334- type : "assistant" ,
335- agent : "build" ,
336- model : { id : "m" , providerID : "p" } ,
337- content,
338- time : done ? { created : at , completed : at + 500 } : { created : at } ,
339- } ) satisfies SessionMessageInfo
385+ const assistantMessage = ( id : string , content : SessionMessageAssistant [ "content" ] , at : number , done : boolean ) =>
386+ ( {
387+ id,
388+ type : "assistant" ,
389+ agent : "build" ,
390+ model : { id : "m" , providerID : "p" } ,
391+ content,
392+ time : done ? { created : at , completed : at + 500 } : { created : at } ,
393+ } ) satisfies SessionMessageInfo
340394
341395 test ( "latest activity walks newest tool calls first" , ( ) => {
342396 const messages = [
0 commit comments