МЕРА: снимок фикстуры бэктеста снова знает пороги движка (#1970)

Ревью #3556: settings_at_capture в _write_fixture писал только поля estimate_*
из Settings. После переноса 31 порога в константы estimator.py будущая фикстура
не знала бы, с какими порогами её захватили. Теперь в снимок попадают и
числовые константы модуля (63 штуки, CORRIDOR_CLAMP_MIN_N в том числе).
replay_fixture снимок по-прежнему не читает.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
bot-backend 2026-09-17 13:57:07 +05:00
parent 228c5f58f9
commit 91a075bc81
2 changed files with 22 additions and 1 deletions

View file

@ -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",

View file

@ -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 по-прежнему в снимке