Skip to content

Commit 5a3794e

Browse files
committed
https://github.com/github/copilot-sdk/pull/1465
1 parent 2ff2844 commit 5a3794e

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

src/main/java/com/github/copilot/rpc/AgentMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* specific mode; defaults to the session's current mode when unset.
1515
*
1616
* @see MessageOptions
17-
* @since 1.1.0
17+
* @since 1.0.0
1818
*/
1919
public enum AgentMode {
2020

@@ -67,6 +67,6 @@ public static AgentMode fromValue(String value) {
6767
return mode;
6868
}
6969
}
70-
throw new IllegalArgumentException("Unknown AgentMode: " + value);
70+
throw new IllegalArgumentException("Unknown AgentMode value: " + value);
7171
}
7272
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.params.ParameterizedTest;
11+
import org.junit.jupiter.params.provider.EnumSource;
12+
13+
import com.fasterxml.jackson.databind.ObjectMapper;
14+
import com.github.copilot.rpc.AgentMode;
15+
16+
/**
17+
* Unit tests for {@link AgentMode} serialization, deserialization, and
18+
* unknown-value behavior.
19+
*/
20+
public class AgentModeTest {
21+
22+
private final ObjectMapper mapper = new ObjectMapper();
23+
24+
@ParameterizedTest
25+
@EnumSource(AgentMode.class)
26+
void jsonRoundTrip_allValues(AgentMode mode) throws Exception {
27+
String json = mapper.writeValueAsString(mode);
28+
AgentMode deserialized = mapper.readValue(json, AgentMode.class);
29+
assertEquals(mode, deserialized);
30+
}
31+
32+
@Test
33+
void getValue_returnsExpectedStrings() {
34+
assertEquals("interactive", AgentMode.INTERACTIVE.getValue());
35+
assertEquals("plan", AgentMode.PLAN.getValue());
36+
assertEquals("autopilot", AgentMode.AUTOPILOT.getValue());
37+
assertEquals("shell", AgentMode.SHELL.getValue());
38+
}
39+
40+
@Test
41+
void fromValue_knownValues_returnsCorrectEnum() {
42+
assertEquals(AgentMode.INTERACTIVE, AgentMode.fromValue("interactive"));
43+
assertEquals(AgentMode.PLAN, AgentMode.fromValue("plan"));
44+
assertEquals(AgentMode.AUTOPILOT, AgentMode.fromValue("autopilot"));
45+
assertEquals(AgentMode.SHELL, AgentMode.fromValue("shell"));
46+
}
47+
48+
@Test
49+
void fromValue_null_returnsNull() {
50+
assertNull(AgentMode.fromValue(null));
51+
}
52+
53+
@Test
54+
void fromValue_unknownValue_throwsWithConsistentMessage() {
55+
var ex = assertThrows(IllegalArgumentException.class, () -> AgentMode.fromValue("unknown"));
56+
assertEquals("Unknown AgentMode value: unknown", ex.getMessage());
57+
}
58+
59+
@Test
60+
void jsonDeserialize_unknownValue_throws() {
61+
String json = "\"not-a-mode\"";
62+
assertThrows(Exception.class, () -> mapper.readValue(json, AgentMode.class));
63+
}
64+
65+
@Test
66+
void jsonSerialize_writesStringValue() throws Exception {
67+
String json = mapper.writeValueAsString(AgentMode.AUTOPILOT);
68+
assertEquals("\"autopilot\"", json);
69+
}
70+
}

0 commit comments

Comments
 (0)