Skip to content

Add unit tests for Formatter metrics#12

Merged
ArtyomVancyan merged 2 commits intomainfrom
copilot/sub-pr-10-again
Mar 2, 2026
Merged

Add unit tests for Formatter metrics#12
ArtyomVancyan merged 2 commits intomainfrom
copilot/sub-pr-10-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Formatter.metrics() introduced in the parent PR had no test coverage for latency formatting, token extraction, or cost calculation, leaving those code paths unprotected against regressions.

Changes

  • make_metrics_run helper — lightweight MagicMock factory that accepts extra, outputs, and a latency float to simulate start_time/end_time differences
  • TestLatency — covers all three branches: sub-second (ms), seconds+ms, and minutes+seconds
  • TestCosts — covers unknown model fallback, zero-token short-circuit, and non-zero token cost computation against a real model entry (openai/gpt-4o-mini)
  • TestMetrics — covers token extraction, latency field formatting, cost lookup for a known model, and unknown-model cost fallback

All new tests follow existing conventions (no inline comments, class-per-feature, descriptive snake_case names).

class TestMetrics:
    def test_cost_for_known_model(self):
        run = make_metrics_run(
            extra={"ls_model_name": "openai/gpt-4o-mini"},
            outputs={"total_tokens": 2000, "cached_tokens": 1000},
        )
        result = Formatter.metrics(run)
        assert result["costs"] == {"cached": "0.000075", "total": "0.0012"}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: ArtyomVancyan <44609997+ArtyomVancyan@users.noreply.github.com>
Base automatically changed from cost-and-latency-tracking to main March 2, 2026 22:23
Copilot AI changed the title [WIP] Update cost and latency tracking implementation based on feedback Add unit tests for Formatter.metrics(), latency(), and costs() Mar 2, 2026
@ArtyomVancyan ArtyomVancyan marked this pull request as ready for review March 2, 2026 22:27
@ArtyomVancyan ArtyomVancyan changed the title Add unit tests for Formatter.metrics(), latency(), and costs() Add unit tests for Formatter metrics Mar 2, 2026
@ArtyomVancyan ArtyomVancyan merged commit 5e49250 into main Mar 2, 2026
@ArtyomVancyan ArtyomVancyan deleted the copilot/sub-pr-10-again branch March 2, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants