diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-30 13:55:05 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-30 13:55:05 -0500 |
| commit | 5bd759151d3ccf2d0a90f4b7de71e8c0e6e4a0a1 (patch) | |
| tree | d25e5300cfa05d272efb124af2dfd6470fed8e55 /.ai/scripts/tests | |
| parent | 82e99ff8a4eb6d5aaba6ee02da3b5318a73b2125 (diff) | |
| download | rulesets-5bd759151d3ccf2d0a90f4b7de71e8c0e6e4a0a1.tar.gz rulesets-5bd759151d3ccf2d0a90f4b7de71e8c0e6e4a0a1.zip | |
feat(drill-deck): add authoring-quality checks and a card-authoring section
I researched spaced-repetition best practices (Wozniak's twenty rules, Matuschak's prompt-writing guide, Nielsen, the Anki and FSRS docs) and folded the findings into the drill-deck pipeline.
drill-deck-stats.py now checks authoring quality on top of structure. Two checks block: answer leakage (a question that echoes >= 80% of its own answer's content words tests recognition, not recall) and duplicate / near-duplicate fronts (confusable cards interfere). Three checks warn without blocking, surfacing rewrite candidates without failing the gate: overloaded backs, list-shaped backs, and binary yes/no prompts. The fuzzy thresholds live in constants at the top of the script, so a real deck that trips false positives can be tuned. I pulled the card-parsing into a parse_cards helper that captures each card's body, and added focused tests for every new helper plus CLI coverage of the leaky, duplicate, and notes-only cases.
drill-deck-review.org gains a Card Authoring Principles section (the why behind the canonical shapes, with sources), a person-card splitting path bounded by the :ID:-preservation rule, a Phase B cost-benefit-removal and leech-reformulation disposition, and a scheduling-is-Anki-side note so a future editor doesn't try to encode FSRS retention in the org source. I left out cloze cards (would need a second note type), per-card tractability targeting and retention encoding (Anki-side telemetry that never reaches the source), and on-face source-stamping (the converter strips those drawers by design). Each is noted with its reason.
Diffstat (limited to '.ai/scripts/tests')
| -rw-r--r-- | .ai/scripts/tests/test_drill_deck_stats.py | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/.ai/scripts/tests/test_drill_deck_stats.py b/.ai/scripts/tests/test_drill_deck_stats.py index 3154d42..80b9913 100644 --- a/.ai/scripts/tests/test_drill_deck_stats.py +++ b/.ai/scripts/tests/test_drill_deck_stats.py @@ -132,3 +132,174 @@ def test_cli_properties_count_mismatch_warns_and_exits_one(tmp_path): r = _run(f) assert r.returncode == 1 assert "does not match card count" in r.stdout + + +# --- content_words / leakage_ratio (pure) --- + +def test_content_words_drops_stopwords_and_short_tokens(stats): + assert stats.content_words("What is the LEO regime?") == {"leo", "regime"} + + +def test_leakage_ratio_high_when_answer_restates_question(stats): + ratio = stats.leakage_ratio( + "primary orbital regimes satellites", + "the primary orbital regimes for satellites are listed", + ) + assert ratio == 1.0 + + +def test_leakage_ratio_zero_for_short_question(stats): + # "LEO" is the only content word, below LEAKAGE_MIN_WORDS, so overlap is noise. + assert stats.leakage_ratio("What is LEO?", "LEO means low earth orbit") == 0.0 + + +# --- normalize_heading (pure) --- + +def test_normalize_heading_lowercases_and_strips_punctuation(stats): + assert stats.normalize_heading(" What is L.E.O.? ") == "what is l e o" + + +def test_normalize_heading_collisions_match(stats): + assert stats.normalize_heading("What is LEO?") == stats.normalize_heading("what is leo") + + +# --- is_binary_prompt (pure) --- + +def test_is_binary_prompt_true_for_yes_no_lead(stats): + assert stats.is_binary_prompt("Is LEO below GEO?") is True + + +def test_is_binary_prompt_true_for_a_or_b(stats): + assert stats.is_binary_prompt("Is it LEO or GEO?") is True + + +def test_is_binary_prompt_false_for_open_question(stats): + assert stats.is_binary_prompt("What distinguishes LEO from GEO?") is False + + +# --- back_word_count / is_list_back (pure) --- + +def test_back_word_count(stats): + assert stats.back_word_count("one two three") == 3 + assert stats.back_word_count("") == 0 + + +def test_is_list_back_true_for_bulleted_body(stats): + assert stats.is_list_back("- LEO\n- MEO\n- GEO") is True + + +def test_is_list_back_false_for_prose(stats): + assert stats.is_list_back("Low Earth Orbit.\nThe closest regime.") is False + + +def test_is_list_back_false_for_single_bullet(stats): + assert stats.is_list_back("- only one bullet\nplain prose line") is False + + +# --- parse_cards (pure) --- + +def test_parse_cards_captures_body_without_drawer_planning_or_answer_header(stats): + text = ( + "* Sec\n" + "** Q one? :drill:\n" + ":PROPERTIES:\n:ID: id-1\n:END:\n" + "SCHEDULED: <2026-05-20 Wed>\n" + "*** Answer\n" + "the real answer\n" + ) + cards, prop_count = stats.parse_cards(text.splitlines()) + assert prop_count == 1 + assert len(cards) == 1 + c = cards[0] + assert c["heading"] == "Q one?" + assert c["has_id"] is True + assert c["has_answer"] is True + assert c["body"] == "the real answer" + + +def test_find_duplicate_fronts_matches_normalized_headings(stats): + cards = [ + {"heading": "What is LEO?"}, + {"heading": "what is leo?"}, + {"heading": "What is GEO?"}, + ] + dups = stats.find_duplicate_fronts(cards) + assert len(dups) == 1 + assert dups[0] == ("What is LEO?", "what is leo?") + + +# --- CLI: new blocking checks --- + +LEAKY_DECK = """#+TITLE: Test Flashcards + +* Section +** What are the primary orbital regimes for satellites? :drill: +:PROPERTIES: +:ID: c1 +:END: +The primary orbital regimes for satellites are listed here. +""" + +DUP_FRONT_DECK = """#+TITLE: Test Flashcards + +* Section +** What is LEO? :drill: +:PROPERTIES: +:ID: c1 +:END: +Low Earth Orbit. +** What is LEO? :drill: +:PROPERTIES: +:ID: c2 +:END: +Low Earth Orbit, restated. +""" + + +def test_cli_answer_leakage_warns_and_exits_one(tmp_path): + f = tmp_path / "leaky.org" + f.write_text(LEAKY_DECK) + r = _run(f) + assert r.returncode == 1 + assert "leak" in r.stdout.lower() + + +def test_cli_duplicate_front_warns_and_exits_one(tmp_path): + f = tmp_path / "dup.org" + f.write_text(DUP_FRONT_DECK) + r = _run(f) + assert r.returncode == 1 + assert "duplicate" in r.stdout.lower() + + +# --- CLI: non-blocking NOTEs keep exit 0 --- + +NOTES_DECK = """#+TITLE: Test Flashcards + +* Section +** Is LEO closer than GEO? :drill: +:PROPERTIES: +:ID: c1 +:END: +Yes, much closer. +** What orbital regimes exist? :drill: +:PROPERTIES: +:ID: c2 +:END: +- LEO +- MEO +- GEO +** Describe the platform elements in full :drill: +:PROPERTIES: +:ID: c3 +:END: +The platform carries power generation, propulsion, attitude control, thermal regulation, and radio hardware arranged around a central frame. Each element draws from shared resources and must survive launch loads, vacuum, and radiation. Engineers trade mass against capability when every kilogram raises cost, so redundancy is added only where a single failure would end the mission entirely and cheaper options cannot cover the same risk. +""" + + +def test_cli_non_blocking_notes_keep_exit_zero(tmp_path): + f = tmp_path / "notes.org" + f.write_text(NOTES_DECK) + r = _run(f) + assert r.returncode == 0 + assert "NOTE" in r.stdout |
