@@ -823,24 +823,17 @@ func TestExpMcpReporter(t *testing.T) {
823
823
// Watch the workspace for changes.
824
824
watcher , err := client .WatchWorkspace (ctx , r .Workspace .ID )
825
825
require .NoError (t , err )
826
- var lastAppStatus codersdk.WorkspaceAppStatusState
827
- wait := func (state codersdk.WorkspaceAppStatusState ) {
826
+ var lastAppStatus codersdk.WorkspaceAppStatus
827
+ nextUpdate := func () codersdk.WorkspaceAppStatus {
828
828
for {
829
829
select {
830
830
case <- ctx .Done ():
831
- require .FailNow (t , "timed out waiting for state" , state )
831
+ require .FailNow (t , "timed out waiting for status update" )
832
832
case w , ok := <- watcher :
833
- require .True (t , ok , "watch channel closed: %s" , state )
834
- var nextAppStatus codersdk.WorkspaceAppStatusState
835
- if w .LatestAppStatus != nil {
836
- nextAppStatus = w .LatestAppStatus .State
837
- }
838
- if nextAppStatus == state {
839
- lastAppStatus = nextAppStatus
840
- return
841
- }
842
- if nextAppStatus != lastAppStatus {
843
- require .FailNow (t , "unexpected status change" , nextAppStatus )
833
+ require .True (t , ok , "watch channel closed" )
834
+ if w .LatestAppStatus != nil && w .LatestAppStatus .ID != lastAppStatus .ID {
835
+ lastAppStatus = * w .LatestAppStatus
836
+ return lastAppStatus
844
837
}
845
838
}
846
839
}
@@ -882,22 +875,32 @@ func TestExpMcpReporter(t *testing.T) {
882
875
tests := []struct {
883
876
// event simulates an event from the screen watcher.
884
877
event * codersdk.ServerSentEvent
885
- // state and summary simulate a tool call from the LLM.
878
+ // state, summary, and uri simulate a tool call from the LLM.
886
879
state codersdk.WorkspaceAppStatusState
887
880
summary string
888
- expected codersdk.WorkspaceAppStatusState
881
+ uri string
882
+ expected * codersdk.WorkspaceAppStatus
889
883
}{
890
884
// First the LLM updates with a state change.
891
885
{
892
- state : codersdk .WorkspaceAppStatusStateWorking ,
893
- summary : "doing work" ,
894
- expected : codersdk .WorkspaceAppStatusStateWorking ,
886
+ state : codersdk .WorkspaceAppStatusStateWorking ,
887
+ summary : "doing work" ,
888
+ uri : "https://dev.coder.com" ,
889
+ expected : & codersdk.WorkspaceAppStatus {
890
+ State : codersdk .WorkspaceAppStatusStateWorking ,
891
+ Message : "doing work" ,
892
+ URI : "https://dev.coder.com" ,
893
+ },
895
894
},
896
895
// Terminal goes quiet but the LLM forgot the update, and it is caught by
897
- // the screen watcher.
896
+ // the screen watcher. Message and URI are preserved.
898
897
{
899
- event : makeStatusEvent (agentapi .StatusStable ),
900
- expected : codersdk .WorkspaceAppStatusStateComplete ,
898
+ event : makeStatusEvent (agentapi .StatusStable ),
899
+ expected : & codersdk.WorkspaceAppStatus {
900
+ State : codersdk .WorkspaceAppStatusStateComplete ,
901
+ Message : "doing work" ,
902
+ URI : "https://dev.coder.com" ,
903
+ },
901
904
},
902
905
// Terminal becomes active again according to the screen watcher, but
903
906
// message length is the same. This could be the LLM being active again,
@@ -906,11 +909,15 @@ func TestExpMcpReporter(t *testing.T) {
906
909
{
907
910
event : makeStatusEvent (agentapi .StatusRunning ),
908
911
},
909
- // LLM reports that it failed.
912
+ // LLM reports that it failed and URI is blank .
910
913
{
911
- state : codersdk .WorkspaceAppStatusStateFailure ,
912
- summary : "oops" ,
913
- expected : codersdk .WorkspaceAppStatusStateFailure ,
914
+ state : codersdk .WorkspaceAppStatusStateFailure ,
915
+ summary : "oops" ,
916
+ expected : & codersdk.WorkspaceAppStatus {
917
+ State : codersdk .WorkspaceAppStatusStateFailure ,
918
+ Message : "oops" ,
919
+ URI : "" ,
920
+ },
914
921
},
915
922
// The watcher reports the screen is active again...
916
923
{
@@ -919,13 +926,21 @@ func TestExpMcpReporter(t *testing.T) {
919
926
// ... but this time the message length has increased so we know there is
920
927
// LLM activity. This time the "working" update will not be skipped.
921
928
{
922
- event : makeMessageEvent (1 ),
923
- expected : codersdk .WorkspaceAppStatusStateWorking ,
929
+ event : makeMessageEvent (1 ),
930
+ expected : & codersdk.WorkspaceAppStatus {
931
+ State : codersdk .WorkspaceAppStatusStateWorking ,
932
+ Message : "oops" ,
933
+ URI : "" ,
934
+ },
924
935
},
925
936
// Watcher reports stable again.
926
937
{
927
- event : makeStatusEvent (agentapi .StatusStable ),
928
- expected : codersdk .WorkspaceAppStatusStateComplete ,
938
+ event : makeStatusEvent (agentapi .StatusStable ),
939
+ expected : & codersdk.WorkspaceAppStatus {
940
+ State : codersdk .WorkspaceAppStatusStateComplete ,
941
+ Message : "oops" ,
942
+ URI : "" ,
943
+ },
929
944
},
930
945
}
931
946
for _ , test := range tests {
@@ -934,7 +949,7 @@ func TestExpMcpReporter(t *testing.T) {
934
949
require .NoError (t , err )
935
950
} else {
936
951
// Call the tool and ensure it works.
937
- payload := fmt .Sprintf (`{"jsonrpc":"2.0","id":3,"method":"tools/call", "params": {"name": "coder_report_task", "arguments": {"state": %q, "summary": %q}}}` , test .state , test .summary )
952
+ payload := fmt .Sprintf (`{"jsonrpc":"2.0","id":3,"method":"tools/call", "params": {"name": "coder_report_task", "arguments": {"state": %q, "summary": %q, "link": %q }}}` , test .state , test .summary , test . uri )
938
953
pty .WriteLine (payload )
939
954
_ = pty .ReadLine (ctx ) // ignore echo
940
955
output := pty .ReadLine (ctx )
@@ -943,8 +958,11 @@ func TestExpMcpReporter(t *testing.T) {
943
958
_ , err = json .Marshal (output )
944
959
require .NoError (t , err , "did not receive valid JSON from coder_report_task" )
945
960
}
946
- if test .expected != "" {
947
- wait (test .expected )
961
+ if test .expected != nil {
962
+ got := nextUpdate ()
963
+ require .Equal (t , got .State , test .expected .State )
964
+ require .Equal (t , got .Message , test .expected .Message )
965
+ require .Equal (t , got .URI , test .expected .URI )
948
966
}
949
967
}
950
968
cancel ()
0 commit comments