"""Unit tests for the bridge's `!testme` / `!testme --quick` trigger parser (WC7 + D1). Pure: imports bridge/bridge.py (stdlib-only, no side effects at import — main() is __main__-guarded). Locks the two accepted forms and the must-NOT-trigger cases the Adversary probes (`!testmexyz`, etc.). """ from __future__ import annotations import os import sys # bridge.py reads HMAC/DRONE/GITEA secret FILES at import; point them at /dev/null (readable, empty) # so the import works in a unit context — parse_trigger doesn't use any of them. for _v in ("HMAC_FILE", "DRONE_TOKEN_FILE", "GITEA_TOKEN_FILE"): os.environ.setdefault(_v, "/dev/null") sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "bridge")) import bridge # noqa: E402 def test_plain_testme_is_cold(): assert bridge.parse_trigger("!testme") == (True, False) assert bridge.parse_trigger(" !testme ") == (True, False) # trimmed def test_quick_form(): assert bridge.parse_trigger("!testme --quick") == (True, True) assert bridge.parse_trigger(" !testme --quick \n") == (True, True) def test_non_trigger_forms_rejected(): for body in ( "!testmexyz", # the Adversary's classic negative "!testme xyz", "!testme--quick", # no space → not the quick form "!testme --quick", # double space → not an exact match (conservative) "please !testme", "testme", "", None, ): assert bridge.parse_trigger(body) == (False, False), body