Skip to content

Commit 1f35e33

Browse files
ellismgCopilot
andcommitted
Report authoritative cwd in recordContextChange E2E tests
The runtime now treats a local session's cwd as authoritative: it is changed via setWorkingDirectory, and a recordContextChange that reports a divergent cwd is ignored (the RPC still succeeds but emits no session.context_changed event). See github/copilot-agent-runtime#12896. The RPC session-state E2E tests set the working directory to a second directory and then reported a third, divergent cwd while waiting for a session.context_changed event. Under the updated contract that event is never emitted, so the C# test timed out. Report the authoritative current cwd (secondDirectory) instead so the event fires, and update the C#, Node, Python, and Go tests accordingly. The Rust test already reported the authoritative cwd and is unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d99e2065-4f40-4f33-90a6-04b2786ac87f
1 parent bfbaa23 commit 1f35e33

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

dotnet/test/E2E/RpcSessionStateE2ETests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ public async Task Should_Call_Metadata_Snapshot_SetWorkingDirectory_And_RecordCo
278278
{
279279
var firstDirectory = CreateUniqueDirectory();
280280
var secondDirectory = CreateUniqueDirectory();
281-
var contextDirectory = CreateUniqueDirectory();
282281
var branch = $"rpc-context-{Guid.NewGuid():N}";
283282
await using var session = await CreateSessionAsync(new SessionConfig
284283
{
@@ -322,9 +321,12 @@ await TestHelper.WaitForConditionAsync(
322321
TimeSpan.FromSeconds(15),
323322
timeoutDescription: "session.context_changed event after metadata.recordContextChange");
324323

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

340342
var contextChanged = await contextChangedTask;
341-
Assert.True(PathEquals(contextDirectory, contextChanged.Data.Cwd),
342-
$"Expected context cwd '{contextDirectory}', actual '{contextChanged.Data.Cwd}'.");
343+
Assert.True(PathEquals(secondDirectory, contextChanged.Data.Cwd),
344+
$"Expected context cwd '{secondDirectory}', actual '{contextChanged.Data.Cwd}'.");
343345
Assert.True(PathEquals(firstDirectory, contextChanged.Data.GitRoot),
344346
$"Expected context git root '{firstDirectory}', actual '{contextChanged.Data.GitRoot}'.");
345347
Assert.Equal(branch, contextChanged.Data.Branch);

go/internal/e2e/rpc_session_state_e2e_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ func TestRPCSessionStateE2E(t *testing.T) {
482482
t.Run("should call metadata snapshot set working directory and record context change", func(t *testing.T) {
483483
firstDirectory := createUniqueRPCWorkDirectory(t, ctx, "rpc-session-state-first")
484484
secondDirectory := createUniqueRPCWorkDirectory(t, ctx, "rpc-session-state-second")
485-
contextDirectory := createUniqueRPCWorkDirectory(t, ctx, "rpc-session-state-context")
486485
branch := "rpc-context-" + randomHex(t)
487486

488487
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
@@ -532,9 +531,12 @@ func TestRPCSessionStateE2E(t *testing.T) {
532531
hostType := rpc.SessionWorkingDirectoryContextHostTypeGitHub
533532
baseCommit := "0000000000000000000000000000000000000000"
534533
headCommit := "1111111111111111111111111111111111111111"
534+
// For local sessions the CLI treats the session cwd as authoritative, so a
535+
// RecordContextChange that reports a divergent cwd is ignored and emits no event.
536+
// Report the current working directory (secondDirectory) to observe the change.
535537
if _, err := session.RPC.Metadata.RecordContextChange(t.Context(), &rpc.MetadataRecordContextChangeRequest{
536538
Context: rpc.SessionWorkingDirectoryContext{
537-
Cwd: contextDirectory,
539+
Cwd: secondDirectory,
538540
GitRoot: &firstDirectory,
539541
Branch: &branch,
540542
Repository: &repo,
@@ -548,7 +550,7 @@ func TestRPCSessionStateE2E(t *testing.T) {
548550
}
549551
contextChanged := awaitEvent(t, awaitContextChanged)
550552
data := contextChanged.Data.(*copilot.SessionContextChangedData)
551-
assertRPCPathEqual(t, contextDirectory, data.Cwd)
553+
assertRPCPathEqual(t, secondDirectory, data.Cwd)
552554
if data.GitRoot == nil {
553555
t.Fatal("Expected context changed git root")
554556
}

nodejs/test/e2e/rpc_session_state.e2e.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ describe("Session-scoped RPC", async () => {
312312
it("should call metadata snapshot, setWorkingDirectory, and recordContextChange", async () => {
313313
const firstDirectory = createUniqueDirectory(workDir, "rpc-session-state-first");
314314
const secondDirectory = createUniqueDirectory(workDir, "rpc-session-state-second");
315-
const contextDirectory = createUniqueDirectory(workDir, "rpc-session-state-context");
316315
const branch = `rpc-context-${randomUUID()}`;
317316
const session = await client.createSession({
318317
onPermissionRequest: approveAll,
@@ -353,8 +352,11 @@ describe("Session-scoped RPC", async () => {
353352
"session.context_changed event"
354353
);
355354

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

368370
const event = await contextChanged;
369-
expect(pathsEqual(event.data.cwd, contextDirectory)).toBe(true);
371+
expect(pathsEqual(event.data.cwd, secondDirectory)).toBe(true);
370372
expect(pathsEqual(event.data.gitRoot ?? "", firstDirectory)).toBe(true);
371373
expect(event.data.branch).toBe(branch);
372374
expect(event.data.repository).toBe("github/copilot-sdk-e2e");

python/e2e/test_rpc_session_state_e2e.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ async def test_should_call_metadata_snapshot_set_working_directory_and_record_co
259259
):
260260
first_dir = _create_unique_directory(ctx, "metadata-first")
261261
second_dir = _create_unique_directory(ctx, "metadata-second")
262-
context_dir = _create_unique_directory(ctx, "metadata-context")
263262
branch = f"rpc-context-{uuid.uuid4().hex}"
264263

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

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

323325
event = await asyncio.wait_for(context_future, timeout=15.0)
324-
assert _path_equals(context_dir, event.data.cwd)
326+
assert _path_equals(second_dir, event.data.cwd)
325327
assert _path_equals(first_dir, event.data.git_root)
326328
assert event.data.branch == branch
327329
assert event.data.repository == "github/copilot-sdk-e2e"

0 commit comments

Comments
 (0)