Files
ss-tools/backend/tests/test_layout_utils.py
busya f49b7d909e feat: GRACE-Poly protocol optimization — ~3200→10 warnings (↓99.7%)
Full optimization cycle:

Protocol (15 files):
- 4-layer SSOT architecture for agent prompts & skills
- Anti-Corruption Protocol consolidated from 5 duplicates
- Tag-to-tier permissiveness matrix (all @tags allowed at all tiers)

Axiom config:
- complexity_rules: all 22+ tags available on C1-C5
- contract_type_overrides: removed (was narrowing per-type)
- 18 new tags added, LAYER enum expanded (Infra, Frontend, Atom, etc.)
- RELATION predicates expanded (USES, CONTAINS, BELONGS_TO, etc.)

Code fixes:
- 2216 @TAG: normalized to @TAG (colon→space)
- 518 [DEF] blocks migrated to #region/#endregion (37 files)
- VERIFIES→BINDS_TO, :Class/:Function suffixes removed, paths→IDs
- 1173-line _external_stubs.py deleted (EXT: handled natively)
- Batch EXT: reference audit (240 targets: 132 external, 99 internal, 9 fix)
- QA regression check: 0 regressions across all checks

Infrastructure:
- DuckDB rebuild stabilized (appender API, INSERT OR IGNORE)
- Anchor regex fix (parent-child BINDS_TO now resolves)
- EXT:*/DTO:/NEED_CONTEXT: regex fixed in validator
- 34MB Doxygen API portal (3194 contract pages)
2026-05-26 11:14:25 +03:00

56 lines
2.5 KiB
Python

# #region TestLayoutUtils [C:3] [TYPE TestModule] [SEMANTICS test, layout, superset, height, estimation]
# @BRIEF Contract tests for layout utility functions — _estimate_markdown_height.
# Verifies the height estimation formula: empty → 19, short text → computed,
# padding accounted for, and long text capped at 200.
# @LAYER Test
# @RELATION BINDS_TO -> [LayoutUtils]
# @TEST_CONTRACT: _estimate_markdown_height(str) -> int in [19, 200]
# @TEST_EDGE: empty_content -> returns minimum height (19)
# @TEST_EDGE: html_only_content -> returns minimum height (19)
# @TEST_EDGE: content_with_padding -> padding:12 correctly increases height
# @TEST_EDGE: very_long_content -> capped at maximum height (200)
import pytest
from src.core.superset_client._layout_utils import _estimate_markdown_height
class TestEstimateMarkdownHeight:
"""Tests for _estimate_markdown_height pure function."""
# #region test_empty_content [C:2] [TYPE Function]
# @BRIEF Empty string returns minimum height 19.
def test_empty_content(self):
assert _estimate_markdown_height("") == 19
# #endregion test_empty_content
# #region test_single_line_text [C:2] [TYPE Function]
# @BRIEF Short text without padding returns expected computed height.
# 200 chars → 200//40+1 = 6 lines → 6*22 = 132px → 40+132 = 172px → 172//8 = 21
def test_single_line_text(self):
text = "A" * 200
assert _estimate_markdown_height(text) == 21
# #endregion test_single_line_text
# #region test_content_with_padding [C:2] [TYPE Function]
# @BRIEF Content with padding:12 — 24px added to content height.
# 200 chars + padding:12 → 6*22 + 24 = 156 → 40+156 = 196 → 196//8 = 24
def test_content_with_padding(self):
content = '<div style="padding:12">' + "A" * 200 + "</div>"
assert _estimate_markdown_height(content) == 24
# #endregion test_content_with_padding
# #region test_very_long_content [C:2] [TYPE Function]
# @BRIEF Very long content (3000 chars) capped at max height 200.
def test_very_long_content(self):
text = "A" * 3000
assert _estimate_markdown_height(text) == 200
# #endregion test_very_long_content
# #region test_html_only_content [C:2] [TYPE Function]
# @BRIEF HTML-only content (no visible text) returns minimum height 19.
def test_html_only_content(self):
content = "<br/><hr/><div></div>"
assert _estimate_markdown_height(content) == 19
# #endregion test_html_only_content
# #endregion TestLayoutUtils