meshai/work/tests/test_budget_shim.py

35 lines
1.2 KiB
Python
Raw Normal View History

refactor(phase0): source-agnostic formatter/gating scaffold + harness (inert) (#28) Foundation for making all hazard formatting+gating source-agnostic. ZERO behavior change — the formatter/decider registries are empty (get_formatter/ get_decider return None → existing precomposed/Mode-B path preserved), and the shadow comparator is off unless MESHAI_SHADOW_CATEGORIES is set. - notifications/formatters/ (registry+dispatch with family fallback), gating/ (GateResult + deferred-commit contract), both empty registries. - notifications/clock.py determinism seam; route wfigs/quake/nws gating time reads through it (identical values) so goldens can freeze time. - formatters/_budget.py = copy of central/budget.py; central/budget.py is now a re-export shim (import-smoke test guards it). - compose_mesh_message consults the registry first (verbatim, no Mode-B re-cap), falls back to legacy; _resolve_budget injects per-category budget. - notifications/shadow.py + two DRY-RUN hooks (consumer._normalize, dispatcher render): compute the new result and diff-log SHADOW_MISMATCH JSONL, but NEVER commit/emit/write tables and always broadcast the OLD result. Inert by default. - tests/harness (pinned_time/pinned_tz, byte-golden, gate-sequence) + scripts/capture_fixtures.py (ephemeral read-only NATS capture); tzdata pinned. Tests: +60 (18 scaffold + 42 harness/shadow); 0 new failures (34 baseline). Co-authored-by: Matt Johnson <mj@k7zvx.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 12:55:48 -06:00
"""Phase-0: verify the budget.py re-export shim is identity-equal to the impl.
Both import paths must resolve to the SAME function objects so any runtime
patching (e.g. in existing tests) affects both paths simultaneously.
"""
import meshai.central.budget as _shim
import meshai.notifications.formatters._budget as _impl
def test_budget_for_is_same_object():
assert _shim.budget_for is _impl.budget_for, (
"meshai.central.budget.budget_for must be the same object as "
"meshai.notifications.formatters._budget.budget_for"
)
def test_fit_to_budget_is_same_object():
assert _shim.fit_to_budget is _impl.fit_to_budget, (
"meshai.central.budget.fit_to_budget must be the same object as "
"meshai.notifications.formatters._budget.fit_to_budget"
)
def test_shim_imports_work():
"""Smoke: the public names are importable from the legacy path."""
from meshai.central.budget import budget_for, fit_to_budget # noqa: F401
assert callable(budget_for)
assert callable(fit_to_budget)
def test_budget_for_returns_default_without_adapter_config(monkeypatch):
"""budget_for falls back to 140 when the adapter key is absent."""
val = _shim.budget_for("__no_such_adapter__")
assert val == 140