mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:08:46 +02:00
Agent: resolve "today" in the browser's timezone, not hardcoded CR
The CR-hardcoded today broke two scenarios: the owner traveling, and any future non-CR user. Now the provider sends the browser's IANA timezone (X-Client-Timezone) with every CopilotKit request — the runtime forwards x-* headers to the agent on its own — and the backend binds it to a per-request ContextVar next to the DB session. get_current_date and the future-cuota bounds use it; the tool also reports the timezone so the model can echo it. Unknown or absent zones (n8n posts, tests) fall back to Costa Rica; comma-joined duplicate header values are tolerated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -214,3 +214,26 @@ def test_daily_spending_day_scoped(bound_session):
|
||||
assert out[0]["date"] == today.date().isoformat()
|
||||
assert out[0]["total_crc"] == 150.0
|
||||
assert out[0]["count"] == 2
|
||||
|
||||
|
||||
def test_get_current_date_respects_client_timezone():
|
||||
from datetime import datetime, timezone as tz
|
||||
|
||||
from app.timeutil import (
|
||||
client_tz,
|
||||
reset_client_timezone,
|
||||
set_client_timezone,
|
||||
)
|
||||
|
||||
token = set_client_timezone("Asia/Tokyo")
|
||||
try:
|
||||
out = tools.get_current_date()
|
||||
assert out["timezone"] == "Asia/Tokyo"
|
||||
assert out["date"] == datetime.now(client_tz()).date().isoformat()
|
||||
finally:
|
||||
reset_client_timezone(token)
|
||||
|
||||
# Unknown names are ignored — CR fallback stays active.
|
||||
assert set_client_timezone("Not/AZone") is None
|
||||
assert set_client_timezone(None) is None
|
||||
assert tools.get_current_date()["timezone"] == "UTC-06:00"
|
||||
|
||||
Reference in New Issue
Block a user