Skip to content

Commit e25eba7

Browse files
committed
Test summary and link
1 parent 46b1984 commit e25eba7

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

cli/exp_mcp_test.go

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -823,24 +823,17 @@ func TestExpMcpReporter(t *testing.T) {
823823
// Watch the workspace for changes.
824824
watcher, err := client.WatchWorkspace(ctx, r.Workspace.ID)
825825
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 {
828828
for {
829829
select {
830830
case <-ctx.Done():
831-
require.FailNow(t, "timed out waiting for state", state)
831+
require.FailNow(t, "timed out waiting for status update")
832832
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
844837
}
845838
}
846839
}
@@ -882,22 +875,32 @@ func TestExpMcpReporter(t *testing.T) {
882875
tests := []struct {
883876
// event simulates an event from the screen watcher.
884877
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.
886879
state codersdk.WorkspaceAppStatusState
887880
summary string
888-
expected codersdk.WorkspaceAppStatusState
881+
uri string
882+
expected *codersdk.WorkspaceAppStatus
889883
}{
890884
// First the LLM updates with a state change.
891885
{
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+
},
895894
},
896895
// 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.
898897
{
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+
},
901904
},
902905
// Terminal becomes active again according to the screen watcher, but
903906
// message length is the same. This could be the LLM being active again,
@@ -906,11 +909,15 @@ func TestExpMcpReporter(t *testing.T) {
906909
{
907910
event: makeStatusEvent(agentapi.StatusRunning),
908911
},
909-
// LLM reports that it failed.
912+
// LLM reports that it failed and URI is blank.
910913
{
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+
},
914921
},
915922
// The watcher reports the screen is active again...
916923
{
@@ -919,13 +926,21 @@ func TestExpMcpReporter(t *testing.T) {
919926
// ... but this time the message length has increased so we know there is
920927
// LLM activity. This time the "working" update will not be skipped.
921928
{
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+
},
924935
},
925936
// Watcher reports stable again.
926937
{
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+
},
929944
},
930945
}
931946
for _, test := range tests {
@@ -934,7 +949,7 @@ func TestExpMcpReporter(t *testing.T) {
934949
require.NoError(t, err)
935950
} else {
936951
// 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)
938953
pty.WriteLine(payload)
939954
_ = pty.ReadLine(ctx) // ignore echo
940955
output := pty.ReadLine(ctx)
@@ -943,8 +958,11 @@ func TestExpMcpReporter(t *testing.T) {
943958
_, err = json.Marshal(output)
944959
require.NoError(t, err, "did not receive valid JSON from coder_report_task")
945960
}
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)
948966
}
949967
}
950968
cancel()

0 commit comments

Comments
 (0)