Backport StrEnum + replace enum imports, normalize retry APIs, and add async pytest hook#1
Backport StrEnum + replace enum imports, normalize retry APIs, and add async pytest hook#1HrachShah wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Reviewer's GuideBackports and centralizes a StrEnum implementation for compatibility across Python versions, standardizes retry helper APIs, and improves async test support while also making minor README and pytest configuration updates. Sequence diagram for retry_with_config and retry_with_backoffsequenceDiagram
participant Caller
participant RetryAPI as retry_with_config
participant Backoff as retry_with_backoff
participant CFactory as coro_factory
Caller->>RetryAPI: call(coro_factory, config, on_retry)
RetryAPI->>Backoff: retry_with_backoff(coro_factory, config.max_retries, config.base_delay, config.max_delay, on_retry)
loop up_to_max_retries
Backoff->>CFactory: create coroutine
CFactory-->>Backoff: coroutine
Backoff->>CFactory: await coroutine
alt success
Backoff-->>RetryAPI: result
RetryAPI-->>Caller: result
Backoff->>Backoff: break
else retryable_exception
Backoff->>RetryAPI: notify on_retry(retry_count, exception)
RetryAPI-->>Backoff: ack
Backoff->>Backoff: compute_next_delay_with_jitter()
Backoff->>Backoff: asyncio.sleep(delay)
else non_retryable_exception
Backoff-->>RetryAPI: raise exception
RetryAPI-->>Caller: propagate exception
Backoff->>Backoff: break
end
end
Sequence diagram for pytest async test execution via local hooksequenceDiagram
actor Dev as Developer
participant Pytest as pytest_runner
participant Hook as pytest_pyfunc_call
participant TestFunc as async_test
participant AsyncIO as asyncio_run
Dev->>Pytest: run tests
Pytest->>Hook: pytest_pyfunc_call(pyfuncitem)
alt test_is_coroutine_function and pytest_asyncio_not_installed
Hook->>AsyncIO: asyncio.run(TestFunc())
AsyncIO-->>Hook: test_result
Hook-->>Pytest: handled
else not_coroutine_or_other_plugin_handles
Hook-->>Pytest: fall_through
Pytest->>TestFunc: call synchronously
TestFunc-->>Pytest: test_result
end
Pytest-->>Dev: report results
Class diagram for StrEnum backport and enum usersclassDiagram
class Enum
class StrEnum {
}
class TaskFamily {
<<enum>>
CHAT
COMPLETION
EMBEDDING
EVAL
AGENT_LOOP
}
class Depth {
<<enum>>
SHALLOW
MEDIUM
DEEP
}
class Sensitivity {
<<enum>>
LOW
MEDIUM
HIGH
}
class LatencyClass {
<<enum>>
INTERACTIVE
NEARLINE
BATCH
}
class ContextTopology {
<<enum>>
SHORT
LONG
MULTI_TURN
MULTIMODAL
}
class ToolDependence {
<<enum>>
NONE
OPTIONAL
MANDATORY
}
class Determinism {
<<enum>>
LOW
MEDIUM
STRICT
}
class SafetyPosture {
<<enum>>
PERMISSIVE
STANDARD
LOCKED_DOWN
}
class OutputContract {
<<enum>>
PROSE
JSON
TOOL_CALLS
}
class EconomicPolicy {
<<enum>>
CHEAPEST
}
class CircuitState {
<<enum>>
CLOSED
}
class BenchmarkType {
<<enum>>
JSON_SCHEMA
}
Enum <|-- StrEnum
StrEnum <|-- TaskFamily
StrEnum <|-- Depth
StrEnum <|-- Sensitivity
StrEnum <|-- LatencyClass
StrEnum <|-- ContextTopology
StrEnum <|-- ToolDependence
StrEnum <|-- Determinism
StrEnum <|-- SafetyPosture
StrEnum <|-- OutputContract
StrEnum <|-- EconomicPolicy
StrEnum <|-- CircuitState
StrEnum <|-- BenchmarkType
class CompatModule {
_compat
+StrEnum
}
CompatModule ..> StrEnum
Flow diagram for async test marker and local hook interactionflowchart LR
A["Async test function
marked with asyncio"] --> B["pytest collects tests
using testpaths"]
B --> C["pytest_pyfunc_call hook
in tests.conftest"]
C --> D{Is function
coroutine?}
D -->|no| E["Run test normally"]
D -->|yes| F{pytest-asyncio
installed?}
F -->|yes| G["Let pytest-asyncio
manage async execution"]
F -->|no| H["Use asyncio.run
on coroutine"]
G --> I["Test result"]
H --> I
E --> I
I --> J["Report outcome
in pytest summary"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Motivation
StrEnumavailability across supported Python runtimes by providing a small backport for pre-3.11 environments.enum.StrEnumand centralize compatibility to avoid runtime import errors on older interpreters.pytesthook so coroutine tests can run even withoutpytest-asyncioinstalled.Description
freerelay/_compat.pywhich backportsStrEnumfor Python < 3.11 and exports it for internal use.from enum import StrEnumand relatedenumusages withfrom freerelay._compat import StrEnumacross multiple modules (control_plane,data_plane,core,shared,skills, etc.).func->coro_factory), incore/execution/retry.pyanddata_plane/execution/retry.py.README.mdwith additional badges and a short "Support FreeRelay" snippet.pyproject.tomlpytest config by removingasyncio_modeand adding amarkersentry for local async tests.tests/conftest.pyimplementingpytest_pyfunc_callto run coroutine test functions withasyncio.runwhenpytest-asynciois not available.Testing
pytest -qusing the new local hook to execute coroutine tests, and the run completed successfully.Codex Task
Summary by Sourcery
Introduce a StrEnum compatibility layer, align internal usages to it, streamline retry helpers, and improve async testing and project documentation.
New Features:
Enhancements:
Tests: