Files
Chronos/tests/Chronos.Data.Tests/Archiving/ArchiveStructureServiceTests.cs
Alby96andClaude Opus 5.5 0075065884
CI / Build and test (push) Successful in 10m37s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 16m19s
CI / PostgreSQL 16 integration (push) Successful in 10m19s
CI / PostgreSQL 17 integration (push) Successful in 11m27s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m34s
feat: work board, no usage data, archive folder tree, deploy guide (owner review 4 + owner review 1 phase 6) (#62)
Owner review 4 and owner review 1 phase 6.

- Work board in Videos (desktop and admin panel): Published and Workspace lanes (#29).
- Anonymous usage counts removed: Chronos sends nothing about its use (#30).
- The archive's whole folder tree is created inside any archive root, on the server and the desktop (#31).
- Video cards start with the preset; sizes keep number and unit together (#28).
- Deploy guide docs/deploy (Docker, Unraid, desktop), BRIEF §24, original documentation in docs/reference/original (#22).

Closes #22 #28 #29 #30 #31

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-06 18:46:22 +01:00

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));
}
}