merge: desktop settings fixes (V-4, V-6, V-7, V-30, V-31, V-32, V-34, ENG-08)
Merge branch fix2/desktop-settings into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
34 files changed
+1132
-171
No files matched your search
@@ -0,0 +1,82 @@
|
||||
using System.IO;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.Core.Windows.Shell;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Infrastructure;
|
||||
|
||||
/// <summary>BRIEF §6.2: the client's data folder, which is never inside a folder OneDrive synchronises.</summary>
|
||||
public sealed class AppEnvironmentTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public void APortableCopyInOneDriveKeepsItsDataInTheUserFolderAndSaysSo()
|
||||
{
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Desktop", "Titano")).FullName;
|
||||
File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), "");
|
||||
var local = context.CreateTempDirectory("local");
|
||||
|
||||
var environment = AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive]));
|
||||
|
||||
Assert.Equal(Path.Combine(local, "Titano", "titano.db"), environment.DatabasePath);
|
||||
Assert.True(environment.IsPortable, "still a portable copy: updates fetch the portable zip, no sign-in entry");
|
||||
Assert.Equal<string?>(oneDrive, environment.PortableSyncRoot);
|
||||
Assert.Null(environment.SyncedFolder);
|
||||
Assert.Null(environment.EarlierPortableData);
|
||||
Assert.True(Directory.Exists(environment.LogDirectory));
|
||||
Assert.False(Directory.Exists(Path.Combine(app, "data")), "nothing is written into the synchronised folder");
|
||||
|
||||
// Elsewhere (a USB stick) a portable copy keeps its data beside it.
|
||||
var stick = context.CreateTempDirectory("stick");
|
||||
File.WriteAllText(Path.Combine(stick, PortableMode.MarkerFileName), "");
|
||||
var beside = AppEnvironment.From(AppPaths.Resolve(stick, local, [oneDrive]));
|
||||
Assert.Equal(Path.Combine(stick, "data"), beside.DataDirectory);
|
||||
Assert.Null(beside.PortableSyncRoot);
|
||||
Assert.Null(beside.SyncedFolder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheDataAPortableCopyKeptInOneDriveBeforeIsNamedAndLeftAlone()
|
||||
{
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Documents", "Titano")).FullName;
|
||||
File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), "");
|
||||
// An earlier version kept its index and settings beside the program.
|
||||
var earlier = Directory.CreateDirectory(Path.Combine(app, "data")).FullName;
|
||||
File.WriteAllText(Path.Combine(earlier, "settings.json"), "{}");
|
||||
File.WriteAllBytes(Path.Combine(earlier, "titano.db"), [1, 2, 3]);
|
||||
var local = context.CreateTempDirectory("local");
|
||||
|
||||
var environment = AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive]));
|
||||
|
||||
Assert.Equal<string?>(earlier, environment.EarlierPortableData);
|
||||
Assert.Equal(Path.Combine(local, "Titano"), environment.DataDirectory);
|
||||
Assert.SequenceEqual(new byte[] { 1, 2, 3 }, File.ReadAllBytes(Path.Combine(earlier, "titano.db")));
|
||||
Assert.Equal("{}", File.ReadAllText(Path.Combine(earlier, "settings.json")));
|
||||
|
||||
// A data folder with neither (logs only) holds nothing the user would miss.
|
||||
File.Delete(Path.Combine(earlier, "settings.json"));
|
||||
File.Delete(Path.Combine(earlier, "titano.db"));
|
||||
Directory.CreateDirectory(Path.Combine(earlier, "logs"));
|
||||
Assert.Null(AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive])).EarlierPortableData);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AUserFolderOneDriveSynchronisesIsReportedNotHidden()
|
||||
{
|
||||
// Nowhere is safe: Titano starts all the same, and the folder that is synchronised is named for the warning.
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var local = Directory.CreateDirectory(Path.Combine(oneDrive, "AppData", "Local")).FullName;
|
||||
|
||||
var installed = AppEnvironment.From(AppPaths.Resolve(context.CreateTempDirectory("app"), local, [oneDrive]));
|
||||
Assert.Equal<string?>(oneDrive, installed.SyncedFolder);
|
||||
Assert.Null(installed.PortableSyncRoot);
|
||||
Assert.True(Directory.Exists(installed.LogDirectory));
|
||||
|
||||
// A portable copy in that OneDrive has nowhere safe either: its data is not said to be kept outside it.
|
||||
var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Desktop", "Titano")).FullName;
|
||||
File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), "");
|
||||
var portable = AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive]));
|
||||
Assert.Equal<(string?, string?)>((oneDrive, oneDrive), (portable.SyncedFolder, portable.PortableSyncRoot));
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,66 @@ public sealed class AppServicesTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>BRIEF §7: polling follows the archive folder, also one chosen after the start (first run, Settings, relink).</summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void RescansFollowTheArchiveFolderChosenAfterTheStart()
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
try
|
||||
{
|
||||
SingleThreadedContext.Run(async () =>
|
||||
{
|
||||
// The first run: the index opens before any archive folder is set.
|
||||
var settings = new AppSettings { Language = "en" };
|
||||
var services = new AppServices(environment, settings, () => { }, new NoDialogs());
|
||||
try
|
||||
{
|
||||
await services.OpenAsync(environment.DatabasePath);
|
||||
Assert.Null(await services.RescanAsync());
|
||||
// The rescans run all the same: Settings › Archive › Rescan every reaches them.
|
||||
settings.ScanIntervalMinutes = 30;
|
||||
services.SaveSettings();
|
||||
Assert.Equal<TimeSpan?>(TimeSpan.FromMinutes(30), services.PollingPeriod);
|
||||
|
||||
// The first-run dialog creates an archive: the next rescan is of it.
|
||||
var firstRoot = Path.Combine(environment.DataDirectory, "first");
|
||||
await services.ArchiveSetup.CreateAsync(firstRoot);
|
||||
var first = Assert.NotNull(await services.RescanAsync());
|
||||
Assert.Equal("first", first.Name);
|
||||
|
||||
// Settings › Archive moves to another archive, which the index lists after the first one: the next rescan
|
||||
// is of the archive at the folder, no longer of the first one.
|
||||
var other = Path.Combine(environment.DataDirectory, "zeta");
|
||||
await new ArchiveService(services.Database!).CreateAsync(other, "zeta");
|
||||
Assert.Equal("first", (await services.Database!.Archives.ListAsync())[0].Name);
|
||||
async Task<int> ScansOfAsync(Guid archiveId) =>
|
||||
(await services.Database!.Jobs.ListAsync(null, JobKind.Scan)).Items.Count(j => j.TargetIds.Contains(archiveId));
|
||||
var scansOfFirst = await ScansOfAsync(first.Id);
|
||||
settings.LastArchivePath = other;
|
||||
services.SaveSettings();
|
||||
var rescanned = Assert.NotNull(await services.RescanAsync());
|
||||
Assert.Equal("zeta", rescanned.Name);
|
||||
Assert.True(await ScansOfAsync(rescanned.Id) > 0, "the archive at the folder is rescanned");
|
||||
Assert.Equal(scansOfFirst, await ScansOfAsync(first.Id));
|
||||
|
||||
// And back: the folder decides, whatever the order of the index.
|
||||
settings.LastArchivePath = firstRoot;
|
||||
services.SaveSettings();
|
||||
Assert.Equal(first.Id, (await services.RescanAsync())?.Id);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
environment.DeleteCaptureData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>BRIEF §6.2: a restore staged in Settings › Advanced recovers an index that no longer opens.</summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.Core.IO;
|
||||
using Titano.Testing;
|
||||
using Titano.Uploader.Infrastructure;
|
||||
|
||||
namespace Titano.App.Tests.Infrastructure;
|
||||
|
||||
@@ -31,6 +33,77 @@ public sealed class StartWithWindowsTests
|
||||
Assert.False(RunKeyStartWithWindows.Follows(installed, null, Gone));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AnEntryTaskManagerTurnedOffShowsOffUntilTheBoxIsTickedAgain()
|
||||
{
|
||||
// A scratch hive of its own: the user's sign-in entries are never touched.
|
||||
var hive = @"Software\Titano.StartupTests." + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
using var root = Registry.CurrentUser.CreateSubKey(hive, writable: true);
|
||||
var startup = new RunKeyStartWithWindows(Installed, root);
|
||||
startup.SetEnabled(true);
|
||||
Assert.True(startup.IsEnabled);
|
||||
|
||||
// Task Manager › Startup › Disable keeps the Run value and writes the switch apart.
|
||||
TurnOff(root, StartupCommand.ClientValue);
|
||||
Assert.False(startup.IsEnabled, "shown as off");
|
||||
Assert.True(StartupCommand.Starts(Value(root, StartupCommand.RunKey, StartupCommand.ClientValue) as string, Installed), "the command stays");
|
||||
|
||||
// An update renamed the program: the command follows it, and the entry stays off.
|
||||
const string renamed = @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.next.exe";
|
||||
var updated = new RunKeyStartWithWindows(renamed, root);
|
||||
updated.Refresh();
|
||||
Assert.True(StartupCommand.Starts(Value(root, StartupCommand.RunKey, StartupCommand.ClientValue) as string, renamed));
|
||||
Assert.False(updated.IsEnabled, "still off after the update");
|
||||
|
||||
// Ticking the box turns it on again; unticking leaves nothing behind.
|
||||
updated.SetEnabled(true);
|
||||
Assert.True(updated.IsEnabled);
|
||||
Assert.Null(Value(root, StartupApproval.RunKey, StartupCommand.ClientValue));
|
||||
TurnOff(root, StartupCommand.ClientValue);
|
||||
updated.SetEnabled(false);
|
||||
Assert.Null(Value(root, StartupCommand.RunKey, StartupCommand.ClientValue));
|
||||
Assert.Null(Value(root, StartupApproval.RunKey, StartupCommand.ClientValue));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Registry.CurrentUser.DeleteSubKeyTree(hive, throwOnMissingSubKey: false);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void TheUploadersEntryHonoursTaskManagerToo()
|
||||
{
|
||||
var hive = @"Software\Titano.StartupTests." + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
using var root = Registry.CurrentUser.CreateSubKey(hive, writable: true);
|
||||
var uploader = @"C:\Users\ada\AppData\Local\Programs\Titano\Uploader\Titano.Uploader.exe";
|
||||
var startup = new RunKeyStartupRegistration(uploader, root);
|
||||
startup.SetEnabled(true);
|
||||
Assert.True(startup.IsEnabled);
|
||||
|
||||
TurnOff(root, StartupCommand.UploaderValue);
|
||||
Assert.False(startup.IsEnabled, "shown as off");
|
||||
startup.Refresh();
|
||||
Assert.False(startup.IsEnabled, "a refresh keeps it off");
|
||||
|
||||
startup.SetEnabled(true);
|
||||
Assert.True(startup.IsEnabled);
|
||||
TurnOff(root, StartupCommand.UploaderValue);
|
||||
startup.SetEnabled(false);
|
||||
Assert.Null(Value(root, StartupCommand.RunKey, StartupCommand.UploaderValue));
|
||||
Assert.Null(Value(root, StartupApproval.RunKey, StartupCommand.UploaderValue));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Registry.CurrentUser.DeleteSubKeyTree(hive, throwOnMissingSubKey: false);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScreenshotsAndPortableCopiesKeepTheChoiceInMemory()
|
||||
{
|
||||
@@ -42,4 +115,17 @@ public sealed class StartWithWindowsTests
|
||||
startup.SetEnabled(false);
|
||||
Assert.False(startup.IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>What Task Manager writes when the user disables an entry: 0x03, three zero bytes, then when.</summary>
|
||||
private static void TurnOff(RegistryKey root, string name)
|
||||
{
|
||||
using var approved = root.CreateSubKey(StartupApproval.RunKey, writable: true);
|
||||
approved.SetValue(name, new byte[] { 0x03, 0, 0, 0, 0x60, 0x1B, 0x3C, 0x92, 0x8A, 0x3F, 0xDB, 0x01 }, RegistryValueKind.Binary);
|
||||
}
|
||||
|
||||
private static object? Value(RegistryKey root, string subKey, string name)
|
||||
{
|
||||
using var key = root.OpenSubKey(subKey);
|
||||
return key?.GetValue(name);
|
||||
}
|
||||
}
|
||||
@@ -169,6 +169,76 @@ public sealed class SettingsScreenSmokeTests
|
||||
installs[0].Command.Execute(null);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ArchiveRowsEditOnlyTheArchiveAtTheFolderAndKeepEditsMadeWhileItOpens() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var shell = app.Shell;
|
||||
await app.Sample.FillAsync();
|
||||
var settings = shell.Settings;
|
||||
var db = shell.Services.Database!;
|
||||
var archive = Assert.NotNull(await Titano.App.Archiving.CurrentArchive.FindAsync(db, null));
|
||||
var manifestPath = new Titano.Core.Archiving.ArchivePaths(archive.RootPath).ManifestPath;
|
||||
static Titano.Core.Archiving.ArchiveManifest Read(string path) => Titano.Core.Archiving.ManifestStore.ReadArchive(path);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
settings.Page = SettingsPage.Archive;
|
||||
|
||||
// No archive folder: a template edit is this PC's default only, never the first archive of the index. The edit is
|
||||
// made once the rows follow the empty folder, so it cannot wait for anything that would hide a write.
|
||||
settings.ArchiveRoot.Text = string.Empty;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
settings.FolderTemplate.Text = "{camera}/{date}";
|
||||
Assert.True(settings.FolderTemplate.Commit());
|
||||
Assert.Equal("{camera}/{date}", shell.Services.Settings.FolderTemplate);
|
||||
|
||||
// The archive's folder is chosen and a template edited at once, while that archive is still opening: the edit
|
||||
// reaches its archive.json instead of being undone when it opens, and the row shows it.
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
settings.FileTemplate.Text = "{date}_{n:0000}";
|
||||
Assert.True(settings.FileTemplate.Commit());
|
||||
await WaitAsync(() => Read(manifestPath).LayoutTemplates.File == "{date}_{n:0000}", "the edit reached the archive that was opening");
|
||||
await WaitAsync(() => settings.FileTemplate.Text == "{date}_{n:0000}" && shell.Services.Settings.FileTemplate == "{date}_{n:0000}", "the row shows it");
|
||||
Assert.NotEqual("{camera}/{date}", Read(manifestPath).LayoutTemplates.Folder);
|
||||
|
||||
// An edit made before a second folder change, while the first folder's archive is still opening, goes to that
|
||||
// archive: never to the archive at the folder chosen after it.
|
||||
var otherRoot = System.IO.Path.Combine(shell.Services.Environment.DataDirectory, "other-archive");
|
||||
await shell.Services.Archives!.CreateAsync(otherRoot, "Other");
|
||||
var otherManifestPath = new Titano.Core.Archiving.ArchivePaths(otherRoot).ManifestPath;
|
||||
settings.ArchiveRoot.Text = otherRoot;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
settings.FileTemplate.Text = "{date}-{n:0000}";
|
||||
Assert.True(settings.FileTemplate.Commit());
|
||||
settings.ArchiveRoot.Text = otherRoot;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await WaitAsync(() => Read(manifestPath).LayoutTemplates.File == "{date}-{n:0000}", "the edit reached the archive of the folder it was made for");
|
||||
await settings.ArchiveRetarget;
|
||||
Assert.NotEqual("{date}-{n:0000}", Read(otherManifestPath).LayoutTemplates.File);
|
||||
Assert.Equal(Read(otherManifestPath).LayoutTemplates.File, settings.FileTemplate.Text);
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
|
||||
// Offline, only archive.json knows the thumbnail size: this PC's stays instead of becoming the default.
|
||||
Titano.Core.Archiving.ManifestStore.WriteArchive(manifestPath, Read(manifestPath) with { ThumbnailPolicy = new Titano.Core.Archiving.ThumbnailPolicy { LongEdge = 480 } });
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
await WaitAsync(() => shell.Services.Settings.ThumbnailLongEdge == 480, "the archive's thumbnail size is shown");
|
||||
var row = Assert.NotNull(await db.Archives.GetAsync(archive.Id));
|
||||
await db.Archives.UpsertAsync(row with { ProxyLongEdge = 2560 });
|
||||
System.IO.File.Move(manifestPath, manifestPath + ".away");
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
await WaitAsync(() => shell.Services.Settings.ProxyLongEdge == 2560, "the index's proxy size is shown while offline");
|
||||
Assert.Equal(480, shell.Services.Settings.ThumbnailLongEdge);
|
||||
Assert.Equal(480, settings.SelectedThumbnailSize.Value);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
|
||||
@@ -125,6 +125,34 @@ public sealed class UploaderScreenSmokeTests
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task StartWithWindowsShowsWhatTaskManagerLeftWhenTheSettingsOpen() => ScreenHost.RunAsync(() =>
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
var startup = new SignInEntry { IsEnabled = true };
|
||||
var vm = new SampleData().CreateViewModel(startup);
|
||||
Assert.True(vm.StartWithWindows);
|
||||
|
||||
// The Uploader runs for the whole session: Task Manager turns its entry off meanwhile, and the box follows when
|
||||
// the settings open.
|
||||
startup.IsEnabled = false;
|
||||
var changed = new List<string?>();
|
||||
vm.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
|
||||
vm.OpenSettingsCommand.Execute(null);
|
||||
Assert.False(vm.StartWithWindows, "shown as Task Manager left it");
|
||||
Assert.Contains(nameof(MainViewModel.StartWithWindows), changed);
|
||||
vm.CloseSettingsCommand.Execute(null);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
/// <summary>A sign-in entry another program (Task Manager) can turn off.</summary>
|
||||
private sealed class SignInEntry : Titano.Uploader.Infrastructure.IStartupRegistration
|
||||
{
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public void SetEnabled(bool enabled) => IsEnabled = enabled;
|
||||
}
|
||||
|
||||
/// <summary>A <see cref="MainWindow"/> on <see cref="SampleData"/>, shown off screen like <c>--capture</c>.</summary>
|
||||
private sealed class UploaderScreen : IDisposable
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user