chore: improved DDD layering#432
Merged
Merged
Conversation
Contributor
Reviewer's GuideRefactors domain services and parsers to be FastAPI-agnostic by operating purely on domain exceptions, adjusts parser and service behavior to propagate ParserBlizzardError/ParserParsingError through to the API layer, tightens lint rules to enforce DDD boundaries, and updates tests and documentation to reflect the new layering model and structured error payloads. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/players/services/test_player_service.py" line_range="378-387" />
<code_context>
+ async def test_unrecognized_exception_type_reraises_unmarked(self):
</code_context>
<issue_to_address>
**issue (testing):** Mock the cache instead of casting to Any to reliably assert `set_player_status` is not awaited.
Here the test relies on `cast("Any", svc.cache).set_player_status.assert_not_awaited()`, which only works if `svc.cache` happens to be a mock exposing that method. With a different implementation this could either raise a type error or, worse, silently stop testing what you intend.
To make the behavior explicit and reliable, please inject a mocked cache as in other tests:
```python
cache = AsyncMock()
svc = _make_service(cache=cache)
...
with pytest.raises(HTTPException) as exc_info:
await svc._handle_player_exceptions(error, "TeKrop-2217", identity)
assert exc_info.value is error
cache.set_player_status.assert_not_awaited()
```
This way the test definitively verifies that unknown-player marking is not triggered for non-domain `HTTPException` instances, independent of the concrete `svc.cache` implementation.
</issue_to_address>
### Comment 2
<location path="tests/players/services/test_player_service.py" line_range="272-273" />
<code_context>
async def test_disabled_feature_is_noop(self):
svc = _make_service()
- exc = HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="not found")
+ exc = ParserBlizzardError(
+ status_code=status.HTTP_404_NOT_FOUND, message="not found"
+ )
with patch("app.domain.services.player_service.settings") as s:
</code_context>
<issue_to_address>
**suggestion (testing):** Add assertions that `_mark_player_unknown` updates `ParserBlizzardError.message` with the structured payload.
Since `_mark_player_unknown` now mutates a `ParserBlizzardError` by replacing `message` with a dict containing `error`, `retry_after`, and `next_check_at`, add assertions in `test_404_marks_player` (and/or `test_404_increments_check_count`) to verify this, e.g.:
```python
assert isinstance(exc.message, dict)
assert exc.message["error"] == "Player not found"
assert "retry_after" in exc.message
assert "next_check_at" in exc.message
```
This ensures the exception is enriched with the structured payload expected by the API layer.
Suggested implementation:
```python
@pytest.mark.asyncio
async def test_404_marks_player(self):
svc = _make_service()
exc = ParserBlizzardError(
status_code=status.HTTP_404_NOT_FOUND, message="not found"
)
# existing setup / cache assertions above or below
await svc._mark_player_unknown("abc123", exc)
# ensure the exception was enriched with structured payload
assert isinstance(exc.message, dict)
assert exc.message["error"] == "Player not found"
assert "retry_after" in exc.message
assert "next_check_at" in exc.message
```
```python
@pytest.mark.asyncio
async def test_404_increments_check_count(self):
svc = _make_service()
exc = ParserBlizzardError(
status_code=status.HTTP_404_NOT_FOUND, message="not found"
)
# existing setup / cache assertions above or below
await svc._mark_player_unknown("abc123", exc)
# ensure the exception was enriched with structured payload
assert isinstance(exc.message, dict)
assert exc.message["error"] == "Player not found"
assert "retry_after" in exc.message
assert "next_check_at" in exc.message
```
I only see the `test_disabled_feature_is_noop` and `test_non_404_is_noop` tests in your snippet, so I’ve assumed the presence and approximate shape of `test_404_marks_player` and `test_404_increments_check_count` based on your comment.
To apply these edits, you may need to:
1. Adjust the `SEARCH` blocks to match the exact bodies of `test_404_marks_player` and `test_404_increments_check_count` in your file (especially comments or extra setup/teardown code).
2. If the error message used by `_mark_player_unknown` is different from `"Player not found"`, update the `exc.message["error"]` assertion accordingly.
3. If only one of the tests exists (e.g., only `test_404_marks_player`), include the assertion block only there.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary by Sourcery
Enforce framework-agnostic domain layering by having domain services and parsers raise and propagate domain-specific exceptions instead of FastAPI HTTPException, and update tests, linting, and documentation to reflect the new error-handling and layering rules.
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: