[AUTO-GUARD-2] Refactor: Long functions in repositories.py #9649

Open
opened 2026-04-15 01:16:30 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: refactor: decompose long functions in repositories.py
  • Branch name: refactor/auto-guard-2-long-functions-repositories

Background and Context

Several functions in src/cleveragents/infrastructure/database/repositories.py exceed the recommended 50-line limit. Long functions are harder to read, understand, test, and maintain. They often violate the Single Responsibility Principle and make it difficult to reason about individual units of logic.

Long functions identified:

  • update (starts at line 1060, ~126 lines)
  • create (starts at line 1789, ~86 lines)
  • update (starts at line 1918, ~90 lines)
  • create (starts at line 2132, ~76 lines)
  • auto_discover_children (starts at line 2601, ~145 lines)
  • attach (starts at line 3812, ~104 lines)
  • prune (starts at line 5733, ~81 lines)

These functions should be refactored into smaller, more manageable helper functions.

Expected Behavior

Each of the identified functions should be decomposed into smaller private helper functions, each no longer than 50 lines. The public API and behavior of the repository classes must remain unchanged. All existing tests must continue to pass.

Acceptance Criteria

  • All 7 identified functions are refactored to be ≤ 50 lines each
  • Each extracted helper function has a clear, descriptive name reflecting its responsibility
  • No public API changes — all existing callers continue to work without modification
  • All existing tests pass without modification
  • New helper functions are covered by existing tests (or new unit tests are added where coverage is missing)
  • nox passes with test coverage ≥ 97%
  • No regressions introduced in database repository behavior

Subtasks

  • Refactor update (line 1060, ~126 lines) — extract helper functions for sub-steps
  • Refactor create (line 1789, ~86 lines) — extract helper functions for sub-steps
  • Refactor update (line 1918, ~90 lines) — extract helper functions for sub-steps
  • Refactor create (line 2132, ~76 lines) — extract helper functions for sub-steps
  • Refactor auto_discover_children (line 2601, ~145 lines) — extract helper functions for sub-steps
  • Refactor attach (line 3812, ~104 lines) — extract helper functions for sub-steps
  • Refactor prune (line 5733, ~81 lines) — extract helper functions for sub-steps
  • Run full test suite and confirm all tests pass
  • Verify coverage ≥ 97% with nox

Definition of Done

This issue should be closed when:

  1. All 7 long functions have been decomposed into helper functions of ≤ 50 lines each
  2. The full test suite passes with no regressions
  3. Test coverage remains ≥ 97%
  4. A PR has been reviewed and merged into the main branch

Automated by CleverAgents Bot
Agent: new-issue-creator
Supervisor: Architecture Guard | Agent: architecture-guard-pool-supervisor

## Metadata - **Commit message:** `refactor: decompose long functions in repositories.py` - **Branch name:** `refactor/auto-guard-2-long-functions-repositories` ## Background and Context Several functions in `src/cleveragents/infrastructure/database/repositories.py` exceed the recommended 50-line limit. Long functions are harder to read, understand, test, and maintain. They often violate the Single Responsibility Principle and make it difficult to reason about individual units of logic. **Long functions identified:** - `update` (starts at line 1060, ~126 lines) - `create` (starts at line 1789, ~86 lines) - `update` (starts at line 1918, ~90 lines) - `create` (starts at line 2132, ~76 lines) - `auto_discover_children` (starts at line 2601, ~145 lines) - `attach` (starts at line 3812, ~104 lines) - `prune` (starts at line 5733, ~81 lines) These functions should be refactored into smaller, more manageable helper functions. ## Expected Behavior Each of the identified functions should be decomposed into smaller private helper functions, each no longer than 50 lines. The public API and behavior of the repository classes must remain unchanged. All existing tests must continue to pass. ## Acceptance Criteria - [ ] All 7 identified functions are refactored to be ≤ 50 lines each - [ ] Each extracted helper function has a clear, descriptive name reflecting its responsibility - [ ] No public API changes — all existing callers continue to work without modification - [ ] All existing tests pass without modification - [ ] New helper functions are covered by existing tests (or new unit tests are added where coverage is missing) - [ ] `nox` passes with test coverage ≥ 97% - [ ] No regressions introduced in database repository behavior ## Subtasks - [ ] Refactor `update` (line 1060, ~126 lines) — extract helper functions for sub-steps - [ ] Refactor `create` (line 1789, ~86 lines) — extract helper functions for sub-steps - [ ] Refactor `update` (line 1918, ~90 lines) — extract helper functions for sub-steps - [ ] Refactor `create` (line 2132, ~76 lines) — extract helper functions for sub-steps - [ ] Refactor `auto_discover_children` (line 2601, ~145 lines) — extract helper functions for sub-steps - [ ] Refactor `attach` (line 3812, ~104 lines) — extract helper functions for sub-steps - [ ] Refactor `prune` (line 5733, ~81 lines) — extract helper functions for sub-steps - [ ] Run full test suite and confirm all tests pass - [ ] Verify coverage ≥ 97% with `nox` ## Definition of Done This issue should be closed when: 1. All 7 long functions have been decomposed into helper functions of ≤ 50 lines each 2. The full test suite passes with no regressions 3. Test coverage remains ≥ 97% 4. A PR has been reviewed and merged into the main branch --- **Automated by CleverAgents Bot** Agent: new-issue-creator Supervisor: Architecture Guard | Agent: architecture-guard-pool-supervisor
Author
Owner
[AUTO-OWNR-1] Triage complete.

**Verified** ✅ — Valid refactoring task. Long functions in repositories.py reduce maintainability.

- **Type**: Task (refactoring)
- **Priority**: Low
- **MoSCoW**: Could Have — code quality improvement, not blocking milestone acceptance criteria

---
**Automated by CleverAgents Bot**
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

Automated by CleverAgents Bot
Agent: automation-tracking-manager

``` [AUTO-OWNR-1] Triage complete. **Verified** ✅ — Valid refactoring task. Long functions in repositories.py reduce maintainability. - **Type**: Task (refactoring) - **Priority**: Low - **MoSCoW**: Could Have — code quality improvement, not blocking milestone acceptance criteria --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor ``` --- **Automated by CleverAgents Bot** Agent: automation-tracking-manager
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9649
No description provided.