"""The poller reads LibreDesk only through conversations.pomper.Lecteur (GET only) and writes only to Supabase.""" import re import unittest from pathlib import Path from poller.poll import Supabase ROOT = Path(__file__).resolve().parents[1] class TestGuardPoller(unittest.TestCase): def test_never_a_libredesk_route(self): files = list((ROOT / "poller").glob("*.py")) self.assertTrue(files) for f in files: self.assertNotIn("/api/v1/", f.read_text(), f.name) def test_writes_only_to_supabase(self): text = (ROOT / "poller" / "poll.py").read_text() self.assertEqual(set(re.findall(r'"(/[a-z]+/v1/)', text)) - {"/rest/v1/", "/storage/v1/"}, set()) with self.assertRaises(ValueError): Supabase("http://x", "k")._request("POST", "/api/v1/conversations", b"") def test_secrets_never_in_the_image(self): # the build context is the repository root ignored = (ROOT / ".dockerignore").read_text().split() self.assertIn("**/.env", ignored) self.assertIn(".git", ignored) def test_db_password_not_in_the_container_env(self): # poller/.env is the container's env_file self.assertIsNone(re.search(r"DB_PASSWORD[^\n]*>> poller/\.env", (ROOT / "docs" / "production.md").read_text())) if __name__ == "__main__": unittest.main()