Skip to content

Commit 031ea1e

Browse files
Add Java E2E coverage for session.todos_changed (WIP)
Adds the generated Java bindings for SessionTodosChangedEvent, PlanSqlTodoDependency, and SessionPlan.readSqlTodosWithDependencies, plus a Java E2E test mirroring the other 5 SDK languages. Status: the test currently fails locally - the runtime's session.todos_changed event is not reaching the Java listener even though the same scenario passes in Node/.NET/Go/Python/Rust against the identical CAPI snapshot. Needs follow-up investigation; pushed as-is so reviewers can see the full 6-language surface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1fcc1c0 commit 031ea1e

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
import java.util.ArrayList;
10+
import java.util.Collections;
11+
import java.util.List;
12+
import java.util.concurrent.TimeUnit;
13+
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.Test;
17+
18+
import com.github.copilot.generated.SessionEvent;
19+
import com.github.copilot.generated.SessionTodosChangedEvent;
20+
import com.github.copilot.generated.rpc.PlanSqlTodoDependency;
21+
import com.github.copilot.rpc.MessageOptions;
22+
import com.github.copilot.rpc.PermissionHandler;
23+
import com.github.copilot.rpc.SessionConfig;
24+
25+
public class SessionTodosChangedTest {
26+
27+
private static E2ETestContext ctx;
28+
29+
@BeforeAll
30+
static void setup() throws Exception {
31+
ctx = E2ETestContext.create();
32+
}
33+
34+
@AfterAll
35+
static void teardown() throws Exception {
36+
if (ctx != null) {
37+
ctx.close();
38+
}
39+
}
40+
41+
@Test
42+
void firesSessionTodosChangedAndExposesRowsAndDependencies() throws Exception {
43+
ctx.configureForTest("session_todos_changed",
44+
"fires_session_todos_changed_and_exposes_rows_and_dependencies");
45+
46+
try (CopilotClient client = ctx.createClient()) {
47+
CopilotSession session = client
48+
.createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
49+
50+
List<SessionEvent> events = Collections.synchronizedList(new ArrayList<>());
51+
session.on(events::add);
52+
53+
session.sendAndWait(new MessageOptions().setPrompt(
54+
"Use the sql tool to execute exactly these statements, in order, with no extra rows:\n"
55+
+ "1. INSERT INTO todos (id, title, status) VALUES ('alpha', 'First todo', 'pending');\n"
56+
+ "2. INSERT INTO todos (id, title, status) VALUES ('beta', 'Second todo', 'done');\n"
57+
+ "3. INSERT INTO todo_deps (todo_id, depends_on) VALUES ('beta', 'alpha');\n"
58+
+ "Then stop. Do not insert any other rows or create any other tables."))
59+
.get(120, TimeUnit.SECONDS);
60+
61+
assertTrue(events.stream().anyMatch(SessionTodosChangedEvent.class::isInstance),
62+
"Should have received at least one session.todos_changed event");
63+
64+
var result = session.getRpc().plan.readSqlTodosWithDependencies().get(15, TimeUnit.SECONDS);
65+
assertEquals(2, result.rows().size());
66+
var ids = result.rows().stream().map(row -> row.id()).filter(id -> id != null).sorted().toList();
67+
68+
assertEquals(List.of("alpha", "beta"), ids);
69+
assertTrue(result.dependencies().stream().anyMatch(SessionTodosChangedTest::isBetaDependsOnAlpha),
70+
"Should contain beta -> alpha dependency");
71+
72+
session.close();
73+
}
74+
}
75+
76+
private static boolean isBetaDependsOnAlpha(PlanSqlTodoDependency dependency) {
77+
return "beta".equals(dependency.todoId()) && "alpha".equals(dependency.dependsOn());
78+
}
79+
}

0 commit comments

Comments
 (0)