fix(convert): close the last edges round 3's checkers found in the trash and the copy check
- A frame flagged corrupt, like one whose file is missing, is one no verify can hash (a verify does not hash a file whose size differs from its record): a replaced entry of its sequence is kept with "restore it", never with an advice to verify that would never settle it. - Erasing a deleted sequence leaves no record that its conversions went with it while the sequence also lives (this index has it, or a folder's sidecar names it: a folder copied back, a second deletion of the same id), so a later emptying whose walk misses that folder keeps the originals. - A copy another conversion made since this one was confirmed supersedes it only once that conversion is done; while it is not (it failed while filing the copy), a retry is left as it was with a reason (new string Archive.Convert.CopyUnfinished, en and it), neither making a second copy nor calling the sequence done with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5012c3bbd2
commit
74ccde7210
7 files changed
+75
-11
No files matched your search
@@ -1666,8 +1666,14 @@ public sealed class ConvertTests(TestContext context)
|
||||
var b = await QueuedAsync(fx, again, DateTimeOffset.UtcNow.AddMinutes(-5));
|
||||
var made = (await RunHereAsync(fx, again, b.Id, confirmed: b.Created)).Sequences.Single();
|
||||
Assert.Equal(ConvertOutcome.Created, made.Outcome);
|
||||
await fx.Db.Jobs.SetStateAsync(b.Id, JobState.Done, null, fx.Ct);
|
||||
var sequences = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id, fx.Ct)).Count;
|
||||
// While job B has not finished (it failed after filing its copy), Retry on A waits for it: no second copy, not done with.
|
||||
await fx.Db.Jobs.SetStateAsync(b.Id, JobState.Failed, "kept", fx.Ct);
|
||||
var waiting = (await RunHereAsync(fx, plan, a.Id, confirmed: a.Created)).Sequences.Single();
|
||||
Assert.Equal((ConvertOutcome.Blocked, Loc.L("Archive.Convert.CopyUnfinished")), (waiting.Outcome, waiting.Error));
|
||||
Assert.Null(await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Id, MassConverter.SessionKey(a.Id, id)));
|
||||
Assert.Equal(sequences, (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id, fx.Ct)).Count);
|
||||
await fx.Db.Jobs.SetStateAsync(b.Id, JobState.Done, null, fx.Ct);
|
||||
|
||||
// Retry on A: done with the sequence, no second copy.
|
||||
var lines = new List<string>();
|
||||
|
||||
@@ -377,6 +377,11 @@ public sealed class ReplacedTrashTests(TestContext context)
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, rebuilt with { Frames = [.. rebuilt.Frames.Select(f => f with { Flags = f.Flags | FrameFlags.Missing })] });
|
||||
plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
|
||||
Assert.Contains(Loc.L("Archive.Log.TrashKeptUnknown", replaced.Title), (await EmptyAsync(fx, engine, plan, JobState.Failed)).LogTail);
|
||||
// Nor when they are flagged corrupt: a verify does not hash a file whose size differs from its record, so it would
|
||||
// never settle the entry.
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, rebuilt with { Frames = [.. rebuilt.Frames.Select(f => f with { Flags = f.Flags | FrameFlags.Corrupt })] });
|
||||
plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
|
||||
Assert.Contains(Loc.L("Archive.Log.TrashKeptUnknown", replaced.Title), (await EmptyAsync(fx, engine, plan, JobState.Failed)).LogTail);
|
||||
|
||||
// Hashed, the conversion damaged meanwhile: no frame holds it and no tombstone says it was deleted. The originals stay,
|
||||
// and the dry run never calls them the last copy: only the archive's own word makes a conversion deleted.
|
||||
@@ -451,6 +456,40 @@ public sealed class ReplacedTrashTests(TestContext context)
|
||||
Assert.False(Directory.Exists(erasures), "no entry needs the record any more");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequenceThatAlsoLivesLeavesNoRecordOfItsErasing()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var (id, _) = await UploadedAsync(fx, 2);
|
||||
var engine = await fx.StartEngineAsync();
|
||||
var replaced = await ReplaceAsync(fx, id, [0, 1], 500);
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(id))!;
|
||||
// A copy of the converted sequence's folder made outside Chronos: its sidecar names the same sequence.
|
||||
var source = fx.Paths.Sequence(sequence.Folder).Folder;
|
||||
var copy = Path.Combine(fx.Paths.Root, "copy", Path.GetFileName(source));
|
||||
foreach (var file in Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
var target = Path.Combine(copy, Path.GetRelativePath(source, file));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target)!);
|
||||
File.Copy(file, target);
|
||||
}
|
||||
await fx.Service.Trash.DeleteAsync(await fx.Service.Trash.PlanAsync([id], null, fx.Ct), null, null, fx.Ct);
|
||||
var deleted = (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single(e => e.Kind == TrashKind.Sequence);
|
||||
|
||||
// Erasing the deleted sequence while a folder still names it leaves no record that its conversions went with it.
|
||||
var erased = await fx.Service.Trash.EmptyAsync(fx.Archive, Parameters(await fx.Service.Trash.PlanEmptyAsync(fx.Archive, [deleted.Name], fx.Ct)), 0,
|
||||
(_, _) => ValueTask.CompletedTask, fx.Ct);
|
||||
Assert.Equal((1, 0), (erased.Erased, erased.Refused.Count));
|
||||
Assert.FileMissing(Path.Combine(SequenceTrash.TrashDirectory(fx.Paths), ".erased", $"{id:N}.json"));
|
||||
|
||||
// So once the copy's sidecar is lost, the walk missing it, the originals stay: its conversions are still there.
|
||||
File.Delete(Path.Combine(copy, Path.GetRelativePath(source, fx.Paths.Sequence(sequence.Folder).ManifestPath)));
|
||||
var plan = await fx.Service.PlanEmptyTrashAsync(fx.Archive.Id, null, fx.Ct);
|
||||
Assert.False(plan.Entries.Single().ConversionDeleted);
|
||||
Assert.Contains(Loc.L("Archive.Log.TrashKeptUnknown", replaced.Title), (await EmptyAsync(fx, engine, plan, JobState.Failed)).LogTail);
|
||||
Assert.Equal(replaced.Name, (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OriginalsOfASequenceGoneWithoutTheTrashErasingItStay()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user