diff --git a/gateframe/core/context.py b/gateframe/core/context.py index 2064985..8ffd855 100644 --- a/gateframe/core/context.py +++ b/gateframe/core/context.py @@ -110,6 +110,17 @@ def update(self, result: ValidationResult) -> None: threshold_breached=self.threshold_breached, ) + def reset(self) -> None: + self.confidence = self._initial_confidence + self._history.clear() + + logger.info( + "workflow_reset", + workflow_id=self.workflow_id, + confidence=self.confidence, + threshold_breached=self.threshold_breached, + ) + def _compute_penalty(self, result: ValidationResult) -> float: penalty = 0.0 for failure in result.failures: diff --git a/tests/core/test_context.py b/tests/core/test_context.py index 19550e9..60cef47 100644 --- a/tests/core/test_context.py +++ b/tests/core/test_context.py @@ -180,6 +180,19 @@ def test_passing_step_keeps_confidence(self) -> None: ctx.update(_make_result(passed=True)) assert ctx.confidence == 1.0 + def test_reset_restores_initial_confidence_and_clears_history(self) -> None: + ctx = WorkflowContext("wf1", initial_confidence=0.8) + ctx.update(_make_result(passed=False, failures=[_soft_failure()])) + assert ctx.confidence == pytest.approx(0.65) + assert ctx.step_count == 1 + + ctx.reset() + + assert ctx.confidence == pytest.approx(0.8) + assert ctx.step_count == 0 + assert ctx.history == [] + assert ctx.threshold_breached is False + class TestStepRecord: def test_to_dict(self) -> None: