Grammar corrections now run through a deterministic guard that blocks protected glossary names/aliases from being changed

This commit is contained in:
2026-04-22 09:04:00 -05:00
parent e50124fa0d
commit 9afb5c5a4e
9 changed files with 238 additions and 5 deletions

View File

@@ -305,6 +305,59 @@ def test_grammar_stage_runs_after_glossary_and_sees_corrected_text(tmp_path):
assert revised[0].text == "I ask Chauntea."
def test_grammar_stage_cannot_reverse_glossary_protected_term(tmp_path):
transcript = parse_source_transcript_json(
"""
[
{"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "Frank moves."}
]
"""
)
glossary = parse_glossary_yaml(
"""
glossary:
- name: "Hrank"
category: pc
summary: "Hrank is a player character."
"""
)
glossary_correction = CorrectionCandidate(
id=1,
original_text="Frank",
corrected_text="Hrank",
confidence=0.95,
)
grammar_reversal = CorrectionCandidate(
id=1,
original_text="Hrank",
corrected_text="Frank",
confidence=0.95,
)
fake_client = FakeLLMClient(
[
CorrectionSet(corrections=[glossary_correction]),
CorrectionSet(corrections=[grammar_reversal]),
]
)
progress = []
revised = process_transcript(
transcript,
glossary,
_config(tmp_path, grammar_max_llm_passes=1),
llm_client=fake_client,
progress=progress.append,
)
assert revised[0].text == "Hrank moves."
assert any("Skipping grammar correction for id 1" in message for message in progress)
run_dirs = list((tmp_path / "work").iterdir())
assert len(run_dirs) == 1
diagnostics = json.loads((run_dirs[0] / "skipped-corrections.json").read_text(encoding="utf-8"))
assert diagnostics["skipped_corrections"][0]["stage"] == "grammar"
assert "protected glossary term" in diagnostics["skipped_corrections"][0]["reason"]
def test_grammar_stage_retries_repeated_span_and_applies_unique_retry(tmp_path):
transcript = parse_source_transcript_json(
"""