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

Function TestArgvToInnerJSON_Flags

cli/plugins/argv_flags_test.go:14–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestArgvToInnerJSON_Flags(t *testing.T) {
15 // Mirrors what the agent emits for {cmd:create, args:{name, triggers:[...]}}.
16 argv := []string{"--name", "deploy-x", "--description", "How to deploy", "--triggers", "deploy x", "--triggers", "ship x", "--allowed_tools", "@coder"}
17 pos, inner := argvToInnerJSON(argv, map[string]bool{"triggers": true, "allowed_tools": true}, nil)
18 if pos != "" {
19 t.Fatalf("unexpected positional %q", pos)
20 }
21 var m map[string]interface{}
22 if err := json.Unmarshal([]byte(inner), &m); err != nil {
23 t.Fatal(err)
24 }
25 if m["name"] != "deploy-x" || m["description"] != "How to deploy" {
26 t.Fatalf("scalars wrong: %v", m)
27 }
28 tr, _ := json.Marshal(m["triggers"])
29 if string(tr) != `["deploy x","ship x"]` {
30 t.Fatalf("triggers wrong: %s", tr)
31 }
32 // single value of an array key still becomes an array
33 at, _ := json.Marshal(m["allowed_tools"])
34 if string(at) != `["@coder"]` {
35 t.Fatalf("allowed_tools should be array: %s", at)
36 }
37}
38
39func TestArgvToInnerJSON_BareFlagAndPositional(t *testing.T) {
40 pos, inner := argvToInnerJSON([]string{"deploy-x"}, nil, nil)

Callers

nothing calls this directly

Calls 1

argvToInnerJSONFunction · 0.85

Tested by

no test coverage detected