Files
DECNET/tests/ttp/store/conftest.py
anti 0217319423 test(ttp): E.2.14b RuleStore conformance — cross-backend + filesystem-specific + database-specific
tests/ttp/store/conftest.py — parametrized rule_store fixture over
FilesystemRuleStore (skipped on non-Linux) + DatabaseRuleStore.

test_conformance.py — shared assertions (default-state, set_state
isolation/round-trip, subscribe_changes per-rule fan-out, expires_at
auto-revert, set_state failure semantics) parametrize over both.
get_state-default GREEN today on FS (returns RuleState() for empty
cache); rest xfail-gated behind E.3.5/E.3.6.

test_filesystem.py — inotify mask + canonical kernel values + 9
scratch-filename rejections + 4 valid-filename acceptances +
fullmatch anchor + tmp_path construction + CompiledRule frozen
property GREEN today; per-save-style + filter-ordering +
atomic-swap concurrency xfail-gated.

test_database.py — class-level surface (no platform guard, ABC
methods concrete, async coroutines) GREEN today; ttp_rule_state
write + filesystem→DB sync xfail-gated behind E.3.6.
2026-05-01 07:45:32 -04:00

48 lines
1.6 KiB
Python

"""Parametrized ``rule_store`` fixture for E.2.14b.
The conformance contract from ``development/TTP_TAGGING.md`` §E.2.14b:
both backends — :class:`FilesystemRuleStore` and
:class:`DatabaseRuleStore` — must satisfy the same observable
behavior. Tests that consume :func:`rule_store` are run twice, once
per backend.
Filesystem is skipped on non-Linux (it raises ``RuntimeError`` from
``__init__`` on macOS / Windows because the inotify dep is
Linux-only).
"""
from __future__ import annotations
import sys
from pathlib import Path
from typing import Iterator
import pytest
from decnet.ttp.store.base import RuleStore
from decnet.ttp.store.impl.database import DatabaseRuleStore
from decnet.ttp.store.impl.filesystem import FilesystemRuleStore
@pytest.fixture(
params=["filesystem", "database"],
ids=["filesystem", "database"],
)
def rule_store(
request: pytest.FixtureRequest, tmp_path: Path,
) -> Iterator[RuleStore]:
"""Yield a fresh :class:`RuleStore` instance per parametrization.
The filesystem backend is constructed against a ``tmp_path``
rules dir so tests never touch the real ``./rules/``. The
database backend's connection wiring lands at E.3.6; today the
fixture just hands out the raw class instance and impl-phase
tests are responsible for plumbing it into a session.
"""
backend = request.param
if backend == "filesystem":
if sys.platform != "linux":
pytest.skip("FilesystemRuleStore requires Linux (inotify)")
yield FilesystemRuleStore(rules_dir=tmp_path)
else:
yield DatabaseRuleStore()