Files
claude-seo/tests/test_content_humanize.py
Agrici DanielandClaude Fable 5.1 f78c644590 fix(content-humanize): stop over-deleting emoji-adjacency glue near non-Latin scripts
PR #279's strip_invisible() treated any codepoint at or above U+2100 as
"emoji" when deciding whether to keep a ZWNJ/ZWJ next to it. That range
also covers CJK ideographs, Hangul, and (crucially) misses Arabic,
Persian, Urdu, Devanagari, Bengali, and Tamil letters, which sit below
U+2100. The result: ZWNJ/ZWJ characters that are orthographic in those
scripts (Persian's word-joining pseudo-space, Devanagari conjuncts) were
being stripped as if they were hidden-text watermarks, corrupting the
words.

Replace the range test with a real emoji test (unicodedata category
"So" plus the U+1F000-U+1FAFF and U+2600-U+27BF ranges), and add an
explicit guard so ZWNJ/ZWJ is never removed when either neighbouring
character is a Unicode letter (category L*), which covers every script
that uses these joiners orthographically. Emoji ZWJ sequences remain
handled via the emoji test; isolated ZWNJ/ZWJ next to punctuation or
digits (no letter, no emoji) is still stripped as a fingerprint.

Also fixes the seo-content SKILL.md example, which called the launcher
as a bare `claude-seo run` instead of the hosted-plugin invocation form
(`"${CLAUDE_PLUGIN_ROOT}/scripts/claude-seo" run`), which the
test_hosted_plugin_layout.py bare-invocation gate caught once merged
onto v2.3.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015qjDbqj88SjLGY4MdQKGB8
2026-09-10 20:45:06 +03:00

98 lines
3.3 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tests for content_humanize.py: phrase swaps + invisible-character strip."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))
from content_humanize import humanize, strip_invisible # noqa: E402
def test_zero_width_space_removed_inside_word():
cleaned, removed = strip_invisible("wat​er​mark")
assert cleaned == "watermark"
assert removed == {"zero-width-space": 2}
def test_exotic_spaces_normalised():
cleaned, removed = strip_invisible("10 GW and more")
assert cleaned == "10 GW and more"
assert removed["space"] == 2
def test_line_separator_becomes_newline():
cleaned, _ = strip_invisible("a
b")
assert cleaned == "a\nb"
def test_emoji_sequences_preserved():
family = "\U0001f468‍\U0001f469‍\U0001f467"
warning = "⚠️"
keycap = "1️⃣"
text = f"{family} {warning} {keycap}"
cleaned, removed = strip_invisible(text)
assert cleaned == text
assert removed == {}
def test_stray_variation_selector_stripped():
# VS-16 sandwiched between plain ASCII is a fingerprint, not an emoji.
cleaned, removed = strip_invisible("pla️in")
assert cleaned == "plain"
assert removed == {"variation-selector-16": 1}
def test_unicode_tag_characters_stripped():
# Tag characters (U+E0000 block) are used to smuggle hidden text.
hidden = "".join(chr(0xE0000 + ord(c)) for c in "hi")
cleaned, removed = strip_invisible(f"visible{hidden}")
assert cleaned == "visible"
assert removed == {"unicode-tag-character": 2}
def test_directional_override_stripped():
cleaned, removed = strip_invisible("safe‮vil")
assert cleaned == "safevil"
assert removed == {"rlo-override": 1}
def test_humanize_strips_invisible_before_phrase_matching():
# A zero-width space inside "delve" must not defeat the \b pattern.
result = humanize("Let's del​ve into roofing.")
assert "delve" not in result["cleaned"]
assert result["invisible_count"] == 1
assert any(c["label"] == "delve-into" for c in result["changes"])
def test_humanize_reports_zero_on_clean_text():
result = humanize("Plain honest prose about roof repair.")
assert result["cleaned"] == "Plain honest prose about roof repair."
assert result["invisible_count"] == 0
assert result["change_count"] == 0
def test_zwnj_preserved_in_persian_orthography():
# ZWNJ between letters is orthographic in Persian (a "pseudo-space" that
# blocks glyph joining), not a hidden-text fingerprint. Deleting it
# changes the word's correct letter-joining shape.
for word in ("می‌رود", "کتاب‌ها"):
cleaned, removed = strip_invisible(word)
assert cleaned == word
assert removed == {}
def test_zwj_preserved_in_devanagari_conjunct():
# ZWJ between letters requests an explicit half-form/conjunct in
# Devanagari; it is orthographic, not a watermark.
word = "कार्य‍कर्ता"
cleaned, removed = strip_invisible(word)
assert cleaned == word
assert removed == {}
def test_stray_zwj_between_digits_still_stripped():
# A ZWJ with no letter or emoji neighbour is still a fingerprint.
cleaned, removed = strip_invisible("12‍34")
assert cleaned == "1234"
assert removed == {"zero-width-joiner": 1}