Repository navigation
Expose the working directory in target snapshots #882
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
9 commits
Select commit
Hold shift + click to select a range
298df24
Expose target snapshot work root from shared transfer scope
nmetulev 7c3274d
Address snapshot review disposal and nullable guard feedback
nmetulev 28306ce
Resolve push output from the reported guest work root
nmetulev 1959e71
Merge branch 'main' into nmetulev-snapshot-work-root
zateutsch d93378a
Merge branch 'main' into nmetulev-snapshot-work-root
github-actions[bot] 0894f1d
Merge branch 'main' into nmetulev-snapshot-work-root
github-actions[bot] 12fbdd7
Merge branch 'main' into nmetulev-snapshot-work-root
github-actions[bot] ee66a31
Merge branch 'main' into nmetulev-snapshot-work-root
github-actions[bot] 681a914
Merge branch 'main' into nmetulev-snapshot-work-root
github-actions[bot] 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
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
106 changes: 106 additions & 0 deletions
106
src/winapp-CLI/WinApp.Cli.Tests/TargetCaptureCommandTests.Transfer.cs
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,106 @@ | ||
| // Copyright (c) Microsoft Corporation and Contributors. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json; | ||
| using Spectre.Console.Testing; | ||
| using WinApp.Cli.Commands; | ||
| using WinApp.Cli.ExecutionTargets.Abstractions; | ||
| using WinApp.Cli.ExecutionTargets.GuestAgent; | ||
| using WinApp.Cli.ExecutionTargets.Orchestration; | ||
|
|
||
| namespace WinApp.Cli.Tests; | ||
|
|
||
| public partial class TargetCaptureCommandTests | ||
| { | ||
| [TestMethod] | ||
| [DataRow(true)] | ||
| [DataRow(false)] | ||
| public async Task Push_NondefaultRootReportsTheActualDestination(bool json) | ||
| { | ||
| await using var harness = new Harness(GuestWindows()); | ||
| using var console = new TestConsole(); | ||
| console.Profile.Width = 240; | ||
| Directory.CreateDirectory(_root); | ||
| var source = Path.Combine(_root, "probe.txt"); | ||
| await File.WriteAllTextAsync(source, "work-root probe", TestContext.CancellationToken); | ||
| var command = new TargetPushCommand(); | ||
| var arguments = new[] { "sandbox", source, "Setup files/./probe.txt" }; | ||
|
|
||
| Assert.AreEqual(0, await new TargetPushCommand.Handler(harness.Orchestrator, console) | ||
| .InvokeAsync(Parse(command, json ? [.. arguments, "--json"] : arguments), | ||
| TestContext.CancellationToken)); | ||
|
|
||
| var workRoot = new GuestFileService(harness.GuestManaged) | ||
| .ResolveScopeDirectory(TargetFileTransferService.WorkScope, create: false); | ||
| var destination = Path.Combine(workRoot, "Setup files", "probe.txt"); | ||
|
nmetulev marked this conversation as resolved.
|
||
| Assert.AreEqual("work-root probe", | ||
| await File.ReadAllTextAsync(destination, TestContext.CancellationToken)); | ||
| if (json) | ||
| { | ||
| using var document = JsonDocument.Parse(console.Output); | ||
| Assert.AreEqual(destination, document.RootElement.GetProperty("targetPath").GetString()); | ||
| } | ||
| else | ||
| { | ||
| StringAssert.Contains(console.Output, $"to {destination} on sandbox."); | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Push_DirectoryToDotReportsWorkRoot() | ||
| { | ||
| await using var harness = new Harness(GuestWindows()); | ||
| using var console = new TestConsole(); | ||
| Directory.CreateDirectory(_root); | ||
| await File.WriteAllTextAsync(Path.Combine(_root, "probe.txt"), "work-root probe", | ||
|
nmetulev marked this conversation as resolved.
|
||
| TestContext.CancellationToken); | ||
| var command = new TargetPushCommand(); | ||
|
|
||
| Assert.AreEqual(0, await new TargetPushCommand.Handler(harness.Orchestrator, console) | ||
| .InvokeAsync(Parse(command, "sandbox", _root, ".", "--json"), | ||
| TestContext.CancellationToken)); | ||
|
|
||
| var workRoot = new GuestFileService(harness.GuestManaged) | ||
| .ResolveScopeDirectory(TargetFileTransferService.WorkScope, create: false); | ||
| using var document = JsonDocument.Parse(console.Output); | ||
| Assert.AreEqual(workRoot, document.RootElement.GetProperty("targetPath").GetString()); | ||
| Assert.AreEqual("work-root probe", | ||
| await File.ReadAllTextAsync(Path.Combine(workRoot, "probe.txt"), TestContext.CancellationToken)); | ||
|
nmetulev marked this conversation as resolved.
|
||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task Push_MissingManagedRootFailsBeforeWriting() | ||
| { | ||
| await using var harness = new Harness(GuestWindows()); | ||
| harness.Backend.ReportsManagedRoot = false; | ||
| using var console = new TestConsole(); | ||
| Directory.CreateDirectory(_root); | ||
| var source = Path.Combine(_root, "probe.txt"); | ||
|
nmetulev marked this conversation as resolved.
|
||
| await File.WriteAllTextAsync(source, "work-root probe", TestContext.CancellationToken); | ||
| var command = new TargetPushCommand(); | ||
|
|
||
| var result = await CaptureStandardErrorAsync(() => | ||
| new TargetPushCommand.Handler(harness.Orchestrator, console).InvokeAsync( | ||
| Parse(command, "sandbox", source, "probe.txt", "--json"), | ||
| TestContext.CancellationToken)); | ||
|
|
||
| Assert.AreNotEqual(0, result.ExitCode); | ||
| using var error = JsonDocument.Parse(result.StandardError); | ||
| Assert.AreEqual(ExecutionTargetErrorCodes.AgentIncompatible, | ||
| error.RootElement.GetProperty("error").GetProperty("code").GetString()); | ||
| Assert.IsFalse(Directory.Exists(Path.Combine(harness.GuestManaged, "work"))); | ||
|
nmetulev marked this conversation as resolved.
|
||
| Assert.AreEqual(string.Empty, console.Output); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Push_RootedPathAdviceDoesNotInventAGuestRoot() | ||
| { | ||
| var failure = Assert.ThrowsExactly<ExecutionTargetException>(() => | ||
| TargetFileTransferService.NormalizeTargetRelative(@"D:\Managed\work\probe.txt")); | ||
|
|
||
| StringAssert.Contains(failure.Error.Message, "managed work area"); | ||
| StringAssert.Contains(failure.Error.UserAction, "target snapshot"); | ||
| Assert.IsFalse(failure.Error.Message.Contains(@"C:\WinApp", StringComparison.Ordinal)); | ||
| Assert.IsFalse(failure.Error.UserAction!.Contains(@"C:\WinApp", StringComparison.Ordinal)); | ||
| } | ||
| } | ||
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.