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
|
||||
{
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using Titano.Core.IO;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
/// <summary>BRIEF §6.2: where the client keeps its index, and never inside a folder OneDrive synchronises.</summary>
|
||||
public sealed class DataLocationTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public void AnInstalledCopyUsesThePerUserFolderAndAPortableOneItsOwn()
|
||||
{
|
||||
var app = context.CreateTempDirectory("app");
|
||||
var local = context.CreateTempDirectory("local");
|
||||
|
||||
var installed = DataLocation.Choose(app, portable: false, local, []);
|
||||
Assert.Equal(new DataLocation(Path.Combine(local, "Titano"), false, null, null), installed);
|
||||
|
||||
var portable = DataLocation.Choose(app, portable: true, local, []);
|
||||
Assert.Equal(new DataLocation(Path.Combine(app, "data"), true, null, null), portable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APortableCopyInASynchronisedFolderKeepsItsDataInThePerUserFolder()
|
||||
{
|
||||
// A portable copy unpacked on a Desktop that OneDrive's folder backup moved into the sync root.
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var app = Path.Combine(oneDrive, "Desktop", "Titano");
|
||||
var local = context.CreateTempDirectory("local");
|
||||
|
||||
var location = DataLocation.Choose(app, portable: true, local, [Path.Combine(context.CreateTempDirectory("other"), "OneDrive"), oneDrive]);
|
||||
|
||||
Assert.Equal(Path.Combine(local, "Titano"), location.Root);
|
||||
Assert.True(location.IsPortable, "still a portable copy (updates, no sign-in entry)");
|
||||
Assert.Equal<string?>(oneDrive, location.PortableSyncRoot);
|
||||
Assert.Null(location.SyncedFolder);
|
||||
|
||||
// A sync root that only shares the start of the name is another folder.
|
||||
var beside = DataLocation.Choose(oneDrive + "Backup", portable: true, local, [oneDrive]);
|
||||
Assert.Equal(new DataLocation(Path.Combine(oneDrive + "Backup", "data"), true, null, null), beside);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APerUserFolderInsideASyncRootIsReported()
|
||||
{
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var local = Path.Combine(oneDrive, "AppData", "Local");
|
||||
|
||||
var installed = DataLocation.Choose(context.CreateTempDirectory("app"), portable: false, local, [oneDrive]);
|
||||
Assert.Equal<string?>(oneDrive, installed.SyncedFolder);
|
||||
|
||||
var portable = DataLocation.Choose(Path.Combine(oneDrive, "Titano"), portable: true, local, [oneDrive]);
|
||||
Assert.Equal<(string, string?, string?)>((Path.Combine(local, "Titano"), oneDrive, oneDrive), (portable.Root, portable.SyncedFolder, portable.PortableSyncRoot));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SyncRootMatchingIsSegmentWiseAndIgnoresCase()
|
||||
{
|
||||
var root = Path.Combine(context.CreateTempDirectory(), "OneDrive");
|
||||
Assert.True(DataLocation.IsUnder(root, root));
|
||||
Assert.True(DataLocation.IsUnder(Path.Combine(root, "Pictures"), root + Path.DirectorySeparatorChar));
|
||||
Assert.True(DataLocation.IsUnder(Path.Combine(root, "x").ToUpperInvariant(), root));
|
||||
Assert.True(DataLocation.IsUnder(@"C:\Users\ada\OneDrive\Desktop\Titano\data", @"c:\users\ada\onedrive"), "Windows paths on any platform");
|
||||
Assert.False(DataLocation.IsUnder(root + "Backup", root));
|
||||
Assert.False(DataLocation.IsUnder(root, string.Empty));
|
||||
Assert.Null(DataLocation.SyncRootOf(root + "Backup", [root]));
|
||||
Assert.Equal<string?>(root, DataLocation.SyncRootOf(Path.Combine(root, "Documents"), ["", root]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Titano.Core.IO;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
/// <summary>The switch Task Manager's Startup tab keeps apart from a sign-in entry's command.</summary>
|
||||
public sealed class StartupApprovalTests
|
||||
{
|
||||
[Test]
|
||||
public void AnOddFirstByteMeansTurnedOff()
|
||||
{
|
||||
// As Task Manager writes them: a state, three zero bytes, then the time it was turned off.
|
||||
Assert.True(StartupApproval.IsTurnedOff([0x03, 0, 0, 0, 0x60, 0x1B, 0x3C, 0x92, 0x8A, 0x3F, 0xDB, 0x01]));
|
||||
Assert.True(StartupApproval.IsTurnedOff([0x01, 0, 0, 0]));
|
||||
Assert.False(StartupApproval.IsTurnedOff([0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
Assert.False(StartupApproval.IsTurnedOff([0x06, 0, 0, 0]));
|
||||
// Never touched in Task Manager, or a value of another type: the entry is on.
|
||||
Assert.False(StartupApproval.IsTurnedOff(null));
|
||||
Assert.False(StartupApproval.IsTurnedOff([]));
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public sealed class AppPathsTests(TestContext context)
|
||||
Assert.Equal(Path.Combine(app, "data"), paths.DataRoot);
|
||||
Assert.Equal(Path.Combine(app, "data", "titano.db"), paths.DatabasePath);
|
||||
Assert.False(paths.IsInSyncedFolder);
|
||||
Assert.Null(paths.PortableSyncRoot);
|
||||
|
||||
paths.CreateDirectories();
|
||||
Assert.True(Directory.Exists(paths.LogsDirectory));
|
||||
@@ -37,13 +38,31 @@ public sealed class AppPathsTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DataInsideOneDriveIsReportedAndRefused()
|
||||
public void APortableCopyInOneDriveKeepsItsDataInLocalAppData()
|
||||
{
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Tools", "Titano")).FullName;
|
||||
File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), "");
|
||||
var local = context.CreateTempDirectory("local");
|
||||
|
||||
var paths = AppPaths.Resolve(app, context.CreateTempDirectory("local"), [oneDrive]);
|
||||
var paths = AppPaths.Resolve(app, local, [oneDrive]);
|
||||
Assert.True(paths.IsPortable);
|
||||
Assert.Equal(Path.Combine(local, "Titano"), paths.DataRoot);
|
||||
Assert.Equal<string?>(oneDrive, paths.PortableSyncRoot);
|
||||
Assert.False(paths.IsInSyncedFolder);
|
||||
paths.CreateDirectories();
|
||||
Assert.True(Directory.Exists(paths.LogsDirectory));
|
||||
Assert.False(Directory.Exists(Path.Combine(app, "data")), "nothing is written into the synchronised folder");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DataInsideOneDriveIsReportedAndRefused()
|
||||
{
|
||||
// Local application data inside a sync root: nowhere is safe, so nothing is created.
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var local = Directory.CreateDirectory(Path.Combine(oneDrive, "AppData", "Local")).FullName;
|
||||
|
||||
var paths = AppPaths.Resolve(context.CreateTempDirectory("app"), local, [oneDrive]);
|
||||
Assert.True(paths.IsInSyncedFolder);
|
||||
Assert.Equal<string?>(oneDrive, paths.SyncedFolder);
|
||||
Assert.Throws<InvalidOperationException>(paths.CreateDirectories);
|
||||
@@ -54,10 +73,7 @@ public sealed class AppPathsTests(TestContext context)
|
||||
public void SyncRootMatchingIsSegmentWise()
|
||||
{
|
||||
var root = Path.Combine(context.CreateTempDirectory(), "OneDrive");
|
||||
Assert.True(OneDriveFolders.IsUnder(root, root));
|
||||
Assert.True(OneDriveFolders.IsUnder(Path.Combine(root, "Pictures"), root + Path.DirectorySeparatorChar));
|
||||
Assert.True(OneDriveFolders.IsUnder(Path.Combine(root, "x").ToUpperInvariant(), root));
|
||||
Assert.False(OneDriveFolders.IsUnder(root + "Backup", root));
|
||||
Assert.Equal<string?>(root, OneDriveFolders.Containing(Path.Combine(root, "Pictures"), [root]));
|
||||
Assert.Null(OneDriveFolders.Containing(root + "Backup", [root]));
|
||||
}
|
||||
|
||||
@@ -68,8 +84,10 @@ public sealed class AppPathsTests(TestContext context)
|
||||
var app = context.CreateTempDirectory("app");
|
||||
File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), "");
|
||||
var paths = AppPaths.Resolve(app, KnownFolders.LocalAppData);
|
||||
var roots = OneDriveFolders.SyncRoots();
|
||||
Assert.True(paths.IsPortable);
|
||||
Assert.Equal(OneDriveFolders.Containing(paths.DataRoot, OneDriveFolders.SyncRoots()), paths.SyncedFolder);
|
||||
Assert.True(OneDriveFolders.SyncRoots().All(Path.IsPathFullyQualified));
|
||||
Assert.Equal(OneDriveFolders.Containing(Path.Combine(app, PortableMode.DataFolderName), roots), paths.PortableSyncRoot);
|
||||
Assert.Equal(OneDriveFolders.Containing(paths.DataRoot, roots), paths.SyncedFolder);
|
||||
Assert.True(roots.All(Path.IsPathFullyQualified));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Titano.Core.Windows.Shell;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Windows.Tests.Shell;
|
||||
|
||||
/// <summary>The OneDrive folders of the user as Windows reports them. Serial: a test sets a process environment variable.</summary>
|
||||
[Serial]
|
||||
public sealed class OneDriveFoldersTests(TestContext context)
|
||||
{
|
||||
private const string Variable = "OneDriveCommercial";
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void APortableCopyInTheUsersOneDriveKeepsItsDataInLocalAppData()
|
||||
{
|
||||
var oneDrive = context.CreateTempDirectory("onedrive");
|
||||
var previous = Environment.GetEnvironmentVariable(Variable);
|
||||
Environment.SetEnvironmentVariable(Variable, oneDrive);
|
||||
try
|
||||
{
|
||||
Assert.Contains(OneDriveFolders.SyncRoots(), root => string.Equals(root, Path.TrimEndingDirectorySeparator(oneDrive), StringComparison.OrdinalIgnoreCase));
|
||||
// A Desktop that OneDrive's folder backup moved into the sync root, with a portable copy unpacked on it.
|
||||
var app = Directory.CreateDirectory(Path.Combine(oneDrive, "Desktop", "Titano")).FullName;
|
||||
File.WriteAllText(Path.Combine(app, PortableMode.MarkerFileName), "");
|
||||
var local = context.CreateTempDirectory("local");
|
||||
|
||||
var paths = AppPaths.Resolve(app, local);
|
||||
|
||||
Assert.True(paths.IsPortable);
|
||||
Assert.Equal(Path.Combine(local, AppPaths.ProductFolderName), paths.DataRoot);
|
||||
Assert.NotNull(paths.PortableSyncRoot);
|
||||
Assert.False(paths.IsInSyncedFolder);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable(Variable, previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,48 @@ public sealed class ArchiveSettingsTests(TestContext context)
|
||||
fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Proxies = s.Proxies with { LongEdge = 2560 } }, fx.Ct));
|
||||
var shown = await fx.Service.GetSettingsAsync(fx.Archive.Id, fx.Ct);
|
||||
Assert.Equal((1280, FrameImageRenderer.ThumbnailLongEdge), (shown.Proxies.LongEdge, shown.Thumbnails.LongEdge));
|
||||
// A refresh reports that only the index's stand-ins are known: the thumbnail size above is not the archive's.
|
||||
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARefreshBringsTheIndexUpToSettingsChangedElsewhere()
|
||||
{
|
||||
await using var fx = await ArchiveFixture.CreateAsync(context);
|
||||
// Another process sharing the archive (a server's admin panel) changed archive.json: this index still has the old row.
|
||||
var manifest = ManifestStore.ReadArchive(fx.Paths.ManifestPath);
|
||||
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with
|
||||
{
|
||||
Name = "Shared",
|
||||
LayoutTemplates = manifest.LayoutTemplates with { Folder = "{year}/{camera}" },
|
||||
ProxyPolicy = manifest.ProxyPolicy with { LongEdge = 2560 },
|
||||
ThumbnailPolicy = manifest.ThumbnailPolicy with { LongEdge = 480 },
|
||||
});
|
||||
Assert.Equal(fx.Archive.FolderTemplate, (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!.FolderTemplate);
|
||||
|
||||
var settings = Assert.NotNull(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
|
||||
Assert.Equal(("{year}/{camera}", 2560, 480), (settings.Templates.Folder, settings.Proxies.LongEdge, settings.Thumbnails.LongEdge));
|
||||
var row = (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!;
|
||||
Assert.Equal(("Shared", "{year}/{camera}", 2560), (row.Name, row.FolderTemplate, row.ProxyLongEdge));
|
||||
|
||||
// The drive is unplugged: nothing is known beyond the index, which stays as it is.
|
||||
File.Move(fx.Paths.ManifestPath, fx.Paths.ManifestPath + ".away");
|
||||
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
|
||||
Assert.Equal("{year}/{camera}", (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!.FolderTemplate);
|
||||
|
||||
// A newer Titano rewrote the file: what this one reads of it is neither shown nor registered.
|
||||
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with { Name = "Newer", LayoutTemplates = manifest.LayoutTemplates with { Folder = "{camera}" } });
|
||||
var newer = JsonNode.Parse(await File.ReadAllTextAsync(fx.Paths.ManifestPath, fx.Ct))!;
|
||||
newer["schemaVersion"] = ArchiveManifest.CurrentSchemaVersion + 1;
|
||||
await File.WriteAllTextAsync(fx.Paths.ManifestPath, newer.ToJsonString(), fx.Ct);
|
||||
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
|
||||
var kept = (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!;
|
||||
Assert.Equal(("Shared", "{year}/{camera}"), (kept.Name, kept.FolderTemplate));
|
||||
|
||||
// The folder now holds another archive: its settings are neither shown nor registered as this one's.
|
||||
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with { Id = Guid.CreateVersion7(), Name = "Other" });
|
||||
Assert.Null(await fx.Service.RefreshSettingsAsync(fx.Archive.Id, fx.Ct));
|
||||
Assert.Equal("Shared", (await fx.Db.Archives.GetAsync(fx.Archive.Id, fx.Ct))!.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -106,6 +106,47 @@ public sealed class ArchiveModuleTests(TestContext context)
|
||||
await UntilImagesAsync(server, editor, archive.Id, "garden");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SettingsADesktopChangedInArchiveJsonReachUploadsAndTheAdminPanel()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
var archive = server.Services.GetRequiredService<ServerArchive>();
|
||||
var polling = server.Services.GetRequiredService<ArchivePolling>();
|
||||
// Nothing changed: the served archive (the one an administrator's edit put there) is not replaced by a row read again.
|
||||
var served = archive.Current;
|
||||
await polling.PollAsync(context.Cancellation);
|
||||
Assert.True(ReferenceEquals(served, archive.Current), "a poll that registered nothing keeps the served archive");
|
||||
|
||||
// A desktop sharing the archive changed its folder template and proxy size in archive.json.
|
||||
var path = new ArchivePaths(archive.Root).ManifestPath;
|
||||
var manifest = ManifestStore.ReadArchive(path);
|
||||
ManifestStore.WriteArchive(path, manifest with
|
||||
{
|
||||
LayoutTemplates = manifest.LayoutTemplates with { Folder = "{camera}/{date}" },
|
||||
ProxyPolicy = manifest.ProxyPolicy with { LongEdge = 2560 },
|
||||
});
|
||||
|
||||
await polling.PollAsync(context.Cancellation);
|
||||
|
||||
// Uploads (the index row) and the admin panel (the served archive) follow it.
|
||||
Assert.Equal(("{camera}/{date}", 2560), (archive.Current.FolderTemplate, archive.Current.ProxyLongEdge));
|
||||
var row = Assert.NotNull(await server.Database.Archives.GetAsync(archive.Id, context.Cancellation));
|
||||
Assert.Equal(("{camera}/{date}", 2560), (row.FolderTemplate, row.ProxyLongEdge));
|
||||
|
||||
// The admin panel opens before the next poll: its form, which saves every field, starts from the desktop's change.
|
||||
ManifestStore.WriteArchive(path, ManifestStore.ReadArchive(path) with { LayoutTemplates = manifest.LayoutTemplates with { Folder = "{year}/{camera}" } });
|
||||
var admin = await server.AdminAsync();
|
||||
using (var read = await admin.GetAsync("/api/v1/archive/settings"))
|
||||
Assert.Equal("{year}/{camera}", (await read.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto)).FolderTemplate);
|
||||
Assert.Equal("{year}/{camera}", archive.Current.FolderTemplate);
|
||||
|
||||
// A refresh that read the archive before an administrator saved an edit never puts it back over that edit.
|
||||
var before = archive.Current;
|
||||
archive.Current = before with { Name = "Edited" };
|
||||
Assert.False(archive.TryReplace(before, before with { Name = "Stale" }), "the edit saved meanwhile stays");
|
||||
Assert.Equal("Edited", archive.Current.Name);
|
||||
}
|
||||
|
||||
private static async Task UntilIndexedAsync(TestServer server, Guid archiveId, string folder)
|
||||
{
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||||
|
||||
Reference in new issue
Block a user