"""Инъекция факта региональной базы в контекст агента (22.11.2026).""" import sqlite3, sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) import main # noqa: E402 def _env(tmp_path, monkeypatch): db = tmp_path / "regional_ref.sqlite" con = sqlite3.connect(db) con.executescript(""" create table subjects(code integer primary key, name text); create table sources(id integer primary key, subject_id int, kind text, edition text, act text, file_sha text, manifest_sha text, imported_at text); create table works(id integer primary key, subject_id int, kind text, code text, name text, unit text, price real, source_id int); create table prices(id integer primary key, subject_id int, kind text, code text, name text, unit text, price_otp real, price_smet real, source_id int); """) con.execute("insert into subjects values(337,'Оренбургская область')") con.execute("insert into sources values(1,337,'ТЕР','ред. 2014','приказ','sha1','sha2','now')") con.execute("insert into works values(1,337,'ТЕР','01-01-001-01','15 м³','м3',3270.04,1)") con.commit(); con.close() reg = tmp_path / "reference_sources.json" reg.write_text('{"subjects":[{"code":337,"name":"Оренбургская область"}]}', encoding="utf-8") monkeypatch.setenv("REGIONAL_REF_PATH", str(db)) monkeypatch.setenv("REGIONAL_REGISTRY", str(reg)) def test_injects_found_rate(tmp_path, monkeypatch): _env(tmp_path, monkeypatch) fact = main._regional_fact("Какая расценка по коду 01-01-001-01 в Оренбургской области?") assert fact and "РЕГИОНАЛЬНОЙ БАЗЫ" in fact and "3270.04" in fact and "sha2" in fact def test_ignores_without_code(tmp_path, monkeypatch): _env(tmp_path, monkeypatch) assert main._regional_fact("Расценка в Оренбургской области?") is None