From fa36c472c45b6b7c79659cabd9060cb866006974 Mon Sep 17 00:00:00 2001 From: Ed Burns Date: Wed, 27 May 2026 11:47:29 -0700 Subject: [PATCH 1/2] Apply review comments --- .../com/github/copilot/rpc/AgentMode.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/java/src/main/java/com/github/copilot/rpc/AgentMode.java b/java/src/main/java/com/github/copilot/rpc/AgentMode.java index 2210bc431..84054e35b 100644 --- a/java/src/main/java/com/github/copilot/rpc/AgentMode.java +++ b/java/src/main/java/com/github/copilot/rpc/AgentMode.java @@ -4,6 +4,7 @@ package com.github.copilot.rpc; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -13,7 +14,7 @@ * specific mode; defaults to the session's current mode when unset. * * @see MessageOptions - * @since 1.0.0 + * @since 1.1.0 */ public enum AgentMode { @@ -44,4 +45,28 @@ public enum AgentMode { public String getValue() { return value; } + + /** + * Deserializes a JSON string value into the corresponding {@code AgentMode} + * enum constant. + * + * @param value + * the JSON string value + * @return the matching {@code AgentMode}, or {@code null} if value is + * {@code null} + * @throws IllegalArgumentException + * if the value does not match any known agent mode + */ + @JsonCreator + public static AgentMode fromValue(String value) { + if (value == null) { + return null; + } + for (AgentMode mode : values()) { + if (mode.value.equals(value)) { + return mode; + } + } + throw new IllegalArgumentException("Unknown AgentMode: " + value); + } } From be4daa91ae3df96fbbe3ae3277f65336278232de Mon Sep 17 00:00:00 2001 From: Ed Burns Date: Wed, 27 May 2026 12:26:52 -0700 Subject: [PATCH 2/2] Address PR review comments on AgentMode - Revert @since tag from 1.1.0 to 1.0.0 for consistency with SendMessageRequest which already references AgentMode - Fix error message format to 'Unknown AgentMode value: ...' matching the convention used by generated enum fromValue methods - Add AgentModeTest covering serialization, deserialization, round-trip, null handling, and unknown-value error behavior Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../com/github/copilot/rpc/AgentMode.java | 4 +- .../com/github/copilot/AgentModeTest.java | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 java/src/test/java/com/github/copilot/AgentModeTest.java diff --git a/java/src/main/java/com/github/copilot/rpc/AgentMode.java b/java/src/main/java/com/github/copilot/rpc/AgentMode.java index 84054e35b..4a286dca3 100644 --- a/java/src/main/java/com/github/copilot/rpc/AgentMode.java +++ b/java/src/main/java/com/github/copilot/rpc/AgentMode.java @@ -14,7 +14,7 @@ * specific mode; defaults to the session's current mode when unset. * * @see MessageOptions - * @since 1.1.0 + * @since 1.0.0 */ public enum AgentMode { @@ -67,6 +67,6 @@ public static AgentMode fromValue(String value) { return mode; } } - throw new IllegalArgumentException("Unknown AgentMode: " + value); + throw new IllegalArgumentException("Unknown AgentMode value: " + value); } } diff --git a/java/src/test/java/com/github/copilot/AgentModeTest.java b/java/src/test/java/com/github/copilot/AgentModeTest.java new file mode 100644 index 000000000..dd1aa01de --- /dev/null +++ b/java/src/test/java/com/github/copilot/AgentModeTest.java @@ -0,0 +1,70 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +package com.github.copilot; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.copilot.rpc.AgentMode; + +/** + * Unit tests for {@link AgentMode} serialization, deserialization, and + * unknown-value behavior. + */ +public class AgentModeTest { + + private final ObjectMapper mapper = new ObjectMapper(); + + @ParameterizedTest + @EnumSource(AgentMode.class) + void jsonRoundTrip_allValues(AgentMode mode) throws Exception { + String json = mapper.writeValueAsString(mode); + AgentMode deserialized = mapper.readValue(json, AgentMode.class); + assertEquals(mode, deserialized); + } + + @Test + void getValue_returnsExpectedStrings() { + assertEquals("interactive", AgentMode.INTERACTIVE.getValue()); + assertEquals("plan", AgentMode.PLAN.getValue()); + assertEquals("autopilot", AgentMode.AUTOPILOT.getValue()); + assertEquals("shell", AgentMode.SHELL.getValue()); + } + + @Test + void fromValue_knownValues_returnsCorrectEnum() { + assertEquals(AgentMode.INTERACTIVE, AgentMode.fromValue("interactive")); + assertEquals(AgentMode.PLAN, AgentMode.fromValue("plan")); + assertEquals(AgentMode.AUTOPILOT, AgentMode.fromValue("autopilot")); + assertEquals(AgentMode.SHELL, AgentMode.fromValue("shell")); + } + + @Test + void fromValue_null_returnsNull() { + assertNull(AgentMode.fromValue(null)); + } + + @Test + void fromValue_unknownValue_throwsWithConsistentMessage() { + var ex = assertThrows(IllegalArgumentException.class, () -> AgentMode.fromValue("unknown")); + assertEquals("Unknown AgentMode value: unknown", ex.getMessage()); + } + + @Test + void jsonDeserialize_unknownValue_throws() { + String json = "\"not-a-mode\""; + assertThrows(Exception.class, () -> mapper.readValue(json, AgentMode.class)); + } + + @Test + void jsonSerialize_writesStringValue() throws Exception { + String json = mapper.writeValueAsString(AgentMode.AUTOPILOT); + assertEquals("\"autopilot\"", json); + } +}