CMLDEV-1110: added reload_definitions method to NodeImageDefinitions;…#227
Conversation
… Included brief test coverage;
| url = self._url_for("image_def", definition_id=definition_id) | ||
| self._session.delete(url) | ||
|
|
||
| def reload_definitions(self) -> dict[str, Any]: |
There was a problem hiding this comment.
[Bug (New) - Confidence: 90%] Missing @_requires_version("2.10.0") decorator.
The server endpoint is gated to CML 2.10+ via CMLVersion.V2_10.introduced() in webserver/simple_webserver/api/system.py. Without the decorator, calling this method against a 2.9.x controller produces a generic 404 / HTTPError instead of the codebase's standard FeatureNotSupported exception. Sibling version-gated methods in lab_repository.py (sync_lab_repositories, refresh_lab_repositories, get_lab_repositories, add_lab_repository) all use this pattern.
Suggested change:
from ..utils import _requires_version, get_url_from_template
# ...
@_requires_version("2.10.0")
def reload_definitions(self) -> dict[str, dict[str, list[str]]]:
...| url = self._url_for("image_def", definition_id=definition_id) | ||
| self._session.delete(url) | ||
|
|
||
| def reload_definitions(self) -> dict[str, Any]: |
There was a problem hiding this comment.
[Nit (New) - Confidence: 50%] dict[str, Any] discards the well-defined server response shape.
The server returns DefinitionReportResponse — two fixed top-level keys (node_definitions, image_definitions), each mapping to a dict of unchanged/updated/new/removed/failed lists of strings. A narrower annotation conveys the same shape without introducing new public symbols:
def reload_definitions(self) -> dict[str, dict[str, list[str]]]:
...Other methods on this class are equally loose (dict[str, Any] / list[dict[str, Any]]), so this is optional polish for consistency.
|
|
||
| report = defs.reload_definitions() | ||
| assert report == expected_report | ||
| assert session.put.mock_calls[0].args[0] == "reload_definitions" |
There was a problem hiding this comment.
[Nit (New) - Confidence: 40%] Test hard-codes "reload_definitions" instead of going through _url_for("reload_defs") / _URL_TEMPLATES. Renaming the template key without updating the URL would not be caught here.
This matches the existing pattern in this file though (other tests don't assert on the URL at all), so optional.
AI-Assisted Code Review Summary
Linked Jira: CMLDEV-1110 Scope checkTight, focused PR (2 files, +63 / −0). Cross-checked against the server-side endpoint in the Two server-side constraints aren't reflected on the client:
Major (should fix)
Minor (negligible / nits)
Things done well
Confidence percentages reflect certainty: lower values may be false positives. Origin column: New = introduced by this PR, Pre-existing = already in the codebase (consider fixing opportunistically). All findings here are New. |
Per PR #227 review: - Decorate reload_definitions with @_requires_version("2.10.0") so older controllers raise FeatureNotSupported instead of bubbling up an HTTPError for a missing route. The server endpoint is annotated CMLVersion.V2_10.introduced() and gated by IsAdminPermDepends. - Surface the version floor and admin-only requirement in the docstring. - Tighten return type from dict[str, Any] to dict[str, dict[str, list[str]]], mirroring the server's DefinitionReportResponse shape. - Anchor the test URL assertion to _URL_TEMPLATES["reload_defs"] so renaming the template key would surface a failure.
… Included brief test coverage;