from pathlib import Path from types import SimpleNamespace from phase_z2_composition import select_layout_preset from phase_z2_pipeline import _build_task24_layout_decision_basis, parse_mdx def _sample_mdx(prefix: str) -> Path: for path in sorted(Path("samples/mdx").glob(f"{prefix}*.mdx")): if "(원본)" not in path.name: return path raise AssertionError(f"sample mdx not found for prefix {prefix!r}") def _unit(section_id: str): return SimpleNamespace(source_section_ids=[section_id]) def _zone(position: str, template_id: str = "frame"): return { "position": position, "template_id": template_id, "content_weight": { "score": 1.0, "text_length": 100, "subsection_count": 2, }, "min_height_px": 120, } def test_task24_mdx01_intro_counts_as_top_level_body_zone(): _, sections, footer = parse_mdx(_sample_mdx("01.")) units = [_unit(s.section_id) for s in sections] assert [s.section_id for s in sections] == ["01-intro", "01-1", "01-2"] assert select_layout_preset(units) == "top-1-bottom-2" basis = _build_task24_layout_decision_basis( units=units, zones_data=[_zone("top"), _zone("bottom-left"), _zone("bottom-right")], slide_footer=footer, layout_preset="top-1-bottom-2", auto_layout_preset="top-1-bottom-2", layout_override_applied=False, ) assert basis["task24"] == "normalized_top_level_unit_layout" assert basis["top_level_unit_count"] == 3 assert basis["zone_count"] == 3 assert basis["summary_footer_excluded_from_zone_count"] is True assert basis["unit_source_section_ids"] == [["01-intro"], ["01-1"], ["01-2"]] def test_task24_registered_component_expansion_stays_frame_internal(): _, sections, footer = parse_mdx(_sample_mdx("02.")) units = [_unit(s.section_id) for s in sections] assert [s.section_id for s in sections] == ["02-1", "02-2"] assert select_layout_preset(units) == "horizontal-2" assert sections[1].sub_sections assert sections[1].sub_sections[0]["component"] == "DxEffect" basis = _build_task24_layout_decision_basis( units=units, zones_data=[_zone("top"), _zone("bottom")], slide_footer=footer, layout_preset="horizontal-2", auto_layout_preset="horizontal-2", layout_override_applied=False, ) assert basis["top_level_unit_count"] == 2 assert basis["zone_count"] == 2 assert basis["unit_source_section_ids"] == [["02-1"], ["02-2"]] assert "component expansions are frame-internal" in basis["policy"] def test_task24_footer_never_increases_body_zone_count(): units = [_unit("09-1"), _unit("09-2")] basis = _build_task24_layout_decision_basis( units=units, zones_data=[_zone("top"), _zone("bottom")], slide_footer="Source footer text", layout_preset="horizontal-2", auto_layout_preset="horizontal-2", layout_override_applied=False, ) assert basis["fixed_footer_present"] is True assert basis["summary_footer_excluded_from_zone_count"] is True assert basis["top_level_unit_count"] == 2 assert basis["zone_count"] == 2