Owner review 2, R6: the web panel manages the library without editing it, so the engine and the server must delete single photos safely, keep them out of sync afterwards, and let an administrator restore or finally erase the trash. - Migration 0008: frame_removals (tombstones by sequence and SHA-256, reason, replacement); the sidecar gains "removed" (omitted when empty) and frames a reserved "source"; the indexer writes the tombstones on every sync, so a rebuild keeps them, and drops a hero frame that is gone. - FrameTrash: dry run (busy, frames changed, offline, would empty), delete under the sequence lease with a write-ahead journal that the next writer undoes after a crash, files to trash/photos/<seq>-<time>/originals with a record, sidecar without the frames plus tombstones, index sync clearing analyses, thumbnails and proxies, proxies renamed to follow their frames, follow-up jobs. Restore re-hashes every file, keeps mismatches in the trash, puts the same frame records back and drops their tombstones, or files the photos into a new sequence through the ingest when theirs is gone. - Project positions on vanished photos are translated by photo and wait as pending frames, so they come back with a restore. - Trash entries have a kind (sequence, photos, replaced); emptying is a dry run with a fingerprint and a new EmptyTrash job (18) that erases exactly the planned entries, refuses a stale plan and erases replaced originals only while their replacements still hash right. - Sync honours tombstones: nothing one side deleted is offered back, local files are never deleted, replaced photos count as their replacement; the server answers an upload of a tombstoned SHA-256 as already there. - Server: sequence thumbnail, photo delete, bulk delete/retag/jobs, trash list/restore/empty endpoints with their error messages; a verify of sequences now targets their archive (POST /jobs failed before). - Desktop trash dialog lists photo entries and empties the trash after a typed confirmation through the same job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 35bb56690a1d69eae57153d036e1409201cd73f7)
245 lines
12 KiB
C#
245 lines
12 KiB
C#
using System.Collections.Specialized;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using Chronos.App.Archiving;
|
||
using Chronos.App.Infrastructure;
|
||
using Chronos.App.Library;
|
||
using Chronos.App.Sections;
|
||
using Chronos.App.Shell;
|
||
using Chronos.App.Tests.Windows;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Model;
|
||
using Chronos.Testing;
|
||
using Chronos.Ui.Controls;
|
||
using Chronos.Ui.Visuals;
|
||
|
||
namespace Chronos.App.Tests.Library;
|
||
|
||
/// <summary>
|
||
/// The Library's new states of <c>--capture</c> (<see cref="LibraryScenes"/>) on the sample index while signed in to the
|
||
/// sample server, rendered in both themes in the real main window: the timeline, a selection with the whole mass actions
|
||
/// bar and its delete dry run, the server's sequences as remote cards, saved views and Save view, and the archive's trash.
|
||
/// </summary>
|
||
[WindowsOnly]
|
||
[Serial]
|
||
[Timeout(300_000)]
|
||
public sealed class LibraryScreenSmokeTests
|
||
{
|
||
[Test]
|
||
public Task EveryLibrarySceneRendersInBothThemes() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
await app.Sample.FillAsync();
|
||
await app.Shell.Services.Server.RestoreAsync();
|
||
await app.Shell.Services.Sync.RefreshAsync();
|
||
var library = app.Shell.Library;
|
||
|
||
await LibraryScenes.ShowAsync(app.Shell, "timeline");
|
||
Assert.True(library.IsTimeline, "the timeline shows its bands");
|
||
Assert.True(library.IsGrid, "the cards stay under the bands");
|
||
Assert.Equal(2, library.TimelineBands.Count, "one band per year, 2026 and 2025, the server's sequences included");
|
||
Assert.True(library.TimelineBand >= 0 && library.TimelineSlot >= 0, "the chosen month is outlined");
|
||
Assert.True(library.IsYearFiltered, "a month narrows the Library to its year");
|
||
await app.ExpectAsync<LibraryView>("library-timeline", waitForThumbnails: true);
|
||
var bands = Assert.NotNull(app.FindAll<TimelineBands>().FirstOrDefault(t => t.IsVisible && t.ActualHeight > 0), "the bands are drawn");
|
||
Assert.True(bands.Focusable, "the keyboard reaches the months");
|
||
// Without the mouse: Enter on the month under the keyboard narrows the Library to its year.
|
||
library.ClearFiltersCommand.Execute(null);
|
||
await library.RefreshAsync();
|
||
Assert.Equal(-1, library.TimelineBand);
|
||
bands.Focus();
|
||
Press(bands, Key.Enter);
|
||
await library.RefreshAsync();
|
||
Assert.True(library.TimelineBand >= 0 && library.TimelineSlot >= 0, "Enter chose a month");
|
||
Assert.True(library.IsYearFiltered, "the year filter follows the band");
|
||
|
||
await LibraryScenes.ShowAsync(app.Shell, "mass");
|
||
Assert.Equal(LibraryScenes.MassSelection, library.SelectionCount);
|
||
await app.ExpectAsync<LibraryView>("library-mass", waitForThumbnails: true);
|
||
foreach (var command in new[] { library.AnalyseCommand, library.ProxiesCommand, library.VerifyCommand, library.TagCommand, library.MoveCommand,
|
||
library.ExportListCommand, library.DeleteCommand })
|
||
Assert.True(ButtonFor(app, command).IsEnabled, "the bar's archive actions work on sequences of this PC");
|
||
Assert.True(library.CanRate);
|
||
|
||
var request = Assert.NotNull(await LibraryScenes.DeleteRequestAsync(app.Shell), "the dry run moves something");
|
||
Assert.True(request.IsDestructive);
|
||
Assert.NotNull(request.TypedConfirmation);
|
||
var dialog = new ConfirmDialog(request) { WindowStartupLocation = WindowStartupLocation.Manual, Left = -20000, Top = -20000, ShowActivated = false };
|
||
dialog.Show();
|
||
try
|
||
{
|
||
dialog.UpdateLayout();
|
||
var action = Find<Button>(dialog).Single(b => Equals(b.Content, request.ActionText));
|
||
Assert.False(action.IsEnabled, "Delete waits for the typed confirmation");
|
||
Find<TextBox>(dialog).Single(t => t.IsVisible).Text = request.TypedConfirmation;
|
||
Assert.True(action.IsEnabled, "typing the count enables Delete");
|
||
}
|
||
finally
|
||
{
|
||
dialog.Close();
|
||
}
|
||
// The sample dialogs cancel every confirmation: the delete dialog closes and nothing moves.
|
||
var selected = library.SelectedItems().Select(i => i.Id).ToList();
|
||
Assert.False(await library.DeleteAsync(selected));
|
||
Assert.Null(library.Dialog, "the delete dialog closes once it is answered");
|
||
foreach (var id in selected) Assert.NotNull(await app.Services.Database!.Sequences.GetAsync(id));
|
||
var first = library.Items.First(i => i.IsSelected);
|
||
Assert.True(library.AnalyseItemCommand.CanExecute(first) && library.RenderItemCommand.CanExecute(first), "the quick actions run on this PC's engine");
|
||
|
||
await LibraryScenes.ShowAsync(app.Shell, "remote");
|
||
Assert.True(library.ShowsOrigin, "signed in, the origin filter shows");
|
||
Assert.Equal(2, library.Items.Count, "the two sequences only on the sample server");
|
||
Assert.True(library.Items.All(i => i.IsRemote));
|
||
Assert.True(library.IsSingleSelection);
|
||
Assert.False(library.DeleteCommand.CanExecute(null), "a remote card has nothing here to delete");
|
||
Assert.True(library.DownloadCommand.CanExecute(null), "its originals can come here");
|
||
Assert.False(library.RevealCommand.CanExecute(null), "a remote card has no folder here");
|
||
Assert.Equal(Loc.L("Library.Blocked.ServerOnly"), library.RevealToolTip);
|
||
await app.ExpectAsync<LibraryView>("library-remote");
|
||
Assert.True(library.Years.Count > 1, "the server's years are choices too");
|
||
|
||
library.ClearFiltersCommand.Execute(null);
|
||
await library.RefreshAsync();
|
||
Assert.True(library.HasViews, "the sample saved two views");
|
||
library.ViewChoices.Single(v => v.Label == "Nikon Z 8").Command.Execute(null);
|
||
await library.RefreshAsync();
|
||
Assert.True(library.IsViewActive);
|
||
Assert.True(library.Items.Count > 0 && library.Items.All(i => i.Sequence.CameraModel == "NIKON Z 8"));
|
||
|
||
await LibraryScenes.ShowAsync(app.Shell, "viewname");
|
||
var naming = Assert.NotNull(library.Dialog as ViewNameDialogViewModel, "Save view asks a name");
|
||
Assert.True(naming.SaveCommand.CanExecute(null), "the status filter's label is a free name");
|
||
Assert.False(library.IsContentEnabled, "the screen behind a dialog takes no input");
|
||
await app.ExpectAsync<LibraryView>("library-viewname");
|
||
naming.CloseCommand.Execute(null);
|
||
Assert.Null(library.Dialog);
|
||
|
||
await ArchiveScenes.ShowAsync(app.Shell, "trash");
|
||
var trash = Assert.NotNull(app.Shell.Archive.Dialog as TrashDialogViewModel, "Maintenance › Trash… opens the trash");
|
||
Assert.Equal(2, trash.Rows.Count, "the sample's deleted sequence and photos");
|
||
Assert.True(trash.HasRows);
|
||
await app.ExpectAsync<ArchiveView>("archive-trash-sample");
|
||
trash.CloseCommand.Execute(null);
|
||
});
|
||
|
||
[Test]
|
||
public Task ADeletedSequenceComesBackFromTheArchiveTrash() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
await app.Sample.FillAsync();
|
||
await LibraryScenes.ShowAsync(app.Shell, "mass");
|
||
var db = app.Services.Database!;
|
||
var archives = app.Services.Archives!;
|
||
|
||
// What Delete runs once confirmed: the movable part of the selection goes to the archive's trash.
|
||
var plan = await archives.PlanDeleteAsync([.. app.Shell.Library.SelectedItems().Select(i => i.Id)]);
|
||
var moved = Assert.NotNull(plan.Steps.FirstOrDefault(), "the selection holds a sequence no job works on").Sequence;
|
||
Assert.NotEmpty(plan.Blocked);
|
||
await archives.DeleteAsync(plan);
|
||
Assert.Null(await db.Sequences.GetAsync(moved.Id));
|
||
|
||
app.Shell.Navigate(SectionKey.Archive);
|
||
await app.Shell.Archive.LoadAsync();
|
||
Assert.True(app.Shell.Archive.DeleteSetCommand.CanExecute(null), "the mass operations bar offers Delete…");
|
||
await app.Shell.Archive.OpenTrashAsync();
|
||
var trash = Assert.NotNull(app.Shell.Archive.Dialog as TrashDialogViewModel);
|
||
var row = trash.Rows.Single();
|
||
Assert.Equal(moved.Id, row.Entry.SequenceId);
|
||
await app.ExpectAsync<ArchiveView>("archive-trash");
|
||
|
||
row.RestoreCommand.Execute(null);
|
||
for (var i = 0; i < 100 && await db.Sequences.GetAsync(moved.Id) is null; i++) await Task.Delay(50);
|
||
var restored = Assert.NotNull(await db.Sequences.GetAsync(moved.Id), "Restore brings the sequence back into the index");
|
||
Assert.Equal(moved.Folder, restored.Folder);
|
||
Assert.True(trash.IsEmpty);
|
||
trash.CloseCommand.Execute(null);
|
||
});
|
||
|
||
/// <summary>A language switch makes the timeline's month readouts again, as it does the filters (BRIEF §16).</summary>
|
||
[Test]
|
||
public Task TheTimelineReadoutsFollowALanguageSwitch() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
await app.Sample.FillAsync();
|
||
await app.Shell.Services.Server.RestoreAsync();
|
||
await app.Shell.Services.Sync.RefreshAsync();
|
||
var library = app.Shell.Library;
|
||
await LibraryScenes.ShowAsync(app.Shell, "timeline");
|
||
var english = Readout(library);
|
||
try
|
||
{
|
||
UiLanguage.Apply("it");
|
||
var italian = Readout(library);
|
||
Assert.NotEqual(english, italian, "the month readouts follow the language");
|
||
}
|
||
finally
|
||
{
|
||
UiLanguage.Apply("en");
|
||
}
|
||
Assert.Equal(english, Readout(library), "and come back with it");
|
||
|
||
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 });
|
||
|
||
private static Button ButtonFor(ScreenSmokeTests.SampleApp app, ICommand command) =>
|
||
Assert.NotNull(app.FindAll<Button>().FirstOrDefault(b => ReferenceEquals(b.Command, command) && b.IsVisible), "a visible button bound to the command");
|
||
|
||
private static List<T> Find<T>(DependencyObject root)
|
||
where T : DependencyObject
|
||
{
|
||
var found = new List<T>();
|
||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
|
||
{
|
||
var child = VisualTreeHelper.GetChild(root, i);
|
||
if (child is T match) found.Add(match);
|
||
found.AddRange(Find<T>(child));
|
||
}
|
||
return found;
|
||
}
|
||
}
|