feat(ai_review): render humanized token counts in usage + inline
This commit is contained in:
@@ -335,7 +335,7 @@ def test_inline_comment_body_with_token_attribution():
|
||||
"fix": "f", "suggestion": "", "reference": "",
|
||||
"_tok_attrib": 1234, "_tok_pct": 0.30}
|
||||
body = inline_comment_body(f)
|
||||
assert "🪙 ~1234 tok" in body
|
||||
assert "🪙 ~1,234 (1.2K) tok" in body
|
||||
assert "30%" in body
|
||||
assert "attributed output" in body
|
||||
|
||||
@@ -757,7 +757,7 @@ def test_render_collapsible_usage_renders_totals():
|
||||
assert "`glm-5.2:cloud`" in sec
|
||||
assert "7 steps" in sec
|
||||
assert "142.0s" in sec
|
||||
assert "18420 in / 612 out" in sec and "19032 total" in sec
|
||||
assert "18,420 (18.4K) in / 612 out" in sec and "19,032 (19.0K) total" in sec
|
||||
assert "$0.00" in sec
|
||||
assert "Whole-repo checkout" in sec
|
||||
assert "attributed" in sec
|
||||
@@ -824,7 +824,7 @@ def test_render_collapsible_usage_contains_details():
|
||||
assert "<summary>🔋 AI Usage & Run Details</summary>" in block
|
||||
assert "</details>" in block
|
||||
assert "glm-5.2:cloud" in block
|
||||
assert "1000 in / 200 out" in block
|
||||
assert "1,000 (1.0K) in / 200 out" in block
|
||||
|
||||
|
||||
def test_render_collapsible_usage_empty_when_no_usage():
|
||||
@@ -1668,3 +1668,27 @@ def test_fmt_tokens_none():
|
||||
def test_fmt_tokens_negative():
|
||||
assert fmt_tokens(-1) == "?"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# fmt_tokens — applied in usage + inline comment bodies (Task 3)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_collapsible_usage_renders_humanized_tokens():
|
||||
usage = {"input": 2_071_025, "output": 17303, "reasoning": 0,
|
||||
"cache_read": 0, "cache_write": 0, "total": 2_088_328,
|
||||
"cost": 0.0, "steps": 1, "duration_s": 10.0}
|
||||
block = _render_collapsible_usage(usage, "glm-5.2:cloud", config={})
|
||||
assert "2,071,025 (2.1M) in" in block
|
||||
assert "17,303 (17.3K) out" in block
|
||||
|
||||
|
||||
def test_inline_comment_body_humanized_tokens():
|
||||
# Value chosen > 1000 so fmt_tokens actually adds the comma + short suffix;
|
||||
# the plan's 362 would render identically with or without fmt_tokens.
|
||||
f = {"severity": "medium", "path": "x.py", "line": 1,
|
||||
"problem": "p", "fix": "", "suggestion": "", "reference": "",
|
||||
"_tok_attrib": 17303, "_tok_pct": 0.11}
|
||||
body = inline_comment_body(f)
|
||||
assert "🪙 ~17,303 (17.3K) tok" in body
|
||||
|
||||
|
||||
Reference in New Issue
Block a user