Skip to content

Commit 4a61f2d

Browse files
temporal-spring-ai: test duplicate MCP client-info names
Replaces an explanatory comment in the two-bean test with an actual test case covering the duplicate clientInfo().name() branch in McpClientActivityImpl construction. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ab17236 commit 4a61f2d

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

temporal-spring-ai/src/test/java/io/temporal/springai/plugin/McpPluginTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.temporal.springai.plugin;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46
import static org.mockito.ArgumentMatchers.any;
57
import static org.mockito.Mockito.atLeastOnce;
68
import static org.mockito.Mockito.mock;
@@ -43,9 +45,32 @@ void discoversMcpClientBeansByType() {
4345
verify(worker, atLeastOnce()).registerActivitiesImplementations(captor.capture());
4446
Object registered = captor.getValue();
4547
assertEquals(McpClientActivityImpl.class, registered.getClass());
48+
}
49+
50+
@Test
51+
void twoMcpBeans_duplicateClientInfoNames_throws() {
52+
// Two distinct beans that both report the same clientInfo().name() — the activity impl
53+
// has to reject this because it keys its internal client map by that name.
54+
McpSyncClient clientA = mockClientNamed("shared");
55+
McpSyncClient clientB = mockClientNamed("shared");
56+
57+
Map<String, McpSyncClient> beans = new LinkedHashMap<>();
58+
beans.put("mcpClientA", clientA);
59+
beans.put("mcpClientB", clientB);
60+
61+
ApplicationContext ctx = mock(ApplicationContext.class);
62+
when(ctx.getBeansOfType(McpSyncClient.class)).thenReturn(beans);
63+
64+
McpPlugin plugin = new McpPlugin();
65+
plugin.setApplicationContext(ctx);
4666

47-
// Duplicate-name protection in McpClientActivityImpl still fires if two clients share a
48-
// clientInfo().name(); here they differ ("alpha" vs "beta") so construction succeeds.
67+
IllegalArgumentException thrown =
68+
assertThrows(
69+
IllegalArgumentException.class,
70+
() -> plugin.initializeWorker("mcp-tq", mock(Worker.class)));
71+
assertTrue(
72+
thrown.getMessage().contains("shared"),
73+
"expected duplicate name in message, got: " + thrown.getMessage());
4974
}
5075

5176
@Test

0 commit comments

Comments
 (0)