fix(app): keep the editor's own save errors and gate an unread archive

- Editor: a failed save showed what the server or the archive layer would say
  for the exception's type, so the editor's own sentences were lost: frames
  changed on the server or settings changed elsewhere read "The server does not
  answer", a read-only account or a gone sequence "Something went wrong". These
  failures are now EditorException (an IOException; ProxiesOutdatedException
  derives from it) and the toast shows their sentence as it is. A project
  written by a newer Titano is reported with the same sentence as a corrupt one
  instead of the parser's English text.
- Library: a job posted to a server whose certificate changed since sign-in
  threw out of the action unreported; the pin's refusal now reaches the error
  toast ("The certificate was not trusted").
- Archive: picking another archive forced it offline until it was read, so the
  rebuild dialog called it offline with the previous archive's count, and
  disabled commands said the archive must be online. What was read is now kept
  apart from availability: until the picked archive is read, Rebuild and the
  online commands wait and say so, health fixes and search results of the
  previous archive are cleared, and a running search is cancelled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 11:09:04 +00:00
1 parent d47e3e9b49
commit 4850af2443
15 files changed
+218 -31

No files matched your search

@@ -189,6 +189,10 @@ public sealed class ArchiveScreenSmokeTests
Assert.Empty(archive.TreeRows);
Assert.False(archive.AnalyseSetCommand.CanExecute(null), "nothing of the first archive can be acted on while the picked one is read");
Assert.False(archive.ScanCommand.CanExecute(null), "the picked archive is not known to be online yet");
Assert.Equal(Loc.L("Archive.Blocked.Reading"), archive.ScanToolTip, "not yet read is not offline");
Assert.False(archive.RebuildCommand.CanExecute(null), "the rebuild dialog waits for the picked archive's own state and figures");
Assert.Null(await archive.OpenRebuildDialogAsync());
Assert.Empty(archive.Health);
await reading;
Assert.Equal(second.Id, archive.SelectedArchive!.Id);
@@ -196,6 +200,13 @@ public sealed class ArchiveScreenSmokeTests
Assert.True(archive.TreeRows[0].IsArchive);
Assert.False(archive.TreeRows.Any(r => r.Node.Kind == TreeNodeKind.Sequence), "the tree is the picked, empty archive's");
Assert.True(archive.ScanCommand.CanExecute(null), "the picked archive was probed: it is online");
Assert.Equal(Loc.L("Tooltips.Archive.Scan"), archive.ScanToolTip);
Assert.True(archive.RebuildCommand.CanExecute(null));
var rebuild = Assert.NotNull(await archive.OpenRebuildDialogAsync());
Assert.Equal(second.Id, rebuild.Archive.Id);
Assert.Equal(ArchiveAvailability.Online, rebuild.Availability, "the dialog shows the picked archive's availability");
Assert.Equal(0, rebuild.Indexed, "and its own index, not the first archive's");
rebuild.CloseCommand.Execute(null);
});
[Test]
@@ -1,5 +1,6 @@
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Windows;
using System.Windows.Controls;
@@ -255,6 +256,7 @@ public sealed class EditorSmokeTests
}
// A failed save says why in one localized sentence (BRIEF §0.2 rule 6); the exception's own text stays in the log.
// The editor's own reasons keep their sentence (they are I/O failures too, which would read "does not answer").
var toasts = new List<Toast>();
NotifyCollectionChangedEventHandler collect = (_, e) => toasts.AddRange(e.NewItems?.OfType<Toast>() ?? []);
shell.PendingToasts.CollectionChanged += collect;
@@ -264,6 +266,10 @@ public sealed class EditorSmokeTests
{
(true, new HttpRequestException("No such host is known."), "Server.Error.Unreachable"),
(false, new UnauthorizedAccessException(@"Access to the path 'D:\Archive\.titano\sequence.json' is denied."), "Archive.Failed.Access"),
(true, new ProxiesOutdatedException(Loc.L("Editor.Error.FramesChanged")), "Editor.Error.FramesChanged"),
(true, new EditorException(Loc.L("Editor.Error.RemoteReadOnly")), "Editor.Error.RemoteReadOnly"),
(false, new EditorException(Loc.L("Editor.Error.SaveConflict")), "Editor.Error.SaveConflict"),
(false, new EditorException(Loc.L("Editor.Error.Project"), new InvalidDataException("project.json version 9 is newer")), "Editor.Error.Project"),
})
{
toasts.Clear();
@@ -4,6 +4,7 @@ using Titano.Core.Archiving;
using Titano.Core.Codecs.Jpeg;
using Titano.Core.Imaging;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Localization;
using Titano.Core.Metadata;
using Titano.Core.Model;
using Titano.Core.Project;
@@ -147,7 +148,8 @@ public sealed class ProjectStoreTests(TestContext context)
new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) });
var content = await source.LoadAsync(context.Cancellation);
Assert.True(await db.Sequences.DeleteAsync(sequenceId));
await Assert.ThrowsAsync<InvalidOperationException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation));
var gone = await Assert.ThrowsAsync<EditorException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.Missing"), gone.Message, "the toast shows the editor's own sentence");
}
}
@@ -178,8 +180,15 @@ public sealed class ProjectStoreTests(TestContext context)
var path = Path.Combine(root, "Synthetic", ".titano", "project.json");
File.WriteAllText(path, "{ not json");
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null);
await Assert.ThrowsAsync<InvalidDataException>(() => source.LoadAsync(context.Cancellation));
var unreadable = await Assert.ThrowsAsync<EditorException>(() => source.LoadAsync(context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.Project"), unreadable.Message);
Assert.Equal("{ not json", File.ReadAllText(path));
// A project written by a newer Titano reads the same, not as the parser's English sentence.
var newer = $"{{\"version\":{ProjectSettings.CurrentVersion + 1}}}";
File.WriteAllText(path, newer);
Assert.Equal(Loc.L("Editor.Error.Project"), (await Assert.ThrowsAsync<EditorException>(() => source.LoadAsync(context.Cancellation))).Message);
Assert.Equal(newer, File.ReadAllText(path));
}
}
@@ -5,6 +5,7 @@ using Titano.Core.Codecs.Jpeg;
using Titano.Core.Diagnostics.Synthetic;
using Titano.Core.Imaging;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Data.Processing;
@@ -229,7 +230,8 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
return (theirs with { Camera = theirs.Camera with { OffsetX = offset } }).ToJson();
});
}
await Assert.ThrowsAsync<IOException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 2 }, content.Project, context.Cancellation));
var conflict = await Assert.ThrowsAsync<EditorException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 2 }, content.Project, context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.SaveConflict"), conflict.Message, "the toast shows the editor's own sentence");
Assert.False(api.Edits.Any(e => e.Accepted));
}
}
@@ -268,8 +270,9 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
}
// The source refuses a change as well; the same project is no change.
await Assert.ThrowsAsync<InvalidOperationException>(() =>
var refused = await Assert.ThrowsAsync<EditorException>(() =>
source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.RemoteReadOnly"), refused.Message);
Assert.True(ProjectMerge.SameValues(content.Project, await source.SaveProjectAsync(content.Project, content.Project, context.Cancellation)));
Assert.Empty(api.Edits);
}
@@ -366,8 +369,9 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
{
var content = await source.LoadAsync(context.Cancellation);
api.Gone = true;
await Assert.ThrowsAsync<InvalidOperationException>(() => source.LoadAsync(context.Cancellation));
await Assert.ThrowsAsync<InvalidOperationException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.Missing"), (await Assert.ThrowsAsync<EditorException>(() => source.LoadAsync(context.Cancellation))).Message);
var gone = await Assert.ThrowsAsync<EditorException>(() => source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.Missing"), gone.Message);
}
}
@@ -1,3 +1,4 @@
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -9,7 +10,9 @@ using Titano.App.Sections;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Testing;
using Titano.Ui.Controls;
using Titano.Ui.Visuals;
namespace Titano.App.Tests.Library;
@@ -180,6 +183,46 @@ public sealed class LibraryScreenSmokeTests
static string Readout(LibraryViewModel library) => library.TimelineBands[0].ToolTips!.First(t => !string.IsNullOrEmpty(t))!;
});
/// <summary>
/// A remote card's Analyse posted to a server whose certificate changed since sign-in: the pin refuses it before
/// anything is sent, and the error toast says so (it used to escape the action unreported).
/// </summary>
[Test]
public Task APostRefusedByThePinnedCertificateSaysSo() => ScreenHost.RunAsync(async () =>
{
using var server = new UntrustedTlsEndpoint();
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
await app.Sample.FillAsync();
app.Services.Settings.ServerUrl = server.Address.ToString();
await app.Shell.Services.Server.RestoreAsync();
var actions = new LibraryActions(app.Shell);
Assert.True(actions.CanPost, "signed in to the endpoint (the sample's own certificate was trusted at sign-in)");
var toasts = new List<Toast>();
NotifyCollectionChangedEventHandler collect = (_, e) => toasts.AddRange(e.NewItems?.OfType<Toast>() ?? []);
app.Shell.PendingToasts.CollectionChanged += collect;
try
{
var remote = new Sequence
{
Id = Guid.CreateVersion7(),
ArchiveId = Guid.Empty,
Folder = "Harbour",
Title = "Harbour sunset",
Origin = SequenceOrigin.Server,
SyncState = SyncState.RemoteOnly,
};
await actions.AnalyseAsync([remote]);
}
finally
{
app.Shell.PendingToasts.CollectionChanged -= collect;
}
var toast = Assert.Contains(toasts, t => t.Title == Loc.L("Library.Post.Failed"));
Assert.Equal(Loc.L("Server.Error.Untrusted"), toast.Message);
Assert.True(toast.IsError);
});
private static void Press(UIElement target, Key key) =>
target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.KeyDownEvent });
@@ -0,0 +1,78 @@
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace Titano.App.Tests.Library;
/// <summary>
/// A TLS endpoint on loopback with a self-signed certificate no client trusted (a server whose certificate changed since
/// sign-in): the client's pinning refuses every handshake, so nothing is ever sent.
/// </summary>
internal sealed class UntrustedTlsEndpoint : IDisposable
{
private readonly TcpListener _listener = new(IPAddress.Loopback, 0);
private readonly X509Certificate2 _certificate;
private readonly CancellationTokenSource _stop = new();
private readonly Task _accepting;
public UntrustedTlsEndpoint()
{
using var key = RSA.Create(2048);
var request = new CertificateRequest("CN=127.0.0.1", key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
using var created = request.CreateSelfSigned(DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddDays(1));
// Schannel serves only a certificate whose key it can open: a PKCS #12 round trip gives it one.
_certificate = X509CertificateLoader.LoadPkcs12(created.Export(X509ContentType.Pkcs12), null);
_listener.Start();
_accepting = Task.Run(AcceptAsync);
}
public Uri Address => new($"https://127.0.0.1:{((IPEndPoint)_listener.LocalEndpoint).Port}/");
public void Dispose()
{
_stop.Cancel();
_listener.Stop();
try
{
_accepting.Wait(TimeSpan.FromSeconds(5));
}
catch (AggregateException)
{
// The loop ends with the listener; how it ended does not matter.
}
_certificate.Dispose();
_stop.Dispose();
}
private async Task AcceptAsync()
{
while (!_stop.IsCancellationRequested)
{
TcpClient client;
try
{
client = await _listener.AcceptTcpClientAsync(_stop.Token);
}
catch (Exception ex) when (ex is OperationCanceledException or SocketException or ObjectDisposedException)
{
return;
}
using (client)
{
try
{
await using var tls = new SslStream(client.GetStream());
await tls.AuthenticateAsServerAsync(new SslServerAuthenticationOptions { ServerCertificate = _certificate }, _stop.Token);
}
catch (Exception ex) when (ex is AuthenticationException or IOException or OperationCanceledException or SocketException)
{
// The client refused the certificate: the handshake ends here, as intended.
}
}
}
}
}