feat(api): limits read unifiedWindows, unknown seven-day windows labelled by model
This commit is contained in:
+24
-3
@@ -247,6 +247,7 @@ async def test_usage_groups_by_agent_day_and_model(world: World) -> None:
|
||||
async def test_limits_report_latest_window_with_gateway_spend(world: World) -> None:
|
||||
api = Api(world)
|
||||
now = datetime.now(UTC)
|
||||
resets = int((now + timedelta(hours=4)).timestamp())
|
||||
async with world.db.session() as session:
|
||||
session.add(
|
||||
RateLimit(
|
||||
@@ -264,7 +265,20 @@ async def test_limits_report_latest_window_with_gateway_spend(world: World) -> N
|
||||
resets_at=now + timedelta(hours=4),
|
||||
)
|
||||
)
|
||||
session.add(RateLimit(window="seven_day", status="allowed", utilization=0.3))
|
||||
session.add(
|
||||
RateLimit(
|
||||
window="seven_day",
|
||||
status="allowed",
|
||||
utilization=0.3,
|
||||
raw={
|
||||
"unifiedWindows": {
|
||||
"five_hour": {"resetsAt": resets, "utilization": 0.72},
|
||||
"seven_day": {"resetsAt": resets, "utilization": 0.25},
|
||||
"seven_day_fable": {"resetsAt": resets, "utilization": 0.1},
|
||||
}
|
||||
},
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
await seed_usage(
|
||||
world,
|
||||
@@ -280,12 +294,19 @@ async def test_limits_report_latest_window_with_gateway_spend(world: World) -> N
|
||||
)
|
||||
out = await api.get("/limits")
|
||||
windows = {w["window"]: w for w in out["windows"]}
|
||||
assert windows["five_hour"]["utilization"] == 0.9
|
||||
assert windows["five_hour"]["utilization"] == 0.72
|
||||
assert windows["five_hour"]["reported_at"] is not None
|
||||
assert windows["five_hour"]["status"] == "allowed_warning"
|
||||
assert windows["five_hour"]["gateway"]["output"] == 7
|
||||
assert windows["five_hour"]["gateway"]["cost_usd"] == 0.25
|
||||
assert windows["seven_day"]["utilization"] == 0.3
|
||||
assert [w["window"] for w in out["windows"]] == ["five_hour", "seven_day"]
|
||||
assert windows["seven_day_fable"]["utilization"] == 0.1
|
||||
assert windows["seven_day_fable"]["status"] == "allowed"
|
||||
assert [w["window"] for w in out["windows"]] == [
|
||||
"five_hour",
|
||||
"seven_day",
|
||||
"seven_day_fable",
|
||||
]
|
||||
assert len(out["history"]) == 3
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user