fix(archive): exports follow a folder any index moved; proxies, exports and copies no longer recreate it

Second review of owner review 2, phase 4a (Reorganize), cross-cutting findings.

- A second index of the archive (a desktop sharing a server's archive, or a folder moved by
  hand) moved the sequence row at its next scan but left renders.output_path at the old
  folder: the export answered 404 there. The scan now rebases the render rows in the same
  transaction when it finds a sequence in another folder.
- The rebase covers every render of the archive under the old folder: the sequence's own
  exports always, and another sequence's export saved inside it (through the Export folder
  picker) when its file moved with the folder. That check keeps the exports of a sequence
  that took the old folder since (a later Reorganize on the other index) where they are. A
  change of case only counts as a move.
- The desktop now tells an open editor after each Reorganize step
  (ArchiveServiceOptions.SequenceChanged -> AppServices.SequenceReorganized), and the editor
  reads its sequence again where it is now, so frames no longer decode blank until the next
  save. LocalSequenceSource.LoadAsync also requires the same folder on both row reads, so a
  move that commits during the frame listing is never taken as current.
- Writers that wrote without the lease, or trusted a row another index had moved, could
  create the old folder again. A proxy sent by a client is now filed under the sequence's
  lease into the folder the index has then, and a gone sequence or folder answers 404
  (sequence_busy 503 after the lease wait). The server files a render a client or render
  node sends under the lease (ArchiveService.UnderLeaseAsync). "Save both" keeps its copy
  under the lease. The proxy pass holds the thumbnail lease, as the thumbnail pass does. The
  deep analysis opens its checkpoint under the sequence lock only while the folder is still
  there, and a pass whose folder another process moved records nothing (the job logs
  Advisor.Log.FramesChangedElsewhere). Editor saves and sync applies refuse when the folder
  is gone.
- ARCHITECTURE.md no longer claims more than this: a render of another process whose folder
  moves while it runs is still not stopped.
- ArchiveVerifier.FlushAsync: corrected the comment. A move keeps each file's stamp, so only a
  check that found the file missing no longer applies.

Tests cover the scan path with a later swap into the vacated folder, another sequence's
export inside a moving folder, a photo deletion refused when the folder moved while it
waited for the lease, proxies sent and made after a move, Save both during a move, a deep
analysis whose folder another index moved, a render filed after a move on the server, and
an open editor reloaded by a Move job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c857b98f795b22956c060f1c5acf4d94b6d1c994)
This commit is contained in:
Alby96 committed 2026-10-27 18:09:02 +01:00
1 parent 765f0ad36b
commit 6e99a4b269
20 files changed
+561 -160

No files matched your search

@@ -330,6 +330,59 @@ public sealed class EditorSmokeTests
}
});
/// <summary>
/// A Reorganize of this PC moves the folder of the sequence open in the editor: the editor reads it again where it is
/// now as soon as its step is done, so its frames decode and its project goes there.
/// </summary>
[Test]
public Task AnOpenSequenceIsReadAgainWhereAReorganizeMovedIt() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var id = await app.Sample.FillEditorAsync();
var db = app.Services.Database!;
var archives = app.Services.Archives!;
var source = new LocalSequenceSource(db, id, Chronos.Core.Imaging.Decoders.DecoderFactory.CreateClient(null), null);
var content = await source.LoadAsync(CancellationToken.None);
var editor = new EditorViewModel(app.Shell, new EditorSession(source, content, []), [], EncoderHost.Client);
await using (editor)
{
var archive = (await db.Archives.GetAsync(content.Sequence.ArchiveId))!;
var templates = new Chronos.Core.Archiving.RenameTemplates("Moved/{date}");
var plan = await archives.PlanReorganizeAsync(archive.Id, [id], templates, CancellationToken.None);
var moved = plan.Steps.Single().ToFolder;
await using var engine = new Chronos.Data.Jobs.JobEngine(db, archives.CreateJobHandlers(), new Chronos.Data.Jobs.JobEngineOptions
{
WorkerId = "test",
Kinds = [JobKind.Move],
PollInterval = TimeSpan.FromMilliseconds(50),
});
await engine.StartAsync(CancellationToken.None);
var job = await Chronos.Data.Archiving.ArchiveJobs.EnqueueAsync(engine, Chronos.Data.Archiving.ArchiveJobs.Reorganize(archive, plan, templates));
// The editor reads its photos as it opens; on Windows the folder cannot move while one is open, and the job that
// failed holds the plan for its retry.
for (var attempt = 1; ; attempt++)
{
Job? ended = null;
for (var i = 0; i < 1200 && ended is null; i++)
{
await Task.Delay(25);
if (await db.Jobs.GetAsync(job.Id) is { State: JobState.Done or JobState.Failed or JobState.Cancelled } now) ended = now;
}
Assert.NotNull(ended, "the move job ends");
if (ended!.State == JobState.Done) break;
Assert.True(ended.State == JobState.Failed && attempt < 20, ended.Error);
await Task.Delay(250);
await engine.ResumeAsync(job.Id, CancellationToken.None);
}
for (var i = 0; i < 400 && editor.Session.Content.Sequence.Folder != moved; i++) await Task.Delay(25);
Assert.Equal(moved, editor.Session.Content.Sequence.Folder);
Assert.True(await source.FramesCurrentAsync(CancellationToken.None), "the editor holds the frames where they are now");
using var frame = await source.DecodeAsync(0, 32, Chronos.Core.Imaging.DecodePurpose.Thumbnail, CancellationToken.None);
Assert.NotNull(frame, "its frames decode");
}
});
/// <summary>
/// At the 1200 px minimum beside the 200 px rail (owner review 1, R1), the preview's tools stay inside the preview in
/// every language, crop mask on (the crop-result tool enabled): they take a second line rather than lose Play and Full screen.
@@ -241,23 +241,30 @@ public sealed class MassRenameTests(TestContext context)
{
await using var fx = await CreateAsync(context);
var ids = await NestedAsync(fx);
// Exports of "trips" and of "trips/day2" in their folders, one of "trips" outside the archive, and a row whose
// path only starts with the same letters.
// Exports of "trips" and of "trips/day2" in their folders, one of "trips/day2/dawn" saved in the exports of "trips"
// (the Export tab's folder picker), one of "trips" outside the archive, a row whose path only starts with the same
// letters, and one of "trips/day2" in "trips" whose file is gone.
var outside = Path.Combine(context.CreateTempDirectory("exports"), "Trips elsewhere.mp4");
List<Guid> renders =
[
await RenderAsync(fx, ids[0], "trips/exports/Trips.mp4"),
await RenderAsync(fx, ids[1], "trips/day2/exports/Day 2.mp4"),
await RenderAsync(fx, ids[2], "trips/exports/Dawn.mp4"),
await RenderAsync(fx, ids[0], outside),
await RenderAsync(fx, ids[0], "trips 2/exports/Other.mp4", write: false),
await RenderAsync(fx, ids[1], "trips/exports/Gone.mp4", write: false),
];
var plan = await fx.Service.PlanRenameAsync(fx.Archive.Id, [ids[0]], "moved/{date}", null, fx.Ct);
Assert.SequenceEqual([false, true, true], plan.Steps.Select(s => s.Carried));
await fx.Service.ApplyRenameAsync(plan, null, fx.Ct);
string[] expected = ["moved/2026-09-28/exports/Trips.mp4", "moved/2026-09-28/day2/exports/Day 2.mp4", outside, "trips 2/exports/Other.mp4"];
string[] expected =
[
"moved/2026-09-28/exports/Trips.mp4", "moved/2026-09-28/day2/exports/Day 2.mp4", "moved/2026-09-28/exports/Dawn.mp4", outside,
"trips 2/exports/Other.mp4", "trips/exports/Gone.mp4",
];
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
foreach (var path in expected[..3]) Assert.FileExists(Path.IsPathRooted(path) ? path : fx.Paths.FromRelative(path));
foreach (var path in expected[..4]) Assert.FileExists(Path.IsPathRooted(path) ? path : fx.Paths.FromRelative(path));
// A crash after the steps were recorded but before the journal said so: completed again, and again, nothing moves twice.
RenameJournal.Write(fx.Paths, new RenameJournal(plan, []));
@@ -266,6 +273,71 @@ public sealed class MassRenameTests(TestContext context)
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
}
[Test]
public async Task AnotherIndexFindsTheExportsWhereAReorganizeMovedTheirFolder()
{
await using var fx = await CreateAsync(context);
var ids = await PopulateAsync(fx);
// This index's exports: of "inbox/a" in its folder, of "inbox/b" saved in the exports of "inbox/a", of "inbox/c" in its own.
List<Guid> renders =
[
await RenderAsync(fx, ids[0], "inbox/a/exports/A.mp4"),
await RenderAsync(fx, ids[1], "inbox/a/exports/B.mp4"),
await RenderAsync(fx, ids[2], "inbox/c/exports/C.mp4"),
];
var (server, archive) = await fx.OtherWriterAsync();
// The other index (a server sharing this desktop's archive) moves "inbox/a", then "inbox/c" into the folder it left.
var first = await server.PlanRenameAsync(archive.Id, [ids[0]], "moved/{date}", null, fx.Ct);
await server.ApplyRenameAsync(first, null, fx.Ct);
var second = await server.PlanRenameAsync(archive.Id, [ids[2]], "inbox/a", null, fx.Ct);
Assert.Equal("inbox/a", second.Steps.Single().ToFolder);
await server.ApplyRenameAsync(second, null, fx.Ct);
// A scan here finds both where they are now (the new "inbox/a" first): each export follows the folder its file moved with.
await fx.ScanAsync();
Assert.Equal("moved/2026-09-28", (await fx.Db.Sequences.GetAsync(ids[0], fx.Ct))!.Folder);
Assert.Equal("inbox/a", (await fx.Db.Sequences.GetAsync(ids[2], fx.Ct))!.Folder);
string[] expected = ["moved/2026-09-28/exports/A.mp4", "moved/2026-09-28/exports/B.mp4", "inbox/a/exports/C.mp4"];
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
foreach (var path in expected) Assert.FileExists(fx.Paths.FromRelative(path));
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
}
[Test]
public async Task APhotoDeletionWhoseFolderMovedWhileItWaitedForTheLeaseIsRefused()
{
await using var fx = await CreateAsync(context);
var ids = await PopulateAsync(fx);
var frames = await fx.Db.Frames.ListBySequenceAsync(ids[0], cancellationToken: fx.Ct);
var deletion = await fx.Service.FrameTrash.PlanDeleteAsync(ids[0], [frames[1].Id], cancellationToken: fx.Ct);
Assert.True(deletion.CanDelete);
var pause = TimeSpan.FromSeconds(TestTiming.Budget(0.5));
// Another process holds the sequence and moves its folder (a Reorganize), while the deletion waits for the lease.
Task<FrameDeleteResult> delete;
using (await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"seq-{ids[0]:N}", "other", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct))
{
delete = fx.Service.FrameTrash.DeleteAsync(deletion, cancellationToken: fx.Ct);
await Task.Delay(pause, fx.Ct);
Assert.False(delete.IsCompleted, "the deletion waits for the other process");
Directory.CreateDirectory(fx.Paths.FromRelative("moved"));
Directory.Move(fx.Paths.FromRelative("inbox/a"), fx.Paths.FromRelative("moved/a"));
await using var tx = await fx.Db.BeginAsync(fx.Ct);
await tx.Sequences.RelocateAsync(ids[0], "moved/a", null, fx.Ct);
await tx.Frames.RebaseFolderAsync(ids[0], "inbox/a", "moved/a", fx.Ct);
await tx.CommitAsync(fx.Ct);
}
await Assert.ThrowsAsync<StaleDeletePlanException>(() => delete);
Assert.Count(3, await fx.Db.Frames.ListBySequenceAsync(ids[0], cancellationToken: fx.Ct));
Assert.Count(3, ManifestStore.ReadSequence(fx.Paths.Sequence("moved/a").ManifestPath).Frames);
foreach (var f in frames) Assert.FileExists(fx.Paths.FromRelative(f.RelativePath.Replace("inbox/a/", "moved/a/", StringComparison.Ordinal)));
Assert.Empty(await fx.Service.Trash.ListAsync(fx.Archive, fx.Ct));
Assert.False(Directory.Exists(fx.Paths.FromRelative("inbox/a")), "the folder it left is not created again");
}
[Test]
public async Task AnInterruptedMoveTakesTheExportsAlongWhenItResumes()
{
@@ -37,11 +37,11 @@ public sealed class ProxyTests(TestContext context)
var folder = fx.Paths.Sequence(sequence.Folder);
var images = fx.Service.Images;
Assert.Equal(ProxyStoreResult.Invalid, images.StoreProxy(fx.Archive, sequence, frames[0], "not a photo"u8.ToArray()));
Assert.Equal(ProxyStoreResult.WrongFrame, images.StoreProxy(fx.Archive, sequence, frames[0], Proxy(frames[1].CapturedAt!.Value, 1)));
Assert.Equal(ProxyStoreResult.Invalid, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], "not a photo"u8.ToArray(), fx.Ct));
Assert.Equal(ProxyStoreResult.WrongFrame, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], Proxy(frames[1].CapturedAt!.Value, 1), fx.Ct));
Assert.FileMissing(folder.Proxy(0));
var proxy = Proxy(frames[0].CapturedAt!.Value, 2);
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frames[0], proxy));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], proxy, fx.Ct));
Assert.SequenceEqual(proxy, await File.ReadAllBytesAsync(folder.Proxy(0), fx.Ct));
// The proxy pass keeps what was sent and makes none from the originals here, even when forced.
@@ -62,6 +62,32 @@ public sealed class ProxyTests(TestContext context)
Assert.Equal((0, 1, 1), (again.Built, again.Reused, again.Undecodable));
}
[Test]
public async Task ProxiesSentOrMadeAfterTheFolderMovedGoWhereTheSequenceIsNow()
{
await using var fx = await CreateAsync(context);
var (stale, frames) = await HeifSequenceAsync(fx);
var images = fx.Service.Images;
var plan = await fx.Service.PlanRenameAsync(fx.Archive.Id, [stale.Id], "moved/{date}", null, fx.Ct);
await fx.Service.ApplyRenameAsync(plan, null, fx.Ct);
var now = fx.Paths.Sequence(plan.Steps.Single().ToFolder);
var left = fx.Paths.Sequence(stale.Folder).Folder;
Assert.False(Directory.Exists(left));
// A proxy upload and a proxy pass that read the sequence before the move write once they hold its lease.
var proxy = Proxy(frames[0].CapturedAt!.Value, 2);
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, stale, frames[0], proxy, fx.Ct));
Assert.SequenceEqual(proxy, await File.ReadAllBytesAsync(now.Proxy(0), fx.Ct));
var pass = await images.BuildProxiesAsync(fx.Archive, stale, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
Assert.Equal((0, 1, 0, 1), (pass.Built, pass.Reused, pass.Undecodable, pass.Waiting));
Assert.False(Directory.Exists(left), "the folder it left is not created again");
// Deleted since: nothing is written.
Assert.True(await fx.Db.Sequences.DeleteAsync(stale.Id, fx.Ct));
Assert.Equal(ProxyStoreResult.Gone, await images.StoreProxyAsync(fx.Archive, stale, frames[1], Proxy(frames[1].CapturedAt!.Value, 3), fx.Ct));
Assert.FileMissing(now.Proxy(1));
}
[Test]
public async Task AProxyLeftByARenumberedFrameIsAskedForAgain()
{
@@ -99,8 +125,8 @@ public sealed class ProxyTests(TestContext context)
// A client or render node sending one that small is refused; one of the policy's size (1920 px) is kept.
var frame = frames[0] with { Width = 4032, Height = 3024 };
Assert.Equal(ProxyStoreResult.TooSmall, images.StoreProxy(fx.Archive, sequence, frame, Proxy(frame.CapturedAt!.Value, 6, 160, 120)));
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frame, Proxy(frame.CapturedAt!.Value, 7, 1920, 1440)));
Assert.Equal(ProxyStoreResult.TooSmall, await images.StoreProxyAsync(fx.Archive, sequence, frame, Proxy(frame.CapturedAt!.Value, 6, 160, 120), fx.Ct));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frame, Proxy(frame.CapturedAt!.Value, 7, 1920, 1440), fx.Ct));
var again = await images.BuildProxiesAsync(fx.Archive, sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
Assert.Equal((0, 1, 0, 1), (again.Built, again.Reused, again.Undecodable, again.Waiting));
Assert.FileExists(folder.Proxy(0));
@@ -114,7 +140,7 @@ public sealed class ProxyTests(TestContext context)
var manifest = ManifestStore.ReadArchive(fx.Paths.ManifestPath);
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with { ProxyPolicy = new ProxyPolicy { LongEdge = ProxyPolicy.Disabled } });
Assert.Equal(ProxyStoreResult.Disabled, fx.Service.Images.StoreProxy(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 4)));
Assert.Equal(ProxyStoreResult.Disabled, await fx.Service.Images.StoreProxyAsync(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 4), fx.Ct));
Assert.FileMissing(fx.Paths.Sequence(sequence.Folder).Proxy(0));
}
@@ -170,7 +196,7 @@ public sealed class ProxyTests(TestContext context)
// A client makes one from the index's time: it is kept, and the next pass reuses it rather than making its own.
var sent = Proxy(frame.CapturedAt!.Value, 1);
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frame, sent));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frame, sent, fx.Ct));
var again = await images.BuildProxiesAsync(fx.Archive, sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
Assert.Equal((0, 1), (again.Built, again.Reused));
Assert.SequenceEqual(sent, await File.ReadAllBytesAsync(folder.Proxy(0), fx.Ct));
@@ -264,7 +290,7 @@ public sealed class ProxyTests(TestContext context)
await using var fx = await CreateAsync(context);
var (sequence, frames) = await HeifSequenceAsync(fx);
var images = fx.Service.Images;
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frames[1], Proxy(frames[1].CapturedAt!.Value, 1)));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frames[1], Proxy(frames[1].CapturedAt!.Value, 1), fx.Ct));
// A pass resumed at frame 1 (paused, retried or restarted) finds that frame done, but frame 0 still waits: the
// status must not tell a server's clients that nothing is wanted.
@@ -272,7 +298,7 @@ public sealed class ProxyTests(TestContext context)
Assert.Equal((0, 1, 0, 0), (resumed.Built, resumed.Reused, resumed.Undecodable, resumed.Waiting));
Assert.False(await ProxiesBuiltAsync(fx, sequence), "frame 0 has no proxy");
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 2)));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 2), fx.Ct));
await images.BuildProxiesAsync(fx.Archive, sequence, force: false, 1, (_, _) => ValueTask.CompletedTask, fx.Ct);
Assert.True(await ProxiesBuiltAsync(fx, sequence), "every frame has its proxy");
}
@@ -290,7 +316,7 @@ public sealed class ProxyTests(TestContext context)
{
Frames = [.. sidecar.Frames.Select(f => f with { Tier = DecodeTier.EmbeddedPreview, Flags = f.Flags | FrameFlags.PreviewOnly, PreviewW = 160, PreviewH = 120 })],
});
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 1)));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 1), fx.Ct));
// Frame 0 now renders from its proxy, not from the thumbnail: it caps nothing. Its tier stays the original's.
await images.BuildProxiesAsync(fx.Archive, sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
@@ -315,7 +341,7 @@ public sealed class ProxyTests(TestContext context)
var (sequence, frames) = await HeifSequenceAsync(fx);
var folder = fx.Paths.Sequence(sequence.Folder);
var images = fx.Service.Images;
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 1, 640, 480)));
Assert.Equal(ProxyStoreResult.Stored, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 1, 640, 480), fx.Ct));
Task<ImagePassResult> ThumbnailsAsync(bool force = false) =>
images.BuildThumbnailsAsync(fx.Archive, sequence, force, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
(int, int) Entry()
@@ -455,6 +455,33 @@ public sealed class AnalysisJobTests(TestContext context)
Assert.Contains("13", ProjectSettings.FromJson(await ProjectJsonAsync(fx, folder)).Timing.FrameRate.ReasonArgs!);
}
[Test]
public async Task ADeepAnalysisWhoseFolderAnotherChronosMovedRecordsNothingAndCreatesNoFolder()
{
// One decode at a time, so the held one is the only photo being read while the folder moves.
await using var fx = await ProcessingFixture.CreateAsync(context, o => o with { DeepAnalysis = o.DeepAnalysis with { MaxDegreeOfParallelism = 1 } });
var sequence = await fx.AddAsync(Flickering(12));
var left = fx.Folder(sequence).Folder;
var (server, archive) = await fx.Archive.OtherWriterAsync();
await fx.StartEngineAsync();
// A server sharing this desktop's archive reorganizes the sequence while the deep pass reads its photos.
fx.Decoder.HoldFrame(5);
var deep = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
await fx.Decoder.Holding.Task.WaitAsync(TimeSpan.FromSeconds(60), fx.Ct);
var plan = await server.PlanRenameAsync(archive.Id, [sequence.Id], "Moved/{date}", null, fx.Ct);
await server.ApplyRenameAsync(plan, null, fx.Ct);
fx.Decoder.Hold = null;
fx.Decoder.Release();
var done = await fx.WaitForAsync(deep.Id, JobState.Done);
Assert.Contains(Loc.L("Advisor.Log.FramesChangedElsewhere", sequence.DisplayTitle), done.LogTail);
Assert.False(Directory.Exists(left), "the folder it left is not created again");
var moved = fx.Archive.Paths.Sequence(plan.Steps.Single().ToFolder);
Assert.FileMissing(moved.AnalysisPath);
Assert.False((await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!.Status.HasFlag(SequenceStatus.AnalyzedDeep), "nothing is recorded");
}
[Test]
public async Task ALightAnalysisOvertakenByAScanMarksNothingAnalysedAndRunsAgain()
{
@@ -432,6 +432,30 @@ 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 KeepMineRefusesWhenTheServerChangedAfterTheConflictWasShown()
{
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using Chronos.Core.Archiving;
using Chronos.Core.Codecs.Jpeg;
using Chronos.Core.Model;
using Chronos.Data.Archiving;
using Chronos.Protocol;
using Chronos.Server.Api;
using Chronos.Server.Events;
@@ -120,6 +121,31 @@ public sealed class ReorganizeTests(TestContext context)
Assert.False(Directory.Exists(Path.Combine(server.Options.ArchivePath, folder)), "nothing is left at the old place");
}
[Test]
public async Task AnExportFiledAfterItsFolderMovedGoesWhereTheSequenceIsNow()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var id = (await Uploads.UploadAsync(editor, Photo(1), "IMG_0001.JPG", sessionKey: "roof")).SequenceId;
await UntilIdleAsync(server);
var stale = (await server.Database.Sequences.GetAsync(id))!;
// A render node's output read the sequence before a Reorganize moved its folder, and is filed after it.
var archives = server.Services.GetRequiredService<ArchiveService>();
var plan = await archives.PlanRenameAsync(stale.ArchiveId, [id], "reorganized/{date}", null, CancellationToken.None);
await archives.ApplyRenameAsync(plan, null, CancellationToken.None);
var folder = plan.Steps.Single().ToFolder;
var video = Uploads.Photo(4096, 29);
var staged = Path.Combine(context.CreateTempDirectory("staged"), "render.mp4");
await File.WriteAllBytesAsync(staged, video);
var render = Assert.NotNull(await server.Services.GetRequiredService<RenderStore>().CommitAsync(stale, staged,
new RenderResultRequest("Roof - 4K.mp4", video.Length, Uploads.Sha(video), "4K HEVC", "hevc", 3840, 2160, 25, 4), "studio-pc", CancellationToken.None));
Assert.Equal($"{folder}/exports/Roof - 4K.mp4", render.OutputPath);
await Http.BytesEqualAsync(video, File.ReadAllBytesAsync(Path.Combine(server.Options.ArchivePath, render.OutputPath)));
Assert.False(Directory.Exists(Path.Combine(server.Options.ArchivePath, stale.Folder)), "the folder it left is not created again");
}
[Test]
public async Task AReorganizeAsksForTheArchiveAndAValidRequest()
{