"""Run the LexGo backend with local environment settings without exposing secrets.""" from pathlib import Path import os import subprocess import sys ROOT = Path(__file__).resolve().parents[1] def main(): commands = { "migrate": ["go", "run", "./cmd/lexgo", "migrate"], "bootstrap": ["go", "run", "./cmd/lexgo", "bootstrap"], "serve": ["go", "run", "./cmd/lexgo", "serve"], "audit-cleanup": ["go", "run", "./cmd/lexgo", "audit-cleanup"], "build": ["go", "build", "./cmd/lexgo"], "test": ["go", "test", "./...", "-count=1"], "test-integration": ["go", "test", "./...", "-count=1", "-v"], } if len(sys.argv) != 2 or sys.argv[1] not in commands: raise SystemExit("Usage: python scripts/server.py migrate|bootstrap|serve|audit-cleanup|build|test|test-integration") env = dict(os.environ) config = ROOT / ".env.local" if config.exists(): for line in config.read_text(encoding="utf-8").splitlines(): if line.strip() and not line.lstrip().startswith("#") and "=" in line: key, value = line.split("=", 1) if key.startswith("LEXGO_"): env.setdefault(key.strip(), value.strip()) env["GOTOOLCHAIN"] = "go1.26.5" env["GOSUMDB"] = "sum.golang.org" env["GIN_MODE"] = "release" if sys.argv[1] == "test-integration": env.setdefault("LEXGO_TEST_DB_NAME", "lexgo_test_issue2") # Tests only use an explicitly supplied dedicated DSN; the Go tests enforce its prefix. return subprocess.call(commands[sys.argv[1]], cwd=str(ROOT / "server"), env=env) if __name__ == "__main__": sys.exit(main())