Orchestrata Ultimate › Tests › Reference › knowledge_graph › test_graph_context_validator

Tests reference — tests/knowledge_graph/test_graph_context_validator.py

Module of tests/knowledge_graph, split out because the directory page would be too large.

Prose pending.

tests/knowledge_graph/test_graph_context_validator.py

source · 40 tests · 468 lines

Tests for GraphContextValidator and ValidationResult.

Covers: core.base.traces, knowledge_graph.graph_context_validator

Kind Name Line Description
class TestExtractEntities 25 Tests for GraphContextValidator._extract_entities() (via constructor).
method TestExtractEntities.test_extracts_class_names 29 'class UserService' yields entity 'UserService'.
method TestExtractEntities.test_extracts_function_names 35 'def validate(self)' yields entity 'validate'.
method TestExtractEntities.test_extracts_inheritance 41 'User inherits from BaseModel' yields both 'User' and 'BaseModel'.
method TestExtractEntities.test_extracts_calls 48 'run() calls validate()' yields both 'run' and 'validate'.
method TestExtractEntities.test_extracts_method_notation 55 'UserService.create()' yields both 'UserService' and 'create'.
method TestExtractEntities.test_filters_noise_words 62 Noise words like 'self', 'cls', 'None' are excluded from entities.
method TestExtractEntities.test_deduplicates 80 The same name appearing multiple times produces a single entry.
method TestExtractEntities.test_empty_context 87 Empty string produces an empty entity list.
method TestExtractEntities.test_none_context 93 None context is treated as empty and produces an empty entity list.
method TestExtractEntities.test_complex_context 99 Multi-line context mixing all patterns yields all expected names.
method TestExtractEntities.test_extracts_requirement_ids 121 Requirement ids like REQ-107-003 are extracted as enforceable entities.
method TestExtractEntities.test_extracts_decision_ids 128 Decision ids under the Prior decisions section are extracted.
method TestExtractEntities.test_extracts_requirement_ids_from_decision_tail 139 REQ ids cited in a decision's [REQ-...] tail are also extracted.
class TestValidate 159 Tests for GraphContextValidator.validate().
method TestValidate.test_passes_when_entities_referenced_and_cited 163 Response referencing and citing all entities passes.
method TestValidate.test_fails_when_no_entities_referenced 175 Response with incomplete citations and no body references fails.
method TestValidate.test_passes_vacuously_with_no_entities 187 Empty graph context produces a vacuously passing ValidationResult.
method TestValidate.test_partial_reference_fails 194 Referencing 1 of 3 public entities fails the 100% threshold.
method TestValidate.test_all_public_referenced_passes 204 Referencing and citing all 3 public entities passes.
method TestValidate.test_entities_found_populated 219 entities_found contains only the names that appear in the response.
method TestValidate.test_entities_missing_populated 229 entities_missing contains names absent from the response.
method TestValidate.test_entity_count_correct 239 entity_count matches the total number of extracted entities.
method TestValidate.test_word_boundary_matching 247 'User' must not be matched by a response containing only 'UserService'.
class TestValidateCitations 257 Tests for citation-aware validation (Phase 0).
method TestValidateCitations.test_missing_citation_section_fails 261 A response that references entities but has no 'Entities used' block fails.
method TestValidateCitations.test_incomplete_citation_section_fails 269 Citing only some core entities fails.
method TestValidateCitations.test_invalid_citation_rejected 277 Citing an entity that was not injected is rejected.
method TestValidateCitations.test_citations_can_be_disabled 287 require_citations=False keeps the previous word-boundary-only behavior.
method TestValidateCitations.test_enforces_requirement_citations 295 A response must cite requirement ids that appear in the context.
method TestValidateCitations.test_fails_when_requirement_citation_missing 304 Omitting a requirement id from the Entities used section fails.
method TestValidateCitations.test_enforces_decision_citations 315 A response must cite decision ids from the context.
class TestComplianceRatio 330 Tests for ValidationResult.compliance_ratio property.
method TestComplianceRatio.test_ratio_all_referenced 334 3 of 3 public entities referenced yields compliance_ratio of 1.0.
method TestComplianceRatio.test_ratio_partial 346 1 of 3 public entities referenced yields compliance_ratio of ~0.333.
method TestComplianceRatio.test_ratio_no_entities 358 Zero public entities (vacuous) yields compliance_ratio of 1.0.
class TestBuildRetryPrompt 373 Tests for GraphContextValidator.build_retry_prompt().
method TestBuildRetryPrompt.test_contains_rejection_notice 389 Retry prompt includes the word 'REJECTED'.
method TestBuildRetryPrompt.test_lists_missing_entities 396 Each missing public entity name appears in the retry prompt.
method TestBuildRetryPrompt.test_preserves_original_prompt 406 The original prompt text appears at the end of the retry prompt.
method TestBuildRetryPrompt.test_separator_present 414 A '---' separator divides the directive section from the original prompt.
class TestHasEntities 426 Tests for GraphContextValidator.has_entities property.
method TestHasEntities.test_has_entities_true 430 Context containing class definitions makes has_entities True.
method TestHasEntities.test_has_entities_false 436 Empty context makes has_entities False.
class TestEntityNames 447 Tests for GraphContextValidator.entity_names property.
method TestEntityNames.test_returns_sorted_list 451 entity_names returns names in alphabetical order.
method TestEntityNames.test_returns_copy 459 Mutating the returned list does not affect subsequent calls.