More bugfixes in the glossary protection guard

This commit is contained in:
2026-04-23 10:51:47 -05:00
parent 671188aaba
commit dee6ae4067
3 changed files with 161 additions and 20 deletions

View File

@@ -1042,6 +1042,74 @@ def test_grammar_stage_can_correct_toward_protected_term(tmp_path):
assert list((tmp_path / "work").iterdir()) == []
def test_grammar_stage_allows_quote_wrapping_with_unchanged_lowercase_protected_term(tmp_path):
transcript = parse_source_transcript_json(
"""
[
{
"speaker": "Eric",
"start": 0.0,
"end": 1.0,
"text": "When you say that, Popov will say, when I was in that room with the jesters, I just knew that Godfrey and Lyra came directly from Loviator herself. They're really powerful."
}
]
"""
)
glossary = parse_glossary_yaml(
"""
glossary:
- name: "Popov"
category: npc
summary: "Popov is an allied NPC."
- name: "Jesters"
aliases:
- "Jester"
category: faction
summary: "The Jesters are a faction."
- name: "Godfrey"
category: npc
summary: "Godfrey is an NPC."
- name: "Lyra"
category: npc
summary: "Lyra is an NPC."
- name: "Loviator"
category: deity
summary: "Loviator is a deity."
"""
)
original_text = (
"When you say that, Popov will say, when I was in that room with the jesters, "
"I just knew that Godfrey and Lyra came directly from Loviator herself. They're really powerful."
)
corrected_text = (
'When you say that, Popov will say, "When I was in that room with the jesters, '
'I just knew that Godfrey and Lyra came directly from Loviator herself. '
'They\'re really powerful."'
)
grammar_correction = CorrectionCandidate(
id=1,
original_text=original_text,
corrected_text=corrected_text,
confidence=0.95,
)
fake_client = FakeLLMClient(
[
CorrectionSet(corrections=[]),
CorrectionSet(corrections=[grammar_correction]),
]
)
revised = process_transcript(
transcript,
glossary,
_config(tmp_path),
llm_client=fake_client,
)
assert revised[0].text == corrected_text
assert list((tmp_path / "work").iterdir()) == []
def test_grammar_stage_cannot_change_away_from_protected_term(tmp_path):
transcript = parse_source_transcript_json(
"""

View File

@@ -25,6 +25,12 @@ def _vocabulary():
- name: "Godfrey"
category: npc
summary: "Godfrey is an NPC."
- name: "Lyra"
category: npc
summary: "Lyra is an NPC."
- name: "Loviator"
category: deity
summary: "Loviator is a deity."
"""
)
return ProtectedVocabulary.from_glossary(glossary)
@@ -66,6 +72,12 @@ def test_protection_allows_canonical_capitalization():
assert vocabulary.violation_reason("hrank moves.", "Hrank moves.") is None
def test_protection_allows_unchanged_noncanonical_protected_term():
vocabulary = _vocabulary()
assert vocabulary.violation_reason("jesters advance.", "jesters advance.") is None
def test_protection_allows_correction_toward_protected_term():
vocabulary = _vocabulary()
@@ -98,6 +110,15 @@ def test_protection_blocks_noncanonical_introduced_protected_term():
)
def test_protection_blocks_changed_noncanonical_variant():
vocabulary = _vocabulary()
assert (
vocabulary.violation_reason("jesters advance.", "JESTERS advance.")
== "correction changes protected glossary term capitalization"
)
def test_protection_allows_inferred_name_plural():
vocabulary = _vocabulary()
@@ -135,6 +156,20 @@ def test_protection_allows_punctuation_around_protected_term():
assert vocabulary.violation_reason("Popov, moves.", "Popov. Moves.") is None
def test_protection_allows_quote_wrapping_sentence_with_unchanged_lowercase_protected_term():
vocabulary = _vocabulary()
before = (
"When you say that, Popov will say, when I was in that room with the jesters, "
"I just knew that Godfrey and Lyra came directly from Loviator herself."
)
after = (
'When you say that, Popov will say, "When I was in that room with the jesters, '
'I just knew that Godfrey and Lyra came directly from Loviator herself."'
)
assert vocabulary.violation_reason(before, after) is None
def test_protection_does_not_match_terms_inside_larger_words():
vocabulary = _vocabulary()
@@ -145,3 +180,12 @@ def test_protection_applies_to_aliases():
vocabulary = _vocabulary()
assert vocabulary.violation_reason("Greenfield waits.", "greenfield waits.") is not None
def test_protection_blocks_removing_preexisting_protected_occurrence():
vocabulary = _vocabulary()
assert (
vocabulary.violation_reason("Jesters flank the Jesters.", "Jesters flank the gestures.")
== "correction changes protected glossary term usage"
)