The fourth verification round of the matches work found 18 defects in the merge, Integrate and Matches surfaces. This commit fixes them: - An Integrate job now carries the planning account's id, so its re-plan decides ownership the way the dialog did. - A merge skips only a project the kept sequence holds a real copy of (name, offset head and history content) and re-points its renders to that copy. - A merge runs its trash checks before the Links stage and records an undo, so an abandoned merge gives the other sequence back its link, session keys and pairs. - The metered hold adopts automatic transfers that were paused before a restart. - Apply in the Compare dialog re-plans when the plan is pending or stale. - The Library's Two versions... lists the second versions a Union merge leaves, each with Drop... (dry run, confirmation, verified partner). A merge job's Open shows that list. - The merge's typed confirmation is the invariant count, and the prompt names it in all 38 languages. - Italian text uses Principale and Gemello. The Main project is named through WorkspaceText in the Projects part and in the twin tooltip. - The session keys tooltip is split into two keys, and To trash... and Delete on server... say why they are disabled. - The capture restores the editor account before the Matches scenes. - Upload again follows SyncHost.CanSendSync (Upload with Edit). - Matches rows trim archive names in the middle on a rebalanced grid; the Projects part rows trim, with the full text in the tooltip. - The sample project targets use ProjectTransplant.FreeName. DECISIONS, CHANGELOG, STATUS 8.7, the request doc and the 16 changed capture baselines are updated. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
6.1 KiB
C#
129 lines
6.1 KiB
C#
using System.IO;
|
|
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, the sync's downloads, and the workspace's copies from and renders
|
|
/// sent to a server, and the integrations of pairs with a server sequence; never a copy from or a send to this PC's archive, nor a merge.
|
|
/// </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)));
|
|
// The sync's downloads too: the option's tooltip says "uploads and downloads".
|
|
Assert.True(UploadHold.Holds(Of(JobKind.Download)));
|
|
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.Download, JobKind.WorkspaceCopy, JobKind.WorkspaceSend, JobKind.Integrate], UploadHold.Kinds);
|
|
}
|
|
|
|
[Test]
|
|
public void AnIntegrationIsHeldAMergeIsNot()
|
|
{
|
|
// An integration always moves photos with a server (owner review 6, #73); a merge of two local sequences never does.
|
|
Assert.True(UploadHold.Holds(Of(JobKind.Integrate)));
|
|
Assert.False(UploadHold.Holds(Of(JobKind.MergeSequences)));
|
|
}
|
|
|
|
[Test]
|
|
public void AnAutomaticTransferIsHeldOnAMeteredConnectionWithTheOptionOff()
|
|
{
|
|
// Owner review 6, Q6: new photos of an integrated pair move by themselves, "paused on metered connections".
|
|
var automatic = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
|
|
var manual = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals"}""");
|
|
Assert.True(Chronos.Data.Sync.SyncService.IsAutomaticTransfer(automatic));
|
|
Assert.False(Chronos.Data.Sync.SyncService.IsAutomaticTransfer(manual));
|
|
|
|
Assert.True(UploadHold.HeldNow(automatic, metered: true, optionOn: false));
|
|
Assert.False(UploadHold.HeldNow(manual, metered: true, optionOn: false));
|
|
Assert.True(UploadHold.HeldNow(manual, metered: true, optionOn: true));
|
|
Assert.False(UploadHold.HeldNow(automatic, metered: false, optionOn: true));
|
|
// An automatic upload too.
|
|
Assert.True(UploadHold.HeldNow(Of(JobKind.UploadCommit, $$"""{"server":"{{Server}}","automatic":true}"""), metered: true, optionOn: false));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnAutomaticTransferPausedBeforeARestartResumesOnceTheConnectionIsNotMetered()
|
|
{
|
|
var folder = Path.Combine(Path.GetTempPath(), "chronos-hold-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(folder);
|
|
try
|
|
{
|
|
await using var db = await Chronos.Data.ChronosDatabase.OpenAsync(Chronos.Data.DatabaseOptions.Sqlite(Path.Combine(folder, "index.db")));
|
|
var automatic = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals","automatic":true}""");
|
|
var manual = Of(JobKind.Download, $$"""{"server":"{{Server}}","mode":"Originals"}""");
|
|
foreach (var job in new[] { automatic, manual })
|
|
{
|
|
await db.Jobs.EnqueueAsync(job);
|
|
await db.Jobs.SetStateAsync(job.Id, JobState.Paused, null);
|
|
}
|
|
await using var engine = new Chronos.Data.Jobs.JobEngine(db, [], new Chronos.Data.Jobs.JobEngineOptions { Workers = 1, WorkerId = "test" });
|
|
// A new hold after a restart: it paused the automatic one before, and its record of that is gone.
|
|
using var hold = new UploadHold(() => db, () => false, () => false);
|
|
hold.Attach(engine);
|
|
await hold.ApplyAsync();
|
|
|
|
Assert.Equal(JobState.Queued, (await db.Jobs.GetAsync(automatic.Id))!.State);
|
|
// A transfer the user started and paused stays paused: its pause may be the user's.
|
|
Assert.Equal(JobState.Paused, (await db.Jobs.GetAsync(manual.Id))!.State);
|
|
Assert.True(UploadHold.Adopts(automatic with { State = JobState.Paused }));
|
|
Assert.False(UploadHold.Adopts(manual with { State = JobState.Paused }));
|
|
}
|
|
finally
|
|
{
|
|
try
|
|
{
|
|
Directory.Delete(folder, recursive: true);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
[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.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)));
|
|
}
|
|
}
|