fix(workspace): close the phase 5c review findings

Originals are now judged by their bytes, never by the media index: a removal
or clean-up hashes every file under media/originals and deletes it only when
the home holds that SHA-256; every other file, named or not, goes to the
workspace trash. Trash entries are filled under a staging name that Empty
never lists. A ledger can only name files inside exports/.

Jobs follow the workspace: a copy, render or send resolves the folder that
holds its project now (a moved workspace, a retry after a move) and waits
while a move has not switched yet. A clean-up failure after the switch is a
warning that keeps the journal for a later resume; entries that changed
since they were copied are kept, and a same-volume rename refused across
volumes falls back to copy and verify.

Sends map a replayed version by content hash, or go with the project only,
and note an old server that drops provenance. The media index (format 2) and
project file (format 3) refuse older readers while they hold originals.
Metered connections also hold sync downloads and server copies. The editor
gains Send again, the Settings page can resume a stopped move, the disabled
tooltips say why, and unused strings are pruned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 17:32:48 +01:00
1 parent 09fcff4eb2
commit 2654683a12
125 files changed
+1618 -401

No files matched your search

@@ -159,34 +159,46 @@ public abstract class WorkspaceCleanupTests(TestContext context) : DatabaseTest(
var fx = await FixtureAsync();
var (store, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
// Originals of two frames: the first as the home holds it, the second of bytes the home no longer has.
// Originals of three frames: the first as the home holds it; the second of bytes the home no longer has; the third
// recorded with the home's hash, its bytes changed since (the index is no proof). And a file the index never named.
var media = project.ReadMedia()!;
var held = WorkspaceProject.OriginalName(media.Frames[0].Id, fx.Frames[0].Sha256!, ".jpg");
var lost = WorkspaceProject.OriginalName(media.Frames[1].Id, new string('f', 64), ".jpg");
var changed = WorkspaceProject.OriginalName(media.Frames[2].Id, fx.Frames[2].Sha256!, ".jpg");
Directory.CreateDirectory(project.OriginalsDirectory);
File.WriteAllText(project.MediaFile(held), "held original");
var heldBytes = File.ReadAllBytes(fx.Archive.Paths.FromRelative(fx.Frames[0].RelativePath));
File.WriteAllBytes(project.MediaFile(held), heldBytes);
File.WriteAllText(project.MediaFile(lost), "last original");
File.WriteAllText(project.MediaFile(changed), "edited since");
File.WriteAllText(Path.Combine(project.OriginalsDirectory, "stray.jpg"), "named by no index");
project.WriteMedia(media with
{
Kind = BundleMedia.Originals,
Frames =
[
media.Frames[0] with { Original = held, OriginalSha256 = fx.Frames[0].Sha256, OriginalBytes = 13 },
media.Frames[0] with { Original = held, OriginalSha256 = fx.Frames[0].Sha256, OriginalBytes = heldBytes.Length },
media.Frames[1] with { Original = lost, OriginalSha256 = new string('f', 64), OriginalBytes = 13 },
.. media.Frames.Skip(2),
media.Frames[2] with { Original = changed, OriginalSha256 = fx.Frames[2].Sha256, OriginalBytes = 12 },
.. media.Frames.Skip(3),
],
});
// The index alone names only the second as the last one.
Assert.SequenceEqual([media.Frames[1].Id], WorkspaceCleaner.LastOriginals(project.ReadMedia(), await fx.Home.FramesAsync(fx.Ct)).Select(f => f.Id));
var report = await Cleaner(fx, sync).CleanAsync(Aged(project.ProjectId), fx.Ct);
Assert.Equal(1, One(report.Cleaned).Trashed);
// Each file hashed now: only the one the home holds byte for byte went away.
Assert.Equal(3, One(report.Cleaned).Trashed);
Assert.False(Directory.Exists(project.OriginalsDirectory), "the originals folder went");
var trash = WorkspaceTrash.List(store.Root, fx.Ct);
var entry = One(trash.Entries);
Assert.True(entry.Name.StartsWith(project.ProjectId.ToString("N") + "-", StringComparison.Ordinal), entry.Name);
Assert.Equal("last original", File.ReadAllText(Path.Combine(trash.Folder, entry.Name, WorkspaceProject.OriginalsFolder, Path.GetFileName(lost))));
Assert.Equal((1, "last original".Length), (entry.Files, entry.Bytes));
var kept = Path.Combine(trash.Folder, entry.Name, WorkspaceProject.OriginalsFolder);
Assert.Equal("last original", File.ReadAllText(Path.Combine(kept, Path.GetFileName(lost))));
Assert.Equal("edited since", File.ReadAllText(Path.Combine(kept, Path.GetFileName(changed))));
Assert.Equal("named by no index", File.ReadAllText(Path.Combine(kept, "stray.jpg")));
Assert.False(File.Exists(Path.Combine(kept, Path.GetFileName(held))), "the home holds that one");
Assert.Equal((3, (long)("last original".Length + "edited since".Length + "named by no index".Length)), (entry.Files, entry.Bytes));
}
[Test]
@@ -214,7 +226,9 @@ public abstract class WorkspaceCleanupTests(TestContext context) : DatabaseTest(
// Once copied again: the oldest goes first, and one is enough this time.
await fx.CopyAsync(sync.Store, b.ProjectId);
await fx.CopyAsync(sync.Store, c.ProjectId);
report = await Cleaner(fx, sync).CleanAsync(new WorkspaceCleanOptions { SizeLimitBytes = total - 1, Opened = opened, Now = now }, fx.Ct);
// Measured again: a copy's timestamps may be a byte shorter or longer than the first copy's.
var again = new[] { main, b, c }.Sum(p => WorkspaceCleaner.Measure(p.Folder).Bytes);
report = await Cleaner(fx, sync).CleanAsync(new WorkspaceCleanOptions { SizeLimitBytes = again - 1, Opened = opened, Now = now }, fx.Ct);
Assert.SequenceEqual([main.ProjectId], report.Cleaned.Select(p => p.ProjectId));
Assert.Empty(report.Kept);
Assert.True(Directory.Exists(b.ProxiesDirectory) && Directory.Exists(c.ProxiesDirectory), "the others stay");