Improve backend coverage for utility serialization and inbox queue behavior#25
Improve backend coverage for utility serialization and inbox queue behavior#25
Conversation
Agent-Logs-Url: https://github.com/thinkwee/HiMe/sessions/12ef4c67-b97d-49c8-99de-b4afe7136ddc Co-authored-by: thinkwee <11889052+thinkwee@users.noreply.github.com>
Agent-Logs-Url: https://github.com/thinkwee/HiMe/sessions/12ef4c67-b97d-49c8-99de-b4afe7136ddc Co-authored-by: thinkwee <11889052+thinkwee@users.noreply.github.com>
Agent-Logs-Url: https://github.com/thinkwee/HiMe/sessions/12ef4c67-b97d-49c8-99de-b4afe7136ddc Co-authored-by: thinkwee <11889052+thinkwee@users.noreply.github.com>
Agent-Logs-Url: https://github.com/thinkwee/HiMe/sessions/12ef4c67-b97d-49c8-99de-b4afe7136ddc Co-authored-by: thinkwee <11889052+thinkwee@users.noreply.github.com>
Agent-Logs-Url: https://github.com/thinkwee/HiMe/sessions/12ef4c67-b97d-49c8-99de-b4afe7136ddc Co-authored-by: thinkwee <11889052+thinkwee@users.noreply.github.com>
Agent-Logs-Url: https://github.com/thinkwee/HiMe/sessions/12ef4c67-b97d-49c8-99de-b4afe7136ddc Co-authored-by: thinkwee <11889052+thinkwee@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves backend test coverage around shared utility serialization/timestamp helpers and async inbox queue behavior, and hardens serialize_value to avoid ambiguous truth-value errors on NumPy arrays.
Changes:
- Added unit tests for UTC timestamp formatting/parsing, timezone selection/fallback, DataFrame-to-JSON sanitization, and recursive scalar serialization.
- Added async tests for
InboxQueuepush/pop, bounded overflow (drop-oldest), debounce merge rules, andwait_and_pop_alldrain behavior. - Updated
serialize_valueto handlenp.ndarraybeforepd.isna(...)and to use an early-return flow with guardedpd.isnaevaluation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/test_utils.py |
Adds coverage for timestamp/timezone helpers and JSON-safe serialization utilities. |
tests/test_inbox_queue.py |
Adds coverage for inbox queue draining, maxsize overflow behavior, and debounce semantics. |
backend/utils.py |
Hardens serialize_value for NumPy arrays and simplifies the control flow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| naive = datetime(2026, 1, 2, 3, 4, 5) | ||
| aware = datetime(2026, 1, 2, 11, 4, 5, tzinfo=ZoneInfo("Asia/Shanghai")) | ||
|
|
||
| assert utils.ts_fmt(naive) == "2026-01-02T03:04:05" | ||
| assert utils.ts_fmt(aware) == "2026-01-02T03:04:05" |
There was a problem hiding this comment.
These assertions depend on IANA tzdata being available for ZoneInfo("Asia/Shanghai"). The repo doesn’t declare a tzdata dependency and the Docker image is based on python:*-slim (often missing /usr/share/zoneinfo), so this test can fail with ZoneInfoNotFoundError in some environments. Consider using a fixed-offset datetime.timezone(timedelta(hours=8)) here, or skipping the test when ZoneInfo("Asia/Shanghai") isn’t available.
| def test_app_timezone_uses_config_and_falls_back_to_utc(monkeypatch) -> None: | ||
| monkeypatch.setattr(settings, "TIMEZONE", "Asia/Shanghai") | ||
| assert utils.app_timezone().key == "Asia/Shanghai" | ||
|
|
||
| monkeypatch.setattr(settings, "TIMEZONE", "Invalid/Timezone") | ||
| assert utils.app_timezone().key == "UTC" |
There was a problem hiding this comment.
This test assumes ZoneInfo("Asia/Shanghai") is resolvable on the runner. On environments without tzdata (common for slim Docker bases), utils.app_timezone() can’t reliably return non-UTC zones and this test will fail. Consider guarding with a try/except ZoneInfoNotFoundError and pytest.skip(...), or ensuring tzdata is installed as part of the test/runtime deps.
Coverage analysis showed thin test depth around shared utility serialization logic and message queue/debounce behavior, leaving important edge paths unverified. This PR adds targeted tests for those high-leverage paths and hardens one serialization branch discovered during coverage-driven testing.
Coverage focus:
backend/utils.pyts_fmt,parse_db_iso_utc)app_timezone,now_*)dataframe_to_json_safe) acrossNaN,Inf, datetime, and empty-frame inputsclean_dict_for_json,serialize_value)Coverage focus:
backend/messaging/inbox.pywait_and_pop_allburst-drain behaviorTargeted runtime hardening
serialize_valueto handlenp.ndarraybeforepd.isna(...)checks, avoiding ambiguous truth-value failures on array inputs.