Noms plus clairs : snippets/, scripts de test numérotés, verifier_ollama.py
- base_connaissances/ → snippets/ (corpus/ → textes/, instructions.md → consignes_redaction.md, decoupage.py → fichiers.py, importer.py → envoyer.py) ; python3 -m snippets.envoyer. - instance-de-test/ : 1_demarrer.sh, 2_creer_boite_et_cle.py, 3_brancher_ia.py, 4_essayer_brouillons.py, voir_empreintes.sh, connexion_admin.py. - ollama/verifier.py → ollama/verifier_ollama.py ; tests, tâches VS Code et docs alignés. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e0b5d03a3
commit
10ed887417
142 files changed
+89
-85
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import socket
|
||||
import unittest
|
||||
|
||||
from base_connaissances.decoupage import Extrait
|
||||
from base_connaissances.importer import Extraits, html, synchroniser
|
||||
from snippets.fichiers import Extrait
|
||||
from snippets.envoyer import Extraits, html, synchroniser
|
||||
from faux_libredesk import FauxLibreDesk
|
||||
|
||||
LISTE = ("GET", "/api/v1/ai/snippets")
|
||||
@@ -2,7 +2,7 @@ import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from base_connaissances.decoupage import Extrait, decouper_markdown, decouper_pdf, ecrire_corpus, lire_corpus
|
||||
from snippets.fichiers import Extrait, decouper_markdown, decouper_pdf, ecrire_textes, lire_textes
|
||||
|
||||
TOC = ("Contents\nInstall . . . . . . 1\n Does it start? . . . . . 1\n How long does the\n battery last? . . . . 2\n"
|
||||
"Data . . . . 3 Which formats? . . . . 3\n")
|
||||
@@ -50,12 +50,12 @@ class TestDecouperMarkdown(unittest.TestCase):
|
||||
|
||||
|
||||
class TestCorpus(unittest.TestCase):
|
||||
def test_aller_retour_du_corpus(self):
|
||||
def test_aller_retour_des_textes(self):
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
d = Path(t)
|
||||
x = [Extrait("Which formats?", "CSV.", "AIMsight FAQ, rév. 1.5")]
|
||||
ecrire_corpus(x, d)
|
||||
self.assertEqual(lire_corpus(d), x)
|
||||
ecrire_textes(x, d)
|
||||
self.assertEqual(lire_textes(d), x)
|
||||
self.assertEqual((d / "which-formats.md").read_text().splitlines()[-1], "Source : AIMsight FAQ, rév. 1.5")
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""Le paquet base_connaissances ne parle à LibreDesk que par les routes des extraits (design §2, plan Global Constraints)."""
|
||||
"""Le paquet snippets ne parle à LibreDesk que par les routes des extraits (design §2, plan Global Constraints)."""
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
PAQUET = Path(__file__).resolve().parents[1] / "base_connaissances"
|
||||
PAQUET = Path(__file__).resolve().parents[1] / "snippets"
|
||||
AUTORISEES = {"/api/v1/ai/snippets", "/api/v1/ai/snippets/{id}"} # la route PUT s'écrit f"/api/v1/ai/snippets/{id}"
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ class TestGardeFouBase(unittest.TestCase):
|
||||
for interdit in ("/messages", "/conversations", "DELETE", "automations", "assistants"):
|
||||
self.assertNotIn(interdit, texte, f"{interdit} dans {f.name}")
|
||||
|
||||
def test_le_paquet_a_bien_un_client(self): # sans importer.py, le test ci-dessus passerait à vide
|
||||
self.assertTrue((PAQUET / "importer.py").exists())
|
||||
def test_le_paquet_a_bien_un_client(self): # sans envoyer.py, le test ci-dessus passerait à vide
|
||||
self.assertTrue((PAQUET / "envoyer.py").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -12,7 +12,7 @@ OLLAMA = Path(__file__).resolve().parents[1] / "ollama"
|
||||
COMPOSE = OLLAMA / "compose.yml"
|
||||
DOCKERFILE = OLLAMA / "Dockerfile"
|
||||
sys.path.insert(0, str(OLLAMA))
|
||||
from verifier import verifier # noqa: E402
|
||||
from verifier_ollama import verifier # noqa: E402
|
||||
|
||||
|
||||
class FauxOllama:
|
||||
@@ -83,7 +83,7 @@ class TestVerifier(unittest.TestCase):
|
||||
|
||||
class TestCompatibilite(unittest.TestCase):
|
||||
def test_verifier_lisible_par_un_vieux_python(self): # le Python du serveur est inconnu (3.8, 3.9…)
|
||||
texte = (OLLAMA / "verifier.py").read_text()
|
||||
texte = (OLLAMA / "verifier_ollama.py").read_text()
|
||||
arbre = ast.parse(texte)
|
||||
futur = any(isinstance(n, ast.ImportFrom) and n.module == "__future__"
|
||||
and any(a.name == "annotations" for a in n.names) for n in arbre.body)
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestTaches(unittest.TestCase):
|
||||
|
||||
def test_import_instance_de_test_lit_son_env(self):
|
||||
for libelle, c in commandes().items():
|
||||
if "base_connaissances.importer" in c and "instance de test" in libelle.lower():
|
||||
if "snippets.envoyer" in c and "instance de test" in libelle.lower():
|
||||
self.assertIn("instance-de-test/.env", c, libelle)
|
||||
|
||||
def test_effacer_l_instance_demande_confirmation(self):
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"""Le corpus versionné de la base de connaissances : présent, propre, sans rien d'interne."""
|
||||
"""Les textes des snippets (snippets/textes/) : présent, propre, sans rien d'interne."""
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from base_connaissances.decoupage import lire_corpus
|
||||
from snippets.fichiers import lire_textes
|
||||
|
||||
CORPUS = Path(__file__).resolve().parents[1] / "base_connaissances" / "corpus"
|
||||
TEXTES = Path(__file__).resolve().parents[1] / "snippets" / "textes"
|
||||
STATIONS = ["BREITHORN", "CLARIDEN", "FLORIDA", "JUNGFRAU", "LENZSPITZE", "MICHIGAN", "NADELHORN", "NEBRASKA",
|
||||
"NIEDERHORN", "NORDEND", "SNCF01", "SUSTENHORN", "WILDSTRUBEL", "VERMONT", "WEISSHORN", "MISSISSIPPI"]
|
||||
INTERDITS = ["python3", "agent-tools", ".py", "Marc", "Barcelone", "Vaud", "GN-1", "GN-5", "seuil provisoire",
|
||||
@@ -13,20 +13,20 @@ INTERDITS = ["python3", "agent-tools", ".py", "Marc", "Barcelone", "Vaud", "GN-1
|
||||
|
||||
|
||||
class TestCorpus(unittest.TestCase):
|
||||
def test_corpus_present(self):
|
||||
self.assertGreaterEqual(len(lire_corpus(CORPUS)), 60)
|
||||
def test_textes_presents(self):
|
||||
self.assertGreaterEqual(len(lire_textes(TEXTES)), 60)
|
||||
|
||||
def test_titres_uniques_et_contenus_non_vides(self):
|
||||
x = lire_corpus(CORPUS)
|
||||
x = lire_textes(TEXTES)
|
||||
self.assertEqual(len({e.titre for e in x}), len(x))
|
||||
self.assertTrue(all(e.contenu.strip() and e.source.strip() for e in x))
|
||||
|
||||
def test_taille_raisonnable(self):
|
||||
trop_longs = [e.cle for e in lire_corpus(CORPUS) if len(e.contenu) > 8000]
|
||||
trop_longs = [e.cle for e in lire_textes(TEXTES) if len(e.contenu) > 8000]
|
||||
self.assertEqual(trop_longs, [])
|
||||
|
||||
def test_rien_d_interne(self):
|
||||
for e in lire_corpus(CORPUS):
|
||||
for e in lire_textes(TEXTES):
|
||||
texte = e.titre + "\n" + e.contenu
|
||||
for s in STATIONS:
|
||||
self.assertIsNone(re.search(rf"\b{s}\b", texte, re.I), f"{s} dans {e.cle}")
|
||||
@@ -34,27 +34,27 @@ class TestCorpus(unittest.TestCase):
|
||||
self.assertNotIn(i.lower(), texte.lower(), f"{i} dans {e.cle}")
|
||||
|
||||
def test_sources_sans_chemin_interne(self): # la source part dans LibreDesk avec l'extrait
|
||||
chemins = [e.cle for e in lire_corpus(CORPUS) if "/" in e.source or ".md" in e.source]
|
||||
chemins = [e.cle for e in lire_textes(TEXTES) if "/" in e.source or ".md" in e.source]
|
||||
self.assertEqual(chemins, [])
|
||||
|
||||
def test_mesure_au_dessus_du_seuil_pas_dite_retiree(self): # elle est jugée non valable mais livrée
|
||||
for e in lire_corpus(CORPUS):
|
||||
for e in lire_textes(TEXTES):
|
||||
if e.source.startswith("Savoir métier"):
|
||||
for faux in ("retirée", "retirées", "supprimée"):
|
||||
self.assertNotIn(faux, e.contenu, f"{faux} dans {e.cle}")
|
||||
|
||||
def test_pas_de_chiffres_d_une_seule_station_presentes_comme_tels(self):
|
||||
for e in lire_corpus(CORPUS):
|
||||
for e in lire_textes(TEXTES):
|
||||
for interne in ("Ces chiffres viennent", "station solaire de 21 Ah", "n'a pas été observé"):
|
||||
self.assertNotIn(interne, e.contenu, f"{interne} dans {e.cle}")
|
||||
|
||||
def test_instructions_ne_contredisent_pas_la_faq(self):
|
||||
texte = (CORPUS.parent / "instructions.md").read_text()
|
||||
texte = (TEXTES.parent / "consignes_redaction.md").read_text()
|
||||
for faux in ("Heures en UTC, dites comme telles", "jamais que la station les rejette", "adresse IP)"):
|
||||
self.assertNotIn(faux, texte)
|
||||
|
||||
def test_instructions_presentes(self):
|
||||
texte = (CORPUS.parent / "instructions.md").read_text()
|
||||
texte = (TEXTES.parent / "consignes_redaction.md").read_text()
|
||||
self.assertIn("langue du client", texte)
|
||||
self.assertLessEqual(len(texte), 4000)
|
||||
|
||||
Reference in new issue
Block a user