A push now moves the base before its local file reads as sent; a replay journals itself in sync.json, writes the replayed versions, then the base (the commit point), and only then sets the old ones aside and adopts the local commits the home already held; a conflict met past such commits moves the base onto them first. A save-both journals its copy and the ids it sends under, so a retry completes the same copy instead of making another. The next push, pull or resolve finishes or undoes whatever a cut left, so no version is orphaned and no false conflict appears. The editor reads the working state and the media index under the project lease; workspace.json is written whole and moved into place (an empty one is made again); project files may hold 64 MiB and one that would be larger is refused before it is written, so large projects check out. The workspace copy checks the drive's free space before and during the copy, keeps the folder in its checkpoint and stores a reset when a pass starts again, and runs at High level in the priority queue. Renders record a version only when the index holds it with the settings rendered; an unsent version renders as the project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
9.0 KiB
C#
179 lines
9.0 KiB
C#
using Chronos.Core.Localization;
|
|
using Chronos.Core.Project;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Core.Tests.Project;
|
|
|
|
/// <summary>The <c>.chronos</c> project file (BRIEF §18): a sequence reference plus the settings to open it with.</summary>
|
|
public sealed class ProjectBundleTests(TestContext context)
|
|
{
|
|
private static readonly Guid ArchiveId = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
|
|
private static readonly Guid SequenceId = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a02");
|
|
|
|
[Test]
|
|
public void ARoundTripKeepsTheReferenceAndTheSettings()
|
|
{
|
|
var bundle = Sample();
|
|
var path = Path.Combine(context.CreateTempDirectory("bundle"), ProjectBundle.FileNameFor("Harbour sunset"));
|
|
bundle.Save(path);
|
|
|
|
var back = ProjectBundle.Load(path);
|
|
Assert.Equal(bundle.Archive, back.Archive);
|
|
Assert.Equal(bundle.Sequence, back.Sequence);
|
|
Assert.Equal(bundle.Saved, back.Saved);
|
|
Assert.Equal(bundle.Project.ToJson(), back.Project.ToJson());
|
|
Assert.Equal(0.8, back.Project.Exposure.DeflickerStrength.Resolve(1.0));
|
|
Assert.SequenceEqual([3, 7], back.Project.ExcludedFrames);
|
|
|
|
var json = File.ReadAllText(path);
|
|
Assert.Contains("\"format\": \"chronos-project\"", json);
|
|
Assert.Contains("\"formatVersion\": 1", json);
|
|
}
|
|
|
|
[Test]
|
|
public void OtherFilesAreRefusedAsNotProjectFiles()
|
|
{
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse("not json"));
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse("[1, 2]"));
|
|
// The archive's own meta files are JSON too, but not project files.
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse("""{ "schemaVersion": 1, "id": "0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01" }"""));
|
|
var json = Sample().ToJson();
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"formatVersion\": 1", "\"formatVersion\": 3", StringComparison.Ordinal)));
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace(SequenceId.ToString(), "not-a-guid", StringComparison.Ordinal)));
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"version\": 1", "\"version\": 99", StringComparison.Ordinal)));
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"folder\"", "\"place\"", StringComparison.Ordinal)));
|
|
}
|
|
|
|
[Test]
|
|
public void AWorkspaceProjectFileRoundTripsItsWorkspaceSection()
|
|
{
|
|
var basis = new BundleBase(Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a10"), 7, new string('a', 64));
|
|
var workspace = new BundleWorkspace(Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a11"), "Vertical social", false,
|
|
new BundleHome(BundleHome.ArchiveKind, SequenceId, ArchiveId), basis, new BundleMedia(BundleMedia.Proxies, 12));
|
|
var bundle = Sample() with { Workspace = workspace };
|
|
var path = Path.Combine(context.CreateTempDirectory("bundle"), "project.chronos");
|
|
bundle.Save(path);
|
|
|
|
var json = File.ReadAllText(path);
|
|
Assert.Contains("\"formatVersion\": 2", json);
|
|
Assert.Contains("\"kind\": \"archive\"", json);
|
|
var back = ProjectBundle.Load(path);
|
|
Assert.Equal(workspace, back.Workspace);
|
|
Assert.Equal(bundle.Project.ToJson(), back.Project.ToJson());
|
|
Assert.False(back.IsReadOnly);
|
|
|
|
// A server home names its server; a project not pulled yet has no base.
|
|
var remote = workspace with { Home = new BundleHome(BundleHome.ServerKind, SequenceId, Server: "https://nas:8443"), Base = null, IsMain = true };
|
|
Assert.Equal(remote, ProjectBundle.Parse((bundle with { Workspace = remote }).ToJson()).Workspace);
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(json.Replace("\"kind\": \"archive\"", "\"kind\": \"cloud\"", StringComparison.Ordinal)));
|
|
}
|
|
|
|
[Test]
|
|
public void AFileOfTheFirstFormatStillOpens()
|
|
{
|
|
const string v1 = """
|
|
{ "format": "chronos-project", "formatVersion": 1, "saved": "2026-10-12T09:30:00+00:00",
|
|
"archive": { "id": "0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01", "name": "Main archive" },
|
|
"sequence": { "id": "0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a02", "folder": "2026/Harbour", "frames": 10 },
|
|
"project": { "excludedFrames": [4] },
|
|
"workspace": { "projectId": "0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a11" } }
|
|
""";
|
|
var bundle = ProjectBundle.Parse(v1);
|
|
Assert.SequenceEqual([4], bundle.Project.ExcludedFrames);
|
|
// A format 1 file has no workspace section, whatever it holds.
|
|
Assert.Null(bundle.Workspace);
|
|
Assert.Contains("\"formatVersion\": 1", bundle.ToJson());
|
|
}
|
|
|
|
[Test]
|
|
public void ANewerProjectOpensReadOnlyInAWorkspaceFileOnly()
|
|
{
|
|
var workspace = new BundleWorkspace(Guid.CreateVersion7(), "Main", true, new BundleHome(BundleHome.ArchiveKind, SequenceId, ArchiveId), null,
|
|
new BundleMedia(BundleMedia.Proxies, 0));
|
|
var json = (Sample() with { Workspace = workspace }).ToJson().Replace("\"version\": 1", "\"version\": 2", StringComparison.Ordinal);
|
|
var bundle = ProjectBundle.Parse(json);
|
|
Assert.True(bundle.IsReadOnly);
|
|
Assert.True(bundle.Project.IsNewerFormat);
|
|
Assert.Equal(0.8, bundle.Project.Exposure.DeflickerStrength.Resolve(1.0));
|
|
|
|
var plain = Sample().ToJson().Replace("\"version\": 1", "\"version\": 2", StringComparison.Ordinal);
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Parse(plain));
|
|
}
|
|
|
|
[Test]
|
|
public void AFileTooLargeToBeAProjectIsNotRead()
|
|
{
|
|
var path = Path.Combine(context.CreateTempDirectory("bundle"), "huge.chronos");
|
|
using (var stream = File.Create(path)) stream.SetLength(ProjectBundle.MaxBytes + 1L);
|
|
Assert.Throws<InvalidDataException>(() => ProjectBundle.Load(path));
|
|
}
|
|
|
|
[Test]
|
|
public void AFileNoReadCouldTakeBackIsRefusedBeforeItIsWritten()
|
|
{
|
|
var folder = context.CreateTempDirectory("bundle");
|
|
var path = Path.Combine(folder, "huge.chronos");
|
|
var sample = Sample();
|
|
var huge = sample with { Sequence = sample.Sequence with { Title = new string('x', ProjectBundle.MaxBytes) } };
|
|
var refused = Assert.Throws<ProjectTooLargeException>(() => huge.Save(path));
|
|
Assert.Equal(Loc.L("Errors.Project.TooLarge", ProjectBundle.MaxBytes >> 20), refused.Message);
|
|
Assert.False(File.Exists(path));
|
|
Assert.Empty(Directory.GetFiles(folder));
|
|
|
|
// Within the limit, the file is written and read back.
|
|
sample.Save(path);
|
|
Assert.Equal(sample.Sequence.Title, ProjectBundle.Load(path).Sequence.Title);
|
|
}
|
|
|
|
[Test]
|
|
public void FramePositionsApplyOnlyToTheFramesTheyWereSavedFor()
|
|
{
|
|
var bundle = Sample();
|
|
var current = new ProjectSettings
|
|
{
|
|
ExcludedFrames = [1],
|
|
HeroFrame = 2,
|
|
Camera = new CameraSettings { Keyframes = [new CameraKey(0, 0.5, 0.5, 1, 0)] },
|
|
};
|
|
|
|
Assert.Same(bundle.Project, bundle.ProjectFor(current, frameCount: 3600));
|
|
|
|
var changed = bundle.ProjectFor(current, frameCount: 3610);
|
|
Assert.SequenceEqual([1], changed.ExcludedFrames);
|
|
Assert.Equal(2, changed.HeroFrame);
|
|
Assert.Same(current.Camera.Keyframes, changed.Camera.Keyframes);
|
|
// Everything else comes from the file.
|
|
Assert.Equal(0.8, changed.Exposure.DeflickerStrength.Resolve(1.0));
|
|
Assert.Equal(bundle.Project.Camera.Crop, changed.Camera.Crop);
|
|
}
|
|
|
|
[Theory]
|
|
[Case("Harbour sunset", "Harbour sunset.chronos")]
|
|
[Case("Roof: 12/03 \"storm\"?", "Roof_ 12_03 _storm__.chronos")]
|
|
[Case("CON", "_CON.chronos")]
|
|
[Case(" ", "Chronos.chronos")]
|
|
public void TheFileNameComesFromTheTitle(string title, string expected) => Assert.Equal(expected, ProjectBundle.FileNameFor(title));
|
|
|
|
[Test]
|
|
public void SavingNeverReplacesAnEarlierProjectFile()
|
|
{
|
|
var folder = context.CreateTempDirectory("bundle");
|
|
Assert.Equal(Path.Combine(folder, "Harbour sunset.chronos"), ProjectBundle.FreePathIn(folder, "Harbour sunset"));
|
|
File.WriteAllText(Path.Combine(folder, "Harbour sunset.chronos"), "{}");
|
|
Directory.CreateDirectory(Path.Combine(folder, "Harbour sunset (2).chronos"));
|
|
Assert.Equal(Path.Combine(folder, "Harbour sunset (3).chronos"), ProjectBundle.FreePathIn(folder, "Harbour sunset"));
|
|
}
|
|
|
|
private static ProjectBundle Sample() => new(
|
|
new BundleArchive(ArchiveId, "Main archive", @"D:\Timelapse"),
|
|
new BundleSequence(SequenceId, "2026/2026-09-28 Harbour sunset", "Harbour sunset", 3600),
|
|
new ProjectSettings
|
|
{
|
|
Exposure = new ExposureSettings { DeflickerStrength = new Auto<double>().WithManual(0.8) },
|
|
Camera = new CameraSettings { Crop = [0.1, 0.1, 0.9, 0.9], Keyframes = [new CameraKey(120, 0.4, 0.5, 1.2, 0)] },
|
|
ExcludedFrames = [3, 7],
|
|
HeroFrame = 1800,
|
|
},
|
|
new DateTimeOffset(2026, 10, 12, 9, 30, 0, TimeSpan.Zero));
|
|
}
|