Public Access
ci / build and test (pull_request) Successful in 2m30s
ci / desktop nightly (pull_request) Skipped
ci / android head (pull_request) Successful in 7m21s
ci / api image (pull_request) Successful in 23s
ci / build and test (push) Successful in 2m28s
ci / android head (push) Successful in 3m27s
ci / desktop nightly (push) Successful in 53s
ci / api image (push) Successful in 36s
Three things the file browser could not do. Somewhere to go had to be walked to, a file that landed under the wrong name could only be removed and sent again, and the listing went on showing the directory as it was before this application put something in it. ◆ THE PATH IS A BOX NOW, not a TextBlock printing where the pane was. A breadcrumb only reaches what is under the directory already listed, so crossing a host's filesystem cost a click and a round trip a level, and a path somebody already knew could not be entered at all. Enter goes; Escape puts back what the pane is really showing. What is typed may be absolute, relative to the directory showing, or start at ~ — the four shapes a shell takes, because somebody typing into a box is typing what they would type into a shell. SftpPath.Resolve turns all of them into one absolute path, and it resolves them here rather than handing a relative path to the server: the server would resolve it against the session's own working directory, which is not necessarily the directory the breadcrumb above the box is showing. `..` is collapsed textually, which differs from cd through a symbolic link; the alternative is a realpath round trip before anything lists. The box holds its own value rather than RemotePath itself. Binding it straight to the path would navigate on every keystroke — `/`, then `/v`, then `/va` — a round trip and a failed listing per character. Every other way of moving writes the real path back into it; a refused listing deliberately does not, because the path that did not resolve is the one worth having in front of you. ◆ RENAME AND MOVE, and DELETE moves to join them. It had been sitting in the pane header beside UP and REFRESH — two things that move the pane and one that destroys a file, in one row — and the three that act on the selected row are now together in a row of their own, under the name of the row they are about. One SFTP rename underneath both new operations and two separate questions on the screen, because the answer is a different kind of thing each time: a rename takes a name and must not take a path, a move takes a directory and must not take a name. One box asking for a destination path would be fewer controls and a worse question — the two mistakes it invites are exactly the ones the split makes impossible. Each form opens on the answer that changes nothing, so what gets edited is the half somebody came to change. Three refusals are made here, and they are the ones a server's message would not explain: a separator in a name (no such file, about a directory nobody meant to name), a destination equal to the source (success, and a file that did not move), and a directory into itself (EINVAL, true and useless). Everything else is the server's — a name already taken, a path that is not there, a mount that cannot be crossed — and arrives in the status line in its own words. Neither is painted in the deletion card's red: a rename is undone by renaming back, and spending that red twice makes it stop meaning anything. ◆ THE LISTING REFRESHES ITSELF when a transfer lands in it. Both panes, since an upload lands on the host and a download lands here and either leaves the pane that is showing that directory a step behind. Only the directory actually on screen: a queue moving a hundred files elsewhere must not be a round trip per file for a listing nobody is looking at. It waits rather than interrupting. Another operation running would have two listings racing for one collection, and re-listing under an open question is how the row somebody answered about stops being the row that gets acted on — so the staleness is remembered and settled at the end of the operation or when the question is dismissed. It says nothing either way: nobody asked for it, and the status line at that moment is carrying the news about the transfer. The selection survives, re-found by path, which is what makes an unasked-for refresh safe to run under somebody's pointer at all. ◆ THE LAYOUT SUITE FOUND A REAL FAULT and the fix is where the height goes. The rename form did not fit the 204 pixels the session shell's own sidebar leaves this pane — MKDIR and the listing were pushed off the bottom. The form is shorter now (the placeholder says what the box wants, so there is no field label above it), and the item row and the breadcrumb step aside while any of the three questions is up, which is what the phone head already did with its own buttons. Measuring also settled something the markup had been claiming and is not true: at that width the listing collapses to nothing under any of the three cards, the deletion card included, and has done since the sidebar arrived. So "the row it is about is still on screen" is retired from the deletion card's remark, and the full path each card carries is what identifies the row instead. Recorded where it is drawn rather than left to be rediscovered. TESTS. SftpPath.Resolve gets the four shapes, ~ with and without a home to expand it to, a blank box, and climbing past the root. ShellFlowTests gets nine against a session that records what it was asked to do — which path was renamed, which directories were listed — rather than against the sentence this code writes about itself: the path box absolute and relative, rename in place, the separator refusal, a move by relative path, the no-op refusal, the three questions displacing each other, and the three rules the automatic refresh follows. The local half is in TransferQueueingTests, where a real folder answers. Two new shapes are measured, and the deletion card's own measurement moves to the connected state — the only state it can be asked in, and the narrow one. What the tests cannot reach is in docs/manual-checks.md as phase 2b: a real server's cross-device and name-taken refusals, and a soft keyboard, which is why the phone's path box has a GO button rather than trusting whatever the IME decided to draw on its return key.
260 lines
9.3 KiB
C#
260 lines
9.3 KiB
C#
using DodoSSH.Client.Ssh;
|
|
|
|
namespace DodoSSH.Client.App.Tests;
|
|
|
|
/// <summary>
|
|
/// An SSH stack that connects to nothing.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The shell suite is about what the view models do, and the real factory would need a reachable
|
|
/// sshd — which <c>DodoSSH.Client.Ssh.Tests</c> already covers against a container. What this makes
|
|
/// testable is everything the connect path does <em>around</em> the connection.
|
|
/// </remarks>
|
|
internal sealed class FakeSshConnectionFactory : ISshConnectionFactory, ISftpSessionFactory
|
|
{
|
|
/// <summary>Thrown instead of connecting, when set. Used for the host-key paths.</summary>
|
|
internal Exception? Failure { get; set; }
|
|
|
|
/// <summary>
|
|
/// Holds a connection open until it is completed, when set.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// A handshake takes as long as a network takes, and connecting is deliberately no longer allowed to
|
|
/// hold the window still while it does — so there is now behaviour that only exists <em>during</em> a
|
|
/// connection: a tab in the strip with no session behind it. This is how a test gets to look at that
|
|
/// moment rather than at the two on either side of it.
|
|
/// </remarks>
|
|
internal TaskCompletionSource? Gate { get; set; }
|
|
|
|
/// <summary>Requests this factory was asked for, in order.</summary>
|
|
internal List<SshConnectionRequest> Requests { get; } = [];
|
|
|
|
/// <summary>Requests for a file-transfer session, in order.</summary>
|
|
/// <remarks>
|
|
/// Kept apart from <see cref="Requests"/> deliberately: file transfer is a separate connection, and a
|
|
/// test asserting that opening a terminal did not also open one would have nothing to look at if the two
|
|
/// shared a list.
|
|
/// </remarks>
|
|
internal List<SshConnectionRequest> SftpRequests { get; } = [];
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ISshConnection> ConnectAsync(
|
|
SshConnectionRequest request,
|
|
IProgress<SshConnectionPhase>? progress,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Requests.Add(request);
|
|
|
|
// Before the gate rather than after it, which is what makes this fake useful for the connecting
|
|
// card: a test that holds Gate open is a connection stuck partway through, and the step list has to
|
|
// show it stuck on a named step rather than on none.
|
|
progress?.Report(SshConnectionPhase.Reaching);
|
|
|
|
if (Gate is { } gate)
|
|
{
|
|
await gate.Task.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
}
|
|
|
|
if (Failure is { } failure)
|
|
{
|
|
throw failure;
|
|
}
|
|
|
|
// Only on the way to succeeding. A failure reported as having authenticated would let a test pass
|
|
// while the card showed a refused connection getting one step further than it did.
|
|
progress?.Report(SshConnectionPhase.CheckingHostKey);
|
|
progress?.Report(SshConnectionPhase.Authenticating);
|
|
|
|
return new FakeSshConnection(request);
|
|
}
|
|
|
|
/// <summary>The file-transfer session this factory last handed out, or null when it never has.</summary>
|
|
/// <remarks>
|
|
/// Kept so a test can read back what the screen actually asked the host to do — which path was renamed,
|
|
/// which was deleted, which directories were listed. The screen reports all three in its own status
|
|
/// line, and a suite that asserted only on that would be checking a sentence this code wrote about
|
|
/// itself rather than the operation it claims to have performed.
|
|
/// </remarks>
|
|
internal FakeSftpSession? OpenedSftp { get; private set; }
|
|
|
|
/// <inheritdoc />
|
|
public Task<ISftpSession> OpenSftpAsync(
|
|
SshConnectionRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
SftpRequests.Add(request);
|
|
|
|
if (Failure is { } failure)
|
|
{
|
|
return Task.FromException<ISftpSession>(failure);
|
|
}
|
|
|
|
OpenedSftp = new FakeSftpSession(request);
|
|
|
|
return Task.FromResult<ISftpSession>(OpenedSftp);
|
|
}
|
|
}
|
|
|
|
/// <summary>A remote filesystem with one directory in it.</summary>
|
|
/// <remarks>
|
|
/// Enough for the shell suite, which is about what the screen does around a session rather than about
|
|
/// moving bytes. The queue's own behaviour is covered against a fuller fake in
|
|
/// <c>DodoSSH.Client.Transfer.Tests</c>, and the real subsystem against a container in
|
|
/// <c>DodoSSH.Client.Ssh.Tests</c>.
|
|
/// </remarks>
|
|
internal sealed class FakeSftpSession(SshConnectionRequest request) : ISftpSession
|
|
{
|
|
/// <inheritdoc />
|
|
public bool IsConnected { get; private set; } = true;
|
|
|
|
/// <inheritdoc />
|
|
public HostKeyPresentation HostKey { get; } =
|
|
new(request.Host, request.Port, "ssh-ed25519", "SHA256:fake");
|
|
|
|
/// <inheritdoc />
|
|
public string Cipher { get; } = "aes256-gcm@openssh.com";
|
|
|
|
/// <inheritdoc />
|
|
public string HomeDirectory => $"/home/{request.Username}";
|
|
|
|
/// <summary>Every directory this session has been asked to list, in order.</summary>
|
|
/// <remarks>
|
|
/// The evidence that a refresh happened at all. A listing whose contents never change — this one always
|
|
/// answers the same single row — leaves no other trace of having been re-read, which is exactly the
|
|
/// thing the automatic refresh after a transfer has to be proved to do.
|
|
/// </remarks>
|
|
internal List<string> Listed { get; } = [];
|
|
|
|
/// <summary>Every rename this session has been asked for, as it was asked.</summary>
|
|
internal List<(string From, string To)> Renamed { get; } = [];
|
|
|
|
/// <summary>Every path this session has been asked to delete.</summary>
|
|
internal List<string> Deleted { get; } = [];
|
|
|
|
/// <inheritdoc />
|
|
public Task<IReadOnlyList<SftpEntry>> ListAsync(string path, CancellationToken cancellationToken)
|
|
{
|
|
Listed.Add(path);
|
|
|
|
return Task.FromResult<IReadOnlyList<SftpEntry>>(
|
|
[
|
|
new SftpEntry(
|
|
"notes.txt",
|
|
SftpPath.Combine(path, "notes.txt"),
|
|
SftpEntryKind.File,
|
|
12,
|
|
DateTimeOffset.UnixEpoch,
|
|
"-rw-r--r--"),
|
|
]);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task<SftpEntry?> StatAsync(string path, CancellationToken cancellationToken) =>
|
|
Task.FromResult<SftpEntry?>(null);
|
|
|
|
/// <inheritdoc />
|
|
public Task<Stream> OpenReadAsync(string path, long offset, CancellationToken cancellationToken) =>
|
|
Task.FromResult<Stream>(new MemoryStream("hello there\n"u8.ToArray(), writable: false));
|
|
|
|
/// <inheritdoc />
|
|
public Task<Stream> OpenWriteAsync(string path, long offset, CancellationToken cancellationToken) =>
|
|
Task.FromResult<Stream>(new MemoryStream());
|
|
|
|
/// <inheritdoc />
|
|
public Task CreateDirectoryAsync(string path, CancellationToken cancellationToken) =>
|
|
Task.CompletedTask;
|
|
|
|
/// <inheritdoc />
|
|
public Task DeleteAsync(string path, CancellationToken cancellationToken)
|
|
{
|
|
Deleted.Add(path);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task RenameAsync(string fromPath, string toPath, CancellationToken cancellationToken)
|
|
{
|
|
Renamed.Add((fromPath, toPath));
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
IsConnected = false;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|
|
|
|
internal sealed class FakeSshConnection(SshConnectionRequest request) : ISshConnection
|
|
{
|
|
/// <inheritdoc />
|
|
public bool IsConnected { get; private set; } = true;
|
|
|
|
/// <inheritdoc />
|
|
public HostKeyPresentation HostKey { get; } =
|
|
new(request.Host, request.Port, "ssh-ed25519", "SHA256:fake");
|
|
|
|
/// <inheritdoc />
|
|
public string Cipher { get; } = "aes256-gcm@openssh.com";
|
|
|
|
/// <inheritdoc />
|
|
public Task<ISshShellSession> OpenShellAsync(
|
|
TerminalSize size,
|
|
CancellationToken cancellationToken) =>
|
|
Task.FromResult<ISshShellSession>(new FakeSshShellSession());
|
|
|
|
/// <inheritdoc />
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
IsConnected = false;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>A shell that is open, silent and never closes on its own.</summary>
|
|
/// <remarks>
|
|
/// <see cref="ReadAsync"/> blocks rather than returning 0. Returning 0 means the remote closed the
|
|
/// channel, which would end the session the moment it was opened and make the test assert against a
|
|
/// connection that had already gone.
|
|
/// </remarks>
|
|
internal sealed class FakeSshShellSession : ISshShellSession
|
|
{
|
|
private readonly CancellationTokenSource closed = new();
|
|
|
|
/// <inheritdoc />
|
|
public bool IsOpen { get; private set; } = true;
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
|
|
{
|
|
using var linked = CancellationTokenSource.CreateLinkedTokenSource(
|
|
cancellationToken, closed.Token);
|
|
|
|
await Task.Delay(Timeout.InfiniteTimeSpan, linked.Token).ConfigureAwait(false);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public ValueTask WriteAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken) =>
|
|
ValueTask.CompletedTask;
|
|
|
|
/// <inheritdoc />
|
|
public void Resize(TerminalSize size)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
IsOpen = false;
|
|
|
|
await closed.CancelAsync().ConfigureAwait(false);
|
|
|
|
closed.Dispose();
|
|
}
|
|
}
|