(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestBlastRadiusSubcommandMarkdownAndJSON(t *testing.T) { |
| 81 | if _, err := exec.LookPath("git"); err != nil { |
| 82 | t.Skip("git not available") |
| 83 | } |
| 84 | if !scanner.NewAstGrepAnalyzer().Available() { |
| 85 | t.Skip("ast-grep not available") |
| 86 | } |
| 87 | |
| 88 | root := makeBlastRadiusGitRepo(t) |
| 89 | |
| 90 | markdown, stderr, err := runCodemapWithInput("", "blast-radius", "--ref", "HEAD", root) |
| 91 | if err != nil { |
| 92 | t.Fatalf("blast-radius markdown failed: %v\nstderr=%s", err, stderr) |
| 93 | } |
| 94 | for _, check := range []string{ |
| 95 | "# Codemap Blast Radius", |
| 96 | "## Affected Outside Diff", |
| 97 | "## Impact Snippets", |
| 98 | "`internal/service/service.go` via `pkg/math/math.go`", |
| 99 | "ComputeTotal", |
| 100 | } { |
| 101 | if !strings.Contains(markdown, check) { |
| 102 | t.Fatalf("expected %q in markdown output, got:\n%s", check, markdown) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | jsonOut, stderr, err := runCodemapWithInput("", "blast-radius", "--json", "--ref", "HEAD", root) |
| 107 | if err != nil { |
| 108 | t.Fatalf("blast-radius json failed: %v\nstderr=%s", err, stderr) |
| 109 | } |
| 110 | var bundle blastRadiusBundle |
| 111 | if err := json.Unmarshal([]byte(jsonOut), &bundle); err != nil { |
| 112 | t.Fatalf("expected blast-radius JSON output, got error %v with body:\n%s", err, jsonOut) |
| 113 | } |
| 114 | if bundle.Ref != "HEAD" { |
| 115 | t.Fatalf("bundle ref = %q, want HEAD", bundle.Ref) |
| 116 | } |
| 117 | if bundle.Summary.ChangedFiles != 1 || bundle.Summary.ChangedFilesTotal != 1 { |
| 118 | t.Fatalf("unexpected changed-file summary: %+v", bundle.Summary) |
| 119 | } |
| 120 | if bundle.Summary.ImpactedOutsideDiffShown == 0 { |
| 121 | t.Fatalf("expected impacted files outside diff, got %+v", bundle.Summary) |
| 122 | } |
| 123 | if len(bundle.Snippets) == 0 { |
| 124 | t.Fatalf("expected at least one impact snippet, got %+v", bundle) |
| 125 | } |
| 126 | if bundle.Snippets[0].MatchedTerm != "ComputeTotal" { |
| 127 | t.Fatalf("expected snippet match to target ComputeTotal, got %+v", bundle.Snippets[0]) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func TestBlastRadiusSubcommandNoChanges(t *testing.T) { |
| 132 | if _, err := exec.LookPath("git"); err != nil { |
nothing calls this directly
no test coverage detected