[DTP-Worker 20260812_110124] fix correctness · financement_bancaire overall_percent — la barre GLOBALE pouvait afficher 100.0 tout en BLOQUANT (l'invariant per-condition de 093114 ne s'était pas propagé à l'agrégat) → matrice 634→635 · test à dents · exemple byte-identique · sans gate

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Code DTP Worker
2026-08-12 11:09:49 +00:00
parent 626c39d958
commit 1992ee63be
11 changed files with 80 additions and 22 deletions
@@ -171,6 +171,14 @@ def gate_status(dossier: dict, cfg: GateConfig) -> dict:
overall = _round1(
sum(conditions[k]["percent"] for k in CONDITION_KEYS) / len(CONDITION_KEYS)
)
# Même invariant qu'au niveau condition (cf. _cond_apport) mais à l'AGRÉGAT :
# la moyenne de 4 percents peut arrondir à 100.0 alors qu'une condition reste
# bloquante — p. ex. apport plafonné à 99.9 (non ok) + les 3 autres à 100.0 →
# (99.9 + 300) / 4 = 99.975 → round1 = 100.0. La barre GLOBALE afficherait
# « 100 % » tout en refusant la soumission (403). On plafonne donc à 99.9.
# Invariant d'affichage : overall_percent == 100.0 ⟺ can_submit.
if not can_submit and overall >= 100.0:
overall = 99.9
return {
"can_submit": can_submit,
"conditions_total": len(CONDITION_KEYS),
@@ -133,6 +133,24 @@ class GateCheckTest(unittest.TestCase):
_, reasons = gate.can_submit_dossier(d, self.cfg)
self.assertTrue(any("Apport initial incomplet" in r and "100" not in r for r in reasons))
def test_overall_percent_agrege_ninclut_pas_100pct(self):
# Invariant d'affichage AGRÉGAT (frère du test per-condition ci-dessus,
# mais au niveau de la barre GLOBALE) : overall_percent == 100.0 ⟺
# can_submit. Cas limite = apport plafonné à 99.9 (non ok) + les 3 autres
# conditions ok à 100.0 → moyenne (99.9 + 300) / 4 = 99.975, qui arrondit
# à 100.0 par _round1. Sans la garde, la barre globale afficherait
# « 100 % » tout en bloquant la soumission (403) — auto-contradiction.
d = _dossier_complet(self.cfg, self.spec)
d["paiements"] = [{"montant_verse_usd": 19999}] # 20 000 requis → apport non ok
status = gate.gate_status(d, self.cfg)
self.assertFalse(status["can_submit"])
# les 3 autres conditions sont bien complètes (isolation du cas limite)
self.assertTrue(status["conditions"]["documents_exiges"]["ok"])
self.assertTrue(status["conditions"]["autorisations_signees"]["ok"])
self.assertTrue(status["conditions"]["validation_wag"]["ok"])
self.assertLess(status["overall_percent"], 100.0)
self.assertEqual(status["overall_percent"], 99.9)
def test_apport_manquant_bloque(self):
d = _dossier_complet(self.cfg, self.spec)
d["paiements"] = [{"montant_verse_usd": 19999}]