fix: projects and the workspace copy follow phase 4's folder and conversion rules
Phase 5a was written on an early phase 4a state. On top of phase 4b it now keeps the rules every writer of a sequence's folder follows, and keeps project versions intact through Reorganize and conversions: - ProjectService writes project sidecars, project.json and the settings only under the sequence's lease and only in a folder that holds the sequence (SequenceFolders.Holds). A folder another index moved away, or one another sequence was moved into, is refused with SequenceFolderMovedException: reads answer from the index, so no project is taken for gone, nothing is written into the other sequence's folder and the old folder is never created again. The home reports it as out of reach. Full scans and rebuilds reconcile projects the same way, and a failure there is logged instead of failing the scan. - Stored versions park positions by photo and now follow the encodings a Replace conversion (or its undo) joined through the sequence's Replaced tombstones (PhotoAlias, HomePhotos): Main's mirror, renders of a version and workspace media place them on the converted frames. ProjectContent.Rebind/SameChoices name parked photos as the frames hold them now, so a conversion or a hash since is no "external" Main version and no spurious "Modified" in a workspace, and merges see one photo. - The workspace copy job only reads the archive: it no longer runs the archive's proxy pass, makes missing proxies in the workspace, reads only a folder that holds the sequence, starts again when the folder moved or files were renamed during the copy, resumes from a checkpoint of its frames version, and refuses a workspace folder inside any library before it writes anything (Errors.Workspace.InsideLibrary). The working state keeps its positions by frame where frames stay. - ArchiveProjectHome looks for a project or version the index does not know yet in the sequence's sidecars first (an index taken back from a backup, a sequence back from the trash), instead of calling it gone. Tests cover the moved and taken folder, conversions in the archive and in the workspace, the copy refusing a workspace in a library, resuming on other frames, the alias lookup and the rebinding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9d1c396a1
commit
50e28fd63d
18 files changed
+596
-91
No files matched your search
@@ -33,6 +33,34 @@ public abstract class ProjectServiceTests(TestContext context) : DatabaseTest(co
|
||||
|
||||
internal static FramePhotos Photos(IEnumerable<Frame> frames) => new(frames.Select(f => (f.Index, new FramePhoto(f.Sha256, f.Size, f.CapturedAt))));
|
||||
|
||||
/// <summary>
|
||||
/// The files of the frames at <paramref name="indices"/> replaced by other encodings, as a Replace conversion does (owner
|
||||
/// review 2, R7, <see cref="FrameTrash.ReplaceAsync"/>): the same frames, other files and SHA-256.
|
||||
/// </summary>
|
||||
internal static async Task ConvertAsync(ArchiveFixture fx, Guid sequenceId, IReadOnlyList<int> indices, int seed)
|
||||
{
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(sequenceId))!;
|
||||
var manifest = ManifestStore.ReadSequence(fx.Paths.Sequence(sequence.Folder).ManifestPath);
|
||||
var staging = Path.Combine(fx.Paths.StagingDirectory, "convert-test");
|
||||
Directory.CreateDirectory(staging);
|
||||
var swaps = new List<FrameSwap>();
|
||||
foreach (var i in indices)
|
||||
{
|
||||
var frame = manifest.Frames[i];
|
||||
var bytes = Chronos.Data.Tests.Archiving.Photos.Jpeg(frame.CapturedAt, seed + i);
|
||||
var path = Path.Combine(staging, $"{Guid.NewGuid():N}.jpeg");
|
||||
File.WriteAllBytes(path, bytes);
|
||||
var sha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(bytes));
|
||||
swaps.Add(new FrameSwap(frame.Id, fx.Paths.ToRelative(path), [], (current, _) => Path.ChangeExtension(current.File, ".jpeg"), current => current with
|
||||
{
|
||||
Sha256 = sha,
|
||||
Size = bytes.Length,
|
||||
Source = new FrameSource { Sha256 = current.Sha256, Format = current.Format, File = current.File, Size = current.Size },
|
||||
}));
|
||||
}
|
||||
Assert.NotNull(await fx.Service.FrameTrash.ReplaceAsync(fx.Archive, sequenceId, null, swaps, null, null, null, null, fx.Ct));
|
||||
}
|
||||
|
||||
/// <summary>The sequence's settings written as an older code path writes them (the editor, an analysis): index first, with its version check.</summary>
|
||||
internal static async Task<Sequence> WriteSettingsAsync(ArchiveFixture fx, Guid sequenceId, ProjectSettings settings)
|
||||
{
|
||||
@@ -278,6 +306,34 @@ public abstract class ProjectServiceTests(TestContext context) : DatabaseTest(co
|
||||
Assert.Equal(mainPush.Id, (await fx.Db.Projects.GetAsync(main.Id))!.MirroredVersionId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProjectTheIndexDoesNotKnowYetIsFoundInItsSidecarsThroughItsHome()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var (sequence, frames) = await UploadedAsync(fx, 3);
|
||||
var vertical = await fx.Service.Projects.CreateAsync(sequence.Id, "Vertical", cancellationToken: fx.Ct);
|
||||
var head = (await fx.Service.Projects.PushAsync(vertical.Id,
|
||||
Draft(await fx.Service.Projects.HeadAsync(vertical.Id, fx.Ct), new ProjectSettings { ExcludedFrames = [1] }, frames), fx.Ct)).Version!;
|
||||
|
||||
// An index taken back from an older backup (or a sequence back from the trash) holds the sequence, not its projects yet:
|
||||
// a workspace that has one checked out still finds it, and its versions.
|
||||
await fx.ReopenWithEmptyIndexAsync();
|
||||
await fx.ScanAsync();
|
||||
Assert.Null(await fx.Db.Projects.GetAsync(vertical.Id));
|
||||
var version = await new ArchiveProjectHome(fx.Db, fx.Service.Projects, sequence.Id).GetVersionAsync(vertical.Id, head.Id, fx.Ct);
|
||||
Assert.Equal(head.ContentHash, Assert.NotNull(version).ContentHash);
|
||||
|
||||
await fx.ReopenWithEmptyIndexAsync();
|
||||
await fx.ScanAsync();
|
||||
var home = new ArchiveProjectHome(fx.Db, fx.Service.Projects, sequence.Id);
|
||||
Assert.Equal(head.Id, (await home.HeadAsync(vertical.Id, fx.Ct)).Id);
|
||||
// A project of another sequence is still none of this home's.
|
||||
var other = (await UploadedAsync(fx, 1, seed: 300)).Sequence;
|
||||
var square = await fx.Service.Projects.CreateAsync(other.Id, "Square", cancellationToken: fx.Ct);
|
||||
Assert.Equal(ProjectError.NotFound, (await Assert.ThrowsAsync<ProjectException>(() => home.HeadAsync(square.Id, fx.Ct))).Reason);
|
||||
Assert.Null(await home.GetVersionAsync(square.Id, head.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AVersionFileAPushLeftBehindItsRecordIsAdoptedAndAStrayOneSetAside()
|
||||
{
|
||||
@@ -327,14 +383,75 @@ public abstract class ProjectServiceTests(TestContext context) : DatabaseTest(co
|
||||
var (sequence, frames) = await UploadedAsync(fx, 3);
|
||||
var projects = fx.Service.Projects;
|
||||
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
||||
var moved = "2026/Moved " + Guid.NewGuid().ToString("N")[..6];
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fx.Paths.Sequence(moved).Folder)!);
|
||||
Directory.Move(fx.Paths.Sequence(sequence.Folder).Folder, fx.Paths.Sequence(moved).Folder);
|
||||
await fx.Db.Sequences.RelocateAsync(sequence.Id, moved, sequence.Title, fx.Ct);
|
||||
var vertical = await projects.CreateAsync(sequence.Id, "Vertical", cancellationToken: fx.Ct);
|
||||
|
||||
// A Reorganize (phase 4a) moves the whole folder under the sequence's lease: the projects' sidecars go with it.
|
||||
var plan = await fx.Service.Renamer.PlanAsync(fx.Archive, [sequence.Id], "Moved/{title}", null, fx.Ct);
|
||||
await fx.Service.Renamer.ApplyAsync(fx.Archive, plan, cancellationToken: fx.Ct);
|
||||
var reorganized = (await fx.Db.Sequences.GetAsync(sequence.Id))!;
|
||||
Assert.NotEqual(sequence.Folder, reorganized.Folder);
|
||||
Assert.FileExists(fx.Paths.Sequence(reorganized.Folder).ProjectRecordPath(vertical.Id));
|
||||
Assert.SequenceEqual([main.Id, vertical.Id], (await projects.ListAsync(sequence.Id, fx.Ct)).Select(p => p.Id));
|
||||
var pushed = await projects.PushAsync(main.Id, Draft(await projects.HeadAsync(main.Id, fx.Ct), new ProjectSettings { ExcludedFrames = [1] }, frames), fx.Ct);
|
||||
Assert.Equal(PushOutcome.Stored, pushed.Outcome);
|
||||
Assert.FileExists(fx.Paths.Sequence(moved).VersionPath(main.Id, 2, pushed.Version!.Id));
|
||||
Assert.FileExists(fx.Paths.Sequence(reorganized.Folder).VersionPath(main.Id, 2, pushed.Version!.Id));
|
||||
|
||||
// Another index of the archive moved it away: until this index finds it there, its projects are read from the index (none
|
||||
// taken for gone) and nothing is written where it was, which is never made again. A workspace hears its home is out of
|
||||
// reach for now, and reads its head from the index meanwhile.
|
||||
var away = "2026/Away " + Guid.NewGuid().ToString("N")[..6];
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fx.Paths.Sequence(away).Folder)!);
|
||||
Directory.Move(fx.Paths.Sequence(reorganized.Folder).Folder, fx.Paths.Sequence(away).Folder);
|
||||
Assert.SequenceEqual([main.Id, vertical.Id], (await projects.ListAsync(sequence.Id, fx.Ct)).Select(p => p.Id));
|
||||
var head = await projects.HeadAsync(main.Id, fx.Ct);
|
||||
await Assert.ThrowsAsync<SequenceFolderMovedException>(() => projects.PushAsync(main.Id, Draft(head, new ProjectSettings { ExcludedFrames = [2] }, frames), fx.Ct));
|
||||
var home = new ArchiveProjectHome(fx.Db, projects, sequence.Id);
|
||||
await Assert.ThrowsAsync<HomeUnavailableException>(() => home.PushAsync(main.Id, Draft(head, new ProjectSettings { ExcludedFrames = [2] }, frames), fx.Ct));
|
||||
await Assert.ThrowsAsync<HomeUnavailableException>(() => home.CreateAsync("Square", null, null, fx.Ct));
|
||||
Assert.Equal(head.Id, (await home.HeadAsync(main.Id, fx.Ct)).Id);
|
||||
Assert.False(Directory.Exists(fx.Paths.Sequence(reorganized.Folder).Folder));
|
||||
// Another sequence moved into the folder it left is no home of its projects either: none is read from it or written there.
|
||||
var other = (await UploadedAsync(fx, 1, seed: 300)).Sequence;
|
||||
Directory.Move(fx.Paths.Sequence(other.Folder).Folder, fx.Paths.Sequence(reorganized.Folder).Folder);
|
||||
await Assert.ThrowsAsync<SequenceFolderMovedException>(() => projects.RenameAsync(vertical.Id, "Vertical 2", fx.Ct));
|
||||
Assert.False(Directory.Exists(fx.Paths.Sequence(reorganized.Folder).ProjectsDirectory));
|
||||
Assert.SequenceEqual([main.Id, vertical.Id], (await projects.ListAsync(sequence.Id, fx.Ct)).Select(p => p.Id));
|
||||
await fx.Db.Sequences.RelocateAsync(sequence.Id, away, reorganized.Title, fx.Ct);
|
||||
Assert.Equal(PushOutcome.Stored, (await projects.PushAsync(main.Id, Draft(head, new ProjectSettings { ExcludedFrames = [2] }, frames), fx.Ct)).Outcome);
|
||||
Assert.Null((await projects.GetAsync(vertical.Id, fx.Ct))!.DeletedAt);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AVersionKeepsItsPositionsWhenItsPhotosAreConverted()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var (sequence, frames) = await UploadedAsync(fx, 4);
|
||||
var projects = fx.Service.Projects;
|
||||
await WriteSettingsAsync(fx, sequence.Id, new ProjectSettings { ExcludedFrames = [1], HeroFrame = 2 });
|
||||
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
||||
var head = await projects.HeadAsync(main.Id, fx.Ct);
|
||||
|
||||
// A Replace conversion (phase 4b) gives frames 1 and 2 other files: the same frames, other SHA-256.
|
||||
await ConvertAsync(fx, sequence.Id, [1, 2], 700);
|
||||
var home = await projects.FramesAsync(sequence.Id, fx.Ct);
|
||||
Assert.NotEqual(frames[1].Sha256, home.Frames[1].Sha256);
|
||||
Assert.Equal(frames[1].Id, home.Frames[1].Id);
|
||||
// The version parked the photos as they were: it still names the converted frames.
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(head.SettingsJson, home.Photos));
|
||||
Assert.SequenceEqual([1], placed.ExcludedFrames);
|
||||
Assert.Equal((int?)2, placed.HeroFrame);
|
||||
|
||||
// The sequence's settings written again with the same choices are no outside change: Main keeps its head.
|
||||
var row = (await fx.Db.Sequences.GetAsync(sequence.Id))!;
|
||||
await WriteSettingsAsync(fx, sequence.Id, ProjectSettings.FromJson(row.SettingsJson!));
|
||||
Assert.Equal(head.Id, (await projects.HeadAsync(main.Id, fx.Ct)).Id);
|
||||
|
||||
// A version pushed on top of it is mirrored onto the converted frames.
|
||||
var pushed = await projects.PushAsync(main.Id, Draft(head, new ProjectSettings { ExcludedFrames = [1, 3], HeroFrame = 2 }, home.Frames), fx.Ct);
|
||||
Assert.Equal(PushOutcome.Stored, pushed.Outcome);
|
||||
var mirrored = ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!);
|
||||
Assert.SequenceEqual([1, 3], mirrored.ExcludedFrames);
|
||||
Assert.Equal((int?)2, mirrored.HeroFrame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user