tests/conftest.py
| 1 | """Shared test fixtures for pqc-audit-log-fs.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | import random |
| 7 | from collections.abc import Callable |
| 8 | from pathlib import Path |
| 9 | |
| 10 | import pytest |
| 11 | from quantumshield.identity.agent import AgentIdentity |
| 12 | |
| 13 | from pqc_audit_log_fs.event import InferenceEvent |
| 14 | |
| 15 | |
| 16 | @pytest.fixture |
| 17 | def signer_identity() -> AgentIdentity: |
| 18 | """A fresh AgentIdentity for signing segments.""" |
| 19 | return AgentIdentity.create( |
| 20 | name="test-audit-signer", |
| 21 | capabilities=["audit.sign"], |
| 22 | ) |
| 23 | |
| 24 | |
| 25 | @pytest.fixture |
| 26 | def tmp_log_dir(tmp_path: Path) -> str: |
| 27 | """A clean log directory under pytest's tmp_path.""" |
| 28 | d = tmp_path / "log" |
| 29 | os.makedirs(d, exist_ok=True) |
| 30 | return str(d) |
| 31 | |
| 32 | |
| 33 | @pytest.fixture |
| 34 | def event_factory() -> Callable[..., InferenceEvent]: |
| 35 | """Factory that builds random InferenceEvents with optional overrides.""" |
| 36 | rng = random.Random(1234) |
| 37 | |
| 38 | def _make( |
| 39 | *, |
| 40 | decision_label: str | None = None, |
| 41 | model_version: str = "1.0.0", |
| 42 | ) -> InferenceEvent: |
| 43 | # Random input / output blobs so hashes differ between calls |
| 44 | inp = rng.randbytes(32) |
| 45 | out = rng.randbytes(32) |
| 46 | return InferenceEvent.create( |
| 47 | model_did="did:pqaid:test-model", |
| 48 | model_version=model_version, |
| 49 | input_bytes=inp, |
| 50 | output_bytes=out, |
| 51 | reasoning_bytes=b"step-by-step", |
| 52 | decision_type="classification", |
| 53 | decision_label=decision_label or rng.choice(["approve", "deny", "review"]), |
| 54 | actor_did="did:pqaid:test-user", |
| 55 | session_id=f"sess-{rng.randint(1, 9999)}", |
| 56 | metadata={"test": True}, |
| 57 | ) |
| 58 | |
| 59 | return _make |
| 60 | |