Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
description: |
Adapt handwritten Java SDK code to work with regenerated types after a
@github/copilot version bump. Assumes codegen succeeded and generated code
compiles. Fixes handwritten source and tests only.

on:
workflow_dispatch:
inputs:
branch:
description: 'Branch containing the upgrade PR'
required: true
type: string
pr_number:
description: 'PR number to push fixes to'
required: true
type: string

permissions:
contents: read
actions: read

timeout-minutes: 60

network:
allowed:
- defaults
- github

tools:
github:
toolsets: [context, repos]

safe-outputs:
push-to-pull-request-branch:
target: "*"
labels: [dependencies, sdk/java]
add-comment:
target: "*"
max: 10
noop:
report-as-issue: false
---
# Java Handwritten Code Adaptation After CLI Upgrade

You are an automation agent that fixes handwritten Java SDK source and test code after a `@github/copilot` version bump has regenerated the typed schemas.

## Assumptions

- The branch `${{ inputs.branch }}` already has:
- Updated `java/scripts/codegen/package.json` with the new version
- Regenerated `java/src/generated/java/` code that compiles successfully
- Updated `java/.lastmerge` and POM property
- Your job is ONLY to fix **handwritten** code, NOT generated code.

## Boundaries

- ❌ Do NOT edit anything under `java/src/generated/java/`
- ❌ Do NOT edit `java/scripts/codegen/java.ts`
- ❌ Do NOT create or modify tests in the `com.github.copilot.generated` test package (`java/src/test/java/com/github/copilot/sdk/generated/`)
- ✅ DO edit `java/src/main/java/com/github/copilot/sdk/**`
- ✅ DO edit `java/src/test/java/com/github/copilot/sdk/**` (excluding the `generated` subpackage)
- ✅ DO add new test methods or test classes if new user-facing API surface is introduced

## Instructions

### Step 0: Setup

```bash
git checkout "${{ inputs.branch }}"
git pull origin "${{ inputs.branch }}"
```

Verify Java environment:
```bash
java -version
mvn --version
node --version
```

### Step 1: Reproduce failures

```bash
cd java
mvn clean test-compile jar:jar
mvn verify -Dskip.test.harness=true 2>&1 | tee /tmp/mvn-verify.log
```

If `mvn verify` succeeds (exit code 0), call `noop` with message "All tests pass on branch ${{ inputs.branch }}. No handwritten fixes needed." and stop.

### Step 2: Analyze compilation errors

Read the build output. Common patterns after a schema bump:

1. **Constructor arity mismatch** — A generated Java record gained new fields, changing its constructor signature. Fix: add `null` (or appropriate default) for new parameters at every call site.
2. **Missing enum constants** — A generated enum gained new values that existing switch/if-else does not cover. Fix: add cases or ensure default handling.
3. **Type changes** — A field type changed (e.g., `String` → enum, `double` → `Long`). Fix: update usages.
4. **New event types** — New session event classes were generated. If `CopilotSession.java` or event handlers reference events by explicit type listing, add the new types.

### Step 3: Fix compilation errors

Apply minimal targeted fixes:
- Search for compilation errors referencing generated type names.
- Update constructor calls to match new arity.
- Update type references if renamed/moved.
- Do NOT over-engineer — just make it compile.

After each fix round, verify:
```bash
cd java && mvn compile -Pskip-test-harness
```

### Step 4: Fix test failures

Once compilation passes, run tests:
```bash
cd java && mvn verify -Dskip.test.harness=true 2>&1 | tee /tmp/mvn-test.log
```

Fix failing assertions:
- Update expected constructor arg counts in test utility calls.
- Update expected enum values in assertions.
- Add coverage for new public API if introduced (new getters, new config options).

### Step 5: Format

```bash
cd java && mvn spotless:apply
```

### Step 6: Final validation

```bash
cd java
mvn clean test-compile jar:jar
mvn verify -Dskip.test.harness=true
```

If this passes, commit and push:
```bash
git add java/src/main/java java/src/test/java
git commit -m "Fix handwritten Java code for @github/copilot schema changes

Adapt constructor calls, enum references, and test assertions to match
regenerated types after CLI version bump."
git push origin "${{ inputs.branch }}"
```

Then add a comment to PR #${{ inputs.pr_number }} summarizing what was fixed.

If after 3 full fix-compile-test cycles the build still fails, add a comment to the PR describing the remaining failures and stop.
83 changes: 72 additions & 11 deletions .github/workflows/update-copilot-dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,37 @@ jobs:
cd ../dotnet && dotnet format src/GitHub.Copilot.SDK.csproj
cd ../rust && cargo +nightly-2026-04-14 fmt --all -- --config-path .rustfmt.nightly.toml

- uses: actions/setup-java@v5
with:
java-version: '25'
distribution: 'microsoft'

- name: Update @github/copilot in Java codegen
env:
VERSION: ${{ inputs.version }}
working-directory: ./java/scripts/codegen
run: npm install "@github/copilot@$VERSION"

- name: Update Java .lastmerge to current commit
run: git rev-parse HEAD > java/.lastmerge

- name: Update Java POM CLI version property
env:
VERSION: ${{ inputs.version }}
working-directory: ./java
run: |
PROP="readonly-copilot-sdk-ref-impl-version-from-lastmerge-file-updated-by-reference-impl-sync"
sed -i -E "s|(<${PROP}>)[^<]*(</${PROP}>)|\1^${VERSION}\2|" pom.xml
grep -q "<${PROP}>^${VERSION}</${PROP}>" pom.xml

- name: Run Java codegen
working-directory: ./java
run: mvn generate-sources -Pcodegen

- name: Compile Java SDK (validate generated code)
working-directory: ./java
run: mvn compile -Pskip-test-harness

- name: Create pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -117,6 +148,46 @@ jobs:
- Formatted generated code"
git push origin "$BRANCH" --force-with-lease

PR_BODY=$(cat <<'BODY_EOF'
Automated update of `@github/copilot` to version `PLACEHOLDER_VERSION`.

### Changes
- Updated `@github/copilot` in `nodejs/package.json` and `test/harness/package.json`
- Re-ran all code generators (`scripts/codegen`)
- Formatted generated output
- Updated Java codegen dependency, `.lastmerge`, POM property, and regenerated Java types

### Java Handwritten Code Adaptation Plan

If `java-sdk-tests` CI fails on this PR, follow these steps:

1. **Identify failures**: Run `mvn verify` from `java/` locally or check the `java-sdk-tests` workflow run logs.
2. **Categorize errors**:
- Constructor signature changes (new fields added to generated records)
- Enum value additions/renames in generated types
- New event types requiring handler registration
- Removed or renamed generated types
3. **Fix handwritten source** (`java/src/main/java/com/github/copilot/sdk/`):
- Update call sites passing positional constructor args to include new fields (typically `null` for optional new fields).
- Update switch/if-else over enum values to handle new cases.
- Register handlers for new event types in `CopilotSession.java` if applicable.
4. **Fix handwritten tests** (`java/src/test/java/com/github/copilot/sdk/`):
- Same constructor/enum fixes as above.
- Add new test methods for new functionality if the change adds user-facing API surface.
5. **Validate**: `cd java && mvn clean test-compile jar:jar && mvn verify -Dskip.test.harness=true`
6. **Format**: `cd java && mvn spotless:apply`
7. Push fixes to this PR branch.

> To automate this, trigger the `java-adapt-handwritten-code-to-accept-upgrade-changes` agentic workflow instead.

### Next steps
When ready, click **Ready for review** to trigger CI checks.

> Created by the **Update @github/copilot Dependency** workflow.
BODY_EOF
)
PR_BODY="${PR_BODY//PLACEHOLDER_VERSION/$VERSION}"

PR_STATE="$(gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null || echo "")"
if [ "$PR_STATE" = "OPEN" ]; then
if [ "$(gh pr view "$BRANCH" --json isDraft --jq '.isDraft')" = "false" ]; then
Expand All @@ -129,17 +200,7 @@ jobs:
gh pr create \
--draft \
--title "Update @github/copilot to $VERSION" \
--body "Automated update of \`@github/copilot\` to version \`$VERSION\`.

### Changes
- Updated \`@github/copilot\` in \`nodejs/package.json\` and \`test/harness/package.json\`
- Re-ran all code generators (\`scripts/codegen\`)
- Formatted generated output

### Next steps
When ready, click **Ready for review** to trigger CI checks.

> Created by the **Update @github/copilot Dependency** workflow." \
--body "$PR_BODY" \
--base main \
--head "$BRANCH"
fi
Loading