""" voice-check's ``checked_at`` is when Discord was last asked — the oldest cached snapshot behind the answer — not the time of the HTTP response, so the picker's "Permissions checked N ago" footer never calls a 10-minute-old denied result fresh (server-26#225 S4). """ import time from datetime import datetime from app.internal import discord_rest from app.routers import discord_checks as checks from tests.test_discord_perm_check import GUILD, OWNER, _snap, _token, fs, run # noqa: F401 (fs = fixture) def _age(out) -> float: return time.time() - datetime.fromisoformat(out["checked_at"]).timestamp() def test_checked_at_is_the_oldest_snapshot_not_now(fs, monkeypatch): _token(fs, "t1"); _token(fs, "t2") ages = {"t1": 30, "t2": 420} async def _old(token_doc, guild_id, *, refresh=False): s = _snap(token_doc["token_id"]) s.fetched_at = time.time() - (0 if refresh else ages[token_doc["token_id"]]) return s monkeypatch.setattr(discord_rest, "guild_snapshot", _old) out = run(checks.node_voice_check("n1", GUILD, refresh=0, channel_id=None, decoded=OWNER)) assert 415 <= _age(out) <= 430 out = run(checks.node_voice_check("n1", GUILD, refresh=1, channel_id=None, decoded=OWNER)) assert _age(out) < 5 def test_checked_at_without_snapshots_is_now(fs): out = run(checks.node_voice_check("n1", GUILD, refresh=0, channel_id=None, decoded=OWNER)) # no bots assert _age(out) < 5