Files
openclaw/apps/macos/Tests/OpenClawIPCTests/RootCommandParserTests.swift
Marko Milosevic b9e193ce22 test(macos): cover root command dispatch (#93705)
* test(macos): cover root command dispatch

* chore(macos): format root command coverage

---------

Co-authored-by: markoub <2418548+markoub@users.noreply.github.com>
Co-authored-by: Vincent Koc <25068+vincentkoc@users.noreply.github.com>
2026-06-17 02:36:33 +08:00

39 lines
1.5 KiB
Swift

import Testing
@testable import OpenClawMacCLI
struct RootCommandParserTests {
@Test func `parse root command returns nil for empty args`() {
#expect(parseRootCommand([]) == nil)
}
@Test func `parse root command splits command name and args`() throws {
let command = try #require(parseRootCommand(["connect", "--json", "--timeout", "3000"]))
#expect(command.name == "connect")
#expect(command.args == ["--json", "--timeout", "3000"])
}
@Test func `help aliases resolve to usage`() {
for args in [[], ["-h"], ["--help"], ["help"]] {
#expect(resolveRootCommandAction(args) == .usage)
}
}
@Test func `known commands preserve trailing args`() {
#expect(resolveRootCommandAction(["connect", "--json"]) == .connect(["--json"]))
#expect(
resolveRootCommandAction(["configure-remote", "--ssh-target", "alice@example.com"])
== .configureRemote(["--ssh-target", "alice@example.com"]))
#expect(resolveRootCommandAction(["discover", "--include-local"]) == .discover(["--include-local"]))
#expect(resolveRootCommandAction(["wizard", "--mode", "local"]) == .wizard(["--mode", "local"]))
}
@Test func `unknown command resolves to nonzero exit action`() {
#expect(resolveRootCommandAction(["nope"]) == .unknown(exitCode: 1))
}
@Test func `command names remain case sensitive`() {
#expect(resolveRootCommandAction(["Connect"]) == .unknown(exitCode: 1))
}
}