052591281d
- Complete agent system with planning and execution - Bridge API with FastAPI server - WhatsApp-style mobile dashboard - Enhanced web search with query improvement - Security guards and policy checks - Comprehensive documentation
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""Flaky test tool — deterministic fail-once-then-succeed behavior.
|
|
|
|
Used exclusively for testing retry logic (goal: "test retry execution").
|
|
|
|
Behavior:
|
|
Attempt 1: flag file does NOT exist → creates flag → returns FAILED
|
|
(failure_class: execution_error → eligible for 1 retry)
|
|
Attempt 2: flag file EXISTS → removes flag → returns DONE
|
|
|
|
The flag file is workspace/.flaky_test_flag.
|
|
It is always cleaned up on the second attempt, so repeated test runs work correctly.
|
|
|
|
Edge case: if the run is aborted between attempt 1 and attempt 2, the flag file
|
|
will persist. The next run will then succeed on attempt 1 (no retry exercised).
|
|
To reset: delete agent/workspace/.flaky_test_flag manually.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from core.state import PlanStep, StepResult, StepStatus
|
|
|
|
# parents: [0]=tools, [1]=runtime, [2]=agent → agent/workspace
|
|
_WORKSPACE_ROOT: Path = Path(__file__).resolve().parents[2] / "workspace"
|
|
_FLAG: Path = _WORKSPACE_ROOT / ".flaky_test_flag"
|
|
|
|
|
|
def run_flaky(step: PlanStep) -> StepResult:
|
|
"""Fail on first call, succeed on second (flag-based)."""
|
|
_WORKSPACE_ROOT.mkdir(parents=True, exist_ok=True)
|
|
|
|
if _FLAG.exists():
|
|
# Second call: cleanup flag, succeed
|
|
_FLAG.unlink()
|
|
return StepResult(
|
|
step_id=step.step_id,
|
|
status=StepStatus.DONE,
|
|
output_text="flaky step succeeded on retry (flag removed)",
|
|
)
|
|
else:
|
|
# First call: create flag, fail with execution_error prefix for classifier
|
|
_FLAG.touch()
|
|
return StepResult(
|
|
step_id=step.step_id,
|
|
status=StepStatus.FAILED,
|
|
error="execution_error: simulated transient failure on attempt 1",
|
|
)
|