fix(maintenance): auto-expiry + adaptive markdown height + tests

- Auto-expiry: expired events auto-end on GET /events via task manager
- Height: _estimate_markdown_height adapted to unit=8px scale with padding detection
- CRITICAL-1: removed dead import remove_chart_from_position (QA finding)
- CRITICAL-2: added chart alive check in ensure_banner_chart (QA finding)
- CRITICAL-3: fixed test assertions update_markdown_chart → update_banner_on_dashboard
- @POST contract: fixed return range [2,12] → [19,200]
- Tests: 8 new tests (auto-expiry + layout height)
This commit is contained in:
2026-05-25 08:36:33 +03:00
parent 2bf686674e
commit 31680a1bc9
100 changed files with 19635 additions and 7923 deletions

View File

@@ -0,0 +1,55 @@
# #region test_layout_utils [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 test_layout_utils