MON-199535 Factorize Tools Implementation#231
Conversation
denrou
left a comment
There was a problem hiding this comment.
🔍 Automated Review — Action Required
Reviewed with the Centreon automated review skill. Complexity: medium–high — Recommended reviewers: 2. All 84 tests pass and CI is green; the refactor itself is clean and consistent. See inline comments for details.
🔴 Critical
- Default sort order dropped for all list endpoints —
components/base.py. The new_listsendssort_by=Nonewhen noorderis passed, where the old helper always applied each model's default sort field. This silently changes default result ordering (and pagination) for all 11 list tools. See inline comment.
🟠 Important
- No test coverage for the new generic helpers — the component tests mock
_list/_create/_delete/_patch, socomponents/base.pyis never executed (regression for_delete's aggregation logic). See inline comment. - Dead code: the old generic
_listinutils/base.py(~L37) is now unused after this refactor and can be removed.
🟡 Suggestion
- Stale test comment in
test_component_host.py. See inline comment.
🤖 Generated with Claude Code
| return await model.list(search, limit, page, sort_by) | ||
|
|
||
|
|
||
| async def _delete[CentreonModel: DeleteMixin]( |
There was a problem hiding this comment.
These new generic helpers have no direct test coverage — every component test mocks _list/_create/_delete/_patch at the module level, so the real implementations here are never executed. This is a coverage regression for _delete in particular: the asyncio.gather(..., return_exceptions=True) + dict(zip(..., strict=True)) aggregation previously ran for real in each component delete test (only Model.delete was mocked). A dedicated test_component_base.py covering _delete success/exception paths and _list's sort_by would also catch the default-ordering issue above.
Ticket Jira: MON-199535
What ?
Factorize tool implementations.
Why ?
Some components related to models inheriting from the same mixins have a common implementation of tools such as
create,list, anddelete. Defining generic CRUD tools will simplify the code by removing redundancy.How ?
_create,_list,_delete,_patchmethods in a newcomponents.base.py.