Coverage for tests / unit / utils / console / test_pre_execution_summary.py: 100%
32 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Unit tests for pre-execution summary AI rendering."""
3from __future__ import annotations
5from unittest.mock import patch
7import pytest
8from assertpy import assert_that
9from rich.console import Console
11from lintro.ai.config import AIConfig
12from lintro.utils.console.pre_execution_summary import print_pre_execution_summary
15def _render_summary(ai_config: AIConfig | None) -> str:
16 """Render the pre-execution summary and return plain text output."""
17 console = Console(record=True, force_terminal=False, width=160)
18 with patch(
19 "lintro.utils.console.pre_execution_summary.Console",
20 return_value=console,
21 ):
22 print_pre_execution_summary(
23 tools_to_run=["ruff"],
24 skipped_tools=[],
25 effective_auto_install=True,
26 is_container=False,
27 is_ci=False,
28 per_tool_auto_install=None,
29 ai_config=ai_config,
30 )
31 return console.export_text()
34def test_pre_execution_summary_shows_ai_when_disabled() -> None:
35 """AI row should still be displayed when AI features are disabled."""
36 output = _render_summary(
37 AIConfig(
38 enabled=False,
39 provider="openai", # type: ignore[arg-type] # Pydantic coerces str
40 max_parallel_calls=7,
41 ),
42 )
44 assert_that(output).contains("AI")
45 assert_that(output).contains("disabled")
46 # When disabled, config details should not be shown
47 assert_that(output).does_not_contain("provider: openai")
48 assert_that(output).does_not_contain("parallel: 7 workers")
51def test_pre_execution_summary_shows_ai_when_enabled(
52 monkeypatch: pytest.MonkeyPatch,
53) -> None:
54 """Enabled AI row should include healthy status and details."""
55 monkeypatch.setenv("ANTHROPIC_API_KEY", "test-key")
56 monkeypatch.setattr(
57 "lintro.ai.availability.is_provider_available",
58 lambda _provider: True,
59 )
61 output = _render_summary(
62 AIConfig(
63 enabled=True,
64 provider="anthropic", # type: ignore[arg-type] # Pydantic coerces str
65 max_parallel_calls=3,
66 ),
67 )
69 assert_that(output).contains("AI")
70 assert_that(output).contains("enabled")
71 assert_that(output).contains("provider: anthropic")
72 assert_that(output).contains("parallel: 3 workers")
73 assert_that(output).contains("safe-auto-apply: on")
74 assert_that(output).contains("verify-fixes: off")
77def test_pre_execution_summary_shows_ai_when_config_missing() -> None:
78 """AI row should still be shown when no AI config object is passed."""
79 output = _render_summary(ai_config=None)
81 assert_that(output).contains("AI")
82 assert_that(output).contains("disabled (no config)")