60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
from pathlib import Path
|
|
|
|
from semantic_kernel import index_project
|
|
from semantic_search import search_snapshot
|
|
|
|
|
|
def test_search_snapshot_finds_routine_by_partial_name(tmp_path: Path):
|
|
module = tmp_path / "demo_module.bsl"
|
|
module.write_text(
|
|
"""
|
|
Процедура Проведение()
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
snapshot = index_project(tmp_path, project_id="demo")
|
|
|
|
results = search_snapshot(snapshot, "Пров", kinds={"PROCEDURE"})
|
|
|
|
assert results
|
|
assert results[0].node.name == "Проведение"
|
|
|
|
|
|
def test_search_snapshot_finds_node_by_source_text(tmp_path: Path):
|
|
module = tmp_path / "integration.bsl"
|
|
module.write_text(
|
|
"""
|
|
Процедура Отправить()
|
|
Адрес = "https://api.example.local/orders";
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
snapshot = index_project(tmp_path, project_id="search-source-text")
|
|
|
|
results = search_snapshot(snapshot, "api.example.local")
|
|
|
|
assert results
|
|
module_result = next(result for result in results if result.node.name == "integration")
|
|
assert "attributes.source_text" in module_result.matched_fields
|
|
|
|
|
|
def test_search_snapshot_finds_node_by_metadata_attribute(tmp_path: Path):
|
|
xml = tmp_path / "metadata.xml"
|
|
xml.write_text(
|
|
"""
|
|
<Configuration>
|
|
<Document name="ЗаказПокупателя" qualifiedName="Документ.ЗаказПокупателя" synonym="Customer Order" />
|
|
</Configuration>
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
snapshot = index_project(tmp_path, project_id="search-attributes")
|
|
|
|
results = search_snapshot(snapshot, "Customer")
|
|
|
|
assert results
|
|
assert results[0].node.qualified_name == "Документ.ЗаказПокупателя"
|
|
assert "attributes.synonym" in results[0].matched_fields
|