Initial SFERA platform baseline
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
from pathlib import Path
|
||||
|
||||
from operations_core import (
|
||||
AiUsageRecord,
|
||||
InMemoryOperationsStore,
|
||||
MarketplacePackage,
|
||||
OperationJob,
|
||||
OperationJobStatus,
|
||||
build_project_report,
|
||||
)
|
||||
from semantic_kernel import index_project
|
||||
|
||||
|
||||
def test_operations_store_jobs_and_marketplace():
|
||||
store = InMemoryOperationsStore()
|
||||
job = store.enqueue(OperationJob(job_id="job.1", kind="INDEX_PROJECT"))
|
||||
store.update_job(job.job_id, OperationJobStatus.SUCCEEDED, result={"ok": True})
|
||||
store.upsert_marketplace_package(
|
||||
MarketplacePackage(package_id="pack.1", name="BSP Knowledge", version="1.0.0")
|
||||
)
|
||||
|
||||
assert store.list_jobs()[0].status == OperationJobStatus.SUCCEEDED
|
||||
assert store.list_marketplace_packages()[0].name == "BSP Knowledge"
|
||||
|
||||
|
||||
def test_operations_store_ai_usage_summary():
|
||||
store = InMemoryOperationsStore()
|
||||
store.record_ai_usage(
|
||||
AiUsageRecord(
|
||||
usage_id="usage.1",
|
||||
project_id="demo",
|
||||
user_id="user.1",
|
||||
model="gpt-test",
|
||||
operation="review",
|
||||
prompt_tokens=100,
|
||||
completion_tokens=40,
|
||||
cost=0.01,
|
||||
)
|
||||
)
|
||||
store.record_ai_usage(
|
||||
AiUsageRecord(
|
||||
usage_id="usage.2",
|
||||
project_id="demo",
|
||||
user_id="user.1",
|
||||
model="gpt-test",
|
||||
operation="impact",
|
||||
prompt_tokens=50,
|
||||
completion_tokens=10,
|
||||
cost=0.005,
|
||||
)
|
||||
)
|
||||
|
||||
summary = store.summarize_ai_usage(project_id="demo", user_id="user.1", model="gpt-test")
|
||||
|
||||
assert summary.request_count == 2
|
||||
assert summary.total_tokens == 200
|
||||
assert summary.cost == 0.015
|
||||
|
||||
|
||||
def test_build_project_report_counts_snapshot_parts(tmp_path: Path):
|
||||
module = tmp_path / "demo_module.bsl"
|
||||
module.write_text(
|
||||
"""
|
||||
Процедура Проведение()
|
||||
Движения.ОстаткиТоваров.Записать();
|
||||
КонецПроцедуры
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
snapshot = index_project(tmp_path, project_id="demo")
|
||||
|
||||
report = build_project_report(snapshot)
|
||||
|
||||
assert report.procedure_count == 1
|
||||
assert report.write_count == 1
|
||||
|
||||
|
||||
def test_build_project_report_counts_1c_role_access(tmp_path: Path):
|
||||
xml = tmp_path / "metadata.xml"
|
||||
xml.write_text(
|
||||
"""
|
||||
<Configuration>
|
||||
<Document name="ЗаказПокупателя" qualifiedName="Документ.ЗаказПокупателя" />
|
||||
<Catalog name="Номенклатура" qualifiedName="Справочник.Номенклатура" />
|
||||
<Role name="Менеджер" qualifiedName="Роль.Менеджер">
|
||||
<Right object="Документ.ЗаказПокупателя" read="true" write="true" />
|
||||
</Role>
|
||||
</Configuration>
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
snapshot = index_project(tmp_path, project_id="security-report")
|
||||
|
||||
report = build_project_report(snapshot)
|
||||
|
||||
assert report.role_count == 1
|
||||
assert report.access_grant_count == 1
|
||||
assert report.unsecured_object_count == 1
|
||||
assert report.unsecured_objects == ["Справочник.Номенклатура"]
|
||||
|
||||
|
||||
def test_build_project_report_counts_1c_schema(tmp_path: Path):
|
||||
xml = tmp_path / "metadata.xml"
|
||||
xml.write_text(
|
||||
"""
|
||||
<Configuration>
|
||||
<Document name="ЗаказПокупателя" qualifiedName="Документ.ЗаказПокупателя">
|
||||
<Attribute name="Контрагент" qualifiedName="Документ.ЗаказПокупателя.Контрагент" />
|
||||
<TabularSection name="Товары" qualifiedName="Документ.ЗаказПокупателя.Товары">
|
||||
<Attribute name="Номенклатура" qualifiedName="Документ.ЗаказПокупателя.Товары.Номенклатура" />
|
||||
</TabularSection>
|
||||
<TabularSection name="Услуги" qualifiedName="Документ.ЗаказПокупателя.Услуги" />
|
||||
</Document>
|
||||
</Configuration>
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
snapshot = index_project(tmp_path, project_id="schema-report")
|
||||
|
||||
report = build_project_report(snapshot)
|
||||
|
||||
assert report.attribute_count == 2
|
||||
assert report.object_attribute_count == 1
|
||||
assert report.tabular_section_count == 2
|
||||
assert report.tabular_section_column_count == 1
|
||||
assert report.empty_tabular_section_count == 1
|
||||
assert report.empty_tabular_sections == ["Документ.ЗаказПокупателя.Услуги"]
|
||||
|
||||
|
||||
def test_build_project_report_counts_integrations(tmp_path: Path):
|
||||
module = tmp_path / "integration.bsl"
|
||||
module.write_text(
|
||||
"""
|
||||
Процедура Отправить()
|
||||
Адрес = "https://api.example.local/orders";
|
||||
Объект = Новый COMОбъект("V83.Application");
|
||||
КонецПроцедуры
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
snapshot = index_project(tmp_path, project_id="integration-report")
|
||||
|
||||
report = build_project_report(snapshot)
|
||||
|
||||
assert report.integration_count == 2
|
||||
assert report.outbound_integration_count == 2
|
||||
assert report.integration_kinds["HTTP_SERVICE"] == 1
|
||||
assert report.integration_kinds["COM_CONNECTOR"] == 1
|
||||
Reference in New Issue
Block a user