Files
Chronos/tests/Titano.Core.Tests/Foundation/StartupCommandTests.cs
T
Claude 97c6484c74 fix(app): Start with Windows belongs to the copy that set it; the uninstaller removes sign-in entries
The client's HKCU Run value now counts as on only when it starts this executable, so a portable copy, a
second install or a development build no longer shows the box ticked, and starting one no longer rewrites the
entry to itself. Refresh only follows an entry whose program an update renamed in this copy's folder, and
unticking removes only this copy's entry. Portable copies keep the choice in memory and hide the Startup row,
since they leave nothing in the registry.

The uninstaller removes the client's and the Uploader's sign-in entries when they start a program of the folder
it removes. StartupCommand in Titano.Core holds the Run key, the value names and the command parsing shared by
both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-12 10:35:13 +00:00

59 lines
3.3 KiB
C#

using Titano.Core.IO;
using Titano.Testing;
namespace Titano.Core.Tests.Foundation;
/// <summary>The sign-in entries of the client and the Uploader: which copy they start, and which folder the uninstaller may clean.</summary>
public sealed class StartupCommandTests
{
private const string Installed = @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.exe";
[Test]
public void TheCommandNamesItsProgram()
{
var command = StartupCommand.Format(Installed, "--minimized");
Assert.Equal("\"" + Installed + "\" --minimized", command);
Assert.Equal(Installed, StartupCommand.Executable(command));
Assert.Equal(@"C:\Users\ada\AppData\Local\Programs\Titano", StartupCommand.Folder(command));
// Written by hand or by an older tool: unquoted, or with spaces around.
Assert.Equal(@"D:\Titano\Titano.exe", StartupCommand.Executable(@" D:\Titano\Titano.exe --minimized "));
Assert.Equal(@"D:\Titano\Titano.exe", StartupCommand.Executable(@"D:\Titano\Titano.exe"));
Assert.Null(StartupCommand.Executable(null));
Assert.Null(StartupCommand.Executable(" "));
Assert.Null(StartupCommand.Executable("\"unterminated --minimized"));
Assert.Null(StartupCommand.Executable("\"\" --minimized"));
Assert.Null(StartupCommand.Folder("Titano.exe"));
Assert.Equal(@"D:\Titano", StartupCommand.FolderOf(@"D:\Titano\Titano.exe"));
}
[Test]
public void AnEntryBelongsToTheCopyItStarts()
{
var command = StartupCommand.Format(Installed, "--minimized");
Assert.True(StartupCommand.Starts(command, Installed));
Assert.True(StartupCommand.Starts(command, Installed.ToUpperInvariant()), "Windows paths ignore case");
// A portable copy on a USB stick, a second install or a development build is another program.
Assert.False(StartupCommand.Starts(command, @"E:\Titano\Titano.exe"));
Assert.False(StartupCommand.Starts(command, @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.exe.old"));
Assert.False(StartupCommand.Starts(command, null));
Assert.False(StartupCommand.Starts(null, Installed));
}
[Test]
public void TheUninstallerRemovesOnlyTheEntriesOfItsFolder()
{
var client = StartupCommand.Format(Installed, "--minimized");
var uploader = StartupCommand.Format(@"C:\Users\ada\AppData\Local\Programs\Titano\Uploader\Titano.Uploader.exe", "--tray");
const string folder = @"C:\Users\ada\AppData\Local\Programs\Titano";
Assert.True(StartupCommand.StartsFrom(client, folder));
Assert.True(StartupCommand.StartsFrom(client, folder + @"\"));
Assert.True(StartupCommand.StartsFrom(uploader, folder.ToLowerInvariant()));
// A sibling folder that shares the name's start, another drive, or nothing at all stay.
Assert.False(StartupCommand.StartsFrom(StartupCommand.Format(@"C:\Users\ada\AppData\Local\Programs\Titano2\Titano.exe", "--minimized"), folder));
Assert.False(StartupCommand.StartsFrom(StartupCommand.Format(@"E:\Titano\Titano.exe", "--minimized"), folder));
Assert.False(StartupCommand.StartsFrom(StartupCommand.Format(folder, "--minimized"), folder));
Assert.False(StartupCommand.StartsFrom(null, folder));
Assert.False(StartupCommand.StartsFrom(client, @"\"));
}
}