@@ -18,6 +18,7 @@ import io.mockk.mockk
18
18
import kotlinx.coroutines.CoroutineScope
19
19
import kotlinx.coroutines.flow.MutableStateFlow
20
20
import kotlinx.coroutines.runBlocking
21
+ import org.junit.jupiter.api.DisplayName
21
22
import java.util.UUID
22
23
import kotlin.test.Test
23
24
import kotlin.test.assertEquals
@@ -47,40 +48,34 @@ internal class CoderProtocolHandlerTest {
47
48
48
49
private val agents =
49
50
mapOf (
50
- " agent_name_3 " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
51
- " agent_name_2 " to " fb3daea4-da6b-424d-84c7-36b90574cfef" ,
52
- " agent_name " to " 9a920eee-47fb-4571-9501-e4b3120c12f2" ,
51
+ " agent_name_bob " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
52
+ " agent_name_bill " to " fb3daea4-da6b-424d-84c7-36b90574cfef" ,
53
+ " agent_name_riker " to " 9a920eee-47fb-4571-9501-e4b3120c12f2" ,
53
54
)
54
- private val oneAgent =
55
+ private val agentBob =
55
56
mapOf (
56
- " agent_name_3 " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
57
+ " agent_name_bob " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
57
58
)
58
59
59
60
@Test
60
- fun tstgetMatchingAgent () {
61
+ @DisplayName(" given a ws with multiple agents, expect the correct agent to be resolved if it matches the agent_name query param" )
62
+ fun getMatchingAgent () {
61
63
val ws = DataGen .workspace(" ws" , agents = agents)
62
64
63
65
val tests =
64
66
listOf (
65
67
Pair (
66
- mapOf (" agent_id " to " 9a920eee-47fb-4571-9501-e4b3120c12f2 " ),
68
+ mapOf (" agent_name " to " agent_name_riker " ),
67
69
" 9a920eee-47fb-4571-9501-e4b3120c12f2"
68
70
),
69
71
Pair (
70
- mapOf (" agent_id " to " fb3daea4-da6b-424d-84c7-36b90574cfef " ),
72
+ mapOf (" agent_name " to " agent_name_bill " ),
71
73
" fb3daea4-da6b-424d-84c7-36b90574cfef"
72
74
),
73
75
Pair (
74
- mapOf (" agent_id " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24 " ),
76
+ mapOf (" agent_name " to " agent_name_bob " ),
75
77
" b0e4c54d-9ba9-4413-8512-11ca1e826a24"
76
- ),
77
- // Prefer agent_id.
78
- Pair (
79
- mapOf (
80
- " agent_id" to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
81
- ),
82
- " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
83
- ),
78
+ )
84
79
)
85
80
runBlocking {
86
81
tests.forEach {
@@ -90,28 +85,20 @@ internal class CoderProtocolHandlerTest {
90
85
}
91
86
92
87
@Test
88
+ @DisplayName(" given a ws with only multiple agents expect the agent resolution to fail if none match the agent_name query param" )
93
89
fun failsToGetMatchingAgent () {
94
90
val ws = DataGen .workspace(" ws" , agents = agents)
95
91
val tests =
96
92
listOf (
97
93
Triple (emptyMap(), MissingArgumentException ::class , " Unable to determine" ),
98
- Triple (mapOf (" agent_id " to " " ), MissingArgumentException ::class , " Unable to determine" ),
99
- Triple (mapOf (" agent_id " to null ), MissingArgumentException ::class , " Unable to determine" ),
100
- Triple (mapOf (" agent_id " to " not-a-uuid " ), IllegalArgumentException ::class , " agent with ID" ),
94
+ Triple (mapOf (" agent_name " to " " ), MissingArgumentException ::class , " Unable to determine" ),
95
+ Triple (mapOf (" agent_name " to null ), MissingArgumentException ::class , " Unable to determine" ),
96
+ Triple (mapOf (" agent_name " to " not-an-agent-name " ), IllegalArgumentException ::class , " agent with ID" ),
101
97
Triple (
102
- mapOf (" agent_id " to " ceaa7bcf-1612-45d7-b484-2e0da9349168 " ),
98
+ mapOf (" agent_name " to " agent_name_homer " ),
103
99
IllegalArgumentException ::class ,
104
- " agent with ID"
105
- ),
106
- // Will ignore agent if agent_id is set even if agent matches.
107
- Triple (
108
- mapOf (
109
- " agent" to " agent_name" ,
110
- " agent_id" to " ceaa7bcf-1612-45d7-b484-2e0da9349168" ,
111
- ),
112
- IllegalArgumentException ::class ,
113
- " agent with ID" ,
114
- ),
100
+ " agent with name"
101
+ )
115
102
)
116
103
runBlocking {
117
104
tests.forEach {
@@ -121,15 +108,14 @@ internal class CoderProtocolHandlerTest {
121
108
}
122
109
123
110
@Test
111
+ @DisplayName(" given a ws with only one agent, the agent is selected even when agent_name query param was not provided" )
124
112
fun getsFirstAgentWhenOnlyOne () {
125
- val ws = DataGen .workspace(" ws" , agents = oneAgent )
113
+ val ws = DataGen .workspace(" ws" , agents = agentBob )
126
114
val tests =
127
115
listOf (
128
116
emptyMap(),
129
- mapOf (" agent" to " " ),
130
- mapOf (" agent_id" to " " ),
131
- mapOf (" agent" to null ),
132
- mapOf (" agent_id" to null ),
117
+ mapOf (" agent_name" to " " ),
118
+ mapOf (" agent_name" to null )
133
119
)
134
120
runBlocking {
135
121
tests.forEach {
@@ -145,43 +131,42 @@ internal class CoderProtocolHandlerTest {
145
131
}
146
132
147
133
@Test
134
+ @DisplayName(" given a ws with only one agent, the agent is NOT selected when agent_name query param was provided but does not match" )
148
135
fun failsToGetAgentWhenOnlyOne () {
149
- val ws = DataGen .workspace(" ws" , agents = oneAgent )
136
+ val wsWithAgentBob = DataGen .workspace(" ws" , agents = agentBob )
150
137
val tests =
151
138
listOf (
152
139
Triple (
153
- mapOf (" agent_id " to " ceaa7bcf-1612-45d7-b484-2e0da9349168 " ),
140
+ mapOf (" agent_name " to " agent_name_garfield " ),
154
141
IllegalArgumentException ::class ,
155
- " agent with ID "
142
+ " agent with name "
156
143
),
157
144
)
158
145
runBlocking {
159
146
tests.forEach {
160
- assertNull(protocolHandler.getMatchingAgent(it.first, ws)?.id )
147
+ assertNull(protocolHandler.getMatchingAgent(it.first, wsWithAgentBob) )
161
148
}
162
149
}
163
150
}
164
151
165
152
@Test
166
- fun failsToGetAgentWithoutAgents () {
167
- val ws = DataGen .workspace(" ws" )
153
+ @DisplayName(" fails to resolve any agent when the workspace has no agents" )
154
+ fun failsToGetAgentWhenWorkspaceHasNoAgents () {
155
+ val wsWithoutAgents = DataGen .workspace(" ws" )
168
156
val tests =
169
157
listOf (
170
158
Triple (emptyMap(), IllegalArgumentException ::class , " has no agents" ),
171
- Triple (mapOf (" agent" to " " ), IllegalArgumentException ::class , " has no agents" ),
172
- Triple (mapOf (" agent_id" to " " ), IllegalArgumentException ::class , " has no agents" ),
173
- Triple (mapOf (" agent" to null ), IllegalArgumentException ::class , " has no agents" ),
174
- Triple (mapOf (" agent_id" to null ), IllegalArgumentException ::class , " has no agents" ),
175
- Triple (mapOf (" agent" to " agent_name" ), IllegalArgumentException ::class , " has no agents" ),
159
+ Triple (mapOf (" agent_name" to " " ), IllegalArgumentException ::class , " has no agents" ),
160
+ Triple (mapOf (" agent_name" to null ), IllegalArgumentException ::class , " has no agents" ),
176
161
Triple (
177
- mapOf (" agent_id " to " 9a920eee-47fb-4571-9501-e4b3120c12f2 " ),
162
+ mapOf (" agent_name " to " agent_name_riker " ),
178
163
IllegalArgumentException ::class ,
179
164
" has no agents"
180
165
),
181
166
)
182
167
runBlocking {
183
168
tests.forEach {
184
- assertNull(protocolHandler.getMatchingAgent(it.first, ws)?.id )
169
+ assertNull(protocolHandler.getMatchingAgent(it.first, wsWithoutAgents) )
185
170
}
186
171
}
187
172
}
0 commit comments