fix(agent): P0.6 guard human corrections
This commit is contained in:
@@ -770,6 +770,63 @@ class TestReplayLearner:
|
||||
|
||||
assert captured["window_title"] == "Fenêtre fallback"
|
||||
|
||||
def test_record_human_correction_uses_last_click_contract(self, learner, monkeypatch):
|
||||
"""Le contrat agent envoie les coordonnées dans correction.last_click."""
|
||||
captured = {}
|
||||
|
||||
def fake_memory_record_success(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(
|
||||
"agent_v0.server_v1.replay_memory.memory_record_success",
|
||||
fake_memory_record_success,
|
||||
)
|
||||
|
||||
learner.record_human_correction(
|
||||
session_id="s_corr_last_click",
|
||||
action={
|
||||
"action_id": "a_corr_last_click",
|
||||
"target_spec": {"by_text": "Enregistrer", "window_title": "Bloc-notes"},
|
||||
},
|
||||
correction={
|
||||
"actions": [{"type": "click", "x_pct": 0.33, "y_pct": 0.66}],
|
||||
"last_click": {"type": "click", "x_pct": 0.33, "y_pct": 0.66},
|
||||
},
|
||||
)
|
||||
|
||||
assert captured["x_pct"] == 0.33
|
||||
assert captured["y_pct"] == 0.66
|
||||
assert len(learner.load_session("s_corr_last_click")) == 1
|
||||
|
||||
def test_record_human_correction_rejects_out_of_bounds_coords(self, learner, monkeypatch):
|
||||
"""Une correction hors écran ne doit pas alimenter la mémoire."""
|
||||
captured = {}
|
||||
|
||||
def fake_memory_record_success(**kwargs):
|
||||
captured.update(kwargs)
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(
|
||||
"agent_v0.server_v1.replay_memory.memory_record_success",
|
||||
fake_memory_record_success,
|
||||
)
|
||||
|
||||
learner.record_human_correction(
|
||||
session_id="s_corr_oob",
|
||||
action={
|
||||
"action_id": "a_corr_oob",
|
||||
"target_spec": {"by_text": "Enregistrer", "window_title": "Bloc-notes"},
|
||||
},
|
||||
correction={
|
||||
"actions": [{"type": "click", "x_pct": 1.748, "y_pct": 0.135}],
|
||||
"last_click": {"type": "click", "x_pct": 1.748, "y_pct": 0.135},
|
||||
},
|
||||
)
|
||||
|
||||
assert captured == {}
|
||||
assert learner.load_session("s_corr_oob") == []
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# Boucle d'apprentissage : consolidation cross-workflow
|
||||
|
||||
Reference in New Issue
Block a user