UAT: ADR-001 Violation — CLI (Presentation) layer directly imports from Infrastructure layer, bypassing Application layer #4052

Open
opened 2026-04-06 09:37:31 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/adr-001-cli-infrastructure-imports
  • Commit Message: fix(architecture): remove infrastructure imports from CLI presentation layer
  • Milestone: None (backlog — see note below)
  • Parent Epic: #397

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.

Bug Report

What was tested: ADR-001 (Layered Architecture) compliance — specifically the strict dependency rule that outer layers must only depend on inner layers through the Application layer

Expected behavior (from ADR-001):
ADR-001 mandates a strict four-layer architecture with the rule: "outer layers depend on inner layers, never the reverse." Specifically:

  • "Presentation Layer components must not call Domain or Infrastructure layers directly; they must go through Application Layer service facades."
  • "No import from infrastructure in domain."
  • The CLI (Presentation layer) must ONLY call Application Layer service facades.

Actual behavior:
The CLI (Presentation layer) directly imports from the Infrastructure layer, bypassing the Application layer service facades. This violates the hexagonal architecture boundary.

Affected files:

src/cleveragents/cli/commands/plan.py:3280:
    from cleveragents.infrastructure.database.unit_of_work import UnitOfWork

src/cleveragents/cli/commands/resource.py:655:
    from cleveragents.infrastructure.database.models import (ResourceEdgeModel, ResourceModel)

src/cleveragents/cli/commands/resource.py:1294:
    from cleveragents.infrastructure.database.models import (ResourceEdgeModel, ResourceModel)

src/cleveragents/cli/commands/validation.py:88:
    from cleveragents.infrastructure.database.repositories import (...)

src/cleveragents/cli/commands/tool.py:88:
    from cleveragents.infrastructure.database.repositories import (...)

src/cleveragents/cli/commands/db.py:29:
    from cleveragents.infrastructure.database.migration_runner import MigrationRunner

src/cleveragents/cli/commands/db.py:38:
    from cleveragents.infrastructure.database.migration_runner import MigrationRunner

Specific violations:

  1. cli/commands/resource.py directly queries ResourceEdgeModel and ResourceModel SQLAlchemy ORM models and calls session.query() directly — this is database access from the Presentation layer
  2. cli/commands/plan.py imports UnitOfWork directly — the Unit of Work pattern is an infrastructure concern
  3. cli/commands/validation.py and cli/commands/tool.py import repository implementations directly
  4. cli/commands/db.py imports MigrationRunner — database migrations are an infrastructure concern that should be exposed through an Application service

Steps to reproduce:

grep -r "from cleveragents.infrastructure" src/cleveragents/cli/ --include="*.py"

Impact:

  • Layer boundary violations make the codebase harder to test (CLI tests now require real database infrastructure)
  • Swapping infrastructure implementations (e.g., SQLite → PostgreSQL) requires changes in the CLI layer
  • The hexagonal architecture's isolation guarantees are broken
  • ADR-001's compliance requirement for "import linting" is not catching these violations

Fix:

  1. Move all database access from cli/commands/resource.py into ResourceRegistryService (Application layer) — add remove_resource_by_id() and unlink_resource_edges() methods
  2. Move UnitOfWork usage from cli/commands/plan.py into the PlanLifecycleService
  3. Move repository access from cli/commands/validation.py and cli/commands/tool.py into appropriate Application layer services
  4. Expose database migration through an Application layer service or keep db.py as a special infrastructure-adjacent command with explicit justification

Subtasks

  • Add remove_resource() method to ResourceRegistryService that handles edge cleanup internally
  • Remove direct ResourceEdgeModel/ResourceModel imports from cli/commands/resource.py
  • Move UnitOfWork usage from cli/commands/plan.py into PlanLifecycleService
  • Add repository-backed methods to application services for validation and tool commands
  • Add import-linter or architecture test to CI to prevent regression
  • Update unit tests to verify CLI commands only use Application layer services
  • Tests (Behave): Add scenarios for CLI layer boundary compliance
  • Verify coverage >=97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • Zero from cleveragents.infrastructure imports in src/cleveragents/cli/
  • All CLI commands interact exclusively with Application layer service facades
  • CI architecture test prevents regression
  • Existing CLI behavior is preserved (no functional regressions)
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/adr-001-cli-infrastructure-imports` - **Commit Message**: `fix(architecture): remove infrastructure imports from CLI presentation layer` - **Milestone**: None (backlog — see note below) - **Parent Epic**: #397 > **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. ## Bug Report **What was tested:** ADR-001 (Layered Architecture) compliance — specifically the strict dependency rule that outer layers must only depend on inner layers through the Application layer **Expected behavior (from ADR-001):** ADR-001 mandates a strict four-layer architecture with the rule: **"outer layers depend on inner layers, never the reverse."** Specifically: - "Presentation Layer components must not call Domain or Infrastructure layers directly; they must go through Application Layer service facades." - "No import from `infrastructure` in `domain`." - The CLI (Presentation layer) must ONLY call Application Layer service facades. **Actual behavior:** The CLI (Presentation layer) directly imports from the Infrastructure layer, bypassing the Application layer service facades. This violates the hexagonal architecture boundary. **Affected files:** ``` src/cleveragents/cli/commands/plan.py:3280: from cleveragents.infrastructure.database.unit_of_work import UnitOfWork src/cleveragents/cli/commands/resource.py:655: from cleveragents.infrastructure.database.models import (ResourceEdgeModel, ResourceModel) src/cleveragents/cli/commands/resource.py:1294: from cleveragents.infrastructure.database.models import (ResourceEdgeModel, ResourceModel) src/cleveragents/cli/commands/validation.py:88: from cleveragents.infrastructure.database.repositories import (...) src/cleveragents/cli/commands/tool.py:88: from cleveragents.infrastructure.database.repositories import (...) src/cleveragents/cli/commands/db.py:29: from cleveragents.infrastructure.database.migration_runner import MigrationRunner src/cleveragents/cli/commands/db.py:38: from cleveragents.infrastructure.database.migration_runner import MigrationRunner ``` **Specific violations:** 1. `cli/commands/resource.py` directly queries `ResourceEdgeModel` and `ResourceModel` SQLAlchemy ORM models and calls `session.query()` directly — this is database access from the Presentation layer 2. `cli/commands/plan.py` imports `UnitOfWork` directly — the Unit of Work pattern is an infrastructure concern 3. `cli/commands/validation.py` and `cli/commands/tool.py` import repository implementations directly 4. `cli/commands/db.py` imports `MigrationRunner` — database migrations are an infrastructure concern that should be exposed through an Application service **Steps to reproduce:** ```bash grep -r "from cleveragents.infrastructure" src/cleveragents/cli/ --include="*.py" ``` **Impact:** - Layer boundary violations make the codebase harder to test (CLI tests now require real database infrastructure) - Swapping infrastructure implementations (e.g., SQLite → PostgreSQL) requires changes in the CLI layer - The hexagonal architecture's isolation guarantees are broken - ADR-001's compliance requirement for "import linting" is not catching these violations **Fix:** 1. Move all database access from `cli/commands/resource.py` into `ResourceRegistryService` (Application layer) — add `remove_resource_by_id()` and `unlink_resource_edges()` methods 2. Move `UnitOfWork` usage from `cli/commands/plan.py` into the `PlanLifecycleService` 3. Move repository access from `cli/commands/validation.py` and `cli/commands/tool.py` into appropriate Application layer services 4. Expose database migration through an Application layer service or keep `db.py` as a special infrastructure-adjacent command with explicit justification ## Subtasks - [ ] Add `remove_resource()` method to `ResourceRegistryService` that handles edge cleanup internally - [ ] Remove direct `ResourceEdgeModel`/`ResourceModel` imports from `cli/commands/resource.py` - [ ] Move `UnitOfWork` usage from `cli/commands/plan.py` into `PlanLifecycleService` - [ ] Add repository-backed methods to application services for validation and tool commands - [ ] Add import-linter or architecture test to CI to prevent regression - [ ] Update unit tests to verify CLI commands only use Application layer services - [ ] Tests (Behave): Add scenarios for CLI layer boundary compliance - [ ] Verify coverage >=97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - Zero `from cleveragents.infrastructure` imports in `src/cleveragents/cli/` - All CLI commands interact exclusively with Application layer service facades - CI architecture test prevents regression - Existing CLI behavior is preserved (no functional regressions) - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass - Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:11:32 +00:00
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.

Blocks
#397 Epic: Server & Autonomy Infrastructure
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#4052
No description provided.