-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_issue_49_integration.py
More file actions
93 lines (76 loc) · 3.32 KB
/
test_issue_49_integration.py
File metadata and controls
93 lines (76 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""
Integration test for issue #49 implementation.
Tests the complete flow of document registration, ID generation, and wikilink resolution.
"""
from knowledgebase_processor.models.kb_entities import KbDocument, KbWikiLink
from knowledgebase_processor.models.content import Document
from knowledgebase_processor.utils.id_generator import EntityIdGenerator
from knowledgebase_processor.utils.document_registry import DocumentRegistry
from knowledgebase_processor.extractor.wikilink_extractor import WikiLinkExtractor
def test_issue_49_integration():
"""Test the complete integration of issue #49 features."""
# Create components
id_generator = EntityIdGenerator(base_url="http://example.org/kb/")
doc_registry = DocumentRegistry()
wikilink_extractor = WikiLinkExtractor(doc_registry, id_generator)
# Register some documents
doc1_path = "docs/architecture/decisions/adr-001.md"
doc1_id = id_generator.generate_document_id(doc1_path)
doc1 = KbDocument(
kb_id=doc1_id,
label="ADR 001",
original_path=doc1_path,
path_without_extension="docs/architecture/decisions/adr-001"
)
doc_registry.register_document(doc1)
doc2_path = "docs/planning/test-plan.md"
doc2_id = id_generator.generate_document_id(doc2_path)
doc2 = KbDocument(
kb_id=doc2_id,
label="Test Plan",
original_path=doc2_path,
path_without_extension="docs/planning/test-plan"
)
doc_registry.register_document(doc2)
# Test document with wikilinks
test_content = """
# Test Document
This document references [[adr-001]] and [[test-plan|the test plan]].
It also has a broken link to [[non-existent-doc]].
"""
test_doc = Document(path="test.md", content=test_content)
test_doc_id = id_generator.generate_document_id("test.md")
# Extract wikilinks
wikilinks = wikilink_extractor.extract(test_doc, test_doc_id)
# Verify results
assert len(wikilinks) == 3
# Check first link (resolved)
link1 = wikilinks[0]
assert link1.target_path == "adr-001"
assert link1.original_text == "[[adr-001]]"
assert link1.alias is None
assert link1.resolved_document_uri == doc1_id
# Check second link (resolved with alias)
link2 = wikilinks[1]
assert link2.target_path == "test-plan"
assert link2.original_text == "[[test-plan|the test plan]]"
assert link2.alias == "the test plan"
assert link2.resolved_document_uri == doc2_id
# Check third link (unresolved)
link3 = wikilinks[2]
assert link3.target_path == "non-existent-doc"
assert link3.original_text == "[[non-existent-doc]]"
assert link3.alias is None
assert link3.resolved_document_uri is None
# Verify ID generation consistency
assert id_generator.generate_document_id(doc1_path) == doc1_id
assert id_generator.generate_wikilink_id(test_doc_id, "[[adr-001]]") == link1.kb_id
print("✅ All integration tests passed!")
print(f" - Document registry working correctly")
print(f" - ID generation is consistent")
print(f" - Wikilink extraction preserves original text")
print(f" - Wikilink resolution works for existing documents")
print(f" - Unresolved links are handled gracefully")
if __name__ == "__main__":
test_issue_49_integration()