fix: full verification against the brief — 137 confirmed findings fixed over six passes #4

Merged
Alby96 merged 169 commits from claude/keen-knuth-uhxv8w into main 2026-10-13 12:10:04 +02:00
2 changed files with 74 additions and 8 deletions
Showing only changes of commit 568ba4f21f - Show all commits

No files matched your search

+41 -8
View File
@@ -130,10 +130,30 @@ public sealed class ArchiveIndexer
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
var folder = paths.Sequence(sequence.Folder);
var manifest = await _writer.UpdateAsync(paths, sequence.Id, sequence.Folder, m => SequenceAdopter.Reconcile(folder, m, cancellationToken),
cancellationToken).ConfigureAwait(false);
await SyncAsync(archive, folder, manifest, cancellationToken).ConfigureAwait(false);
return manifest;
return await UpdateAndSyncAsync(archive, paths, folder, sequence.Id, m => SequenceAdopter.Reconcile(folder, m, cancellationToken), cancellationToken)
.ConfigureAwait(false);
}
/// <summary>
/// Applies <paramref name="edit"/> to the sidecar (null writes nothing) and indexes the result, both under the sequence
/// lease. Frames inserted before indexed ones move the project's positions (<see cref="ProjectPositions"/>) without a
/// new settings version; an editor saving its project holds the same lease, so it reads them moved and merges onto
/// them rather than writing its old positions back.
/// </summary>
private async Task<SequenceManifest> UpdateAndSyncAsync(Archive archive, ArchivePaths paths, SequencePaths sequence, Guid sequenceId,
Func<SequenceManifest, SequenceManifest?> edit, CancellationToken cancellationToken)
{
await using (await _writer.LockAsync(paths, sequenceId, cancellationToken).ConfigureAwait(false))
{
var manifest = SequenceWriter.ReadLocked(sequence, sequenceId);
if (edit(manifest) is { } updated)
{
ManifestStore.WriteSequence(sequence.ManifestPath, updated);
manifest = updated;
}
await SyncAsync(archive, sequence, manifest, cancellationToken).ConfigureAwait(false);
return manifest;
}
}
/// <summary>Indexes one folder; returns the sidecar bytes when they were read and not rewritten since (for the snapshot).</summary>
@@ -169,20 +189,33 @@ public sealed class ArchiveIndexer
}
if (reconcile || File.Exists(sequence.IngestJournalPath))
{
var before = manifest;
// Photos added, gone or back: the light analysis no longer describes the frames, so the scan's follow-up runs it again.
manifest = await _writer.UpdateAsync(paths, manifest.Id, folder.RelativeFolder,
manifest = await UpdateAndSyncAsync(archive, paths, sequence, manifest.Id,
m => SequenceAdopter.Reconcile(sequence, m, cancellationToken) is { } reconciled
? reconciled with { Status = reconciled.Status & ~SequenceStatus.AnalyzedLight }
: null,
cancellationToken).ConfigureAwait(false);
if (!ReferenceEquals(before, manifest)) bytes = null;
bytes = null;
}
else if (await MayMovePositionsAsync(manifest, cancellationToken).ConfigureAwait(false))
{
// Another process changed the frames: the sidecar is read again under the lease the project moves under.
manifest = await UpdateAndSyncAsync(archive, paths, sequence, manifest.Id, _ => null, cancellationToken).ConfigureAwait(false);
bytes = null;
}
else
{
await SyncAsync(archive, sequence, manifest, cancellationToken).ConfigureAwait(false);
}
await SyncAsync(archive, sequence, manifest, cancellationToken).ConfigureAwait(false);
locations.Set(manifest.Id, folder.RelativeFolder);
return bytes;
}
/// <summary>The index holds a project for this sequence and other frames than the sidecar: its positions may move.</summary>
private async Task<bool> MayMovePositionsAsync(SequenceManifest manifest, CancellationToken cancellationToken) =>
await _db.Sequences.GetAsync(manifest.Id, cancellationToken).ConfigureAwait(false) is { SettingsJson: not null } indexed
&& indexed.FramesVersion != manifest.Versions.Frames;
/// <summary>A sidecar for a folder that has none; ids of a sequence the index already knew at this folder are kept.</summary>
private async Task<SequenceManifest> AdoptAsync(SequencePaths sequence, Locations locations, CancellationToken cancellationToken)
{
@@ -298,4 +298,37 @@ public sealed class ArchiveIngestTests(TestContext context)
Assert.Contains("futureOption", settings);
Assert.True(JsonNode.DeepEquals(JsonNode.Parse(settings), JsonNode.Parse(File.ReadAllText(folder.ProjectPath))), "project.json mirrors the index");
}
[Test]
public async Task AScanMovesTheProjectPositionsOnlyBetweenProjectSaves()
{
await using var fx = await CreateAsync(context);
var late = await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start.AddMinutes(1), 1)), fx.Ct);
await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start.AddMinutes(2), 2)), fx.Ct);
var id = late.SequenceId;
var folder = fx.Paths.Sequence((await fx.Db.Sequences.GetAsync(id))!.Folder);
var version = (await fx.Db.Sequences.EditAsync(id, new SequenceEdit { SettingsJson = "{ \"excludedFrames\": [1] }" }, null, fx.Ct)).Sequence!.SettingsVersion;
// Another process files a photo captured before both into the sidecar; this index learns of it from a scan.
var photos = ArchiveScanner.PhotoDirectory(folder);
var stamp = Directory.GetLastWriteTimeUtc(photos);
File.WriteAllBytes(folder.File("originals/early.JPG"), Photos.Jpeg(Start, 3));
ManifestStore.WriteSequence(folder.ManifestPath, SequenceAdopter.Reconcile(folder, ManifestStore.ReadSequence(folder.ManifestPath), fx.Ct)!);
Directory.SetLastWriteTimeUtc(photos, stamp);
// An editor saving the project holds the sequence lease (LocalSequenceSource.SaveProjectAsync).
var save = await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"seq-{id:N}", "editor", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct);
var scan = Task.Run(() => fx.ScanAsync());
await Task.Delay(500, fx.Ct);
Assert.False(scan.IsCompleted, "the scan waits for the save");
// The save stores the positions its editor knew, as of the frames before the scan.
Assert.Equal(SequenceEditOutcome.Updated,
(await fx.Db.Sequences.EditAsync(id, new SequenceEdit { SettingsJson = "{ \"excludedFrames\": [0, 1] }" }, version, fx.Ct)).Outcome);
save.Dispose();
Assert.Equal(1, (await scan).Indexed);
var row = (await fx.Db.Sequences.GetAsync(id))!;
Assert.Equal(3, row.FrameCount);
Assert.SequenceEqual([1, 2], ProjectSettings.FromJson(row.SettingsJson!).ExcludedFrames);
}
}