|
| 1 | +"""Smoke tests — verify the package imports and CLI entry point work.""" |
| 2 | + |
| 3 | +import json |
| 4 | +from pathlib import Path |
| 5 | +from click.testing import CliRunner |
| 6 | +from context_profiler.cli import main |
| 7 | + |
| 8 | +FIXTURES = Path(__file__).parent / "fixtures" |
| 9 | + |
| 10 | + |
| 11 | +def test_import(): |
| 12 | + import context_profiler |
| 13 | + assert hasattr(context_profiler, "__version__") |
| 14 | + |
| 15 | + |
| 16 | +def test_cli_help(): |
| 17 | + runner = CliRunner() |
| 18 | + result = runner.invoke(main, ["--help"]) |
| 19 | + assert result.exit_code == 0 |
| 20 | + assert "context-profiler" in result.output |
| 21 | + |
| 22 | + |
| 23 | +def test_analyze_snapshot(tmp_path): |
| 24 | + snapshot = FIXTURES / "repeated_tool_calls.json" |
| 25 | + runner = CliRunner() |
| 26 | + result = runner.invoke(main, ["analyze", str(snapshot)]) |
| 27 | + assert result.exit_code == 0 |
| 28 | + assert "Token Distribution" in result.output |
| 29 | + |
| 30 | + |
| 31 | +def test_analyze_json_output(tmp_path): |
| 32 | + snapshot = FIXTURES / "repeated_tool_calls.json" |
| 33 | + out = tmp_path / "report.json" |
| 34 | + runner = CliRunner() |
| 35 | + result = runner.invoke(main, ["analyze", str(snapshot), "-o", str(out)]) |
| 36 | + assert result.exit_code == 0 |
| 37 | + assert out.exists() |
| 38 | + data = json.loads(out.read_text()) |
| 39 | + assert "analyzers" in data |
| 40 | + |
| 41 | + |
| 42 | +def test_analyze_html_output(tmp_path): |
| 43 | + snapshot = FIXTURES / "repeated_tool_calls.json" |
| 44 | + out = tmp_path / "report.html" |
| 45 | + runner = CliRunner() |
| 46 | + result = runner.invoke(main, ["analyze", str(snapshot), "--html", str(out)]) |
| 47 | + assert result.exit_code == 0 |
| 48 | + assert out.exists() |
| 49 | + assert "<html" in out.read_text().lower() |
0 commit comments