tests/conftest.py
| 1 | """Shared fixtures for the pqc-kv-cache-encryption test suite.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from collections.abc import Callable |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from pqc_kv_cache.entry import EntryMetadata, KVCacheEntry |
| 11 | from pqc_kv_cache.session import ( |
| 12 | TenantIdentity, |
| 13 | TenantSession, |
| 14 | establish_tenant_session, |
| 15 | ) |
| 16 | |
| 17 | |
| 18 | @pytest.fixture |
| 19 | def tenant_alice() -> TenantIdentity: |
| 20 | return TenantIdentity(tenant_id="tenant-alice", display_name="Alice Inc.") |
| 21 | |
| 22 | |
| 23 | @pytest.fixture |
| 24 | def tenant_bob() -> TenantIdentity: |
| 25 | return TenantIdentity(tenant_id="tenant-bob", display_name="Bob LLC") |
| 26 | |
| 27 | |
| 28 | @pytest.fixture |
| 29 | def session_alice(tenant_alice: TenantIdentity) -> TenantSession: |
| 30 | return establish_tenant_session(tenant_alice) |
| 31 | |
| 32 | |
| 33 | @pytest.fixture |
| 34 | def session_bob(tenant_bob: TenantIdentity) -> TenantSession: |
| 35 | return establish_tenant_session(tenant_bob) |
| 36 | |
| 37 | |
| 38 | @pytest.fixture |
| 39 | def sample_k_bytes() -> bytes: |
| 40 | return os.urandom(32) |
| 41 | |
| 42 | |
| 43 | @pytest.fixture |
| 44 | def sample_v_bytes() -> bytes: |
| 45 | return os.urandom(32) |
| 46 | |
| 47 | |
| 48 | @pytest.fixture |
| 49 | def sample_entry_factory() -> Callable[[TenantSession, int, int], KVCacheEntry]: |
| 50 | """Factory producing a fresh KVCacheEntry bound to a session/tenant.""" |
| 51 | |
| 52 | def _make(session: TenantSession, layer: int, pos: int) -> KVCacheEntry: |
| 53 | meta = EntryMetadata( |
| 54 | tenant_id=session.tenant.tenant_id, |
| 55 | session_id=session.session_id, |
| 56 | layer_idx=layer, |
| 57 | position=pos, |
| 58 | token_id=1000 + pos, |
| 59 | kv_role="both", |
| 60 | ) |
| 61 | return KVCacheEntry( |
| 62 | metadata=meta, |
| 63 | key_tensor_bytes=os.urandom(32), |
| 64 | value_tensor_bytes=os.urandom(32), |
| 65 | ) |
| 66 | |
| 67 | return _make |
| 68 | |