Skip to content

No tests cover parseRootCommand or the command-dispatch switch in main() #83879

Description

@davinci282828

Severity: medium / Confidence: high / Category: test-gap
Triage: test-gap
Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18)
Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol

Evidence

  • apps/macos/Sources/OpenClawMacCLI/EntryPoint.swift:11-28 (OpenClawMacCLI.main)
switch command?.name {
case nil:
    printUsage()
case "-h", "--help", "help":
    printUsage()
case "connect":
    await runConnect(command?.args ?? [])
...
  • apps/macos/Sources/OpenClawMacCLI/EntryPoint.swift:32-36 (parseRootCommand)
private func parseRootCommand(_ args: [String]) -> RootCommand? {
    guard let first = args.first else { return nil }
    return RootCommand(name: first, args: Array(args.dropFirst()))
}

Reasoning

The five supplied test files target AgentEventStore, AgentWorkspace, AnyCodable, AppState, and AudioInputDeviceObserver — none touch the CLI entrypoint. parseRootCommand and the switch command?.name dispatch in main() are completely untested. Uncovered behaviors include: (1) zero-argument invocation returning nil and printing usage; (2) unknown command correctly printing usage and calling exit(1); (3) args.dropFirst() correctly splitting subcommand arguments; (4) case sensitivity — Connect vs connect falls through to the default branch and exits with error, which may surprise users. The exit(1) path is the only explicit non-zero exit in the file, so regressions in the dispatch table would be invisible.

Recommendation

Extract parseRootCommand to a separate, independently testable file and add unit tests covering: empty args → nil, single-word command with no further args, multi-word command splitting, unknown command, and each help alias. For the dispatch table, add a test that exercises the exit path for an unknown command and verifies the exit code is 1.

Why existing tests miss this

There is no test file for EntryPoint.swift or OpenClawMacCLI. The adjacent test suite (OpenClawIPCTests) targets IPC and app-state components, not the CLI dispatch layer.

Suggested regression test

struct ParseRootCommandTests { @test func nil when no args() { #expect(parseRootCommand([]) == nil) } @test func splits subcommand and args() { let cmd = parseRootCommand(["connect", "--json"]); #expect(cmd?.name == "connect"); #expect(cmd?.args == ["--json"]) } @test func unknown command exits non-zero() { ... spawn process with unknown subcommand, assert exit code == 1 } }

Minimum fix scope

Move parseRootCommand to a non-private function (or internal module function) so it is accessible from tests, and add a new OpenClawMacCLITests.swift test file covering the cases above.


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-035db88068-_5c2e6185ed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions