from pathlib import Path from query_intelligence import table_usage, tables_with_read_write_conflicts from semantic_kernel import index_project def test_table_usage_finds_query_readers(tmp_path: Path): module = tmp_path / "demo_module.bsl" module.write_text( """ Процедура ПроверитьОстатки() Запрос = Новый Запрос; Запрос.Текст = "ВЫБРАТЬ Остатки.Номенклатура ИЗ РегистрНакопления.ОстаткиТоваров КАК Остатки"; КонецПроцедуры """, encoding="utf-8", ) snapshot = index_project(tmp_path, project_id="demo") usage = table_usage(snapshot, "РегистрНакопления.ОстаткиТоваров") assert usage[0].table.name == "ОстаткиТоваров" assert usage[0].readers[0].name == "ПроверитьОстатки" def test_table_usage_finds_writers(tmp_path: Path): module = tmp_path / "demo_module.bsl" module.write_text( """ Процедура Проведение() Движения.ОстаткиТоваров.Записать(); КонецПроцедуры """, encoding="utf-8", ) snapshot = index_project(tmp_path, project_id="demo") usage = table_usage(snapshot, "ОстаткиТоваров") assert usage[0].writers[0].name == "Проведение" def test_tables_with_read_write_conflicts_find_register_dependencies(tmp_path: Path): module = tmp_path / "demo_module.bsl" module.write_text( """ Процедура ПроверитьОстатки() Запрос = Новый Запрос; Запрос.Текст = "ВЫБРАТЬ Остатки.Номенклатура ИЗ РегистрНакопления.ОстаткиТоваров КАК Остатки"; КонецПроцедуры Процедура Проведение() Движения.ОстаткиТоваров.Записать(); КонецПроцедуры """, encoding="utf-8", ) snapshot = index_project(tmp_path, project_id="query-conflicts") conflicts = tables_with_read_write_conflicts(snapshot) assert [usage.table.qualified_name for usage in conflicts] == ["РегистрНакопления.ОстаткиТоваров"] assert [node.name for node in conflicts[0].readers] == ["ПроверитьОстатки"] assert [node.name for node in conflicts[0].writers] == ["Проведение"]