cli: add test coverage for WithCommands lifecycle #13

Closed
opened 2026-02-22 19:17:37 +00:00 by Virgil · 1 comment
Member

Problem

cli.WithCommands is the core registration pattern for the entire fleet — every domain repo uses it to wire commands through the Core framework lifecycle. But there are no tests for it.

The lifecycle path:

  1. cli.Main() creates core services + command services
  2. cli.Init() creates root cobra command, starts services
  3. commandService.OnStartup() casts Core.App to *cobra.Command and calls the register function
  4. Commands are now available on the root

Proposal

Add tests in pkg/cli/commands_test.go:

  • TestWithCommands_RegistersOnStartup — verify commands appear on root after startup
  • TestWithCommands_MultipleGroups — verify multiple WithCommands calls compose correctly
  • TestWithCommands_GroupWithSubcommands — verify nested group/subcommand registration
  • TestWithCommands_ExecutesCommand — verify a registered command's RunE is invoked

Context

LEM is the first external consumer. go-ml, go-devops, and go-ai will follow. This is the API contract that all domain repos depend on — it needs test coverage before more consumers adopt it.

Acceptance

  • commands_test.go exists with the above test cases
  • Tests pass with go test ./pkg/cli/ -run TestWithCommands
  • No test pollution (each test creates its own runtime)
## Problem `cli.WithCommands` is the core registration pattern for the entire fleet — every domain repo uses it to wire commands through the Core framework lifecycle. But there are no tests for it. The lifecycle path: 1. `cli.Main()` creates core services + command services 2. `cli.Init()` creates root cobra command, starts services 3. `commandService.OnStartup()` casts `Core.App` to `*cobra.Command` and calls the register function 4. Commands are now available on the root ## Proposal Add tests in `pkg/cli/commands_test.go`: - `TestWithCommands_RegistersOnStartup` — verify commands appear on root after startup - `TestWithCommands_MultipleGroups` — verify multiple `WithCommands` calls compose correctly - `TestWithCommands_GroupWithSubcommands` — verify nested group/subcommand registration - `TestWithCommands_ExecutesCommand` — verify a registered command's RunE is invoked ## Context LEM is the first external consumer. go-ml, go-devops, and go-ai will follow. This is the API contract that all domain repos depend on — it needs test coverage before more consumers adopt it. ## Acceptance - [ ] `commands_test.go` exists with the above test cases - [ ] Tests pass with `go test ./pkg/cli/ -run TestWithCommands` - [ ] No test pollution (each test creates its own runtime)
Author
Member

Completed by Charon in core/cli (e360115). CLI package now lives at forge.lthn.ai/core/cli/pkg/cli, not core/go/pkg/cli.

Completed by Charon in `core/cli` (e360115). CLI package now lives at `forge.lthn.ai/core/cli/pkg/cli`, not `core/go/pkg/cli`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: core/go#13
No description provided.