import json
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent


def test_wordpool_answers_are_valid_and_guessable():
    """Every daily-word answer must be lowercase alpha, the right length, unique,
    and present in the bundled guess dictionary — so no answer is ever unguessable.
    Locks the 'code disposes' invariant against future pool additions."""
    pool = json.loads((ROOT / "goodnews" / "data" / "wordpool.json").read_text())
    for variant, n in (("5", 5), ("6", 6)):
        dictwords = set(json.loads((ROOT / "frontend" / "static" / f"words-{n}.json").read_text()))
        answers = pool[variant]
        assert answers, f"{variant}-letter pool is empty"
        assert len(answers) == len(set(answers)), f"{variant}-letter pool has duplicates"
        for w in answers:
            assert isinstance(w, str) and w.isalpha() and w.islower(), f"bad token: {w!r}"
            assert len(w) == n, f"{w!r} is not {n} letters"
            assert w in dictwords, f"{w!r} not in the guess dictionary → would be unguessable"
