Phase 5a was written on an early phase 4a state. On top of phase 4b it now keeps the rules every writer of a sequence's folder follows, and keeps project versions intact through Reorganize and conversions: - ProjectService writes project sidecars, project.json and the settings only under the sequence's lease and only in a folder that holds the sequence (SequenceFolders.Holds). A folder another index moved away, or one another sequence was moved into, is refused with SequenceFolderMovedException: reads answer from the index, so no project is taken for gone, nothing is written into the other sequence's folder and the old folder is never created again. The home reports it as out of reach. Full scans and rebuilds reconcile projects the same way, and a failure there is logged instead of failing the scan. - Stored versions park positions by photo and now follow the encodings a Replace conversion (or its undo) joined through the sequence's Replaced tombstones (PhotoAlias, HomePhotos): Main's mirror, renders of a version and workspace media place them on the converted frames. ProjectContent.Rebind/SameChoices name parked photos as the frames hold them now, so a conversion or a hash since is no "external" Main version and no spurious "Modified" in a workspace, and merges see one photo. - The workspace copy job only reads the archive: it no longer runs the archive's proxy pass, makes missing proxies in the workspace, reads only a folder that holds the sequence, starts again when the folder moved or files were renamed during the copy, resumes from a checkpoint of its frames version, and refuses a workspace folder inside any library before it writes anything (Errors.Workspace.InsideLibrary). The working state keeps its positions by frame where frames stay. - ArchiveProjectHome looks for a project or version the index does not know yet in the sequence's sidecars first (an index taken back from a backup, a sequence back from the trash), instead of calling it gone. Tests cover the moved and taken folder, conversions in the archive and in the workspace, the copy refusing a workspace in a library, resuming on other frames, the alias lookup and the rebinding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
211 lines
11 KiB
C#
211 lines
11 KiB
C#
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 APhotoParkedOnAnotherEncodingFindsTheFrameHoldingItsReplacement()
|
|
{
|
|
// Owner review 2, R7: a conversion replaced photo 2 by 20 and a later one 20 by 21; the undo of another gave 3 back for 30.
|
|
PhotoAlias[] links = [new(Photo(20).Sha256!, Photo(21).Sha256!), new(Photo(2).Sha256!.ToUpperInvariant(), Photo(20).Sha256!), new(Photo(30).Sha256!, Photo(3).Sha256!)];
|
|
var converted = new FramePhotos([(0, Photo(1)), (1, Photo(21)), (2, Photo(3))], links);
|
|
var portable = ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [1], HeroFrame = 2 }, Frames(Photo(1), Photo(2), Photo(30)));
|
|
|
|
var placed = ProjectSettings.FromJson(ProjectContent.Place(portable, converted));
|
|
Assert.SequenceEqual([1], placed.ExcludedFrames);
|
|
Assert.Equal(2, placed.HeroFrame);
|
|
Assert.Null(placed.PendingFrames);
|
|
// The links joined in any order, either way: every encoding is the same frame.
|
|
var reversed = new FramePhotos([(0, Photo(1)), (1, Photo(21)), (2, Photo(3))], links.Reverse().Select(l => new PhotoAlias(l.Replacement, l.Sha256)));
|
|
foreach (var photos in new[] { converted, reversed })
|
|
Assert.SequenceEqual(new int?[] { 1, 1, 1, 2, 2 }, new[] { Photo(2), Photo(20), Photo(21), Photo(3), Photo(30) }.Select(p => photos.IndexOf(p)));
|
|
Assert.Null(converted.IndexOf(Photo(4)));
|
|
// Without the links the photos are not there: the positions wait for them.
|
|
var waiting = ProjectSettings.FromJson(ProjectContent.Place(portable, Frames(Photo(1), Photo(21), Photo(3))));
|
|
Assert.Null(waiting.HeroFrame);
|
|
Assert.Equal(2, waiting.PendingFrames!.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void ChoicesSavedOnPhotosAsTheyWereReadAsTheSameOnceRenamed()
|
|
{
|
|
// Saved while photo 1 was not hashed and photo 2 not converted yet; since, 1 was hashed and 2 converted into 20.
|
|
var before = Frames(Photo(1, hashed: false), Photo(2), Photo(3));
|
|
var now = new FramePhotos([(0, Photo(1)), (1, Photo(20)), (2, Photo(3))], [new PhotoAlias(Photo(2).Sha256!, Photo(20).Sha256!)]);
|
|
var saved = ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [0, 1] }, before);
|
|
var current = ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [0, 1] }, now);
|
|
Assert.NotEqual(saved, current);
|
|
|
|
Assert.Equal(current, ProjectContent.Rebind(saved, now));
|
|
Assert.True(ProjectContent.SameChoices(saved, current, now));
|
|
Assert.False(ProjectContent.SameChoices(saved, ProjectContent.ToPortable(new ProjectSettings { ExcludedFrames = [1] }, now), now));
|
|
// Named as the frames hold them already, or held by no frame: the text as it is.
|
|
Assert.Equal(current, ProjectContent.Rebind(current, now));
|
|
Assert.Equal(saved, ProjectContent.Rebind(saved, Frames(Photo(7))));
|
|
Assert.False(ProjectContent.SameChoices(saved, current, Frames(Photo(7))));
|
|
// A newer Chronos's settings are its own to rename.
|
|
var newer = """{ "version": 2, "pendingFrames": [ { "size": 1001, "capturedAt": "2026-09-28T18:00:10", "excluded": true } ] }""";
|
|
Assert.Equal(newer, ProjectContent.Rebind(newer, now));
|
|
}
|
|
|
|
[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]"));
|
|
}
|
|
}
|