fix: full verification against the brief — 137 confirmed findings fixed over six passes #4

Merged
Alby96 merged 169 commits from claude/keen-knuth-uhxv8w into main 2026-10-13 12:10:04 +02:00
5 changed files with 174 additions and 31 deletions
Showing only changes of commit 789c2dae3e - Show all commits

No files matched your search

+22 -7
View File
@@ -937,7 +937,8 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
else OnServerJobChanged();
LearnAnalysisSpeed(job);
if (!wasActive) return;
if (job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render ? job : null);
// A render this editor followed to its end is said here, with its output, unless the Jobs screen said it first.
if (job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render && Shell.Jobs.ClaimRenderToast(job.Id) ? job : null);
else if (IsRemote && job.State is JobState.Failed or JobState.Cancelled) ReportServerJobEnded(job);
});
}
@@ -1010,23 +1011,37 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
if (job is { Kind: JobKind.DeepAnalyse, State: JobState.Done, ItemsPerSecond: > 0 and var speed }) _analysisSecondsPerFrame = 1 / speed;
}
/// <summary>Reads the sequence again after a job; a finished render offers its follow-ups (BRIEF §11.5).</summary>
/// <summary>
/// Reads the sequence again after a job. A finished render whose toast this editor took (<see cref="Sections.JobsViewModel.ClaimRenderToast"/>)
/// is said in any case, also when the editor closed meanwhile: with its output and follow-ups (BRIEF §11.5) once the
/// sequence is read again, without them when that failed.
/// </summary>
private async Task ReloadAsync(Job? render)
{
var reloaded = false;
try
{
await Session.ReloadAsync();
reloaded = true;
}
catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or InvalidOperationException or UnauthorizedAccessException
or System.Net.Http.HttpRequestException or Protocol.Client.TitanoApiException or OperationCanceledException)
or System.Net.Http.HttpRequestException or Protocol.Client.TitanoApiException or OperationCanceledException
or Data.DatabaseException)
{
// A server that does not answer in time cancels the request (OperationCanceledException).
Shell.ReportError(ex);
return;
}
if (render is null || _disposed) return;
// A server's render stays on the server: nothing to show in Explorer.
var output = Session.Content.Renders.FirstOrDefault(r => render.Started is not { } started || r.Created >= started)?.OutputPath is { Length: > 0 } path
finally
{
if (render is not null) AnnounceRender(render, reloaded);
}
}
/// <summary>"Render finished" with the output file and Show in folder; <paramref name="read"/>: the sequence was read again after the render.</summary>
private void AnnounceRender(Job render, bool read)
{
// A server's render stays on the server: nothing to show in Explorer. Before a read the renders are the old ones.
var output = read && Session.Content.Renders.FirstOrDefault(r => render.Started is not { } started || r.Created >= started)?.OutputPath is { Length: > 0 } path
? path
: null;
Shell.ShowToast(new Toast
+34 -9
View File
@@ -63,6 +63,10 @@ public sealed class JobsViewModel : SectionViewModel
private readonly Dictionary<Guid, JobRowViewModel> _rows = [];
private readonly HashSet<Guid> _unseenFailures = [];
private readonly JobEndings _endings = new();
/// <summary>Finished renders whose toast was taken (<see cref="ClaimRenderToast"/>).</summary>
private readonly HashSet<Guid> _renderToasts = [];
private readonly JobActions _actions;
private CoalescingThrottle? _throttle;
private IJobQueue? _queue;
@@ -250,10 +254,17 @@ public sealed class JobsViewModel : SectionViewModel
if (job.State != JobState.Failed) _unseenFailures.Remove(job.Id);
else if (before != JobState.Failed && !IsSelected) _unseenFailures.Add(job.Id);
var notice = JobNotices.For(before, job);
if (notice == JobNotice.Done && EditorAnnounces(job)) return;
if (notice == JobNotice.Done && job.Kind == JobKind.Render && !ClaimRenderToast(job.Id)) return;
_endings.Add(notice, job);
}
/// <summary>
/// Takes the toast of a finished render, which is said once (UI thread): true for the first caller only, which then
/// raises it. The editor of the render's sequence takes it when it sees the render end, and says it with the output
/// file even when the sequence cannot be read again; a render the editor did not follow is said here.
/// </summary>
internal bool ClaimRenderToast(Guid jobId) => _renderToasts.Add(jobId);
/// <summary>
/// The toast of a job that ended, with one action (BRIEF §12.1, §0.2 rule 6). Several endings at once (a batch
/// finished, or failed together) say how many and lead to this screen. Clicking the Windows notification of a
@@ -311,11 +322,6 @@ public sealed class JobsViewModel : SectionViewModel
};
}
/// <summary>A finished render of the sequence open in the editor: the editor says it, with its output file.</summary>
private bool EditorAnnounces(Job job) =>
job is { Kind: JobKind.Render, State: JobState.Done } && Shell.Sequence.Editor is { IsRemote: false } editor
&& job.TargetIds.Contains(editor.Session.Content.Sequence.Id);
/// <summary>A job changed state (any thread; tests feed it too): buffered until the next flush.</summary>
internal void OnJobChanged(Job job)
{
@@ -403,13 +409,32 @@ public sealed class JobsViewModel : SectionViewModel
SyncRows();
}
/// <summary>Opens what a job worked on inside Titano: its sequence in the editor, or the Archive screen.</summary>
/// <summary>
/// Opens what a job worked on inside Titano: its sequence in the editor; several sequences (a deep analysis of a
/// Library selection) in the Library, every one of them selected; else the Archive screen.
/// </summary>
internal async Task OpenTargetAsync(Job job)
{
var db = Shell.Services.Database;
if (db is null || job.TargetIds.Count == 0) return;
if (await db.Sequences.GetAsync(job.TargetIds[0]) is { } sequence) Shell.OpenSequence(sequence.Id);
else Shell.Navigate(SectionKey.Archive);
var sequences = new List<Guid>();
foreach (var id in job.TargetIds.Distinct())
{
if (await db.Sequences.GetAsync(id) is { } sequence) sequences.Add(sequence.Id);
}
switch (sequences.Count)
{
case 0:
Shell.Navigate(SectionKey.Archive);
break;
case 1:
Shell.OpenSequence(sequences[0]);
break;
default:
Shell.Navigate(SectionKey.Library);
await Shell.Library.ShowSelectedAsync(sequences);
break;
}
}
/// <summary>Shows the folder of what a job worked on in Explorer.</summary>
+41 -1
View File
@@ -581,6 +581,37 @@ public sealed class LibraryViewModel : SectionViewModel
RaiseMass();
}
/// <summary>
/// Shows the sequences of <paramref name="ids"/> selected, under the mass actions bar (Open on a job over several
/// sequences). Search and filters go when one of them would be hidden or is still being applied, pages are read until
/// each is listed, and the first comes into sight. Ids not in the index are left out.
/// </summary>
public async Task ShowSelectedAsync(IReadOnlyCollection<Guid> ids)
{
if (_pager is null) return;
var wanted = ids.ToHashSet();
if (_searchDelay.IsEnabled || _pager.IsLoading || !Lists(wanted))
{
ResetFilters();
await ReloadAsync();
while (!Lists(wanted) && _pager is { HasMore: true })
{
var listed = Items.Count;
await LoadMoreAsync();
if (Items.Count == listed) break;
}
}
SequenceItem? first = null;
foreach (var item in Items)
{
var chosen = wanted.Contains(item.Sequence.Id);
if (item.IsSelected != chosen) item.IsSelected = chosen;
if (chosen) first ??= item;
}
OnSelectionChanged();
if (first is not null) ScrollRequested?.Invoke(first);
}
/// <summary>Opens Tags on the selection (capture, tests).</summary>
public void OpenRetag() => OpenRetag(Targets(MassAction.Tag));
@@ -850,6 +881,13 @@ public sealed class LibraryViewModel : SectionViewModel
}
private void ClearFilters()
{
ResetFilters();
Reload();
}
/// <summary>Search and filters back to "any", without reading the list again.</summary>
private void ResetFilters()
{
_suppressReload = true;
_searchDelay.Stop();
@@ -863,9 +901,11 @@ public sealed class LibraryViewModel : SectionViewModel
_timelineMonth = null;
_scrollToMonth = false;
_suppressReload = false;
Reload();
}
/// <summary>Every sequence of <paramref name="ids"/> is in the list on screen.</summary>
private bool Lists(HashSet<Guid> ids) => ids.IsSubsetOf(Items.Select(i => i.Sequence.Id));
/// <summary>Shows a saved view: its search, filters and sort, at once.</summary>
private void Apply(SavedView view)
{
@@ -111,7 +111,15 @@ internal sealed class FakeSequenceSource(SyntheticSequence sequence, SequenceCon
/// <summary>Awaited by every decode (tests of cancellation).</summary>
public Task DecodeGate { get; set; } = Task.CompletedTask;
public Task<SequenceContent> LoadAsync(CancellationToken cancellationToken) => Task.FromResult(Content with { Project = Stored });
/// <summary>Thrown by the next load (the sequence read again after a job).</summary>
public Exception? FailNextLoad { get; set; }
public Task<SequenceContent> LoadAsync(CancellationToken cancellationToken)
{
if (FailNextLoad is not { } failure) return Task.FromResult(Content with { Project = Stored });
FailNextLoad = null;
return Task.FromException<SequenceContent>(failure);
}
public async ValueTask<ImageBuffer?> DecodeAsync(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken)
{
@@ -1,11 +1,15 @@
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shell;
using Titano.App.Editor;
using Titano.App.Infrastructure;
using Titano.App.Sections;
using Titano.App.Settings;
using Titano.App.Shell;
using Titano.App.Tests.Editor;
using Titano.Core.Export;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data.Repositories;
@@ -133,26 +137,40 @@ public sealed class ShellNotificationTests
Assert.Equal(badge, jobs.Badge);
Assert.NotEqual(TaskbarItemProgressState.Error, shell.TaskbarState);
// The editor announces the renders of its own sequence, with their output: the shell says nothing then.
var id = await app.Sample.FillEditorAsync();
shell.OpenSequence(id);
await shell.Sequence.OpenAsync(id);
Assert.NotNull(shell.Sequence.Editor);
// The editor says the renders it followed to their end, with their output: the shell says nothing then. It says them
// also when the sequence cannot be read again (that error is said too), without Show in folder then.
var content = EditorFixture.Content(EditorFixture.Sunset);
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
var editor = new EditorViewModel(shell, new EditorSession(source, content, []), [], EncoderHost.Client);
await using (editor)
{
foreach (var readable in new[] { true, false })
{
raised.Clear();
var render = Job(JobKind.Render, JobState.Running, content.Sequence.Id);
source.Report(render);
jobs.OnJobChanged(render);
await UntilAsync(() => editor.IsBusy);
jobs.Flush();
if (!readable) source.FailNextLoad = new IOException("The specified network name is no longer available.");
source.Report(render with { State = JobState.Done });
jobs.OnJobChanged(render with { State = JobState.Done });
await UntilAsync(() => raised.Any(t => t.Title == Loc.L("Editor.Render.Done")));
jobs.Flush();
var finished = Assert.Contains(raised, t => t.Title == Loc.L("Editor.Render.Done"));
Assert.False(raised.Any(t => t.Title == Loc.L("Shell.Job.Done")), "the editor's own render toast is not doubled");
Assert.Equal(readable ? 0 : 1, raised.Count(t => t.IsError), "a failed read is said beside the render's end");
if (!readable) Assert.Null(finished.ActionCommand, "without the sequence read again, there is no output to show");
}
}
// A render the editor did not follow (of another sequence) is the shell's to announce.
raised.Clear();
var render = Job(JobKind.Render, JobState.Running, id);
jobs.OnJobChanged(render);
jobs.Flush();
jobs.OnJobChanged(render with { State = JobState.Done });
jobs.Flush();
Assert.False(raised.Any(t => t.Title == Loc.L("Shell.Job.Done")), "the editor's own render toast is not doubled");
// A render of another sequence is the shell's to announce.
var other = Job(JobKind.Render, JobState.Running, Guid.CreateVersion7());
jobs.OnJobChanged(other);
jobs.Flush();
jobs.OnJobChanged(other with { State = JobState.Done });
jobs.Flush();
Assert.Equal(1, raised.Count(t => t.Title == Loc.L("Shell.Job.Done")));
await shell.Sequence.CloseAsync();
// Server › Upload all: the batch speaks once, when its last upload ends.
raised.Clear();
@@ -380,6 +398,43 @@ public sealed class ShellNotificationTests
Assert.Equal(shell.Archive.Health.Count(h => !h.IsOk), shell.Archive.Badge);
});
/// <summary>
/// Open on a job that worked on several sequences (a deep analysis of a Library selection) shows every one of them
/// selected in the Library, also those a search hid; a job on an archive opens the Archive screen.
/// </summary>
[Test]
public Task OpenOnAJobOverSeveralSequencesSelectsThemAllInTheLibrary() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
shell.CompleteWelcome();
await app.Sample.FillAsync();
var db = Assert.NotNull(shell.Services.Database);
var library = shell.Library;
await library.RefreshAsync();
var ids = (await db.Sequences.ListAsync(new SequenceQuery { Sort = SequenceSort.Oldest, Limit = 3 })).Items.Select(s => s.Id).ToList();
Assert.Count(3, ids);
library.SearchText = "no such sequence";
var analysis = Job(JobKind.DeepAnalyse, JobState.Done, ids[0]) with { TargetIds = ids, TargetLabel = Loc.Plural("Library.Selection.Count", ids.Count) };
await shell.Jobs.OpenTargetAsync(analysis);
Assert.Equal(SectionKey.Library, shell.Current.Key);
Assert.Equal(string.Empty, library.SearchText, "the search that hid them is cleared");
Assert.Equal(ids.Count, library.SelectionCount, "every sequence the job worked on, not only the first");
Assert.SequenceEqual(ids.Order(), library.SelectedItems().Select(i => i.Sequence.Id).Order());
await shell.Jobs.OpenTargetAsync(Job(JobKind.Verify, JobState.Done, Guid.CreateVersion7()));
Assert.Equal(SectionKey.Archive, shell.Current.Key);
// The Archive screen reads its figures when it opens: let that end before the app closes.
await shell.Archive.LoadAsync();
});
/// <summary>Lets the dispatcher run what was posted to it (the editor's job events and reload) until <paramref name="done"/> holds.</summary>
private static async Task UntilAsync(Func<bool> done)
{
for (var i = 0; i < 250 && !done(); i++) await Task.Delay(20);
}
/// <summary>The Jobs screen read its first page (it would set the job bar and the badge again).</summary>
private static async Task JobsLoadedAsync(ShellViewModel shell)
{