UAT: DecisionRepositoryProtocol missing 4 methods used by DecisionService — protocol/implementation contract mismatch #3707

Open
opened 2026-04-05 22:15:32 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/decision-repository-protocol-missing-methods
  • Commit Message: fix(domain): add missing methods to DecisionRepositoryProtocol — update_superseded_by, list_by_type, get_max_sequence_number, count
  • Milestone: (none — backlog)
  • Parent Epic: #394

Background

DecisionService calls four methods on ctx.decisions (the DecisionRepository accessed via UnitOfWork) that are not declared in the DecisionRepositoryProtocol domain port. This creates a contract mismatch: the protocol (the domain-layer interface) does not match the concrete implementation, meaning any code that depends on the protocol (type-checked code, mock implementations in features/mocks/) will not know about these methods.

Affected Files

  • src/cleveragents/domain/repositories/decision_repository.pyDecisionRepositoryProtocol (the port)
  • src/cleveragents/infrastructure/database/repositories.pyDecisionRepository (the adapter)
  • src/cleveragents/application/services/decision_service.py — calls the missing methods

Missing Methods

The DecisionRepositoryProtocol currently defines only:

  • create, get, get_by_plan, get_tree, get_path_to_root, get_superseded, delete

But DecisionService calls these additional methods on ctx.decisions:

  1. ctx.decisions.update_superseded_by(decision_id, new_decision_id) — called in mark_superseded() (line ~780)
  2. ctx.decisions.list_by_type(plan_id, str(decision_type)) — called in list_by_type() (line ~620)
  3. ctx.decisions.get_max_sequence_number(plan_id) — called in _rehydrate_sequence() (line ~870)
  4. ctx.decisions.count(plan_id) — called in count_decisions() (line ~730)

All four methods exist in the concrete DecisionRepository implementation in repositories.py but are absent from the DecisionRepositoryProtocol in decision_repository.py.

Steps to Reproduce

  1. Inspect src/cleveragents/domain/repositories/decision_repository.py — note only 7 methods defined
  2. Inspect src/cleveragents/application/services/decision_service.py — search for ctx.decisions.update_superseded_by, ctx.decisions.list_by_type, ctx.decisions.get_max_sequence_number, ctx.decisions.count
  3. Run nox -e typecheck — Pyright will report that these method calls are not valid on the protocol type

Expected Behaviour

DecisionRepositoryProtocol should declare all methods that DecisionService calls on it, so that:

  • Type checking passes (nox -e typecheck)
  • Mock implementations in features/mocks/ can implement the full contract
  • The domain layer accurately documents the persistence contract

Actual Behaviour

DecisionRepositoryProtocol is missing update_superseded_by, list_by_type, get_max_sequence_number, and count. Any mock or alternative implementation of the protocol will silently omit these methods, causing runtime AttributeError when DecisionService calls them.

Subtasks

  • Add update_superseded_by(decision_id: str, new_decision_id: str) -> Decision to DecisionRepositoryProtocol
  • Add list_by_type(plan_id: str, decision_type: str) -> list[Decision] to DecisionRepositoryProtocol
  • Add get_max_sequence_number(plan_id: str) -> int | None to DecisionRepositoryProtocol
  • Add count(plan_id: str) -> int to DecisionRepositoryProtocol
  • Update mock implementation in features/mocks/ to implement the new methods
  • Verify nox -e typecheck passes

Definition of Done

  • All 4 missing methods are declared in DecisionRepositoryProtocol with correct signatures and docstrings
  • Mock implementations updated
  • nox -e typecheck passes
  • nox -e unit_tests passes
  • PR merged

Backlog note: This issue was discovered during autonomous operation
on milestone . 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/decision-repository-protocol-missing-methods` - **Commit Message**: `fix(domain): add missing methods to DecisionRepositoryProtocol — update_superseded_by, list_by_type, get_max_sequence_number, count` - **Milestone**: *(none — backlog)* - **Parent Epic**: #394 ## Background `DecisionService` calls four methods on `ctx.decisions` (the `DecisionRepository` accessed via `UnitOfWork`) that are **not declared in the `DecisionRepositoryProtocol`** domain port. This creates a contract mismatch: the protocol (the domain-layer interface) does not match the concrete implementation, meaning any code that depends on the protocol (type-checked code, mock implementations in `features/mocks/`) will not know about these methods. ## Affected Files - `src/cleveragents/domain/repositories/decision_repository.py` — `DecisionRepositoryProtocol` (the port) - `src/cleveragents/infrastructure/database/repositories.py` — `DecisionRepository` (the adapter) - `src/cleveragents/application/services/decision_service.py` — calls the missing methods ## Missing Methods The `DecisionRepositoryProtocol` currently defines only: - `create`, `get`, `get_by_plan`, `get_tree`, `get_path_to_root`, `get_superseded`, `delete` But `DecisionService` calls these additional methods on `ctx.decisions`: 1. `ctx.decisions.update_superseded_by(decision_id, new_decision_id)` — called in `mark_superseded()` (line ~780) 2. `ctx.decisions.list_by_type(plan_id, str(decision_type))` — called in `list_by_type()` (line ~620) 3. `ctx.decisions.get_max_sequence_number(plan_id)` — called in `_rehydrate_sequence()` (line ~870) 4. `ctx.decisions.count(plan_id)` — called in `count_decisions()` (line ~730) All four methods exist in the concrete `DecisionRepository` implementation in `repositories.py` but are absent from the `DecisionRepositoryProtocol` in `decision_repository.py`. ## Steps to Reproduce 1. Inspect `src/cleveragents/domain/repositories/decision_repository.py` — note only 7 methods defined 2. Inspect `src/cleveragents/application/services/decision_service.py` — search for `ctx.decisions.update_superseded_by`, `ctx.decisions.list_by_type`, `ctx.decisions.get_max_sequence_number`, `ctx.decisions.count` 3. Run `nox -e typecheck` — Pyright will report that these method calls are not valid on the protocol type ## Expected Behaviour `DecisionRepositoryProtocol` should declare all methods that `DecisionService` calls on it, so that: - Type checking passes (`nox -e typecheck`) - Mock implementations in `features/mocks/` can implement the full contract - The domain layer accurately documents the persistence contract ## Actual Behaviour `DecisionRepositoryProtocol` is missing `update_superseded_by`, `list_by_type`, `get_max_sequence_number`, and `count`. Any mock or alternative implementation of the protocol will silently omit these methods, causing runtime `AttributeError` when `DecisionService` calls them. ## Subtasks - [ ] Add `update_superseded_by(decision_id: str, new_decision_id: str) -> Decision` to `DecisionRepositoryProtocol` - [ ] Add `list_by_type(plan_id: str, decision_type: str) -> list[Decision]` to `DecisionRepositoryProtocol` - [ ] Add `get_max_sequence_number(plan_id: str) -> int | None` to `DecisionRepositoryProtocol` - [ ] Add `count(plan_id: str) -> int` to `DecisionRepositoryProtocol` - [ ] Update mock implementation in `features/mocks/` to implement the new methods - [ ] Verify `nox -e typecheck` passes ## Definition of Done - All 4 missing methods are declared in `DecisionRepositoryProtocol` with correct signatures and docstrings - Mock implementations updated - `nox -e typecheck` passes - `nox -e unit_tests` passes - PR merged > **Backlog note:** This issue was discovered during autonomous operation > on milestone <M>. 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
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
#394 Epic: Decision Framework
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3707
No description provided.