refactor: heading transforms + dedup moved to shared layer

- conversion_planner.py: caps normalization in _build_chapters()
- conversion_executor.py: heading dedup + state machine via headings_equivalent()
- Fixed seg_start_time → chapter_body_start bug in executor
- Removed getattr fallback defaults in both adapters
- Added 4 tests for caps normalization and heading dedup
- Updated ARCHITECTURE_REFACTOR_PLAN.md with deferred WebUI cleanup
This commit is contained in:
Artem Akymenko
2026-07-26 11:41:59 +03:00
parent f516cf1985
commit 0b953d48e8
6 changed files with 180 additions and 4 deletions
+28
View File
@@ -641,3 +641,31 @@ class TestFeatureParity:
if output_format.lower() == "m4b":
merge_chapters_at_end = True
assert merge_chapters_at_end is True
class TestCapsNormalization:
"""Tests for caps normalization in planner."""
def test_caps_normalization_applied_when_enabled(self):
"""When normalize_chapter_opening_caps=True, body text is normalized."""
req = ConversionRequest(
direct_text="<<CHAPTER_MARKER:Chapter 1>>\nALL CAPS OPENING TEXT here",
voice="M1",
normalize_chapter_opening_caps=True,
)
plan = build_conversion_plan(req)
body = plan.chapters[0].body_text
# ALL CAPS should be normalized to Title Case
assert body != "ALL CAPS OPENING TEXT here"
assert "ALL CAPS" not in body
def test_caps_normalization_skipped_when_disabled(self):
"""When normalize_chapter_opening_caps=False, body text is unchanged."""
req = ConversionRequest(
direct_text="<<CHAPTER_MARKER:Chapter 1>>\nALL CAPS OPENING TEXT here",
voice="M1",
normalize_chapter_opening_caps=False,
)
plan = build_conversion_plan(req)
body = plan.chapters[0].body_text
assert "ALL CAPS OPENING TEXT" in body