"""No em dash in anything a shopper or the client reads.

The house style (agents.md, OVERNIGHT-RULES.md) had reached the tests and the client pages
but not the storefront: on 10 Sep fifteen remained in shopper-facing strings (the shared
title, the savings page, the airport picker's maximum notice, the search placeholder) and
one in a served product title the night before. This walks the SPA sources and the served
strings so the next one fails here. Comments may still use one; only string content is read.
"""

import pathlib
import re

from app.services.seo import DEFAULT_TITLE

WEB = pathlib.Path(__file__).resolve().parents[1] / "web"
COMMENT = re.compile(r"/\*.*?\*/|^\s*//.*$|^\s*\*.*$", re.S | re.M)


def sources():
    for path in sorted((WEB / "src").rglob("*")):
        # The vendored packs (src/vendor) are byte-identical to their sources and never edited;
        # a pack string that could reach the client is overridden through a prop where it
        # carries an em dash (the thread starter's hint), so DFP's own files are the test.
        if "vendor" in path.relative_to(WEB / "src").parts:
            continue
        if path.suffix in (".ts", ".tsx") and path.name != "schema.ts":
            yield path
    yield WEB / "index.html"


def test_no_em_dash_outside_comments():
    offenders = []
    for path in sources():
        text = COMMENT.sub("", path.read_text())
        for number, line in enumerate(text.splitlines(), 1):
            if "\u2014" in line:
                offenders.append(f"{path.relative_to(WEB)}:{number}: {line.strip()[:80]}")
    assert not offenders, "\n".join(offenders)


def test_served_titles_carry_none():
    assert "\u2014" not in DEFAULT_TITLE
