Skip to content

Add automated tests for generated RPC code to restore JaCoCo coverage ≥85%#85

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-automated-tests-for-generated-code
Open

Add automated tests for generated RPC code to restore JaCoCo coverage ≥85%#85
Copilot wants to merge 4 commits intomainfrom
copilot/add-automated-tests-for-generated-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

Coverage dropped from 84.4% → 69.2% after PR #81 added ~120 generated RPC files with no tests. This PR adds 222 unit tests targeting the generated code directly.

Before the change?

  • Generated code in src/generated/java/ (RPC API classes, param/result records, event types) had near-zero test coverage
  • JaCoCo badge: 69.2%
  • Tests for generated code were placed in com.github.copilot.sdk rather than mirroring the package structure of the code under test

After the change?

Three new test classes, all pure unit tests (no network/CLI required), placed in packages that mirror the production code they test:

  • com.github.copilot.sdk.generated.rpc.GeneratedRpcApiCoverageTest (47 tests) — verifies every API method in SessionRpc/ServerRpc dispatches the correct JSON-RPC method name and injects sessionId correctly, using a StubCaller. Covers all 15+ session namespaces: mode, plan, workspace, fleet, skills, mcp, plugins, extensions, tools, commands, ui, permissions, shell, history, usage, agent, log.

  • com.github.copilot.sdk.generated.GeneratedEventTypesCoverageTest (52 tests) — JSON deserialization tests for the 34 event types not covered by the existing SessionEventDeserializationTest. Covers CapabilitiesChanged, Elicitation*, ExitPlanMode*, ExternalTool*, McpOauth*, Permission*, Sampling*, SessionContext, SessionCustomAgents, SessionExtensions, SessionMcpServer*, SessionSkills/Tools/TitleChanged, UserInput*, SubagentDeselected, CommandsChanged, and more. Includes enum fromValue() round-trips and invalid-value exception cases.

  • com.github.copilot.sdk.generated.rpc.GeneratedRpcRecordsCoverageTest (123 tests) — constructor/accessor tests for all ~100 generated param/result records, including nested records and enum variants (e.g. SessionModeGetResult.Mode, SessionShellKillParams.Signal, SessionFsReaddirWithTypesResult.EntriesItemType).

Package alignment means tests no longer need cross-package imports for the classes they exercise, and the generated source tree remains exclusively for auto-generated code.

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • mvn spotless:apply has been run to format the code
  • mvn clean verify passes locally

Does this introduce a breaking change?

  • Yes
  • No

Copilot AI linked an issue Apr 20, 2026 that may be closed by this pull request
1 task
Copilot AI changed the title [WIP] Add automated tests for generated code to improve JaCoCo coverage Add automated tests for generated RPC code to restore JaCoCo coverage ≥85% Apr 20, 2026
Copilot AI requested a review from edburns April 20, 2026 17:05
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@edburns edburns marked this pull request as ready for review April 20, 2026 17:29
Copilot AI review requested due to automatic review settings April 20, 2026 17:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds targeted unit tests to increase JaCoCo coverage for newly generated JSON-RPC/event code (introduced in #81) without requiring any network/CLI integration.

Changes:

  • Add RPC API wrapper coverage tests to validate method name dispatch and sessionId injection behavior.
  • Add JSON deserialization coverage tests for generated session event types not covered elsewhere.
  • Add constructor/accessor/enum-variant tests for generated RPC param/result record types to boost coverage.
Show a summary per file
File Description
src/test/java/com/github/copilot/sdk/GeneratedRpcApiCoverageTest.java Verifies generated ServerRpc/SessionRpc wrappers call the expected JSON-RPC method names and inject/merge sessionId correctly using a stub caller.
src/test/java/com/github/copilot/sdk/GeneratedEventTypesCoverageTest.java Adds Jackson deserialization tests for additional generated SessionEvent subtypes and enum round-trips/invalid values.
src/test/java/com/github/copilot/sdk/GeneratedRpcRecordsCoverageTest.java Adds record construction/accessor and enum fromValue() coverage for generated RPC param/result types (including nested records).

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment on lines +134 to +135
private static final ObjectMapper MAPPER = JsonRpcClient.getObjectMapper();

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAPPER is declared but never used in this test class. Please remove the field (and the ObjectMapper import) or use it in a serialization/deserialization assertion so the constant isn’t dead code.

Copilot uses AI. Check for mistakes.
Comment on lines +341 to +345
var params = new SessionFsWriteFileParams("sess-21", "/tmp/out.txt", "content here", 0644.0);
assertEquals("sess-21", params.sessionId());
assertEquals("/tmp/out.txt", params.path());
assertEquals("content here", params.content());
assertEquals(0644.0, params.mode());
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The literal 0644.0 looks like a Unix octal file mode, but in Java it reads as the decimal value 644.0 (octal notation doesn’t apply here). To avoid confusion, use an explicit decimal value (e.g., 420.0 for 0o644) or add a clarifying comment.

Suggested change
var params = new SessionFsWriteFileParams("sess-21", "/tmp/out.txt", "content here", 0644.0);
assertEquals("sess-21", params.sessionId());
assertEquals("/tmp/out.txt", params.path());
assertEquals("content here", params.content());
assertEquals(0644.0, params.mode());
var params = new SessionFsWriteFileParams("sess-21", "/tmp/out.txt", "content here", 644.0);
assertEquals("sess-21", params.sessionId());
assertEquals("/tmp/out.txt", params.path());
assertEquals("content here", params.content());
assertEquals(644.0, params.mode());

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@edburns edburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Consider this guidance:


The tests should go in src/test/java/com/github/copilot/sdk/generated/ and sub package rpc, as appropriate.

Here's the reasoning from Java best practices:

  1. Standard Maven convention: Tests always live under java, mirroring the package structure of the code they test. The test source root doesn't change based on where the production source root is — it's always java.

  2. Package alignment: The generated code is in package com.github.copilot.sdk.generated, so the tests go in the same package under the test tree: src/test/java/com/github/copilot/sdk/generated/. This gives tests package-private access to the generated classes if needed.

  3. No separate test source root needed: Your build-helper-maven-plugin already adds java as a compile source root. Maven's default test source root (java) can already see all compile-scope classes, including generated ones. No POM changes required.

  4. Clear ownership boundary: Placing tests in java (not generated) makes it obvious they are hand-maintained artifacts, not code-gen output. The generated tree remains exclusively for auto-generated code, while java is where all human/LLM-authored tests live — both for java code and java code.

This also aligns with how the existing tests already work — e.g., tests in sdk test code from sdk.


✅✅ Tests must reside under src/test/java. You have that already. ✅✅

  1. Standard Maven convention: Tests always live under java, mirroring the package structure of the code they test. The test source root doesn't change based on where the production source root is — it's always java. ❌❌You violate this❌❌.

Here's how to fix it.

  • Your new class GeneratedEventTypesCoverageTest must reside in com.github.copilot.sdk.generated. Then you don't need import com.github.copilot.sdk.generated.*;
  • Your new classes GeneratedRpcRecordsCoverageTest and GeneratedRpcRecordsCoverageTest must reside in com.github.copilot.sdk.generated.rpc. Then you don't need all those imports of the classes in that package.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 20, 2026

@copilot

Consider this guidance:...

Done in commit 863eba8. All three test files have been moved to mirror the package structure of the production code:

  • GeneratedEventTypesCoverageTestsrc/test/java/com/github/copilot/sdk/generated/ (package com.github.copilot.sdk.generated) — the wildcard import com.github.copilot.sdk.generated.* is gone.
  • GeneratedRpcApiCoverageTestsrc/test/java/com/github/copilot/sdk/generated/rpc/ (package com.github.copilot.sdk.generated.rpc) — all 28 individual import com.github.copilot.sdk.generated.rpc.* lines are gone.
  • GeneratedRpcRecordsCoverageTestsrc/test/java/com/github/copilot/sdk/generated/rpc/ (package com.github.copilot.sdk.generated.rpc) — all 110 generated-rpc imports are gone, along with the unused MAPPER field and the 0644.0644.0 fix.

All 366 unit tests still pass.

Copilot AI requested a review from edburns April 20, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MAINT]:

3 participants