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)
217 lines
8.1 KiB
C#
217 lines
8.1 KiB
C#
using Chronos.Data.Projects;
|
|
using System.Globalization;
|
|
using Chronos.App.Editor;
|
|
using Chronos.Core.Analysis;
|
|
using Chronos.Core.Analysis.Deep;
|
|
using Chronos.Core.Diagnostics.Synthetic;
|
|
using Chronos.Core.Imaging;
|
|
using Chronos.Core.Localization;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Core.Project;
|
|
using Chronos.Core.Render.Diagnostics;
|
|
using Chronos.Data.Archiving.Jobs;
|
|
|
|
namespace Chronos.App.Tests.Editor;
|
|
|
|
/// <summary>A synthetic sunset with flicker and two exposure steps, as the editor tests open it.</summary>
|
|
internal static class EditorFixture
|
|
{
|
|
private static readonly Lazy<SyntheticSequence> Shared = new(() => Sequence());
|
|
|
|
static EditorFixture() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
|
|
|
public static SyntheticSequence Sunset => Shared.Value;
|
|
|
|
public static SyntheticSequence Sequence(int frames = 72) => SyntheticSequence.Create(new SyntheticSequenceOptions
|
|
{
|
|
Width = 96,
|
|
Height = 64,
|
|
FrameCount = frames,
|
|
StartEv = 0,
|
|
EndEv = -2,
|
|
FlickerEv = 0.25,
|
|
ExposureSteps = [new SyntheticExposureStep(24, -1), new SyntheticExposureStep(48, -1)],
|
|
StartKelvin = 5200,
|
|
EndKelvin = 3400,
|
|
});
|
|
|
|
/// <summary>The sequence as <see cref="ISequenceSource.LoadAsync"/> returns it, with a deep analysis when asked.</summary>
|
|
public static SequenceContent Content(SyntheticSequence sequence, ProjectSettings? project = null, bool deep = true)
|
|
{
|
|
var id = Guid.CreateVersion7();
|
|
var frames = sequence.Frames.Select(f => f with { SequenceId = id }).ToList();
|
|
var row = new Sequence
|
|
{
|
|
Id = id,
|
|
ArchiveId = Guid.CreateVersion7(),
|
|
Title = "Harbour sunset",
|
|
Folder = "2026/2026-09-28 Synthetic",
|
|
CameraMake = sequence.Options.CameraMake,
|
|
CameraModel = sequence.Options.CameraModel,
|
|
FirstCapture = frames[0].CapturedAt,
|
|
LastCapture = frames[^1].CapturedAt,
|
|
FrameCount = frames.Count,
|
|
MedianInterval = sequence.Options.IntervalSeconds,
|
|
};
|
|
var report = deep ? DeepAnalyzer.AnalyzeAsync(new Frames(sequence)).GetAwaiter().GetResult() : null;
|
|
return new SequenceContent(row, frames, project ?? new ProjectSettings(), LightAnalyzer.Analyze(frames), report, sequence.Options.Width,
|
|
sequence.Options.Height, null, [], []);
|
|
}
|
|
|
|
/// <summary>Synthetic frames as the deep analysis reads them.</summary>
|
|
private sealed class Frames(SyntheticSequence sequence) : IFrameSource
|
|
{
|
|
public int Count => sequence.Count;
|
|
|
|
public LightFrame Metadata(int index) => LightFrame.From(sequence.Metadata[index], index);
|
|
|
|
public ValueTask<ImageBuffer?> LoadAsync(int index, int maxLongEdge, CancellationToken cancellationToken) =>
|
|
ValueTask.FromResult<ImageBuffer?>(sequence.Render(index));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// An in-memory <see cref="ISequenceSource"/>: synthetic pixels, a stored project with the same merge rule as the
|
|
/// archive, recorded jobs. <see cref="ExternalEdit"/> simulates someone else changing the stored project before a save.
|
|
/// </summary>
|
|
internal sealed class FakeSequenceSource(SyntheticSequence sequence, SequenceContent content) : ISequenceSource
|
|
{
|
|
private readonly SyntheticFrameSource _pixels = new(sequence);
|
|
|
|
/// <summary>The frames the session read last (opened with, or loaded since).</summary>
|
|
private IReadOnlyList<Frame> _read = content.Frames;
|
|
|
|
public ProjectSettings Stored { get; set; } = content.Project;
|
|
|
|
public SequenceContent Content { get; set; } = content;
|
|
|
|
public List<ArchiveJobRequest> Submitted { get; } = [];
|
|
|
|
/// <summary>A server sequence: renders become one job per preset.</summary>
|
|
public bool IsRemote { get; init; }
|
|
|
|
public bool IsReadOnly { get; set; }
|
|
|
|
public bool IsOutdated { get; private set; }
|
|
|
|
/// <summary>Jobs cancelled and retried through the source.</summary>
|
|
public List<Guid> Cancelled { get; } = [];
|
|
|
|
public List<Guid> Retried { get; } = [];
|
|
|
|
/// <summary>Jobs <see cref="ListJobsAsync"/> returns.</summary>
|
|
public List<Job> Jobs { get; } = [];
|
|
|
|
public int Saves { get; private set; }
|
|
|
|
public int Decodes { get; private set; }
|
|
|
|
/// <summary>Applied to the stored project before the next save reads it.</summary>
|
|
public Func<ProjectSettings, ProjectSettings>? ExternalEdit { get; set; }
|
|
|
|
/// <summary>Thrown by the next save.</summary>
|
|
public Exception? FailNextSave { get; set; }
|
|
|
|
/// <summary>Thrown by every save while set (an archive that stays offline).</summary>
|
|
public Exception? FailSaves { get; set; }
|
|
|
|
/// <summary>Awaited by every decode (tests of cancellation).</summary>
|
|
public Task DecodeGate { get; set; } = Task.CompletedTask;
|
|
|
|
/// <summary>Thrown by the next load (the sequence read again after a job).</summary>
|
|
public Exception? FailNextLoad { get; set; }
|
|
|
|
/// <summary>Awaited by the next load once it has read the sequence (a read that is slow to complete).</summary>
|
|
public Task? NextLoadGate { get; set; }
|
|
|
|
/// <summary>Times the sequence was read (<see cref="LoadAsync"/>).</summary>
|
|
public int Loads { get; private set; }
|
|
|
|
public async Task<SequenceContent> LoadAsync(CancellationToken cancellationToken)
|
|
{
|
|
if (FailNextLoad is { } failure)
|
|
{
|
|
FailNextLoad = null;
|
|
throw failure;
|
|
}
|
|
Loads++;
|
|
var content = Content with { Project = Stored };
|
|
if (NextLoadGate is { } gate)
|
|
{
|
|
NextLoadGate = null;
|
|
await gate;
|
|
}
|
|
_read = content.Frames;
|
|
return content;
|
|
}
|
|
|
|
/// <summary>Whether <see cref="Content"/> holds the frames read last; a server sequence becomes outdated when not.</summary>
|
|
public Task<bool> FramesCurrentAsync(CancellationToken cancellationToken)
|
|
{
|
|
var current = _read.Select(f => f.Id).SequenceEqual(Content.Frames.Select(f => f.Id));
|
|
if (!current && IsRemote) MarkOutdated();
|
|
return Task.FromResult(current);
|
|
}
|
|
|
|
public async ValueTask<ImageBuffer?> DecodeAsync(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken)
|
|
{
|
|
await DecodeGate.WaitAsync(cancellationToken);
|
|
Decodes++;
|
|
return await _pixels.GetFrameAsync(index, maxLongEdge, purpose, cancellationToken);
|
|
}
|
|
|
|
public Task<ProjectSettings> SaveProjectAsync(ProjectSettings project, ProjectSettings basis, CancellationToken cancellationToken)
|
|
{
|
|
if (FailSaves is { } lasting) return Task.FromException<ProjectSettings>(lasting);
|
|
if (FailNextSave is { } failure)
|
|
{
|
|
FailNextSave = null;
|
|
return Task.FromException<ProjectSettings>(failure);
|
|
}
|
|
if (ExternalEdit is { } edit)
|
|
{
|
|
Stored = edit(Stored);
|
|
ExternalEdit = null;
|
|
}
|
|
Stored = ProjectMerge.SameValues(Stored, basis) ? project : ProjectMerge.Merge(basis, project, Stored);
|
|
Saves++;
|
|
return Task.FromResult(Stored);
|
|
}
|
|
|
|
public Task<Guid> SubmitAsync(ArchiveJobRequest request, CancellationToken cancellationToken)
|
|
{
|
|
Submitted.Add(request);
|
|
return Task.FromResult(Guid.CreateVersion7());
|
|
}
|
|
|
|
public event Action<Job>? JobChanged;
|
|
|
|
public event Action? ReadOnlyChanged;
|
|
|
|
/// <summary>The server's frames changed under the proxies (as a server sequence finds out).</summary>
|
|
public void MarkOutdated()
|
|
{
|
|
IsOutdated = IsReadOnly = true;
|
|
ReadOnlyChanged?.Invoke();
|
|
}
|
|
|
|
public Task CancelJobAsync(Guid jobId, CancellationToken cancellationToken)
|
|
{
|
|
Cancelled.Add(jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task RetryJobAsync(Guid jobId, CancellationToken cancellationToken)
|
|
{
|
|
Retried.Add(jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<IReadOnlyList<Job>> ListJobsAsync(CancellationToken cancellationToken) => Task.FromResult<IReadOnlyList<Job>>([.. Jobs]);
|
|
|
|
/// <summary>A job of the sequence changed (as the engine or the server reports it).</summary>
|
|
public void Report(Job job) => JobChanged?.Invoke(job);
|
|
|
|
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
|
}
|