diff --git a/plugins/1c/connector/adapter_1c_server.py b/plugins/1c/connector/adapter_1c_server.py index 250c2eb..88a3d1d 100644 --- a/plugins/1c/connector/adapter_1c_server.py +++ b/plugins/1c/connector/adapter_1c_server.py @@ -4129,7 +4129,12 @@ def template_type_candidates_from_features(features: dict[str, Any], content_par return candidates -def public_template_summary(parts: list[dict[str, Any]], *, include_storage: bool = False) -> dict[str, Any]: +def public_template_summary( + parts: list[dict[str, Any],], + *, + include_storage: bool = False, + confirmed_platform_type_id: str | None = None, +) -> dict[str, Any]: content_parts = [part for part in parts if part.get("role") != "metadata_payload"] declared_platform_type = next( (template_type for template_type in (declared_template_platform_type_from_part(part) for part in parts) if template_type), @@ -4150,13 +4155,28 @@ def public_template_summary(parts: list[dict[str, Any]], *, include_storage: boo ), } template_type_candidates = template_type_candidates_from_features(features, content_parts) + confirmed_platform_type = onec_template_type_by_id(confirmed_platform_type_id) if confirmed_platform_type_id else None + if confirmed_platform_type and confirmed_platform_type.get("id") != confirmed_platform_type_id: + confirmed_platform_type = None + if confirmed_platform_type: + # This classification comes from the report's decoded Template record, + # not a marker guess in the compressed content stream. In particular, + # an SCD stream has no MOXCEL/HTML marker and must not be presented as + # a low-confidence binary template merely because it is compressed. + confirmed_platform_type.update({"confidence": "high", "evidence": ["confirmed Template identity"]}) + template_type_candidates = [confirmed_platform_type] + [ + candidate for candidate in template_type_candidates if candidate.get("id") != confirmed_platform_type.get("id") + ] summary: dict[str, Any] = { "features": features, "known_platform_types": ONEC_TEMPLATE_PLATFORM_TYPES, "template_type_candidates": template_type_candidates, "counts": {"parts": len(parts), "content_parts": len(content_parts)}, } - if features.get("tabular_document"): + if confirmed_platform_type: + summary["format"] = confirmed_platform_type.get("xml_type") or confirmed_platform_type.get("id") + summary["platform_type"] = confirmed_platform_type.get("name") + elif features.get("tabular_document"): summary["format"] = "ТабличныйДокумент" summary["platform_type"] = "Табличный документ" summary["preview"] = { @@ -42368,9 +42388,17 @@ def metadata_object_templates(payload: dict[str, Any]) -> dict[str, Any]: } ) parts.append(public_part) + category_platform_type = { + "DataCompositionSchema": "data_composition_schema", + "DataCompositionAppearanceTemplate": "data_composition_appearance_template", + }.get(str(item.get("category") or "")) template = { **public_child_identity(item), - **public_template_summary(parts, include_storage=include_storage), + **public_template_summary( + parts, + include_storage=include_storage, + confirmed_platform_type_id=category_platform_type, + ), **({"kind": "data_composition_schema"} if item.get("category") == "DataCompositionSchema" else {}), } if wanted: diff --git a/tests/1c/test_payload_codec.py b/tests/1c/test_payload_codec.py index 7f12e0b..2563216 100644 --- a/tests/1c/test_payload_codec.py +++ b/tests/1c/test_payload_codec.py @@ -10397,6 +10397,12 @@ def test_metadata_object_templates_includes_decoded_data_composition_schema(monk assert result["templates"][0]["name"] == "ОсновнаяСхемаКомпоновкиДанных" assert result["templates"][0]["kind"] == "data_composition_schema" assert result["templates"][0]["match_by"] == "name_exact" + assert result["templates"][0]["platform_type"] == "Схема компоновки данных" + assert result["templates"][0]["template_type_candidates"] == [{ + **adapter_server.onec_template_type_by_id("data_composition_schema"), + "confidence": "high", + "evidence": ["confirmed Template identity"], + }] def test_templates_bindings_preserves_data_composition_schema_kind(monkeypatch: pytest.MonkeyPatch) -> None: