| 104 | } |
| 105 | |
| 106 | func TestHelpCmd_FormatJSONEmits(t *testing.T) { |
| 107 | // TASK-934 replaced the stub with a real emitter. Verify --format json |
| 108 | // produces a parseable cmdhelp document with the expected envelope. |
| 109 | out, _, err := runHelp(t, "--format", "json") |
| 110 | if err != nil { |
| 111 | t.Fatalf("--format json: unexpected error: %v\nstdout:\n%s", err, out) |
| 112 | } |
| 113 | var doc map[string]interface{} |
| 114 | if uerr := json.Unmarshal([]byte(out), &doc); uerr != nil { |
| 115 | t.Fatalf("--format json output is not valid JSON: %v\n%s", uerr, out) |
| 116 | } |
| 117 | if doc["cmdhelp_version"] != "0.1" { |
| 118 | t.Errorf("cmdhelp_version = %v, want 0.1", doc["cmdhelp_version"]) |
| 119 | } |
| 120 | if _, ok := doc["binary"]; !ok { |
| 121 | t.Errorf("emitted JSON missing required key 'binary'") |
| 122 | } |
| 123 | cmds, ok := doc["commands"].(map[string]interface{}) |
| 124 | if !ok { |
| 125 | t.Fatalf("emitted JSON missing required key 'commands' or wrong type: %T", doc["commands"]) |
| 126 | } |
| 127 | for _, want := range []string{"item", "item create", "project", "project dashboard"} { |
| 128 | if _, ok := cmds[want]; !ok { |
| 129 | t.Errorf("expected command %q in emitted commands map", want) |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func TestHelpCmd_FormatMarkdownEmits(t *testing.T) { |
| 135 | // TASK-935 replaced the stub with a real emitter. Assert structural |