Skip to content

Commit 2766820

Browse files
edburnsCopilot
andauthored
test(java): add arity 0 and arity 2 coverage to ErgonomicToolDefinitionIT (#1897)
* test(java): add arity 0 and arity 2 coverage to ErgonomicToolDefinitionIT Both the annotation-based (ErgonomicTestTools) and lambda-based (ToolDefinition.from()) APIs previously only exercised arity 1. This commit adds: - ErgonomicTestTools.getStatus() — zero-parameter @copilotTool - ErgonomicTestTools.combineValues(String, String) — two-parameter @copilotTool - ergonomicToolArity0 / lambdaToolArity0 test methods (Supplier overload) - ergonomicToolArity2 / lambdaToolArity2 test methods (BiFunction overload) - test/snapshots/tools/ergonomic_tool_arity0.yaml - test/snapshots/tools/ergonomic_tool_arity2.yaml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(java): add missing get_status and combine_values to hand-written CopilotToolMeta The hand-written ErgonomicTestTools$$CopilotToolMeta.java fixture only defined set_current_phase and search_items, but the ergonomicToolArity0 and ergonomicToolArity2 tests expect get_status and combine_values to be registered. This caused the replay proxy to fail with "Tool does not exist" errors in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9eedd7f commit 2766820

5 files changed

Lines changed: 186 additions & 0 deletions

File tree

java/src/test/java/com/github/copilot/e2e/ErgonomicTestTools$$CopilotToolMeta.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ public List<ToolDefinition> definitions(ErgonomicTestTools instance, ObjectMappe
4444
Map<String, Object> args = invocation.getArguments();
4545
String keyword = (String) args.get("keyword");
4646
return CompletableFuture.completedFuture(instance.searchItems(keyword));
47+
}, null, null, null),
48+
new ToolDefinition("get_status", "Returns the current status",
49+
Map.of("type", "object", "properties", Map.of(), "required", List.of()), invocation -> {
50+
return CompletableFuture.completedFuture(instance.getStatus());
51+
}, null, null, null),
52+
new ToolDefinition("combine_values", "Combines two values into a single string", Map.of(
53+
"type", "object", "properties", Map
54+
.ofEntries(
55+
Map.entry("value1",
56+
(Map<String, Object>) (Map) withMeta(Map.of("type", "string"),
57+
"First value", null)),
58+
Map.entry("value2",
59+
(Map<String, Object>) (Map) withMeta(Map.of("type", "string"),
60+
"Second value", null))),
61+
"required", List.of("value1", "value2")), invocation -> {
62+
Map<String, Object> args = invocation.getArguments();
63+
String value1 = (String) args.get("value1");
64+
String value2 = (String) args.get("value2");
65+
return CompletableFuture.completedFuture(instance.combineValues(value1, value2));
4766
}, null, null, null));
4867
}
4968
}

java/src/test/java/com/github/copilot/e2e/ErgonomicTestTools.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@ public String setCurrentPhase(@CopilotToolParam("The phase to transition to") St
2929
public String searchItems(@CopilotToolParam("Search keyword") String keyword) {
3030
return "Found: " + keyword + " -> item_alpha, item_beta";
3131
}
32+
33+
@CopilotTool("Returns the current status")
34+
public String getStatus() {
35+
return "Status: OK";
36+
}
37+
38+
@CopilotTool("Combines two values into a single string")
39+
public String combineValues(@CopilotToolParam("First value") String value1,
40+
@CopilotToolParam("Second value") String value2) {
41+
return "combined: " + value1 + " + " + value2;
42+
}
3243
}

java/src/test/java/com/github/copilot/e2e/ErgonomicToolDefinitionIT.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,120 @@ void ergonomicToolDefinition() throws Exception {
8484
}
8585
}
8686

87+
@Test
88+
void ergonomicToolArity0() throws Exception {
89+
ctx.configureForTest("tools", "ergonomic_tool_arity0");
90+
91+
ErgonomicTestTools tools = new ErgonomicTestTools();
92+
List<ToolDefinition> toolDefs = ToolDefinition.fromObject(tools);
93+
94+
try (CopilotClient client = ctx.createClient()) {
95+
CopilotSession session = client
96+
.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
97+
.setAvailableTools(new ToolSet().addCustom("*")).setTools(toolDefs))
98+
.get(30, TimeUnit.SECONDS);
99+
100+
try {
101+
AssistantMessageEvent response = session
102+
.sendAndWait(new MessageOptions().setPrompt("Call get_status and tell me the result."), 60_000)
103+
.get(90, TimeUnit.SECONDS);
104+
105+
assertNotNull(response, "Expected a response from the assistant");
106+
String content = response.getData().content().toLowerCase();
107+
assertTrue(content.contains("ok"),
108+
"Response should mention the status: " + response.getData().content());
109+
} finally {
110+
session.close();
111+
}
112+
}
113+
}
114+
115+
@Test
116+
void ergonomicToolArity2() throws Exception {
117+
ctx.configureForTest("tools", "ergonomic_tool_arity2");
118+
119+
ErgonomicTestTools tools = new ErgonomicTestTools();
120+
List<ToolDefinition> toolDefs = ToolDefinition.fromObject(tools);
121+
122+
try (CopilotClient client = ctx.createClient()) {
123+
CopilotSession session = client
124+
.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
125+
.setAvailableTools(new ToolSet().addCustom("*")).setTools(toolDefs))
126+
.get(30, TimeUnit.SECONDS);
127+
128+
try {
129+
AssistantMessageEvent response = session.sendAndWait(
130+
new MessageOptions().setPrompt(
131+
"Call combine_values with 'alpha' and 'beta', then report the combined result."),
132+
60_000).get(90, TimeUnit.SECONDS);
133+
134+
assertNotNull(response, "Expected a response from the assistant");
135+
String content = response.getData().content().toLowerCase();
136+
assertTrue(content.contains("alpha") && content.contains("beta"),
137+
"Response should contain the combined values: " + response.getData().content());
138+
} finally {
139+
session.close();
140+
}
141+
}
142+
}
143+
144+
@Test
145+
void lambdaToolArity0() throws Exception {
146+
ctx.configureForTest("tools", "ergonomic_tool_arity0");
147+
148+
ToolDefinition getStatus = ToolDefinition.from("get_status", "Returns the current status", () -> "Status: OK");
149+
150+
try (CopilotClient client = ctx.createClient()) {
151+
CopilotSession session = client
152+
.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
153+
.setAvailableTools(new ToolSet().addCustom("*")).setTools(List.of(getStatus)))
154+
.get(30, TimeUnit.SECONDS);
155+
156+
try {
157+
AssistantMessageEvent response = session
158+
.sendAndWait(new MessageOptions().setPrompt("Call get_status and tell me the result."), 60_000)
159+
.get(90, TimeUnit.SECONDS);
160+
161+
assertNotNull(response, "Expected a response from the assistant");
162+
String content = response.getData().content().toLowerCase();
163+
assertTrue(content.contains("ok"),
164+
"Response should mention the status: " + response.getData().content());
165+
} finally {
166+
session.close();
167+
}
168+
}
169+
}
170+
171+
@Test
172+
void lambdaToolArity2() throws Exception {
173+
ctx.configureForTest("tools", "ergonomic_tool_arity2");
174+
175+
ToolDefinition combineValues = ToolDefinition.from("combine_values", "Combines two values into a single string",
176+
Param.of(String.class, "value1", "First value"), Param.of(String.class, "value2", "Second value"),
177+
(v1, v2) -> "combined: " + v1 + " + " + v2);
178+
179+
try (CopilotClient client = ctx.createClient()) {
180+
CopilotSession session = client
181+
.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
182+
.setAvailableTools(new ToolSet().addCustom("*")).setTools(List.of(combineValues)))
183+
.get(30, TimeUnit.SECONDS);
184+
185+
try {
186+
AssistantMessageEvent response = session.sendAndWait(
187+
new MessageOptions().setPrompt(
188+
"Call combine_values with 'alpha' and 'beta', then report the combined result."),
189+
60_000).get(90, TimeUnit.SECONDS);
190+
191+
assertNotNull(response, "Expected a response from the assistant");
192+
String content = response.getData().content().toLowerCase();
193+
assertTrue(content.contains("alpha") && content.contains("beta"),
194+
"Response should contain the combined values: " + response.getData().content());
195+
} finally {
196+
session.close();
197+
}
198+
}
199+
}
200+
87201
@Test
88202
void lambdaToolDefinition() throws Exception {
89203
ctx.configureForTest("tools", "ergonomic_tool_definition");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
models:
2+
- claude-sonnet-4.5
3+
conversations:
4+
- messages:
5+
- role: system
6+
content: ${system}
7+
- role: user
8+
content: Call get_status and tell me the result.
9+
- role: assistant
10+
content: I'll call get_status now.
11+
tool_calls:
12+
- id: toolcall_0
13+
type: function
14+
function:
15+
name: get_status
16+
arguments: '{}'
17+
- role: tool
18+
tool_call_id: toolcall_0
19+
content: "Status: OK"
20+
- role: assistant
21+
content: "The status is: OK"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
models:
2+
- claude-sonnet-4.5
3+
conversations:
4+
- messages:
5+
- role: system
6+
content: ${system}
7+
- role: user
8+
content: Call combine_values with 'alpha' and 'beta', then report the combined result.
9+
- role: assistant
10+
content: I'll call combine_values with those arguments.
11+
tool_calls:
12+
- id: toolcall_0
13+
type: function
14+
function:
15+
name: combine_values
16+
arguments: '{"value1":"alpha","value2":"beta"}'
17+
- role: tool
18+
tool_call_id: toolcall_0
19+
content: "combined: alpha + beta"
20+
- role: assistant
21+
content: "The combined result is: alpha + beta"

0 commit comments

Comments
 (0)