From 91a075bc81b07d2106135c956ab3cf09ee359778 Mon Sep 17 00:00:00 2001 From: bot-backend Date: Thu, 17 Sep 2026 13:57:07 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=95=D0=A0=D0=90:=20=D1=81=D0=BD=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D0=BA=20=D1=84=D0=B8=D0=BA=D1=81=D1=82=D1=83=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B1=D1=8D=D0=BA=D1=82=D0=B5=D1=81=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=B7=D0=BD=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=80=D0=BE=D0=B3=D0=B8=20=D0=B4=D0=B2=D0=B8?= =?UTF-8?q?=D0=B6=D0=BA=D0=B0=20(#1970)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ревью #3556: settings_at_capture в _write_fixture писал только поля estimate_* из Settings. После переноса 31 порога в константы estimator.py будущая фикстура не знала бы, с какими порогами её захватили. Теперь в снимок попадают и числовые константы модуля (63 штуки, CORRIDOR_CLAMP_MIN_N в том числе). replay_fixture снимок по-прежнему не читает. Co-Authored-By: Claude Opus 5 --- tradein-mvp/backend/scripts/backtest_estimator.py | 9 ++++++++- .../tests/test_backtest_fixture_roundtrip.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 по-прежнему в снимке