fix(server): keep convert dry runs like Reorganize's, say what a new sequence lacks
The convert endpoint planned the whole selection inside the HTTP request, again for every mode, quality keystroke and confirmation, with no limit: behind a proxy an all-sequence conversion could never get past its dry run or its apply. - ReorganizePlanCache becomes PlanCache, shared by Reorganize and Convert: one plan per key made apart from the request, two at once across both kinds, eight kept, 15-minute timeout, 5-minute lifetime, 503 plan_dropped. Keys are typed records (ReorganizePlanKey, ConvertPlanKey) that also say which exceptions are refusals. - A conversion plan is keyed by archive, a convert stamp of the index (SequenceRepository.GetConvertStampAsync: the Reorganize stamp plus, per planned sequence, the photos' count, sizes, formats, pixel sizes and missing, corrupt, preview-only and undecodable flags), the sequences and the target with the quality that counts. Not the mode: the request's mode and options are set on the kept plan, and the free space is measured again at every request through the engine. A plan made while the volume was away is not kept (503 archive_offline). - New sequence holds the converted copies alone: the dry run says the skipped photos are not copied into it (Archive.Convert.NotCopied.*, Server.Convert.OnPcNew), the panel's totals, column and confirmation give the count, and so does the desktop's summary. - Panel: the preview is asked in Replace's neutral words; a dry run cut off by a proxy is asked again while the totals show how long it takes, plan_dropped is retried once; an apply the server let go plans again, a changed one shows Admin.Convert.PlanChanged, and one with no answer is not resent (its job may be queued). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit f0b1e379ce7c08b6d3459ab25ca6214c8f366f6c)
This commit is contained in:
1 parent
d0bbd77c92
commit
8174852a2c
22 files changed
+927
-342
No files matched your search
@@ -66,6 +66,19 @@ public sealed partial class AdminConvertTests(TestContext context)
|
||||
Assert.Contains("if (plan !== shownPlan && (plan?.key !== shownPlan.key || plan.fingerprint !== shownPlan.fingerprint)) {", dialog);
|
||||
Assert.Contains(@"showError(t(""Admin.Convert.PlanChanged""))", dialog);
|
||||
Assert.True(!dialog.Contains("plan !== shownPlan) return;", StringComparison.Ordinal), "a confirmed apply is dropped when the same plan is answered again");
|
||||
// Until a mode is chosen the preview is asked in Replace's words (the photos stay as they are); New sequence asks
|
||||
// again and says what the new sequences lack, in the rows, the totals and the confirmation.
|
||||
Assert.Contains(@"const PREVIEW_MODE = ""replace"";", dialog);
|
||||
Assert.Contains(@"t(copies ? ""Admin.Convert.TotalsNew"" : ""Admin.Convert.Totals""", dialog);
|
||||
Assert.Contains(@"plural(""Admin.Convert.ConfirmNewNotCopied"", notCopied)", dialog);
|
||||
// A dry run the server is still making is asked again (a proxy cut the request off, or the server let the plan go)
|
||||
// while the totals say how long it takes; a confirmation the server let go plans again, one that changed says so,
|
||||
// and one with no answer is not sent again (its job may be queued).
|
||||
Assert.Contains(@"cutOff(err, Date.now() - sent) || (err?.code === ""plan_dropped"" && dropped++ < DROPPED_RETRIES)", dialog);
|
||||
Assert.Contains(@"t(""Admin.Convert.PlanningFor"", formatDuration(seconds))", dialog);
|
||||
Assert.Contains(@"[""plan_changed"", ""plan_dropped"", ""not_enough_space"", ""nothing_to_convert""].includes(err?.code)", dialog);
|
||||
Assert.Contains(@"notice = err.code === ""plan_changed"" ? t(""Admin.Convert.PlanChanged"") : errorText(err);", dialog);
|
||||
Assert.Contains(@"showError(t(""Admin.Convert.NoAnswer""));", dialog);
|
||||
// The panel runs under a strict CSP: no inline handlers or styles.
|
||||
Assert.True(!Regex.IsMatch(dialog, @"\son[a-z]+="""), "inline handler");
|
||||
Assert.True(!dialog.Contains(" style=", StringComparison.Ordinal), "inline style");
|
||||
@@ -105,24 +118,24 @@ public sealed partial class AdminConvertTests(TestContext context)
|
||||
var browser = await Browser.SignInAsync(server);
|
||||
var italian = CultureInfo.GetCultureInfo("it");
|
||||
|
||||
// The body the dialog writes: the selection's ids, the format, the quality for a JPEG only, the mode (the preview's
|
||||
// while none is chosen), then dryRun.
|
||||
// The body the dialog writes: the selection's ids, the format, the quality for a JPEG only, the mode (the preview's,
|
||||
// Replace, while none is chosen), then dryRun.
|
||||
StringContent Body(string target, string quality, string mode, string tail) =>
|
||||
Json($$"""{"all":false,"sequenceIds":["{{id}}"],"target":"{{target}}","quality":{{quality}},"mode":"{{mode}}",{{tail}}}""");
|
||||
string preview;
|
||||
using (var dry = await browser.SendAsync(HttpMethod.Post, Url, Body("linear-dng", "null", "new-sequence", "\"dryRun\":true")))
|
||||
string fingerprint;
|
||||
using (var dry = await browser.SendAsync(HttpMethod.Post, Url, Body("linear-dng", "null", "replace", "\"dryRun\":true")))
|
||||
{
|
||||
await dry.ExpectAsync(HttpStatusCode.OK);
|
||||
using var plan = JsonDocument.Parse(await dry.Content.ReadAsStringAsync());
|
||||
var root = plan.RootElement;
|
||||
Assert.Equal(("linear-dng", "new-sequence"), (root.GetProperty("target").GetString(), root.GetProperty("mode").GetString()));
|
||||
Assert.Equal(("linear-dng", "replace"), (root.GetProperty("target").GetString(), root.GetProperty("mode").GetString()));
|
||||
Assert.Equal((1, 2, 0), (root.GetProperty("sequences").GetInt32(), root.GetProperty("photos").GetInt32(), root.GetProperty("skipped").GetInt32()));
|
||||
Assert.True(root.GetProperty("bytesBefore").GetInt64() > 0 && root.GetProperty("bytesAfter").GetInt64() > 0, "sizes");
|
||||
var space = root.GetProperty("space");
|
||||
Assert.True(space.GetProperty("enough").GetBoolean(), "enough");
|
||||
Assert.False(string.IsNullOrWhiteSpace(space.GetProperty("message").GetString()));
|
||||
preview = root.GetProperty("fingerprint").GetString()!;
|
||||
Assert.Equal(64, preview.Length);
|
||||
fingerprint = root.GetProperty("fingerprint").GetString()!;
|
||||
Assert.Equal(64, fingerprint.Length);
|
||||
var step = root.GetProperty("steps").EnumerateArray().Single();
|
||||
Assert.Equal(id, step.GetProperty("sequenceId").GetGuid());
|
||||
Assert.True(step.GetProperty("folder").GetString()!.Length > 0, "folder");
|
||||
@@ -132,14 +145,13 @@ public sealed partial class AdminConvertTests(TestContext context)
|
||||
Assert.Equal((0, 0), (step.GetProperty("skipped").GetArrayLength(), step.GetProperty("blocked").GetArrayLength()));
|
||||
}
|
||||
|
||||
// Replace chosen: the same photos, another fingerprint, so the dialog plans again before Apply.
|
||||
string fingerprint;
|
||||
using (var dry = await browser.SendAsync(HttpMethod.Post, Url, Body("linear-dng", "null", "replace", "\"dryRun\":true")))
|
||||
// New sequence chosen: the same photos, another fingerprint, so the dialog asks again before Apply (the server
|
||||
// answers from the plan it kept).
|
||||
using (var dry = await browser.SendAsync(HttpMethod.Post, Url, Body("linear-dng", "null", "new-sequence", "\"dryRun\":true")))
|
||||
{
|
||||
using var plan = JsonDocument.Parse(await dry.Content.ReadAsStringAsync());
|
||||
Assert.Equal(2, plan.RootElement.GetProperty("photos").GetInt32());
|
||||
fingerprint = plan.RootElement.GetProperty("fingerprint").GetString()!;
|
||||
Assert.NotEqual(preview, fingerprint);
|
||||
Assert.Equal(("new-sequence", 2), (plan.RootElement.GetProperty("mode").GetString(), plan.RootElement.GetProperty("photos").GetInt32()));
|
||||
Assert.NotEqual(fingerprint, plan.RootElement.GetProperty("fingerprint").GetString());
|
||||
}
|
||||
|
||||
// A quality the server refuses names its field: the dialog marks Quality.
|
||||
@@ -154,6 +166,14 @@ public sealed partial class AdminConvertTests(TestContext context)
|
||||
Assert.Equal(("same_format", 2), (skipped.GetProperty("reason").GetString(), skipped.GetProperty("photos").GetInt32()));
|
||||
Assert.Equal(Loc.Get("Archive.Convert.Skipped.SameFormat", italian), skipped.GetProperty("message").GetString());
|
||||
}
|
||||
// Into a new sequence, the same photos are not copied into it, and the table says so.
|
||||
using (var same = await browser.SendAsync(HttpMethod.Post, Url, Body("jpeg", "90", "new-sequence", "\"dryRun\":true")))
|
||||
{
|
||||
using var plan = JsonDocument.Parse(await same.Content.ReadAsStringAsync());
|
||||
var skipped = plan.RootElement.GetProperty("steps")[0].GetProperty("skipped").EnumerateArray().Single();
|
||||
Assert.Equal(("same_format", 2), (skipped.GetProperty("reason").GetString(), skipped.GetProperty("photos").GetInt32()));
|
||||
Assert.Equal(Loc.Get("Archive.Convert.NotCopied.SameFormat", italian), skipped.GetProperty("message").GetString());
|
||||
}
|
||||
// A plan that no longer matches is refused with the one there is now: the dialog plans again.
|
||||
using (var stale = await browser.SendAsync(HttpMethod.Post, Url, Body("linear-dng", "null", "replace", $"\"dryRun\":false,\"fingerprint\":\"{new string('0', 64)}\"")))
|
||||
Assert.Equal(fingerprint, (await stale.ExpectErrorAsync(HttpStatusCode.Conflict, "plan_changed")).Details);
|
||||
|
||||
Reference in new issue
Block a user