Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions gateframe/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading