From 98de8f331f02c7efcb749736552858dd0d994219 Mon Sep 17 00:00:00 2001 From: Chris Coutinho Date: Sun, 7 Jun 2026 15:52:54 +0200 Subject: [PATCH] refactor(usage): final round-6 nits on PR #871 - semantic.py: normalize both None and [] doc_types to null in the metadata so a future `metadata->'doc_types' IS NULL` query counts the all-types case consistently. - test: use a fixed past date in test_occurred_at_roundtrip instead of a future literal (deterministic, no "why this date" confusion). Co-Authored-By: Claude Opus 4.8 (1M context) --- nextcloud_mcp_server/server/semantic.py | 5 ++++- tests/unit/test_usage_store.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/nextcloud_mcp_server/server/semantic.py b/nextcloud_mcp_server/server/semantic.py index ec93a851..8d78849f 100644 --- a/nextcloud_mcp_server/server/semantic.py +++ b/nextcloud_mcp_server/server/semantic.py @@ -548,10 +548,13 @@ def configure_semantic_tools(mcp: FastMCP): "user_id": username, "fusion": fusion, # Bounded copy — see _USAGE_METADATA_MAX_DOC_TYPES. + # Both None and [] normalize to null so a future + # metadata->'doc_types' IS NULL query counts the + # all-types case consistently. "doc_types": ( doc_types[:_USAGE_METADATA_MAX_DOC_TYPES] if doc_types - else doc_types + else None ), }, # The outer guard already confirmed the flag, so pass diff --git a/tests/unit/test_usage_store.py b/tests/unit/test_usage_store.py index 475254c8..aa4b6944 100644 --- a/tests/unit/test_usage_store.py +++ b/tests/unit/test_usage_store.py @@ -185,7 +185,7 @@ async def test_occurred_at_roundtrip(storage, monkeypatch): _set_metering(monkeypatch, True) store = UsageEventStore(storage) eid = str(uuid.uuid4()) - when = datetime(2026, 6, 10, 12, 0, 0, tzinfo=timezone.utc) + when = datetime(2026, 1, 15, 12, 0, 0, tzinfo=timezone.utc) await store.record_usage_event( metric="pages_chunks", value=1, event_id=eid, occurred_at=when )