Files
ai-agent/backend/test_usage_merge.py
gabrielvidalandClaude Opus 5.5 604bc1dee6 feat(usage): usage widgets follow the picked model's provider; Fable weekly limit
- sidecar: read the lab's own Claude logins through /api/oauth/usage too
  (oauth-usage.json beside the status line's file) and keep the reply's
  weekly_scoped limits as seven_day_<model> (Fable)
- hub: take only the per-model windows from that read and merge them per
  window with the status line's snapshot; alert label 'Fable weekly'
- home usage strip follows the composer's pick (lib/composerPick): Claude ->
  week + Fable week (no empty 5-hour tile), Gemini -> agy 5h + week
- composer rings: Fable week ring while a Fable model is picked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:05:08 +01:00

36 lines
1.5 KiB
Python

"""The poller keeps the windows a staler source reports when the freshest one
lacks them: the status line's week, the OAuth read's Fable week."""
import unittest
from usage.poller import STALE_S, merge
class MergeTest(unittest.TestCase):
def test_freshest_wins_and_keeps_scoped_windows(self):
line = {"updatedAt": 1000, "windows": {"seven_day": {"pct": 5, "resetsAt": 9}}}
oauth = {"updatedAt": 900, "windows": {"seven_day": {"pct": 4, "resetsAt": 9},
"seven_day_fable": {"pct": 12, "resetsAt": 9}}}
got = merge([oauth, line])
self.assertEqual(got["updatedAt"], 1000)
self.assertEqual(got["windows"]["seven_day"]["pct"], 5)
self.assertEqual(got["windows"]["seven_day_fable"]["pct"], 12)
def test_the_week_survives_a_fresher_scoped_only_read(self):
line = {"updatedAt": 900, "windows": {"seven_day": {"pct": 5}}}
oauth = {"updatedAt": 1000, "windows": {"seven_day_fable": {"pct": 1}}}
got = merge([line, oauth])["windows"]
self.assertEqual(set(got), {"seven_day", "seven_day_fable"})
def test_a_stale_source_carries_nothing(self):
line = {"updatedAt": 10 + STALE_S * 2, "windows": {"seven_day": {"pct": 5}}}
old = {"updatedAt": 10, "windows": {"seven_day_fable": {"pct": 1}}}
self.assertNotIn("seven_day_fable", merge([line, old])["windows"])
def test_empty(self):
self.assertIsNone(merge([]))
if __name__ == "__main__":
unittest.main()