(t *testing.T)
| 553 | } |
| 554 | |
| 555 | func TestGeneratePerformanceMetrics(t *testing.T) { |
| 556 | tests := []struct { |
| 557 | name string |
| 558 | processedRun ProcessedRun |
| 559 | metrics MetricsData |
| 560 | toolUsage []ToolUsageInfo |
| 561 | checkMetrics func(t *testing.T, pm *PerformanceMetrics) |
| 562 | }{ |
| 563 | { |
| 564 | name: "tokens per minute calculation", |
| 565 | processedRun: func() ProcessedRun { |
| 566 | pr := createTestProcessedRun() |
| 567 | pr.Run.Duration = 2 * time.Minute |
| 568 | return pr |
| 569 | }(), |
| 570 | metrics: MetricsData{ |
| 571 | TokenUsage: 1000, |
| 572 | }, |
| 573 | toolUsage: []ToolUsageInfo{}, |
| 574 | checkMetrics: func(t *testing.T, pm *PerformanceMetrics) { |
| 575 | assert.InDelta(t, 500.0, pm.TokensPerMinute, 0.01, |
| 576 | "Tokens per minute should be 1000 tokens / 2 minutes = 500") |
| 577 | }, |
| 578 | }, |
| 579 | { |
| 580 | name: "most used tool", |
| 581 | processedRun: createTestProcessedRun(), |
| 582 | metrics: MetricsData{}, |
| 583 | toolUsage: []ToolUsageInfo{ |
| 584 | {Name: "bash", CallCount: 5}, |
| 585 | {Name: "github_issue_read", CallCount: 10}, |
| 586 | {Name: "file_edit", CallCount: 3}, |
| 587 | }, |
| 588 | checkMetrics: func(t *testing.T, pm *PerformanceMetrics) { |
| 589 | assert.Contains(t, pm.MostUsedTool, "github_issue_read", |
| 590 | "Most used tool should be github_issue_read") |
| 591 | assert.Contains(t, pm.MostUsedTool, "10 calls", |
| 592 | "Most used tool should show 10 calls") |
| 593 | }, |
| 594 | }, |
| 595 | { |
| 596 | name: "average tool duration", |
| 597 | processedRun: createTestProcessedRun(), |
| 598 | metrics: MetricsData{}, |
| 599 | toolUsage: []ToolUsageInfo{ |
| 600 | {Name: "bash", CallCount: 5, MaxDuration: "1s"}, |
| 601 | {Name: "github_issue_read", CallCount: 10, MaxDuration: "3s"}, |
| 602 | }, |
| 603 | checkMetrics: func(t *testing.T, pm *PerformanceMetrics) { |
| 604 | assert.NotEmpty(t, pm.AvgToolDuration, |
| 605 | "Average tool duration should be calculated") |
| 606 | }, |
| 607 | }, |
| 608 | { |
| 609 | name: "network requests from firewall", |
| 610 | processedRun: func() ProcessedRun { |
| 611 | pr := createTestProcessedRun() |
| 612 | pr.FirewallAnalysis = &FirewallAnalysis{ |
nothing calls this directly
no test coverage detected