feat: single setup, mass-pass progress, per-server homes, Desktop shares its library (owner review 5, v1.1.0) (#68)
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #68.
This commit is contained in:
1 parent
988068ee8e
commit
20d64af4a4
793 files changed
+23882
-2096
No files matched your search
@@ -0,0 +1,172 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Data.Tests.Homes;
|
||||
using Chronos.Data.Workspaces;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Workspaces;
|
||||
|
||||
/// <summary>The workspace split into one store per home (owner review 5, #66).</summary>
|
||||
[Category("workspace")]
|
||||
public sealed class WorkspaceHomesTests(TestContext context)
|
||||
{
|
||||
private static readonly Guid Id = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
|
||||
|
||||
[Test]
|
||||
public void ANewWorkspaceIsSplitAndEachHomeGetsItsStore()
|
||||
{
|
||||
var root = Path.Combine(context.CreateTempDirectory("ws"), "workspace");
|
||||
var homes = new WorkspaceHomes(root, new ServerIdentity([new KnownServerKey(Id, [HomeFixtures.Nas])]));
|
||||
Assert.True(homes.IsSplit);
|
||||
Assert.True(WorkspaceHomes.IsSplitRoot(root));
|
||||
Assert.Equal((WorkspaceHomes.ParentFormatVersion, WorkspaceHomes.HomesLayout), (homes.Manifest.FormatVersion, homes.Manifest.Layout));
|
||||
Assert.Empty(homes.Homes());
|
||||
// A 1.0 Chronos (store format 1) refuses the parent: it never shows the workspace empty.
|
||||
Assert.Throws<InvalidDataException>(() => new WorkspaceStore(root));
|
||||
|
||||
var local = homes.StoreFor(HomeFixtures.Local());
|
||||
Assert.Equal(Path.Combine(homes.Root, "local"), local.Root);
|
||||
var server = homes.StoreFor(HomeFixtures.Server(HomeFixtures.Nas));
|
||||
Assert.Equal(Path.Combine(homes.Root, "servers", Id.ToString("N")), server.Root);
|
||||
Assert.Same(server, homes.StoreFor(HomeFixtures.Server(ServerIdentity.IdKey(Id))));
|
||||
var record = Assert.NotNull(ServerHomeRecord.Read(server.Root));
|
||||
Assert.Equal((ServerIdentity.IdKey(Id), (Guid?)Id), (record.Key, record.Id));
|
||||
var other = homes.StoreFor(HomeFixtures.Server(HomeFixtures.Other));
|
||||
Assert.Equal(Path.Combine(homes.Root, "servers", HomeFolders.ServerFolder(HomeFixtures.Other)), other.Root);
|
||||
Assert.Equal(HomeFixtures.Other, Assert.NotNull(ServerHomeRecord.Read(other.Root)).Address);
|
||||
Assert.NotEqual(local.Id, server.Id);
|
||||
|
||||
var described = Assert.NotNull(homes.Describe(HomeFixtures.Nas, "Studio NAS", HomeFixtures.Nas, "AA:BB", DateTimeOffset.UtcNow));
|
||||
Assert.Equal(("Studio NAS", HomeFixtures.Nas, "AA:BB"), (described.Name, described.Address, described.TlsFingerprint));
|
||||
Assert.Equal(record.FirstSeen, described.FirstSeen);
|
||||
|
||||
var listed = homes.Homes();
|
||||
Assert.Equal(3, listed.Count);
|
||||
Assert.True(listed[0].IsLocal);
|
||||
Assert.Contains(listed, h => h.ServerKey == ServerIdentity.IdKey(Id) && h.Server?.Name == "Studio NAS");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProjectsAreFoundInEveryHomeAndTheTrashIsListedPerHome()
|
||||
{
|
||||
var root = Path.Combine(context.CreateTempDirectory("ws"), "workspace");
|
||||
var homes = new WorkspaceHomes(root);
|
||||
var a = HomeFixtures.Project(homes.StoreFor(HomeFixtures.Local()).Root, HomeFixtures.Local());
|
||||
var serverHome = HomeFixtures.Server(HomeFixtures.Nas);
|
||||
var b = HomeFixtures.Project(homes.StoreFor(serverHome).Root, serverHome);
|
||||
Assert.Equal(homes.LocalRoot, Path.GetDirectoryName(Assert.NotNull(homes.Find(a)).Folder));
|
||||
Assert.Equal(homes.ServerRoot(HomeFixtures.Nas), Path.GetDirectoryName(Assert.NotNull(homes.Find(b)).Folder));
|
||||
Assert.Null(homes.Find(Guid.CreateVersion7()));
|
||||
Assert.Equal(2, homes.List().Count);
|
||||
Assert.Equal(2, homes.ListBundles().Count);
|
||||
|
||||
HomeFixtures.TrashEntry(homes.ServerRoot(HomeFixtures.Nas), b, serverHome);
|
||||
var trash = homes.Trash();
|
||||
Assert.Equal(2, trash.Count);
|
||||
Assert.Equal(1, trash.Sum(t => t.Entries.Count));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void A10WorkspaceStaysOneStoreUntilItIsSorted()
|
||||
{
|
||||
var root = HomeFixtures.LegacyWorkspace(context.CreateTempDirectory("ws"));
|
||||
var a = HomeFixtures.Project(root, HomeFixtures.Local());
|
||||
var homes = new WorkspaceHomes(root);
|
||||
Assert.False(homes.IsSplit);
|
||||
Assert.Equal(1, homes.Manifest.FormatVersion);
|
||||
Assert.Equal(homes.Root, homes.StoreFor(HomeFixtures.Server(HomeFixtures.Nas)).Root);
|
||||
Assert.Equal(homes.Root, homes.Local.Root);
|
||||
Assert.True(Assert.NotNull(homes.Find(a)).Exists);
|
||||
Assert.True(homes.Homes().Single().IsLegacy);
|
||||
Assert.False(Directory.Exists(homes.LocalRoot), "nothing is made beside the 1.0 projects");
|
||||
|
||||
// A folder with projects and no manifest is a 1.0 workspace too, never a new split one.
|
||||
var bare = Path.Combine(context.CreateTempDirectory("bare"), "workspace");
|
||||
HomeFixtures.Project(bare, HomeFixtures.Local());
|
||||
Assert.False(new WorkspaceHomes(bare).IsSplit);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AProjectNotSortedYetIsListedWhereItIs()
|
||||
{
|
||||
var root = Path.Combine(context.CreateTempDirectory("ws"), "workspace");
|
||||
_ = new WorkspaceHomes(root);
|
||||
var left = HomeFixtures.Project(root, HomeFixtures.Local());
|
||||
var homes = new WorkspaceHomes(root);
|
||||
Assert.True(homes.IsSplit);
|
||||
Assert.Equal(homes.Root, Path.GetDirectoryName(Assert.NotNull(homes.Find(left)).Folder));
|
||||
Assert.True(homes.Homes()[0].IsLegacy);
|
||||
Assert.Equal(homes.LocalRoot, homes.Local.Root);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AJobQueuedBeforeTheSortingFindsItsProjectInItsHome()
|
||||
{
|
||||
var root = Path.Combine(context.CreateTempDirectory("ws"), "workspace");
|
||||
var homes = new WorkspaceHomes(root);
|
||||
var home = HomeFixtures.Server(HomeFixtures.Nas);
|
||||
var id = HomeFixtures.Project(homes.ServerRoot(HomeFixtures.Nas), home);
|
||||
_ = homes.StoreFor(home);
|
||||
// Queued with the 1.0 folder (the parent): found in the server's home.
|
||||
Assert.Equal(homes.ServerRoot(HomeFixtures.Nas), WorkspaceJobRoots.Resolve(root, id, null, "Errors.Workspace.NotCheckedOut"));
|
||||
// Queued with the home of the address, which was re-keyed to the id since.
|
||||
var rekeyed = Path.Combine(root, "servers", Id.ToString("N"));
|
||||
Directory.Move(homes.ServerRoot(HomeFixtures.Nas), rekeyed);
|
||||
Assert.Equal(rekeyed, WorkspaceJobRoots.Resolve(Path.Combine(root, "servers", HomeFolders.ServerFolder(HomeFixtures.Nas)), id, null, "Errors.Workspace.NotCheckedOut"));
|
||||
// With the parent in use now (Settings › Workspace) and an older folder named.
|
||||
Assert.Equal(rekeyed, WorkspaceJobRoots.Resolve(Path.Combine(context.CreateTempDirectory("gone"), "workspace"), id, () => root, "Errors.Workspace.NotCheckedOut"));
|
||||
// While the parent is being moved nothing runs.
|
||||
File.WriteAllText(Path.Combine(root, WorkspaceMover.JournalFile), "{}");
|
||||
var moving = Assert.Throws<InvalidOperationException>(() => WorkspaceJobRoots.Resolve(rekeyed, id, null, "Errors.Workspace.NotCheckedOut"));
|
||||
Assert.Equal(Loc.L("Errors.Workspace.Moving"), moving.Message);
|
||||
File.Delete(Path.Combine(root, WorkspaceMover.JournalFile));
|
||||
Assert.Throws<InvalidOperationException>(() => WorkspaceJobRoots.Resolve(root, Guid.CreateVersion7(), null, "Errors.Workspace.NotCheckedOut"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SameServerGoesThroughTheAliases()
|
||||
{
|
||||
var identity = new ServerIdentity([new KnownServerKey(Id, [HomeFixtures.Nas])]);
|
||||
var options = new WorkspaceJobOptions(new Chronos.Data.Processing.ProcessingOptions(), () => false);
|
||||
Assert.True(options.IsSameServer("https://NAS.local:8443", HomeFixtures.Nas));
|
||||
Assert.False(options.IsSameServer(ServerIdentity.IdKey(Id), HomeFixtures.Nas));
|
||||
var aliased = options with { SameServer = identity.Same };
|
||||
Assert.True(aliased.IsSameServer(ServerIdentity.IdKey(Id), HomeFixtures.Nas));
|
||||
Assert.False(aliased.IsSameServer(ServerIdentity.IdKey(Id), HomeFixtures.Other));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MovingASplitWorkspaceMovesEveryHome()
|
||||
{
|
||||
foreach (var sameVolume in new[] { true, false })
|
||||
{
|
||||
var parent = context.CreateTempDirectory("move");
|
||||
var from = Path.Combine(parent, "workspace");
|
||||
var homes = new WorkspaceHomes(from);
|
||||
var serverHome = HomeFixtures.Server(HomeFixtures.Nas);
|
||||
var ids = new[]
|
||||
{
|
||||
HomeFixtures.Project(homes.StoreFor(HomeFixtures.Local()).Root, HomeFixtures.Local()),
|
||||
HomeFixtures.Project(homes.StoreFor(serverHome).Root, serverHome),
|
||||
HomeFixtures.Project(homes.StoreFor(HomeFixtures.Server(HomeFixtures.Other)).Root, HomeFixtures.Server(HomeFixtures.Other)),
|
||||
};
|
||||
var before = HomeFixtures.Manifest(from);
|
||||
var to = Path.Combine(parent, "moved");
|
||||
var mover = new WorkspaceMover(from, to) { SameVolume = sameVolume };
|
||||
var survey = mover.Survey();
|
||||
Assert.Equal(3, survey.Projects.Count);
|
||||
Assert.SequenceEqual(new[] { "local", "servers", WorkspaceStore.ManifestFile }, survey.Entries);
|
||||
var lines = new List<string>();
|
||||
await mover.MoveAsync(survey.Fingerprint, log: lines.Add, cancellationToken: context.Cancellation);
|
||||
Assert.False(Directory.Exists(from), "the old folder went");
|
||||
var moved = new WorkspaceHomes(to);
|
||||
Assert.True(moved.IsSplit);
|
||||
Assert.Equal(3, moved.List().Count);
|
||||
foreach (var id in ids) Assert.NotNull(moved.Find(id));
|
||||
Assert.SequenceEqual(before, HomeFixtures.Manifest(to));
|
||||
Assert.Contains(Loc.L("Archive.Log.WorkspaceMoved", mover.To, 3, survey.Files), lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user