Coverage for node / src / stigmem_node / lifecycle / tombstone_gate.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-25 01:49 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-25 01:49 +0000
1"""Runtime gate for experimental RTBF tombstone behavior."""
3from __future__ import annotations
5import os
6from collections.abc import Mapping
8TOMBSTONE_PLUGIN_NAME = "stigmem-plugin-tombstones"
9_ENV_PREFIX = "STIGMEM_TOMBSTONES_"
12def tombstone_plugin_registered() -> bool:
13 """Return True when the RTBF tombstone plugin is active in the registry."""
14 from ..plugins import get_registry
16 return TOMBSTONE_PLUGIN_NAME in get_registry().registered_plugins()
19def tombstone_filter_enabled(environ: Mapping[str, str] | None = None) -> bool:
20 """Return True only when tombstone filtering is explicitly enabled."""
22 if not tombstone_plugin_registered():
23 return False
24 env = environ if environ is not None else os.environ
25 return _env_bool(env, f"{_ENV_PREFIX}ENABLED") and _env_bool(
26 env, f"{_ENV_PREFIX}ALLOW_RECALL_FILTER"
27 )
30def _env_bool(env: Mapping[str, str], name: str, *, default: bool = False) -> bool:
31 raw = env.get(name)
32 if raw is None:
33 return default
34 return raw.strip().lower() in {"1", "true", "yes", "on"}