WOTD _polish: enforce the "examples must use the word" contract

Per Codex audit: only accept a polish when there's a gloss AND at least one
example sentence that actually contains the word (case-insensitive). Examples
that don't use the word are dropped; if none remain, fall back to the raw
dictionary def/examples instead of shipping a gloss with empty/irrelevant usage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jay
2026-06-23 07:56:22 -04:00
parent 26b23a8f09
commit bdf3b1f47b
2 changed files with 31 additions and 4 deletions
+27 -3
View File
@@ -108,13 +108,37 @@ def test_pick_lazy_polishes_older_words(conn, monkeypatch):
def test_polish_trims_and_caps_two_examples():
class C:
def chat_text(self, m):
return 'sure: {"gloss": " Calm and peaceful. ", "examples": ["One.", "Two.", "Three."]} done'
return ('sure: {"gloss": " Calm and peaceful. ", "examples": '
'["A serene lake.", "The serene night.", "A serene mood."]} done')
out = wotd._polish(C(), "serene", "adjective", "x")
assert out["gloss"] == "Calm and peaceful." and out["examples"] == ["One.", "Two."]
assert out["gloss"] == "Calm and peaceful." and out["examples"] == ["A serene lake.", "The serene night."]
def test_polish_returns_none_without_a_gloss():
class C:
def chat_text(self, m):
return '{"examples": ["x"]}'
return '{"examples": ["A serene lake."]}'
assert wotd._polish(C(), "serene", None, "x") is None
def test_polish_drops_examples_that_dont_use_the_word():
# the word must appear (case-insensitive) — example here keeps only the matching one
class C:
def chat_text(self, m):
return '{"gloss": "Calm.", "examples": ["It was quiet.", "A SERENE harbor."]}'
out = wotd._polish(C(), "serene", "adjective", "x")
assert out["examples"] == ["A SERENE harbor."]
def test_polish_returns_none_when_no_example_uses_the_word():
class C:
def chat_text(self, m):
return '{"gloss": "A warm clear gloss.", "examples": ["Totally unrelated.", "Still nothing."]}'
assert wotd._polish(C(), "serene", "adjective", "x") is None
def test_polish_returns_none_with_empty_examples():
class C:
def chat_text(self, m):
return '{"gloss": "A warm clear gloss.", "examples": []}'
assert wotd._polish(C(), "serene", "adjective", "x") is None