Files
cleveragents-core/features/uko_persistence.feature
HAL9000 ba7870da3e
CI / helm (pull_request) Successful in 55s
CI / e2e_tests (pull_request) Failing after 1m5s
CI / build (pull_request) Failing after 44s
CI / security (pull_request) Failing after 1m7s
CI / typecheck (pull_request) Failing after 1m7s
CI / integration_tests (pull_request) Failing after 1m6s
CI / push-validation (pull_request) Successful in 1m21s
CI / lint (pull_request) Successful in 1m46s
CI / quality (pull_request) Successful in 2m5s
CI / unit_tests (pull_request) Failing after 7m12s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / benchmark-publish (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
CI / benchmark-regression (pull_request) Failing after 31s
fix(acms): fix format violations and remove duplicate step definitions in uko_persistence tests
2026-05-05 02:49:54 +00:00

207 lines
11 KiB
Gherkin

Feature: UKO Graph Persistence — Full Coverage for Error Paths and Edge Cases
As a test infrastructure maintainer
I need comprehensive test coverage for all branches in uko_persistence.py
So that the module meets the 97% coverage threshold and all error paths are validated
# =================================================================
# JSONFilePersistenceBackend.load() corrupted JSON file handling
# =================================================================
Scenario: JSONFilePersistenceBackend.load() returns empty list when JSON file is corrupted
Given uko a JSON file persistence backend in a temp directory
And uko the JSON file contains corrupted JSON data
When uko I load from the JSON file backend for project "local/test"
Then uko the result should be an empty list
And uko a warning should be logged for load failure
Scenario: JSONFilePersistenceBackend.load() returns empty list when JSON file is missing required keys
Given uko a JSON file persistence backend in a temp directory
And uko the JSON file contains valid JSON but missing "triples" key
When uko I load from the JSON file backend for project "local/test"
Then uko the result should be an empty list
And uko a warning should be logged for load failure
Scenario: JSONFilePersistenceBackend.load() returns empty list when file is unreadable
Given uko a JSON file persistence backend in a temp directory
And uko the JSON file exists but is unreadable (permission denied)
When uko I load from the JSON file backend for project "local/test"
Then uko the result should be an empty list
And uko a warning should be logged for load failure
# =================================================================
# UKOGraphPersistence.save() — query failure path
# =================================================================
Scenario: UKOGraphPersistence.save() returns 0 when graph_backend.query() raises an exception
Given uko a graph backend that raises an exception on query
And uko a UKOGraphPersistence service with the failing backend
When uko I call save on the persistence service
Then uko the save result should be 0
And uko a warning should be logged for query failure
# =================================================================
# UKOGraphPersistence.restore() — incomplete triple handling
# =================================================================
Scenario: UKOGraphPersistence.restore() skips triples with missing subject key
Given uko a persistence backend with triples missing the "subject" key
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko no triples should be added to the graph backend
Scenario: UKOGraphPersistence.restore() skips triples with missing predicate key
Given uko a persistence backend with triples missing the "predicate" key
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko no triples should be added to the graph backend
Scenario: UKOGraphPersistence.restore() skips triples with missing object key
Given uko a persistence backend with triples missing the "object" key
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko no triples should be added to the graph backend
Scenario: UKOGraphPersistence.restore() skips triples with empty subject value
Given uko a persistence backend with triples having empty subject value
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko no triples should be added to the graph backend
Scenario: UKOGraphPersistence.restore() skips triples with empty predicate value
Given uko a persistence backend with triples having empty predicate value
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko no triples should be added to the graph backend
Scenario: UKOGraphPersistence.restore() skips triples with empty object value
Given uko a persistence backend with triples having empty object value
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko no triples should be added to the graph backend
# =================================================================
# UKOGraphPersistence.restore() — add_triple failure path
# =================================================================
Scenario: UKOGraphPersistence.restore() continues and logs warning when add_triple() raises an exception
Given uko a persistence backend with valid triples
And uko a graph backend that raises an exception on add_triple
And uko a UKOGraphPersistence service with the failing backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko a warning should be logged for triple failure
Scenario: UKOGraphPersistence.restore() restores valid triples even when some fail
Given uko a persistence backend with mixed valid and invalid triples
And uko a graph backend that raises an exception only for specific triples
And uko a UKOGraphPersistence service with the mixed backend
When uko I call restore on the persistence service
Then uko the restore result should be greater than 0
And uko warnings should be logged for failed triples
# =================================================================
# InMemoryPersistenceBackend.clear() method
# =================================================================
Scenario: InMemoryPersistenceBackend.clear() removes stored triples for a project
Given uko an in-memory persistence backend
And uko I save triples to the persistence backend for project "local/test"
When uko I clear the persistence backend for project "local/test"
Then uko loading from the persistence backend for project "local/test" should return empty list
Scenario: InMemoryPersistenceBackend.clear() does not affect other projects
Given uko an in-memory persistence backend
And uko I save triples to the persistence backend for project "local/test1"
And uko I save triples to the persistence backend for project "local/test2"
When uko I clear the persistence backend for project "local/test1"
Then uko loading from the persistence backend for project "local/test1" should return empty list
And uko loading from the persistence backend for project "local/test2" should return the saved triples
Scenario: InMemoryPersistenceBackend.clear() on non-existent project does not raise error
Given uko an in-memory persistence backend
When uko I clear the persistence backend for project "local/nonexistent"
Then uko no error should be raised
# =================================================================
# UKOGraphPersistence.project property
# =================================================================
Scenario: UKOGraphPersistence.project property returns the correct project name
Given uko a graph backend with no triples
And uko a UKOGraphPersistence service with project "local/my-app"
When uko I access the project property
Then uko the project property should return "local/my-app"
Scenario: UKOGraphPersistence.project property is read-only
Given uko a graph backend with no triples
And uko a UKOGraphPersistence service with project "local/my-app"
Then uko attempting to set the project property should raise AttributeError
# =================================================================
# Integration: Full save/restore lifecycle with JSONFilePersistenceBackend
# =================================================================
Scenario: Full save/restore lifecycle with JSONFilePersistenceBackend
Given uko a mock graph backend with two sample triples
And uko a JSON file persistence backend in a temp directory
And uko a UKOGraphPersistence service with the JSON file backend
When uko I save the graph state via the persistence service
And uko I restore the graph state into a fresh backend with the same JSON file backend
Then uko the restored backend should have the same triples
Scenario: JSONFilePersistenceBackend creates base directory if it does not exist
Given uko a JSON file persistence backend in a non-existent temp directory
When uko I save triples to the JSON file backend for project "local/test"
Then uko the base directory should be created
And uko the JSON file should exist
# =================================================================
# Edge cases and validation
# =================================================================
Scenario: UKOGraphPersistence rejects whitespace-only project name
Given uko a graph backend with no triples
Then uko creating UKOGraphPersistence with whitespace-only project should raise ValueError
Scenario: JSONFilePersistenceBackend rejects whitespace-only project on save
Given uko a JSON file persistence backend in a temp directory
Then uko saving to JSON file backend with whitespace-only project should raise ValueError
Scenario: JSONFilePersistenceBackend rejects whitespace-only project on load
Given uko a JSON file persistence backend in a temp directory
Then uko loading from JSON file backend with whitespace-only project should raise ValueError
Scenario: InMemoryPersistenceBackend rejects whitespace-only project on save
Given uko an in-memory persistence backend
Then uko saving to persistence backend with whitespace-only project should raise ValueError
Scenario: InMemoryPersistenceBackend rejects whitespace-only project on load
Given uko an in-memory persistence backend
Then uko loading from persistence backend with whitespace-only project should raise ValueError
Scenario: UKOGraphPersistence.save() handles empty bindings from query
Given uko a graph backend that returns empty bindings on query
And uko a UKOGraphPersistence service with the backend
When uko I call save on the persistence service
Then uko the save result should be 0
Scenario: UKOGraphPersistence.save() filters out incomplete bindings
Given uko a graph backend that returns bindings with missing keys
And uko a UKOGraphPersistence service with the backend
When uko I call save on the persistence service
Then uko the save result should be 0
And uko only complete triples should be persisted
Scenario: UKOGraphPersistence.restore() handles empty persistence backend
Given uko a persistence backend with no data
And uko a UKOGraphPersistence service with the persistence backend
When uko I call restore on the persistence service
Then uko the restore result should be 0
And uko an info log should be recorded for no data