@@ -200,16 +200,24 @@ func TestCancelIntentBlocksConcurrentStartAndCompletion(t *testing.T) {
200200
201201func TestGuestFileFailedCommandEventReconcilesDurableOperation (t * testing.T ) {
202202 s := guestExecutionTestServer (t )
203- op := controlplane.GuestFileOperation {ID : "op" , Version : 1 , AgentID : "host-a" , CommandID : "cmd" , Status : controlplane .GuestExecutionRunning }
204- require .NoError (t , s .apiStore .SaveGuestFileOperation (context .Background (), op ))
205- _ , err := s .agentService ().PublishCommand (context .Background (), "host-a" , controlplane.AgentCommand {ID : "cmd" , Type : "guest_file_put" , FilePut : & controlplane.GuestFilePut {ID : "op" }})
203+
204+ // A completed command leaves the durable operation running.
205+ done := controlplane.GuestFileOperation {ID : "op-done" , Version : 1 , AgentID : "host-a" , CommandID : "cmd-done" , Status : controlplane .GuestExecutionRunning }
206+ require .NoError (t , s .apiStore .SaveGuestFileOperation (context .Background (), done ))
207+ _ , err := s .agentService ().PublishCommand (context .Background (), "host-a" , controlplane.AgentCommand {ID : "cmd-done" , Type : "guest_file_put" , FilePut : & controlplane.GuestFilePut {ID : "op-done" }})
206208 require .NoError (t , err )
207- s .agentService ().RecordCommandEvent (context .Background (), controlplane.AgentCommandEvent {CommandID : "cmd" , AgentID : "host-a" , Status : controlplane .AgentCommandStatusCompleted })
208- got , err := s .apiStore .GetGuestFileOperation (context .Background (), "op" )
209+ s .agentService ().RecordCommandEvent (context .Background (), controlplane.AgentCommandEvent {CommandID : "cmd-done " , AgentID : "host-a" , Status : controlplane .AgentCommandStatusCompleted })
210+ got , err := s .apiStore .GetGuestFileOperation (context .Background (), "op-done " )
209211 require .NoError (t , err )
210212 require .Equal (t , controlplane .GuestExecutionRunning , got .Status )
211- s .agentService ().RecordCommandEvent (context .Background (), controlplane.AgentCommandEvent {CommandID : "cmd" , AgentID : "host-a" , Status : controlplane .AgentCommandStatusFailed })
212- got , err = s .apiStore .GetGuestFileOperation (context .Background (), "op" )
213+
214+ // A failed command reconciles the durable operation to failed.
215+ failed := controlplane.GuestFileOperation {ID : "op-failed" , Version : 1 , AgentID : "host-a" , CommandID : "cmd-failed" , Status : controlplane .GuestExecutionRunning }
216+ require .NoError (t , s .apiStore .SaveGuestFileOperation (context .Background (), failed ))
217+ _ , err = s .agentService ().PublishCommand (context .Background (), "host-a" , controlplane.AgentCommand {ID : "cmd-failed" , Type : "guest_file_put" , FilePut : & controlplane.GuestFilePut {ID : "op-failed" }})
218+ require .NoError (t , err )
219+ s .agentService ().RecordCommandEvent (context .Background (), controlplane.AgentCommandEvent {CommandID : "cmd-failed" , AgentID : "host-a" , Status : controlplane .AgentCommandStatusFailed })
220+ got , err = s .apiStore .GetGuestFileOperation (context .Background (), "op-failed" )
213221 require .NoError (t , err )
214222 require .Equal (t , controlplane .GuestExecutionFailed , got .Status )
215223}
0 commit comments