-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[E2E] session.todos_changed event + readSqlTodosWithDependencies (6 languages) #1622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
086a3cb
Add E2E test for session.todos_changed event + readSqlTodosWithDepend…
SteveSandersonMS 266555c
Use PlanTodo / PlanTodoDependency names, drop CREATE TABLE from prompt
SteveSandersonMS 1fcc1c0
Add E2E coverage for session.todos_changed in .NET, Go, Python, Rust
SteveSandersonMS 031ea1e
Add Java E2E coverage for session.todos_changed (WIP)
SteveSandersonMS 9ffba90
Regenerate RPC bindings against @github/copilot 1.0.62
SteveSandersonMS 762a2e1
Apply prettier formatting to session_todos_changed e2e test
SteveSandersonMS 9f3a8ee
Apply ruff format to session_todos_changed python e2e test
SteveSandersonMS 9221e06
Apply Java spotless formatting to SessionTodosChangedTest
SteveSandersonMS 7b3e35a
Fix .NET test to use OrderBy for net472 compatibility
SteveSandersonMS ab07a04
Fix Rust e2e to use SessionTodosChanged variant now that codegen reco…
SteveSandersonMS 001f6f4
Fix model switchTo e2e assertion to match runtime behavior
SteveSandersonMS c07cfb8
Revert "Fix model switchTo e2e assertion to match runtime behavior"
SteveSandersonMS 5245ddd
Make model switchTo e2e wait for the switch to take effect
SteveSandersonMS f58c955
Tighten model switchTo e2e to assert the switch takes effect (5s poll)
SteveSandersonMS 3d3d439
Use typed Rust RPC API for session_todos_changed E2E test
SteveSandersonMS b5772fe
Use gpt-5.4 in model switchto E2E tests
SteveSandersonMS f1460dd
Use active event-wait pattern in todos_changed E2E tests
SteveSandersonMS c50207a
Add gpt-5.4 to getcurrent snapshot to avoid cross-test model cache co…
SteveSandersonMS 0e3d686
Document why getcurrent snapshot lists gpt-5.4
SteveSandersonMS ebb2a90
Isolate model switchTo test in its own SDK context
SteveSandersonMS aa99b00
Isolate model switchTo e2e in Go/Python/.NET; tighten Rust assertions
SteveSandersonMS fa47e5b
Rename Python switch_to test to switchto so it finds the shared snapshot
SteveSandersonMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| using GitHub.Copilot.Rpc; | ||
| using GitHub.Copilot.Test.Harness; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace GitHub.Copilot.Test.E2E; | ||
|
|
||
| public class SessionTodosChangedE2ETests(E2ETestFixture fixture, ITestOutputHelper output) | ||
| : E2ETestBase(fixture, "session_todos_changed", output) | ||
| { | ||
| private static readonly string[] ExpectedTodoIds = ["alpha", "beta"]; | ||
|
|
||
| [Fact] | ||
| public async Task Fires_Session_Todos_Changed_And_Exposes_Rows_And_Dependencies() | ||
| { | ||
| await using var session = await CreateSessionAsync(new SessionConfig | ||
| { | ||
| OnPermissionRequest = PermissionHandler.ApproveAll, | ||
| }); | ||
|
|
||
| var todosChangedTask = TestHelper.GetNextEventOfTypeAsync<SessionTodosChangedEvent>( | ||
| session, | ||
| TimeSpan.FromSeconds(30)); | ||
|
|
||
| await session.SendAndWaitAsync(new MessageOptions | ||
| { | ||
| Prompt = | ||
| "Use the sql tool to execute exactly these statements, in order, with no extra rows:\n" + | ||
| "1. INSERT INTO todos (id, title, status) VALUES ('alpha', 'First todo', 'pending');\n" + | ||
| "2. INSERT INTO todos (id, title, status) VALUES ('beta', 'Second todo', 'done');\n" + | ||
| "3. INSERT INTO todo_deps (todo_id, depends_on) VALUES ('beta', 'alpha');\n" + | ||
| "Then stop. Do not insert any other rows or create any other tables.", | ||
| }); | ||
|
|
||
| await todosChangedTask; | ||
|
|
||
| var result = await session.Rpc.Plan.ReadSqlTodosWithDependenciesAsync(); | ||
|
|
||
| var ids = result.Rows | ||
| .Select(row => row.Id) | ||
| .OfType<string>() | ||
| .OrderBy(id => id, StringComparer.Ordinal) | ||
| .ToArray(); | ||
|
|
||
| Assert.Equal(ExpectedTodoIds, ids); | ||
|
|
||
| Assert.Contains(result.Dependencies, dependency => | ||
| dependency.TodoId == "beta" && | ||
| dependency.DependsOn == "alpha"); | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "slices" | ||
| "sort" | ||
| "testing" | ||
| "time" | ||
|
|
||
| copilot "github.com/github/copilot-sdk/go" | ||
| "github.com/github/copilot-sdk/go/internal/e2e/testharness" | ||
| ) | ||
|
|
||
| func TestFiresSessionTodosChangedAndExposesRowsAndDependencies(t *testing.T) { | ||
| ctx := testharness.NewTestContext(t) | ||
| client := ctx.NewClient() | ||
| t.Cleanup(func() { client.ForceStop() }) | ||
|
|
||
| t.Run("fires session.todos_changed and exposes rows and dependencies", func(t *testing.T) { | ||
| ctx.ConfigureForTest(t) | ||
|
|
||
| session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ | ||
| OnPermissionRequest: copilot.PermissionHandler.ApproveAll, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create session: %v", err) | ||
| } | ||
| defer session.Disconnect() | ||
|
|
||
| awaitTodosChanged := waitForMatchingEvent( | ||
| session, | ||
| copilot.SessionEventType("session.todos_changed"), | ||
| func(copilot.SessionEvent) bool { return true }, | ||
| "session.todos_changed event", | ||
| ) | ||
|
|
||
| sendCtx, cancel := context.WithTimeout(t.Context(), 120*time.Second) | ||
| defer cancel() | ||
| _, err = session.SendAndWait(sendCtx, copilot.MessageOptions{ | ||
| Prompt: "Use the sql tool to execute exactly these statements, in order, with no extra rows:\n" + | ||
| "1. INSERT INTO todos (id, title, status) VALUES ('alpha', 'First todo', 'pending');\n" + | ||
| "2. INSERT INTO todos (id, title, status) VALUES ('beta', 'Second todo', 'done');\n" + | ||
| "3. INSERT INTO todo_deps (todo_id, depends_on) VALUES ('beta', 'alpha');\n" + | ||
| "Then stop. Do not insert any other rows or create any other tables.", | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to send message: %v", err) | ||
| } | ||
|
|
||
| awaitEvent(t, awaitTodosChanged) | ||
|
|
||
| result, err := session.RPC.Plan.ReadSqlTodosWithDependencies(t.Context()) | ||
| if err != nil { | ||
| t.Fatalf("Plan.ReadSqlTodosWithDependencies failed: %v", err) | ||
| } | ||
|
|
||
| var ids []string | ||
| for _, row := range result.Rows { | ||
| if row.ID != nil && *row.ID != "" { | ||
| ids = append(ids, *row.ID) | ||
| } | ||
| } | ||
| sort.Strings(ids) | ||
| if !slices.Equal(ids, []string{"alpha", "beta"}) { | ||
| t.Fatalf("Expected todo ids [alpha beta], got %v", ids) | ||
| } | ||
|
|
||
| foundDependency := false | ||
| for _, dependency := range result.Dependencies { | ||
| if dependency.TodoID == "beta" && dependency.DependsOn == "alpha" { | ||
| foundDependency = true | ||
| break | ||
| } | ||
| } | ||
| if !foundDependency { | ||
| t.Fatalf("Expected dependency beta -> alpha, got %+v", result.Dependencies) | ||
| } | ||
| }) | ||
| } |
79 changes: 79 additions & 0 deletions
79
java/src/test/java/com/github/copilot/SessionTodosChangedTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package com.github.copilot; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.github.copilot.generated.SessionTodosChangedEvent; | ||
| import com.github.copilot.generated.rpc.PlanSqlTodoDependency; | ||
| import com.github.copilot.rpc.MessageOptions; | ||
| import com.github.copilot.rpc.PermissionHandler; | ||
| import com.github.copilot.rpc.SessionConfig; | ||
|
|
||
| public class SessionTodosChangedTest { | ||
|
|
||
| private static E2ETestContext ctx; | ||
|
|
||
| @BeforeAll | ||
| static void setup() throws Exception { | ||
| ctx = E2ETestContext.create(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void teardown() throws Exception { | ||
| if (ctx != null) { | ||
| ctx.close(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void firesSessionTodosChangedAndExposesRowsAndDependencies() throws Exception { | ||
| ctx.configureForTest("session_todos_changed", "fires_session_todos_changed_and_exposes_rows_and_dependencies"); | ||
|
|
||
| try (CopilotClient client = ctx.createClient()) { | ||
| CopilotSession session = client | ||
| .createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get(); | ||
|
|
||
| CompletableFuture<SessionTodosChangedEvent> todosChanged = new CompletableFuture<>(); | ||
| session.on(event -> { | ||
| if (event instanceof SessionTodosChangedEvent todosEvent && !todosChanged.isDone()) { | ||
| todosChanged.complete(todosEvent); | ||
| } | ||
| }); | ||
|
|
||
| session.sendAndWait(new MessageOptions() | ||
| .setPrompt("Use the sql tool to execute exactly these statements, in order, with no extra rows:\n" | ||
| + "1. INSERT INTO todos (id, title, status) VALUES ('alpha', 'First todo', 'pending');\n" | ||
| + "2. INSERT INTO todos (id, title, status) VALUES ('beta', 'Second todo', 'done');\n" | ||
| + "3. INSERT INTO todo_deps (todo_id, depends_on) VALUES ('beta', 'alpha');\n" | ||
| + "Then stop. Do not insert any other rows or create any other tables.")) | ||
| .get(120, TimeUnit.SECONDS); | ||
|
|
||
| assertNotNull(todosChanged.get(15, TimeUnit.SECONDS), | ||
| "Should have received at least one session.todos_changed event"); | ||
|
|
||
| var result = session.getRpc().plan.readSqlTodosWithDependencies().get(15, TimeUnit.SECONDS); | ||
| assertEquals(2, result.rows().size()); | ||
| var ids = result.rows().stream().map(row -> row.id()).filter(id -> id != null).sorted().toList(); | ||
|
|
||
| assertEquals(java.util.List.of("alpha", "beta"), ids); | ||
| assertTrue(result.dependencies().stream().anyMatch(SessionTodosChangedTest::isBetaDependsOnAlpha), | ||
| "Should contain beta -> alpha dependency"); | ||
|
|
||
| session.close(); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isBetaDependsOnAlpha(PlanSqlTodoDependency dependency) { | ||
| return "beta".equals(dependency.todoId()) && "alpha".equals(dependency.dependsOn()); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible contributor to the known Java test failure: no post-send event wait
The
session.todos_changedevent can fire asynchronously aftersendAndWaitreturns (e.g., once the runtime finishes persisting state). The .NET, Go, and Rust tests guard against this by setting up an explicit awaitable before the send and then awaiting it after with a timeout:This test checks
eventsimmediately aftersendAndWaitwith no additional wait. If the Java SDK'ssession.todos_changednotification arrives slightly after the response is received (which the PR description hints at), theassertTruewill fail even though the event does eventually arrive. Consider using a polling-wait or aCompletableFuture-based listener pattern similar toGetNextEventOfTypeAsyncin .NET.