openclaw - 💡(How to fix) Fix No tests cover parseRootCommand or the command-dispatch switch in main() [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#83879Fetched 2026-05-20 03:47:46
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
1
Timeline (top)
labeled ×5commented ×1mentioned ×1subscribed ×1

Error Message

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.

Fix Action

Fix / Workaround

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

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.

Code Example

switch command?.name {
case nil:
    printUsage()
case "-h", "--help", "help":
    printUsage()
case "connect":
    await runConnect(command?.args ?? [])
...

---

private func parseRootCommand(_ args: [String]) -> RootCommand? {
    guard let first = args.first else { return nil }
    return RootCommand(name: first, args: Array(args.dropFirst()))
}
RAW_BUFFERClick to expand / collapse

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix No tests cover parseRootCommand or the command-dispatch switch in main() [1 comments, 2 participants]