Files
Chronos/tests/Chronos.Data.Tests/Copies/CopyJournalMaintenanceTests.cs
T
Alby96andClaude Opus 5.5 d10577b175 fix(copies): close the owner review 6 gaps with tests
Photos not sent: automatic photos of an integrated pair that failed three
times in a row are now told with an error toast that shows the row, and the
row reads "not sent" with the last reason. The matches-found and linked toasts
of background detections run from their Windows notification too.

Maintenance now clears a merge's or an integration's journal whose job is done,
cancelled, or deleted without a cancel and untouched for the history's days.

Tests pin the matches jobs in the priority queue, the owner's defaults (ask
always, union, copy across), the dialog starting from the settings, Choose
each preselecting nothing, no automatic photos for a pair whose server copy
is gone, the repair of a corrupt local frame by an Integrate, and the owner's
whole scenario end to end against a real in-process server.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:03:23 +01:00

77 lines
3.8 KiB
C#

using Chronos.Core.Model;
using Chronos.Data.Archiving;
using Chronos.Data.Copies;
using Chronos.Data.Tests.Archiving;
using Chronos.Testing;
namespace Chronos.Data.Tests.Copies;
/// <summary>
/// What a merge or an integration leaves in the archive's journal folder (owner review 6, #73): the maintenance pass keeps
/// the journal a retry can use and clears the one no job will read again, as it does for conversions.
/// </summary>
[Category("archive")]
public sealed class CopyJournalMaintenanceTests(TestContext context)
{
[Test]
public async Task MaintenanceClearsTheJournalOfAMergeOrIntegrateNoJobWillReadAgain()
{
await using var fx = await ArchiveFixture.CreateAsync(context);
var failed = Guid.CreateVersion7();
var done = Guid.CreateVersion7();
var cancelled = Guid.CreateVersion7();
var paused = Guid.CreateVersion7();
foreach (var (id, kind, state) in new[]
{
(failed, JobKind.MergeSequences, JobState.Failed), (done, JobKind.Integrate, JobState.Done),
(cancelled, JobKind.MergeSequences, JobState.Cancelled), (paused, JobKind.Integrate, JobState.Paused),
})
await fx.Db.Jobs.EnqueueAsync(new Job { Id = id, Kind = kind, State = state, Created = DateTimeOffset.UtcNow }, fx.Ct);
// Deleted without a cancel: the index no longer knows the job.
var deleted = Guid.CreateVersion7();
var recent = Guid.CreateVersion7();
const int Old = Housekeeping.CleanupSteps.DefaultHistoryDays + 1;
string Write(string path, int daysOld)
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
File.WriteAllText(path, "{}");
File.SetLastWriteTimeUtc(path, DateTime.UtcNow.AddDays(-daysOld));
return path;
}
var failedJournal = Write(MergeJournal.PathFor(fx.Paths, failed), Old);
var doneJournal = Write(IntegrateJournal.PathFor(fx.Paths, done), 0);
var cancelledJournal = Write(MergeJournal.PathFor(fx.Paths, cancelled), 0);
var pausedJournal = Write(IntegrateJournal.PathFor(fx.Paths, paused), Old);
var deletedJournal = Write(MergeJournal.PathFor(fx.Paths, deleted), Old);
var recentJournal = Write(IntegrateJournal.PathFor(fx.Paths, recent), 1);
var other = Write(Path.Combine(fx.Paths.JournalDirectory, "merge-notes.json"), Old);
var dry = await fx.Service.Maintenance.RunAsync(fx.Archive, dryRun: true, 0, _ => ValueTask.CompletedTask, fx.Ct);
Assert.SequenceEqual(new[] { doneJournal, cancelledJournal, deletedJournal }.Select(fx.Paths.ToRelative).Order(), dry.TemporaryFiles.Order());
Assert.FileExists(deletedJournal);
await fx.Service.Maintenance.RunAsync(fx.Archive, dryRun: false, 0, _ => ValueTask.CompletedTask, fx.Ct);
Assert.FileMissing(doneJournal);
Assert.FileMissing(cancelledJournal);
Assert.FileMissing(deletedJournal);
// A retry still reads these: the failed and the paused job's, and one another host may still be writing.
Assert.FileExists(failedJournal);
Assert.FileExists(pausedJournal);
Assert.FileExists(recentJournal);
Assert.FileExists(other);
}
[Test]
public void OnlyTheJournalsOfMergesAndIntegrationsAreRecognised()
{
var job = Guid.CreateVersion7();
Assert.Equal(job, ArchiveMaintenance.CopyJournalJob($"merge-{job:N}.json"));
Assert.Equal(job, ArchiveMaintenance.CopyJournalJob($"integrate-{job:N}.json"));
Assert.Null(ArchiveMaintenance.CopyJournalJob($"convert-{job:N}.json"));
Assert.Null(ArchiveMaintenance.CopyJournalJob($"merge-{job:N}.json.tmp"));
Assert.Null(ArchiveMaintenance.CopyJournalJob($"merge-{job:D}.json"));
}
}