Skip to content

Commit 28336b2

Browse files
authored
Merge pull request #7 from copilot-community-sdk/merge-upstream-20260201
Port upstream SDK changes: auth options, reasoning effort, user input, handlers, and hooks.
2 parents 55316e2 + f247620 commit 28336b2

32 files changed

Lines changed: 2268 additions & 35 deletions

.github/prompts/agentic-merge-upstream.prompt.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,53 @@ Follow the existing Java SDK patterns:
194194
- **Match the style of surrounding code** - Consistency with existing code is more important than upstream patterns
195195
- **Prefer existing abstractions** - If the Java SDK already solves a problem differently than .NET, keep the Java approach
196196

197+
## Step 7.5: Port Tests
198+
199+
After porting implementation changes, **always check for new or updated tests** in the upstream repository:
200+
201+
### Check for New Tests
202+
203+
```bash
204+
cd "$TEMP_DIR/copilot-sdk"
205+
git diff "$LAST_MERGE_COMMIT"..origin/main --stat -- dotnet/test/
206+
git diff "$LAST_MERGE_COMMIT"..origin/main --stat -- test/snapshots/
207+
```
208+
209+
### Port Test Cases
210+
211+
For each new or modified test file in `dotnet/test/`:
212+
213+
1. **Create corresponding Java test class** in `src/test/java/com/github/copilot/sdk/`
214+
2. **Follow existing test patterns** - Look at existing tests like `PermissionsTest.java` for structure
215+
3. **Use the E2ETestContext** infrastructure for tests that need the test harness
216+
4. **Match snapshot directory names** - Test snapshots in `test/snapshots/` must match the directory name used in `ctx.configureForTest()`
217+
218+
### Test File Mapping
219+
220+
| Upstream Test (.NET) | Java SDK Test |
221+
|-----------------------------|--------------------------------------------------------|
222+
| `dotnet/test/AskUserTests.cs` | `src/test/java/com/github/copilot/sdk/AskUserTest.java` |
223+
| `dotnet/test/HooksTests.cs` | `src/test/java/com/github/copilot/sdk/HooksTest.java` |
224+
| `dotnet/test/ClientTests.cs` | `src/test/java/com/github/copilot/sdk/CopilotClientTest.java` |
225+
| `dotnet/test/*Tests.cs` | `src/test/java/com/github/copilot/sdk/*Test.java` |
226+
227+
### Test Snapshot Compatibility
228+
229+
New test snapshots are stored in `test/snapshots/` in the upstream repository. These snapshots are automatically cloned during the Maven build process.
230+
231+
If tests fail with errors like `TypeError: Cannot read properties of undefined`, the test harness may not yet support the new RPC methods. In this case:
232+
233+
1. **Mark tests as `@Disabled`** with a clear reason (e.g., `@Disabled("Requires test harness update with X support - see upstream PR #NNN")`)
234+
2. **Document the dependency** in the test class Javadoc
235+
3. **Enable tests later** once the harness is updated
236+
237+
### Unit Tests vs E2E Tests
238+
239+
- **Unit tests** (like auth option validation) can run without the test harness
240+
- **E2E tests** require the test harness with matching snapshots
241+
242+
Commit tests separately or together with their corresponding implementation changes.
243+
197244
## Step 8: Format and Run Tests
198245

199246
After applying changes, format the code and run the test suite:
@@ -295,6 +342,8 @@ Before finishing:
295342
- [ ] Diff analyzed between `.lastmerge` commit and HEAD
296343
- [ ] New features/fixes identified
297344
- [ ] Changes ported to Java SDK following conventions
345+
- [ ] **New/updated tests ported from upstream** (check `dotnet/test/` and `test/snapshots/`)
346+
- [ ] Tests marked `@Disabled` if harness doesn't support new features yet
298347
- [ ] Changes committed incrementally with descriptive messages
299348
- [ ] `mvn test` passes
300349
- [ ] `mvn package` builds successfully

.lastmerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
87ff5510e0dacb030912501e4eb8deaac38f913f
1+
e6e4decda7bdc74cb669cb1da6fdf45be7151034

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "java",
6+
"name": "Debug JUnit Tests (with FINE logging)",
7+
"request": "launch",
8+
"mainClass": "",
9+
"projectName": "copilot-sdk",
10+
"vmArgs": "-Djava.util.logging.config.file=${workspaceFolder}/src/test/resources/logging-debug.properties -Dcopilot.sdk.dir=${workspaceFolder}/target/copilot-sdk -Dcopilot.tests.dir=${workspaceFolder}/target/copilot-sdk/test"
11+
},
12+
{
13+
"type": "java",
14+
"name": "Debug Current Test File",
15+
"request": "launch",
16+
"mainClass": "",
17+
"projectName": "copilot-sdk",
18+
"vmArgs": "-Djava.util.logging.config.file=${workspaceFolder}/src/test/resources/logging-debug.properties -Dcopilot.sdk.dir=${workspaceFolder}/target/copilot-sdk -Dcopilot.tests.dir=${workspaceFolder}/target/copilot-sdk/test"
19+
}
20+
]
21+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"java.test.config": {
3+
"vmArgs": [
4+
"-Djava.util.logging.config.file=${workspaceFolder}/src/test/resources/logging-debug.properties",
5+
"-Dcopilot.sdk.dir=${workspaceFolder}/target/copilot-sdk",
6+
"-Dcopilot.tests.dir=${workspaceFolder}/target/copilot-sdk/test"
7+
]
8+
}
9+
}

pom.xml

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,54 @@
9292
<artifactId>maven-compiler-plugin</artifactId>
9393
<version>3.14.1</version>
9494
</plugin>
95-
<!-- Copy image.png to site resources directory -->
95+
<!-- Clone or update the official copilot-sdk repository for test resources, and copy image to site -->
9696
<plugin>
9797
<groupId>org.apache.maven.plugins</groupId>
9898
<artifactId>maven-antrun-plugin</artifactId>
99-
<version>3.1.0</version>
99+
<version>3.2.0</version>
100100
<executions>
101+
<execution>
102+
<id>clone-or-update-copilot-sdk</id>
103+
<phase>generate-test-resources</phase>
104+
<goals>
105+
<goal>run</goal>
106+
</goals>
107+
<configuration>
108+
<target xmlns:if="ant:if" xmlns:unless="ant:unless">
109+
<!-- Check if .git directory exists -->
110+
<condition property="repo.exists">
111+
<available file="${copilot.sdk.clone.dir}/.git" type="dir" />
112+
</condition>
113+
114+
<!-- If repo exists, fetch and reset -->
115+
<sequential if:set="repo.exists">
116+
<echo message="Updating existing copilot-sdk repository..." />
117+
<exec executable="git" dir="${copilot.sdk.clone.dir}" failonerror="true">
118+
<arg value="fetch" />
119+
<arg value="origin" />
120+
</exec>
121+
<exec executable="git" dir="${copilot.sdk.clone.dir}" failonerror="true">
122+
<arg value="reset" />
123+
<arg value="--hard" />
124+
<arg value="origin/main" />
125+
</exec>
126+
</sequential>
127+
128+
<!-- If repo doesn't exist, clone it -->
129+
<sequential unless:set="repo.exists">
130+
<echo message="Cloning copilot-sdk repository..." />
131+
<delete dir="${copilot.sdk.clone.dir}" quiet="true" />
132+
<exec executable="git" failonerror="true">
133+
<arg value="clone" />
134+
<arg value="--depth" />
135+
<arg value="1" />
136+
<arg value="https://github.com/github/copilot-sdk.git" />
137+
<arg value="${copilot.sdk.clone.dir}" />
138+
</exec>
139+
</sequential>
140+
</target>
141+
</configuration>
142+
</execution>
101143
<execution>
102144
<id>copy-image-to-site</id>
103145
<phase>pre-site</phase>
@@ -111,34 +153,21 @@
111153
</configuration>
112154
</execution>
113155
</executions>
156+
<dependencies>
157+
<!-- Required for if:set and unless:set -->
158+
<dependency>
159+
<groupId>org.apache.ant</groupId>
160+
<artifactId>ant</artifactId>
161+
<version>1.10.15</version>
162+
</dependency>
163+
</dependencies>
114164
</plugin>
115-
<!-- Clone the official copilot-sdk repository for test resources -->
165+
<!-- Install harness dependencies -->
116166
<plugin>
117167
<groupId>org.codehaus.mojo</groupId>
118168
<artifactId>exec-maven-plugin</artifactId>
119169
<version>3.6.2</version>
120170
<executions>
121-
<execution>
122-
<id>clone-copilot-sdk</id>
123-
<phase>generate-test-resources</phase>
124-
<goals>
125-
<goal>exec</goal>
126-
</goals>
127-
<configuration>
128-
<executable>git</executable>
129-
<arguments>
130-
<argument>clone</argument>
131-
<argument>--depth</argument>
132-
<argument>1</argument>
133-
<argument>https://github.com/github/copilot-sdk.git</argument>
134-
<argument>${copilot.sdk.clone.dir}</argument>
135-
</arguments>
136-
<successCodes>
137-
<successCode>0</successCode>
138-
<successCode>128</successCode> <!-- Already exists -->
139-
</successCodes>
140-
</configuration>
141-
</execution>
142171
<execution>
143172
<id>install-harness-dependencies</id>
144173
<phase>generate-test-resources</phase>
@@ -318,6 +347,23 @@
318347
</reporting>
319348

320349
<profiles>
350+
<!-- Debug profile for FINE logging during tests -->
351+
<profile>
352+
<id>debug</id>
353+
<build>
354+
<plugins>
355+
<plugin>
356+
<groupId>org.apache.maven.plugins</groupId>
357+
<artifactId>maven-surefire-plugin</artifactId>
358+
<configuration>
359+
<systemPropertyVariables>
360+
<java.util.logging.config.file>${project.basedir}/src/test/resources/logging-debug.properties</java.util.logging.config.file>
361+
</systemPropertyVariables>
362+
</configuration>
363+
</plugin>
364+
</plugins>
365+
</build>
366+
</profile>
321367
<profile>
322368
<id>release</id>
323369
<build>

0 commit comments

Comments
 (0)