trustgraph/tests
Trevin Chow e59aa023d4
test(ontology): harden domain/range validation + add missing tests (#848)
Fixes #826. Addresses all five points the maintainer called out in
the follow-up to #825.

Source change (trustgraph-flow/trustgraph/extract/kg/ontology/extract.py):
- Added `_is_subclass_of(cls, target, ontology_subset, max_depth=100)`
  helper with visited-set cycle detection + a defensive depth cap.
  LLM-generated ontologies may emit cycles (A subclass_of B,
  B subclass_of A); the prior while-loop would infinite-loop on that.
- Replaced both near-identical domain and range subclass walks in
  `is_valid_triple` with a single call to the new helper. Net is
  -20 duplicated lines + 26-line helper.

Tests (tests/unit/test_extract/test_ontology/test_prompt_and_extraction.py):
- test_is_valid_triple_subclass_is_accepted: domain expects Recipe,
  actual type is Cake (subclass), validates.
- test_is_valid_triple_handles_subclass_cycle_without_infinite_loop:
  A subclass_of B, B subclass_of A; call returns False within the
  depth cap rather than hanging.
- test_parse_and_validate_triples_collects_entity_types_from_rdf_type:
  end-to-end path: rdf:type triples build the entity_types dict,
  subsequent domain-check triples validate against it.
- test_is_valid_triple_entity_types_none_default: the None default
  path now has explicit coverage.

156 existing tests in tests/unit/test_extract/test_ontology still pass.
2026-04-28 16:33:49 +01:00
..
contract release/v2.4 -> master (#844) 2026-04-22 15:19:57 +01:00
integration release/v2.4 -> master (#844) 2026-04-22 15:19:57 +01:00
unit test(ontology): harden domain/range validation + add missing tests (#848) 2026-04-28 16:33:49 +01:00
utils Add agent explainability instrumentation and unify envelope field naming (#795) 2026-04-13 16:16:42 +01:00
__init__.py Test suite executed from CI pipeline (#433) 2025-07-14 14:57:44 +01:00
conftest.py Feat: TrustGraph i18n & Documentation Translation Updates (#781) 2026-04-14 12:08:32 +01:00
pytest.ini Fix tests broken by the recent RabbitMQ/Cassandra async fixes (#815) 2026-04-16 10:00:18 +01:00
requirements.txt Test suite executed from CI pipeline (#433) 2025-07-14 14:57:44 +01:00