Skip to content

Commit 005e275

Browse files
authored
Merge pull request #85 from github/copilot/add-automated-tests-for-generated-code
Add automated tests for generated RPC code to restore JaCoCo coverage ≥85%
2 parents 9697a1d + 4b19e4b commit 005e275

File tree

5 files changed

+2512
-5
lines changed

5 files changed

+2512
-5
lines changed

src/main/java/com/github/copilot/sdk/CopilotSession.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,17 @@ public CompletableFuture<AssistantMessageEvent> sendAndWait(MessageOptions optio
542542
}
543543
}
544544

545-
// When inner future completes, run cleanup and propagate to result
545+
// When inner future completes, run cleanup and propagate to result.
546+
// Use whenCompleteAsync so that result.complete(r) is not called
547+
// synchronously on the event-dispatch thread while dispatchEvent() is
548+
// still iterating over handlers. Without async dispatch, a caller that
549+
// registered its own session.on() listener before calling sendAndWait()
550+
// could see its listener invoked *after* result.get() returned, because
551+
// sendAndWait's internal handler would complete the future mid-loop. By
552+
// submitting the completion to timeoutScheduler we allow the current
553+
// dispatch loop to finish calling all other handlers first.
546554
final ScheduledFuture<?> taskToCancel = timeoutTask;
547-
future.whenComplete((r, ex) -> {
555+
future.whenCompleteAsync((r, ex) -> {
548556
try {
549557
subscription.close();
550558
} catch (IOException e) {
@@ -560,7 +568,7 @@ public CompletableFuture<AssistantMessageEvent> sendAndWait(MessageOptions optio
560568
result.complete(r);
561569
}
562570
}
563-
});
571+
}, timeoutScheduler);
564572

565573
// When result is cancelled externally, cancel inner future to trigger cleanup
566574
result.whenComplete((v, ex) -> {

src/test/java/com/github/copilot/sdk/TestUtil.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@
1010
import java.nio.file.Paths;
1111

1212
/**
13-
* Shared test utilities for locating the Copilot CLI binary.
13+
* Shared test utilities for locating the Copilot CLI binary and other
14+
* cross-platform test helpers.
1415
*/
15-
final class TestUtil {
16+
public final class TestUtil {
1617

1718
private TestUtil() {
1819
}
1920

21+
/**
22+
* Returns a platform-independent path string for a file inside the system
23+
* temporary directory. Uses {@code java.io.tmpdir} so tests run correctly on
24+
* both POSIX and Windows.
25+
*
26+
* @param filename
27+
* the file name (no directory separator required)
28+
* @return absolute path string in the system temp directory
29+
*/
30+
public static String tempPath(String filename) {
31+
return Path.of(System.getProperty("java.io.tmpdir"), filename).toString();
32+
}
33+
2034
/**
2135
* Locates a launchable Copilot CLI executable.
2236
* <p>

0 commit comments

Comments
 (0)