@@ -18,6 +18,7 @@ import io.mockk.mockk
1818import kotlinx.coroutines.CoroutineScope
1919import kotlinx.coroutines.flow.MutableStateFlow
2020import kotlinx.coroutines.runBlocking
21+ import org.junit.jupiter.api.DisplayName
2122import java.util.UUID
2223import kotlin.test.Test
2324import kotlin.test.assertEquals
@@ -47,40 +48,34 @@ internal class CoderProtocolHandlerTest {
4748
4849 private val agents =
4950 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" ,
5354 )
54- private val oneAgent =
55+ private val agentBob =
5556 mapOf (
56- " agent_name_3 " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
57+ " agent_name_bob " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24" ,
5758 )
5859
5960 @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 () {
6163 val ws = DataGen .workspace(" ws" , agents = agents)
6264
6365 val tests =
6466 listOf (
6567 Pair (
66- mapOf (" agent_id " to " 9a920eee-47fb-4571-9501-e4b3120c12f2 " ),
68+ mapOf (" agent_name " to " agent_name_riker " ),
6769 " 9a920eee-47fb-4571-9501-e4b3120c12f2"
6870 ),
6971 Pair (
70- mapOf (" agent_id " to " fb3daea4-da6b-424d-84c7-36b90574cfef " ),
72+ mapOf (" agent_name " to " agent_name_bill " ),
7173 " fb3daea4-da6b-424d-84c7-36b90574cfef"
7274 ),
7375 Pair (
74- mapOf (" agent_id " to " b0e4c54d-9ba9-4413-8512-11ca1e826a24 " ),
76+ mapOf (" agent_name " to " agent_name_bob " ),
7577 " 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+ )
8479 )
8580 runBlocking {
8681 tests.forEach {
@@ -90,28 +85,20 @@ internal class CoderProtocolHandlerTest {
9085 }
9186
9287 @Test
88+ @DisplayName(" given a ws with only multiple agents expect the agent resolution to fail if none match the agent_name query param" )
9389 fun failsToGetMatchingAgent () {
9490 val ws = DataGen .workspace(" ws" , agents = agents)
9591 val tests =
9692 listOf (
9793 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" ),
10197 Triple (
102- mapOf (" agent_id " to " ceaa7bcf-1612-45d7-b484-2e0da9349168 " ),
98+ mapOf (" agent_name " to " agent_name_homer " ),
10399 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+ )
115102 )
116103 runBlocking {
117104 tests.forEach {
@@ -121,15 +108,14 @@ internal class CoderProtocolHandlerTest {
121108 }
122109
123110 @Test
111+ @DisplayName(" given a ws with only one agent, the agent is selected even when agent_name query param was not provided" )
124112 fun getsFirstAgentWhenOnlyOne () {
125- val ws = DataGen .workspace(" ws" , agents = oneAgent )
113+ val ws = DataGen .workspace(" ws" , agents = agentBob )
126114 val tests =
127115 listOf (
128116 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 )
133119 )
134120 runBlocking {
135121 tests.forEach {
@@ -145,43 +131,42 @@ internal class CoderProtocolHandlerTest {
145131 }
146132
147133 @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" )
148135 fun failsToGetAgentWhenOnlyOne () {
149- val ws = DataGen .workspace(" ws" , agents = oneAgent )
136+ val wsWithAgentBob = DataGen .workspace(" ws" , agents = agentBob )
150137 val tests =
151138 listOf (
152139 Triple (
153- mapOf (" agent_id " to " ceaa7bcf-1612-45d7-b484-2e0da9349168 " ),
140+ mapOf (" agent_name " to " agent_name_garfield " ),
154141 IllegalArgumentException ::class ,
155- " agent with ID "
142+ " agent with name "
156143 ),
157144 )
158145 runBlocking {
159146 tests.forEach {
160- assertNull(protocolHandler.getMatchingAgent(it.first, ws)?.id )
147+ assertNull(protocolHandler.getMatchingAgent(it.first, wsWithAgentBob) )
161148 }
162149 }
163150 }
164151
165152 @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" )
168156 val tests =
169157 listOf (
170158 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" ),
176161 Triple (
177- mapOf (" agent_id " to " 9a920eee-47fb-4571-9501-e4b3120c12f2 " ),
162+ mapOf (" agent_name " to " agent_name_riker " ),
178163 IllegalArgumentException ::class ,
179164 " has no agents"
180165 ),
181166 )
182167 runBlocking {
183168 tests.forEach {
184- assertNull(protocolHandler.getMatchingAgent(it.first, ws)?.id )
169+ assertNull(protocolHandler.getMatchingAgent(it.first, wsWithoutAgents) )
185170 }
186171 }
187172 }
0 commit comments