Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions dotnet/test/E2E/RpcSessionStateE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ public async Task Should_Call_Metadata_Snapshot_SetWorkingDirectory_And_RecordCo
{
var firstDirectory = CreateUniqueDirectory();
var secondDirectory = CreateUniqueDirectory();
var contextDirectory = CreateUniqueDirectory();
var branch = $"rpc-context-{Guid.NewGuid():N}";
await using var session = await CreateSessionAsync(new SessionConfig
{
Expand Down Expand Up @@ -322,9 +321,12 @@ await TestHelper.WaitForConditionAsync(
TimeSpan.FromSeconds(15),
timeoutDescription: "session.context_changed event after metadata.recordContextChange");

// For local sessions the CLI treats the session cwd as authoritative, so a
// recordContextChange that reports a divergent cwd is ignored and emits no event.
// Report the current working directory (secondDirectory) to observe the change.
var context = new SessionWorkingDirectoryContext
{
Cwd = contextDirectory,
Cwd = secondDirectory,
GitRoot = firstDirectory,
Branch = branch,
Repository = "github/copilot-sdk-e2e",
Expand All @@ -338,8 +340,8 @@ await TestHelper.WaitForConditionAsync(
Assert.NotNull(recordResult);

var contextChanged = await contextChangedTask;
Assert.True(PathEquals(contextDirectory, contextChanged.Data.Cwd),
$"Expected context cwd '{contextDirectory}', actual '{contextChanged.Data.Cwd}'.");
Assert.True(PathEquals(secondDirectory, contextChanged.Data.Cwd),
$"Expected context cwd '{secondDirectory}', actual '{contextChanged.Data.Cwd}'.");
Assert.True(PathEquals(firstDirectory, contextChanged.Data.GitRoot),
$"Expected context git root '{firstDirectory}', actual '{contextChanged.Data.GitRoot}'.");
Assert.Equal(branch, contextChanged.Data.Branch);
Expand Down
8 changes: 5 additions & 3 deletions go/internal/e2e/rpc_session_state_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ func TestRPCSessionStateE2E(t *testing.T) {
t.Run("should call metadata snapshot set working directory and record context change", func(t *testing.T) {
firstDirectory := createUniqueRPCWorkDirectory(t, ctx, "rpc-session-state-first")
secondDirectory := createUniqueRPCWorkDirectory(t, ctx, "rpc-session-state-second")
contextDirectory := createUniqueRPCWorkDirectory(t, ctx, "rpc-session-state-context")
branch := "rpc-context-" + randomHex(t)

session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
Expand Down Expand Up @@ -532,9 +531,12 @@ func TestRPCSessionStateE2E(t *testing.T) {
hostType := rpc.SessionWorkingDirectoryContextHostTypeGitHub
baseCommit := "0000000000000000000000000000000000000000"
headCommit := "1111111111111111111111111111111111111111"
// For local sessions the CLI treats the session cwd as authoritative, so a
// RecordContextChange that reports a divergent cwd is ignored and emits no event.
// Report the current working directory (secondDirectory) to observe the change.
if _, err := session.RPC.Metadata.RecordContextChange(t.Context(), &rpc.MetadataRecordContextChangeRequest{
Context: rpc.SessionWorkingDirectoryContext{
Cwd: contextDirectory,
Cwd: secondDirectory,
GitRoot: &firstDirectory,
Branch: &branch,
Repository: &repo,
Expand All @@ -548,7 +550,7 @@ func TestRPCSessionStateE2E(t *testing.T) {
}
contextChanged := awaitEvent(t, awaitContextChanged)
data := contextChanged.Data.(*copilot.SessionContextChangedData)
assertRPCPathEqual(t, contextDirectory, data.Cwd)
assertRPCPathEqual(t, secondDirectory, data.Cwd)
if data.GitRoot == nil {
t.Fatal("Expected context changed git root")
}
Expand Down
8 changes: 5 additions & 3 deletions nodejs/test/e2e/rpc_session_state.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ describe("Session-scoped RPC", async () => {
it("should call metadata snapshot, setWorkingDirectory, and recordContextChange", async () => {
const firstDirectory = createUniqueDirectory(workDir, "rpc-session-state-first");
const secondDirectory = createUniqueDirectory(workDir, "rpc-session-state-second");
const contextDirectory = createUniqueDirectory(workDir, "rpc-session-state-context");
const branch = `rpc-context-${randomUUID()}`;
const session = await client.createSession({
onPermissionRequest: approveAll,
Expand Down Expand Up @@ -353,8 +352,11 @@ describe("Session-scoped RPC", async () => {
"session.context_changed event"
);

// For local sessions the CLI treats the session cwd as authoritative, so a
// recordContextChange that reports a divergent cwd is ignored and emits no event.
// Report the current working directory (secondDirectory) to observe the change.
const context = {
cwd: contextDirectory,
cwd: secondDirectory,
gitRoot: firstDirectory,
branch,
repository: "github/copilot-sdk-e2e",
Expand All @@ -366,7 +368,7 @@ describe("Session-scoped RPC", async () => {
await session.rpc.metadata.recordContextChange({ context });

const event = await contextChanged;
expect(pathsEqual(event.data.cwd, contextDirectory)).toBe(true);
expect(pathsEqual(event.data.cwd, secondDirectory)).toBe(true);
expect(pathsEqual(event.data.gitRoot ?? "", firstDirectory)).toBe(true);
expect(event.data.branch).toBe(branch);
expect(event.data.repository).toBe("github/copilot-sdk-e2e");
Expand Down
8 changes: 5 additions & 3 deletions python/e2e/test_rpc_session_state_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ async def test_should_call_metadata_snapshot_set_working_directory_and_record_co
):
first_dir = _create_unique_directory(ctx, "metadata-first")
second_dir = _create_unique_directory(ctx, "metadata-second")
context_dir = _create_unique_directory(ctx, "metadata-context")
branch = f"rpc-context-{uuid.uuid4().hex}"

session = await ctx.client.create_session(
Expand Down Expand Up @@ -304,10 +303,13 @@ def on_event(event):

unsubscribe = session.on(on_event)
try:
# For local sessions the CLI treats the session cwd as authoritative, so a
# record_context_change that reports a divergent cwd is ignored and emits
# no event. Report the current working directory (second_dir) to observe it.
result = await session.rpc.metadata.record_context_change(
MetadataRecordContextChangeRequest(
context=SessionWorkingDirectoryContext(
cwd=context_dir,
cwd=second_dir,
git_root=first_dir,
branch=branch,
repository="github/copilot-sdk-e2e",
Expand All @@ -321,7 +323,7 @@ def on_event(event):
assert result is not None

event = await asyncio.wait_for(context_future, timeout=15.0)
assert _path_equals(context_dir, event.data.cwd)
assert _path_equals(second_dir, event.data.cwd)
assert _path_equals(first_dir, event.data.git_root)
assert event.data.branch == branch
assert event.data.repository == "github/copilot-sdk-e2e"
Expand Down
Loading