@@ -38,7 +38,7 @@ func (m *mockResultProvider) ToolCalls() map[string]int64 { return m.toolCall
3838func TestEmitRunResult_JSONNoFiles (t * testing.T ) {
3939 ag := & mockResultProvider {filesReviewed : 0 }
4040 got := captureStdout (t , func () {
41- err := emitRunResult (context .Background (), ag , nil , time .Now (), "json" , "developer" , nil )
41+ err := emitRunResult (context .Background (), ag , nil , time .Now (), "json" , "developer" , nil , nil )
4242 if err != nil {
4343 t .Fatalf ("unexpected error: %v" , err )
4444 }
@@ -63,7 +63,7 @@ func TestEmitRunResult_JSONWithComments(t *testing.T) {
6363 }
6464 comments := []model.LlmComment {{Path : "main.go" , Content : "fix" , StartLine : 1 , EndLine : 2 }}
6565 got := captureStdout (t , func () {
66- err := emitRunResult (context .Background (), ag , comments , time .Now (), "json" , "developer" , nil )
66+ err := emitRunResult (context .Background (), ag , comments , time .Now (), "json" , "developer" , nil , nil )
6767 if err != nil {
6868 t .Fatalf ("unexpected error: %v" , err )
6969 }
@@ -83,7 +83,7 @@ func TestEmitRunResult_JSONWithComments(t *testing.T) {
8383func TestEmitRunResult_TextNoComments (t * testing.T ) {
8484 ag := & mockResultProvider {filesReviewed : 2 }
8585 got := captureStdout (t , func () {
86- err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "developer" , nil )
86+ err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "developer" , nil , nil )
8787 if err != nil {
8888 t .Fatalf ("unexpected error: %v" , err )
8989 }
@@ -97,7 +97,7 @@ func TestEmitRunResult_TextWithComments(t *testing.T) {
9797 ag := & mockResultProvider {filesReviewed : 1 }
9898 comments := []model.LlmComment {{Path : "a.go" , Content : "rename" , StartLine : 5 , EndLine : 10 }}
9999 got := captureStdout (t , func () {
100- err := emitRunResult (context .Background (), ag , comments , time .Now (), "text" , "developer" , nil )
100+ err := emitRunResult (context .Background (), ag , comments , time .Now (), "text" , "developer" , nil , nil )
101101 if err != nil {
102102 t .Fatalf ("unexpected error: %v" , err )
103103 }
@@ -116,7 +116,7 @@ func TestEmitRunResult_TextWithProjectSummary(t *testing.T) {
116116 projectSummary : "All tests pass, code quality is good." ,
117117 }
118118 got := captureStdout (t , func () {
119- err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "developer" , nil )
119+ err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "developer" , nil , nil )
120120 if err != nil {
121121 t .Fatalf ("unexpected error: %v" , err )
122122 }
@@ -133,7 +133,7 @@ func TestEmitRunResult_AgentTextRestoresQuiet(t *testing.T) {
133133 ag := & mockResultProvider {filesReviewed : 1 }
134134 q := newQuietHandle ("text" , "agent" )
135135 got := captureStdout (t , func () {
136- err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "agent" , q )
136+ err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "agent" , q , nil )
137137 if err != nil {
138138 t .Fatalf ("unexpected error: %v" , err )
139139 }
@@ -153,7 +153,7 @@ func TestEmitRunResult_AgentJSONDoesNotRestore(t *testing.T) {
153153 }
154154 q := newQuietHandle ("json" , "agent" )
155155 got := captureStdout (t , func () {
156- err := emitRunResult (context .Background (), ag , nil , time .Now (), "json" , "agent" , q )
156+ err := emitRunResult (context .Background (), ag , nil , time .Now (), "json" , "agent" , q , nil )
157157 if err != nil {
158158 t .Fatalf ("unexpected error: %v" , err )
159159 }
@@ -168,10 +168,106 @@ func TestEmitRunResult_AgentJSONDoesNotRestore(t *testing.T) {
168168func TestEmitRunResult_NilQuietHandle (t * testing.T ) {
169169 ag := & mockResultProvider {filesReviewed : 1 }
170170 got := captureStdout (t , func () {
171- err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "agent" , nil )
171+ err := emitRunResult (context .Background (), ag , nil , time .Now (), "text" , "agent" , nil , nil )
172172 if err != nil {
173173 t .Fatalf ("unexpected error: %v" , err )
174174 }
175175 })
176176 _ = got
177177}
178+
179+ func TestEmitRunResult_FilteredNoMatchShowsMessage (t * testing.T ) {
180+ fc := parseFilterFlags ("low" , "" )
181+ ag := & mockResultProvider {filesReviewed : 1 }
182+ comments := []model.LlmComment {
183+ {Path : "a.go" , Severity : "high" , Category : "bug" , Content : "should be filtered out" },
184+ }
185+ got := captureStdout (t , func () {
186+ err := emitRunResult (context .Background (), ag , comments , time .Now (), "text" , "developer" , nil , fc )
187+ if err != nil {
188+ t .Fatalf ("unexpected error: %v" , err )
189+ }
190+ })
191+ if ! strings .Contains (got , "No comments generated. Looks good to me.\n " ) {
192+ t .Errorf ("expected 'No comments match', got %q" , got )
193+ }
194+ }
195+
196+ func TestEmitRunResult_SortedBySeverityAndCategory (t * testing.T ) {
197+ fc := parseFilterFlags ("" , "" )
198+ ag := & mockResultProvider {filesReviewed : 1 }
199+ comments := []model.LlmComment {
200+ {Path : "c.go" , Severity : "low" , Category : "bug" , Content : "low bug" , StartLine : 1 , EndLine : 2 },
201+ {Path : "a.go" , Severity : "high" , Category : "security" , Content : "high sec" , StartLine : 1 , EndLine : 2 },
202+ {Path : "b.go" , Severity : "medium" , Category : "bug" , Content : "mid bug" , StartLine : 1 , EndLine : 2 },
203+ }
204+ got := captureStdout (t , func () {
205+ err := emitRunResult (context .Background (), ag , comments , time .Now (), "text" , "developer" , nil , fc )
206+ if err != nil {
207+ t .Fatalf ("unexpected error: %v" , err )
208+ }
209+ })
210+ // a.go (high·security) should appear first, then b.go (medium·bug), then c.go (low·bug)
211+ aIdx := strings .Index (got , "a.go" )
212+ bIdx := strings .Index (got , "b.go" )
213+ cIdx := strings .Index (got , "c.go" )
214+ if aIdx < 0 || bIdx < 0 || cIdx < 0 {
215+ t .Fatal ("expected all three files in output" )
216+ }
217+ if ! (aIdx < bIdx && bIdx < cIdx ) {
218+ t .Errorf ("expected order a.go -> b.go -> c.go, got a=%d b=%d c=%d" , aIdx , bIdx , cIdx )
219+ }
220+ }
221+
222+ func TestEmitRunResult_FilteredWithCountHint (t * testing.T ) {
223+ fc := parseFilterFlags ("high" , "" )
224+ ag := & mockResultProvider {filesReviewed : 1 }
225+ comments := []model.LlmComment {
226+ {Path : "a.go" , Severity : "high" , Category : "bug" , Content : "keep" },
227+ {Path : "b.go" , Severity : "medium" , Category : "style" , Content : "hidden" },
228+ {Path : "c.go" , Severity : "low" , Category : "docs" , Content : "hidden" },
229+ }
230+ got := captureStdout (t , func () {
231+ err := emitRunResult (context .Background (), ag , comments , time .Now (), "text" , "developer" , nil , fc )
232+ if err != nil {
233+ t .Fatalf ("unexpected error: %v" , err )
234+ }
235+ })
236+ if ! strings .Contains (got , "a.go" ) {
237+ t .Errorf ("expected a.go in output, got %q" , got )
238+ }
239+ if strings .Contains (got , "b.go" ) || strings .Contains (got , "c.go" ) {
240+ t .Errorf ("did not expect filtered-out files in output, got %q" , got )
241+ }
242+ }
243+
244+ func TestEmitRunResult_JSONFilteredByLevel (t * testing.T ) {
245+ fc := parseFilterFlags ("high" , "" )
246+ ag := & mockResultProvider {
247+ filesReviewed : 2 ,
248+ inputTokens : 100 ,
249+ outputTokens : 50 ,
250+ totalTokens : 150 ,
251+ toolCalls : map [string ]int64 {"file_read" : 1 },
252+ }
253+ comments := []model.LlmComment {
254+ {Path : "a.go" , Severity : "high" , Category : "bug" , Content : "keep" },
255+ {Path : "b.go" , Severity : "medium" , Category : "style" , Content : "hidden" },
256+ }
257+ got := captureStdout (t , func () {
258+ err := emitRunResult (context .Background (), ag , comments , time .Now (), "json" , "developer" , nil , fc )
259+ if err != nil {
260+ t .Fatalf ("unexpected error: %v" , err )
261+ }
262+ })
263+ var out jsonOutput
264+ if err := json .Unmarshal ([]byte (got ), & out ); err != nil {
265+ t .Fatalf ("unmarshal: %v" , err )
266+ }
267+ if len (out .Comments ) != 1 {
268+ t .Errorf ("expected 1 comment after filter, got %d" , len (out .Comments ))
269+ }
270+ if out .Comments [0 ].Path != "a.go" {
271+ t .Errorf ("expected a.go, got %s" , out .Comments [0 ].Path )
272+ }
273+ }
0 commit comments