Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/test/java/com/github/copilot/sdk/AgentInfoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/

package com.github.copilot.sdk;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

import com.github.copilot.sdk.json.AgentInfo;

/**
* Unit tests for {@link AgentInfo} getters, setters, and fluent chaining.
*/
class AgentInfoTest {

@Test
void defaultValuesAreNull() {
var agent = new AgentInfo();
assertNull(agent.getName());
assertNull(agent.getDisplayName());
assertNull(agent.getDescription());
}

@Test
void nameGetterSetter() {
var agent = new AgentInfo();
agent.setName("coder");
assertEquals("coder", agent.getName());
}

@Test
void displayNameGetterSetter() {
var agent = new AgentInfo();
agent.setDisplayName("Code Assistant");
assertEquals("Code Assistant", agent.getDisplayName());
}

@Test
void descriptionGetterSetter() {
var agent = new AgentInfo();
agent.setDescription("Helps with coding tasks");
assertEquals("Helps with coding tasks", agent.getDescription());
}

@Test
void fluentChainingReturnsThis() {
var agent = new AgentInfo().setName("coder").setDisplayName("Code Assistant")
.setDescription("Helps with coding tasks");

assertEquals("coder", agent.getName());
assertEquals("Code Assistant", agent.getDisplayName());
assertEquals("Helps with coding tasks", agent.getDescription());
}

@Test
void fluentChainingReturnsSameInstance() {
var agent = new AgentInfo();
assertSame(agent, agent.setName("test"));
assertSame(agent, agent.setDisplayName("Test"));
assertSame(agent, agent.setDescription("A test agent"));
}
}
27 changes: 27 additions & 0 deletions src/test/java/com/github/copilot/sdk/CliServerManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;

import com.github.copilot.sdk.json.CopilotClientOptions;
import com.github.copilot.sdk.json.TelemetryConfig;

/**
* Unit tests for {@link CliServerManager} covering parseCliUrl,
Expand Down Expand Up @@ -212,4 +213,30 @@ void startCliServerWithNullCliPath() throws Exception {
assertNotNull(e);
}
}

@Test
void startCliServerWithTelemetryAllOptions() throws Exception {
// The telemetry env vars are applied before ProcessBuilder.start()
// so even with a nonexistent CLI path, the telemetry code path is exercised
var telemetry = new TelemetryConfig().setOtlpEndpoint("https://localhost:4318").setFilePath("/tmp/telemetry.log")
.setExporterType("otlp-http").setSourceName("test-app").setCaptureContent(true);
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setTelemetry(telemetry)
.setUseStdio(true);
var manager = new CliServerManager(options);

var ex = assertThrows(IOException.class, () -> manager.startCliServer());
assertNotNull(ex);
}

@Test
void startCliServerWithTelemetryCaptureContentFalse() throws Exception {
// Test the false branch of getCaptureContent()
var telemetry = new TelemetryConfig().setCaptureContent(false);
var options = new CopilotClientOptions().setCliPath("/nonexistent/copilot").setTelemetry(telemetry)
.setUseStdio(true);
var manager = new CliServerManager(options);

var ex = assertThrows(IOException.class, () -> manager.startCliServer());
assertNotNull(ex);
}
}
18 changes: 18 additions & 0 deletions src/test/java/com/github/copilot/sdk/CommandsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,22 @@ void commandWireDefinitionNullDescriptionAllowed() {
assertEquals("rollback", wire.getName());
assertNull(wire.getDescription());
}

@Test
void commandWireDefinitionFluentSetters() {
var wire = new CommandWireDefinition();
wire.setName("status");
wire.setDescription("Show deployment status");

assertEquals("status", wire.getName());
assertEquals("Show deployment status", wire.getDescription());
}

@Test
void commandWireDefinitionFluentSettersChaining() {
var wire = new CommandWireDefinition().setName("logs").setDescription("View application logs");

assertEquals("logs", wire.getName());
assertEquals("View application logs", wire.getDescription());
}
}
96 changes: 96 additions & 0 deletions src/test/java/com/github/copilot/sdk/ConfigCloneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

import com.github.copilot.sdk.events.AbstractSessionEvent;
import com.github.copilot.sdk.json.CopilotClientOptions;
import com.github.copilot.sdk.json.InfiniteSessionConfig;
import com.github.copilot.sdk.json.MessageOptions;
import com.github.copilot.sdk.json.ModelInfo;
import com.github.copilot.sdk.json.ResumeSessionConfig;
import com.github.copilot.sdk.json.SessionConfig;
import com.github.copilot.sdk.json.SystemMessageConfig;
import com.github.copilot.sdk.json.TelemetryConfig;

class ConfigCloneTest {

Expand Down Expand Up @@ -193,4 +196,97 @@ void clonePreservesNullFields() {
MessageOptions msgClone = msg.clone();
assertNull(msgClone.getMode());
}

@Test
@SuppressWarnings("deprecation")
void copilotClientOptionsDeprecatedAutoRestart() {
CopilotClientOptions opts = new CopilotClientOptions();
assertFalse(opts.isAutoRestart());
opts.setAutoRestart(true);
assertTrue(opts.isAutoRestart());
}

@Test
void copilotClientOptionsSetCliArgsNullClearsExisting() {
CopilotClientOptions opts = new CopilotClientOptions();
opts.setCliArgs(new String[]{"--flag1"});
assertNotNull(opts.getCliArgs());

// Setting null should clear the existing array
opts.setCliArgs(null);
assertNotNull(opts.getCliArgs());
assertEquals(0, opts.getCliArgs().length);
}

@Test
void copilotClientOptionsSetEnvironmentNullClearsExisting() {
CopilotClientOptions opts = new CopilotClientOptions();
opts.setEnvironment(Map.of("KEY", "VALUE"));
assertNotNull(opts.getEnvironment());

// Setting null should clear the existing map (clears in-place → returns empty
// map)
opts.setEnvironment(null);
var env = opts.getEnvironment();
assertTrue(env == null || env.isEmpty());
}

@Test
@SuppressWarnings("deprecation")
void copilotClientOptionsDeprecatedGithubToken() {
CopilotClientOptions opts = new CopilotClientOptions();
opts.setGithubToken("ghp_deprecated_token");
assertEquals("ghp_deprecated_token", opts.getGithubToken());
assertEquals("ghp_deprecated_token", opts.getGitHubToken());
}

@Test
void copilotClientOptionsSetTelemetry() {
var telemetry = new TelemetryConfig().setOtlpEndpoint("https://localhost:4318");
var opts = new CopilotClientOptions();
opts.setTelemetry(telemetry);
assertSame(telemetry, opts.getTelemetry());
}

@Test
void copilotClientOptionsSetUseLoggedInUserNull() {
var opts = new CopilotClientOptions();
opts.setUseLoggedInUser(null);
// null → Boolean.FALSE
assertEquals(Boolean.FALSE, opts.getUseLoggedInUser());
}

@Test
void resumeSessionConfigAllSetters() {
var config = new ResumeSessionConfig();

var sysMsg = new SystemMessageConfig();
config.setSystemMessage(sysMsg);
assertSame(sysMsg, config.getSystemMessage());

config.setAvailableTools(List.of("bash", "read_file"));
assertEquals(List.of("bash", "read_file"), config.getAvailableTools());

config.setExcludedTools(List.of("write_file"));
assertEquals(List.of("write_file"), config.getExcludedTools());

config.setReasoningEffort("high");
assertEquals("high", config.getReasoningEffort());

config.setWorkingDirectory("/project/src");
assertEquals("/project/src", config.getWorkingDirectory());

config.setConfigDir("/home/user/.config/copilot");
assertEquals("/home/user/.config/copilot", config.getConfigDir());

config.setSkillDirectories(List.of("/skills/custom"));
assertEquals(List.of("/skills/custom"), config.getSkillDirectories());

config.setDisabledSkills(List.of("some-skill"));
assertEquals(List.of("some-skill"), config.getDisabledSkills());

var infiniteConfig = new InfiniteSessionConfig().setEnabled(true);
config.setInfiniteSessions(infiniteConfig);
assertSame(infiniteConfig, config.getInfiniteSessions());
}
}
Loading
Loading