fix: keep pre-rule templates through web settings saves; retry render filing after another index moved the folder
The web panel's archive settings save checked both request templates against every template rule before the engine ran, so an archive.json saved before the rules made every save fail, even of the name or proxy size. Only a template that differs from the stored one is now held to the rules, as ArchiveService already does, and a TemplateRuleException from the engine (archive.json changed since the form was read) answers invalid_template with its rule instead of archive_policy. Exports follow a moved folder correctly in two more cases. Image-sequence exports are folders, so the rebase now tests Path.Exists instead of File.Exists. An export left at the old path no longer pins a sequence's row when that path now belongs to another sequence (its sidecar holds the old folder, or its render row names the path); the row follows to the new path, so it never names another sequence's file. RenderStore throws FolderMovedException when the sequence is not in the folder the index has. That is transient until this index's next scan, so client render uploads and render-node results now answer 503 folder_moved, keep the part file and the node's job, instead of failing them for good with a wrong reason. Save both and Take server refused because the folder moved now say Errors.Archive.FolderMoved (try again after the next scan) instead of the "changed again, choose again" sentence, which repeated until a scan. Doc wording: the ReorganizeDialogViewModel summary covers a sequence kept whole, and RenamePlanner.Plan's existsExactly says the own folder is found under at most one of the two names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit d898798657197d48f4e19b7f776003eb2fc441b5)
This commit is contained in:
1 parent
d0da224de5
commit
964b996af2
21 files changed
+239
-46
No files matched your search
@@ -266,4 +266,54 @@ public sealed class AdminTests(TestContext context)
|
||||
}
|
||||
await File.WriteAllBytesAsync(path, saved, context.Cancellation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TemplatesSavedBeforeTheRulesNeverFailASaveOfTheOtherFields()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: Chronos.Server.Storage.ArchiveModule.Register);
|
||||
var admin = await server.AdminAsync();
|
||||
// An archive.json of 0.1.0-rc.5 or earlier: both templates break a rule new templates are held to.
|
||||
var path = new Chronos.Core.Archiving.ArchivePaths(server.Options.ArchivePath).ManifestPath;
|
||||
var manifest = Chronos.Core.Archiving.ManifestStore.ReadArchive(path);
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(path, manifest with
|
||||
{
|
||||
LayoutTemplates = new Chronos.Core.Archiving.LayoutTemplates { Folder = "exports/{date}", File = "{date}" },
|
||||
});
|
||||
using var read = await admin.GetAsync("/api/v1/archive/settings");
|
||||
var archive = await read.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(("exports/{date}", "{date}"), (archive.FolderTemplate, archive.FileTemplate));
|
||||
|
||||
// The form sends every field with each save: the name and the proxies change, the templates stay as they are.
|
||||
using (var put = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { Name = "Studio", ProxyLongEdge = 2560 }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
var saved = await put.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(("Studio", "exports/{date}", "{date}", 2560), (saved.Name, saved.FolderTemplate, saved.FileTemplate, saved.ProxyLongEdge));
|
||||
}
|
||||
archive = archive with { Name = "Studio", ProxyLongEdge = 2560 };
|
||||
|
||||
// A template given anew is held to every rule; each one is fixed alone.
|
||||
using (var refused = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { FileTemplate = "{n}{ext}" }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
Assert.Equal("fileTemplate:extension", (await refused.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
using (var folder = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { FolderTemplate = "{year}/{date}" }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
var saved = await folder.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(("{year}/{date}", "{date}"), (saved.FolderTemplate, saved.FileTemplate));
|
||||
}
|
||||
archive = archive with { FolderTemplate = "{year}/{date}" };
|
||||
|
||||
// A desktop fixed the file template in archive.json since the form was read: the old one the form still sends is no
|
||||
// longer the file's, so it is held to the rules and the save says which one it breaks.
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(path, Chronos.Core.Archiving.ManifestStore.ReadArchive(path) with
|
||||
{
|
||||
LayoutTemplates = new Chronos.Core.Archiving.LayoutTemplates { Folder = "{year}/{date}", File = "{date}_{n:0000}" },
|
||||
});
|
||||
var before = await File.ReadAllBytesAsync(path, context.Cancellation);
|
||||
using (var stale = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { ProxyLongEdge = 1280 }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
var error = await stale.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template");
|
||||
Assert.Equal(("fileTemplate:not_unique", Chronos.Core.Localization.Loc.Get("Errors.Template.NotUnique", System.Globalization.CultureInfo.GetCultureInfo("en"))),
|
||||
(error.Details, error.Message));
|
||||
}
|
||||
Assert.SequenceEqual(before, await File.ReadAllBytesAsync(path, context.Cancellation));
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
var video = Uploads.Photo(4096, 30);
|
||||
var staged = Path.Combine(context.CreateTempDirectory("staged"), "render.mp4");
|
||||
await File.WriteAllBytesAsync(staged, video);
|
||||
Assert.Null(await server.Services.GetRequiredService<RenderStore>().CommitAsync(sequence, staged,
|
||||
await Assert.ThrowsAsync<FolderMovedException>(() => server.Services.GetRequiredService<RenderStore>().CommitAsync(sequence, staged,
|
||||
new RenderResultRequest("Roof - 4K.mp4", video.Length, Uploads.Sha(video), "4K HEVC", "hevc", 3840, 2160, 25, 4), "studio-pc", CancellationToken.None));
|
||||
|
||||
Assert.FileExists(staged);
|
||||
|
||||
@@ -190,6 +190,20 @@ public sealed class RenderNodeTests(TestContext context)
|
||||
{
|
||||
File.Move(paths.ManifestPath + ".away", paths.ManifestPath);
|
||||
}
|
||||
// A desktop sharing the archive moved the sequence's folder: this server's index has it at the old place until its
|
||||
// next scan, and nothing is filed there meanwhile.
|
||||
var folder = (await server.Database.Sequences.GetAsync(frame.SequenceId))!.Folder;
|
||||
var left = paths.FromRelative(folder);
|
||||
Directory.Move(left, paths.FromRelative(folder + " moved"));
|
||||
await RefusedAsync("folder_moved");
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
// The next scan finds it where it is now (moved here as a scan moves it: this composition writes no sidecars), and the
|
||||
// renders are filed there.
|
||||
await using (var tx = await server.Database.BeginAsync(context.Cancellation))
|
||||
{
|
||||
await tx.Sequences.RelocateAsync(frame.SequenceId, folder + " moved", null, context.Cancellation);
|
||||
await tx.CommitAsync(context.Cancellation);
|
||||
}
|
||||
|
||||
foreach (var complete in completions)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user