from buddhagpt.datagen import build_messages, parse_pairs, dedupe, interleaved_variant def test_build_messages_varies_templates(): sutta = {"uid": "mn21", "title": "T", "text": "x" * 900} prompts = {build_messages(sutta, v)[1]["content"] for v in range(6)} assert len(prompts) == 6 # rotating templates, not one fixed prompt def test_interleaved_variant_cycles_all_templates(): # Any run of >=6 calls must touch every template, not just the first one or two. variants = [interleaved_variant(i) for i in range(18)] assert set(variants) == {0, 1, 2, 3, 4, 5} assert variants[:6] == [0, 1, 2, 3, 4, 5] assert variants == variants[:6] * 3 def test_parse_pairs_extracts_json_lines(): out = '{"question": "Q1?", "answer": "A1"}\n{"question": "Q2?", "answer": "A2"}' assert len(parse_pairs(out, uid="mn21")) == 2 def test_dedupe_drops_near_duplicates(): pairs = [{"question": "What is craving?", "answer": "a"}, {"question": "What is craving?", "answer": "b"}, {"question": "How does one practice metta?", "answer": "c"}] assert len(dedupe(pairs)) == 2