| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/pluginpkg" |
| 9 | ) |
| 10 | |
| 11 | func TestPluginInstallReturnsFailureExitForFailedJSON(t *testing.T) { |
| 12 | home := t.TempDir() |
| 13 | t.Setenv("REASONIX_HOME", home) |
| 14 | |
| 15 | source := filepath.Join(t.TempDir(), "superpowers") |
| 16 | writePluginTestFile(t, filepath.Join(source, pluginpkg.CodexManifest), `{ |
| 17 | "name": "superpowers", |
| 18 | "version": "6.1.1", |
| 19 | "description": "Planning workflows", |
| 20 | "skills": "skills" |
| 21 | }`) |
| 22 | writePluginTestFile(t, filepath.Join(source, "skills", "using-superpowers", "SKILL.md"), "---\ndescription: Use Superpowers\n---\nUse Superpowers.") |
| 23 | |
| 24 | firstOut := captureStdout(t, func() { |
| 25 | if rc := pluginCommand([]string{"install", source, "--yes"}); rc != 0 { |
| 26 | t.Fatalf("first plugin install rc = %d, want 0", rc) |
| 27 | } |
| 28 | }) |
| 29 | var first struct { |
| 30 | OK bool `json:"ok"` |
| 31 | } |
| 32 | if err := json.Unmarshal([]byte(firstOut), &first); err != nil { |
| 33 | t.Fatalf("first output is not JSON: %v\n%s", err, firstOut) |
| 34 | } |
| 35 | if !first.OK { |
| 36 | t.Fatalf("first output ok = false:\n%s", firstOut) |
| 37 | } |
| 38 | |
| 39 | secondOut := captureStdout(t, func() { |
| 40 | if rc := pluginCommand([]string{"install", source, "--yes"}); rc != 1 { |
| 41 | t.Fatalf("duplicate plugin install rc = %d, want 1", rc) |
| 42 | } |
| 43 | }) |
| 44 | var second struct { |
| 45 | OK bool `json:"ok"` |
| 46 | Status string `json:"status"` |
| 47 | } |
| 48 | if err := json.Unmarshal([]byte(secondOut), &second); err != nil { |
| 49 | t.Fatalf("second output is not JSON: %v\n%s", err, secondOut) |
| 50 | } |
| 51 | if second.OK || second.Status != "failed" { |
| 52 | t.Fatalf("duplicate output ok/status = %v/%q, want false/failed\n%s", second.OK, second.Status, secondOut) |
| 53 | } |
| 54 | } |
| 55 |