Skip to content

Commit 11bb571

Browse files
coder999999999vincentkoc
authored andcommitted
test(model-usage): cover pick_current_model and latest_day_cost coercion
1 parent 7ea9e67 commit 11bb571

1 file changed

Lines changed: 60 additions & 1 deletion

File tree

skills/model-usage/scripts/test_model_usage.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
from datetime import date, timedelta
88
from unittest import TestCase, main
99

10-
from model_usage import aggregate_costs, coerce_finite_cost, filter_by_days, positive_int
10+
from model_usage import (
11+
aggregate_costs,
12+
coerce_finite_cost,
13+
filter_by_days,
14+
latest_day_cost,
15+
pick_current_model,
16+
positive_int,
17+
)
1118

1219

1320
class TestModelUsage(TestCase):
@@ -88,6 +95,58 @@ def test_aggregate_costs_ignores_bool_and_non_finite(self):
8895
# NaN/Infinity must not poison the total; bool must not add 1.0.
8996
self.assertEqual(totals, {"claude-sonnet-4-6": 3.25})
9097

98+
def test_pick_current_model_scores_numeric_string_costs(self):
99+
# model-b's cost is a numeric string; it must still win on highest cost.
100+
entries = [
101+
{
102+
"date": "2026-05-25",
103+
"modelBreakdowns": [
104+
{"modelName": "model-a", "cost": 1.0},
105+
{"modelName": "model-b", "cost": "5.0"},
106+
],
107+
}
108+
]
109+
model, day = pick_current_model(entries)
110+
self.assertEqual(model, "model-b")
111+
self.assertEqual(day, "2026-05-25")
112+
113+
def test_pick_current_model_ignores_bool_and_non_finite(self):
114+
# Only model-a has a usable cost; bool and NaN must not be scored.
115+
entries = [
116+
{
117+
"date": "2026-05-25",
118+
"modelBreakdowns": [
119+
{"modelName": "model-a", "cost": 2.0},
120+
{"modelName": "model-b", "cost": True},
121+
{"modelName": "model-c", "cost": float("nan")},
122+
],
123+
}
124+
]
125+
model, _day = pick_current_model(entries)
126+
self.assertEqual(model, "model-a")
127+
128+
def test_latest_day_cost_accepts_numeric_string(self):
129+
entries = [
130+
{
131+
"date": "2026-05-25",
132+
"modelBreakdowns": [{"modelName": "model-a", "cost": "2.50"}],
133+
}
134+
]
135+
day, cost = latest_day_cost(entries, "model-a")
136+
self.assertEqual(day, "2026-05-25")
137+
self.assertEqual(cost, 2.50)
138+
139+
def test_latest_day_cost_rejects_non_finite(self):
140+
entries = [
141+
{
142+
"date": "2026-05-25",
143+
"modelBreakdowns": [{"modelName": "model-a", "cost": float("inf")}],
144+
}
145+
]
146+
day, cost = latest_day_cost(entries, "model-a")
147+
self.assertEqual(day, "2026-05-25")
148+
self.assertIsNone(cost)
149+
91150

92151
if __name__ == "__main__":
93152
main()

0 commit comments

Comments
 (0)