UAT: application/services/plan_apply_service.py violates clean architecture — imports from cli (presentation) layer at line 344 #4125

Closed
opened 2026-04-06 10:30:29 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/plan-apply-service-clean-arch-violation
  • Commit Message: fix(application): remove cli layer import from PlanApplyService.render_artifacts
  • Milestone: (none — backlog)
  • Parent Epic: #946

Bug Report

Feature Area: Code Organization and Module Structure
Tested by: UAT tester instance uat-tester-code-org-001
Severity: Medium (Clean Architecture layer boundary violation)

What Was Tested

Checked the codebase for clean architecture layer boundary violations — specifically whether the application layer imports from the presentation layer (cli/tui), which is a dependency inversion violation.

Expected Behavior (from CONTRIBUTING.md)

CONTRIBUTING.md line 402 states: "Clean Architecture: Separate concerns, maintain clear boundaries between layers."

In clean architecture, the application layer must NOT import from the CLI or TUI (presentation) layer. Formatting concerns belong in the presentation layer, not the application layer.

Actual Behavior

src/cleveragents/application/services/plan_apply_service.py imports from the CLI (presentation) layer inside a method at line 344:

def render_artifacts(self, plan_id: str, fmt: str = "json") -> str:
    ...
    from cleveragents.cli.formatting import format_output  # line 344
    ...
    return format_output(data, fmt)

This creates an upward dependency: applicationcli, which violates the clean architecture dependency rule. The application service should not depend on CLI formatting utilities.

Evidence

$ grep -n "from cleveragents.cli" src/cleveragents/application/services/plan_apply_service.py
344:        from cleveragents.cli.formatting import format_output

Steps to Reproduce

grep -rn "from cleveragents.cli\|from cleveragents.tui" src/cleveragents/application/ --include="*.py"

Impact

  • The application service cannot be used without the CLI layer being present
  • Unit testing PlanApplyService.render_artifacts() requires CLI dependencies
  • Breaks the clean architecture dependency rule
  • This is also a function-level import, violating CONTRIBUTING.md line 1379-1383

Suggested Fix

Move format_output to a shared utility module (e.g., shared/formatting.py) or pass a formatting callable as a dependency to the service. The application layer should not know about CLI-specific formatting.

Code Location

src/cleveragents/application/services/plan_apply_service.py line 344

Subtasks

  • Audit src/cleveragents/application/ for all imports from cleveragents.cli or cleveragents.tui
  • Create src/cleveragents/shared/formatting.py (or equivalent shared utility) with a format_output function
  • Refactor PlanApplyService.render_artifacts to use the shared utility instead of the CLI import
  • Update all callers of format_output in the CLI layer to import from the new shared location
  • Write Behave unit tests for the shared formatting utility
  • Verify no remaining applicationcli/tui imports exist
  • Run nox -e typecheck to confirm no type errors introduced
  • Run nox -e lint to confirm no linting violations

Definition of Done

  • All subtasks above are completed and checked
  • src/cleveragents/application/services/plan_apply_service.py contains no imports from cleveragents.cli or cleveragents.tui
  • A grep audit confirms zero applicationcli/tui imports remain
  • Shared formatting utility is in the correct architectural layer
  • All nox stages pass
  • Coverage >= 97%
  • Fix commit pushed to fix/plan-apply-service-clean-arch-violation with message fix(application): remove cli layer import from PlanApplyService.render_artifacts
  • Associated PR merged

Backlog note: This issue was discovered during autonomous operation
on milestone v3.5.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/plan-apply-service-clean-arch-violation` - **Commit Message**: `fix(application): remove cli layer import from PlanApplyService.render_artifacts` - **Milestone**: *(none — backlog)* - **Parent Epic**: #946 ## Bug Report **Feature Area:** Code Organization and Module Structure **Tested by:** UAT tester instance uat-tester-code-org-001 **Severity:** Medium (Clean Architecture layer boundary violation) ### What Was Tested Checked the codebase for clean architecture layer boundary violations — specifically whether the application layer imports from the presentation layer (cli/tui), which is a dependency inversion violation. ### Expected Behavior (from CONTRIBUTING.md) CONTRIBUTING.md line 402 states: *"Clean Architecture: Separate concerns, maintain clear boundaries between layers."* In clean architecture, the application layer must NOT import from the CLI or TUI (presentation) layer. Formatting concerns belong in the presentation layer, not the application layer. ### Actual Behavior `src/cleveragents/application/services/plan_apply_service.py` imports from the CLI (presentation) layer inside a method at line 344: ```python def render_artifacts(self, plan_id: str, fmt: str = "json") -> str: ... from cleveragents.cli.formatting import format_output # line 344 ... return format_output(data, fmt) ``` This creates an upward dependency: `application` → `cli`, which violates the clean architecture dependency rule. The application service should not depend on CLI formatting utilities. ### Evidence ``` $ grep -n "from cleveragents.cli" src/cleveragents/application/services/plan_apply_service.py 344: from cleveragents.cli.formatting import format_output ``` ### Steps to Reproduce ```bash grep -rn "from cleveragents.cli\|from cleveragents.tui" src/cleveragents/application/ --include="*.py" ``` ### Impact - The application service cannot be used without the CLI layer being present - Unit testing `PlanApplyService.render_artifacts()` requires CLI dependencies - Breaks the clean architecture dependency rule - This is also a function-level import, violating CONTRIBUTING.md line 1379-1383 ### Suggested Fix Move `format_output` to a shared utility module (e.g., `shared/formatting.py`) or pass a formatting callable as a dependency to the service. The application layer should not know about CLI-specific formatting. ### Code Location `src/cleveragents/application/services/plan_apply_service.py` line 344 ## Subtasks - [ ] Audit `src/cleveragents/application/` for all imports from `cleveragents.cli` or `cleveragents.tui` - [ ] Create `src/cleveragents/shared/formatting.py` (or equivalent shared utility) with a `format_output` function - [ ] Refactor `PlanApplyService.render_artifacts` to use the shared utility instead of the CLI import - [ ] Update all callers of `format_output` in the CLI layer to import from the new shared location - [ ] Write Behave unit tests for the shared formatting utility - [ ] Verify no remaining `application` → `cli`/`tui` imports exist - [ ] Run `nox -e typecheck` to confirm no type errors introduced - [ ] Run `nox -e lint` to confirm no linting violations ## Definition of Done - [ ] All subtasks above are completed and checked - [ ] `src/cleveragents/application/services/plan_apply_service.py` contains no imports from `cleveragents.cli` or `cleveragents.tui` - [ ] A grep audit confirms zero `application` → `cli`/`tui` imports remain - [ ] Shared formatting utility is in the correct architectural layer - [ ] All nox stages pass - [ ] Coverage >= 97% - [ ] Fix commit pushed to `fix/plan-apply-service-clean-arch-violation` with message `fix(application): remove cli layer import from PlanApplyService.render_artifacts` - [ ] Associated PR merged > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.5.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Author
Owner

DUPLICATE: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations"

This UAT finding about clean architecture violation in plan_apply_service.py is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic.

Action: Closing as duplicate in favor of Epic #4179

**DUPLICATE**: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations" This UAT finding about clean architecture violation in `plan_apply_service.py` is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic. **Action**: Closing as duplicate in favor of Epic #4179
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.

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