feat(workspace): clean-up of media, size limit and workspace trash

Phase 5c P4. The workspace no longer grows without bound: a daily
workspace-cleanup system schedule (04:30, catch-up) removes the media of
projects in step with their home that were not opened for Clean after,
and the size limit removes the least recently used after each copy.
Each project kept is logged with its reason (open in Edit, not in step,
home offline, jobs pending, renders not sent, unreadable, just copied).

- WorkspaceCleaner: cleans under the project's lease, re-checking every
  condition; the originals the home no longer holds go to the workspace
  trash, never away. The media index is marked Cleaned, so the project
  reads as MediaRemoved and opening it copies the media again.
- WorkspaceTrash: lists entries with a fingerprint, and empties only the
  plan the user confirmed (refused when the trash changed since).
- Trash dialog view model and view: Erase is enabled only after the user
  types the number of entries.
- Removing a copy counts the unsent renders and the last originals. Send
  first queues the renders' sending and refuses the removal until they
  are sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 15:41:48 +01:00
1 parent 2e1c67f531
commit f86630c77a
19 files changed
+1595 -44

No files matched your search

@@ -37,7 +37,7 @@ public sealed class DesktopScheduleHostTests(TestContext context)
await fx.StartAsync();
var kept = Assert.NotNull(await fx.Db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.ArchiveScan));
Assert.Equal((scan.Id, "every:2h"), (kept.Id, kept.Recurrence));
Assert.Count(3, (await fx.Db.Schedules.ListAsync()).Where(s => s.IsSystem));
Assert.Count(4, (await fx.Db.Schedules.ListAsync()).Where(s => s.IsSystem));
// Reset goes back to what the host seeds with.
Assert.Null((await fx.Scheduler!.ResetAsync(scan.Id)).Problem);
@@ -109,9 +109,9 @@ public sealed class DesktopScheduleHostTests(TestContext context)
Assert.Equal(fx.Clock.Now.AddDays(1), backup.NextRun);
// Chronos was closed for two days: the missed copy is made once at start (catch-up, as the housekeeping's run; the
// scan has none and just moves on).
// scan has none and just moves on; the workspace clean-up, with catch-up too, runs once as well).
fx.Clock.Advance(TimeSpan.FromDays(2.5));
Assert.Equal(2, await scheduler.RunDueAsync());
Assert.Equal(3,await scheduler.RunDueAsync());
var job = (await fx.Db.Jobs.ListByScheduleAsync(backup.Id)).Single();
Assert.Equal((JobKind.Backup, JobPriority.Background, JobState.Queued), (job.Kind, job.Priority, job.State));
Assert.Equal(0, await scheduler.RunDueAsync());
@@ -168,6 +168,23 @@ public sealed class DesktopScheduleHostTests(TestContext context)
Assert.Equal(ScheduleRecurrence.DailyAt(new TimeOnly(4, 0)).Next(fx.Clock.Now, TimeZoneInfo.Utc), housekeeping.NextRun);
}
/// <summary>Phase 5c: the workspace's clean-up is a system schedule of its own, seeded once, daily at 04:30 with catch-up.</summary>
[Test]
public async Task TheWorkspaceCleanUpIsSeededOnceAsASystemSchedule()
{
await using var fx = await ScheduleFixture.CreateAsync(context);
await fx.StartAsync();
var cleanup = Assert.NotNull(await fx.Db.Schedules.GetBySystemKeyAsync(DesktopScheduleHost.WorkspaceCleanup));
Assert.Equal(("daily:04:30", true, ScheduleActions.Cleanup, true), (cleanup.Recurrence, cleanup.CatchUp, cleanup.Action, cleanup.Enabled));
var parameters = ScheduleMapping.Parameters(cleanup);
Assert.SequenceEqual([WorkspaceCleanStep.StepName, WorkspaceTrashStep.StepName], parameters.Steps!);
Assert.Equal(0, parameters.OlderThanDays);
Assert.Equal(("Workspace media", "Workspace trash"), (ScheduleText.Step(WorkspaceCleanStep.StepName), ScheduleText.Step(WorkspaceTrashStep.StepName)));
await fx.StartAsync();
Assert.Count(1, (await fx.Db.Schedules.ListAsync()).Where(s => s.SystemKey == DesktopScheduleHost.WorkspaceCleanup));
}
[Test]
public async Task SchedulesWorkOnTheArchiveAtTheFolderWhileItIsOnline()
{
@@ -36,9 +36,9 @@ public sealed class ScheduledTabTests
shell.Jobs.TabIndex = 1;
await app.ExpectAsync<SchedulesView>("jobs-scheduled");
Assert.SequenceEqual(["Archive scan", "Index backup", "Housekeeping", "Weekly integrity check", "Monthly orphans report"], schedules.Rows.Select(r => r.Name));
Assert.SequenceEqual(["Archive scan", "Index backup", "Housekeeping", "Workspace clean-up", "Weekly integrity check", "Monthly orphans report"], schedules.Rows.Select(r => r.Name));
var items = app.FindAll<ListBoxItem>().Where(i => i.DataContext is ScheduleRowViewModel && i.IsVisible).ToList();
Assert.Count(5, items);
Assert.Count(6, items);
foreach (var item in items)
{
var row = (ScheduleRowViewModel)item.DataContext;
@@ -30,9 +30,9 @@ public sealed class SchedulesViewModelTests
using var vm = await fx.ViewModelAsync();
Assert.True(vm.IsRunning && vm.IsLoaded && vm.HasRows, "the schedules are listed");
Assert.SequenceEqual(["Archive scan", "Index backup", "Housekeeping"], vm.Rows.Select(r => r.Name));
Assert.SequenceEqual(["Every 10 minutes", "Every day", "Daily at " + ScheduleText.Time(new TimeOnly(4, 0))], vm.Rows.Select(r => r.WhenText));
Assert.SequenceEqual(["Archive scan", "Index backup", "Clean-up"], vm.Rows.Select(r => r.ActionText));
Assert.SequenceEqual(["Archive scan", "Index backup", "Housekeeping", "Workspace clean-up"], vm.Rows.Select(r => r.Name));
Assert.SequenceEqual(["Every 10 minutes", "Every day", "Daily at " + ScheduleText.Time(new TimeOnly(4, 0)), "Daily at " + ScheduleText.Time(new TimeOnly(4, 30))], vm.Rows.Select(r => r.WhenText));
Assert.SequenceEqual(["Archive scan", "Index backup", "Clean-up", "Clean-up"], vm.Rows.Select(r => r.ActionText));
Assert.True(vm.Rows.All(r => r.IsSystem && r.IsEnabled && r.LastText == "never run" && r.LastKind == StatusKind.Offline), "nothing ran yet");
// The scan's next run is ten minutes away, today.
Assert.Equal(ScheduleText.Moment(fx.Clock.Now.AddMinutes(10)), vm.Rows[0].NextText);
@@ -41,9 +41,9 @@ public sealed class SchedulesViewModelTests
// A schedule the user creates joins the list after the system ones.
var created = await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Weekly check", ScheduleActions.Verify, new RecurrenceDto("weekly", Time: "02:30", Days: ["mon", "thu"])), null);
Assert.Null(created.Problem);
Assert.Equal("Weekly check", vm.Rows[3].Name);
Assert.Equal("Weekly check", vm.Rows[4].Name);
Assert.Equal(ScheduleText.DayShort(DayOfWeek.Monday) + ", " + ScheduleText.DayShort(DayOfWeek.Thursday) + " at " + ScheduleText.Time(new TimeOnly(2, 30)),
vm.Rows[3].WhenText);
vm.Rows[4].WhenText);
}
[Test]
@@ -141,11 +141,11 @@ public sealed class SchedulesViewModelTests
Assert.False(scan.DeleteCommand.CanExecute(null));
Assert.False(mine.ResetCommand.CanExecute(null));
await vm.DeleteAsync(mine);
Assert.Count(4, vm.Rows);
Assert.Count(5, vm.Rows);
answer = true;
vm.Selected = mine;
await vm.DeleteAsync(mine);
Assert.Count(3, vm.Rows);
Assert.Count(4, vm.Rows);
Assert.Null(vm.Selected);
Assert.Null(await fx.Db.Schedules.GetAsync(mine.Id));
@@ -172,7 +172,7 @@ public sealed class SchedulesViewModelTests
await vm.DeleteAsync(mine);
Assert.SequenceEqual([Loc.L("Jobs.Schedule.Failed")], toasts);
Assert.Count(4, vm.Rows);
Assert.Count(5, vm.Rows);
Assert.Contains(mine, vm.Rows);
Assert.NotNull(await fx.Db.Schedules.GetAsync(mine.Id));
}