Les agents lancés sans clé d'API (env nettoyé), testé ; le lien donnees.py / detectors data.py redit dans les contrats
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23e1eea0b8
commit
a53d267531
3 files changed
+25
-6
No files matched your search
@@ -41,6 +41,11 @@ optimisations = {}
|
||||
OCCUPE = "une optimisation des détecteurs est en cours"
|
||||
|
||||
|
||||
def _env():
|
||||
"""L'environnement de claude -p, sans clé d'API : les agents tournent sur l'abonnement Claude, jamais sur une clé."""
|
||||
return {k: v for k, v in os.environ.items() if k not in ("ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN")}
|
||||
|
||||
|
||||
def _optimise():
|
||||
return any(o["etat"] == "en cours" for o in optimisations.values())
|
||||
|
||||
@@ -78,7 +83,7 @@ def travailler(nom, sortie, prompt, reprise=None):
|
||||
"--output-format", "stream-json", "--verbose",
|
||||
"--allowedTools", "Read,Write,Bash", "--permission-mode", "acceptEdits", *station.liens()]
|
||||
+ (["--resume", reprise] if reprise else []),
|
||||
cwd=station.RACINE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
cwd=station.RACINE, env=_env(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
with open(sortie / "travail" / "journal.jsonl", "a", encoding="utf-8") as journal:
|
||||
for ligne in p.stdout:
|
||||
journal.write(ligne)
|
||||
@@ -283,7 +288,7 @@ def optimiser_fil(nom):
|
||||
for dossier, (prompt, *options) in tours:
|
||||
p = subprocess.Popen(["claude", "-p", prompt, "--output-format", "stream-json", "--verbose",
|
||||
"--permission-mode", "acceptEdits", *station.liens(), *options],
|
||||
cwd=dossier, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
cwd=dossier, env=_env(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
for ligne in p.stdout:
|
||||
flux.write(ligne)
|
||||
o["lignes"] += resume(ligne)
|
||||
|
||||
+17
-3
@@ -1,5 +1,6 @@
|
||||
"""Vérifications de la web app, sans appel à claude : .venv/bin/python app/serveur/check.py [nom]"""
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import sys
|
||||
@@ -118,6 +119,8 @@ def check_optimisation():
|
||||
return 0
|
||||
|
||||
avant = analyse.DOSSIER, analyse.subprocess.Popen, analyse.OPTIMIZER, analyse.SEANCES, analyse.AGENTS
|
||||
cle = os.environ.get("ANTHROPIC_API_KEY")
|
||||
os.environ["ANTHROPIC_API_KEY"] = "cle-de-test"
|
||||
racine = seance_temporaire()
|
||||
analyse.DOSSIER, analyse.OPTIMIZER, analyse.AGENTS = racine / "analyses", racine / "optimizer", racine / "agents"
|
||||
analyse.SEANCES = analyse.OPTIMIZER / "seances"
|
||||
@@ -151,6 +154,7 @@ def check_optimisation():
|
||||
assert requete.startswith("/improve ") and "STATION: data/NORDEND. FROM: 2026-11-04. TO: 2026-11-08." in requete \
|
||||
and "OUT: seances/NORDEND_a_" in requete, requete
|
||||
assert k["cwd"] == analyse.OPTIMIZER.resolve() and "--plugin-dir" in args, (args, k)
|
||||
assert all("ANTHROPIC_API_KEY" not in kw["env"] for _, kw in lances), "une clé d'API passe à claude"
|
||||
args, k = lances[1] # puis le tool-builder du dépôt agents, sur le dépôt tools
|
||||
assert args[args.index("--agent") + 1] == "agents:tool-builder" and "Outils : tools/" in args[2], args
|
||||
analyse.analyses["NORDEND_b"]["etat"] = "en cours" # une analyse qui tourne bloque l'optimisation
|
||||
@@ -178,6 +182,9 @@ def check_optimisation():
|
||||
assert analyse.etat("NORDEND_b")["optimisation"] is None
|
||||
finally:
|
||||
fin.set()
|
||||
os.environ.pop("ANTHROPIC_API_KEY")
|
||||
if cle is not None:
|
||||
os.environ["ANTHROPIC_API_KEY"] = cle
|
||||
shutil.rmtree(racine)
|
||||
analyse.DOSSIER, analyse.subprocess.Popen, analyse.OPTIMIZER, analyse.SEANCES, analyse.AGENTS = avant
|
||||
analyse.analyses.clear()
|
||||
@@ -194,7 +201,7 @@ def check_analyse():
|
||||
returncode = 0
|
||||
|
||||
def __init__(self, args, *a, **k):
|
||||
lances.append(args)
|
||||
lances.append((args, k))
|
||||
self.stdout = iter([])
|
||||
|
||||
def wait(self):
|
||||
@@ -205,22 +212,29 @@ def check_analyse():
|
||||
analyse.DOSSIER = Path(tempfile.mkdtemp(dir=station.RACINE / "out"))
|
||||
analyse.subprocess.Popen = FauxProcessus
|
||||
analyse.verser = lambda *a: 0 # sinon le test réécrit le vrai labeling/auto/NORDEND.jsonl
|
||||
cle = os.environ.get("ANTHROPIC_API_KEY")
|
||||
os.environ["ANTHROPIC_API_KEY"] = "cle-de-test" # l'agent tourne sur l'abonnement, jamais sur une clé d'API
|
||||
try:
|
||||
nom = analyse.lancer({"station": "NORDEND", "debut": "2026-11-05T06:00Z", "fin": "2026-11-05T12:00Z"})["nom"]
|
||||
while analyse.analyses[nom]["etat"] == "en cours":
|
||||
time.sleep(0.05)
|
||||
assert analyse.analyses[nom]["etat"] == "fini", analyse.analyses[nom]
|
||||
args = lances[0]
|
||||
args, k = lances[0]
|
||||
assert args[args.index("--agent") + 1] == "agents:analyste" and "--plugin-dir" in args, args
|
||||
assert "ANTHROPIC_API_KEY" not in k["env"] and "PATH" in k["env"], sorted(k.get("env") or {})
|
||||
assert "DETECTEURS : non" in args[2] and "CONSIGNES : consignes/analyste.md" in args[2], args[2]
|
||||
(analyse.DOSSIER / nom / "travail" / "session").write_text("s-1")
|
||||
analyse.message(nom, {"texte": "continue"})
|
||||
while analyse.analyses[nom]["etat"] == "en cours":
|
||||
time.sleep(0.05)
|
||||
args = lances[1]
|
||||
args, k = lances[1]
|
||||
assert "ANTHROPIC_API_KEY" not in k["env"], sorted(k.get("env") or {})
|
||||
assert args[args.index("--resume") + 1] == "s-1" and args[args.index("--agent") + 1] == "agents:analyste" \
|
||||
and "--plugin-dir" in args, args
|
||||
finally:
|
||||
os.environ.pop("ANTHROPIC_API_KEY")
|
||||
if cle is not None:
|
||||
os.environ["ANTHROPIC_API_KEY"] = cle
|
||||
shutil.rmtree(analyse.DOSSIER)
|
||||
analyse.DOSSIER, analyse.subprocess.Popen, analyse.verser = avant
|
||||
analyse.analyses.clear()
|
||||
|
||||
Reference in new issue
Block a user