#!/usr/bin/env python3
"""Regression tests for echo.py client-side normalization."""

from __future__ import annotations

import json

import echo


def test_heading_replace_body_is_newline_guarded() -> None:
    assert (
        echo.normalize_patch_body(b"- [x] Formalized\n", "replace", "heading")
        == b"\n- [x] Formalized\n"
    )


def test_heading_append_body_ends_with_newline() -> None:
    assert echo.normalize_patch_body(b"- item", "append", "heading") == b"- item\n"


def test_frontmatter_plain_string_becomes_json_scalar() -> None:
    assert json.loads(echo.normalize_json_scalar("Fabrication Lead")) == "Fabrication Lead"


def test_frontmatter_existing_json_is_preserved() -> None:
    assert echo.normalize_json_scalar('"2026-06-20"') == b'"2026-06-20"'


if __name__ == "__main__":
    test_heading_replace_body_is_newline_guarded()
    test_heading_append_body_ends_with_newline()
    test_frontmatter_plain_string_becomes_json_scalar()
    test_frontmatter_existing_json_is_preserved()
    print("test_echo_client: ok")
