-
Notifications
You must be signed in to change notification settings - Fork 8
Upstream sync: Add clone() methods to config classes (6 commits) #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1af066a
21f9560
4bf82eb
962f97b
8dbd48f
bd64fb8
64ab5c1
003d5f7
5cf778b
7bbabef
063be94
6e2e991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 304d812cd4c98755159da427c6701bfb7e0b7c32 | ||
| 5016587a62652f3d184b3c6958dfc63359921aa8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,4 +323,32 @@ public CopilotClientOptions setUseLoggedInUser(Boolean useLoggedInUser) { | |
| this.useLoggedInUser = useLoggedInUser; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a shallow clone of this {@code CopilotClientOptions} instance. | ||
| * <p> | ||
| * Array properties (like {@code cliArgs}) are copied into new arrays so that | ||
| * modifications to the clone do not affect the original. The | ||
| * {@code environment} map is also copied to a new map instance. Other | ||
| * reference-type properties are shared between the original and clone. | ||
| * | ||
| * @return a clone of this options instance | ||
| */ | ||
| @Override | ||
| public CopilotClientOptions clone() { | ||
github-code-quality[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
github-code-quality[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| CopilotClientOptions copy = new CopilotClientOptions(); | ||
| copy.cliPath = this.cliPath; | ||
| copy.cliArgs = this.cliArgs != null ? this.cliArgs.clone() : null; | ||
| copy.cwd = this.cwd; | ||
| copy.port = this.port; | ||
| copy.useStdio = this.useStdio; | ||
| copy.cliUrl = this.cliUrl; | ||
| copy.logLevel = this.logLevel; | ||
| copy.autoStart = this.autoStart; | ||
| copy.autoRestart = this.autoRestart; | ||
| copy.environment = this.environment != null ? new java.util.HashMap<>(this.environment) : null; | ||
| copy.githubToken = this.githubToken; | ||
| copy.useLoggedInUser = this.useLoggedInUser; | ||
| return copy; | ||
|
Comment on lines
327
to
352
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package com.github.copilot.sdk; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.github.copilot.sdk.json.CopilotClientOptions; | ||
| import com.github.copilot.sdk.json.SessionConfig; | ||
| import com.github.copilot.sdk.json.ResumeSessionConfig; | ||
| import com.github.copilot.sdk.json.MessageOptions; | ||
|
|
||
| class ConfigCloneTest { | ||
|
|
||
| @Test | ||
| void copilotClientOptionsCloneBasic() { | ||
| CopilotClientOptions original = new CopilotClientOptions(); | ||
| original.setCliPath("/usr/local/bin/copilot"); | ||
| original.setLogLevel("debug"); | ||
| original.setPort(9000); | ||
|
|
||
| CopilotClientOptions cloned = original.clone(); | ||
|
|
||
| assertEquals(original.getCliPath(), cloned.getCliPath()); | ||
|
Comment on lines
26
to
32
|
||
| assertEquals(original.getLogLevel(), cloned.getLogLevel()); | ||
| assertEquals(original.getPort(), cloned.getPort()); | ||
| } | ||
|
|
||
| @Test | ||
| void copilotClientOptionsArrayIndependence() { | ||
| CopilotClientOptions original = new CopilotClientOptions(); | ||
| String[] args = {"--flag1", "--flag2"}; | ||
| original.setCliArgs(args); | ||
|
|
||
| CopilotClientOptions cloned = original.clone(); | ||
| cloned.getCliArgs()[0] = "--changed"; | ||
|
|
||
| assertEquals("--flag1", original.getCliArgs()[0]); | ||
| assertEquals("--changed", cloned.getCliArgs()[0]); | ||
| } | ||
|
|
||
| @Test | ||
| void copilotClientOptionsEnvironmentIndependence() { | ||
| CopilotClientOptions original = new CopilotClientOptions(); | ||
| Map<String, String> env = new HashMap<>(); | ||
| env.put("KEY1", "value1"); | ||
| original.setEnvironment(env); | ||
|
|
||
| CopilotClientOptions cloned = original.clone(); | ||
|
|
||
| // Mutate the original environment map to test independence | ||
| env.put("KEY2", "value2"); | ||
|
|
||
| // The cloned config should be unaffected by mutations to the original map | ||
| assertEquals(1, cloned.getEnvironment().size()); | ||
| assertEquals(2, original.getEnvironment().size()); | ||
| } | ||
|
|
||
| @Test | ||
| void sessionConfigCloneBasic() { | ||
| SessionConfig original = new SessionConfig(); | ||
| original.setSessionId("my-session"); | ||
| original.setModel("gpt-4o"); | ||
| original.setStreaming(true); | ||
|
|
||
| SessionConfig cloned = original.clone(); | ||
|
|
||
| assertEquals(original.getSessionId(), cloned.getSessionId()); | ||
| assertEquals(original.getModel(), cloned.getModel()); | ||
| assertEquals(original.isStreaming(), cloned.isStreaming()); | ||
| } | ||
|
|
||
| @Test | ||
| void sessionConfigListIndependence() { | ||
| SessionConfig original = new SessionConfig(); | ||
| List<String> toolList = new ArrayList<>(); | ||
| toolList.add("grep"); | ||
| toolList.add("bash"); | ||
| original.setAvailableTools(toolList); | ||
|
|
||
| SessionConfig cloned = original.clone(); | ||
|
|
||
| // Mutate the original list directly to test independence | ||
| toolList.add("web"); | ||
|
|
||
| // The cloned config should be unaffected by mutations to the original list | ||
| assertEquals(2, cloned.getAvailableTools().size()); | ||
| assertEquals(3, original.getAvailableTools().size()); | ||
| } | ||
|
Comment on lines
82
to
97
|
||
|
|
||
| @Test | ||
| void resumeSessionConfigCloneBasic() { | ||
| ResumeSessionConfig original = new ResumeSessionConfig(); | ||
| original.setModel("o1"); | ||
| original.setStreaming(false); | ||
|
|
||
| ResumeSessionConfig cloned = original.clone(); | ||
|
|
||
| assertEquals(original.getModel(), cloned.getModel()); | ||
| assertEquals(original.isStreaming(), cloned.isStreaming()); | ||
| } | ||
|
|
||
| @Test | ||
| void messageOptionsCloneBasic() { | ||
| MessageOptions original = new MessageOptions(); | ||
| original.setPrompt("What is 2+2?"); | ||
| original.setMode("immediate"); | ||
|
|
||
| MessageOptions cloned = original.clone(); | ||
|
|
||
| assertEquals(original.getPrompt(), cloned.getPrompt()); | ||
| assertEquals(original.getMode(), cloned.getMode()); | ||
| } | ||
|
|
||
| @Test | ||
| void clonePreservesNullFields() { | ||
| CopilotClientOptions opts = new CopilotClientOptions(); | ||
| CopilotClientOptions optsClone = opts.clone(); | ||
| assertNull(optsClone.getCliPath()); | ||
|
|
||
| SessionConfig cfg = new SessionConfig(); | ||
| SessionConfig cfgClone = cfg.clone(); | ||
| assertNull(cfgClone.getModel()); | ||
|
|
||
| MessageOptions msg = new MessageOptions(); | ||
| MessageOptions msgClone = msg.clone(); | ||
| assertNull(msgClone.getMode()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.