@@ -5791,23 +5791,27 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
57915791 } ) ,
57925792 ) ;
57935793
5794- it . effect ( "maps native task updates and command results to client progress " , ( ) =>
5794+ it . effect ( "maps native task progress only while a turn is active " , ( ) =>
57955795 Effect . gen ( function * ( ) {
57965796 const adapter = yield * OpenCodeAdapter ;
57975797 const threadId = asThreadId ( "thread-native-progress" ) ;
57985798 const sessionID = "http://127.0.0.1:9999/session" ;
5799+ const startProgress = promiseWithResolvers < OpenCodeEvent > ( ) ;
5800+ const finishTurn = promiseWithResolvers < OpenCodeEvent > ( ) ;
5801+ const lateProgress = promiseWithResolvers < OpenCodeEvent > ( ) ;
57995802 const todos = [
58005803 { content : "Read files" , status : "completed" , priority : "high" } ,
58015804 { content : "Fix OpenCode" , status : "in_progress" , priority : "high" } ,
58025805 { content : "Run tests" , status : "pending" , priority : "medium" } ,
58035806 { content : "Old task" , status : "cancelled" , priority : "low" } ,
58045807 ] ;
5808+ const todoEvent = {
5809+ id : "evt-todos" ,
5810+ type : "todo.updated" ,
5811+ properties : { sessionID, todos } ,
5812+ } satisfies OpenCodeEvent ;
58055813 runtimeMock . state . subscribedEvents = [
5806- {
5807- id : "evt-todos" ,
5808- type : "todo.updated" ,
5809- properties : { sessionID, todos } ,
5810- } satisfies OpenCodeEvent ,
5814+ startProgress . promise ,
58115815 ...[ "todowrite" , "bash" ] . map (
58125816 ( tool ) =>
58135817 ( {
@@ -5835,6 +5839,9 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
58355839 } ,
58365840 } ) satisfies OpenCodeEvent ,
58375841 ) ,
5842+ finishTurn . promise ,
5843+ lateProgress . promise ,
5844+ { id : "evt-progress-drained" , type : "session.compacted" , properties : { sessionID } } ,
58385845 ] ;
58395846 const eventsFiber = yield * adapter . streamEvents . pipe (
58405847 Stream . filter (
@@ -5851,8 +5858,18 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
58515858 threadId,
58525859 runtimeMode : "full-access" ,
58535860 } ) ;
5861+ const turn = yield * adapter . sendTurn ( {
5862+ threadId,
5863+ input : "Work through the task list" ,
5864+ modelSelection : createModelSelection (
5865+ ProviderInstanceId . make ( "opencode" ) ,
5866+ "opencode/kimi-k3" ,
5867+ ) ,
5868+ } ) ;
5869+ startProgress . resolve ( todoEvent ) ;
58545870 const events = yield * Fiber . join ( eventsFiber ) ;
58555871 const plan = events . find ( ( event ) => event . type === "turn.plan.updated" ) ;
5872+ NodeAssert . equal ( plan ?. turnId , turn . turnId ) ;
58565873 NodeAssert . deepEqual ( plan ?. payload . plan , [
58575874 { step : "Read files" , status : "completed" } ,
58585875 { step : "Fix OpenCode" , status : "inProgress" } ,
@@ -5865,6 +5882,28 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
58655882 command : "pwd" ,
58665883 result : "/repo\n" ,
58675884 } ) ;
5885+ const completedFiber = yield * adapter . streamEvents . pipe (
5886+ Stream . filter ( ( event ) => event . threadId === threadId && event . type === "turn.completed" ) ,
5887+ Stream . runHead ,
5888+ Effect . forkChild ,
5889+ ) ;
5890+ finishTurn . resolve ( {
5891+ id : "evt-progress-completed" ,
5892+ type : "session.status" ,
5893+ properties : { sessionID, status : { type : "idle" } } ,
5894+ } ) ;
5895+ yield * Fiber . join ( completedFiber ) ;
5896+ const lateEventsFiber = yield * adapter . streamEvents . pipe (
5897+ Stream . filter ( ( event ) => event . threadId === threadId ) ,
5898+ Stream . takeUntil ( ( event ) => event . type === "thread.state.changed" ) ,
5899+ Stream . runCollect ,
5900+ Effect . forkChild ,
5901+ ) ;
5902+ lateProgress . resolve ( { ...todoEvent , id : "evt-late-todos" } ) ;
5903+ NodeAssert . deepEqual (
5904+ ( yield * Fiber . join ( lateEventsFiber ) ) . map ( ( event ) => event . type ) ,
5905+ [ "thread.state.changed" ] ,
5906+ ) ;
58685907 yield * adapter . stopSession ( threadId ) ;
58695908 } ) ,
58705909 ) ;
0 commit comments