CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
199 lines
10 KiB
C#
199 lines
10 KiB
C#
using Chronos.Core.Archiving;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Testing;
|
|
using static Chronos.Data.Tests.Archiving.ArchiveFixture;
|
|
|
|
namespace Chronos.Data.Tests.Archiving;
|
|
|
|
[Category("archive")]
|
|
public sealed class ArchiveIndexTests(TestContext context)
|
|
{
|
|
/// <summary>Two folders adopted in place and one folder in the layout whose sidecar was lost.</summary>
|
|
private static void Populate(ArchivePaths paths)
|
|
{
|
|
Photos.WriteSeries(Path.Combine(paths.Root, "Trips", "Harbour sunset"), Start, 6);
|
|
Photos.WriteSeries(Path.Combine(paths.Root, "Trips", "Comet"), Start.AddDays(1), 4, firstSeed: 100);
|
|
Photos.WriteSeries(Path.Combine(paths.Root, "2026", "2026-09-30 Canon EOS R5", "originals"), Start.AddDays(2), 5, firstSeed: 200);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AdoptionIndexesFoldersInPlaceWithoutTouchingPhotos()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
var photos = Directory.EnumerateFiles(fx.Paths.Root, "*.JPG", SearchOption.AllDirectories).ToDictionary(p => p, File.ReadAllBytes);
|
|
|
|
var summary = await fx.ScanAsync(ScanMode.Full);
|
|
Assert.Equal(3, summary.Adopted);
|
|
Assert.Empty(summary.Failed);
|
|
var stats = await fx.Db.Sequences.GetStatsAsync(fx.Archive.Id);
|
|
Assert.Equal(3, stats.Sequences);
|
|
Assert.Equal(15L, stats.Photos);
|
|
var harbour = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Single(l => l.Folder == "Trips/Harbour sunset");
|
|
Assert.Equal("Harbour sunset", harbour.Title);
|
|
var frames = await fx.Db.Frames.ListBySequenceAsync(harbour.Id);
|
|
Assert.Equal("Trips/Harbour sunset/IMG_0001.JPG", frames[0].RelativePath);
|
|
Assert.Equal(Start, frames[0].CapturedAt);
|
|
Assert.Equal(10.0, (await fx.Db.Sequences.GetAsync(harbour.Id))!.MedianInterval);
|
|
Assert.FileExists(Path.Combine(fx.Paths.Root, "Trips", "Harbour sunset", ".chronos", "sequence.json"));
|
|
foreach (var (path, bytes) in photos) Assert.BytesEqual(bytes, File.ReadAllBytes(path));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnUnchangedArchiveRescansWithoutReadingSidecars()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
var again = await fx.ScanAsync();
|
|
Assert.Equal(3, again.Folders);
|
|
Assert.Equal(0, again.Indexed);
|
|
|
|
// A photo dropped into a folder and a title edited in a sidecar by another machine.
|
|
Photos.WriteSeries(Path.Combine(fx.Paths.Root, "Trips", "Comet"), Start.AddDays(1).AddMinutes(1), 1, firstSeed: 150, firstNumber: 5);
|
|
var sidecar = fx.Paths.Sequence("Trips/Harbour sunset").ManifestPath;
|
|
var manifest = ManifestStore.ReadSequence(sidecar);
|
|
ManifestStore.WriteSequence(sidecar, manifest with { Title = "Harbour at dusk", Versions = manifest.Versions with { Settings = 5 } });
|
|
|
|
var changed = await fx.ScanAsync();
|
|
Assert.Equal(2, changed.Indexed);
|
|
var locations = await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id);
|
|
Assert.Equal("Harbour at dusk", locations.Single(l => l.Folder == "Trips/Harbour sunset").Title);
|
|
Assert.Equal(5, (await fx.Db.Sequences.GetAsync(locations.Single(l => l.Folder == "Trips/Comet").Id))!.FrameCount);
|
|
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
|
}
|
|
|
|
[Test]
|
|
public async Task RebuildingFromSidecarsGivesTheSameIndex()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync(ScanMode.Full);
|
|
var comet = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Single(l => l.Folder == "Trips/Comet");
|
|
await fx.Service.SetSequenceInfoAsync(comet.Id, "Comet", ["sky", "night"], 5, "Clear", fx.Ct);
|
|
var before = await Photos.DumpIndexAsync(fx.Db, fx.Archive.Id);
|
|
|
|
await fx.ReopenWithEmptyIndexAsync();
|
|
var rebuilt = await fx.Service.Indexer.ScanAsync(fx.Archive, ScanMode.Rebuild, null, _ => ValueTask.CompletedTask, fx.Ct);
|
|
Assert.Equal(0, rebuilt.Adopted);
|
|
Assert.Equal(before, await Photos.DumpIndexAsync(fx.Db, fx.Archive.Id));
|
|
|
|
// A second rebuild reads the snapshot written by the first and still yields the same index.
|
|
Assert.NotNull(IndexSnapshot.TryLoad(fx.Paths.SnapshotPath));
|
|
await fx.ReopenWithEmptyIndexAsync();
|
|
await fx.Service.Indexer.ScanAsync(fx.Archive, ScanMode.Rebuild, null, _ => ValueTask.CompletedTask, fx.Ct);
|
|
Assert.Equal(before, await Photos.DumpIndexAsync(fx.Db, fx.Archive.Id));
|
|
}
|
|
|
|
[Test]
|
|
public async Task RebuildDropsRowsWhoseSidecarIsGoneAndScanKeepsThem()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
Directory.Move(Path.Combine(fx.Paths.Root, "Trips", "Comet"), Path.Combine(context.CreateTempDirectory("elsewhere"), "Comet"));
|
|
await fx.ScanAsync();
|
|
Assert.Equal(3, (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Count);
|
|
var orphans = await fx.Service.FindOrphansAsync(fx.Archive.Id, fx.Ct);
|
|
Assert.Equal("Trips/Comet", orphans.MissingSequences.Single().Folder);
|
|
|
|
var summary = await fx.ScanAsync(ScanMode.Rebuild);
|
|
Assert.Equal(1, summary.Removed);
|
|
Assert.Equal(2, (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Count);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ADamagedSidecarIsKeptAsideAndRebuiltWithTheSameIds()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
var harbour = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Single(l => l.Folder == "Trips/Harbour sunset");
|
|
var frameIds = (await fx.Db.Frames.ListBySequenceAsync(harbour.Id)).Select(f => f.Id).ToList();
|
|
var sidecar = fx.Paths.Sequence(harbour.Folder).ManifestPath;
|
|
File.WriteAllText(sidecar, "{ \"id\": \"broken");
|
|
|
|
var summary = await fx.ScanAsync();
|
|
Assert.Empty(summary.Failed);
|
|
Assert.Equal(harbour.Id, ManifestStore.ReadSequence(sidecar).Id);
|
|
Assert.SequenceEqual(frameIds, (await fx.Db.Frames.ListBySequenceAsync(harbour.Id)).Select(f => f.Id));
|
|
Assert.Count(1, Directory.GetFiles(Path.GetDirectoryName(sidecar)!, "sequence.json.damaged-*"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ACopiedSequenceFolderGetsItsOwnIdentity()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
var source = Path.Combine(fx.Paths.Root, "Trips", "Comet");
|
|
var copy = Path.Combine(fx.Paths.Root, "Trips", "Comet copy");
|
|
Directory.CreateDirectory(Path.Combine(copy, ".chronos"));
|
|
foreach (var file in Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories))
|
|
File.Copy(file, Path.Combine(copy, Path.GetRelativePath(source, file)));
|
|
|
|
await fx.ScanAsync();
|
|
var locations = await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id);
|
|
Assert.Equal(4, locations.Count);
|
|
var original = locations.Single(l => l.Folder == "Trips/Comet");
|
|
var copied = locations.Single(l => l.Folder == "Trips/Comet copy");
|
|
Assert.NotEqual(original.Id, copied.Id);
|
|
Assert.Equal(4, (await fx.Db.Frames.ListBySequenceAsync(original.Id)).Count);
|
|
Assert.Equal(4, (await fx.Db.Frames.ListBySequenceAsync(copied.Id)).Count);
|
|
Assert.Equal(copied.Id, ManifestStore.ReadSequence(fx.Paths.Sequence("Trips/Comet copy").ManifestPath).Id);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnOfflineArchiveIsLeftAsItWas()
|
|
{
|
|
var root = context.CreateTempDirectory("archive");
|
|
await using var fx = await CreateAsync(context, root);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
var before = await Photos.DumpIndexAsync(fx.Db, fx.Archive.Id);
|
|
var unplugged = root + "-unplugged";
|
|
Directory.Move(root, unplugged);
|
|
Assert.Equal(ArchiveAvailability.Offline, ArchiveService.GetAvailability(fx.Archive));
|
|
await Assert.ThrowsAsync<ArchiveOfflineException>(() => fx.ScanAsync(ScanMode.Rebuild));
|
|
Assert.Equal(before, await Photos.DumpIndexAsync(fx.Db, fx.Archive.Id));
|
|
Directory.Move(unplugged, root);
|
|
Assert.Equal(ArchiveAvailability.Online, ArchiveService.GetAvailability(fx.Archive));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SequenceInfoIsWrittenToSidecarAndIndexTogether()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
var comet = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Single(l => l.Folder == "Trips/Comet");
|
|
var updated = await fx.Service.SetSequenceInfoAsync(comet.Id, " Comet 2026 ", ["Night"], 4, "Tripod", fx.Ct);
|
|
Assert.Equal("Comet 2026", updated.Title);
|
|
var manifest = ManifestStore.ReadSequence(fx.Paths.Sequence(comet.Folder).ManifestPath);
|
|
Assert.Equal("Comet 2026", manifest.Title);
|
|
Assert.SequenceEqual(["Night"], manifest.Tags);
|
|
Assert.Equal(updated.SettingsVersion, manifest.Versions.Settings);
|
|
Assert.SequenceEqual(["Night"], (await fx.Db.Sequences.GetAsync(comet.Id))!.Tags);
|
|
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnEditOfOneFieldKeepsWhatChangedSinceTheRowWasRead()
|
|
{
|
|
await using var fx = await CreateAsync(context);
|
|
Populate(fx.Paths);
|
|
await fx.ScanAsync();
|
|
var comet = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).Single(l => l.Folder == "Trips/Comet");
|
|
var stale = (await fx.Db.Sequences.GetAsync(comet.Id))!;
|
|
var edited = await fx.Service.SetSequenceInfoAsync(comet.Id, "Comet 2026", ["night"], 2, "Tripod", fx.Ct);
|
|
|
|
var rated = await fx.Service.EditSequenceInfoAsync(stale.Id, info => info with { Rating = 5 }, fx.Ct);
|
|
|
|
Assert.Equal(("Comet 2026", "night", 5, "Tripod"), (rated.Title, rated.Tags.Single(), rated.Rating, rated.Notes));
|
|
Assert.Equal(edited.SettingsVersion + 1, rated.SettingsVersion);
|
|
var manifest = ManifestStore.ReadSequence(fx.Paths.Sequence(comet.Folder).ManifestPath);
|
|
Assert.Equal(("Comet 2026", "night", 5, "Tripod"), (manifest.Title, manifest.Tags.Single(), manifest.Rating, manifest.Notes));
|
|
}
|
|
}
|