Index restore (ENG-06, UI-09): - A staged restore now runs on the files before the index is opened, so it also recovers an index that no longer opens; Settings > Advanced > Restore works without an open index (the current one is shown as unreadable). - The staged copy passes PRAGMA quick_check (before migration, in a scratch copy) ahead of any backup: a damaged copy is set aside as .failed and never renews the daily copies. The index it replaces is kept as a VACUUM INTO copy, or, when it cannot be read, copied whole with its WAL as titano-replaced-<stamp>.db outside the rotation. The staged file is renamed over the index, so it is never applied twice. - Archive > Maintenance gains Restore database..., which opens Settings > Advanced. Archive settings (UI-03, ENG-03): - An archive.json with an empty or overlong name (drive roots) can be edited again: the name read is made usable as at creation. - Proxy and thumbnail sizes outside the presets (an admin's 3840) are listed and shown with their number. - Changing the archive folder retargets the rows: an archive there is registered and rescanned; with none, the rows edit only the defaults of new archives. The rows never fall back to another archive of the index. - Reset all and Import settings no longer rewrite the shared archive.json; Archive > Reset section asks first, naming the archive. - PUT /api/v1/archive/settings: 409 archive_busy on a lease conflict, 409 archive_manifest for a damaged, newer or foreign archive.json (was 500). Parallelism (UI-02): - Auto is the job engine's default, half the logical cores (BRIEF 14.6), with each job's own decode and analysis threads; a value the user sets is the number of workers and caps those threads. The memory budget is shared: each job's frame window gets budget / workers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
97 lines
4.3 KiB
C#
97 lines
4.3 KiB
C#
using System.IO;
|
||
using Titano.App.Infrastructure;
|
||
using Titano.App.Tests.Uploader;
|
||
using Titano.Core.Model;
|
||
using Titano.Data;
|
||
using Titano.Data.Archiving;
|
||
using Titano.Testing;
|
||
|
||
namespace Titano.App.Tests.Infrastructure;
|
||
|
||
public sealed class AppServicesTests
|
||
{
|
||
/// <summary>Dialogs that answer like a user who cancels everything.</summary>
|
||
private sealed class NoDialogs : IAppDialogs
|
||
{
|
||
public string? PickFolder(string title, string? initialFolder = null) => null;
|
||
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;
|
||
}
|
||
|
||
[Test]
|
||
[WindowsOnly]
|
||
public void ExitStopsPollingAndTheEngineWhileTheUiThreadWaits()
|
||
{
|
||
var environment = AppEnvironment.ForCapture();
|
||
try
|
||
{
|
||
SingleThreadedContext.Run(async () =>
|
||
{
|
||
var root = Path.Combine(environment.DataDirectory, "archive");
|
||
await using (var setup = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(environment.DataDirectory, "setup.db"))))
|
||
await new ArchiveService(setup).CreateAsync(root, "Exit");
|
||
var services = new AppServices(environment, new AppSettings { Language = "en", LastArchivePath = root }, () => { }, new NoDialogs());
|
||
await services.OpenAsync(environment.DatabasePath);
|
||
// The archive was reopened and its first rescan queued: polling now waits for the next one.
|
||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
|
||
while ((await services.Database!.Jobs.ListAsync(null, JobKind.Scan)).Items.Count == 0)
|
||
{
|
||
Assert.True(DateTime.UtcNow < until, "no rescan queued");
|
||
await Task.Delay(50);
|
||
}
|
||
|
||
// App.OnExit blocks the UI thread until the services stop: nothing they await may continue on it.
|
||
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]
|
||
public void AStagedRestoreRecoversAnIndexThatNoLongerOpens()
|
||
{
|
||
var environment = AppEnvironment.ForCapture();
|
||
try
|
||
{
|
||
SingleThreadedContext.Run(async () =>
|
||
{
|
||
await using (var db = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(environment.DatabasePath)))
|
||
{
|
||
await db.Archives.UpsertAsync(new Archive { Id = Guid.CreateVersion7(), Name = "Kept", RootPath = @"C:\Kept", Created = DateTimeOffset.UtcNow });
|
||
var backup = await db.BackupAsync(environment.BackupDirectory, DatabaseBackups.Keep);
|
||
await DatabaseBackups.StageRestoreAsync(backup, environment.DatabasePath);
|
||
}
|
||
// The index is damaged beyond opening ("file is not a database").
|
||
File.Delete(environment.DatabasePath + "-wal");
|
||
File.Delete(environment.DatabasePath + "-shm");
|
||
await File.WriteAllBytesAsync(environment.DatabasePath, [.. Enumerable.Repeat((byte)0x5A, 8192)]);
|
||
|
||
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
||
try
|
||
{
|
||
await services.OpenAsync(environment.DatabasePath);
|
||
|
||
Assert.Null(services.OpenError);
|
||
Assert.Equal(StagedRestoreResult.Restored, services.StagedRestore);
|
||
Assert.SequenceEqual(["Kept"], (await services.Database!.Archives.ListAsync()).Select(a => a.Name));
|
||
Assert.False(DatabaseBackups.HasStagedRestore(environment.DatabasePath));
|
||
}
|
||
finally
|
||
{
|
||
Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
|
||
}
|
||
});
|
||
}
|
||
finally
|
||
{
|
||
environment.DeleteCaptureData();
|
||
}
|
||
}
|
||
}
|