feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job. - One naming rule (FrameNaming) for import, upload and Reorganize. - Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder. - Writers refuse a folder another program moved or gave to another sequence. - Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules. - Phase 3 docs and translations merged; strings in all 38 languages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
1 parent
9aa818ed47
commit
7e4a3b481d
416 files changed
+15304
-1572
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
@@ -97,6 +98,35 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SettingsTakenWhileAReorganizeMovesTheFolderGoWhereTheSequenceIsNow()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var photos = f.NewPhotos(2);
|
||||
var local = await f.LocalAsync("Harbour", photos);
|
||||
var remote = f.Remote.Add("Harbour", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
var left = f.Archive.Paths.Sequence((await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Folder).Folder;
|
||||
|
||||
// The server's edit is taken after a Reorganize moved the folder of the copy the comparison had read.
|
||||
f.Remote.EditSettings(remote.Id, SyncFixture.Window33);
|
||||
f.Remote.OnceBeforeManifest = async () =>
|
||||
{
|
||||
var plan = await f.Archive.Service.PlanRenameAsync(f.Archive.Archive.Id, [local.Id], "moved/{title}", null, f.Ct);
|
||||
await f.Archive.Service.ApplyRenameAsync(plan, null, f.Ct);
|
||||
};
|
||||
await f.RefreshAsync();
|
||||
Assert.Null(f.Remote.OnceBeforeManifest, "the folder moved during the comparison");
|
||||
|
||||
var taken = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.Equal("moved/Harbour", taken.Folder);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, taken.SettingsJson), "the server's edit reached this PC");
|
||||
var project = await File.ReadAllTextAsync(f.Archive.Paths.Sequence(taken.Folder).ProjectPath, f.Ct);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, project), "project.json in the moved folder follows the index");
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PositionsSentToTheServerNameItsFramesAndWaitForPhotosItLacks()
|
||||
{
|
||||
@@ -403,6 +433,144 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Holy grail")).Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveBothWhileAReorganizeMovesTheFolderKeepsTheCopyWhereTheSequenceIsNow()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
var left = f.Archive.Paths.Sequence(local.Folder).Folder;
|
||||
|
||||
// A Reorganize moves the folder while the server's version is read.
|
||||
f.Remote.OnceBeforeManifest = async () =>
|
||||
{
|
||||
var plan = await f.Archive.Service.PlanRenameAsync(f.Archive.Archive.Id, [local.Id], "moved/{title}", null, f.Ct);
|
||||
await f.Archive.Service.ApplyRenameAsync(plan, null, f.Ct);
|
||||
};
|
||||
var copy = await f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct);
|
||||
Assert.Null(f.Remote.OnceBeforeManifest, "the folder moved during the resolution");
|
||||
|
||||
var taken = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.Equal("moved/Holy grail", taken.Folder);
|
||||
Assert.Equal(copy, Assert.Contains(Directory.GetFiles(f.Archive.Paths.Sequence(taken.Folder).MetaDirectory, "project.this-pc-*.json"), _ => true));
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(copy!, f.Ct)), "this PC's version is kept");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, taken.SettingsJson));
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveBothThatCannotKeepThisPcsVersionTakesNothing()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
// The server holds a photo this PC does not have yet, and its settings name a frame: taking them reads the server's
|
||||
// frames, after this PC's copy was kept and before the server's version is written.
|
||||
var photos = f.NewPhotos(3);
|
||||
var local = await f.LocalAsync("Holy grail", photos[..2]);
|
||||
var remote = f.Remote.Add("Holy grail", photos);
|
||||
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
|
||||
await f.RefreshAsync();
|
||||
local = await f.EditLocalSettingsAsync(local.Id, SyncFixture.Window41);
|
||||
var theirs = """{"heroFrame":1,"exposure":{"deflickerWindow":{"isAuto":false,"manual":33}}}""";
|
||||
f.Remote.EditSettings(remote.Id, theirs);
|
||||
await f.RefreshAsync();
|
||||
Assert.NotNull((await f.EntryAsync("Holy grail")).Link!.ConflictRemote);
|
||||
var left = f.Archive.Paths.Sequence(local.Folder).Folder;
|
||||
|
||||
// Another index moves the folder while the server's version is read, so this PC's version cannot be kept there; this
|
||||
// index's scan finds the folder before the server's version would be written.
|
||||
var (other, archive) = await f.Archive.OtherWriterAsync();
|
||||
string? moved = null;
|
||||
f.Remote.OnceBeforeManifest = async () =>
|
||||
{
|
||||
var plan = await other.PlanRenameAsync(archive.Id, [local.Id], "moved/{title}", null, f.Ct);
|
||||
await other.ApplyRenameAsync(plan, null, f.Ct);
|
||||
moved = plan.Steps.Single().ToFolder;
|
||||
};
|
||||
f.Remote.OnceBeforeFrames = () => f.Archive.ScanAsync();
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct));
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), refused.Message, "the user hears to try again after the next scan");
|
||||
// The server's frames were not read for a version that is not taken: the scan comes now.
|
||||
f.Remote.OnceBeforeFrames = null;
|
||||
await f.Archive.ScanAsync();
|
||||
|
||||
var kept = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!;
|
||||
Assert.Equal(moved, kept.Folder, "the scan found the folder");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, kept.SettingsJson), "this PC's version is not replaced without its copy");
|
||||
var meta = f.Archive.Paths.Sequence(kept.Folder).MetaDirectory;
|
||||
Assert.Empty(Directory.GetFiles(meta, SyncService.SavedCopyPattern));
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
Assert.NotNull((await f.EntryAsync("Holy grail")).Link!.ConflictRemote, "still a conflict");
|
||||
|
||||
// Asked again where the sequence is now, both versions are kept.
|
||||
var copy = await f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct);
|
||||
Assert.Equal(copy, Assert.Contains(Directory.GetFiles(meta, SyncService.SavedCopyPattern), _ => true));
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(copy!, f.Ct)), "this PC's version is kept");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakeServerWhereAnotherIndexMovedTheFolderWritesNothing()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
var left = f.Archive.Paths.Sequence(local.Folder).Folder;
|
||||
|
||||
// Another index moves the folder while the server's version is read; this index has not scanned it since.
|
||||
var (other, archive) = await f.Archive.OtherWriterAsync();
|
||||
f.Remote.OnceBeforeManifest = async () =>
|
||||
{
|
||||
var plan = await other.PlanRenameAsync(archive.Id, [local.Id], "moved/{title}", null, f.Ct);
|
||||
await other.ApplyRenameAsync(plan, null, f.Ct);
|
||||
};
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
Assert.Null(f.Remote.OnceBeforeManifest, "the folder moved during the resolution");
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), refused.Message, "the user hears to try again after the next scan");
|
||||
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "nothing applied");
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(f.Archive.Paths.Sequence("moved/Holy grail").ProjectPath, f.Ct)),
|
||||
"the moved project is this PC's version");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakeServerAndSaveBothWriteNothingIntoAnotherSequenceMovedIntoTheFolder()
|
||||
{
|
||||
const string strangers = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":7}}}""";
|
||||
foreach (var resolution in new[] { SyncResolution.TakeServer, SyncResolution.SaveBoth })
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
var stranger = await f.LocalAsync("Stranger", f.NewPhotos(2), strangers);
|
||||
var folder = f.Archive.Paths.Sequence(local.Folder);
|
||||
|
||||
// Another index moves the folder away while the server's version is read, then another sequence (first parked
|
||||
// elsewhere: its folder is the same name with a number) into the folder it left; this index has scanned neither.
|
||||
var (other, archive) = await f.Archive.OtherWriterAsync();
|
||||
List<string>? before = null;
|
||||
f.Remote.OnceBeforeManifest = async () =>
|
||||
{
|
||||
foreach (var (id, template) in new[] { (local.Id, "moved/{title}"), (stranger.Id, "parked/{title}"), (stranger.Id, local.Folder) })
|
||||
await other.ApplyRenameAsync(await other.PlanRenameAsync(archive.Id, [id], template, null, f.Ct), null, f.Ct);
|
||||
before = ArchiveFixture.FilesOf(folder.Folder);
|
||||
};
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, resolution, f.Ct));
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), refused.Message, $"{resolution}: the user hears to try again after the next scan");
|
||||
|
||||
// Neither version went into the other sequence's folder, nor replaced this PC's where the sequence is.
|
||||
Assert.Equal(stranger.Id, SequenceTrash.SidecarId(folder.ManifestPath), "the other sequence holds the folder");
|
||||
Assert.SequenceEqual(before!, ArchiveFixture.FilesOf(folder.Folder), $"{resolution}: the other sequence's files are untouched");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "nothing applied");
|
||||
var moved = f.Archive.Paths.Sequence("moved/Holy grail");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(moved.ProjectPath, f.Ct)), "the moved project is this PC's version");
|
||||
Assert.Empty(Directory.GetFiles(moved.MetaDirectory, SyncService.SavedCopyPattern));
|
||||
|
||||
// Chosen again once this index's scan found both, it is done where the sequence is now.
|
||||
await f.Archive.ScanAsync();
|
||||
var copy = await f.Sync.ResolveAsync(f.Remote, remote.Id, resolution, f.Ct);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, await File.ReadAllTextAsync(moved.ProjectPath, f.Ct)), resolution.ToString());
|
||||
Assert.Equal(resolution == SyncResolution.SaveBoth, copy is not null && Path.GetDirectoryName(copy) == moved.MetaDirectory);
|
||||
Assert.True(SyncRules.SameSettings(strangers, await File.ReadAllTextAsync(folder.ProjectPath, f.Ct)), "the other sequence keeps its own");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepMineRefusesWhenTheServerChangedAfterTheConflictWasShown()
|
||||
{
|
||||
@@ -441,7 +609,8 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
var later = SyncFixture.Window41.Replace("41", "45", StringComparison.Ordinal);
|
||||
await f.EditLocalSettingsAsync(local.Id, later);
|
||||
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
Assert.Equal(Loc.L("Errors.Sync.ChangedAgain"), refused.Message);
|
||||
|
||||
Assert.True(SyncRules.SameSettings(later, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "this PC's later edit is kept");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, remote.SettingsJson));
|
||||
|
||||
Reference in new issue
Block a user