[TDD] InvariantService: add failing BDD scenario proving invariants are not persisted to database across restarts #8548

Open
opened 2026-04-13 20:38:17 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: test(invariant): add failing BDD scenario proving invariants are not persisted across restarts
  • Branch: test/invariant-persistence-tdd

Background and Context

The v3.2.0 specification requires that invariant data is persisted to the database and is durable across restarts (Spec Requirement #6). UAT testing (worker [AUTO-UAT-2]) has confirmed that InvariantService uses in-memory storage only (self._invariants: dict[str, Invariant] = {}). There is no database table, no repository, and no Alembic migration for standalone global/project-scoped invariants. Any invariants added via agents invariant add are lost when the process exits.

This TDD issue captures the failing test that proves the bug exists. The test must be tagged @tdd_expected_fail so it passes CI while the underlying bug is unfixed.

Current Behavior

InvariantService.__init__ initializes self._invariants: dict[str, Invariant] = {} — a plain Python dict with no database backing. When the process restarts, all invariants added via agents invariant add are gone.

Expected Behavior

Invariants added via agents invariant add must survive process restarts. The InvariantService must persist to and load from the database (SQLite/PostgreSQL via SQLAlchemy), consistent with how other services (e.g., LifecyclePlanRepository, ActionRepository) work.

Acceptance Criteria

  • A new BDD feature file features/invariant_persistence.feature contains a scenario tagged @tdd_expected_fail that:
    1. Adds a global invariant via InvariantService
    2. Simulates a restart by creating a new InvariantService instance backed by the same database
    3. Asserts the invariant is still present after restart
    4. This scenario fails (proving the bug) until the fix is implemented
  • The scenario uses the @tdd_expected_fail tag so CI passes while the bug is open
  • All existing BDD tests continue to pass

Supporting Information

  • Spec requirement: "Invariant data is persisted to the database (durable across restarts)" — v3.2.0 milestone acceptance criteria
  • Affected file: src/cleveragents/application/services/invariant_service.pyInvariantService.__init__ uses self._invariants: dict[str, Invariant] = {}
  • No database table: No Alembic migration exists for a standalone invariants table (only action_invariants and plan_invariants child tables exist, which are different)
  • No repository: No InvariantRepository class exists in src/cleveragents/infrastructure/database/repositories.py
  • UAT finding: Confirmed by [AUTO-UAT-2] on 2026-04-13

Subtasks

  • Create features/invariant_persistence.feature with @tdd_expected_fail scenario
  • Implement step definitions in features/steps/invariant_persistence_steps.py
  • Verify the scenario fails (proving the bug) with nox -s bdd -- features/invariant_persistence.feature
  • Verify all other BDD tests still pass
  • 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.
  • 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.

Automated by CleverAgents Bot
Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor
Worker: [AUTO-UAT-2]

## Metadata - **Commit Message**: `test(invariant): add failing BDD scenario proving invariants are not persisted across restarts` - **Branch**: `test/invariant-persistence-tdd` ## Background and Context The v3.2.0 specification requires that invariant data is persisted to the database and is durable across restarts (Spec Requirement #6). UAT testing (worker [AUTO-UAT-2]) has confirmed that `InvariantService` uses **in-memory storage only** (`self._invariants: dict[str, Invariant] = {}`). There is no database table, no repository, and no Alembic migration for standalone global/project-scoped invariants. Any invariants added via `agents invariant add` are lost when the process exits. This TDD issue captures the failing test that proves the bug exists. The test must be tagged `@tdd_expected_fail` so it passes CI while the underlying bug is unfixed. ## Current Behavior `InvariantService.__init__` initializes `self._invariants: dict[str, Invariant] = {}` — a plain Python dict with no database backing. When the process restarts, all invariants added via `agents invariant add` are gone. ## Expected Behavior Invariants added via `agents invariant add` must survive process restarts. The `InvariantService` must persist to and load from the database (SQLite/PostgreSQL via SQLAlchemy), consistent with how other services (e.g., `LifecyclePlanRepository`, `ActionRepository`) work. ## Acceptance Criteria - [ ] A new BDD feature file `features/invariant_persistence.feature` contains a scenario tagged `@tdd_expected_fail` that: 1. Adds a global invariant via `InvariantService` 2. Simulates a restart by creating a new `InvariantService` instance backed by the same database 3. Asserts the invariant is still present after restart 4. This scenario **fails** (proving the bug) until the fix is implemented - [ ] The scenario uses the `@tdd_expected_fail` tag so CI passes while the bug is open - [ ] All existing BDD tests continue to pass ## Supporting Information - **Spec requirement**: "Invariant data is persisted to the database (durable across restarts)" — v3.2.0 milestone acceptance criteria - **Affected file**: `src/cleveragents/application/services/invariant_service.py` — `InvariantService.__init__` uses `self._invariants: dict[str, Invariant] = {}` - **No database table**: No Alembic migration exists for a standalone `invariants` table (only `action_invariants` and `plan_invariants` child tables exist, which are different) - **No repository**: No `InvariantRepository` class exists in `src/cleveragents/infrastructure/database/repositories.py` - **UAT finding**: Confirmed by [AUTO-UAT-2] on 2026-04-13 ## Subtasks - [ ] Create `features/invariant_persistence.feature` with `@tdd_expected_fail` scenario - [ ] Implement step definitions in `features/steps/invariant_persistence_steps.py` - [ ] Verify the scenario fails (proving the bug) with `nox -s bdd -- features/invariant_persistence.feature` - [ ] Verify all other BDD tests still pass - [ ] 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. - 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. --- **Automated by CleverAgents Bot** Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor Worker: [AUTO-UAT-2]
HAL9000 added this to the v3.2.0 milestone 2026-04-13 20:38:34 +00:00
Author
Owner

[AUTO-OWNR-1] Triage Decision (Cycle 2)

Status: Verified

MoSCoW: Must Have
Priority: High

Rationale: This TDD/BDD failing scenario is a valid and necessary testing approach to prove the invariant persistence gap confirmed by UAT worker [AUTO-UAT-2]. The v3.2.0 spec explicitly requires invariant data to be durable across restarts, and InvariantService currently uses in-memory storage only. A @tdd_expected_fail tagged scenario is the correct mechanism to document the bug in CI without breaking the build, and it creates a clear contract for the fix implementation.

Next Steps: Implement the failing BDD scenario in features/invariant_persistence.feature with @tdd_expected_fail tag. Verify the scenario fails (proving the bug), confirm all existing BDD tests still pass, and submit a PR to master on branch test/invariant-persistence-tdd. This issue should be paired with a follow-up fix issue for InvariantService database persistence.


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

## [AUTO-OWNR-1] Triage Decision (Cycle 2) **Status**: ✅ Verified **MoSCoW**: Must Have **Priority**: High **Rationale**: This TDD/BDD failing scenario is a valid and necessary testing approach to prove the invariant persistence gap confirmed by UAT worker [AUTO-UAT-2]. The v3.2.0 spec explicitly requires invariant data to be durable across restarts, and `InvariantService` currently uses in-memory storage only. A `@tdd_expected_fail` tagged scenario is the correct mechanism to document the bug in CI without breaking the build, and it creates a clear contract for the fix implementation. **Next Steps**: Implement the failing BDD scenario in `features/invariant_persistence.feature` with `@tdd_expected_fail` tag. Verify the scenario fails (proving the bug), confirm all existing BDD tests still pass, and submit a PR to `master` on branch `test/invariant-persistence-tdd`. This issue should be paired with a follow-up fix issue for `InvariantService` database persistence. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#8548
No description provided.