date: 2026-11-05T22:48:32.038850+00:00 commit: 4513d90e482e9bb7bb1fd0402cfec45aa7f52d36 (find method); new tests based on da2f392442c0b62493f3639e4e27a4d7fc5eb7e6 + WIP

$ Inject original CachedSessionDirectory.find from git show into current adapter and run pytest -q student-tests/unit/test_session_cache.py -k delayed_fill
Offline CacheModel; Lua and PostgreSQL are not executed.

.FFF                                                                     [100%]
=================================== FAILURES ===================================
_________ test_delayed_fill_cannot_revive_logged_out_session[flushall] _________

session = Session(user_id=UUID('707d8826-260e-489a-81a0-fe469adc5850'), created_at=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), expires_at=datetime.datetime(2030, 1, 1, 0, 0, 30, tzinfo=datetime.timezone.utc))
loss = 'flushall'

    @pytest.mark.parametrize("loss", ["none", "flushall", "evict", "replacement"])
    async def test_delayed_fill_cannot_revive_logged_out_session(session: Session, loss: str) -> None:
        origin, cache = AsyncMock(), CacheModel()
        origin.find.return_value = session
        entered, released = asyncio.Event(), asyncio.Event()

        async def stale_find(token_hash: bytes, now: datetime) -> Session:
            entered.set()
            await released.wait()
            return session

        slow = AsyncMock()
        slow.find.side_effect = stale_find
        async with asyncio.TaskGroup() as group:
            reader = group.create_task(directory(slow, cache).find(session.token_hash, NOW))
            await asyncio.wait_for(entered.wait(), 1)
            try:
                await directory(origin, cache).revoke(session)
                origin.find.return_value = None
                key = key_of(session.token_hash)
                if loss == "flushall":
                    cache.values.clear()
                elif loss in {"evict", "replacement"}:
                    await cache.delete(key)
                if loss == "replacement":
                    await cache.set(f"{key}:fill", uuid4().hex, pxat=milliseconds(session.expires_at))
            finally:
                released.set()
        assert reader.result() == session
>       assert await directory(origin, cache).find(session.token_hash, NOW) is None
E       AssertionError: assert Session(user_id=UUID('707d8826-260e-489a-81a0-fe469adc5850'), created_at=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), expires_at=datetime.datetime(2030, 1, 1, 0, 0, 30, tzinfo=datetime.timezone.utc)) is None

student-tests/unit/test_session_cache.py:117: AssertionError
__________ test_delayed_fill_cannot_revive_logged_out_session[evict] ___________

session = Session(user_id=UUID('d32076b9-cf70-4df9-8ca0-169b50d1d633'), created_at=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), expires_at=datetime.datetime(2030, 1, 1, 0, 0, 30, tzinfo=datetime.timezone.utc))
loss = 'evict'

    @pytest.mark.parametrize("loss", ["none", "flushall", "evict", "replacement"])
    async def test_delayed_fill_cannot_revive_logged_out_session(session: Session, loss: str) -> None:
        origin, cache = AsyncMock(), CacheModel()
        origin.find.return_value = session
        entered, released = asyncio.Event(), asyncio.Event()

        async def stale_find(token_hash: bytes, now: datetime) -> Session:
            entered.set()
            await released.wait()
            return session

        slow = AsyncMock()
        slow.find.side_effect = stale_find
        async with asyncio.TaskGroup() as group:
            reader = group.create_task(directory(slow, cache).find(session.token_hash, NOW))
            await asyncio.wait_for(entered.wait(), 1)
            try:
                await directory(origin, cache).revoke(session)
                origin.find.return_value = None
                key = key_of(session.token_hash)
                if loss == "flushall":
                    cache.values.clear()
                elif loss in {"evict", "replacement"}:
                    await cache.delete(key)
                if loss == "replacement":
                    await cache.set(f"{key}:fill", uuid4().hex, pxat=milliseconds(session.expires_at))
            finally:
                released.set()
        assert reader.result() == session
>       assert await directory(origin, cache).find(session.token_hash, NOW) is None
E       AssertionError: assert Session(user_id=UUID('d32076b9-cf70-4df9-8ca0-169b50d1d633'), created_at=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), expires_at=datetime.datetime(2030, 1, 1, 0, 0, 30, tzinfo=datetime.timezone.utc)) is None

student-tests/unit/test_session_cache.py:117: AssertionError
_______ test_delayed_fill_cannot_revive_logged_out_session[replacement] ________

session = Session(user_id=UUID('9851ca54-cd26-4afa-b3c5-062bb762b064'), created_at=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), expires_at=datetime.datetime(2030, 1, 1, 0, 0, 30, tzinfo=datetime.timezone.utc))
loss = 'replacement'

    @pytest.mark.parametrize("loss", ["none", "flushall", "evict", "replacement"])
    async def test_delayed_fill_cannot_revive_logged_out_session(session: Session, loss: str) -> None:
        origin, cache = AsyncMock(), CacheModel()
        origin.find.return_value = session
        entered, released = asyncio.Event(), asyncio.Event()

        async def stale_find(token_hash: bytes, now: datetime) -> Session:
            entered.set()
            await released.wait()
            return session

        slow = AsyncMock()
        slow.find.side_effect = stale_find
        async with asyncio.TaskGroup() as group:
            reader = group.create_task(directory(slow, cache).find(session.token_hash, NOW))
            await asyncio.wait_for(entered.wait(), 1)
            try:
                await directory(origin, cache).revoke(session)
                origin.find.return_value = None
                key = key_of(session.token_hash)
                if loss == "flushall":
                    cache.values.clear()
                elif loss in {"evict", "replacement"}:
                    await cache.delete(key)
                if loss == "replacement":
                    await cache.set(f"{key}:fill", uuid4().hex, pxat=milliseconds(session.expires_at))
            finally:
                released.set()
        assert reader.result() == session
>       assert await directory(origin, cache).find(session.token_hash, NOW) is None
E       AssertionError: assert Session(user_id=UUID('9851ca54-cd26-4afa-b3c5-062bb762b064'), created_at=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), expires_at=datetime.datetime(2030, 1, 1, 0, 0, 30, tzinfo=datetime.timezone.utc)) is None

student-tests/unit/test_session_cache.py:117: AssertionError
=========================== short test summary info ============================
FAILED student-tests/unit/test_session_cache.py::test_delayed_fill_cannot_revive_logged_out_session[flushall]
FAILED student-tests/unit/test_session_cache.py::test_delayed_fill_cannot_revive_logged_out_session[evict]
FAILED student-tests/unit/test_session_cache.py::test_delayed_fill_cannot_revive_logged_out_session[replacement]
3 failed, 1 passed, 5 deselected in 0.06s

exit: 1
