| 1 | """Tests for scripts/lib/preflight.py Class 1 keyword-trap refuse-gate. |
| 2 | |
| 3 | Class 1 (demographic shopping) is the one failure class that shipped to |
| 4 | public v3.0.8 and still returned junk for queries like 'birthday gift for |
| 5 | 40 year old'. This module is the engine's structural refusal, so the model |
| 6 | cannot bypass by skipping SKILL.md. |
| 7 | """ |
| 8 | |
| 9 | import unittest |
| 10 | |
| 11 | from lib import preflight |
| 12 | |
| 13 | |
| 14 | class TestClass1Match(unittest.TestCase): |
| 15 | """Queries that MUST trigger the refuse-gate.""" |
| 16 | |
| 17 | def test_birthday_gift_for_age(self): |
| 18 | self.assertIsNotNone(preflight.check_class_1_trap("birthday gift for 40 year old")) |
| 19 | |
| 20 | def test_gift_for_age(self): |
| 21 | self.assertIsNotNone(preflight.check_class_1_trap("gift for 42 year old")) |
| 22 | |
| 23 | def test_gift_for_age_relationship(self): |
| 24 | self.assertIsNotNone(preflight.check_class_1_trap("gift for my 42 year old husband")) |
| 25 | |
| 26 | def test_gift_ideas_for_age(self): |
| 27 | self.assertIsNotNone(preflight.check_class_1_trap("gift ideas for 30 year old")) |
| 28 | |
| 29 | def test_present_for_age(self): |
| 30 | self.assertIsNotNone(preflight.check_class_1_trap("present for a 50 year old")) |
| 31 | |
| 32 | def test_hyphenated_year_old(self): |
| 33 | self.assertIsNotNone(preflight.check_class_1_trap("gift for 40-year-old")) |
| 34 | |
| 35 | def test_best_for_men(self): |
| 36 | self.assertIsNotNone(preflight.check_class_1_trap("best running shoes for men")) |
| 37 | |
| 38 | def test_best_for_women(self): |
| 39 | self.assertIsNotNone(preflight.check_class_1_trap("best gifts for women")) |
| 40 | |
| 41 | def test_best_for_kids(self): |
| 42 | self.assertIsNotNone(preflight.check_class_1_trap("best toys for kids")) |
| 43 | |
| 44 | def test_what_to_buy_husband(self): |
| 45 | self.assertIsNotNone(preflight.check_class_1_trap("what to buy my husband")) |
| 46 | |
| 47 | def test_what_to_get_boss(self): |
| 48 | self.assertIsNotNone(preflight.check_class_1_trap("what to get my boss")) |
| 49 | |
| 50 | def test_what_to_gift_age(self): |
| 51 | self.assertIsNotNone(preflight.check_class_1_trap("what to gift a 35 year old")) |
| 52 | |
| 53 | def test_gifts_for_husband(self): |
| 54 | self.assertIsNotNone(preflight.check_class_1_trap("gifts for my husband")) |
| 55 | |
| 56 | def test_case_insensitive(self): |
| 57 | self.assertIsNotNone(preflight.check_class_1_trap("Birthday Gift For 40 Year Old")) |
| 58 | |
| 59 | def test_leading_whitespace(self): |
| 60 | self.assertIsNotNone(preflight.check_class_1_trap(" gift for 40 year old ")) |
| 61 | |
| 62 | |
| 63 | class TestClass1Skip(unittest.TestCase): |
| 64 | """Queries that MUST NOT trigger the refuse-gate (qualifier present or not shopping).""" |
| 65 | |
| 66 | def test_named_person(self): |
| 67 | self.assertIsNone(preflight.check_class_1_trap("Peter Steinberger")) |
| 68 | |
| 69 | def test_comparison(self): |
| 70 | self.assertIsNone(preflight.check_class_1_trap("OpenClaw vs Paperclip")) |
| 71 | |
| 72 | def test_entity_query(self): |
| 73 | self.assertIsNone(preflight.check_class_1_trap("Kanye West")) |
| 74 | |
| 75 | def test_general_concept(self): |
| 76 | self.assertIsNone(preflight.check_class_1_trap("vibe coding")) |
| 77 | |
| 78 | def test_budget_qualifier(self): |
| 79 | self.assertIsNone(preflight.check_class_1_trap("gift for my husband, $200 budget")) |
| 80 | |
| 81 | def test_hobby_qualifier(self): |
| 82 | self.assertIsNone(preflight.check_class_1_trap("gift for my cooking-obsessed husband")) |
| 83 | |
| 84 | def test_loves_qualifier(self): |
| 85 | self.assertIsNone(preflight.check_class_1_trap("gift for my dad who loves golf")) |
| 86 | |
| 87 | def test_is_into_qualifier(self): |
| 88 | self.assertIsNone(preflight.check_class_1_trap("gift for my brother who is into woodworking")) |
| 89 | |
| 90 | def test_specific_interest_in_query(self): |
| 91 | self.assertIsNone(preflight.check_class_1_trap("birthday gift for 40 year old runner")) |
| 92 | |
| 93 | |
| 94 | class TestRefuseMessage(unittest.TestCase): |
| 95 | """The REFUSE message must contain the diagnostic content the model needs.""" |
| 96 | |
| 97 | def test_refuse_mentions_class_1(self): |
| 98 | msg = preflight.check_class_1_trap("birthday gift for 40 year old") |
| 99 | assert msg is not None |
| 100 | self.assertIn("Class 1", msg) |
| 101 | |
| 102 | def test_refuse_asks_for_hobbies(self): |
| 103 | msg = preflight.check_class_1_trap("gift for 40 year old") |
| 104 | assert msg is not None |
| 105 | self.assertIn("hobbies", msg.lower()) |
| 106 | |
| 107 | def test_refuse_asks_for_relationship(self): |
| 108 | msg = preflight.check_class_1_trap("gift for 40 year old") |
| 109 | assert msg is not None |
| 110 | self.assertIn("relationship", msg.lower()) |
| 111 | |
| 112 | def test_refuse_asks_for_budget(self): |
| 113 | msg = preflight.check_class_1_trap("gift for 40 year old") |
| 114 | assert msg is not None |
| 115 | self.assertIn("budget", msg.lower()) |
| 116 | |
| 117 | def test_refuse_echoes_topic(self): |
| 118 | msg = preflight.check_class_1_trap("birthday gift for 40 year old") |
| 119 | assert msg is not None |
| 120 | self.assertIn("birthday gift for 40 year old", msg) |
| 121 | |
| 122 | if __name__ == "__main__": |
| 123 | unittest.main() |
| 124 |