(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | |
| 39 | func TestArgvToInnerJSON_BareFlagAndPositional(t *testing.T) { |
| 40 | pos, inner := argvToInnerJSON([]string{"deploy-x"}, nil, nil) |
nothing calls this directly
no test coverage detected