122 lines
4.6 KiB
Python
122 lines
4.6 KiB
Python
from pathlib import Path
|
|
|
|
from incremental_indexer import rebuild_changed_file
|
|
from semantic_kernel import index_project
|
|
from sir import EdgeKind, NodeKind
|
|
|
|
|
|
def test_rebuild_changed_file_returns_delta(tmp_path: Path):
|
|
module = tmp_path / "demo_module.bsl"
|
|
module.write_text(
|
|
"""
|
|
Процедура Проведение()
|
|
ПроверитьОстатки();
|
|
КонецПроцедуры
|
|
|
|
Процедура ПроверитьОстатки()
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
previous = index_project(tmp_path, project_id="demo")
|
|
|
|
module.write_text(
|
|
"""
|
|
Процедура Проведение()
|
|
ПроверитьОстатки();
|
|
Движения.ОстаткиТоваров.Записать();
|
|
КонецПроцедуры
|
|
|
|
Процедура ПроверитьОстатки()
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
current, delta = rebuild_changed_file(previous, module)
|
|
|
|
assert current.snapshot_hash != previous.snapshot_hash
|
|
assert delta.added_edges
|
|
assert any(node.name == "ОстаткиТоваров" for node in delta.added_nodes)
|
|
|
|
|
|
def test_rebuild_changed_xml_rebuilds_project_metadata_links(tmp_path: Path):
|
|
xml = tmp_path / "metadata.xml"
|
|
xml.write_text(
|
|
"""
|
|
<Configuration>
|
|
<Document name="ЗаказПокупателя" qualifiedName="Документ.ЗаказПокупателя" />
|
|
</Configuration>
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
module = tmp_path / "Documents" / "ЗаказПокупателя" / "Ext" / "ObjectModule.bsl"
|
|
module.parent.mkdir(parents=True)
|
|
module.write_text("Процедура Проведение()\nКонецПроцедуры\n", encoding="utf-8")
|
|
previous = index_project(tmp_path, project_id="xml-incremental")
|
|
|
|
xml.write_text(
|
|
"""
|
|
<Configuration>
|
|
<Document name="ЗаказПокупателя" qualifiedName="Документ.ЗаказПокупателя">
|
|
<Form name="ФормаДокумента" qualifiedName="Документ.ЗаказПокупателя.ФормаДокумента">
|
|
<Command name="Провести" qualifiedName="Документ.ЗаказПокупателя.ФормаДокумента.Провести" />
|
|
</Form>
|
|
</Document>
|
|
</Configuration>
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
current, delta = rebuild_changed_file(previous, xml)
|
|
|
|
assert current.snapshot_hash != previous.snapshot_hash
|
|
assert any(node.kind == NodeKind.FORM and node.name == "ФормаДокумента" for node in delta.added_nodes)
|
|
assert any(node.kind == NodeKind.COMMAND and node.name == "Провести" for node in delta.added_nodes)
|
|
assert any(edge.kind == EdgeKind.CONTAINS for edge in current.edges)
|
|
assert any(edge.kind == EdgeKind.HAS_FORM for edge in current.edges)
|
|
|
|
|
|
def test_rebuild_changed_bsl_preserves_metadata_owner_link(tmp_path: Path):
|
|
xml = tmp_path / "metadata.xml"
|
|
xml.write_text(
|
|
"""
|
|
<Configuration>
|
|
<Document name="ЗаказПокупателя" qualifiedName="Документ.ЗаказПокупателя" />
|
|
</Configuration>
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
module = tmp_path / "Documents" / "ЗаказПокупателя" / "Ext" / "ObjectModule.bsl"
|
|
module.parent.mkdir(parents=True)
|
|
module.write_text("Процедура Проведение()\nКонецПроцедуры\n", encoding="utf-8")
|
|
previous = index_project(tmp_path, project_id="bsl-incremental")
|
|
|
|
module.write_text(
|
|
"""
|
|
Процедура Проведение()
|
|
Движения.ОстаткиТоваров.Записать();
|
|
КонецПроцедуры
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
current, delta = rebuild_changed_file(previous, module)
|
|
|
|
assert any(node.kind == NodeKind.REGISTER and node.name == "ОстаткиТоваров" for node in delta.added_nodes)
|
|
assert any(edge.kind == EdgeKind.CONTAINS for edge in current.edges)
|
|
assert any(edge.kind == EdgeKind.WRITES for edge in delta.added_edges)
|
|
|
|
|
|
def test_rebuild_changed_file_refreshes_diagnostics(tmp_path: Path):
|
|
module = tmp_path / "demo_module.bsl"
|
|
module.write_text("Процедура Проведение()\nКонецПроцедуры\n", encoding="utf-8")
|
|
previous = index_project(tmp_path, project_id="diagnostics-incremental")
|
|
|
|
module.write_text("Процедура Проведение()\n", encoding="utf-8")
|
|
|
|
current, delta = rebuild_changed_file(previous, module)
|
|
|
|
assert any(diagnostic.code == "BSL_UNCLOSED_ROUTINE" for diagnostic in current.diagnostics)
|
|
assert delta.updated_nodes or delta.removed_nodes or current.snapshot_hash != previous.snapshot_hash
|