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>
113 lines
5.8 KiB
C#
113 lines
5.8 KiB
C#
using Chronos.Core.Model;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Data.Projects;
|
|
using Chronos.Data.Tests.Archiving;
|
|
using Chronos.Data.Tests.Projects;
|
|
using Chronos.Data.Workspaces;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Workspaces;
|
|
|
|
/// <summary>An archive with an uploaded sequence as the projects' home, and workspaces that edit it (owner review 2, R8).</summary>
|
|
internal sealed class WorkspaceFixture : IAsyncDisposable
|
|
{
|
|
private readonly TestContext _context;
|
|
private JobEngine? _engine;
|
|
|
|
private WorkspaceFixture(TestContext context, ArchiveFixture archive, Sequence sequence, List<Frame> frames)
|
|
{
|
|
_context = context;
|
|
Archive = archive;
|
|
Sequence = sequence;
|
|
Frames = frames;
|
|
Home = new ArchiveProjectHome(archive.Db, archive.Service.Projects, sequence.Id);
|
|
}
|
|
|
|
public ArchiveFixture Archive { get; }
|
|
public Sequence Sequence { get; set; }
|
|
public List<Frame> Frames { get; }
|
|
public ArchiveProjectHome Home { get; }
|
|
public ChronosDatabase Db => Archive.Db;
|
|
public CancellationToken Ct => Archive.Ct;
|
|
|
|
public static async Task<WorkspaceFixture> CreateAsync(TestContext context, ArchiveFixture archive, int frames = 5)
|
|
{
|
|
var (sequence, list) = await ProjectServiceTests.UploadedAsync(archive, frames);
|
|
return new WorkspaceFixture(context, archive, sequence, list);
|
|
}
|
|
|
|
/// <summary>A workspace of its own (another PC, or another folder of this one) and its sync.</summary>
|
|
public (WorkspaceStore Store, WorkspaceSync Sync) Workspace(string name = "workspace")
|
|
{
|
|
var store = new WorkspaceStore(Path.Combine(_context.CreateTempDirectory(name), "workspace"));
|
|
return (store, new WorkspaceSync(store, "Chronos on " + name) { LockWait = TimeSpan.FromSeconds(TestTiming.Budget(10)) });
|
|
}
|
|
|
|
/// <summary>Main of the sequence checked out into <paramref name="sync"/>'s workspace, its media copied.</summary>
|
|
public async Task<WorkspaceProject> CheckoutAsync(WorkspaceSync sync, Guid? projectId = null)
|
|
{
|
|
var id = projectId ?? (await Archive.Service.Projects.MainAsync(Sequence.Id, Ct)).Id;
|
|
var project = await sync.CheckoutAsync(Home, id, cancellationToken: Ct);
|
|
await CopyAsync(sync.Store, id);
|
|
return project;
|
|
}
|
|
|
|
/// <summary>Runs a workspace copy job to its end.</summary>
|
|
public Task<Job> CopyAsync(WorkspaceStore store, Guid projectId, JobState expected = JobState.Done, string? checkpoint = null, string media = "proxies") =>
|
|
CopyAsync(store.Root, projectId, expected, checkpoint, media);
|
|
|
|
/// <summary>Runs a workspace copy job into the workspace at <paramref name="root"/> to its end.</summary>
|
|
public async Task<Job> CopyAsync(string root, Guid projectId, JobState expected = JobState.Done, string? checkpoint = null, string media = "proxies")
|
|
{
|
|
var engine = await EngineAsync();
|
|
var request = WorkspaceJobs.Copy(Sequence, root, projectId, media);
|
|
var job = checkpoint is null ? await engine.EnqueueAsync(request, cancellationToken: Ct) : await Archive.EnqueueWithCheckpointAsync(engine, request, checkpoint);
|
|
return await Archive.WaitForAsync(job.Id, expected, (int)TestTiming.Budget(60));
|
|
}
|
|
|
|
private async Task<JobEngine> EngineAsync()
|
|
{
|
|
if (_engine is not null) return _engine;
|
|
_engine = new JobEngine(Db, [.. Archive.Service.CreateJobHandlers(), .. WorkspaceJobs.CreateHandlers(Db, Archive.Service)],
|
|
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
|
|
await _engine.StartAsync(Ct);
|
|
return _engine;
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
if (_engine is not null) await _engine.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
/// <summary>A home that cannot be reached, standing for a server out of reach or an archive offline.</summary>
|
|
internal sealed class UnreachableHome(IProjectHome home) : IProjectHome
|
|
{
|
|
public bool Reachable { get; set; }
|
|
|
|
private T Reach<T>(Func<T> call) => Reachable ? call() : throw new HomeUnavailableException("The home cannot be reached.");
|
|
|
|
public Task<HomeSequence> SequenceAsync(CancellationToken cancellationToken) => Reach(() => home.SequenceAsync(cancellationToken));
|
|
public Task<IReadOnlyList<SequenceProject>> ListAsync(CancellationToken cancellationToken) => Reach(() => home.ListAsync(cancellationToken));
|
|
|
|
public Task<SequenceProject> CreateAsync(string name, Guid? fromVersionId, string? author, CancellationToken cancellationToken) =>
|
|
Reach(() => home.CreateAsync(name, fromVersionId, author, cancellationToken));
|
|
|
|
public Task<ProjectVersion> HeadAsync(Guid projectId, CancellationToken cancellationToken) => Reach(() => home.HeadAsync(projectId, cancellationToken));
|
|
|
|
public Task<ProjectVersion?> GetVersionAsync(Guid projectId, Guid versionId, CancellationToken cancellationToken) =>
|
|
Reach(() => home.GetVersionAsync(projectId, versionId, cancellationToken));
|
|
|
|
public Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken) =>
|
|
Reach(() => home.VersionsAfterAsync(projectId, afterNumber, limit, cancellationToken));
|
|
|
|
public Task<IReadOnlyList<ProjectVersion>> HistoryAsync(Guid projectId, int? beforeNumber, int limit, CancellationToken cancellationToken) =>
|
|
Reach(() => home.HistoryAsync(projectId, beforeNumber, limit, cancellationToken));
|
|
|
|
public Task<PushResult> PushAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken) =>
|
|
Reach(() => home.PushAsync(projectId, version, cancellationToken));
|
|
|
|
public Task<HomeFrames> FramesAsync(CancellationToken cancellationToken) => Reach(() => home.FramesAsync(cancellationToken));
|
|
}
|