MCPcopy Create free account
hub / github.com/diillson/chatcli / TestCommandRoutingCoverage

Function TestCommandRoutingCoverage

cli/command_handler_routing_test.go:9–49  ·  view source on GitHub ↗

TestCommandRoutingCoverage guards the table-driven dispatcher: every known command must resolve to a handler, and non-commands must fall through to the default (chat/skill) path. It exercises lookup only (no handler is invoked), so it needs no live ChatCLI.

(t *testing.T)

Source from the content-addressed store, hash-verified

7// default (chat/skill) path. It exercises lookup only (no handler is invoked),
8// so it needs no live ChatCLI.
9func TestCommandRoutingCoverage(t *testing.T) {
10 ch := NewCommandHandler(&ChatCLI{})
11
12 // Commands resolved by the dispatch table (lookup). The mode-switch
13 // commands (/agent, /run, /coder, /plan) and /reload are handled
14 // separately in HandleCommand's switch — so they are not in the table and
15 // are asserted below.
16 known := []string{
17 "/exit", "exit", "/quit", "quit", "/help",
18 "/nextchunk", "/retry", "/retryall", "/skipchunk",
19 "/newsession", "/disconnect", "/rewind", "/metrics", "/cost",
20 "/reset", "/redraw", "/clear", "/switch openai",
21 "/config", "/config providers", "/status", "/settings",
22 "/session list", "/context show", "/auth login", "/plugin list",
23 "/skill list", "/connect host", "/watch x", "/compact", "/memory",
24 "/mcp", "/hooks", "/ratelimit", "/limits", "/export", "/export f.jsonl",
25 "/moa hi", "/thinking", "/refine", "/verify", "/reflect",
26 "/worktree", "/schedule x", "/wait x", "/jobs", "/parked", "/resume x",
27 "/cancel-park", "/channel", "/websearch x",
28 }
29 for _, in := range known {
30 if _, ok := ch.lookup(in); !ok {
31 t.Errorf("expected a route for %q", in)
32 }
33 }
34
35 // Mode-switch commands, /reload and /version|/v are intentionally NOT in
36 // the table (handled by HandleCommand's switch so the per-command ctx flows).
37 for _, in := range []string{"/agent", "/run task", "/coder fix", "/plan x", "/reload", "/version", "/v"} {
38 if _, ok := ch.lookup(in); ok {
39 t.Errorf("%q should be handled by HandleCommand's switch, not the table", in)
40 }
41 }
42
43 notCommands := []string{"/totallyunknown", "hello world", "/exporting", "/moax", "just text"}
44 for _, in := range notCommands {
45 if _, ok := ch.lookup(in); ok {
46 t.Errorf("did not expect a route for %q", in)
47 }
48 }
49}
50
51func TestPrefixRouteMatches(t *testing.T) {
52 word := prefixRoute{prefix: "/export", word: true}

Callers

nothing calls this directly

Calls 3

lookupMethod · 0.95
NewCommandHandlerFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected