fix(workspace): a deleted project asks nothing, prunes and copies clean up only after what ended well
Owner review 2, phase 5a (R8), fix round 4. A project the library no longer has now reads as Gone with no conflict to answer. The conflict stays recorded in sync.json, so Save both on a deleted project says Gone once and offers its copy. It no longer reopens the conflict dialog. Keep mine and Take the library's first check that the home still has the project. Neither is merged onto the last version a deleted project had, so the working state and the unsent versions stay as they were. Old files in versions/.replaced are pruned only after a push that ended well, never after one that stopped at a conflict. A file an earlier build set aside kept the time its version was written. It now counts as set aside no earlier than when this build first knew the folder (versions/.replaced.since), so an upgrade does not prune it by an old mtime. The Merge mark goes on the replayed version whose own change met a setting the conflict listed. A version that only rides along with a working-state conflict stays a commit. A first copy cancelled while paused or failed, which no handler runs, now has its partial media removed under the project's lease, as a running one does (ICancelledJobHandler). The space estimate counts a proxy held under its <id>-<sha16>.jpg name. The frames stamp carries a weighted SQL checksum of the hashes, so a hash replaced in place (a Verify) makes the workspace read the frames again. Desktop: a removal that cannot move a file puts back what it moved, so the copy stays whole and listed, and the failure is said. The Removed toast names a damaged copy as it is known, never by its folder id. One copy that cannot be listed no longer hides the others. A Main this Chronos cannot read (newer or damaged) is refused at once with the reason, and a damaged one offers Remove local copy. Save version is off on a Gone project, and Send/Delete there say the project was deleted in the library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5ed31bced
commit
279ebf437f
14 files changed
+729
-57
No files matched your search
@@ -192,6 +192,9 @@ public sealed class WorkspaceSectionTests(TestContext context)
|
||||
var aside = Assert.Contains(Directory.EnumerateDirectories(Path.Combine(outside, WorkspaceHost.TrashFolder)),
|
||||
d => Path.GetFileName(d).StartsWith(damagedId.ToString("N"), StringComparison.Ordinal));
|
||||
Assert.Equal("kept", await File.ReadAllTextAsync(Path.Combine(aside, "notes.txt")));
|
||||
// Nothing knows its name: the toast names no folder id.
|
||||
await WorkspaceTestBed.UntilAsync(() => toasts.Any(t => t.Title == Loc.L("Editor.Workspace.Removed")), "the removal is said");
|
||||
Assert.Null(toasts.Single(t => t.Title == Loc.L("Editor.Workspace.Removed")).Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -201,6 +204,91 @@ public sealed class WorkspaceSectionTests(TestContext context)
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task AMainThisChronosCannotReadSaysWhyAtOnceAndADamagedOneOffersItsRemoval() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
var directory = context.CreateTempDirectory("workspace-unreadable-main");
|
||||
var environment = AppEnvironment.From(AppPaths.Resolve(Directory.CreateDirectory(Path.Combine(directory, "app")).FullName,
|
||||
Directory.CreateDirectory(Path.Combine(directory, "local")).FullName, []));
|
||||
UiLanguage.Apply("en");
|
||||
var settings = new AppSettings { Language = "en", FirstRunCompleted = true, CheckForUpdates = false };
|
||||
var dialogs = new ScriptedDialogs();
|
||||
var services = new AppServices(environment, settings, () => { }, dialogs);
|
||||
await services.AttachAsync(await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(environment.DatabasePath)), startEngine: true);
|
||||
var shell = new ShellViewModel(services);
|
||||
var toasts = new List<Toast>();
|
||||
shell.PendingToasts.CollectionChanged += (_, e) => toasts.AddRange(e.NewItems?.OfType<Toast>() ?? []);
|
||||
try
|
||||
{
|
||||
var sequenceId = await SequenceAsync(services, Path.Combine(directory, "archive"));
|
||||
var section = shell.Sequence;
|
||||
shell.OpenSequence(sequenceId);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace asks the first time");
|
||||
((OpenInWorkspaceDialogViewModel)section.Dialog!).OpenCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Editor is not null, "Main opens");
|
||||
var mainId = section.OpenProjectId!.Value;
|
||||
Assert.True(await section.ConfirmCloseAsync());
|
||||
await section.CloseAsync();
|
||||
shell.KeepSequence(null);
|
||||
var folder = Path.Combine(services.Workspace.Root, mainId.ToString("N"));
|
||||
var bundle = Path.Combine(folder, WorkspaceProject.BundleFile);
|
||||
|
||||
// Saved by a newer Chronos: said at once, nothing offered over it, nothing asked.
|
||||
await WriteWhenFreeAsync(bundle,
|
||||
$$"""{ "format": "chronos-project", "formatVersion": 9, "sequence": { "title": "Synthetic" }, "workspace": { "projectId": "{{mainId}}", "name": "Main", "isMain": true } }""");
|
||||
shell.OpenSequence(sequenceId);
|
||||
await WorkspaceTestBed.UntilAsync(() => toasts.Any(t => t.Message == Loc.L("Errors.Workspace.NewerCopy")), "a newer Main is refused");
|
||||
var newer = toasts.Single(t => t.Message == Loc.L("Errors.Workspace.NewerCopy"));
|
||||
Assert.True(newer is { Title: var title, IsError: true, ActionCommand: null } && title == Loc.L("Editor.Workspace.OpenFailed"));
|
||||
Assert.True(section.Dialog is null && section.Editor is null, "nothing asked, nothing opened");
|
||||
Assert.FileExists(bundle);
|
||||
shell.KeepSequence(null);
|
||||
|
||||
// Damaged: said at once, with Remove local copy; its Discard keeps the files aside, named as the copy is known.
|
||||
await WriteWhenFreeAsync(bundle, "{ not a project");
|
||||
shell.OpenSequence(sequenceId);
|
||||
await WorkspaceTestBed.UntilAsync(() => toasts.Any(t => t.Message == Loc.L("Errors.Workspace.Damaged")), "a damaged Main is refused");
|
||||
var damaged = toasts.Single(t => t.Message == Loc.L("Errors.Workspace.Damaged"));
|
||||
Assert.Equal((Loc.L("Editor.Workspace.OpenFailed"), true, Loc.L("Editor.Project.RemoveCopy"), Loc.L("Tooltips.Editor.Workspace.State.DamagedCopy")),
|
||||
(damaged.Title, damaged.IsError, damaged.ActionText, damaged.ActionToolTip));
|
||||
Assert.True(section.Dialog is null && section.Editor is null, "nothing asked, nothing opened");
|
||||
damaged.ActionCommand!.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Dialog is RemoveCopyDialogViewModel, "its removal is offered");
|
||||
var remove = (RemoveCopyDialogViewModel)section.Dialog!;
|
||||
Assert.True(remove.Plan.Damaged, "removed as a damaged copy");
|
||||
Assert.Equal(Loc.L("Editor.RemoveCopy.Title", Loc.L("Editor.Project.Main")), remove.Heading);
|
||||
remove.DiscardCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => toasts.Any(t => t.Title == Loc.L("Editor.Workspace.Removed")), "the copy goes");
|
||||
Assert.False(Directory.Exists(folder));
|
||||
var removed = toasts.Single(t => t.Title == Loc.L("Editor.Workspace.Removed"));
|
||||
Assert.Equal(Loc.L("Editor.Project.Main"), removed.Message, "named as the index knows it, never by its folder");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await shell.Sequence.CloseAsync();
|
||||
shell.Dispose();
|
||||
await services.DisposeAsync();
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>Writes <paramref name="path"/> once the project's last background read (its state, after the close) lets go of it.</summary>
|
||||
private static async Task WriteWhenFreeAsync(string path, string text)
|
||||
{
|
||||
var until = DateTime.UtcNow + TimeSpan.FromSeconds(TestTiming.Budget(20));
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(path, text);
|
||||
return;
|
||||
}
|
||||
catch (IOException) when (DateTime.UtcNow < until)
|
||||
{
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>An archive with one sequence of six synthetic photos, indexed.</summary>
|
||||
private async Task<Guid> SequenceAsync(AppServices services, string root)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user