fix(ai_review): show actual model in cost line (was hardcoded glm-5.2:cloud)

The webhook pod now routes through headroom's MiniMax-M2.7 endpoint, but the
cost line in the AI-usage collapsible still read 'headroom glm-5.2:cloud'.
Resolve a single display_model at the top of review_pr (OPENCODE_MODEL env
wins, else headroom/{OLLAMA_MODEL}) and pass it to:
  * the opencode subprocess (was already doing this on the same line, now
    sharing the value)
  * format_review_body so REVIEW_HEADER also reflects the actual run
  * _render_collapsible_usage so the parenthetical reads
    '({display_model} — free tier)' or '({display_model} — billed)'.

Test additions in tests/pilot/test_ai_review.py cover:
  * the parenthetical picks up the passed-in model verbatim
  * the full provider prefix survives (headroom/<id>) for the opencode path
  * nonzero cost flips the inner clause from 'free tier' to 'billed'
  * the existing nonzero-cost assertion flips to assert 'billed' instead
    of dropping the parenthetical entirely
This commit is contained in:
Marcos
2026-08-22 14:41:56 +00:00
parent cdf116ece9
commit b6b8173ccb
2 changed files with 58 additions and 12 deletions
+36
View File
@@ -771,6 +771,39 @@ def test_render_collapsible_usage_cost_nonzero_drops_free_tier_note():
"cache_write": 0, "total": 10, "cost": 0.0123, "steps": 1, "duration_s": 1.0}
sec = _render_collapsible_usage(usage, "m", config=None)
assert "$0.0123" in sec
# Was hardcoded "free tier" previously; now says "billed" since cost > 0.
assert "billed" in sec
assert "free tier" not in sec
def test_render_collapsible_usage_uses_passed_model_for_free_tier_clause():
# Regression: the cost parenthetical must reflect the actually-routed model,
# not a stale hardcoded `headroom glm-5.2:cloud` literal that predates the
# MiniMax / Anthropic switch.
usage = {"input": 10, "output": 0, "reasoning": 0, "cache_read": 0,
"cache_write": 0, "total": 10, "cost": 0.0, "steps": 1, "duration_s": 1.0}
sec = _render_collapsible_usage(usage, "MiniMax-M2.7", config=None)
# The parenthetical clause is "(<model> — free tier)" — a model name MUST
# sit immediately before "— free tier".
assert "(MiniMax-M2.7 — free tier)" in sec
# And the stale hardcoded model name must no longer appear anywhere.
assert "glm-5.2:cloud" not in sec
def test_render_collapsible_usage_full_provider_prefix_in_display():
# When the caller has resolved a provider-prefixed model ref (the opencode
# subprocess path), the parenthetical should mirror that verbatim.
usage = {"input": 10, "output": 0, "reasoning": 0, "cache_read": 0,
"cache_write": 0, "total": 10, "cost": 0.0, "steps": 1, "duration_s": 1.0}
sec = _render_collapsible_usage(usage, "headroom/MiniMax-M2.7", config=None)
assert "(headroom/MiniMax-M2.7 — free tier)" in sec
def test_render_collapsible_usage_nonzero_cost_says_billed():
usage = {"input": 10, "output": 0, "reasoning": 0, "cache_read": 0,
"cache_write": 0, "total": 10, "cost": 0.123, "steps": 1, "duration_s": 1.0}
sec = _render_collapsible_usage(usage, "MiniMax-M2.7", config=None)
assert "(MiniMax-M2.7 — billed)" in sec
assert "free tier" not in sec
@@ -1082,7 +1115,10 @@ def test_usage_block_shows_equivalent_provider_cost():
assert "🔋 AI Usage & Run Details" in sec
assert "**Est. cost on Claude Sonnet 5**" in sec
assert "**Actual**: $0.00" in sec
# The "free tier" clause must mention the routed model verbatim, not the
# stale hardcoded `headroom glm-5.2:cloud` literal.
assert "free tier" in sec
assert "glm-5.2:cloud" in sec
# Equivalent should be > 0 for non-trivial token counts.
assert "$0.00" in sec # the actual line
# And a non-zero one for the equivalent.