Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ctxlens/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _load(path, fmt, tokenizer, top, tool_result_cap, tool_def_budget):


def _maybe_fail(ratio: float, threshold: float | None):
if threshold is not None and ratio > threshold:
if threshold is not None and ratio >= threshold:
err_console.print(
f"[red]waste ratio {ratio * 100:.1f}% exceeds threshold {threshold * 100:.1f}%[/red]"
)
Expand Down
15 changes: 14 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import json

import pytest
import typer
from typer.testing import CliRunner

from ctxlens.cli import app
from ctxlens.cli import EXIT_THRESHOLD, _maybe_fail, app

runner = CliRunner()

Expand Down Expand Up @@ -49,6 +51,17 @@ def test_analyze_fail_over_threshold_ok(claude_jsonl):
assert result.exit_code == 0


def test_maybe_fail_exact_threshold():
with pytest.raises(typer.Exit) as exc_info:
_maybe_fail(0.5, 0.5)
assert exc_info.value.exit_code == EXIT_THRESHOLD


def test_maybe_fail_below_threshold():
_maybe_fail(0.4, 0.5)
_maybe_fail(0.5, None)


def test_report_html_to_file(tmp_path, codex_session):
out = tmp_path / "r.html"
result = runner.invoke(app, ["report", str(codex_session), "--html", "-o", str(out)])
Expand Down
Loading