Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions tests/unit/test_adoption_telemetry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
from unittest.mock import AsyncMock
from uuid import UUID, uuid4

Expand Down Expand Up @@ -699,7 +699,10 @@ def collect(request: httpx.Request) -> httpx.Response:
@pytest.mark.skipif(CLICKHOUSE is None, reason="clickhouse binary not installed")
def test_public_domain_directory_uses_latest_snapshot_until_daily_report() -> None:
telemetry = ROOT / "deploy" / "telemetry"
clock = "toDateTime('2026-11-27 01:30:00', 'UTC')"
# The warehouse view uses the fixture clock, while the snapshot TTL uses real UTC.
today = datetime.now(UTC).date()
yesterday = today - timedelta(days=1)
clock = f"toDateTime('{today} 01:30:00', 'UTC')"
warehouse = (telemetry / "warehouse.sql").read_text().strip().removesuffix(";")
[report] = run(
[
Expand All @@ -708,42 +711,42 @@ def test_public_domain_directory_uses_latest_snapshot_until_daily_report() -> No
INSERT INTO loom_product_analytics.adoption_enrollments (installation_id, is_internal)
VALUES ('internal', 1)
""",
"""
f"""
INSERT INTO loom_product_analytics.adoption_reports
(installation_id, window_start, window_end, day, schema_version,
loom_version, clickhouse_version, requests, successful_requests,
daily_successful_requests, user_domains, domain_activity)
VALUES
('measured', '2026-11-26 12:00:00', '2026-11-27 00:00:00', '2026-11-26',
('measured', '{yesterday} 12:00:00', '{today} 00:00:00', '{yesterday}',
3, '1.2.0', '26.1.0', 23, 23, 23, [('live.example', 1, 23)],
[('live.example', 3, 23, 2)]),
('capped', '2026-11-26 12:00:00', '2026-11-27 00:00:00', '2026-11-26',
('capped', '{yesterday} 12:00:00', '{today} 00:00:00', '{yesterday}',
3, '1.2.0', '26.1.0', 4, 4, 4, [('capped.example', 1, 4)], []),
('stale', '2026-11-26 12:00:00', '2026-11-27 00:00:00', '2026-11-26',
('stale', '{yesterday} 12:00:00', '{today} 00:00:00', '{yesterday}',
3, '1.2.0', '26.1.0', 1, 1, 1, [('stale.example', 1, 1)], [])
""",
"""
f"""
INSERT INTO loom_product_analytics.adoption_domain_snapshots
(schema_version, installation_id, day, observed_at, loom_version,
clickhouse_version, domain_activity)
VALUES
(4, 'measured', '2026-11-27', '2026-11-27 01:25:00', '1.3.0', '26.1.0',
(4, 'measured', '{today}', '{today} 01:25:00', '1.3.0', '26.1.0',
[('live.example', 2, 7, 2), ('new.example', 1, 2, NULL)]),
(4, 'measured', '2026-11-27', '2026-11-27 01:20:00', '1.3.0', '26.1.0',
(4, 'measured', '{today}', '{today} 01:20:00', '1.3.0', '26.1.0',
[('live.example', 3, 5, 1)]),
(4, 'a', '2026-11-27', '2026-11-27 01:25:00', '1.3.0', '26.1.0',
(4, 'a', '{today}', '{today} 01:25:00', '1.3.0', '26.1.0',
[('shared.example', 1, 3, 1)]),
(4, 'z', '2026-11-27', '2026-11-27 01:20:00', '1.2.0', '26.1.0',
(4, 'z', '{today}', '{today} 01:20:00', '1.2.0', '26.1.0',
[('shared.example', 1, 2, 1)]),
(4, 'measured', '2026-11-26', '2026-11-26 23:55:00', '1.3.0', '26.1.0',
(4, 'measured', '{yesterday}', '{yesterday} 23:55:00', '1.3.0', '26.1.0',
[('live.example', 3, 20, 2)]),
(4, 'capped', '2026-11-26', '2026-11-26 23:55:00', '1.3.0', '26.1.0',
(4, 'capped', '{yesterday}', '{yesterday} 23:55:00', '1.3.0', '26.1.0',
[('capped.example', 1, 3, 1), ('removed.example', 2, 8, 1)]),
(4, 'internal', '2026-11-27', '2026-11-27 01:25:00', '1.3.0', '26.1.0',
(4, 'internal', '{today}', '{today} 01:25:00', '1.3.0', '26.1.0',
[('internal.example', 1, 30, 1)]),
(4, 'smoke', '2026-11-27', '2026-11-27 01:25:00', '1.3.0', '0.0.0-smoke',
(4, 'smoke', '{today}', '{today} 01:25:00', '1.3.0', '0.0.0-smoke',
[('smoke.example', 1, 50, 1)]),
(4, 'stale', '2026-11-26', '2026-11-26 23:25:00', '1.3.0', '26.1.0',
(4, 'stale', '{yesterday}', '{yesterday} 23:25:00', '1.3.0', '26.1.0',
[('stale.example', 1, 30, 1)])
""",
],
Expand All @@ -769,9 +772,9 @@ def test_public_domain_directory_uses_latest_snapshot_until_daily_report() -> No
"active_accounts": 2,
"serving_processes": 2,
"loom_version": "1.3.0",
"day": "2026-11-27",
"first_seen": "2026-11-26",
"last_seen": "2026-11-27",
"day": today.isoformat(),
"first_seen": yesterday.isoformat(),
"last_seen": today.isoformat(),
}
assert domain_rows["new.example"]["successful_requests"] == 2
assert domain_rows["capped.example"]["successful_requests"] == 4
Expand Down
Loading