fix(workspace): a cancelled copy clears only media no other copy writes; a deletion keeps late versions
Owner review 2, phase 5a, fix round 5. - A cancelled workspace copy clears its partial media only under the project's lease, after checking again that the job is still cancelled, that no other copy of the same root and project is queued, running or paused, and that no copy in this process is writing. The engine now waits for a paused job's run to end before calling the cancel handler, so the clean-up is never skipped. - The clean-up never recreates a project folder that was removed meanwhile (the lease no longer creates the folder). The next list removes a project folder that holds only lease files nobody holds, older than the lease. - A Main this Chronos cannot read (newer or damaged) refuses the open at once only when nothing else can be offered. Otherwise Open in workspace lists it disabled, with the reason as its tooltip. The refusal's action tooltip is now Remove copy. - The removal plan counts a conflict the same way the sync status does: a conflict that a settling replay took past its commit point is not work left. - A healed record is stamped after both the record's time and the index's, so the next rename made elsewhere is taken. - A trash folder holds back the rebuild of a lost record only when it is this sequence's deletion: its record names this sequence or cannot be read, or it has no record, is within a one-day grace and holds no version of another project. What was seen of folders that are gone or have a record again is forgotten. - When a deletion wins, version files pushed into the live folder before the deletion arrived are moved beside the deleted record in the trash, never deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
93afe71639
commit
7692ab402e
16 files changed
+750
-61
No files matched your search
@@ -249,7 +249,7 @@ public sealed class WorkspaceSectionTests(TestContext context)
|
||||
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")),
|
||||
Assert.Equal((Loc.L("Editor.Workspace.OpenFailed"), true, Loc.L("Editor.Project.RemoveCopy"), Loc.L("Tooltips.Editor.Project.RemoveCopy")),
|
||||
(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);
|
||||
@@ -271,6 +271,72 @@ public sealed class WorkspaceSectionTests(TestContext context)
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task AMainThisChronosCannotReadIsListedDisabledWhileAnotherProjectCanOpen() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
var directory = context.CreateTempDirectory("workspace-unreadable-main-others");
|
||||
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 services = new AppServices(environment, settings, () => { }, new ScriptedDialogs());
|
||||
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 vertical = (await services.Archives!.Projects.CreateAsync(sequenceId, "Vertical", cancellationToken: context.Cancellation)).Id;
|
||||
var bundle = Path.Combine(services.Workspace.Root, mainId.ToString("N"), WorkspaceProject.BundleFile);
|
||||
|
||||
// Damaged: the sequence has another project, so it is asked which; Main is listed, disabled, why in its tooltip.
|
||||
await WriteWhenFreeAsync(bundle, "{ not a project");
|
||||
shell.OpenSequence(sequenceId);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace offers the other project");
|
||||
var asked = (OpenInWorkspaceDialogViewModel)section.Dialog!;
|
||||
var main = asked.Projects.Single(p => p.Project.IsMain);
|
||||
Assert.True(main is { IsAvailable: false } && main.ToolTip == Loc.L("Tooltips.Editor.Workspace.State.DamagedCopy"), "a damaged Main is listed as it is");
|
||||
Assert.Equal(vertical, asked.SelectedProject?.Project.Id);
|
||||
asked.SelectedProject = main;
|
||||
Assert.Equal(vertical, asked.SelectedProject?.Project.Id, "never chosen");
|
||||
Assert.True(asked.CanOpen && asked.HasProjects);
|
||||
asked.CloseCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Dialog is null, "closed without a choice");
|
||||
Assert.False(toasts.Any(t => t.Message == Loc.L("Errors.Workspace.Damaged")), "nothing refused");
|
||||
shell.KeepSequence(null);
|
||||
|
||||
// Saved by a newer Chronos: the same, and the other project opens; Main's copy is left as it is.
|
||||
var newer = $$"""{ "format": "chronos-project", "formatVersion": 9, "sequence": { "title": "Synthetic" }, "workspace": { "projectId": "{{mainId}}", "name": "Main", "isMain": true } }""";
|
||||
await WriteWhenFreeAsync(bundle, newer);
|
||||
shell.OpenSequence(sequenceId);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Dialog is OpenInWorkspaceDialogViewModel, "Open in workspace offers the other project");
|
||||
asked = (OpenInWorkspaceDialogViewModel)section.Dialog!;
|
||||
main = asked.Projects.Single(p => p.Project.IsMain);
|
||||
Assert.True(main is { IsAvailable: false } && main.ToolTip == Loc.L("Tooltips.Editor.Workspace.State.NewerCopy"), "a newer Main is listed as it is");
|
||||
asked.OpenCommand.Execute(null);
|
||||
await WorkspaceTestBed.UntilAsync(() => section.Editor is not null, "the other project opens");
|
||||
Assert.Equal(vertical, section.OpenProjectId);
|
||||
Assert.False(toasts.Any(t => t.Message == Loc.L("Errors.Workspace.NewerCopy")), "nothing refused");
|
||||
Assert.Equal(newer, await File.ReadAllTextAsync(bundle));
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user