- Notifications
You must be signed in to change notification settings - Fork 0
Fix session service validator coroutine handling #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdjusts session service validation to support coroutine-based get_session methods using an is_coroutine flag, centralizes mismatch TypeError raising, and adds guarded close() on awaitable results with debug logging on failure. Updates unit tests to reflect acceptance of proper async implementations and removes previous expectation of TypeError for coroutines. Changes
Sequence Diagram(s)sequenceDiagram autonumber participant V as Validator participant S as SessionService participant R as Result Note over V: Validation entry V->>S: get_session(...) alt Method is async (is_coroutine=true) S-->>V: Awaitable V->>R: await result Note over V,R: Centralized handling else Method is sync (is_coroutine=false) S-->>V: Value or Awaitable alt Got Awaitable but method not async V-->>V: Raise TypeError (mismatch) else Got Value Note over V: Proceed end end rect rgba(200, 230, 255, 0.2) Note over V,R: Best-effort cleanup V->>R: try result.close() R-->>V: may fail Note over V: On failure: debug log, continue end Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/core/testing/interfaces.py (1)
86-93
: Broad exception acceptable for cleanup, but consider logging the exception type.The broad
Exception
catch is appropriate for cleanup code where we don't want close() failures to propagate. However, consider logging the exception type to help with debugging if unexpected exceptions occur during validation.Apply this diff to log the exception type:
try: close() - except Exception: + except Exception as e: if logger.isEnabledFor(logging.DEBUG): logger.debug( - "Failed to close coroutine produced during validation", + f"Failed to close coroutine produced during validation: {type(e).__name__}", exc_info=True, )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/testing/interfaces.py
(2 hunks)tests/unit/core/testing/test_interfaces.py
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py
: Avoid using emojis in Python code comments or docstrings
Follow PEP 8 and use type hints for all functions
Import order must be: standard library, third-party, then local imports, separated by blank lines
Naming conventions: snake_case for variables and functions; PascalCase for classes
Error handling: use specific exceptions and include meaningful error messages
Prefer f-strings for string formatting
Files:
tests/unit/core/testing/test_interfaces.py
src/core/testing/interfaces.py
src/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.py
: Catch specific exceptions; avoid broad except Exception blocks
If a broad exception must be caught, log with exc_info=True and re-raise a specific custom exception
Use the most specific exception class from src.core.common.exceptions that accurately describes the error
Provide clear, helpful error messages and include relevant details in the details dictionary of custom exceptions
Files:
src/core/testing/interfaces.py
🧬 Code graph analysis (1)
tests/unit/core/testing/test_interfaces.py (2)
src/core/interfaces/session_service_interface.py (1)
ISessionService
(8-37)src/core/testing/interfaces.py (2)
TestServiceValidator
(42-146)validate_session_service
(49-109)
🪛 Ruff (0.13.3)
src/core/testing/interfaces.py
88-88: Do not catch blind exception: Exception
(BLE001)
96-100: Abstract raise
to an inner function
(TRY301)
96-100: Avoid specifying long messages outside the exception class
(TRY003)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test (3.10)
🔇 Additional comments (3)
src/core/testing/interfaces.py (2)
71-71
: LGTM! Good approach to capture async status upfront.Storing the coroutine status before calling the method enables proper validation of the consistency between the method signature and its return value.
95-105
: TestServiceValidator supports sync and async by design
SyncSessionManager’s synchronous get_session is an intended use-case to avoid coroutine warnings in tests. No changes required.Likely an incorrect or invalid review comment.
tests/unit/core/testing/test_interfaces.py (1)
74-84
: LGTM! Test correctly validates the new coroutine-friendly behavior.The test changes properly reflect the updated validation logic:
- Renamed from
bad_get_session
togood_get_session
to indicate the expected behavior- Updated docstring to describe a "proper coroutine implementation"
- Removed the
pytest.raises(TypeError)
expectation, now asserting that validation passes- Uses a properly declared async function that returns a Session
This correctly validates that well-behaved async implementations are now accepted by the validator.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Closing this PR due to significant flaws identified during automated code review. |
Summary
TestServiceValidator.validate_session_service
to handle coroutine-basedget_session
implementations while preserving AsyncMock safeguardsTesting
https://chatgpt.com/codex/tasks/task_e_68ec26ffb7448333ace9a74c4ba180a1
Summary by CodeRabbit