Files
fxhnt/tests/integration/test_factory_store.py
jgrusewski 86eadae42f fix(factory): capital-correct loop — record_cycle, sequential HRP-weighted admission, kill-switch, tests
Fix 1: wire record_cycle in factory-cycle --execute so the funnel table is populated.
  LoopResult gains deployed_before/deployed_after/forward_count; cli.py calls
  fs.record_cycle(proposed=forward_count, ...) and record_allocation after the loop.

Fix 2+4: replace equal-weight book proxy with HRP-weighted blend of deployed sleeves;
  rewrite admission as sequential — each candidate is re-gated against the running mean
  of already-admitted-this-cycle candidates, so two candidates uncorrelated to the book
  but correlated to each other cannot both be admitted in one cycle.

Fix 3: HRP inclusion now requires >= min_forward_days (was >= 2). Folded into the
  final rets comprehension in allocate_and_promote.

Fix 5: StrategyStoreLoopAdapter.set_status now asserts status == "DEPLOYED" so a future
  demotion path cannot silently promote via the loop adapter.

Fix 6: persisted kill-switch — FactoryFlagRow ORM model added to cockpit_models.py;
  FactoryStore.set_kill(on)/is_killed() read/write a key="kill" row; factory-cycle
  folds db kill with env kill; factory-flatten renamed to factory-halt; factory-resume
  and factory-status commands added.

Fix 7: sleeve returns fetched once per sleeve in the final HRP comprehension via a
  shared dict, avoiding double store I/O.

Fix 8: three new integration tests covering min_forward_days filter, empty-book
  founding-admit-then-gate, and mutual-correlation blocking within a cycle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 20:24:50 +02:00

29 lines
1.1 KiB
Python

"""Factory store: persist a cycle's funnel counts + the deployed allocation (for the cockpit)."""
from __future__ import annotations
import datetime as dt
from fxhnt.adapters.persistence.factory_store import FactoryStore
def test_funnel_and_allocation_roundtrip() -> None:
st = FactoryStore("sqlite://")
at = dt.datetime(2026, 6, 15, 0, 0)
st.record_cycle(cycle_id="c1", proposed=12, tested=12, survived=3, forward=8, deployed=2,
retired=1, global_trials=5000, at=at)
st.record_allocation("c1", {"A": 0.6, "B": 0.4}, at)
funnel = st.latest_cycle()
assert funnel.proposed == 12 and funnel.deployed == 2 and funnel.global_trials == 5000
alloc = {a.strategy_id: a.weight for a in st.allocation("c1")}
assert abs(alloc["A"] - 0.6) < 1e-9 and abs(alloc["B"] - 0.4) < 1e-9
def test_kill_switch_persists() -> None:
"""set_kill(True) → is_killed() True; set_kill(False) → is_killed() False."""
st = FactoryStore("sqlite://")
assert st.is_killed() is False # default: no row → False
st.set_kill(True)
assert st.is_killed() is True
st.set_kill(False)
assert st.is_killed() is False