Files
DodoSSH/tests/DodoSSH.Client.Session.Tests/ClientPathsTests.cs
jaap-jan af0e29a98b Give the desktop a nightly channel, the way the phone has one
ADR 0014 gave the phone a nightly and ADR 0013 rule 3 gave the desktop none, so
the two heads had different answers to the same question — how does somebody try
what is on main? — for no reason except the order the work happened in. This is
the desktop's answer: CI publishes a build from main on every push, and it
installs beside the release one rather than over it.

The phone gets its separation from the platform. Android refuses an update signed
by a different key, so its two channels cannot replace one another whatever
anybody does. Nothing refuses anything here: Velopack applies what its feed serves
and verifies no signature. So all of it is construction, and there are four
separations because each closes a different door.

A pack id each, so the two install in different directories and neither feed's
package can be applied to the other's install. A Velopack channel each —
win and win-nightly — so neither build ever reads the other's release index; the
name reaches the wire as releases.win-nightly.json, which is why the constant in
VelopackUpdateChannel and the argument in ci.yml have to agree or the channel
answers nothing forever with no error. A prerelease flag, so the release channel
cannot see the nightly even by accident. And a profile directory each, which is
the one that is easy to skip and would hurt most: the cache schema is migrated on
every launch, before unlock, so a shared profile means a nightly quietly upgrading
a database the release build then opens. Both are installed at once by design, so
that is an ordinary Tuesday rather than a corner case.

The prerelease flag turns out to be load-bearing across heads as well. The phone's
release channel reads releases/latest, which skips prereleases — so a desktop
nightly published as a stable release would become the newest release in this
repository and every phone on the release channel would start failing its check
against a release carrying no Android manifest.

Which build this is arrives as assembly metadata, the same mechanism and the same
reasoning as the Android head: the updater needs the string rather than a branch,
and a value baked into the assembly is one a crash report can be asked for. Three
things read it — the feed, the prerelease flag, and the profile — and one more
shows it: the titlebar says DodoSSH Nightly. Everything else that distinguishes
the two is somewhere nobody is looking while typing a passphrase into one of them.

The version needed a floor and it is applied to the whole build rather than to the
packaging. MinVer answers 0.0.0-alpha.0.N until the first v* tag and vpk refuses
anything below 0.0.1, so the job lifts the patch digit and keeps the height —
through MinVerVersionOverride, so the assemblies carry the same number the
installer does. Packing a version the assembly disagreed with would put one string
on the preferences screen and another in the feed, which is the screen somebody
reads when asked which nightly they are on.

Two things found by running it rather than reading it. -t:MinVer needs a restore
first, because the target arrives with the package and MSB4057 on a clean checkout
reads like a typo in the workflow rather than a missing restore; the release
script had the same gap and now restores before it reads. And vpk rejects an empty
--packVersion loudly, which is how a broken version handoff announces itself
rather than shipping a package called 1.0.0.

Rule 3 is untouched. The release channel still has no job, no token and no runner,
and the two channels cannot see each other. What a nightly costs is written where
somebody reads it before installing one: whoever can write a release here can put
a build on every nightly machine, which is fine for a build being tried and is not
fine for a build holding somebody's infrastructure credentials.

Verified by running the job's own steps against a clone in a Linux container:
DodoSSH.Desktop.Nightly-win-nightly-Setup.exe, and an index naming pack id
DodoSSH.Desktop.Nightly at 0.0.1-alpha.0.144. The upload itself is the one step
not exercised — it needs a real forge and a write token, and check 16.10 is what
walks the half no runner can.
2026-08-05 22:35:51 +02:00

144 lines
6.3 KiB
C#

namespace DodoSSH.Client.Session.Tests;
/// <summary>
/// Where the profile goes.
/// </summary>
/// <remarks>
/// A short suite for something that looks trivial and is not. The cache is a SQLite file written by one
/// process, and the design assumes each machine has its own — the outbox holds changes only this machine
/// has made. Two machines sharing one file through a cloud sync client corrupts it, so a roaming or
/// synced directory is a correctness problem rather than a matter of taste.
/// </remarks>
public sealed class ClientPathsTests
{
[Fact]
public void TheCacheLivesInsideTheProfileDirectory()
{
var paths = new ClientPaths(Path.Combine("C:", "somewhere", "DodoSSH"));
Path.GetDirectoryName(paths.CacheFile).ShouldBe(paths.DataDirectory);
Path.GetFileName(paths.CacheFile).ShouldBe("cache.db");
}
[Fact]
public void TheDefaultDirectoryIsAbsoluteAndNamed()
{
var paths = ClientPaths.Default;
Path.IsPathFullyQualified(paths.DataDirectory).ShouldBeTrue(paths.DataDirectory);
// OrdinalIgnoreCase, and the casing is the point rather than an oversight. ClientPaths spells the
// folder DodoSSH on Windows and dodossh on Unix on purpose — one follows the platform's title-cased
// convention, the other the lower-case dotfile one. The Ordinal "odoSSH" this used to look for was
// clever enough to survive either spelling of the leading D and still only ever matched Windows,
// which went unnoticed for exactly as long as nothing ran the suite anywhere else.
paths.DataDirectory.Contains("dodossh", StringComparison.OrdinalIgnoreCase)
.ShouldBeTrue($"'{paths.DataDirectory}' should be identifiable as ours");
}
[Fact]
public void ResolvingTheDefault_CreatesNothing()
{
// Read during startup diagnostics and by tests. A side effect here would mean merely asking where
// the cache would go creates a directory.
var paths = new ClientPaths(
Path.Combine(Path.GetTempPath(), $"dodossh-paths-{Guid.CreateVersion7():N}"));
Directory.Exists(paths.DataDirectory).ShouldBeFalse();
paths.EnsureCreated();
try
{
Directory.Exists(paths.DataDirectory).ShouldBeTrue();
// Idempotent, because startup runs it every launch.
paths.EnsureCreated();
}
finally
{
Directory.Delete(paths.DataDirectory, recursive: true);
}
}
/// <summary>
/// The nightly channel keeps its own profile, and everything else keeps the existing one.
/// </summary>
/// <remarks>
/// Both halves are load-bearing and they fail in opposite directions. A nightly sharing the release
/// build's directory would migrate the cache schema of a database the release build then opens — the
/// two are installed at once by design, so that is an ordinary Tuesday. And the release channel's
/// directory moving even slightly would orphan every existing install's cache, outbox and device key:
/// the application would start, find nothing, and ask for a server. See ADR 0013 decision 9.
/// </remarks>
[Theory]
[InlineData("release")]
[InlineData("")]
[InlineData(null)]
[InlineData("something nobody wrote")]
public void EveryChannelButTheNightlyKeepsTheExistingProfile(string? channel)
{
var resolved = ClientPaths.ForChannel(channel).DataDirectory;
// string.Equals with an explicit comparison rather than ShouldBe, here and below: these are paths
// built from the same constants, so the comparison that means anything is the exact one.
string.Equals(resolved, ClientPaths.Default.DataDirectory, StringComparison.Ordinal)
.ShouldBeTrue($"'{channel}' resolved to '{resolved}' rather than to the default profile");
}
[Fact]
public void TheNightlyProfileIsASiblingOfTheReleaseOne()
{
var release = ClientPaths.Default.DataDirectory;
var nightly = ClientPaths.ForChannel("nightly").DataDirectory;
string.Equals(nightly, release, StringComparison.Ordinal)
.ShouldBeFalse($"the nightly and the release build would share '{release}'");
// A sibling rather than a child, so neither install's uninstaller or reset can reach the other's.
string.Equals(
Path.GetDirectoryName(nightly),
Path.GetDirectoryName(release),
StringComparison.Ordinal)
.ShouldBeTrue($"'{nightly}' should sit beside '{release}'");
// And still identifiably ours, on either platform's spelling — the same property the default is
// checked for above, for the same reason.
nightly.Contains("dodossh", StringComparison.OrdinalIgnoreCase)
.ShouldBeTrue($"'{nightly}' should be identifiable as ours");
// The files follow the directory. A nightly writing the release build's cache or device key is the
// whole failure this separation exists to prevent, so it is asserted rather than inferred.
var separated = ClientPaths.ForChannel("nightly");
string.Equals(separated.CacheFile, ClientPaths.Default.CacheFile, StringComparison.Ordinal)
.ShouldBeFalse("the two builds would write one cache.db");
string.Equals(separated.DeviceKeyFile, ClientPaths.Default.DeviceKeyFile, StringComparison.Ordinal)
.ShouldBeFalse("the two builds would share one device key");
}
[Fact]
public void OnWindowsItIsTheLocalProfileAndNotTheRoamingOne()
{
// %APPDATA% roams in a domain environment, which would sync one machine's SQLite cache to another
// and corrupt it. %LOCALAPPDATA% does not.
if (!OperatingSystem.IsWindows())
{
Assert.Skip("Windows-only path convention.");
}
var local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var roaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
ClientPaths.Default.DataDirectory.ShouldStartWith(local);
// Guard against the two happening to be equal on some configuration, which would make the
// assertion above meaningless.
if (!string.Equals(local, roaming, StringComparison.OrdinalIgnoreCase))
{
ClientPaths.Default.DataDirectory.ShouldNotStartWith(roaming);
}
}
}