(t *testing.T)
| 428 | } |
| 429 | |
| 430 | func TestComputeMCPToolsDiff_ChangedTools(t *testing.T) { |
| 431 | run1 := &MCPToolUsageData{ |
| 432 | Summary: []MCPToolSummary{ |
| 433 | {ServerName: "github", ToolName: "issue_read", CallCount: 5, ErrorCount: 0}, |
| 434 | {ServerName: "github", ToolName: "create_pr", CallCount: 2, ErrorCount: 1}, |
| 435 | }, |
| 436 | } |
| 437 | run2 := &MCPToolUsageData{ |
| 438 | Summary: []MCPToolSummary{ |
| 439 | {ServerName: "github", ToolName: "issue_read", CallCount: 10, ErrorCount: 0}, |
| 440 | {ServerName: "github", ToolName: "create_pr", CallCount: 2, ErrorCount: 3}, |
| 441 | }, |
| 442 | } |
| 443 | |
| 444 | diff := computeMCPToolsDiff(run1, run2) |
| 445 | |
| 446 | assert.Len(t, diff.ChangedTools, 2, "Should have 2 changed tools") |
| 447 | |
| 448 | issueRead := findMCPToolDiffEntry(diff.ChangedTools, "github", "issue_read") |
| 449 | require.NotNil(t, issueRead, "Should find issue_read in changed tools") |
| 450 | assert.Equal(t, "changed", issueRead.Status, "Status should be 'changed'") |
| 451 | assert.Equal(t, 5, issueRead.Run1CallCount, "Run1 call count should be 5") |
| 452 | assert.Equal(t, 10, issueRead.Run2CallCount, "Run2 call count should be 10") |
| 453 | assert.Equal(t, "+5", issueRead.CallCountChange, "Call count change should be +5") |
| 454 | assert.False(t, issueRead.IsAnomaly, "No error increase should not be anomaly") |
| 455 | |
| 456 | createPR := findMCPToolDiffEntry(diff.ChangedTools, "github", "create_pr") |
| 457 | require.NotNil(t, createPR, "Should find create_pr in changed tools") |
| 458 | assert.True(t, createPR.IsAnomaly, "Increased error count should be anomaly") |
| 459 | assert.Equal(t, "error count increased", createPR.AnomalyNote, "Anomaly note should explain error increase") |
| 460 | assert.Equal(t, 1, createPR.Run1ErrorCount, "Run1 error count should be 1") |
| 461 | assert.Equal(t, 3, createPR.Run2ErrorCount, "Run2 error count should be 3") |
| 462 | |
| 463 | assert.Equal(t, 2, diff.Summary.ChangedToolCount, "Summary should show 2 changed tools") |
| 464 | assert.True(t, diff.Summary.HasAnomalies, "Should have anomalies") |
| 465 | assert.Equal(t, 1, diff.Summary.AnomalyCount, "Should have 1 anomaly") |
| 466 | } |
| 467 | |
| 468 | func TestComputeMCPToolsDiff_BothNil(t *testing.T) { |
| 469 | diff := computeMCPToolsDiff(nil, nil) |
nothing calls this directly
no test coverage detected