@@ -97,6 +97,7 @@ func TestBuildSummaryAggregatesSignals(t *testing.T) {
9797 Event : schema.EventInfo {Action : "command.executed" , Category : "command" },
9898 Severity : schema .SeverityInfo ,
9999 Harness : schema.HarnessInfo {Name : "cursor" },
100+ Model : "gpt-5.5" ,
100101 Session : & schema.SessionInfo {ID : "s1" },
101102 Command : & schema.CommandInfo {Command : "go test ./..." },
102103 }},
@@ -105,6 +106,7 @@ func TestBuildSummaryAggregatesSignals(t *testing.T) {
105106 Event : schema.EventInfo {Action : "mcp.tool_invoked" , Category : "mcp" },
106107 Severity : schema .SeverityHigh ,
107108 Harness : schema.HarnessInfo {Name : "cursor" },
109+ Model : "claude-4-sonnet" ,
108110 Session : & schema.SessionInfo {ID : "s2" },
109111 MCP : & schema.MCPInfo {Server : "github" , Tool : "get_issue" },
110112 }, WazuhLevel : WazuhLevel ("mcp.tool_invoked" )},
@@ -137,6 +139,15 @@ func TestBuildSummaryAggregatesSignals(t *testing.T) {
137139 if summary .CountsByHarness ["cursor" ] != 4 {
138140 t .Fatalf ("cursor harness count = %d, want 4" , summary .CountsByHarness ["cursor" ])
139141 }
142+ if summary .CountsByModel ["gpt-5.5" ] != 1 || summary .CountsByModel ["claude-4-sonnet" ] != 1 {
143+ t .Fatalf ("model counts = %#v, want gpt-5.5 and claude-4-sonnet" , summary .CountsByModel )
144+ }
145+ if len (summary .TopHarnesses ) == 0 || summary .TopHarnesses [0 ].Name != "cursor" {
146+ t .Fatalf ("top harnesses = %#v, want cursor first" , summary .TopHarnesses )
147+ }
148+ if len (summary .TopModels ) != 2 {
149+ t .Fatalf ("top models = %#v, want 2 models" , summary .TopModels )
150+ }
140151 if summary .NeedsReviewEvents != 3 || summary .DeniedApprovalEvents != 1 || summary .PolicyBlockedEvents != 1 {
141152 t .Fatalf ("review counts = needs %d denied %d blocked %d, want 3/1/1" , summary .NeedsReviewEvents , summary .DeniedApprovalEvents , summary .PolicyBlockedEvents )
142153 }
@@ -217,6 +228,28 @@ func TestReadEventsSecurityFilters(t *testing.T) {
217228 }
218229}
219230
231+ func TestReadEventsFiltersByModel (t * testing.T ) {
232+ path := filepath .Join (t .TempDir (), "runtime.jsonl" )
233+ events := []schema.Event {
234+ testSchemaEvent ("2026-05-13T01:00:00Z" , "cursor" , "prompt.submitted" , "prompt" , "repo-a" ),
235+ testSchemaEvent ("2026-05-13T01:01:00Z" , "claude_code" , "prompt.submitted" , "prompt" , "repo-b" ),
236+ }
237+ events [0 ].Model = "claude-4-sonnet"
238+ events [1 ].Model = "gpt-5.5"
239+ writeTestLog (t , path , marshalEvents (t , events ... )... )
240+
241+ result , err := ReadEvents (path , EventQuery {Model : "sonnet" , Limit : 10 })
242+ if err != nil {
243+ t .Fatalf ("ReadEvents returned error: %v" , err )
244+ }
245+ if result .TotalMatched != 1 || result .Events [0 ].Event .Model != "claude-4-sonnet" {
246+ t .Fatalf ("matched %d model %q, want 1 claude-4-sonnet" , result .TotalMatched , result .Events [0 ].Event .Model )
247+ }
248+ if got := result .Filters ["model" ]; got != "sonnet" {
249+ t .Fatalf ("model filter = %q, want sonnet" , got )
250+ }
251+ }
252+
220253func TestFindEventCanReadOutsideTailWindow (t * testing.T ) {
221254 path := filepath .Join (t .TempDir (), "runtime.jsonl" )
222255 lines := make ([][]byte , 0 , maxEventLimit + 1 )
@@ -289,6 +322,32 @@ func TestHandlerEventsEndpoint(t *testing.T) {
289322 }
290323}
291324
325+ func TestHandlerEventsEndpointParsesModelFilter (t * testing.T ) {
326+ path := filepath .Join (t .TempDir (), "runtime.jsonl" )
327+ event := testSchemaEvent ("2026-05-13T01:00:00Z" , "cursor" , "prompt.submitted" , "prompt" , "repo-a" )
328+ event .Model = "gpt-5.5"
329+ writeTestLog (t , path , marshalEvents (t , event )... )
330+
331+ handler , err := Handler (Options {LogPath : path , UserMode : true })
332+ if err != nil {
333+ t .Fatalf ("Handler returned error: %v" , err )
334+ }
335+ req := httptest .NewRequest (http .MethodGet , "/api/events?model=gpt-5.5" , nil )
336+ rec := httptest .NewRecorder ()
337+ handler .ServeHTTP (rec , req )
338+
339+ if rec .Code != http .StatusOK {
340+ t .Fatalf ("status = %d, want 200; body=%s" , rec .Code , rec .Body .String ())
341+ }
342+ var result EventResult
343+ if err := json .Unmarshal (rec .Body .Bytes (), & result ); err != nil {
344+ t .Fatalf ("decode response: %v" , err )
345+ }
346+ if len (result .Events ) != 1 || result .Events [0 ].Event .Model != "gpt-5.5" {
347+ t .Fatalf ("events len/model = %d/%q, want 1/gpt-5.5" , len (result .Events ), result .Events [0 ].Event .Model )
348+ }
349+ }
350+
292351func TestValidateLoopbackAddr (t * testing.T ) {
293352 if err := ValidateLoopbackAddr ("127.0.0.1:8765" ); err != nil {
294353 t .Fatalf ("loopback address rejected: %v" , err )
0 commit comments