Skip to content

Extract tool and type lookup crud modules - #2600

Merged
akwasigroch merged 1 commit into
mainfrom
refactor/extract-tool-type-lookup-crud
Aug 25, 2026
Merged

Extract tool and type lookup crud modules#2600
akwasigroch merged 1 commit into
mainfrom
refactor/extract-tool-type-lookup-crud

Conversation

@akwasigroch

Copy link
Copy Markdown
Collaborator

Purpose

app/crud/__init__.py is the crud monolith that apps/backend/AGENTS.md says should only shrink from here. This continues the incremental split started in #2588, #2590, #2591 and #2592, taking the Tool and TypeLookup blocks off the tail of the file.

What Changed

  • New crud/tool.py (_TOOL_RELATED_FIELDS, get_tool, get_tools, create_tool, update_tool, delete_tool) and crud/type_lookup.py (get_type_lookup, get_type_lookups, create_type_lookup, update_type_lookup, delete_type_lookup, get_type_lookup_by_name_and_value), moved verbatim from crud/__init__.py.
  • 141 lines removed from crud/__init__.py, 998 → 857. No re-exports left behind — the old names are gone from the monolith.
  • Callers switched to direct submodule imports: routers/tools.py, routers/type_lookup.py, services/source.py, services/task_notification.py, services/tool/actions.py, services/tool/mcp/config.py, services/tool/rest/config.py, services/tool/rest/health.py and services/tool/rest/jira.py. All but two of those only used the monolith for these entities, so the from rhesis.backend.app import crud import is dropped where it became unused.
  • Patch targets and mock variable names updated in tests/backend/services/test_mcp_service.py, test_rest_health.py, test_rest_config.py and test_jira_rest.py — these patch the module attribute by string, so the targets move from ...config.crud to ...config.tool_crud / .type_lookup_crud depending on which entity the block exercises.

This is a pure move: the two new module bodies were diffed byte-for-byte against the removed blocks.

Additional Context

  • Tool and TypeLookup ship together because they share caller files (routers/tools.py, services/tool/*); splitting them into two PRs would make the two fight over the same lines.
  • services/task_notification.py was reached through a direct name import (from rhesis.backend.app.crud import get_status, get_type_lookup) rather than attribute access, so it does not show up in a crud.get_type_lookup grep. It keeps get_status on the monolith for now.
  • get_or_create_type_lookup lives in utils/crud_utils.py and is left alone.
  • Two sibling PRs split other blocks of the same file in parallel. They touch different line ranges, but the one that lands second will need a trivial conflict resolution on the task_notification.py import line.
  • ruff format also tidied a few pre-existing over-long dict literals and hand-wrapped @patch decorators in test_mcp_service.py and test_rest_config.py as a side effect of formatting those files.

Testing

uv run pytest tests/backend/services/ → 1976 passed, 14 skipped, 1 xfailed.

uv run pytest tests/backend/routes/test_type_lookup.py tests/backend/routes/test_tools_*.py tests/backend/routes/test_source.py → 148 passed, 4 skipped.

Ruff check and format on all 16 touched files are at the pre-change baseline.

Continues the incremental split of the crud monolith. Tool and TypeLookup
move to their own modules; callers switch to direct submodule imports.
Pure move -- no logic changes.
@akwasigroch
akwasigroch force-pushed the refactor/extract-tool-type-lookup-crud branch from 77d7376 to cdcd6c5 Compare August 25, 2026 15:13
@akwasigroch
akwasigroch merged commit ee940b0 into main Aug 25, 2026
15 of 17 checks passed
@akwasigroch
akwasigroch deleted the refactor/extract-tool-type-lookup-crud branch August 25, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant