Files
Chronos/tests/Chronos.Tools.Tests/PackInstallerCommandTests.cs
T
Alby96andClaude Opus 5.5 7d0c6554a4 feat(setup): one setup for Chronos Desktop and Chronos Uploader
Chronos Server now ships as a Docker image only, so the Windows setup no
longer offers it and the separate Uploader setup goes: one setup installs,
updates, adds and removes Chronos Desktop and Chronos Uploader in place.

- Install log format 2 records each component's files, shortcuts, version
  and SHA-256; format 1 logs (1.0) are still read. A file of a removed
  program that changed since setup installed it is kept, never deleted.
- A Chronos Server 1.0 for Windows installed by 1.0 is retained as "no
  longer offered": its files and service are untouched until the user
  unticks it or explicit /COMPONENTS leave it out; then it is removed with
  its service. A format 1 log keeps every file the payload does not know.
- The separate 1.0 Chronos Uploader product is replaced: the Uploader is
  preselected, its sign-in entry moves to the new copy (Task Manager state
  kept), its shortcut is handed over and the old product is uninstalled.
  An all-users copy under a per-user install stays and is said so.
- The setup window shows the dry-run plan (Changes: adds, removes,
  replaces) before Update; with every program unticked the primary action
  becomes Uninstall. /COMPONENTS=Desktop names the desktop app.
- pack-installer refuses Server (--legacy packs a 1.0 one for the CI test);
  release.yml publishes only Chronos-Setup-<v>.exe and the portable zip;
  the installer test covers add/remove in place, the Uploader replacement
  and the retained Server.

Refs #64

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 13:13:54 +01:00

81 lines
3.8 KiB
C#

using Chronos.Core.Packaging;
using Chronos.Testing;
using Chronos.Tools.Commands;
namespace Chronos.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 TheSetupCarriesTheDesktopAppPreselectedAndTheUploaderToChoose()
{
var root = context.CreateTempDirectory("pack");
var stub = await Stub(root);
var app = Program(root, "app", "Chronos.exe");
var uploader = Program(root, "uploader", "Chronos.Uploader.exe");
var output = Path.Combine(root, "out", "Chronos-Setup.exe");
// "Desktop" names the desktop app, as /COMPONENTS=Desktop does.
Assert.Equal(0, await new PackInstallerCommand().RunAsync(
["--setup", stub, "--product", "Chronos", "--version", "1.2.3", "--component", "Desktop=" + app, "--component", "Uploader=" + uploader, "--out", output]));
using var reader = PayloadReader.Open(output);
var manifest = reader.Manifest;
Assert.SequenceEqual(["Chronos", "Uploader"], manifest.Components.Select(c => c.Id));
var desktop = manifest.FindComponent("Chronos")!;
Assert.True(desktop.DefaultSelected);
Assert.Equal("Chronos Desktop", desktop.DisplayName);
Assert.False(desktop.AllUsersOnly);
Assert.False(manifest.FindComponent("Uploader")!.DefaultSelected);
// The shortcut names that links, pins and the installer test follow stay as in 1.0.
Assert.SequenceEqual(["Chronos", "Chronos Uploader"], manifest.Shortcuts.Select(s => s.Name));
var association = Assert.Contains(manifest.Associations, a => a.Extension == ".chronos");
Assert.Equal("Chronos.Project", association.ProgId);
Assert.Equal("Chronos.exe", association.Target);
Assert.Equal("Chronos", association.Component);
}
[Test]
public async Task TheServerIsPackedOnlyForTheMigrationTest()
{
var root = context.CreateTempDirectory("pack");
var stub = await Stub(root);
var app = Program(root, "app", "Chronos.exe");
var server = Program(root, "server", "Chronos.Server.exe");
var output = Path.Combine(root, "out", "Chronos-Setup.exe");
string[] args = ["--setup", stub, "--product", "Chronos", "--version", "1.0.0", "--component", "Chronos=" + app, "--component", "Server=" + server, "--out", output];
var refused = await Assert.ThrowsAsync<ToolException>(() => new PackInstallerCommand().RunAsync(args));
Assert.Contains("Docker", refused.Message);
Assert.FileMissing(output);
Assert.Equal(0, await new PackInstallerCommand().RunAsync([.. args, "--legacy"]));
using var reader = PayloadReader.Open(output);
var serverComponent = reader.Manifest.FindComponent("Server")!;
Assert.False(serverComponent.DefaultSelected);
// Installable for the current user, so that the test needs no administrator rights.
Assert.False(serverComponent.AllUsersOnly);
var shortcut = Assert.Contains(reader.Manifest.Shortcuts, s => s.Component == "Server");
Assert.Equal("Chronos Server", shortcut.Name);
Assert.False(shortcut.Desktop);
}
private static async Task<string> Stub(string root)
{
var stub = Path.Combine(root, "Chronos.Setup.exe");
var bytes = new byte[4096];
new Random(5).NextBytes(bytes);
"MZ"u8.CopyTo(bytes);
await File.WriteAllBytesAsync(stub, bytes);
return stub;
}
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;
}
}