@@ -72,13 +72,17 @@ func TestNewRemoteRuntimeAdapterBranches(t *testing.T) {
7272 adapter , err := NewRemoteRuntimeAdapter (RemoteRuntimeAdapterOptions {
7373 ListenAddress : "ok" ,
7474 RequestTimeout : - 1 ,
75+ RetryCount : 0 ,
7576 })
7677 if err != nil {
7778 t .Fatalf ("NewRemoteRuntimeAdapter() error = %v" , err )
7879 }
7980 if adapter .timeout != defaultRemoteRuntimeTimeout {
8081 t .Fatalf ("timeout = %v, want %v" , adapter .timeout , defaultRemoteRuntimeTimeout )
8182 }
83+ if adapter .retryCount != defaultGatewayRPCRetryCount {
84+ t .Fatalf ("retryCount = %d, want %d" , adapter .retryCount , defaultGatewayRPCRetryCount )
85+ }
8286 _ = adapter .Close ()
8387}
8488
@@ -304,6 +308,62 @@ func TestRemoteRuntimeAdapterEventObservationAndActiveRunState(t *testing.T) {
304308 if runID != "" {
305309 t .Fatalf ("expected cleared run id, got %q" , runID )
306310 }
311+
312+ adapter .setActiveRun ("run-c" , "session-c" )
313+ adapter .observeEvent (agentruntime.RuntimeEvent {Type : agentruntime .EventError })
314+ runID , sessionID = adapter .activeRun ()
315+ if runID != "run-c" || sessionID != "session-c" {
316+ t .Fatalf ("event error without run id should not clear active run, got run=%q session=%q" , runID , sessionID )
317+ }
318+ }
319+
320+ func TestNewRemoteRuntimeAdapterWithClientsNormalizesRetryCount (t * testing.T ) {
321+ t .Parallel ()
322+
323+ adapter := newRemoteRuntimeAdapterWithClients (
324+ & stubRemoteRPCClient {notifications : make (chan gatewayRPCNotification )},
325+ & stubRemoteStreamClient {events : make (chan agentruntime.RuntimeEvent )},
326+ time .Second ,
327+ 0 ,
328+ )
329+ t .Cleanup (func () { _ = adapter .Close () })
330+
331+ if adapter .retryCount != defaultGatewayRPCRetryCount {
332+ t .Fatalf ("retryCount = %d, want %d" , adapter .retryCount , defaultGatewayRPCRetryCount )
333+ }
334+ }
335+
336+ func TestRemoteRuntimeAdapterUsesDefaultRetryWhenOptionsZero (t * testing.T ) {
337+ t .Parallel ()
338+
339+ rpcClient := & stubRemoteRPCClient {
340+ frames : map [string ]gateway.MessageFrame {
341+ protocol .MethodGatewayListSessions : {
342+ Type : gateway .FrameTypeAck ,
343+ Action : gateway .FrameActionListSessions ,
344+ Payload : map [string ]any {"sessions" : []gateway.SessionSummary {}},
345+ },
346+ },
347+ notifications : make (chan gatewayRPCNotification ),
348+ }
349+ adapter := newRemoteRuntimeAdapterWithClients (
350+ rpcClient ,
351+ & stubRemoteStreamClient {events : make (chan agentruntime.RuntimeEvent )},
352+ time .Second ,
353+ 0 ,
354+ )
355+ t .Cleanup (func () { _ = adapter .Close () })
356+
357+ if _ , err := adapter .ListSessions (context .Background ()); err != nil {
358+ t .Fatalf ("ListSessions() error = %v" , err )
359+ }
360+ options , ok := rpcClient .snapshotOptions ()[protocol .MethodGatewayListSessions ]
361+ if ! ok {
362+ t .Fatalf ("expected listSessions call options to be captured" )
363+ }
364+ if options .Retries != defaultGatewayRPCRetryCount {
365+ t .Fatalf ("listSessions retries = %d, want %d" , options .Retries , defaultGatewayRPCRetryCount )
366+ }
307367}
308368
309369func TestRemoteRuntimeAdapterLoadSessionAndCancelErrorPaths (t * testing.T ) {
@@ -347,9 +407,13 @@ func TestRemoteRuntimeAdapterSubmitAndCompactErrorPaths(t *testing.T) {
347407 if err := adapter .Submit (context .Background (), agentruntime.PrepareInput {}); err == nil || ! strings .Contains (err .Error (), "bind failed" ) {
348408 t .Fatalf ("expected bind failed submit error, got %v" , err )
349409 }
350- params := rpcClient .snapshotParams ()[protocol .MethodGatewayLoadSession ].(protocol.LoadSessionParams )
351- if strings .TrimSpace (params .SessionID ) == "" {
352- t .Fatalf ("Submit() should generate default session id" )
410+ methods := rpcClient .snapshotMethods ()
411+ if len (methods ) != 1 || methods [0 ] != protocol .MethodGatewayBindStream {
412+ t .Fatalf ("Submit() should fail after bindStream and before loadSession, methods=%#v" , methods )
413+ }
414+ bindParams , ok := rpcClient .snapshotParams ()[protocol .MethodGatewayBindStream ].(protocol.BindStreamParams )
415+ if ! ok || strings .TrimSpace (bindParams .SessionID ) == "" {
416+ t .Fatalf ("Submit() should generate default session id for bindStream, params=%#v" , rpcClient .snapshotParams ()[protocol .MethodGatewayBindStream ])
353417 }
354418
355419 rpcClient .authErr = errors .New ("auth failed" )
0 commit comments