diff --git a/tradein-mvp/backend/scripts/backtest_estimator.py b/tradein-mvp/backend/scripts/backtest_estimator.py index f77eb0c8..1a4b1645 100644 --- a/tradein-mvp/backend/scripts/backtest_estimator.py +++ b/tradein-mvp/backend/scripts/backtest_estimator.py @@ -2633,7 +2633,9 @@ def _write_fixture( ) -> None: """Freeze captured per-deal replay records into a committed JSON fixture. - ``settings_at_capture`` records every ``estimate_*`` Settings field as an + ``settings_at_capture`` records every ``estimate_*`` Settings field plus the + estimator's numeric module constants (#1970: калибровочные пороги переехали из + Settings в код — без них снимок не говорит, с какими порогами захватили) as an informational snapshot (NOT consulted by ``replay_fixture``). A final recursive ``_sanitize_json`` pass guarantees the whole document is finite + JSON-plain before ``json.dump(allow_nan=False)``. @@ -2643,6 +2645,11 @@ def _write_fixture( for name in sorted(type(est.settings).model_fields) if name.startswith("estimate_") } + settings_at_capture.update( + (name, _sanitize_json(value)) + for name, value in sorted(vars(est.m).items()) + if name.isupper() and isinstance(value, int | float) + ) fixture = { "schema_version": FIXTURE_SCHEMA_VERSION, "engine": "full", diff --git a/tradein-mvp/backend/tests/test_backtest_fixture_roundtrip.py b/tradein-mvp/backend/tests/test_backtest_fixture_roundtrip.py index 4e7ee9e4..b648afba 100644 --- a/tradein-mvp/backend/tests/test_backtest_fixture_roundtrip.py +++ b/tradein-mvp/backend/tests/test_backtest_fixture_roundtrip.py @@ -297,3 +297,17 @@ def test_load_fixture_plain_and_gzip_roundtrip() -> None: m_plain = bt.replay_fixture(loaded_plain) m_gz = bt.replay_fixture(loaded_gz) assert json.dumps(m_plain, sort_keys=True) == json.dumps(m_gz, sort_keys=True) + + +def test_write_fixture_records_engine_constants(tmp_path: Path) -> None: + """#1970: пороги движка — константы estimator.py, снимок фикстуры обязан их нести.""" + est = bt._import_estimator_full() + out = tmp_path / "fixture.json" + bt._write_fixture(str(out), capture=[], since="2026-09-01", est=est) + snap = json.loads(out.read_text(encoding="utf-8"))["settings_at_capture"] + assert { + k: snap.get(k) + for k in ("CORRIDOR_CLAMP_MIN_N", "CORRIDOR_CLAMP_SLACK", "QUARTER_INDEX_MIN_N_DEALS") + } == {"CORRIDOR_CLAMP_MIN_N": 10, "CORRIDOR_CLAMP_SLACK": 0.4, "QUARTER_INDEX_MIN_N_DEALS": 10} + assert snap.get("SB_ROOMS_MATCH_BOOST") == 1.6 + assert "estimate_pi_low_mult" in snap # поля Settings по-прежнему в снимке