Classify common template payloads consistently

This commit is contained in:
2026-08-14 13:31:58 +03:00
parent 945ba28c4b
commit 863bda9436
2 changed files with 22 additions and 0 deletions
+11
View File
@@ -42362,9 +42362,20 @@ def metadata_object_templates(payload: dict[str, Any]) -> dict[str, Any]:
) )
if direct.get("status") != "ok": if direct.get("status") != "ok":
return direct return direct
parts_result = metadata_object_parts(
{
"base_id": base_id, "guid": guid, "kind": "Template", "table": table,
"include_text": bool(include_text), "include_tree": bool(include_tree),
"include_storage": include_storage, "evidence_mode": evidence_mode,
"timeout_seconds": timeout_seconds,
}
)
classified_parts = parts_result.get("parts") if isinstance(parts_result.get("parts"), list) else []
common_summary = public_template_summary(classified_parts, include_storage=include_storage) if classified_parts else {}
templates = [] templates = []
for template_item in direct.get("templates") or []: for template_item in direct.get("templates") or []:
item = dict(template_item) item = dict(template_item)
item.update(common_summary)
item["name"] = item.get("name") or (object_card or {}).get("name") item["name"] = item.get("name") or (object_card or {}).get("name")
item["kind"] = "CommonTemplate" item["kind"] = "CommonTemplate"
item["ref"] = (object_card or {}).get("ref") or object_selector_ref("CommonTemplate", str(item.get("name") or "")) item["ref"] = (object_card or {}).get("ref") or object_selector_ref("CommonTemplate", str(item.get("name") or ""))
+11
View File
@@ -7012,6 +7012,17 @@ def test_public_template_summary_recognizes_live_appearance_xml_root() -> None:
assert summary["template_type_candidates"][0]["evidence"] == ["payload XML root"] assert summary["template_type_candidates"][0]["evidence"] == ["payload XML root"]
def test_common_template_inventory_uses_parts_classifier(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(adapter_server, "resolve_object_guid", lambda *_args, **_kwargs: ("a" * 36, None, {"name": "Оформление", "ref": "CommonTemplate.Оформление"}, None))
monkeypatch.setattr(adapter_server, "read_template_by_guid", lambda _payload: {"status": "ok", "source": {"kind": "live_sql"}, "templates": [{"guid": "a" * 36}]})
monkeypatch.setattr(adapter_server, "metadata_object_parts", lambda _payload: {"parts": [{"role": "content", "classification": {"xml_root": "AppearanceTemplate"}, "features": {}}]})
result = adapter_server.metadata_object_templates({"base_id": "upo_test", "kind": "CommonTemplate", "name": "Оформление"})
assert result["templates"][0]["platform_type"] == "Макет оформления компоновки данных"
assert result["templates"][0]["name"] == "Оформление"
def test_moxel_template_artifact_kind_tracks_coordinate_hint_schema() -> None: def test_moxel_template_artifact_kind_tracks_coordinate_hint_schema() -> None:
assert adapter_server.MOXEL_TEMPLATE_ARTIFACT_KIND == "template_part_moxel_v11" assert adapter_server.MOXEL_TEMPLATE_ARTIFACT_KIND == "template_part_moxel_v11"