Files
cleveragents-core/features/tdd_invariant_persistence.feature
CleverAgents Bot 525a0e1d56
CI / push-validation (pull_request) Successful in 27s
CI / load-versions (pull_request) Successful in 27s
CI / lint (pull_request) Successful in 46s
CI / build (pull_request) Successful in 56s
CI / quality (pull_request) Successful in 1m27s
CI / typecheck (pull_request) Successful in 1m35s
CI / security (pull_request) Successful in 1m35s
CI / helm (pull_request) Successful in 3m17s
CI / unit_tests (pull_request) Successful in 5m42s
CI / integration_tests (pull_request) Successful in 9m8s
CI / docker (pull_request) Successful in 2m24s
CI / coverage (pull_request) Successful in 10m14s
CI / status-check (pull_request) Successful in 3s
fix(invariant): route persistence through repository
2026-06-18 11:36:35 -04:00

85 lines
5.0 KiB
Gherkin

# TDD issue-capture test for bug #1022 — InvariantService persistence.
#
# Bug #1022 has been fixed: InvariantService now uses SQLite-based storage
# via a lazy session-factory pattern. Invariants added in one CLI invocation
# persist across process restarts because all instances share the same
# ``cleveragents.db`` (or equivalent) database configured in Settings.
#
# These scenarios verify cross-instance data visibility by simulating
# separate CLI invocations (fresh service instances backing a shared DB).
@tdd_issue @tdd_issue_1022
Feature: TDD Issue #1022 — InvariantService persistence across process restarts
As a developer using the agents CLI
I want invariants added via "agents invariant add" to persist across CLI invocations
So that "agents invariant list" in a subsequent invocation returns previously added invariants
InvariantService uses SQLite-based storage backed by the configured database URL.
Fresh service instances share the same underlying database, so data persists across
process restarts. These tests simulate separate process invocations by
creating fresh service instances and verifying cross-instance data visibility.
@tdd_issue_1022
Scenario: Invariant added in one service instance is visible in a fresh instance
Given I add a project invariant "All APIs must validate auth tokens" to project "local/api-service" via invariant service instance A
When I create a fresh invariant service instance B
And I list project invariants for "local/api-service" via instance B
Then the invariant list from instance B should contain "All APIs must validate auth tokens"
@tdd_issue_1022
Scenario: Global invariant persists across simulated process restarts
Given I add a global invariant "Never delete production data" via invariant service instance A
When I create a fresh invariant service instance B
And I list global invariants via instance B
Then the invariant list from instance B should contain "Never delete production data"
@tdd_issue_1022
Scenario: Invariant added via CLI add is visible via CLI list in a new invocation
Given I invoke invariant add via CLI with "--project local/webapp" and text "All changes need tests" using service invocation 1
When I invoke invariant list via CLI with "--project local/webapp" using service invocation 2
Then the CLI list output from invocation 2 should contain "All changes need tests"
@tdd_issue_1022
Scenario: Invariant soft-deleted in a fresh instance after being added in another
Given I add a project invariant "Temporary constraint" to project "local/temp" via invariant service instance A
And I capture the invariant ID from instance A
When I create a fresh invariant service instance B
And I attempt to remove the captured invariant ID via instance B
Then the remove operation via instance B should succeed without NotFoundError
@tdd_issue_1022
Scenario: Standalone repository can list inactive invariants on request
Given a fresh standalone invariant repository
And I repository-create inactive project invariant "Archived constraint" for project "local/archive"
When I repository-list inactive project invariants for "local/archive"
Then the repository invariant list should contain inactive "Archived constraint"
@tdd_issue_1022
Scenario: Standalone repository reports missing invariants explicitly
Given a fresh standalone invariant repository
When I repository-get invariant "01ARZ3NDEKTSV4RRFFQ69G5FAV"
Then the repository get result should be missing
When I repository-update missing invariant "01ARZ3NDEKTSV4RRFFQ69G5FAV"
Then the repository update should raise NotFoundError
@tdd_issue_1022
Scenario: Invariant service merges and checks active invariants in memory
Given a fresh in-memory invariant service
And I add a global invariant "Never delete backups" via the in-memory service
And I add a project invariant "Do not deploy secrets" for project "local/app" via the in-memory service
And I add an inactive project invariant "Never rotate logs" for project "local/app" via the in-memory service
When I list effective project invariants for "local/app" via the in-memory service
And I load active invariants for project "local/app" via the in-memory service
And I load global active invariants via the in-memory service
And I check action "deploy secrets to staging" against the loaded invariants
Then an invariant violation should be raised
And the effective invariant list should contain "Do not deploy secrets"
And the effective invariant list should not contain "Never rotate logs"
@tdd_issue_1022
Scenario: Invariant service records enforcement even when event bus fails
Given a fresh in-memory invariant service with a failing event bus
And I add a global invariant "Never delete audit logs" via the in-memory service
When I enforce the global invariant for plan "plan-event-failure" as violated
Then the enforcement record should be marked not enforced