feat(projects): workspace projects with linear versions, the local archive as their home
Owner review 2, phase 5a (R8): editing moves out of the library into a workspace on a fast disk, and a sequence gets several projects, each with a linear version history pushed and pulled like git. - Core: ProjectSettings keeps members a newer Chronos wrote (Extra) and reads a newer settings format read-only; ProjectContent is the portable form of a version (every frame position parked by photo, canonical text, SHA-256 content hash); ProjectBundle format 2 adds the workspace section, and a file without it is still written as format 1. JobKind.WorkspaceCopy = 20 (19 kept for Convert). - Data: migration 0009 (projects, project_versions, the render's project columns); ProjectService on ArchiveService.Projects keeps projects as sidecars first (.chronos/projects/<id>/), then the index, under the sequence lease: create, rename, delete into the projects' trash, history, push with fast-forward, idempotent repeat, divergence and hash checks. Main is made from the sequence's settings and mirrored both ways, so every older code path keeps working; outside writes become "external" versions, a mirror a crash cut short is completed or merged. Full scans and rebuilds take the projects back from their sidecars. - ProjectMerge moves from the App to Data/Projects, merges pending frames photo by photo and replays unpushed commits on a moved head. - Workspaces: WorkspaceStore, WorkspaceSync (checkout, save, commit, push, pull with replay and merge, conflicts settled by keep mine / take server / save both, restore, status) and the WorkspaceCopy job (proxies copied hash-verified and resumable; originals refused until phase 5c). - Renders of a project version place its positions on the frames and record the project and version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c4c1802884e403db8759ed0501f770a67a047f20)
This commit is contained in:
1 parent
e3cbe30b29
commit
03d32f18d3
51 files changed
+4917
-108
No files matched your search
@@ -0,0 +1,165 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Core.Tests.Project;
|
||||
|
||||
/// <summary>The portable form of project versions (owner review 2, R8): positions parked by photo, canonical text, a stable hash.</summary>
|
||||
public sealed class ProjectContentTests
|
||||
{
|
||||
private static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0);
|
||||
|
||||
private static FramePhoto Photo(int n, bool hashed = true) =>
|
||||
new(hashed ? n.ToString("x64", System.Globalization.CultureInfo.InvariantCulture) : null, 1000 + n, Start.AddSeconds(10 * n));
|
||||
|
||||
private static FramePhotos Frames(params FramePhoto[] photos) => new(photos.Select((p, i) => (i, p)));
|
||||
|
||||
private static ProjectSettings Positions(int[] excluded, int? hero, int keyframe) => new()
|
||||
{
|
||||
ExcludedFrames = excluded,
|
||||
HeroFrame = hero,
|
||||
Camera = new CameraSettings { Keyframes = [new CameraKey(keyframe, 0.4, 0.5, 1.2, 0)] },
|
||||
Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 },
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void ThePortableFormParksEveryPositionByPhotoAndPlacesThemBack()
|
||||
{
|
||||
var frames = Frames(Photo(1), Photo(2), Photo(3), Photo(4), Photo(5));
|
||||
var settings = Positions([1, 3], 2, 0);
|
||||
|
||||
var portable = ProjectContent.ToPortable(settings, frames);
|
||||
var parked = ProjectSettings.FromJson(portable);
|
||||
Assert.Empty(parked.ExcludedFrames);
|
||||
Assert.Null(parked.HeroFrame);
|
||||
Assert.Empty(parked.Camera.Keyframes);
|
||||
Assert.Equal(4, parked.PendingFrames!.Count);
|
||||
Assert.Equal(0.5, parked.Exposure.ExposureOffsetEv);
|
||||
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(portable, frames));
|
||||
Assert.SequenceEqual([1, 3], placed.ExcludedFrames);
|
||||
Assert.Equal(2, placed.HeroFrame);
|
||||
Assert.Equal(0, Assert.NotNull(placed.Camera.Keyframes.SingleOrDefault()).Frame);
|
||||
Assert.Null(placed.PendingFrames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PositionsFollowTheirPhotosAcrossInsertionsAndRemovals()
|
||||
{
|
||||
var before = Frames(Photo(1), Photo(2), Photo(3), Photo(4));
|
||||
var portable = ProjectContent.ToPortable(Positions([1, 3], 2, 0), before);
|
||||
|
||||
// Two photos inserted before the others, and photo 4 removed: each position names its photo, the one on 4 waits.
|
||||
var after = Frames(Photo(10), Photo(11), Photo(1), Photo(2), Photo(3));
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(portable, after));
|
||||
Assert.SequenceEqual([3], placed.ExcludedFrames);
|
||||
Assert.Equal(4, placed.HeroFrame);
|
||||
Assert.Equal(2, placed.Camera.Keyframes.Single().Frame);
|
||||
var waiting = Assert.NotNull(placed.PendingFrames).Single();
|
||||
Assert.True(waiting.Excluded && waiting.Photo.Matches(Photo(4)));
|
||||
|
||||
// Photo 4 back: the exclusion takes its place again.
|
||||
var back = ProjectSettings.FromJson(ProjectContent.Place(placed.ToJson(), Frames(Photo(10), Photo(11), Photo(1), Photo(2), Photo(3), Photo(4))));
|
||||
Assert.SequenceEqual([3, 5], back.ExcludedFrames);
|
||||
Assert.Null(back.PendingFrames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ACopyOfAPhotoHeldTwiceKeepsItsOwnPosition()
|
||||
{
|
||||
var frames = Frames(Photo(1), Photo(2), Photo(2), Photo(3));
|
||||
var portable = ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [2] }, frames);
|
||||
Assert.Equal(1, ProjectSettings.FromJson(portable).PendingFrames!.Single().Occurrence);
|
||||
|
||||
var inserted = Frames(Photo(0), Photo(1), Photo(2), Photo(2), Photo(3));
|
||||
Assert.SequenceEqual([3], ProjectSettings.FromJson(ProjectContent.Place(portable, inserted)).ExcludedFrames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhotosNotHashedYetAreMatchedBySizeAndCaptureTime()
|
||||
{
|
||||
var unhashed = Frames(Photo(1, hashed: false), Photo(2, hashed: false), Photo(3, hashed: false));
|
||||
var portable = ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [1] }, unhashed);
|
||||
var parked = ProjectSettings.FromJson(portable).PendingFrames!.Single();
|
||||
Assert.Null(parked.Sha256);
|
||||
Assert.Equal(Photo(2).Size, parked.Size);
|
||||
|
||||
// The same photos hashed since, with one inserted before them.
|
||||
var hashed = Frames(Photo(9), Photo(1), Photo(2), Photo(3));
|
||||
Assert.SequenceEqual([2], ProjectSettings.FromJson(ProjectContent.Place(portable, hashed)).ExcludedFrames);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheSameSettingsGiveTheSameTextAndHashWhateverTheFrames()
|
||||
{
|
||||
var before = Frames(Photo(1), Photo(2), Photo(3));
|
||||
var after = Frames(Photo(7), Photo(1), Photo(2), Photo(3));
|
||||
var first = ProjectContent.ToPortable(Positions([0, 2], 1, 2), before);
|
||||
// The same choices made against frames with one inserted before them: every position one further.
|
||||
var second = ProjectContent.ToPortable(Positions([1, 3], 2, 3), after);
|
||||
Assert.Equal(first, second);
|
||||
Assert.Equal(ProjectContent.Hash(first), ProjectContent.Hash(second));
|
||||
Assert.Equal(64, ProjectContent.Hash(first).Length);
|
||||
Assert.True(ProjectContent.Verifies(first, ProjectContent.Hash(first).ToUpperInvariant()));
|
||||
Assert.False(ProjectContent.Verifies(first + " ", ProjectContent.Hash(first)));
|
||||
|
||||
// Pending frames listed in another order, or written by hand with other spacing, read as the same text.
|
||||
var parked = ProjectSettings.FromJson(first);
|
||||
var shuffled = parked with { PendingFrames = [.. parked.PendingFrames!.Reverse()] };
|
||||
Assert.Equal(first, ProjectContent.Canonical(shuffled.ToJson()));
|
||||
Assert.Equal(first, ProjectContent.Canonical(JsonNode.Parse(first)!.ToJsonString()));
|
||||
Assert.Equal(first, ProjectContent.ToPortable(first, after));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MembersOfANewerChronosSurviveEveryRoundTrip()
|
||||
{
|
||||
const string json = """
|
||||
{
|
||||
"version": 1,
|
||||
"filters": { "lut": "teal-orange", "strength": 0.4 },
|
||||
"exposure": { "exposureOffsetEv": 0.25, "toneCurve": [0, 0.5, 1] },
|
||||
"camera": { "aspect": { "isAuto": false, "manual": "9:16" }, "lensProfile": "rf-15-35" },
|
||||
"pendingFrames": [ { "sha256": "abc", "size": 10, "excluded": true, "rating": 5 } ]
|
||||
}
|
||||
""";
|
||||
var settings = ProjectSettings.FromJson(json);
|
||||
Assert.Equal(0.25, settings.Exposure.ExposureOffsetEv);
|
||||
var written = JsonNode.Parse(settings.ToJson())!;
|
||||
Assert.Equal("teal-orange", written["filters"]!["lut"]!.GetValue<string>());
|
||||
Assert.Equal(3, written["exposure"]!["toneCurve"]!.AsArray().Count);
|
||||
Assert.Equal("rf-15-35", written["camera"]!["lensProfile"]!.GetValue<string>());
|
||||
Assert.Equal(5, written["pendingFrames"]![0]!["rating"]!.GetValue<int>());
|
||||
|
||||
var portable = ProjectContent.ToPortable(json, Frames(Photo(1)));
|
||||
Assert.Contains("teal-orange", portable);
|
||||
Assert.Contains("lensProfile", ProjectContent.Place(portable, Frames(Photo(1))));
|
||||
Assert.Equal(portable, ProjectContent.Canonical(ProjectSettings.FromJson(portable).ToJson()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingsOfANewerFormatAreReadOnlyAndKeptAsTheyAre()
|
||||
{
|
||||
var newer = """{ "version": 2, "excludedFrames": [1], "exposure": { "exposureOffsetEv": 1.5 }, "grade": { "look": "film" } }""";
|
||||
Assert.Throws<InvalidDataException>(() => ProjectSettings.FromJson(newer));
|
||||
var read = ProjectSettings.FromJson(newer, allowNewer: true);
|
||||
Assert.True(read.IsNewerFormat);
|
||||
Assert.Equal(1.5, read.Exposure.ExposureOffsetEv);
|
||||
Assert.Equal(2, ProjectContent.FormatOf(newer));
|
||||
Assert.Equal(1, ProjectContent.FormatOf("""{ "exposure": {} }"""));
|
||||
|
||||
// Its positions are a newer Chronos's to translate: only the text is made canonical.
|
||||
var portable = ProjectContent.ToPortable(newer, Frames(Photo(1), Photo(2)));
|
||||
Assert.SequenceEqual([1], ProjectSettings.FromJson(portable, allowNewer: true).ExcludedFrames);
|
||||
Assert.Contains("film", portable);
|
||||
Assert.Equal(portable, ProjectContent.Place(portable, Frames(Photo(2))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TextThatIsNoProjectIsRefused()
|
||||
{
|
||||
Assert.Throws<JsonException>(() => ProjectContent.ToPortable("not json", Frames(Photo(1))));
|
||||
Assert.Throws<JsonException>(() => ProjectContent.Canonical("[1, 2]"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user