fix(admin): follow jobs on the Library pages, cap the delete list, honest restore tooltip
Review fixes for owner review 2, phase 3 (R6 Library on the web panel):
- Trash: the worker can end an emptying before the browser has read the
POST's 202, so its jobState arrived while the page did not know the job
yet; Empty then stayed disabled ("being emptied") and no result showed.
The page now keeps the last state of the jobs that ended and looks its
job up there before following it. Any ended job also reloads the list
(an emptying from another tab or the desktop sends no sequenceChanged),
and a Restore answered 404 shows the trash as it is now.
- Sequence: thumbnail, proxy, verify and analysis jobs send no
sequenceChanged, so tiles and the cover stayed placeholders and the
status chips stale. An ended job now schedules one refresh (not pushed
back by the next): the sequence is read again and failed images are
asked for again under a retry address (shared retryImages).
- Library list: Esc, Ctrl+A or unticking every card left the "Select all"
snapshot in place, hiding Select all and stopping the live refresh from
pruning the selection. It is dropped once no selected sequence lies
beyond the loaded rows; Clear filters clears the selection too.
- The sequences' delete dialog lists at most 500 names (blocked ones
first, with their reasons), like the photos' dialog (shared LISTED).
- Admin.Trash.RestoreSequence.Tip promised a SHA-256 check that a sequence
restore never makes (it moves the folder back); it now says so and names
Verify (en, it; no other culture had the key).
- The upload test's name and comments say what it checks: upload.js is
only imported dynamically, not loaded on click.
Tests pin each change in SystemEndpointTests; the pages were also driven
in a browser against a fake API, where the pre-fix modules fail and the
fixed ones pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 78f66082fd85543d619375574c82cc63a233b7a8)
This commit is contained in:
1 parent
66c3662954
commit
13278710a2
8 files changed
+182
-21
No files matched your search
@@ -190,10 +190,11 @@ public sealed partial class SystemEndpointTests(TestContext context)
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AdminPanelListsTheLibraryAndLoadsTheWebUploadOnDemand()
|
||||
public async Task AdminPanelListsTheLibraryAndImportsTheWebUploadOnlyDynamically()
|
||||
{
|
||||
// Owner review 2, R6: the Library comes right after the Dashboard. The web upload (R3) is a module of its own that the
|
||||
// Library imports on demand (Upload, and a sequence's Add photos), so a page that never uploads never loads it.
|
||||
// Owner review 2, R6: the Library comes right after the Dashboard. The web upload (R3) is a module of its own that
|
||||
// only the Library list and a sequence import, and only dynamically (never statically): the other pages never load
|
||||
// it, and the Library still works, without Upload and Add photos, when the module does not load.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var app = await server.Client.GetStringAsync("/admin/app.js");
|
||||
var top = MenuPages(app)[0];
|
||||
@@ -222,11 +223,83 @@ public sealed partial class SystemEndpointTests(TestContext context)
|
||||
Assert.Contains("openUpload({ api, sequence: seq, onDone: ", modules["pages/library/sequence.js"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheTrashPageSeesAnEmptyingThatEndedBeforeItsPostAnswered()
|
||||
{
|
||||
// The worker claims an emptying as soon as it is queued and can end it before the browser has read the 202: the page
|
||||
// keeps the last state of the jobs that ended and looks its own job up there before it starts following it.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var trash = await server.Client.GetStringAsync("/admin/pages/library/trash.js");
|
||||
Assert.Contains("ended.set(e.jobId, e)", trash);
|
||||
var lookedUp = trash.IndexOf("ended.get(job.id)", StringComparison.Ordinal);
|
||||
var followed = trash.IndexOf("emptyJob = job.id", StringComparison.Ordinal);
|
||||
Assert.True(lookedUp > 0 && followed > lookedUp, "the queued job is looked up among the ended ones before it is followed");
|
||||
// An emptying started elsewhere sends no sequenceChanged: any job that ends shows the trash again, and a restore
|
||||
// of an entry that is gone (404) does too.
|
||||
Assert.True(Regex.IsMatch(trash, @"e\.type === ""jobState"" && JOB_ENDED\.has\(e\.state\)"), "every ended job is seen");
|
||||
Assert.True(Regex.IsMatch(trash, @"if \(err\.status === 404\) await load\(\);"), "a restore of a gone entry reloads the trash");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASequencePageRefreshesAfterJobsAndAsksAgainForMissingThumbnails()
|
||||
{
|
||||
// Thumbnail, proxy, verify and analysis jobs send no sequenceChanged: when any job ends, the sequence page reads the
|
||||
// sequence again (facts, status chips) and asks again, past the browser's first answer, for the images that failed.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var sequence = await server.Client.GetStringAsync("/admin/pages/library/sequence.js");
|
||||
var shared = await server.Client.GetStringAsync("/admin/pages/library/shared.js");
|
||||
Assert.True(Regex.IsMatch(sequence, @"e\.type === ""jobState""\) \{\s+(//[^\n]*\s+)*if \(JOB_ENDED\.has\(e\.state\) && jobTimer === null\) jobTimer = setTimeout\(afterJob"),
|
||||
"an ended job schedules one refresh, not pushed back by the next");
|
||||
Assert.True(Regex.IsMatch(sequence, @"async function afterJob\(\) \{[^}]*await reload\(false\);[^}]*retryImages\(root\);", RegexOptions.Singleline),
|
||||
"the refresh reads the sequence again, then retries the cover and the photos");
|
||||
Assert.Contains(@"export const JOB_ENDED = new Set([""done"", ""failed"", ""cancelled""]);", shared);
|
||||
Assert.True(Regex.IsMatch(shared, @"export function retryImages\(root\) \{\s+root\.querySelectorAll\(""img\.failed""\)[^}]*searchParams\.set\(""retry"",", RegexOptions.Singleline),
|
||||
"a retried image gets an address the browser has not tried");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheTrashsRestoreTooltipsSayWhatIsChecked()
|
||||
{
|
||||
// A photo entry is hashed against its record before it goes back; a sequence entry is moved back as a folder and
|
||||
// nothing is hashed (SequenceTrash.RestoreAsync), so its tooltip must not promise a check.
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
foreach (var (culture, verify) in new[] { ("en", "Verify"), ("it", "Verifica") })
|
||||
{
|
||||
var strings = Assert.NotNull(await server.Client.GetFromJsonAsync($"/api/v1/i18n/{culture}", ProtocolJson.Default.DictionaryStringString));
|
||||
Assert.Contains("SHA-256", strings["Admin.Trash.RestorePhotos.Tip"]);
|
||||
var sequence = strings["Admin.Trash.RestoreSequence.Tip"];
|
||||
Assert.False(sequence.Contains("SHA-256", StringComparison.Ordinal), $"{culture}: {sequence}");
|
||||
// The check it does not make is named, with the job that makes it.
|
||||
Assert.Contains(verify, sequence);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheLibraryListDropsSelectAllWhenNoUnloadedSequenceStaysSelectedAndCapsItsDeleteList()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var library = await server.Client.GetStringAsync("/admin/pages/library.js");
|
||||
var sequence = await server.Client.GetStringAsync("/admin/pages/library/sequence.js");
|
||||
var shared = await server.Client.GetStringAsync("/admin/pages/library/shared.js");
|
||||
// Esc and Ctrl+A in the grid change the selection through onChange: once no selected sequence lies beyond the loaded
|
||||
// rows, "Select all" no longer holds, so its button comes back and a live refresh prunes the selection again.
|
||||
Assert.True(Regex.IsMatch(library, @"onChange: \(\) => \{.*?if \(matching\) \{.*?\[\.\.\.selection\.ids\]\.every\(\(id\) => loaded\.has\(id\)\)\) matching = null;.*?syncSelection\(\);", RegexOptions.Singleline),
|
||||
"the grid's onChange drops matching");
|
||||
Assert.True(Regex.IsMatch(library, @"function clearFilters\(\) \{(?:(?!\n \}).)*selection\.clear\(\);\s+matching = null;", RegexOptions.Singleline),
|
||||
"clearing the filters clears the selection as setFilter does");
|
||||
// A delete of thousands of sequences or photos lists at most LISTED names (the dialog's title counts them all); the
|
||||
// sequences that stay come first, with their reasons.
|
||||
Assert.True(Regex.IsMatch(shared, @"export const LISTED = 500;"), "LISTED");
|
||||
Assert.True(Regex.IsMatch(library, @"list: listed\(\[\.\.\.blocked\.map\("), "the sequences' delete list is capped, blocked first");
|
||||
Assert.Contains("list: listed(names),", sequence);
|
||||
Assert.False(Regex.IsMatch(library + sequence, @"list: \[\.\.\."), "an uncapped delete list");
|
||||
}
|
||||
|
||||
/// <summary>The admin panel's modules from app.js and the menu's pages along their static imports, with their source.</summary>
|
||||
private static async Task<Dictionary<string, string>> ModulesAsync(TestServer server)
|
||||
{
|
||||
var app = await server.Client.GetStringAsync("/admin/app.js");
|
||||
// The upload dialog is a module the Library opens on demand (owner review 2, R3); its hash worker is named by a URL.
|
||||
// The upload dialog is a module the Library imports dynamically (owner review 2, R3); its hash worker is named by a URL.
|
||||
var pending = new Queue<string>(MenuPages(app).SelectMany(group => group).Select(p => $"pages/{p}.js").Prepend("upload.js").Prepend("app.js"));
|
||||
var seen = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
while (pending.TryDequeue(out var module))
|
||||
|
||||
Reference in new issue
Block a user