Startup → activity → shutdown → restart → state restored.
(tmp_path)
| 103 | |
| 104 | |
| 105 | def test_persistence_roundtrip(tmp_path): |
| 106 | """Startup → activity → shutdown → restart → state restored.""" |
| 107 | _reset_lifecycle() |
| 108 | lc.on_startup(tmp_path) |
| 109 | # Simulate a routing + feedback that changes weights |
| 110 | lc.on_route_complete( |
| 111 | request_id="", tier_id=1, model="test", method="direct", confidence=0.8, |
| 112 | signal_a_tier=0, signal_a_conf=0.8, |
| 113 | signal_b_tier=1, signal_b_conf=0.7, |
| 114 | signal_c_tier=1, signal_c_conf=0.8, |
| 115 | ) |
| 116 | lc.associate_request_id("req_persist") |
| 117 | lc.on_feedback(request_id="req_persist", signal="weak", routed_tier_v1="MEDIUM") |
| 118 | weights_before = list(lc._weight_tracker.weights) |
| 119 | lc.on_shutdown() |
| 120 | # Restart |
| 121 | _reset_lifecycle() |
| 122 | lc.on_startup(tmp_path) |
| 123 | weights_after = lc._weight_tracker.weights |
| 124 | # Weights should be restored |
| 125 | for a, b in zip(weights_before, weights_after): |
| 126 | assert abs(a - b) < 1e-9 |
| 127 | _reset_lifecycle() |
| 128 | |
| 129 | |
| 130 | def test_signal_b_not_promoted_initially(tmp_path): |
nothing calls this directly
no test coverage detected