Enhance chunking strategies and graph utilities for section-type transitions and block ID extraction

- Implemented WP-26 v1.1: Section-Type-Wechsel erzwingt Split auch in SMART MODE (Schritt 2) zur Verbesserung der Chunking-Logik.
- Updated `parse_link_target` to extract block IDs from section strings, ensuring accurate handling of links with block references.
- Added unit tests to validate section-type change behavior and block ID extraction functionality, enhancing overall reliability.
This commit is contained in:
Lars committed 2026-01-25 17:47:22 +01:00
1 parent af3cc0a254
commit 52fdc425f7
3 files changed
+121

No files matched your search

+75
View File
@@ -477,6 +477,81 @@ Meine positive Einstellung hat mir geholfen.
# Der insight-Chunk sollte den Lektions-Inhalt enthalten
insight_text = insight_chunks[0].text
assert "durchdenken" in insight_text.lower() or "positive" in insight_text.lower()
def test_section_type_change_in_smart_mode_forces_split(self):
"""WP-26 v1.1 Fix: Section-Type-Wechsel erzwingt Split auch in SMART MODE (Schritt 2)"""
md = """
## Section A ohne Typ
Inhalt A ohne section_type.
## Section B ohne Typ
Inhalt B ohne section_type.
## Section C mit Typ
> [!section] insight
Inhalt C mit section_type "insight".
"""
blocks, _ = parse_blocks(md)
# SMART MODE: strict=False, smart_edge=True
# Token-Limit hoch genug, dass alles zusammengefasst werden KÖNNTE
config = {
"target": 2000,
"max": 4000,
"split_level": 2,
"strict_heading_split": False,
"enable_smart_edge_allocation": True
}
chunks = strategy_by_heading(blocks, config, "test-note")
# Trotz hohem Token-Limit sollte Section C ein separater Chunk sein
# wegen Section-Type-Wechsel (None -> insight)
assert len(chunks) >= 2, f"Erwartet mindestens 2 Chunks, bekommen: {len(chunks)}"
# Der letzte Chunk sollte section_type "insight" haben
insight_chunks = [c for c in chunks if c.section_type == "insight"]
assert len(insight_chunks) >= 1, "Kein Chunk mit section_type 'insight' gefunden"
class TestBlockIdParsing:
"""UT-18: Block-ID-Extraktion aus Section-Referenzen"""
def test_block_id_extraction_from_section(self):
"""Block-ID wird aus Section-String extrahiert"""
from app.core.graph.graph_utils import parse_link_target
# Test: Überschrift mit Block-ID
target, section = parse_link_target("#📖 Diagnose: Glioblastom ^kontext", "note1")
assert target == "note1" # Self-Link
assert section == "kontext", f"Erwartet 'kontext', bekommen: {section}"
def test_block_id_extraction_only_caret(self):
"""Nur Block-ID mit ^"""
from app.core.graph.graph_utils import parse_link_target
target, section = parse_link_target("#^learning", "note1")
assert target == "note1"
assert section == "learning"
def test_block_id_extraction_with_spaces(self):
"""Block-ID mit Text davor"""
from app.core.graph.graph_utils import parse_link_target
target, section = parse_link_target("OtherNote#🎭 Emotions-Check ^emotionen", None)
assert target == "OtherNote"
assert section == "emotionen"
def test_section_without_block_id(self):
"""Section ohne Block-ID bleibt unverändert"""
from app.core.graph.graph_utils import parse_link_target
target, section = parse_link_target("Note#Normale Überschrift", None)
assert target == "Note"
assert section == "Normale Überschrift"
if __name__ == "__main__":