HSCP-T-024 · open test
Log of AI module deactivations and dependency alerts
What the test checks
The artefact is the log, one JSON object per event (JSON Lines): evenement (desactivation, reactivation, mesure, alerte_dependance), horodatage, utilisateur, module; for a measurement or an alert: periode_jours, propositions, acceptees_sans_modification, seuil.
The test accepts the log if each event carries its fields; if each measurement whose rate of acceptance without change reaches the threshold, over at least the minimum number of proposals, is followed by an alert for the same user and the same module; and if no alert is raised below the threshold.
Running the test
python3 verifier.py journal.jsonl --minimum 50
--minimum sets the number of proposals below which a measurement does not trigger an alert (50 by default), --json gives the answer in JSON. Exit code: 0 artefact accepted, 1 artefact rejected, 2 incorrect call. Python 3.10 or later, no dependencies.
Examples
exemples/valide/: a deactivation then a reactivation, a measurement above the threshold followed by its alert, a measurement over too few proposals without an alert. Accepted.exemples/refuse/: deactivation without a user, measurement above the threshold without an alert, alert below the threshold, inconsistent numbers, event outside the list. Rejected.
What the test does not say
- It does not say that a user depends on the system: the alert opens the question.
- It does not say that deactivation is effective in the product, or that rejecting a proposal is as easy as accepting it: the review of the screenshots judges that.
- It does not say that the threshold is well chosen.
Code
Download the test (zip archive: program, examples, README, licence) (10 KB) · verifier.py
The code and its messages are not translated (French).
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 les contributeurs des Gestes communs du logiciel de santé
"""HSCP-T-024 : journal des désactivations de modules d'IA et des alertes de dépendance.
python3 verifier.py <journal.jsonl> [--minimum N] [--json]
Lit le journal, un objet JSON par événement (JSON Lines) : evenement (desactivation, reactivation,
alerte_dependance, mesure), horodatage, utilisateur, module ; pour mesure et alerte_dependance : periode_jours,
propositions, acceptees_sans_modification, seuil.
Refus : ligne illisible ; événement hors liste ; champ obligatoire absent ; horodatage illisible ; mesure aux
nombres incohérents ou seuil hors de ]0, 1] ; mesure au-dessus du seuil, sur au moins --minimum propositions
(50 par défaut), sans alerte ultérieure pour le même utilisateur et le même module ; alerte émise sous le seuil.
Il ne dit pas qu'un utilisateur dépend du système, ni que la désactivation est effective dans le produit.
Codes de retour : 0 pièce acceptée, 1 pièce refusée, 2 appel incorrect.
Bibliothèque standard seulement, aucun accès réseau.
"""
import argparse
import datetime as dt
import json
import sys
ID = "HSCP-T-024"
BASE = ("horodatage", "utilisateur", "module")
MESURE = ("periode_jours", "propositions", "acceptees_sans_modification", "seuil")
EVENEMENTS = {"desactivation": BASE, "reactivation": BASE, "mesure": BASE + MESURE, "alerte_dependance": BASE + MESURE}
def entier(v):
return isinstance(v, int) and not isinstance(v, bool) and v >= 0
def verifier(chemin, minimum):
refus, n, mesures, alertes = [], 0, [], []
for num, ligne in enumerate(open(chemin, encoding="utf-8"), 1):
if not ligne.strip():
continue
try:
e = json.loads(ligne)
assert isinstance(e, dict)
except (ValueError, AssertionError):
refus.append(f"ligne {num} : objet JSON illisible")
continue
n += 1
t = e.get("evenement")
if t not in EVENEMENTS:
refus.append(f"ligne {num} : événement hors liste")
continue
nom = f"ligne {num} ({t}, {e.get('utilisateur') or '?'}, {e.get('module') or '?'})"
manque = [c for c in EVENEMENTS[t] if e.get(c) in (None, "")]
if manque:
refus.append(f"{nom} : champ(s) absent(s) : {', '.join(manque)}")
continue
try:
h = dt.datetime.fromisoformat(str(e["horodatage"])).replace(tzinfo=None)
except ValueError:
refus.append(f"{nom} : horodatage illisible")
continue
if t in ("mesure", "alerte_dependance"):
p, a, s = e["propositions"], e["acceptees_sans_modification"], e["seuil"]
if not (entier(p) and entier(a) and a <= p and p > 0 and isinstance(s, (int, float)) and 0 < s <= 1):
refus.append(f"{nom} : nombres incohérents ou seuil hors de ]0, 1]")
continue
taux = a / p
if t == "mesure":
mesures.append((nom, h, e["utilisateur"], e["module"], taux, s, p))
else:
alertes.append((h, e["utilisateur"], e["module"]))
if taux < s:
refus.append(f"{nom} : alerte émise sous le seuil ({taux:.2f} < {s})")
for nom, h, u, m, taux, s, p in mesures:
if taux >= s and p >= minimum and not any(ha >= h and ua == u and ma == m for ha, ua, ma in alertes):
refus.append(f"{nom} : acceptation {taux:.2f} au-dessus du seuil {s} sans alerte")
if n == 0:
refus.append("journal vide")
return refus, n
def main(argv):
p = argparse.ArgumentParser(prog="verifier.py", description=__doc__.splitlines()[0])
p.add_argument("journal")
p.add_argument("--minimum", type=int, default=50)
p.add_argument("--json", action="store_true")
try:
a = p.parse_args(argv)
except SystemExit:
return 2
try:
refus, n = verifier(a.journal, a.minimum)
except OSError as e:
print(f"{ID} : pièce illisible : {e}", file=sys.stderr)
return 2
if a.json:
print(json.dumps({"test": ID, "accepte": not refus, "evenements": n, "refus": refus}, ensure_ascii=False, indent=2))
else:
print(f"{ID} : {'pièce acceptée' if not refus else 'pièce refusée'} ({n} événement(s))")
for x in refus:
print(" refus :", x)
return 0 if not refus else 1
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))