flexicraft-website/tools/test_full_architecture.py

51 lines
2.9 KiB
Python
Raw Permalink Normal View History

import os, sys, json, sqlite3, subprocess
sys.path.insert(0, "/var/www/flexicraft-site")
from core.audit_core import AUDIT_DB, AUDIT_SOCK, GENESIS_HASH, _compute_hash, emit_audit
from core.permissions_bus import evaluate_web_access, resolve_forgejo_team, update_role_domain_guarded
from core.package_updater import load_registry
print("=================================================================")
print(" BANC DE TEST & DIAGNOSTIC GLOBAL — INFRASTRUCTURE FLEXICRAFT")
print("=================================================================")
for svc in ("flexicraft-status", "flexicraft-web", "forgejo"):
st = subprocess.run(["systemctl", "is-active", svc], capture_output=True, text=True).stdout.strip()
print(f" {'✅' if st == 'active' else '❌'} Service {svc:<20} : {st}")
sock_ok = os.path.exists(AUDIT_SOCK)
print(f" {'✅' if sock_ok else '❌'} Socket Unix Audit Bus : {'actif (' + AUDIT_SOCK + ')' if sock_ok else 'ABSENT'}")
web_adm = evaluate_web_access(["683346841265373195"])
fg_team = resolve_forgejo_team(["683346841265373195"])
guard_test = update_role_domain_guarded("TestBot", False, "web", "683346841265373195", {"web_tier": "visitor"})
guard_ok = (not guard_test.get("ok")) and ("Verrou constitutionnel" in guard_test.get("error", ""))
print(f" {'✅' if web_adm.get('admin') and fg_team == 'guardian' else '❌'} Bus Permissions (3 dom.) : web={web_adm.get('tier')} | forgejo={fg_team}")
print(f" {'✅' if guard_ok else '❌'} Garde-fou Anti-Coup d'Etat: {'bloque correctement' if guard_ok else 'ECHEC'}")
reg = load_registry().get("packages", [])
print(f" {'✅' if len(reg) > 0 else '❌'} Registre Paquets : {len(reg)} paquets indexes")
eid = emit_audit("quartz", "self_test", "SystemCheck", "Diagnostic d'intégrité SQLite WAL & SHA-256", "audit.db", {"sphere": "Test Système"})
conn = sqlite3.connect(AUDIT_DB)
wal_mode = next(iter(conn.execute("PRAGMA journal_mode;").fetchone()))
rows = conn.execute("SELECT id, ts, ministry, source, actor_name, action, target, details_json, prev_hash, row_hash FROM audit_events ORDER BY id ASC").fetchall()
conn.close()
expected_prev = GENESIS_HASH
chain_valid = True
for r in rows:
_, ts, m, s, act, ac, tgt, det, ph, rh = r
if ph != expected_prev or rh != _compute_hash(expected_prev, ts, m, s, act, ac, tgt or "", det or "{}"):
chain_valid = False
break
expected_prev = rh
print(f" {'✅' if wal_mode == 'wal' else '❌'} Base SQLite mode WAL : journal_mode={wal_mode} ({len(rows)} evenements)")
print(f" {'✅' if chain_valid else '❌'} Integrite Chaine SHA-256 : {'VALIDE (0 alteration)' if chain_valid else 'CORROMPUE'}")
with open("/var/www/flexicraft-site/config/audit_channels.json", "r") as f:
ch_map = json.load(f).get("channels", {})
linked = sum(1 for v in ch_map.values() if int(v or 0) > 0)
print(f" {'✅' if linked == 12 else '⚠️'} Salons Charcoal mappes : {linked}/12 ministeres relies")