Fix Java tool-processor test generation and stabilize session-id test#1799
Open
edburns wants to merge 4 commits into
Open
Conversation
Address the Java test failures observed in the Java 17 surefire/failsafe run by fixing how annotation-processing output is discovered in CopilotToolProcessor tests and by hardening one timing-sensitive session test. Changes included: - CopilotToolProcessor: resolve @copilotTool elements via TypeElement lookup and reuse that element list through validation and generation passes, making annotation discovery robust across compiler/module contexts. - CopilotToolProcessorTest: force annotation processing in the in-memory compile harness (-proc:full, explicit processor), close the file manager with try-with-resources, and add a collecting forwarding file manager that captures generated source content from getJavaFileForOutput to avoid missing generated CopilotToolMeta classes in tests. - CopilotSessionTest#testShouldGetLastSessionId: add bounded retry for session creation (including timeout and execution-timeout-cause handling) to absorb transient startup delays while preserving failure behavior on persistent errors. Result: - CopilotToolProcessorTest now consistently observes generated CopilotToolMeta output and passes. - The full requested Maven workflow (jacoco prepare/report + surefire + failsafe under Java 17, with prior Java 25 compile) completes successfully. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Java test instability by making the CopilotToolProcessor’s annotation discovery more robust, improving the in-memory compilation harness so generated $$CopilotToolMeta sources are reliably observed in tests, and adding timeout/retry logic to a timing-sensitive session-id test.
Changes:
CopilotToolProcessor: resolve@CopilotTool-annotated elements viaTypeElementlookup and reuse the discovered element list across validation + generation.CopilotToolProcessorTest: force annotation processing (-proc:full+ explicit-processor) and capture generated source content via a forwardingJavaFileManagerwrapper, with a disk-scan fallback.CopilotSessionTest: add bounded retry + timeout handling around session creation intestShouldGetLastSessionId.
Show a summary per file
| File | Description |
|---|---|
| java/src/test/java/com/github/copilot/tool/CopilotToolProcessorTest.java | Makes the compile harness reliably run the processor and capture generated $$CopilotToolMeta sources. |
| java/src/test/java/com/github/copilot/CopilotSessionTest.java | Adds timeout/retry around session creation to reduce test flakiness. |
| java/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java | Stabilizes annotation discovery by resolving @CopilotTool via TypeElement and reusing the element set. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
The retry on session creation uses `future.get(timeout)` but does not cancel the in-flight `createSession` future when a timeout occurs. If attempt 1 eventually completes after attempt 2 starts, it can leave an orphaned session registered in the client (and potentially race `getLastSessionId` persistence), reintroducing flakiness and leaking resources. Capture the future and cancel it on timeout before retrying. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Cross-SDK Consistency Review ✅This PR is focused on Java-internal bug fixes with no cross-SDK consistency concerns. Changes analyzed:
No action required in other SDK implementations (Node.js, Python, Go, .NET, Rust). The abort-session test already exists in all six SDKs and the snapshot addition only covers an additional valid response pattern.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Address the Java test failures observed in the Java 17 surefire/failsafe run by fixing how annotation-processing output is discovered in CopilotToolProcessor tests and by hardening one timing-sensitive session test.
Changes included:
CopilotToolProcessor: resolve @copilotTool elements via TypeElement lookup and reuse that element list through validation and generation passes, making annotation discovery robust across compiler/module contexts.
CopilotToolProcessorTest: force annotation processing in the in-memory compile harness (-proc:full, explicit processor), close the file manager with try-with-resources, and add a collecting forwarding file manager that captures generated source content from getJavaFileForOutput to avoid missing generated CopilotToolMeta classes in tests.
CopilotSessionTest#testShouldGetLastSessionId: add bounded retry for session creation (including timeout and execution-timeout-cause handling) to absorb transient startup delays while preserving failure behavior on persistent errors.
Result:
CopilotToolProcessorTest now consistently observes generated CopilotToolMeta output and passes.
The full requested Maven workflow (jacoco prepare/report + surefire + failsafe under Java 17, with prior Java 25 compile) completes successfully.