From c59b3008653f7d305a19907fd9f969e76b4fdea8 Mon Sep 17 00:00:00 2001 From: spiky02plateau Date: Wed, 27 May 2026 00:59:32 +0200 Subject: [PATCH] test: lock Codex usage percent polarity --- tests/agent/test_account_usage.py | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/agent/test_account_usage.py b/tests/agent/test_account_usage.py index 27068f3b3aa..acf1745cbfc 100644 --- a/tests/agent/test_account_usage.py +++ b/tests/agent/test_account_usage.py @@ -108,3 +108,46 @@ def test_codex_usage_falls_back_to_native_credential_pool(monkeypatch, codex_usa assert snapshot.windows[1].label == "Weekly" assert calls[0]["url"] == "https://chatgpt.com/backend-api/wham/usage" assert calls[0]["headers"]["Authorization"] == "Bearer pooled-token" + + +def test_codex_usage_treats_wham_used_percent_as_used_not_remaining(monkeypatch): + """ChatGPT UI says "left"; /wham/usage.used_percent is already used.""" + payload = { + "plan_type": "plus", + "rate_limit": { + "primary_window": { + "used_percent": 85, + "reset_at": 1779846359, + }, + "secondary_window": { + "used_percent": 14, + "reset_at": 1780230796, + }, + }, + "credits": {"has_credits": False}, + } + calls = [] + monkeypatch.setattr( + account_usage.httpx, + "Client", + lambda timeout: _FakeClient(calls, payload), + ) + monkeypatch.setattr( + account_usage, + "resolve_codex_runtime_credentials", + lambda **kwargs: (_ for _ in ()).throw(AssertionError("explicit auth should be used")), + ) + + snapshot = account_usage.fetch_account_usage( + "openai-codex", + base_url="https://chatgpt.com/backend-api/codex", + api_key="live-agent-token", + ) + + assert snapshot is not None + assert [window.used_percent for window in snapshot.windows] == [85, 14] + rendered = "\n".join(account_usage.render_account_usage_lines(snapshot, markdown=True)) + assert "85% used" in rendered + assert "14% used" in rendered + assert "15% used" not in rendered + assert "86% used" not in rendered