feat(cli,management): close area-move and template-folder CLI parity gaps
Two verified-absent parity gaps between the service layer and the CLI / ManagementActor command surface, both left as follow-ups by the 2026-05-11 design plans. (1) area move. AreaService.MoveAreaAsync had existed since the deployment topology page shipped but was reachable only from the Blazor UI. Adds MoveAreaCommand(AreaId, NewParentAreaId?) to Commons, a ManagementActor dispatch arm delegating straight to AreaService.MoveAreaAsync (not-found / self-parent / descendant-cycle / cross-site / name-collision all surface as the standard curated ManagementCommandException failure response; the service writes its own "Move" audit row), and the CLI verb `site area move --id [--parent-id]`. Omitting --parent-id moves the area to the site root, matching the command's nullable NewParentAreaId. The command carries the SAME any-of [Designer, Deployer] gate as CreateArea/UpdateArea/DeleteArea (arch-review C6): re-parenting is the same structural authoring act, exposed on the same two surfaces. Placed under the existing `site area` group rather than a new top-level `area` group, alongside its create/update/delete siblings. (2) template folder verbs. The five folder management commands have been handled by ManagementActor since the folder-hierarchy plan, but the promised CLI surface was never written. Adds `template folder list|create|rename|move|reorder|delete` mapping 1:1 onto ListTemplateFolders / CreateTemplateFolder / RenameTemplateFolder / MoveTemplateFolder / ReorderTemplateFolder / DeleteTemplateFolder. --parent-id is omitted to target the tree root; --direction takes the lowercase literals up/down, validated at parse time by AcceptOnlyFromAmong (same case-sensitive contract as the audit --channel/--kind/--status options). Follow-on updates: the frozen authorization matrix gains its MoveArea entry (reflection-driven, so a missing entry would have failed CI); CommandTreeTests pins both new verb sets plus the omit-parent-id-means-root parse behaviour and registry round-trips; ManagementActorTests covers the MoveArea role gate and the delegate-to-service success/root/cycle/not-found paths; the CLI README and Component-ManagementService.md document the new surface (the latter also gained the previously-undocumented ReorderTemplateFolder); both plan docs' follow-up lines are marked done.
This commit is contained in:
@@ -151,6 +151,135 @@ public class CommandTreeTests
|
||||
Assert.Contains("clear", subNames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TemplateFolder_HasFullManagementCommandParity()
|
||||
{
|
||||
// CLI/management parity follow-up (docs/plans/2026-05-11-templates-folder-hierarchy.md):
|
||||
// the folder management commands shipped without any CLI surface. Pin the
|
||||
// 1:1 verb set so a verb cannot silently disappear again.
|
||||
var template = TemplateCommands.Build(Url, Format, Username, Password);
|
||||
var folder = template.Subcommands.Single(c => c.Name == "folder");
|
||||
var subNames = folder.Subcommands.Select(c => c.Name).ToHashSet();
|
||||
Assert.Contains("list", subNames);
|
||||
Assert.Contains("create", subNames);
|
||||
Assert.Contains("rename", subNames);
|
||||
Assert.Contains("move", subNames);
|
||||
Assert.Contains("reorder", subNames);
|
||||
Assert.Contains("delete", subNames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TemplateFolderCreate_ParentIdIsOptional_SoRootIsReachable()
|
||||
{
|
||||
// Omitting --parent-id must parse cleanly — that is how a folder is created
|
||||
// at the tree root (null ParentFolderId on CreateTemplateFolderCommand).
|
||||
var template = TemplateCommands.Build(Url, Format, Username, Password);
|
||||
var folder = template.Subcommands.Single(c => c.Name == "folder");
|
||||
var create = folder.Subcommands.Single(c => c.Name == "create");
|
||||
var parentOption = create.Options.Single(o => o.Name == "--parent-id");
|
||||
|
||||
var rootParse = create.Parse(new[] { "--name", "Dev" });
|
||||
Assert.Empty(rootParse.Errors);
|
||||
Assert.Null(rootParse.GetValue((Option<int?>)parentOption));
|
||||
|
||||
var nestedParse = create.Parse(new[] { "--name", "Sub", "--parent-id", "7" });
|
||||
Assert.Empty(nestedParse.Errors);
|
||||
Assert.Equal(7, nestedParse.GetValue((Option<int?>)parentOption));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TemplateFolderMove_ParentIdIsOptional_SoRootIsReachable()
|
||||
{
|
||||
var template = TemplateCommands.Build(Url, Format, Username, Password);
|
||||
var folder = template.Subcommands.Single(c => c.Name == "folder");
|
||||
var move = folder.Subcommands.Single(c => c.Name == "move");
|
||||
var parentOption = move.Options.Single(o => o.Name == "--parent-id");
|
||||
|
||||
var parse = move.Parse(new[] { "--id", "3" });
|
||||
Assert.Empty(parse.Errors);
|
||||
Assert.Null(parse.GetValue((Option<int?>)parentOption));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("up")]
|
||||
[InlineData("down")]
|
||||
public void TemplateFolderReorder_AcceptsUpAndDown(string direction)
|
||||
{
|
||||
var template = TemplateCommands.Build(Url, Format, Username, Password);
|
||||
var folder = template.Subcommands.Single(c => c.Name == "folder");
|
||||
var reorder = folder.Subcommands.Single(c => c.Name == "reorder");
|
||||
|
||||
var parse = reorder.Parse(new[] { "--id", "3", "--direction", direction });
|
||||
Assert.Empty(parse.Errors);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("sideways")]
|
||||
// AcceptOnlyFromAmong is case-SENSITIVE (same contract as the audit
|
||||
// --channel / --kind / --status options), so the literals are lowercase only.
|
||||
[InlineData("Up")]
|
||||
public void TemplateFolderReorder_RejectsAnythingElse(string direction)
|
||||
{
|
||||
var template = TemplateCommands.Build(Url, Format, Username, Password);
|
||||
var folder = template.Subcommands.Single(c => c.Name == "folder");
|
||||
var reorder = folder.Subcommands.Single(c => c.Name == "reorder");
|
||||
|
||||
var parse = reorder.Parse(new[] { "--id", "3", "--direction", direction });
|
||||
Assert.NotEmpty(parse.Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TemplateFolderReorder_RequiresDirection()
|
||||
{
|
||||
var template = TemplateCommands.Build(Url, Format, Username, Password);
|
||||
var folder = template.Subcommands.Single(c => c.Name == "folder");
|
||||
var reorder = folder.Subcommands.Single(c => c.Name == "reorder");
|
||||
|
||||
var parse = reorder.Parse(new[] { "--id", "3" });
|
||||
Assert.NotEmpty(parse.Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SiteArea_HasMoveVerb()
|
||||
{
|
||||
// CLI/management parity follow-up (docs/plans/2026-05-11-deployment-topology-page-design.md):
|
||||
// AreaService.MoveAreaAsync had no management command and no CLI verb.
|
||||
var site = SiteCommands.Build(Url, Format, Username, Password);
|
||||
var area = site.Subcommands.Single(c => c.Name == "area");
|
||||
var subNames = area.Subcommands.Select(c => c.Name).ToHashSet();
|
||||
Assert.Contains("move", subNames);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SiteAreaMove_ParentIdIsOptional_SoSiteRootIsReachable()
|
||||
{
|
||||
// Omitting --parent-id is how an area is moved to the site root
|
||||
// (null NewParentAreaId on MoveAreaCommand).
|
||||
var site = SiteCommands.Build(Url, Format, Username, Password);
|
||||
var area = site.Subcommands.Single(c => c.Name == "area");
|
||||
var move = area.Subcommands.Single(c => c.Name == "move");
|
||||
var parentOption = move.Options.Single(o => o.Name == "--parent-id");
|
||||
|
||||
var rootParse = move.Parse(new[] { "--id", "3" });
|
||||
Assert.Empty(rootParse.Errors);
|
||||
Assert.Null(rootParse.GetValue((Option<int?>)parentOption));
|
||||
|
||||
var reparentParse = move.Parse(new[] { "--id", "3", "--parent-id", "2" });
|
||||
Assert.Empty(reparentParse.Errors);
|
||||
Assert.Equal(2, reparentParse.GetValue((Option<int?>)parentOption));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SiteAreaMove_RequiresId()
|
||||
{
|
||||
var site = SiteCommands.Build(Url, Format, Username, Password);
|
||||
var area = site.Subcommands.Single(c => c.Name == "area");
|
||||
var move = area.Subcommands.Single(c => c.Name == "move");
|
||||
|
||||
var parse = move.Parse(Array.Empty<string>());
|
||||
Assert.NotEmpty(parse.Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TemplateList_HasSkipAndTakePagingOptions()
|
||||
{
|
||||
@@ -200,6 +329,13 @@ public class CommandTreeTests
|
||||
[InlineData(typeof(ImportBundleCommand))]
|
||||
[InlineData(typeof(AddTemplateNativeAlarmSourceCommand))]
|
||||
[InlineData(typeof(SetInstanceNativeAlarmSourceOverrideCommand))]
|
||||
[InlineData(typeof(MoveAreaCommand))]
|
||||
[InlineData(typeof(ListTemplateFoldersCommand))]
|
||||
[InlineData(typeof(CreateTemplateFolderCommand))]
|
||||
[InlineData(typeof(RenameTemplateFolderCommand))]
|
||||
[InlineData(typeof(MoveTemplateFolderCommand))]
|
||||
[InlineData(typeof(ReorderTemplateFolderCommand))]
|
||||
[InlineData(typeof(DeleteTemplateFolderCommand))]
|
||||
public void CommandPayloadTypes_ResolveViaRegistry(Type commandType)
|
||||
{
|
||||
// GetCommandName throws ArgumentException for an unregistered type — the CLI
|
||||
|
||||
@@ -3429,6 +3429,99 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
ExpectMsg<ManagementUnauthorized>(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// MoveArea (CLI/management parity follow-up from the deployment-topology
|
||||
// plan): re-parenting is the same structural authoring act as create /
|
||||
// update / delete, so it carries the identical any-of [Designer, Deployer]
|
||||
// gate, and every validation rule is delegated to AreaService.MoveAreaAsync.
|
||||
// ========================================================================
|
||||
|
||||
[Theory]
|
||||
[InlineData("Designer")]
|
||||
[InlineData("Deployer")]
|
||||
public void MoveArea_DesignerOrDeployer_Allowed(string role)
|
||||
{
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new MoveAreaCommand(1, 2), role));
|
||||
var resp = ExpectMsg<object>(TimeSpan.FromSeconds(5));
|
||||
Assert.IsNotType<ManagementUnauthorized>(resp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveArea_ViewerOnly_Unauthorized()
|
||||
{
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new MoveAreaCommand(1, 2), "Viewer"));
|
||||
ExpectMsg<ManagementUnauthorized>(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveArea_ToNewParent_ReturnsSuccessAndReparentsArea()
|
||||
{
|
||||
_services.AddScoped<AreaService>();
|
||||
var moving = new Area("Line1") { Id = 3, SiteId = 1, ParentAreaId = 1 };
|
||||
var target = new Area("Building2") { Id = 2, SiteId = 1 };
|
||||
_templateRepo.GetAreaByIdAsync(3, Arg.Any<CancellationToken>()).Returns(moving);
|
||||
_templateRepo.GetAreaByIdAsync(2, Arg.Any<CancellationToken>()).Returns(target);
|
||||
_templateRepo.GetAreasBySiteIdAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Area> { new("Building1") { Id = 1, SiteId = 1 }, target, moving });
|
||||
|
||||
var actor = CreateActor();
|
||||
var envelope = Envelope(new MoveAreaCommand(3, 2), "Deployer");
|
||||
actor.Tell(envelope);
|
||||
|
||||
var response = ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal(envelope.CorrelationId, response.CorrelationId);
|
||||
Assert.Equal(2, moving.ParentAreaId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveArea_WithNullParent_MovesToSiteRoot()
|
||||
{
|
||||
_services.AddScoped<AreaService>();
|
||||
var moving = new Area("Line1") { Id = 3, SiteId = 1, ParentAreaId = 1 };
|
||||
_templateRepo.GetAreaByIdAsync(3, Arg.Any<CancellationToken>()).Returns(moving);
|
||||
_templateRepo.GetAreasBySiteIdAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Area> { new("Building1") { Id = 1, SiteId = 1 }, moving });
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new MoveAreaCommand(3, null), "Designer"));
|
||||
|
||||
ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
Assert.Null(moving.ParentAreaId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveArea_UnderOwnDescendant_ReturnsError()
|
||||
{
|
||||
_services.AddScoped<AreaService>();
|
||||
var parent = new Area("Building1") { Id = 1, SiteId = 1 };
|
||||
var child = new Area("Line1") { Id = 2, SiteId = 1, ParentAreaId = 1 };
|
||||
_templateRepo.GetAreaByIdAsync(1, Arg.Any<CancellationToken>()).Returns(parent);
|
||||
_templateRepo.GetAreaByIdAsync(2, Arg.Any<CancellationToken>()).Returns(child);
|
||||
_templateRepo.GetAreasBySiteIdAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Area> { parent, child });
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new MoveAreaCommand(1, 2), "Designer"));
|
||||
|
||||
var response = ExpectMsg<ManagementError>(TimeSpan.FromSeconds(5));
|
||||
Assert.Contains("descendants", response.Error, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveArea_AreaNotFound_ReturnsError()
|
||||
{
|
||||
_services.AddScoped<AreaService>();
|
||||
_templateRepo.GetAreaByIdAsync(99, Arg.Any<CancellationToken>()).Returns((Area?)null);
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new MoveAreaCommand(99, null), "Designer"));
|
||||
|
||||
var response = ExpectMsg<ManagementError>(TimeSpan.FromSeconds(5));
|
||||
Assert.Contains("99", response.Error);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Remote-query actor dispatch for the OPC UA design-time commands
|
||||
// (arch-review C4): BrowseNode / SearchAddressSpace / VerifyEndpoint gain
|
||||
|
||||
@@ -54,6 +54,9 @@ public class RequiredRoleMatrixTests
|
||||
// ---- Area management: any-of [Designer, Deployer] ---------------------------
|
||||
["CreateArea"] = AreaManagers,
|
||||
["UpdateArea"] = AreaManagers,
|
||||
// Re-parenting an area is the same structural authoring act as create /
|
||||
// rename / delete, so it carries the identical any-of gate.
|
||||
["MoveArea"] = AreaManagers,
|
||||
["DeleteArea"] = AreaManagers,
|
||||
|
||||
// ---- Designer-only ----------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user