@@ -842,14 +842,145 @@ it.effect("keeps the last OpenCode 2 model list while a fresh server's stays emp
842842 Effect . gen ( function * ( ) {
843843 let listed : ReadonlyArray < OpenCode2Model > = [ bigPickle ] ;
844844 const load = yield * makeOpenCode2ModelLoader ( Effect . sync ( ( ) => listed ) ) ;
845- NodeAssert . deepEqual ( yield * load , [ bigPickle ] ) ;
845+ const first = yield * load . pipe ( Effect . forkChild ) ;
846+ yield * TestClock . adjust ( "1 second" ) ;
847+ NodeAssert . deepEqual ( yield * Fiber . join ( first ) , [ bigPickle ] ) ;
846848 listed = [ ] ;
847849 const fiber = yield * load . pipe ( Effect . forkChild ) ;
848850 yield * TestClock . adjust ( "6 seconds" ) ;
849851 NodeAssert . deepEqual ( yield * Fiber . join ( fiber ) , [ bigPickle ] ) ;
850852 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
851853) ;
852854
855+ it . effect ( "waits for a growing OpenCode 2 catalog to settle before caching it" , ( ) =>
856+ Effect . gen ( function * ( ) {
857+ const first : OpenCode2Model = {
858+ providerID : "opencode" ,
859+ id : "first" ,
860+ name : "First" ,
861+ variants : [ ] ,
862+ } ;
863+ const second : OpenCode2Model = {
864+ providerID : "opencode" ,
865+ id : "second" ,
866+ name : "Second" ,
867+ variants : [ ] ,
868+ } ;
869+ const replies : Array < ReadonlyArray < OpenCode2Model > > = [
870+ [ first ] ,
871+ [ first , second ] ,
872+ [ first , second ] ,
873+ ] ;
874+ const load = yield * makeOpenCode2ModelLoader (
875+ Effect . sync ( ( ) => replies . shift ( ) ?? [ first , second ] ) ,
876+ ) ;
877+ const fiber = yield * load . pipe ( Effect . forkChild ) ;
878+ yield * TestClock . adjust ( "1 second" ) ;
879+ NodeAssert . ok ( fiber . pollUnsafe ( ) , "A settled catalog should finish before the load deadline" ) ;
880+ NodeAssert . deepEqual ( yield * Fiber . join ( fiber ) , [ first , second ] ) ;
881+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
882+ ) ;
883+
884+ it . effect ( "waits for OpenCode 2 model names, provider labels, and variants to settle" , ( ) =>
885+ Effect . gen ( function * ( ) {
886+ const renamed = { ...bigPickle , name : "Bigger Pickle" } ;
887+ const labeled = { ...renamed , providerName : "OpenCode Zen" } ;
888+ const withVariants = { ...labeled , variants : [ { id : "low" } ] } ;
889+ const complete = { ...labeled , variants : [ { id : "high" } , { id : "medium" } ] } ;
890+ const reordered = { ...complete , variants : [ { id : "medium" } , { id : "high" } ] } ;
891+ const replies = [ [ bigPickle ] , [ renamed ] , [ labeled ] , [ withVariants ] , [ complete ] , [ reordered ] ] ;
892+ const load = yield * makeOpenCode2ModelLoader ( Effect . sync ( ( ) => replies . shift ( ) ?? [ complete ] ) ) ;
893+ const fiber = yield * load . pipe ( Effect . forkChild ) ;
894+ yield * TestClock . adjust ( "1500 millis" ) ;
895+ NodeAssert . ok (
896+ fiber . pollUnsafe ( ) ,
897+ "Equivalent variant orders should settle before the deadline" ,
898+ ) ;
899+ NodeAssert . deepEqual ( yield * Fiber . join ( fiber ) , [ reordered ] ) ;
900+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
901+ ) ;
902+
903+ it . effect ( "bounds an unsettled OpenCode 2 catalog and keeps its latest nonempty observation" , ( ) =>
904+ Effect . gen ( function * ( ) {
905+ let reads = 0 ;
906+ let latest : ReadonlyArray < OpenCode2Model > = [ ] ;
907+ const changing = ( ) => {
908+ latest = [ { ...bigPickle , name : `Pickle ${ ++ reads } ` } ] ;
909+ return latest ;
910+ } ;
911+ let list = changing ;
912+ const load = yield * makeOpenCode2ModelLoader ( Effect . sync ( ( ) => list ( ) ) ) ;
913+ const cold = yield * load . pipe ( Effect . forkChild ) ;
914+ yield * TestClock . adjust ( "5 seconds" ) ;
915+ NodeAssert . ok ( cold . pollUnsafe ( ) ) ;
916+ NodeAssert . ok ( reads > 1 ) ;
917+ NodeAssert . deepEqual ( yield * Fiber . join ( cold ) , latest ) ;
918+
919+ list = ( ) => [ ] ;
920+ const empty = yield * load . pipe ( Effect . forkChild ) ;
921+ yield * TestClock . adjust ( "5 seconds" ) ;
922+ NodeAssert . ok ( empty . pollUnsafe ( ) ) ;
923+ NodeAssert . deepEqual ( yield * Fiber . join ( empty ) , latest ) ;
924+
925+ list = ( ) => [ bigPickle ] ;
926+ const settled = yield * load . pipe ( Effect . forkChild ) ;
927+ yield * TestClock . adjust ( "1 second" ) ;
928+ NodeAssert . deepEqual ( yield * Fiber . join ( settled ) , [ bigPickle ] ) ;
929+
930+ reads = 0 ;
931+ list = ( ) => ( reads ++ === 0 ? [ bigPickle ] : changing ( ) ) ;
932+ const fresh = yield * load . pipe ( Effect . forkChild ) ;
933+ yield * TestClock . adjust ( "5 seconds" ) ;
934+ NodeAssert . ok ( fresh . pollUnsafe ( ) ) ;
935+ NodeAssert . ok ( reads > 1 ) ;
936+ NodeAssert . deepEqual ( yield * Fiber . join ( fresh ) , latest ) ;
937+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
938+ ) ;
939+
940+ it . effect (
941+ "refreshes a warm OpenCode 2 catalog when slow reads cannot settle before the deadline" ,
942+ ( ) =>
943+ Effect . gen ( function * ( ) {
944+ let listed : ReadonlyArray < OpenCode2Model > = [ bigPickle ] ;
945+ let slow = false ;
946+ const load = yield * makeOpenCode2ModelLoader (
947+ Effect . gen ( function * ( ) {
948+ if ( slow ) yield * Effect . sleep ( "3 seconds" ) ;
949+ return listed ;
950+ } ) ,
951+ ) ;
952+ const warm = yield * load . pipe ( Effect . forkChild ) ;
953+ yield * TestClock . adjust ( "1 second" ) ;
954+ NodeAssert . deepEqual ( yield * Fiber . join ( warm ) , [ bigPickle ] ) ;
955+
956+ listed = [ { ...bigPickle , name : "Fresh Pickle" } ] ;
957+ slow = true ;
958+ const fresh = yield * load . pipe ( Effect . forkChild ) ;
959+ yield * TestClock . adjust ( "5 seconds" ) ;
960+ NodeAssert . ok ( fresh . pollUnsafe ( ) ) ;
961+ NodeAssert . deepEqual ( yield * Fiber . join ( fresh ) , listed ) ;
962+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
963+ ) ;
964+
965+ it . effect (
966+ "keeps a fresh OpenCode 2 observation if confirmation fails but propagates an initial failure" ,
967+ ( ) =>
968+ Effect . gen ( function * ( ) {
969+ const error = new OpenCodeRuntime . OpenCodeRuntimeError ( {
970+ operation : "model.list" ,
971+ detail : "Model list failed" ,
972+ } ) ;
973+ let reads = 0 ;
974+ const load = yield * makeOpenCode2ModelLoader (
975+ Effect . suspend ( ( ) => ( reads ++ === 0 ? Effect . succeed ( [ bigPickle ] ) : Effect . fail ( error ) ) ) ,
976+ ) ;
977+ const fresh = yield * load . pipe ( Effect . forkChild ) ;
978+ yield * TestClock . adjust ( "250 millis" ) ;
979+ NodeAssert . deepEqual ( yield * Fiber . join ( fresh ) , [ bigPickle ] ) ;
980+ NodeAssert . equal ( yield * load . pipe ( Effect . flip ) , error ) ;
981+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
982+ ) ;
983+
853984const builtinCommands = [
854985 { name : "init" , description : "guided AGENTS.md setup" } ,
855986 { name : "review" , description : "review changes [commit|branch|pr], defaults to uncommitted" } ,
0 commit comments