Commit 730efbd
committed
fix(ogit_bridge): reject unknown ancestors in is_ancestor (codex P2)
Codex flagged on PR #189 that `is_ancestor` returned true as soon as
`entity.parent == ancestor`, even when `ancestor` was not a declared
rdfs:Class in `self.entities`. Because `from_triples` accepts
`rdfs:subClassOf` targets without requiring them to be declared, a
partial or malformed ontology could make
`is_ancestor("missing:Class", "ogit:Leaf")` succeed for a non-reflexive
unknown ancestor — directly contradicting the method's documented
contract that unknown IRIs are only true in the reflexive case.
Fix: after the reflexive `ancestor == descendant` shortcut, early-return
false if `ancestor` is not present in `self.entities`. Reflexivity on
unknown IRIs is preserved (still defined on the full IRI space), but
no entity's parent field can now project a phantom IRI into the
ancestor closure.
Added regression test
`is_ancestor_unknown_ancestor_returns_false_when_non_reflexive` that
parses a turtle source where `ogit:Leaf rdfs:subClassOf ogit:Phantom`
but `ogit:Phantom` is never declared as a class. Asserts both:
- `is_ancestor("ogit:Phantom", "ogit:Phantom")` → true (reflexive)
- `is_ancestor("ogit:Phantom", "ogit:Leaf")` → false (was previously
true — the bug)
All 7 `is_ancestor` tests pass; lib clippy + fmt clean.1 parent 6c4607d commit 730efbd
1 file changed
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
630 | 630 | | |
631 | 631 | | |
632 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
633 | 644 | | |
634 | 645 | | |
635 | 646 | | |
| |||
905 | 916 | | |
906 | 917 | | |
907 | 918 | | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
908 | 947 | | |
909 | 948 | | |
910 | 949 | | |
| |||
0 commit comments