-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add rewind support across all SDKs #2321
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,81 @@ | ||
| // Copyright (c) GitHub, Inc. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using GitHub.Copilot.Rpc; | ||
| using GitHub.Copilot.Test.Harness; | ||
|
|
||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace GitHub.Copilot.Test.E2E; | ||
|
|
||
| public class RewindE2ETests(E2ETestFixture fixture, ITestOutputHelper output) | ||
| : E2ETestBase(fixture, "rewind", output) | ||
| { | ||
| private const string FileName = "rewind-sdk.txt"; | ||
| private const string FileContent = "SDK rewind content"; | ||
|
|
||
| [Fact] | ||
| public async Task Should_Restore_Tracked_File_And_Conversation() | ||
| { | ||
| var filePath = Path.Combine(Ctx.WorkDir, FileName); | ||
| await using var session = await CreateSessionAsync(new SessionConfig | ||
| { | ||
| Model = "claude-sonnet-4.5", | ||
| EnableFileChangeTracking = true, | ||
| }); | ||
|
|
||
| var response = await session.SendAndWaitAsync( | ||
| new MessageOptions | ||
| { | ||
| Prompt = $"Use the create tool to create {FileName} containing exactly {FileContent}. " | ||
| + "After the tool succeeds, reply with exactly SDK_REWIND_DONE.", | ||
| }, | ||
| TimeSpan.FromSeconds(30)); | ||
|
|
||
| Assert.Equal("SDK_REWIND_DONE", response?.Data.Content); | ||
| Assert.True(File.Exists(filePath)); | ||
| Assert.Equal(FileContent, await File.ReadAllTextAsync(filePath)); | ||
|
|
||
| HistoryListRewindPointsResult? rewindPoints = null; | ||
| await TestHelper.WaitForConditionAsync( | ||
| async () => | ||
| { | ||
| rewindPoints = await session.Rpc.History.ListRewindPointsAsync(); | ||
| return rewindPoints.UnavailableReason is null; | ||
| }, | ||
| timeout: TimeSpan.FromSeconds(10), | ||
| timeoutMessage: "Timed out waiting for rewind points to become available.", | ||
| pollInterval: TimeSpan.FromMilliseconds(100)); | ||
|
|
||
| Assert.NotNull(rewindPoints); | ||
| Assert.True(rewindPoints.FileChangeTrackingEnabled); | ||
| var rewindPoint = Assert.Single(rewindPoints.Points); | ||
| Assert.True(rewindPoint.CanRestoreFiles); | ||
| Assert.Equal(1, rewindPoint.FileCount); | ||
|
|
||
| var preview = await session.Rpc.History.PreviewRewindAsync(rewindPoint.EventId); | ||
| Assert.True(preview.Available); | ||
| var previewFile = Assert.Single(preview.Files); | ||
| Assert.Equal( | ||
| Path.GetFullPath(filePath), | ||
| Path.GetFullPath(previewFile.Path), | ||
| OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal); | ||
|
|
||
| var rewind = await session.Rpc.History.RewindAsync( | ||
| rewindPoint.EventId, | ||
| HistoryRewindMode.ConversationAndFiles); | ||
|
|
||
| Assert.Equal(HistoryRewindOutcome.Success, rewind.Outcome); | ||
| Assert.True(rewind.EventsRemoved > 0); | ||
| var restoredFile = Assert.Single(rewind.RestoredFiles); | ||
| Assert.Equal( | ||
| Path.GetFullPath(filePath), | ||
| Path.GetFullPath(restoredFile), | ||
| OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal); | ||
| Assert.False(File.Exists(filePath)); | ||
|
|
||
| var events = await session.GetEventsAsync(); | ||
| Assert.DoesNotContain(events, sessionEvent => sessionEvent.Id.ToString() == rewindPoint.EventId); | ||
| } | ||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.