init
This commit is contained in:
32
backend/tests/test_modell_ids.py
Normal file
32
backend/tests/test_modell_ids.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Wächter für Leitprinzip 2: Modell-IDs stehen NUR in der .env, nie im Code.
|
||||
|
||||
Greppt den gesamten backend-Quellcode (ohne tests/) nach Modell-ID-Mustern.
|
||||
Schlägt dieser Test an, hat jemand ein Modell hart verdrahtet.
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
BACKEND = Path(__file__).resolve().parent.parent
|
||||
MUSTER = re.compile(r"claude-\w+-\d|MiniMax-M\d|\bopus\b|\bsonnet\b|\bhaiku\b|gpt-\d",
|
||||
re.IGNORECASE)
|
||||
|
||||
|
||||
def test_keine_modell_ids_im_code():
|
||||
treffer = []
|
||||
for pfad in BACKEND.rglob("*.py"):
|
||||
if "tests" in pfad.parts:
|
||||
continue
|
||||
for nr, zeile in enumerate(pfad.read_text(encoding="utf-8").splitlines(), 1):
|
||||
if MUSTER.search(zeile):
|
||||
treffer.append(f"{pfad.relative_to(BACKEND)}:{nr}: {zeile.strip()}")
|
||||
assert not treffer, "Modell-IDs im Code gefunden (gehören in die .env):\n" + "\n".join(treffer)
|
||||
|
||||
|
||||
def test_keine_modell_ids_in_templates():
|
||||
templates = BACKEND / "templates"
|
||||
if not templates.is_dir():
|
||||
return
|
||||
treffer = [f"{p.name}:{nr}" for p in templates.rglob("*.md")
|
||||
for nr, zeile in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
|
||||
if MUSTER.search(zeile)]
|
||||
assert not treffer, f"Modell-IDs in Templates: {treffer}"
|
||||
Reference in New Issue
Block a user