Install command batches through one path

This commit is contained in:
2026-10-11 01:22:47 +00:00
parent 74f6bdeade
commit 24e8cd8629
8 changed files with 87 additions and 46 deletions

View File

@@ -56,8 +56,8 @@ func TestAppsHaveIndependentRegistries(t *testing.T) {
if _, exists := second.commands["custom"]; exists {
t.Fatal("registration leaked to another app")
}
if !first.commands["help"].reserved || !first.commands["version"].reserved {
t.Fatal("New did not reserve generated root commands")
if first.commands["help"] == nil || first.commands["help"].command.record.payload == nil || first.commands["version"] == nil || first.commands["version"].command.record.payload == nil {
t.Fatal("New did not install real help and version declarations")
}
}
@@ -138,6 +138,55 @@ func TestRootGroupRetainsPlacementMetadata(t *testing.T) {
}
}
func TestBatchInstallationRejectsNestedRootOnlyAndKeepsExistingState(t *testing.T) {
root := RootGroup("config", "Configuration.")
app, err := New(Identity{Name: "Example"})
if err != nil {
t.Fatal(err)
}
if err := app.Register(Group("outer", "", root)); err == nil {
t.Fatal("installation accepted nested root-only declaration")
}
if _, exists := app.commands["outer"]; exists {
t.Fatal("failed batch partially installed its parent")
}
if err := app.Register(root); err != nil {
t.Fatalf("root-level declaration rejected: %v", err)
}
}
func TestNoOpOnlyRegistrationPreservesRoutingSnapshot(t *testing.T) {
app, err := New(Identity{Name: "Example"})
if err != nil {
t.Fatal(err)
}
before := app.bridgeTree()
if err := app.Register(NoCommand()); err != nil {
t.Fatal(err)
}
if after := app.bridgeTree(); after != before {
t.Fatal("no-op-only registration invalidated derived metadata")
}
}
func TestCapturedDeclarationCanBeInstalledIntoMultipleApps(t *testing.T) {
declaration := Group("tools", "", NewCommand(CommandSpec[struct{}]{Name: "run"}))
first, err := New(Identity{Name: "First"}, declaration)
if err != nil {
t.Fatal(err)
}
second, err := New(Identity{Name: "Second"}, declaration)
if err != nil {
t.Fatal(err)
}
if _, ok := first.commandAt([]string{"tools", "run"}); !ok {
t.Fatal("first app lost reused declaration")
}
if _, ok := second.commandAt([]string{"tools", "run"}); !ok {
t.Fatal("second app lost reused declaration")
}
}
func TestWithErrorCopiesDeclarationAndRetainsWrappedCauses(t *testing.T) {
first := errors.New("first construction issue")
second := errors.New("second construction issue")