@@ -472,3 +472,61 @@ def test_narrative_without_session_is_dropped(self, db, topo_dual_ccd_x3d, mock_
472472 eng = _make_engine (db , topo_dual_ccd_x3d , mock_backend )
473473 eng ._session_id = None
474474 eng .log_message .emit ("nowhere to persist" ) # must not raise
475+
476+
477+ def _mce_payload (cpu : int ) -> str :
478+ return json .dumps ([
479+ {"cpu" : cpu , "bank" : 0 , "corrected" : True ,
480+ "message" : CPU5_CORRECTED .format (cpu = cpu ), "raw_ts" : 1.0 }
481+ ])
482+
483+
484+ class TestUnattributedMcePayload :
485+ """A machine check that names NO core taints every resident value.
486+
487+ Surviving a stress test does not clear an error the hardware just reported,
488+ and with no CPU named there is no core to exclude -- so the whole resident
489+ set must stay unproven. Journalling it survived would record a value the
490+ hardware complained about as proven, and the search would then treat it as
491+ a safe floor.
492+ """
493+
494+ def test_a_payload_naming_no_cpu_is_detected (self ):
495+ from corecycler .tuner .engine import _has_unattributed_mce
496+
497+ assert _has_unattributed_mce (_mce_payload (- 1 )) is True
498+
499+ def test_an_attributed_or_absent_payload_is_not (self ):
500+ from corecycler .tuner .engine import _has_unattributed_mce
501+
502+ assert _has_unattributed_mce (_mce_payload (5 )) is False
503+ assert _has_unattributed_mce ("" ) is False
504+ assert _has_unattributed_mce ("not json" ) is False
505+ assert _has_unattributed_mce (json .dumps ({"cpu" : - 1 })) is False
506+
507+ def _mark_survived_calls (self , db , topo_single_ccd , mock_backend , mce_json , monkeypatch ):
508+ eng = _make_engine (db , topo_single_ccd , mock_backend )
509+ sid = eng ._session_id
510+ cs = CoreState (core_id = 0 , phase = TunerPhase .CONFIRMING ,
511+ current_offset = - 20 , best_offset = - 20 , baseline_offset = 0 )
512+ eng ._core_states = {0 : cs }
513+ tp .save_core_state (db , sid , cs )
514+ eng ._co_applied [0 ] = - 20
515+ db .journal_co_intent (sid , 0 , - 20 , survived = False )
516+ calls = []
517+ monkeypatch .setattr (tp , "journal_mark_survived" , lambda * a , ** kw : calls .append (kw ))
518+ eng ._on_test_finished (0 , True , "" , "" , 1.0 , 0.0 , mce_json , "" )
519+ return calls
520+
521+ def test_a_clean_pass_marks_the_resident_set_survived (
522+ self , db , topo_single_ccd , mock_backend , monkeypatch
523+ ):
524+ assert self ._mark_survived_calls (db , topo_single_ccd , mock_backend , "" , monkeypatch )
525+
526+ def test_a_pass_carrying_an_unattributed_mce_marks_nothing_survived (
527+ self , db , topo_single_ccd , mock_backend , monkeypatch
528+ ):
529+ calls = self ._mark_survived_calls (
530+ db , topo_single_ccd , mock_backend , _mce_payload (- 1 ), monkeypatch
531+ )
532+ assert calls == []
0 commit comments