forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolDefinitionTest.java
More file actions
62 lines (44 loc) · 2.24 KB
/
Copy pathToolDefinitionTest.java
File metadata and controls
62 lines (44 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.copilot.rpc.ToolDefer;
import com.github.copilot.rpc.ToolDefinition;
/**
* Unit tests for {@link ToolDefinition} JSON serialization.
*/
public class ToolDefinitionTest {
private static final ObjectMapper MAPPER = JsonRpcClient.getObjectMapper();
private static Map<String, Object> schema() {
return Map.of("type", "object", "properties",
Map.of("query", Map.of("type", "string", "description", "Search query")), "required", List.of("query"));
}
@Test
void testDeferIsSerialized() throws Exception {
ToolDefinition tool = ToolDefinition.createWithDefer("lookup_issue", "Fetch issue details", schema(),
invocation -> CompletableFuture.completedFuture("ok"), ToolDefer.AUTO);
ObjectNode json = (ObjectNode) MAPPER.readTree(MAPPER.writeValueAsString(tool));
assertEquals("auto", json.get("defer").asText());
}
@Test
void testDeferOmittedWhenNull() throws Exception {
ToolDefinition tool = ToolDefinition.create("lookup_issue", "Fetch issue details", schema(),
invocation -> CompletableFuture.completedFuture("ok"));
ObjectNode json = (ObjectNode) MAPPER.readTree(MAPPER.writeValueAsString(tool));
assertFalse(json.has("defer"));
}
@Test
void testDeferNeverIsSerialized() throws Exception {
ToolDefinition tool = ToolDefinition.createWithDefer("lookup_issue", "Fetch issue details", schema(),
invocation -> CompletableFuture.completedFuture("ok"), ToolDefer.NEVER);
ObjectNode json = (ObjectNode) MAPPER.readTree(MAPPER.writeValueAsString(tool));
assertEquals("never", json.get("defer").asText());
}
}