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

@@ -98,6 +98,76 @@ public sealed class WorkspaceFoundationTests(TestContext context)
Assert.Equal(Path.Combine(project.ExportsDirectory, "Roof 4K.mp4"), project.ExportFile("Roof 4K.mp4"));
}
[Test]
public void AMediaIndexHoldingOriginalsIsWrittenInAFormatAPhase5bChronosRefuses()
{
var store = new WorkspaceStore(Path.Combine(context.CreateTempDirectory("ws"), "workspace"));
var project = store.Project(Guid.CreateVersion7());
var sequenceId = Guid.CreateVersion7();
int Written() => JsonNode.Parse(File.ReadAllText(project.MediaIndexPath))!["formatVersion"]!.GetValue<int>();
// Proxies only: as phase 5b wrote it, which it reads.
project.WriteMedia(Media(sequenceId, BundleMedia.Proxies, Frame(sequenceId, 0)));
Assert.Equal(WorkspaceMedia.ProxiesFormatVersion, Written());
// Originals, or a frame holding one, or media the clean-up removed: format 2, which phase 5b refuses as newer
// rather than reading the frames' files as its proxies.
project.WriteMedia(Media(sequenceId, BundleMedia.Originals, Frame(sequenceId, 0)));
Assert.Equal(WorkspaceMedia.CurrentFormatVersion, Written());
var held = Frame(sequenceId, 0);
held = held with { Original = WorkspaceProject.OriginalName(held.Id, new string('c', 64), ".jpg"), OriginalSha256 = new string('c', 64), OriginalBytes = 9 };
project.WriteMedia(Media(sequenceId, BundleMedia.Proxies, held));
Assert.Equal(WorkspaceMedia.CurrentFormatVersion, Written());
project.WriteMedia(Media(sequenceId, BundleMedia.Proxies, Frame(sequenceId, 0)) with { Cleaned = T0 });
Assert.Equal(WorkspaceMedia.CurrentFormatVersion, Written());
Assert.True(Assert.NotNull(project.ReadMedia()).IsCleaned, "this Chronos reads its own format back");
Assert.Equal(2, WorkspaceMedia.CurrentFormatVersion);
}
[Test]
public void ALedgerNamesOnlyFilesInsideTheExports()
{
var store = new WorkspaceStore(Path.Combine(context.CreateTempDirectory("ws"), "workspace"));
var project = store.Project(Guid.CreateVersion7());
Assert.Equal(Path.GetFullPath(project.ExportFile("Roof 4K.mp4")), project.ContainedExportFile("Roof 4K.mp4"));
Assert.Equal(Path.GetFullPath(project.ExportFile(Path.Combine("Roof frames", "0001.tif"))), project.ContainedExportFile("Roof frames/0001.tif"));
foreach (var refused in new[]
{
null, "", " ", ".", "..", "../project.chronos", @"..\media.json", "a/../../x.mp4", "a//b.mp4", "./a.mp4", "/etc/passwd",
@"C:\Windows\win.ini", "C:x.mp4", @"\\server\share\x.mp4", WorkspaceProject.RendersFileName,
})
Assert.Null(project.ContainedExportFile(refused), refused ?? "null");
}
[Test]
public void ATrashEntryBeingFilledIsNeverListedAndTakesItsNameWhenWhole()
{
var root = Path.Combine(context.CreateTempDirectory("ws"), "workspace");
var projectId = Guid.CreateVersion7();
string staging;
using (var trash = WorkspaceTrash.Begin(root, projectId, T0.UtcDateTime))
{
staging = trash.Path;
Assert.True(Directory.Exists(staging));
File.WriteAllText(Path.Combine(staging, "half.jpg"), "half");
// Listed while it is being filled, an Empty… could erase what a removal is still moving there.
var listing = WorkspaceTrash.List(root);
Assert.True(listing.IsEmpty, string.Join(", ", listing.Entries.Select(e => e.Name)));
Assert.Equal((0, 0L), WorkspaceTrash.Empty(root, listing));
Assert.FileExists(Path.Combine(staging, "half.jpg"));
}
Assert.False(Directory.Exists(staging));
var entries = WorkspaceTrash.List(root).Entries;
Assert.Equal(1, entries.Count);
var entry = entries[0];
Assert.True(entry.Name.StartsWith(projectId.ToString("N") + "-", StringComparison.Ordinal), entry.Name);
Assert.Equal((1, 4L), (entry.Files, entry.Bytes));
// One that nothing came into leaves no entry.
using (var empty = WorkspaceTrash.Begin(root, projectId, T0.UtcDateTime))
Assert.True(Directory.Exists(empty.Path));
Assert.Equal(1, WorkspaceTrash.List(root).Entries.Count);
}
private static WorkspaceRenderEntry Entry(Guid projectId, string file) =>
new(Guid.CreateVersion7(), Guid.CreateVersion7(), file, new string('b', 64), 12_345, "4K HEVC", "hevc", 3840, 2160, 30, 10, projectId,
Guid.CreateVersion7(), "hash", T0);