The owner asked (2026-11-06) that whatever path is given as the archive root, on the server in Docker or on Windows, Chronos creates inside it every folder the archive keeps. Until now only .chronos was made up front; locks, journal, staging, trash and its photos and videos areas appeared on first use, and an archive copied or made by an older build could lack them. ArchiveStructure.Ensure (Core) creates the missing folders of BRIEF §7 idempotently, never touching existing folders or files, and reports why it could not (drive or share unavailable, permission denied, read-only, a file in the way) as one localized sentence. ArchiveService runs it when it creates an archive (refused with the reason when the tree cannot be made) and at every open. The server checks it at start-up and on each dashboard read: it logs a warning, the dashboard shows an "Archive incomplete" chip with the reason, and /health reports archive "incomplete". The desktop runs it when an archive is created, adopted or opened at start, and a folder typed in Settings that is not an archive yet becomes one in place, as Welcome's Create does; a writable archive whose tree cannot be completed is refused with the reason. Refs #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
3.0 KiB
C#
65 lines
3.0 KiB
C#
using Chronos.Core.Archiving;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Archiving;
|
|
|
|
/// <summary>Every archive the service creates, adopts or opens holds its whole layout (BRIEF §7, owner request 2026-11-06).</summary>
|
|
[Category("archive")]
|
|
public sealed class ArchiveStructureServiceTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public async Task ANewArchiveGetsItsWholeLayout()
|
|
{
|
|
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory("db"), "chronos.db")), context.Cancellation);
|
|
var service = new ArchiveService(db);
|
|
var root = Path.Combine(context.CreateTempDirectory("new"), "Chronos", "Archive");
|
|
|
|
var archive = await service.AdoptAsync(root, "Fresh", context.Cancellation);
|
|
|
|
var paths = new ArchivePaths(archive.RootPath);
|
|
Assert.FileExists(paths.ManifestPath);
|
|
Assert.Empty(ArchiveStructure.Missing(paths));
|
|
Assert.True(Directory.Exists(paths.TrashPhotosDirectory) && Directory.Exists(paths.TrashVideosDirectory));
|
|
}
|
|
|
|
[Test]
|
|
public async Task OpeningAnArchiveMakesTheFoldersItLacksAndTouchesNothingElse()
|
|
{
|
|
await using var fx = await ArchiveFixture.CreateAsync(context);
|
|
var paths = fx.Paths;
|
|
var kept = Path.Combine(paths.StagingDirectory, "copy.tmp");
|
|
File.WriteAllText(kept, "staged");
|
|
var manifest = File.ReadAllBytes(paths.ManifestPath);
|
|
// An archive an older Chronos or a copy left without its trash, journal and locks.
|
|
Directory.Delete(paths.TrashDirectory, recursive: true);
|
|
Directory.Delete(paths.JournalDirectory);
|
|
Directory.Delete(paths.LocksDirectory, recursive: true);
|
|
|
|
await fx.Service.OpenAsync(paths.Root, fx.Ct);
|
|
|
|
Assert.Empty(ArchiveStructure.Missing(paths));
|
|
Assert.Equal("staged", File.ReadAllText(kept));
|
|
Assert.BytesEqual(manifest, File.ReadAllBytes(paths.ManifestPath));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnArchiveThatCannotBeLaidOutIsNotCreated()
|
|
{
|
|
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory("db"), "chronos.db")), context.Cancellation);
|
|
var service = new ArchiveService(db);
|
|
var root = context.CreateTempDirectory("blocked");
|
|
// A file where the archive's metadata folder belongs: it stays, and the archive is refused with the reason.
|
|
var meta = new ArchivePaths(root).MetaDirectory;
|
|
File.WriteAllText(meta, "not a folder");
|
|
|
|
var error = await Assert.ThrowsAsync<ArchiveStructureException>(() => service.CreateAsync(root, "Blocked", cancellationToken: context.Cancellation));
|
|
|
|
Assert.Equal(ArchiveStructureProblem.Failed, error.Report.Problem);
|
|
Assert.Equal(meta, error.Report.Folder);
|
|
Assert.Equal(error.Report.Message, error.Message);
|
|
Assert.Equal("not a folder", File.ReadAllText(meta));
|
|
Assert.Empty(await db.Archives.ListAsync(context.Cancellation));
|
|
}
|
|
}
|