Merge branch 'fix/setup-bundle': .titano project files, per-machine server, services and Run entries handled by setup, per-product data removal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
49 files changed
+2741
-128
No files matched your search
@@ -0,0 +1,207 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Titano.App.DesignTime;
|
||||
using Titano.App.Editor;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Shell;
|
||||
using Titano.App.Tests.Windows;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Testing;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Theming;
|
||||
|
||||
namespace Titano.App.Tests.Editor;
|
||||
|
||||
/// <summary>
|
||||
/// <c>.titano</c> project files (BRIEF §18) in the real main window on the editor sample: the editor saves one, and
|
||||
/// opening one shows its sequence with the file's settings as one undo step, or says in one sentence why not.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(300_000)]
|
||||
public sealed class ProjectFilesTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public Task AProjectFileSavesAndOpensItsSequenceWithItsSettings() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
var folder = context.CreateTempDirectory("project-files");
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
UiLanguage.Apply("en");
|
||||
ThemeManager.Apply(AppTheme.Dark);
|
||||
var services = new AppServices(environment, new AppSettings { Language = "en", FirstRunCompleted = true }, () => { }, new FolderDialogs(folder));
|
||||
var sample = SampleData.Configure(services);
|
||||
var shell = new ShellViewModel(services);
|
||||
var toasts = new List<Toast>();
|
||||
shell.PendingToasts.CollectionChanged += (_, e) => toasts.AddRange(e.NewItems?.OfType<Toast>() ?? []);
|
||||
var window = new MainWindow(shell)
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||
Left = -20000,
|
||||
Top = -20000,
|
||||
Width = 1200,
|
||||
Height = 788,
|
||||
ShowActivated = false,
|
||||
ShowInTaskbar = false,
|
||||
};
|
||||
window.Show();
|
||||
try
|
||||
{
|
||||
await sample.OpenEmptyAsync();
|
||||
await shell.StartAsync();
|
||||
var id = await sample.FillEditorAsync();
|
||||
var files = new ProjectFiles(shell);
|
||||
|
||||
// Saved under the sequence's title, never over an earlier file.
|
||||
var editor = Assert.NotNull(await shell.Sequence.ShowAsync(id));
|
||||
await files.SaveAsync(editor.Session);
|
||||
await files.SaveAsync(editor.Session);
|
||||
var path = Path.Combine(folder, "Harbour sunset.titano");
|
||||
Assert.FileExists(path);
|
||||
Assert.FileExists(Path.Combine(folder, "Harbour sunset (2).titano"));
|
||||
Assert.Equal(Loc.L("Editor.ProjectFile.Saved"), toasts[^1].Title);
|
||||
var bundle = ProjectBundle.Load(path);
|
||||
Assert.Equal(id, bundle.Sequence.Id);
|
||||
Assert.Equal(editor.FrameCount, bundle.Sequence.Frames);
|
||||
Assert.Equal(editor.Session.Project.ToJson(), bundle.Project.ToJson());
|
||||
|
||||
// Opening it with other settings shows the sequence with them, as one step Undo takes back.
|
||||
var before = editor.Session.Project;
|
||||
bundle.ExposureOffset(0.7).Save(path);
|
||||
await files.OpenAsync(path);
|
||||
Assert.Same(editor, shell.Sequence.Editor);
|
||||
Assert.Equal(0.7, editor.Session.Project.Exposure.ExposureOffsetEv);
|
||||
var applied = toasts[^1];
|
||||
Assert.Equal(Loc.L("Editor.ProjectFile.Applied"), applied.Title);
|
||||
Assert.False(applied.IsError);
|
||||
applied.ActionCommand!.Execute(null);
|
||||
Assert.Equal(before.ToJson(), editor.Session.Project.ToJson());
|
||||
|
||||
// A sequence this library does not have, and a file that is not a project: one sentence each.
|
||||
var elsewhere = bundle with
|
||||
{
|
||||
Archive = bundle.Archive with { Id = Guid.CreateVersion7() },
|
||||
Sequence = bundle.Sequence with { Id = Guid.CreateVersion7(), Folder = "2026/elsewhere" },
|
||||
};
|
||||
var missing = Path.Combine(folder, "Elsewhere.titano");
|
||||
elsewhere.Save(missing);
|
||||
await files.OpenAsync(missing);
|
||||
Assert.Equal(Loc.L("Editor.ProjectFile.NotFound"), toasts[^1].Title);
|
||||
Assert.True(toasts[^1].IsError);
|
||||
|
||||
var text = Path.Combine(folder, "notes.titano");
|
||||
await File.WriteAllTextAsync(text, "not a project");
|
||||
await files.OpenAsync(text);
|
||||
Assert.Equal(Loc.L("Editor.ProjectFile.Unreadable"), toasts[^1].Title);
|
||||
Assert.True(toasts[^1].IsError);
|
||||
Assert.Same(editor, shell.Sequence.Editor, "the open sequence stays");
|
||||
await editor.Session.FlushAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
await shell.Sequence.CloseAsync();
|
||||
shell.Dispose();
|
||||
await services.DisposeAsync();
|
||||
environment.DeleteCaptureData();
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void AHandOverMessageRoundTrips()
|
||||
{
|
||||
string[] args = [@"C:\Users\me\Desktop\Harbour sunset.titano"];
|
||||
Assert.SequenceEqual(args, SingleInstance.Decode(SingleInstance.Encode(args))!);
|
||||
Assert.Empty(SingleInstance.Decode(SingleInstance.Encode([]))!);
|
||||
Assert.Null(SingleInstance.Decode("TITANO-UPLOADER/1\nE:\\"u8));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASecondLaunchOnTheSameDataFolderHandsItsFileToTheFirst()
|
||||
{
|
||||
var data = context.CreateTempDirectory("instance");
|
||||
var first = Assert.NotNull(SingleInstance.TryAcquire(data));
|
||||
try
|
||||
{
|
||||
first.Listen();
|
||||
Assert.Null(SingleInstance.TryAcquire(data), "one Titano per data folder");
|
||||
using (var other = SingleInstance.TryAcquire(context.CreateTempDirectory("other-copy")))
|
||||
Assert.NotNull(other, "a portable copy with its own data folder runs on its own");
|
||||
|
||||
// Launches while the first one is still opening its window are kept until the window takes them. The pipe
|
||||
// takes one launch at a time, so once the second hand-over is through, the first one is already waiting.
|
||||
Assert.True(SingleInstance.HandOver(data, [@"D:\Projects\Early.titano"]));
|
||||
Assert.True(SingleInstance.HandOver(data, []));
|
||||
using var received = new System.Collections.Concurrent.BlockingCollection<IReadOnlyList<string>>();
|
||||
first.Receive(received.Add);
|
||||
Assert.True(received.TryTake(out var early, TimeSpan.FromSeconds(10)), "the hand-over that came first is delivered");
|
||||
Assert.SequenceEqual([@"D:\Projects\Early.titano"], early!);
|
||||
Assert.True(received.TryTake(out var show, TimeSpan.FromSeconds(10)), "then the plain launch");
|
||||
Assert.Empty(show!);
|
||||
|
||||
Assert.True(SingleInstance.HandOver(data, [@"D:\Projects\Roof.titano"]));
|
||||
Assert.True(received.TryTake(out var later, TimeSpan.FromSeconds(10)), "the running instance received the hand-over");
|
||||
Assert.SequenceEqual([@"D:\Projects\Roof.titano"], later!);
|
||||
}
|
||||
finally
|
||||
{
|
||||
first.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALaunchWhileTitanoClosesWaitsForItAndStartsInItsPlace()
|
||||
{
|
||||
var data = context.CreateTempDirectory("closing");
|
||||
var first = Assert.NotNull(SingleInstance.TryAcquire(data));
|
||||
first.Listen();
|
||||
first.Receive(_ => { });
|
||||
// Closing: it no longer answers, but it still holds the data folder until its services have stopped.
|
||||
first.StopListening();
|
||||
Assert.False(SingleInstance.HandOver(data, [@"D:\Projects\Roof.titano"]), "a closing Titano takes no file it could not open");
|
||||
Assert.Null(SingleInstance.TryAcquire(data));
|
||||
|
||||
// The next launch waits (the mutex belongs to a thread, so it waits on its own) and gets its turn once the first exits.
|
||||
var next = Task.Run(() =>
|
||||
{
|
||||
using var instance = SingleInstance.WaitForTurn(data, TimeSpan.FromSeconds(20));
|
||||
return instance is not null;
|
||||
});
|
||||
Assert.False(next.Wait(TimeSpan.FromMilliseconds(300)), "it waits while the first one still runs");
|
||||
first.Dispose();
|
||||
Assert.True(next.Wait(TimeSpan.FromSeconds(20)) && next.Result, "it starts once the first one has exited");
|
||||
|
||||
// Nobody exits in time: the launch gives up.
|
||||
var holder = Assert.NotNull(SingleInstance.TryAcquire(data));
|
||||
try
|
||||
{
|
||||
Assert.False(Task.Run(() => SingleInstance.WaitForTurn(data, TimeSpan.FromMilliseconds(200)) is { } got && Dispose(got)).Result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
holder.Dispose();
|
||||
}
|
||||
|
||||
static bool Dispose(SingleInstance instance)
|
||||
{
|
||||
instance.Dispose();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Dialogs that pick one folder and cancel everything else.</summary>
|
||||
private sealed class FolderDialogs(string folder) : IAppDialogs
|
||||
{
|
||||
public string? PickFolder(string title, string? initialFolder = null) => folder;
|
||||
public string? PickJsonFile(string title) => null;
|
||||
public bool Confirm(ConfirmRequest request) => false;
|
||||
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ProjectBundleTestExtensions
|
||||
{
|
||||
/// <summary>The same file with another exposure offset.</summary>
|
||||
public static ProjectBundle ExposureOffset(this ProjectBundle bundle, double ev) =>
|
||||
bundle with { Project = bundle.Project with { Exposure = bundle.Project.Exposure with { ExposureOffsetEv = ev } } };
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using Titano.Core.Packaging;
|
||||
using Titano.Setup.Cli;
|
||||
using Titano.Setup.Engine;
|
||||
using Titano.Setup.Interop;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// What setup leaves behind and what it registers: services and startup entries of the programs it installed, never
|
||||
/// of other programs in the same folder (SETUP-1, SETUP-2), shortcuts another product owns or takes over (SRS-09), the
|
||||
/// Server's all-users scope inside Program Files (SRS-06) and the file type name in setup's language (SRS-04).
|
||||
/// </summary>
|
||||
public sealed class SetupEngineTests(TestContext context)
|
||||
{
|
||||
private const string TestsKey = @"Software\Titano.Tests";
|
||||
|
||||
[Theory]
|
||||
[Case(@"""C:\Program Files\Titano\Titano.Server.exe"" --service", @"C:\Program Files\Titano\Titano.Server.exe")]
|
||||
[Case(@"C:\Program Files\Titano\Titano.Server.exe --service", @"C:\Program Files\Titano\Titano.Server.exe")]
|
||||
[Case(@"""C:\Program Files\dotnet\dotnet.exe"" ""C:\Apps\Titano\Titano.Server.dll"" --service", @"C:\Apps\Titano\Titano.Server.dll")]
|
||||
[Case(@"C:\Windows\system32\svchost.exe -k netsvcs", @"C:\Windows\system32\svchost.exe")]
|
||||
[Case(@"Titano.Uploader.exe --tray", null)]
|
||||
[Case("", null)]
|
||||
public void TheProgramOfACommandLineIsItsFirstFullPath(string commandLine, string? program) =>
|
||||
Assert.Equal(program, CommandProgram.Of(commandLine));
|
||||
|
||||
[Test]
|
||||
public void ServiceStepsTravelToTheElevatedCopyWithTheirServices()
|
||||
{
|
||||
var arguments = new SetupArguments
|
||||
{
|
||||
Services = ServiceActions.Prune | ServiceActions.Start,
|
||||
ServiceNames = ["TitanoServer"],
|
||||
Directory = @"C:\Program Files\Titano",
|
||||
Elevated = true,
|
||||
};
|
||||
var switches = arguments.ToSwitches().ToList();
|
||||
Assert.Contains("/SERVICES=prune,start", switches);
|
||||
Assert.Contains("/NAMES=TitanoServer", switches);
|
||||
var parsed = SetupArguments.Parse(switches);
|
||||
Assert.Equal(arguments.Services, parsed.Services);
|
||||
Assert.Equal(arguments.Directory, parsed.Directory);
|
||||
Assert.SequenceEqual(["TitanoServer"], parsed.ServiceNames!);
|
||||
Assert.True(parsed.Elevated);
|
||||
|
||||
Assert.Equal(ServiceActions.Remove, SetupArguments.Parse(["/SERVICES=Remove", "/NAMES=TitanoServer", "/DIR=C:\\Apps\\Titano"]).Services);
|
||||
// The step acts only on services the unelevated setup named.
|
||||
Assert.Throws<ArgumentException>(() => SetupArguments.Parse(["/SERVICES=stop", "/NAMES=TitanoServer"]));
|
||||
Assert.Throws<ArgumentException>(() => SetupArguments.Parse(["/SERVICES=stop", "/DIR=C:\\Apps\\Titano"]));
|
||||
Assert.Throws<ArgumentException>(() => SetupArguments.Parse(["/SERVICES=kill", "/NAMES=TitanoServer", "/DIR=C:\\Apps\\Titano"]));
|
||||
Assert.Throws<ArgumentException>(() => SetupArguments.Parse(["/SERVICES=none", "/NAMES=TitanoServer", "/DIR=C:\\Apps\\Titano"]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void OnlyTheServicesOfProgramsSetupInstalledAreFound()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("services"), "Apps");
|
||||
var owned = CommandProgram.FullPaths(folder, ["Titano.Server.exe", "Titano.exe", "lib/Titano.Core.dll"]);
|
||||
var keyPath = TestsKey + @"\" + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
using var services = Registry.CurrentUser.CreateSubKey(keyPath, writable: true);
|
||||
Service(services, "TitanoServer", 0x10, $"\"{Path.Combine(folder, "Titano.Server.exe")}\" --service");
|
||||
Service(services, "TitanoServerUnquoted", 0x10, Path.Combine(folder, "TITANO.SERVER.EXE") + " --service");
|
||||
// Another vendor's service, and a driver, that live in the same folder (a shared D:\Apps): never Titano's.
|
||||
Service(services, "OtherVendor", 0x10, $"\"{Path.Combine(folder, "Other", "Other.exe")}\"");
|
||||
Service(services, "OtherBeside", 0x10, $"\"{Path.Combine(folder, "Helper.exe")}\" /run");
|
||||
Service(services, "Driver", 0x1, Path.Combine(folder, "Titano.Server.exe"));
|
||||
using (var deleting = services.CreateSubKey("Deleting", writable: true))
|
||||
{
|
||||
deleting.SetValue("Type", 0x10, RegistryValueKind.DWord);
|
||||
deleting.SetValue("DeleteFlag", 1, RegistryValueKind.DWord);
|
||||
deleting.SetValue("ImagePath", Path.Combine(folder, "Titano.Server.exe"), RegistryValueKind.ExpandString);
|
||||
}
|
||||
|
||||
var found = InstalledServices.Find(services, owned);
|
||||
Assert.SequenceEqual(["TitanoServer", "TitanoServerUnquoted"], found.Select(s => s.Name).Order(StringComparer.Ordinal));
|
||||
Assert.True(found.All(s => s.Program.Equals(Path.Combine(folder, "Titano.Server.exe"), StringComparison.OrdinalIgnoreCase)));
|
||||
Assert.Empty(InstalledServices.Find(services, CommandProgram.FullPaths(folder, ["Titano.exe"])));
|
||||
}
|
||||
finally
|
||||
{
|
||||
DeleteTestKey(keyPath);
|
||||
}
|
||||
|
||||
static void Service(RegistryKey services, string name, int type, string imagePath)
|
||||
{
|
||||
using var key = services.CreateSubKey(name, writable: true);
|
||||
key.SetValue("Type", type, RegistryValueKind.DWord);
|
||||
key.SetValue("ImagePath", imagePath, RegistryValueKind.ExpandString);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AServiceThatIsNotRegisteredNeedsNothing()
|
||||
{
|
||||
var folder = context.CreateTempDirectory("services");
|
||||
// No service starts a program of a fresh folder, and nothing is asked of the Service Control Manager.
|
||||
Assert.Empty(InstalledServices.Find(CommandProgram.FullPaths(folder, ["Titano.Server.exe"])));
|
||||
Assert.Equal(SetupExitCode.Success, InstalledServices.Apply([], ServiceActions.Remove));
|
||||
|
||||
var gone = new InstalledService("TitanoTest" + Guid.NewGuid().ToString("N"), "Titano Server", Path.Combine(folder, "Titano.Server.exe"));
|
||||
Assert.False(InstalledServices.IsRunning(gone));
|
||||
foreach (var action in (ServiceActions[])[ServiceActions.Stop, ServiceActions.Prune, ServiceActions.Start, ServiceActions.Remove])
|
||||
Assert.False(InstalledServices.NeedsWork([gone], action), $"{action} of a service that does not exist");
|
||||
// Applying to it skips it: a service deleted meanwhile is not a failure.
|
||||
Assert.Equal(SetupExitCode.Success, InstalledServices.Apply([gone], ServiceActions.Remove | ServiceActions.Start));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void UninstallRemovesOnlyTheSignInEntriesOfTheProgramsItRemoves()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("startup"), "Apps");
|
||||
var keyPath = TestsKey + @"\" + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
using (var run = Registry.CurrentUser.CreateSubKey(keyPath, writable: true))
|
||||
{
|
||||
run.SetValue("Titano Uploader", $"\"{Path.Combine(folder, "Uploader", "Titano.Uploader.exe")}\" --tray");
|
||||
// A portable Titano unpacked in a subfolder of the same folder: not a program this installation lists.
|
||||
run.SetValue("Titano", $"\"{Path.Combine(folder, "Portable", "Titano.exe")}\" --minimized");
|
||||
// Another program in the same folder, and a copy in a sibling folder.
|
||||
run.SetValue("Other", $"\"{Path.Combine(folder, "Other.exe")}\" --background");
|
||||
run.SetValue("Sibling", $"\"{folder} 2\\Titano.Uploader.exe\"");
|
||||
|
||||
var programs = CommandProgram.FullPaths(folder, ["Titano.exe", "Uploader/Titano.Uploader.exe", "Other.exe"]);
|
||||
Assert.SequenceEqual(["Titano Uploader"], SetupRegistry.DeleteStartupEntries(run, programs));
|
||||
Assert.SequenceEqual(["Other", "Sibling", "Titano"], run.GetValueNames().Order(StringComparer.Ordinal));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
DeleteTestKey(keyPath);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AShortcutTellsWhichProgramItStarts()
|
||||
{
|
||||
var folder = context.CreateTempDirectory("links");
|
||||
var target = Path.Combine(folder, "Product A", "Titano.Uploader.exe");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target)!);
|
||||
File.WriteAllBytes(target, [0x4D, 0x5A]);
|
||||
var link = Path.Combine(folder, "Titano Uploader.lnk");
|
||||
ShellLink.Create(link, target, "Titano Uploader");
|
||||
|
||||
// The shell may store the long form of a short (8.3) temporary path: the same file either way.
|
||||
var stored = Assert.NotNull(ShellLink.TargetOf(link));
|
||||
Assert.Equal(Path.GetFileName(target), Path.GetFileName(stored));
|
||||
Assert.FileExists(stored);
|
||||
var productA = Path.GetDirectoryName(stored)!;
|
||||
Assert.True(CommandProgram.IsPathInside(stored, productA));
|
||||
Assert.False(CommandProgram.IsPathInside(stored, Path.Combine(Path.GetDirectoryName(productA)!, "Product B")));
|
||||
Assert.False(CommandProgram.IsPathInside(stored, productA + " 2"));
|
||||
Assert.Null(ShellLink.TargetOf(Path.Combine(folder, "missing.lnk")));
|
||||
var notALink = Path.Combine(folder, "not a link.lnk");
|
||||
File.WriteAllText(notALink, "plain text");
|
||||
Assert.Null(ShellLink.TargetOf(notALink));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AnUninstalledProductHandsItsShortcutToTheProductThatKeepsTheProgram()
|
||||
{
|
||||
var root = context.CreateTempDirectory("handover");
|
||||
foreach (var product in (string[])["Product A", "Product B"])
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(root, product));
|
||||
File.WriteAllBytes(Path.Combine(root, product, "Titano.Uploader.exe"), [0x4D, 0x5A]);
|
||||
}
|
||||
// A uniquely named shortcut in the user's own Start menu, the only folder setup deletes shortcuts from.
|
||||
var link = Path.Combine(SetupPaths.StartMenu(InstallScope.CurrentUser), "Titano Test " + Guid.NewGuid().ToString("N") + ".lnk");
|
||||
try
|
||||
{
|
||||
ShellLink.Create(link, Path.Combine(root, "Product A", "Titano.Uploader.exe"), "Titano Test");
|
||||
// The folders as the shell stores them (the long form of a short temporary path).
|
||||
var productA = Path.GetDirectoryName(Assert.NotNull(ShellLink.TargetOf(link)))!;
|
||||
var productB = Path.Combine(Path.GetDirectoryName(productA)!, "Product B");
|
||||
var logB = new InstallLog { Product = "Titano Uploader", Version = "1.0.0", Scope = InstallScope.CurrentUser, Files = ["Titano.Uploader.exe"], Shortcuts = [link] };
|
||||
|
||||
// Product B also has the program and lists the shortcut: uninstalling A points it at B's copy.
|
||||
UninstallEngine.DeleteShortcut(link, InstallScope.CurrentUser, productA, [new OtherInstall(productB, logB)]);
|
||||
var handed = Assert.NotNull(ShellLink.TargetOf(link));
|
||||
Assert.Equal("Product B", Path.GetFileName(Path.GetDirectoryName(handed)));
|
||||
|
||||
// Uninstalling A again leaves B's shortcut alone; uninstalling B with nobody left deletes it.
|
||||
UninstallEngine.DeleteShortcut(link, InstallScope.CurrentUser, productA, []);
|
||||
Assert.FileExists(link);
|
||||
UninstallEngine.DeleteShortcut(link, InstallScope.CurrentUser, productB, [new OtherInstall(productA, null)]);
|
||||
Assert.FileMissing(link);
|
||||
|
||||
// A product that does not list the shortcut, or whose folder cannot be read now, takes nothing over.
|
||||
ShellLink.Create(link, Path.Combine(productA, "Titano.Uploader.exe"), "Titano Test");
|
||||
UninstallEngine.DeleteShortcut(link, InstallScope.CurrentUser, productA, [new OtherInstall(productB, new InstallLog { Product = "Titano", Version = "1.0.0", Files = ["Titano.Uploader.exe"] })]);
|
||||
Assert.FileMissing(link);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(link)) File.Delete(link);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void TheServerMakesANewInstallationAnAllUsersOneInsideProgramFiles()
|
||||
{
|
||||
var manifest = Manifest();
|
||||
var plan = InstallPlan.Resolve(manifest, new SetupArguments { Components = ["Titano", "Server"] });
|
||||
Assert.Equal(InstallScope.AllUsers, plan.Scope);
|
||||
Assert.Equal(SetupPaths.DefaultDirectory(InstallScope.AllUsers, manifest.Product), plan.Directory);
|
||||
Assert.True(InstallPlan.IsValidDirectory(manifest, plan.Scope, plan.Directory, plan.Components));
|
||||
|
||||
// A folder standard users can change (C:\Titano, D:\Apps\Titano) would let them replace what the service starts.
|
||||
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
|
||||
var custom = Path.Combine(Path.GetPathRoot(programFiles)!, "Titano");
|
||||
Assert.False(InstallPlan.IsValidDirectory(manifest, InstallScope.AllUsers, custom, ["Titano", "Server"]));
|
||||
Assert.True(InstallPlan.IsValidDirectory(manifest, InstallScope.AllUsers, custom, ["Titano"]));
|
||||
Assert.True(InstallPlan.IsValidDirectory(manifest, InstallScope.CurrentUser, custom, ["Titano"]));
|
||||
Assert.False(InstallPlan.IsValidDirectory(manifest, InstallScope.CurrentUser, Path.Combine(programFiles, "Titano"), ["Server"]));
|
||||
Assert.True(InstallPlan.IsValidDirectory(manifest, InstallScope.AllUsers, Path.Combine(programFiles, "Vendor", "Titano"), ["Server"]));
|
||||
Assert.False(SetupPaths.IsInsideProgramFiles(programFiles), "Program Files itself is shared by every program");
|
||||
Assert.False(SetupPaths.IsInsideProgramFiles(programFiles + " Extra" + Path.DirectorySeparatorChar + "Titano"));
|
||||
|
||||
var desktop = InstallPlan.Resolve(manifest, new SetupArguments { Components = ["Titano"] });
|
||||
Assert.Equal(InstallScope.CurrentUser, desktop.Scope);
|
||||
Assert.True(desktop.CanInstall(manifest.FindComponent("Server")!));
|
||||
|
||||
// A per-user installation upgraded in place keeps its scope, so it cannot take the Server; nor can an
|
||||
// all-users one in a folder outside Program Files.
|
||||
var perUser = desktop with { Existing = new ExistingInstall(InstallScope.CurrentUser, desktop.Directory, "0.9.0") };
|
||||
Assert.False(perUser.CanInstall(manifest.FindComponent("Server")!));
|
||||
Assert.True(perUser.CanInstall(manifest.FindComponent("Titano")!));
|
||||
var elsewhere = desktop with { Existing = new ExistingInstall(InstallScope.AllUsers, custom, "0.9.0") };
|
||||
Assert.False(elsewhere.CanInstall(manifest.FindComponent("Server")!));
|
||||
var protectedFolder = desktop with { Existing = new ExistingInstall(InstallScope.AllUsers, Path.Combine(programFiles, "Titano"), "0.9.0") };
|
||||
Assert.True(protectedFolder.CanInstall(manifest.FindComponent("Server")!));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheProjectFileTypeIsNamedInSetupsLanguage()
|
||||
{
|
||||
var association = new PayloadAssociation { Component = "Titano", Extension = ".titano", ProgId = "Titano.Project", Description = "Titano project", Target = "Titano.exe" };
|
||||
Assert.Equal("Titano project", InstallEngine.FileTypeName(association, CultureInfo.GetCultureInfo("en")));
|
||||
Assert.Equal("Progetto Titano", InstallEngine.FileTypeName(association, CultureInfo.GetCultureInfo("it")));
|
||||
|
||||
var unknown = new PayloadAssociation { Component = "Titano", Extension = ".tlx", ProgId = "Titano.Unknown", Description = "Something else", Target = "Titano.exe" };
|
||||
Assert.Equal("Something else", InstallEngine.FileTypeName(unknown, CultureInfo.GetCultureInfo("it")));
|
||||
}
|
||||
|
||||
/// <summary>Deletes a scratch key under <see cref="TestsKey"/>, and that key too once it is empty.</summary>
|
||||
private static void DeleteTestKey(string keyPath)
|
||||
{
|
||||
Registry.CurrentUser.DeleteSubKeyTree(keyPath, throwOnMissingSubKey: false);
|
||||
bool empty;
|
||||
using (var tests = Registry.CurrentUser.OpenSubKey(TestsKey)) empty = tests is { SubKeyCount: 0, ValueCount: 0 };
|
||||
if (empty) Registry.CurrentUser.DeleteSubKey(TestsKey, throwOnMissingSubKey: false);
|
||||
}
|
||||
|
||||
/// <summary>A manifest under a product name no machine has installed, so the registry holds no installation of it.</summary>
|
||||
private static PayloadManifest Manifest() => new()
|
||||
{
|
||||
Product = "TitanoTest" + Guid.NewGuid().ToString("N")[..12],
|
||||
Version = "1.0.0",
|
||||
Components =
|
||||
[
|
||||
new PayloadComponent { Id = "Titano", DisplayName = "Titano", DefaultSelected = true },
|
||||
new PayloadComponent { Id = "Server", DisplayName = "Titano Server", AllUsersOnly = true },
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using System.IO;
|
||||
using Titano.Setup.Engine;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// "Remove my data" covers only the programs being removed (SRS-05): the desktop app and the Uploader share
|
||||
/// %LOCALAPPDATA%\Titano and its logs folder, and uninstalling one product never deletes what another still uses.
|
||||
/// </summary>
|
||||
public sealed class UserDataPlanTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public void TheDesktopAppsPlanLeavesTheUploadersFiles()
|
||||
{
|
||||
var folder = SampleFolder();
|
||||
var plan = UserDataPlan.Measure(folder, Owners(UserDataOwners.Titano));
|
||||
|
||||
Assert.SequenceEqual(
|
||||
["backups", "cache", "logs" + Path.DirectorySeparatorChar + "titano-20261012.log", "settings.json", "titano.db"],
|
||||
plan.Entries.Select(e => e.Name).Order(StringComparer.Ordinal));
|
||||
Assert.Equal(4000L + 3000 + 300 + 20 + 100, plan.TotalBytes);
|
||||
|
||||
plan.Remove();
|
||||
Assert.SequenceEqual(
|
||||
["logs" + Path.DirectorySeparatorChar + "uploader-20261012.log", "uploader-queue.json", "uploader.json"],
|
||||
Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Select(f => Path.GetRelativePath(folder, f)).Order(StringComparer.Ordinal));
|
||||
Assert.False(Directory.Exists(Path.Combine(folder, "cache")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheUploadersPlanLeavesTheDesktopAppsFilesAndEmptiedFoldersGo()
|
||||
{
|
||||
var folder = SampleFolder();
|
||||
var plan = UserDataPlan.Measure(folder, Owners(UserDataOwners.Uploader));
|
||||
|
||||
Assert.SequenceEqual(
|
||||
["logs" + Path.DirectorySeparatorChar + "uploader-20261012.log", "uploader-queue.json", "uploader.json"],
|
||||
plan.Entries.Select(e => e.Name).Order(StringComparer.Ordinal));
|
||||
|
||||
plan.Remove();
|
||||
Assert.True(File.Exists(Path.Combine(folder, "titano.db")));
|
||||
Assert.True(File.Exists(Path.Combine(folder, "logs", "titano-20261012.log")));
|
||||
Assert.FileMissing(Path.Combine(folder, "uploader.json"));
|
||||
Assert.FileMissing(Path.Combine(folder, "logs", "uploader-20261012.log"));
|
||||
|
||||
// Once the desktop app's data goes too, nothing is left of the folder.
|
||||
UserDataPlan.Measure(folder, Owners(UserDataOwners.Titano)).Remove();
|
||||
Assert.False(Directory.Exists(folder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BothProgramsDataIsTheWholeFolderAndNoOwnerIsAnEmptyPlan()
|
||||
{
|
||||
var folder = SampleFolder();
|
||||
var whole = UserDataPlan.Measure(folder, UserDataOwners.All);
|
||||
Assert.SequenceEqual(
|
||||
["backups", "cache", "logs", "settings.json", "titano.db", "uploader-queue.json", "uploader.json"],
|
||||
whole.Entries.Select(e => e.Name).Order(StringComparer.Ordinal));
|
||||
Assert.Empty(UserDataPlan.Measure(folder, Owners()).Entries);
|
||||
|
||||
whole.Remove();
|
||||
Assert.False(Directory.Exists(folder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AProductRemovesTheDataOfItsProgramsThatNoOtherInstalledProductHas()
|
||||
{
|
||||
string[] titano = ["Titano", "Uploader", "Server"];
|
||||
string[] uploader = ["Uploader"];
|
||||
|
||||
Assert.SequenceEqual(["Titano", "Uploader"], UserDataOwners.Removable(titano, []).Order(StringComparer.Ordinal));
|
||||
Assert.SequenceEqual(["Titano"], UserDataOwners.Removable(titano, [uploader]).Order(StringComparer.Ordinal));
|
||||
Assert.Empty(UserDataOwners.Removable(uploader, [titano]));
|
||||
Assert.SequenceEqual(["Uploader"], UserDataOwners.Removable(uploader, [["titano"]]));
|
||||
// Titano Server keeps its data elsewhere: a Server-only product removes nothing here.
|
||||
Assert.Empty(UserDataOwners.Removable(["Server"], []));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnInstallationThatCannotBeReadNowKeepsEveryProgramsData()
|
||||
{
|
||||
string[] titano = ["Titano", "Uploader", "Server"];
|
||||
var uploader = new InstallLog { Product = "Titano Uploader", Version = "1.0.0", Components = ["Uploader"] };
|
||||
|
||||
Assert.SequenceEqual(["Titano"], UserDataOwners.RemovableBeside(titano, [new OtherInstall(@"D:\Titano Uploader", uploader)]).Order(StringComparer.Ordinal));
|
||||
// Its drive is offline, its folder is gone or its log is damaged: it may still use the desktop app's index.
|
||||
Assert.Empty(UserDataOwners.RemovableBeside(titano, [new OtherInstall(@"E:\Titano Uploader", null)]));
|
||||
Assert.Empty(UserDataOwners.RemovableBeside(titano, [new OtherInstall(null, null)]));
|
||||
}
|
||||
|
||||
private static HashSet<string> Owners(params string[] owners) => new(owners, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private string SampleFolder()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("userdata"), "Titano");
|
||||
Write(folder, "titano.db", 4000);
|
||||
Write(folder, "settings.json", 20);
|
||||
Write(folder, Path.Combine("cache", "proxies", "a.jpg"), 3000);
|
||||
Write(folder, Path.Combine("backups", "titano-1.db"), 100);
|
||||
Write(folder, Path.Combine("logs", "titano-20261012.log"), 300);
|
||||
Write(folder, Path.Combine("logs", "uploader-20261012.log"), 200);
|
||||
Write(folder, "uploader.json", 10);
|
||||
Write(folder, "uploader-queue.json", 50);
|
||||
return folder;
|
||||
}
|
||||
|
||||
private static void Write(string folder, string relative, int bytes)
|
||||
{
|
||||
var path = Path.Combine(folder, relative);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
File.WriteAllBytes(path, new byte[bytes]);
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,6 @@
|
||||
<ProjectReference Include="..\Titano.Testing\Titano.Testing.csproj" />
|
||||
<ProjectReference Include="..\..\src\Titano.App\Titano.App.csproj" />
|
||||
<ProjectReference Include="..\..\src\Titano.Uploader\Titano.Uploader.csproj" />
|
||||
<ProjectReference Include="..\..\src\Titano.Setup\Titano.Setup.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,104 @@
|
||||
using Titano.Core.Project;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Project;
|
||||
|
||||
/// <summary>The <c>.titano</c> project file (BRIEF §18): a sequence reference plus the settings to open it with.</summary>
|
||||
public sealed class ProjectBundleTests(TestContext context)
|
||||
{
|
||||
private static readonly Guid ArchiveId = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
|
||||
private static readonly Guid SequenceId = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a02");
|
||||
|
||||
[Test]
|
||||
public void ARoundTripKeepsTheReferenceAndTheSettings()
|
||||
{
|
||||
var bundle = Sample();
|
||||
var path = Path.Combine(context.CreateTempDirectory("bundle"), ProjectBundle.FileNameFor("Harbour sunset"));
|
||||
bundle.Save(path);
|
||||
|
||||
var back = ProjectBundle.Load(path);
|
||||
Assert.Equal(bundle.Archive, back.Archive);
|
||||
Assert.Equal(bundle.Sequence, back.Sequence);
|
||||
Assert.Equal(bundle.Saved, back.Saved);
|
||||
Assert.Equal(bundle.Project.ToJson(), back.Project.ToJson());
|
||||
Assert.Equal(0.8, back.Project.Exposure.DeflickerStrength.Resolve(1.0));
|
||||
Assert.SequenceEqual([3, 7], back.Project.ExcludedFrames);
|
||||
|
||||
var json = File.ReadAllText(path);
|
||||
Assert.Contains("\"format\": \"titano-project\"", json);
|
||||
Assert.Contains("\"formatVersion\": 1", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OtherFilesAreRefusedAsNotProjectFiles()
|
||||
{
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse("not json"));
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse("[1, 2]"));
|
||||
// The archive's own meta files are JSON too, but not project files.
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse("""{ "schemaVersion": 1, "id": "0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01" }"""));
|
||||
var json = Sample().ToJson();
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"formatVersion\": 1", "\"formatVersion\": 2", StringComparison.Ordinal)));
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace(SequenceId.ToString(), "not-a-guid", StringComparison.Ordinal)));
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"version\": 1", "\"version\": 99", StringComparison.Ordinal)));
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"folder\"", "\"place\"", StringComparison.Ordinal)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFileTooLargeToBeAProjectIsNotRead()
|
||||
{
|
||||
var path = Path.Combine(context.CreateTempDirectory("bundle"), "huge.titano");
|
||||
using (var stream = File.Create(path)) stream.SetLength(ProjectBundle.MaxBytes + 1L);
|
||||
Assert.Throws<InvalidDataException>(() => ProjectBundle.Load(path));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FramePositionsApplyOnlyToTheFramesTheyWereSavedFor()
|
||||
{
|
||||
var bundle = Sample();
|
||||
var current = new ProjectSettings
|
||||
{
|
||||
ExcludedFrames = [1],
|
||||
HeroFrame = 2,
|
||||
Camera = new CameraSettings { Keyframes = [new CameraKey(0, 0.5, 0.5, 1, 0)] },
|
||||
};
|
||||
|
||||
Assert.Same(bundle.Project, bundle.ProjectFor(current, frameCount: 3600));
|
||||
|
||||
var changed = bundle.ProjectFor(current, frameCount: 3610);
|
||||
Assert.SequenceEqual([1], changed.ExcludedFrames);
|
||||
Assert.Equal(2, changed.HeroFrame);
|
||||
Assert.Same(current.Camera.Keyframes, changed.Camera.Keyframes);
|
||||
// Everything else comes from the file.
|
||||
Assert.Equal(0.8, changed.Exposure.DeflickerStrength.Resolve(1.0));
|
||||
Assert.Equal(bundle.Project.Camera.Crop, changed.Camera.Crop);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("Harbour sunset", "Harbour sunset.titano")]
|
||||
[Case("Roof: 12/03 \"storm\"?", "Roof_ 12_03 _storm__.titano")]
|
||||
[Case("CON", "_CON.titano")]
|
||||
[Case(" ", "Titano.titano")]
|
||||
public void TheFileNameComesFromTheTitle(string title, string expected) => Assert.Equal(expected, ProjectBundle.FileNameFor(title));
|
||||
|
||||
[Test]
|
||||
public void SavingNeverReplacesAnEarlierProjectFile()
|
||||
{
|
||||
var folder = context.CreateTempDirectory("bundle");
|
||||
Assert.Equal(Path.Combine(folder, "Harbour sunset.titano"), ProjectBundle.FreePathIn(folder, "Harbour sunset"));
|
||||
File.WriteAllText(Path.Combine(folder, "Harbour sunset.titano"), "{}");
|
||||
Directory.CreateDirectory(Path.Combine(folder, "Harbour sunset (2).titano"));
|
||||
Assert.Equal(Path.Combine(folder, "Harbour sunset (3).titano"), ProjectBundle.FreePathIn(folder, "Harbour sunset"));
|
||||
}
|
||||
|
||||
private static ProjectBundle Sample() => new(
|
||||
new BundleArchive(ArchiveId, "Main archive", @"D:\Timelapse"),
|
||||
new BundleSequence(SequenceId, "2026/2026-09-28 Harbour sunset", "Harbour sunset", 3600),
|
||||
new ProjectSettings
|
||||
{
|
||||
Exposure = new ExposureSettings { DeflickerStrength = new Auto<double>().WithManual(0.8) },
|
||||
Camera = new CameraSettings { Crop = [0.1, 0.1, 0.9, 0.9], Keyframes = [new CameraKey(120, 0.4, 0.5, 1.2, 0)] },
|
||||
ExcludedFrames = [3, 7],
|
||||
HeroFrame = 1800,
|
||||
},
|
||||
new DateTimeOffset(2026, 10, 12, 9, 30, 0, TimeSpan.Zero));
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Tests.Infrastructure;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Data.Tests.Processing;
|
||||
|
||||
/// <summary>A <c>.titano</c> project file names a sequence of this index, found again by id or by its folder (BRIEF §18).</summary>
|
||||
public abstract class ProjectBundlesTests(TestContext context) : RepositoryTest(context)
|
||||
{
|
||||
[Test]
|
||||
public async Task TheFileNamesTheSequenceAndItsArchive()
|
||||
{
|
||||
var db = await OpenTitanoAsync();
|
||||
var archive = TestData.Archive("Main");
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
var sequence = TestData.Sequence(archive.Id, title: "Harbour sunset");
|
||||
await db.Sequences.UpsertAsync(sequence, Ct);
|
||||
var project = new ProjectSettings { ExcludedFrames = [2] };
|
||||
|
||||
var bundle = await ProjectBundles.CreateAsync(db, sequence.Id, project, frames: 120, Ct);
|
||||
|
||||
Assert.Equal(new BundleArchive(archive.Id, "Main", archive.RootPath), bundle.Archive);
|
||||
Assert.Equal(new BundleSequence(sequence.Id, sequence.Folder, "Harbour sunset", 120), bundle.Sequence);
|
||||
Assert.Same(project, bundle.Project);
|
||||
Assert.Equal(sequence.Id, (await ProjectBundles.ResolveAsync(db, ProjectBundle.Parse(bundle.ToJson()), Ct))!.Id);
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => ProjectBundles.CreateAsync(db, Guid.CreateVersion7(), project, 0, Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceWithANewIdIsFoundByItsFolderInTheSameArchive()
|
||||
{
|
||||
var db = await OpenTitanoAsync();
|
||||
var archive = TestData.Archive("Main");
|
||||
var other = TestData.Archive("Other");
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
await db.Archives.UpsertAsync(other, Ct);
|
||||
var adoptedAgain = TestData.Sequence(archive.Id) with { Folder = "2026/2026-09-28 Harbour" };
|
||||
var elsewhere = TestData.Sequence(other.Id) with { Folder = "2026/2026-09-28 Roof" };
|
||||
await db.Sequences.UpsertAsync(adoptedAgain, Ct);
|
||||
await db.Sequences.UpsertAsync(elsewhere, Ct);
|
||||
|
||||
var bundle = Bundle(archive.Id, Guid.CreateVersion7(), "2026/2026-09-28 HARBOUR");
|
||||
Assert.Equal(adoptedAgain.Id, (await ProjectBundles.ResolveAsync(db, bundle, Ct))!.Id);
|
||||
|
||||
// A folder of another archive, an unknown folder or an archive this index does not have: not found.
|
||||
Assert.Null(await ProjectBundles.ResolveAsync(db, Bundle(archive.Id, Guid.CreateVersion7(), "2026/2026-09-28 Roof"), Ct));
|
||||
Assert.Null(await ProjectBundles.ResolveAsync(db, Bundle(archive.Id, Guid.CreateVersion7(), "2025/missing"), Ct));
|
||||
Assert.Null(await ProjectBundles.ResolveAsync(db, Bundle(Guid.CreateVersion7(), Guid.CreateVersion7(), "2026/2026-09-28 Harbour"), Ct));
|
||||
}
|
||||
|
||||
private static ProjectBundle Bundle(Guid archiveId, Guid sequenceId, string folder) =>
|
||||
new(new BundleArchive(archiveId, "Main", null), new BundleSequence(sequenceId, folder, "Harbour", 10), new ProjectSettings(), TestData.Now);
|
||||
}
|
||||
|
||||
public sealed class SqliteProjectBundlesTests(TestContext context) : ProjectBundlesTests(context)
|
||||
{
|
||||
protected override Backend Backend => Backend.SqliteMemory;
|
||||
}
|
||||
|
||||
[RequiresEnvironment(PgTestServer.Variable)]
|
||||
public sealed class PostgresProjectBundlesTests(TestContext context) : ProjectBundlesTests(context)
|
||||
{
|
||||
protected override Backend Backend => Backend.Postgres;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Titano.Testing;
|
||||
using Titano.Tools.Commands;
|
||||
|
||||
namespace Titano.Tools.Tests;
|
||||
|
||||
/// <summary>Release notes from Conventional Commits (BRIEF §19.3), as release.yml renders them with a title.</summary>
|
||||
public sealed class ChangelogCommandTests
|
||||
{
|
||||
[Test]
|
||||
public void EntriesAreGroupedByTypeUnderTheTitle()
|
||||
{
|
||||
var notes = ChangelogCommand.Render(["abc1234\tfeat(editor): save the project as a .titano file", "def5678\tfix: keep user data", "0a1b2c3\tchore: bump"], "Titano 1.2.0");
|
||||
Assert.Equal(
|
||||
"# Titano 1.2.0\n\n### Added\n- **editor**: save the project as a .titano file (abc1234)\n\n### Fixed\n- keep user data (def5678)\n\n",
|
||||
notes.ReplaceLineEndings("\n"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATitledReleaseWithoutListedChangesSaysItIsAMaintenanceRelease()
|
||||
{
|
||||
string[] lines = ["abc1234\tchore: bump", "def5678\tci: cache", "0a1b2c3\ttest(setup): cover uninstall", "not a conventional subject"];
|
||||
Assert.Equal("# Titano 1.2.1\n\nMaintenance release.\n", ChangelogCommand.Render(lines, "Titano 1.2.1").ReplaceLineEndings("\n"));
|
||||
Assert.Equal("Maintenance release.\n", ChangelogCommand.Render(lines, null).ReplaceLineEndings("\n"));
|
||||
Assert.Equal("Maintenance release.\n", ChangelogCommand.Render([], null).ReplaceLineEndings("\n"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABreakingChangeOfAnUnlistedTypeIsStillWritten()
|
||||
{
|
||||
var notes = ChangelogCommand.Render(["abc1234\trefactor(core)!: rename the archive layout"], "Titano 2.0.0").ReplaceLineEndings("\n");
|
||||
Assert.Equal("# Titano 2.0.0\n\n### Breaking changes\n- **core**: rename the archive layout (abc1234)\n\n", notes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Titano.Core.Packaging;
|
||||
using Titano.Testing;
|
||||
using Titano.Tools.Commands;
|
||||
|
||||
namespace Titano.Tools.Tests;
|
||||
|
||||
/// <summary>pack-installer writes the components, shortcuts and file types setup installs (BRIEF §18).</summary>
|
||||
public sealed class PackInstallerCommandTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task TheServerInstallsOnlyForAllUsersAndTitanoOwnsTheProjectFileType()
|
||||
{
|
||||
var root = context.CreateTempDirectory("pack");
|
||||
var stub = Path.Combine(root, "Titano.Setup.exe");
|
||||
var bytes = new byte[4096];
|
||||
new Random(5).NextBytes(bytes);
|
||||
"MZ"u8.CopyTo(bytes);
|
||||
await File.WriteAllBytesAsync(stub, bytes);
|
||||
var app = Program(root, "app", "Titano.exe");
|
||||
var server = Program(root, "server", "Titano.Server.exe");
|
||||
var output = Path.Combine(root, "out", "Titano-Setup.exe");
|
||||
|
||||
Assert.Equal(0, await new PackInstallerCommand().RunAsync(
|
||||
["--setup", stub, "--product", "Titano", "--version", "1.2.3", "--component", "Titano=" + app, "--component", "Server=" + server, "--out", output]));
|
||||
|
||||
using var reader = PayloadReader.Open(output);
|
||||
var manifest = reader.Manifest;
|
||||
Assert.False(manifest.FindComponent("Titano")!.AllUsersOnly);
|
||||
var serverComponent = manifest.FindComponent("Server")!;
|
||||
Assert.True(serverComponent.AllUsersOnly);
|
||||
Assert.False(serverComponent.DefaultSelected);
|
||||
var association = Assert.Contains(manifest.Associations, a => a.Extension == ".titano");
|
||||
Assert.Equal("Titano.Project", association.ProgId);
|
||||
Assert.Equal("Titano.exe", association.Target);
|
||||
Assert.Equal("Titano", association.Component);
|
||||
}
|
||||
|
||||
private static string Program(string root, string folder, string name)
|
||||
{
|
||||
var dir = Directory.CreateDirectory(Path.Combine(root, folder)).FullName;
|
||||
File.WriteAllText(Path.Combine(dir, name), "MZ " + name);
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user