"""Width contract through parsing, document operations and real HTTP boundaries.""" import os import tempfile import unittest from dataclasses import asdict from html.parser import HTMLParser from pathlib import Path from unittest.mock import patch from fastapi.testclient import TestClient from test_fragment_catalog_ui import environment from theme_fixture import seed, write from site_engine.build.pipeline import build_site, make_views from site_engine.core.block_layout import BlockLayout, default_layout from site_engine.core.layout_marks import apply_layout from site_engine.core.models import parse_block from site_engine.core.page_ops import find_block from site_engine.core.registry import load_site from site_engine.core.render import Renderer from site_engine.core.routes import build_route_table from site_engine.core.validate import validate_workspace from site_engine.errors import Report from site_engine.parsing.yamlio import dump_yaml from site_engine.services.auth import hash_password from site_engine.services.documents import DocumentService, EditorContext class Elements(HTMLParser): def __init__(self, html): super().__init__() self.items = [] self.feed(html) def handle_starttag(self, tag, attrs): self.items.append((tag, dict(attrs))) class BlockLayoutTest(unittest.TestCase): def test_strict_shapes_modes_and_unknown_keys(self): for raw in (None, False, [], "full", {"width": "boxed"}, {"section_width": []}, {"section_width": "wide"}, {"content_width": 1080}, {"content_width": None}): with self.subTest(layout=raw): report = Report() block = parse_block({"id": "test_block", "fragment": "hero", "layout": raw}, "test", report) self.assertIsNone(block) self.assertIn("E_BLOCK_LAYOUT", report.codes()) self.assertTrue(all(".layout" in i.path for i in report.errors)) def test_all_modes_defaults_and_explicit_inheritance(self): for fragment in ("hero", "cta_banner", "site_header", "site_footer", "richtext", "columns"): block = parse_block({"id": "test_block", "fragment": fragment}, "test", Report()) self.assertIsNone(block.layout) expected = "full" if fragment in ("hero", "cta_banner", "site_header", "site_footer") else "inherit" self.assertEqual(default_layout(fragment).section_width, expected) for section in ("inherit", "boxed", "fluid", "full"): for content in ("inherit", "boxed", "fluid", "full"): report = Report() block = parse_block({"id": "test_block", "fragment": "hero", "layout": {"section_width": section, "content_width": content}}, "test", report) self.assertTrue(report.ok) effective = block.layout.resolve("fluid") self.assertEqual(effective.section_width, "fluid" if section == "inherit" else section) self.assertEqual(effective.content_width, "fluid" if content == "inherit" else content) def test_layout_marks_do_not_change_roots_or_overwrite_nested_block_containers(self): child = apply_layout('
', BlockLayout("boxed", "fluid")) source = '
' + child + '
' html = apply_layout(source, BlockLayout("full", "boxed")) self.assertEqual(html.count("