Skip to content

Commit 8a2cfd7

Browse files
authored
Merge pull request #55 from github/copilot/maint-increase-jacoco-coverage
Increase JaCoCo coverage from 78.7% to 85.2%
2 parents 2b24c6f + 2bd1bf8 commit 8a2cfd7

10 files changed

+849
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import com.github.copilot.sdk.json.AgentInfo;
12+
13+
/**
14+
* Unit tests for {@link AgentInfo} getters, setters, and fluent chaining.
15+
*/
16+
class AgentInfoTest {
17+
18+
@Test
19+
void defaultValuesAreNull() {
20+
var agent = new AgentInfo();
21+
assertNull(agent.getName());
22+
assertNull(agent.getDisplayName());
23+
assertNull(agent.getDescription());
24+
}
25+
26+
@Test
27+
void nameGetterSetter() {
28+
var agent = new AgentInfo();
29+
agent.setName("coder");
30+
assertEquals("coder", agent.getName());
31+
}
32+
33+
@Test
34+
void displayNameGetterSetter() {
35+
var agent = new AgentInfo();
36+
agent.setDisplayName("Code Assistant");
37+
assertEquals("Code Assistant", agent.getDisplayName());
38+
}
39+
40+
@Test
41+
void descriptionGetterSetter() {
42+
var agent = new AgentInfo();
43+
agent.setDescription("Helps with coding tasks");
44+
assertEquals("Helps with coding tasks", agent.getDescription());
45+
}
46+
47+
@Test
48+
void fluentChainingReturnsThis() {
49+
var agent = new AgentInfo().setName("coder").setDisplayName("Code Assistant")
50+
.setDescription("Helps with coding tasks");
51+
52+
assertEquals("coder", agent.getName());
53+
assertEquals("Code Assistant", agent.getDisplayName());
54+
assertEquals("Helps with coding tasks", agent.getDescription());
55+
}
56+
57+
@Test
58+
void fluentChainingReturnsSameInstance() {
59+
var agent = new AgentInfo();
60+
assertSame(agent, agent.setName("test"));
61+
assertSame(agent, agent.setDisplayName("Test"));
62+
assertSame(agent, agent.setDescription("A test agent"));
63+
}
64+
}

src/test/java/com/github/copilot/sdk/CliServerManagerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.jupiter.api.Test;
1414

1515
import com.github.copilot.sdk.json.CopilotClientOptions;
16+
import com.github.copilot.sdk.json.TelemetryConfig;
1617

1718
/**
1819
* Unit tests for {@link CliServerManager} covering parseCliUrl,
@@ -212,4 +213,30 @@ void startCliServerWithNullCliPath() throws Exception {
212213
assertNotNull(e);
213214
}
214215
}
216+
217+
@Test
218+
void startCliServerWithTelemetryAllOptions() throws Exception {
219+
// The telemetry env vars are applied before ProcessBuilder.start()
220+
// so even with a nonexistent CLI path, the telemetry code path is exercised
221+
var telemetry = new TelemetryConfig().setOtlpEndpoint("http://localhost:4318").setFilePath("/tmp/telemetry.log")
222+
.setExporterType("otlp-http").setSourceName("test-app").setCaptureContent(true);
223+
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setTelemetry(telemetry)
224+
.setUseStdio(true);
225+
var manager = new CliServerManager(options);
226+
227+
var ex = assertThrows(IOException.class, () -> manager.startCliServer());
228+
assertNotNull(ex);
229+
}
230+
231+
@Test
232+
void startCliServerWithTelemetryCaptureContentFalse() throws Exception {
233+
// Test the false branch of getCaptureContent()
234+
var telemetry = new TelemetryConfig().setCaptureContent(false);
235+
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setTelemetry(telemetry)
236+
.setUseStdio(true);
237+
var manager = new CliServerManager(options);
238+
239+
var ex = assertThrows(IOException.class, () -> manager.startCliServer());
240+
assertNotNull(ex);
241+
}
215242
}

src/test/java/com/github/copilot/sdk/CommandsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,22 @@ void commandWireDefinitionNullDescriptionAllowed() {
135135
assertEquals("rollback", wire.getName());
136136
assertNull(wire.getDescription());
137137
}
138+
139+
@Test
140+
void commandWireDefinitionFluentSetters() {
141+
var wire = new CommandWireDefinition();
142+
wire.setName("status");
143+
wire.setDescription("Show deployment status");
144+
145+
assertEquals("status", wire.getName());
146+
assertEquals("Show deployment status", wire.getDescription());
147+
}
148+
149+
@Test
150+
void commandWireDefinitionFluentSettersChaining() {
151+
var wire = new CommandWireDefinition().setName("logs").setDescription("View application logs");
152+
153+
assertEquals("logs", wire.getName());
154+
assertEquals("View application logs", wire.getDescription());
155+
}
138156
}

src/test/java/com/github/copilot/sdk/ConfigCloneTest.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
import com.github.copilot.sdk.events.AbstractSessionEvent;
1919
import com.github.copilot.sdk.json.CopilotClientOptions;
20+
import com.github.copilot.sdk.json.InfiniteSessionConfig;
2021
import com.github.copilot.sdk.json.MessageOptions;
2122
import com.github.copilot.sdk.json.ModelInfo;
2223
import com.github.copilot.sdk.json.ResumeSessionConfig;
2324
import com.github.copilot.sdk.json.SessionConfig;
25+
import com.github.copilot.sdk.json.SystemMessageConfig;
26+
import com.github.copilot.sdk.json.TelemetryConfig;
2427

2528
class ConfigCloneTest {
2629

@@ -193,4 +196,97 @@ void clonePreservesNullFields() {
193196
MessageOptions msgClone = msg.clone();
194197
assertNull(msgClone.getMode());
195198
}
199+
200+
@Test
201+
@SuppressWarnings("deprecation")
202+
void copilotClientOptionsDeprecatedAutoRestart() {
203+
CopilotClientOptions opts = new CopilotClientOptions();
204+
assertFalse(opts.isAutoRestart());
205+
opts.setAutoRestart(true);
206+
assertTrue(opts.isAutoRestart());
207+
}
208+
209+
@Test
210+
void copilotClientOptionsSetCliArgsNullClearsExisting() {
211+
CopilotClientOptions opts = new CopilotClientOptions();
212+
opts.setCliArgs(new String[]{"--flag1"});
213+
assertNotNull(opts.getCliArgs());
214+
215+
// Setting null should clear the existing array
216+
opts.setCliArgs(null);
217+
assertNotNull(opts.getCliArgs());
218+
assertEquals(0, opts.getCliArgs().length);
219+
}
220+
221+
@Test
222+
void copilotClientOptionsSetEnvironmentNullClearsExisting() {
223+
CopilotClientOptions opts = new CopilotClientOptions();
224+
opts.setEnvironment(Map.of("KEY", "VALUE"));
225+
assertNotNull(opts.getEnvironment());
226+
227+
// Setting null should clear the existing map (clears in-place → returns empty
228+
// map)
229+
opts.setEnvironment(null);
230+
var env = opts.getEnvironment();
231+
assertTrue(env == null || env.isEmpty());
232+
}
233+
234+
@Test
235+
@SuppressWarnings("deprecation")
236+
void copilotClientOptionsDeprecatedGithubToken() {
237+
CopilotClientOptions opts = new CopilotClientOptions();
238+
opts.setGithubToken("ghp_deprecated_token");
239+
assertEquals("ghp_deprecated_token", opts.getGithubToken());
240+
assertEquals("ghp_deprecated_token", opts.getGitHubToken());
241+
}
242+
243+
@Test
244+
void copilotClientOptionsSetTelemetry() {
245+
var telemetry = new TelemetryConfig().setOtlpEndpoint("http://localhost:4318");
246+
var opts = new CopilotClientOptions();
247+
opts.setTelemetry(telemetry);
248+
assertSame(telemetry, opts.getTelemetry());
249+
}
250+
251+
@Test
252+
void copilotClientOptionsSetUseLoggedInUserNull() {
253+
var opts = new CopilotClientOptions();
254+
opts.setUseLoggedInUser(null);
255+
// null → Boolean.FALSE
256+
assertEquals(Boolean.FALSE, opts.getUseLoggedInUser());
257+
}
258+
259+
@Test
260+
void resumeSessionConfigAllSetters() {
261+
var config = new ResumeSessionConfig();
262+
263+
var sysMsg = new SystemMessageConfig();
264+
config.setSystemMessage(sysMsg);
265+
assertSame(sysMsg, config.getSystemMessage());
266+
267+
config.setAvailableTools(List.of("bash", "read_file"));
268+
assertEquals(List.of("bash", "read_file"), config.getAvailableTools());
269+
270+
config.setExcludedTools(List.of("write_file"));
271+
assertEquals(List.of("write_file"), config.getExcludedTools());
272+
273+
config.setReasoningEffort("high");
274+
assertEquals("high", config.getReasoningEffort());
275+
276+
config.setWorkingDirectory("/project/src");
277+
assertEquals("/project/src", config.getWorkingDirectory());
278+
279+
config.setConfigDir("/home/user/.config/copilot");
280+
assertEquals("/home/user/.config/copilot", config.getConfigDir());
281+
282+
config.setSkillDirectories(List.of("/skills/custom"));
283+
assertEquals(List.of("/skills/custom"), config.getSkillDirectories());
284+
285+
config.setDisabledSkills(List.of("some-skill"));
286+
assertEquals(List.of("some-skill"), config.getDisabledSkills());
287+
288+
var infiniteConfig = new InfiniteSessionConfig().setEnabled(true);
289+
config.setInfiniteSessions(infiniteConfig);
290+
assertSame(infiniteConfig, config.getInfiniteSessions());
291+
}
196292
}

0 commit comments

Comments
 (0)