Files
Chronos/tests/Chronos.App.Tests/Server/UploadHoldTests.cs
T
Alby96andClaude Opus 5.5 00b8dcd249 feat(workspace): send local renders home with their project and version
Phase 5c P3. A render made in a workspace must reach its home with the project
and version it was rendered from, and transfers with a server must respect a
metered connection, downloads into the workspace included.

- WorkspaceSendJobHandler: per unsent ledger entry, hash the file again
  (missing or changed: marked failed, file left in place), push the named
  version first when the home lacks it (failure fails the job, entry pending),
  then file it in this PC's archive (staged copy read back against its SHA-256,
  project and version checked against the sequence) or upload it to the server
  with ProjectId/ProjectVersionId; mark it sent. Idempotent by render id. A send
  to a server waits while HoldTransfers says so.
- SyncTransfers: extract FileRenderAsync, the lease-held filing of a staged
  render into a sequence's exports, shared by GetExportsAsync and the send.
- ISyncConnector.ProjectHome (default null; SyncHost already implements it) so
  the send can push a version to a server home.
- Server: RenderUploads checks the project fields at start and completion
  (422 project_mismatch) and records them; RenderDto carries them.
- UploadHold also pauses WorkspaceCopy and WorkspaceSend jobs naming a server;
  Server screen checkbox reads "Pause metered transfers".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 15:32:49 +01:00

63 lines
2.5 KiB
C#

using Chronos.App.Server;
using Chronos.Core.Model;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Workspaces;
using Chronos.Testing;
namespace Chronos.App.Tests.Server;
/// <summary>
/// Which jobs "Pause metered transfers" holds (Server.html, phase 5c): uploads, and the workspace's copies from and renders
/// sent to a server; never a copy from or a send to this PC's archive.
/// </summary>
public sealed class UploadHoldTests
{
private const string Server = "https://nas.local:8443";
private static readonly Guid SequenceId = Guid.CreateVersion7();
private static readonly Guid ProjectId = Guid.CreateVersion7();
private const string Root = @"C:\Users\me\Chronos\workspace";
private static Job Of(ArchiveJobRequest request) => new()
{
Id = Guid.CreateVersion7(),
Kind = request.Kind,
TargetIds = request.Targets,
TargetLabel = request.Label,
ParametersJson = request.ParametersJson,
State = JobState.Queued,
Created = DateTimeOffset.UtcNow,
};
private static Job Of(JobKind kind, string? parameters = null) => new()
{
Id = Guid.CreateVersion7(),
Kind = kind,
TargetIds = [SequenceId],
ParametersJson = parameters,
State = JobState.Queued,
Created = DateTimeOffset.UtcNow,
};
[Test]
public void TransfersWithAServerAreHeld()
{
Assert.True(UploadHold.Holds(Of(JobKind.UploadCommit)));
Assert.True(UploadHold.Holds(Of(WorkspaceJobs.CopyFromServer(SequenceId, "Harbour", Server, Root, ProjectId))));
Assert.True(UploadHold.Holds(Of(WorkspaceJobs.Send(SequenceId, "Harbour", Root, ProjectId, [], Server))));
Assert.SequenceEqual([JobKind.UploadCommit, JobKind.WorkspaceCopy, JobKind.WorkspaceSend], UploadHold.Kinds);
}
[Test]
public void TransfersWithThisPcsLibraryAndOtherJobsAreNot()
{
var sequence = new Sequence { Id = SequenceId, ArchiveId = Guid.CreateVersion7(), Title = "Harbour", Folder = "2026/harbour" };
Assert.False(UploadHold.Holds(Of(WorkspaceJobs.Copy(sequence, Root, ProjectId))));
Assert.False(UploadHold.Holds(Of(WorkspaceJobs.Send(SequenceId, "Harbour", Root, ProjectId, []))));
Assert.False(UploadHold.Holds(Of(JobKind.Download)));
Assert.False(UploadHold.Holds(Of(JobKind.Render)));
// Parameters that cannot be read are not held: the job fails with its reason.
Assert.False(UploadHold.Holds(Of(JobKind.WorkspaceSend, "{not json")));
Assert.False(UploadHold.Holds(Of(JobKind.WorkspaceCopy)));
}
}