File size: 5,231 Bytes
e26f4cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
"""53_suite_v050.py — Suíte de verificação consolidada v0.5.0.

Agrega: suíte SOM (48), suíte JEPA (49), Pensamento (50), treino real (51),
telemetria (52), suíte V legada (41) e os testes cargo (38/38). Produz o
veredito final com TODOS os gates. Saída: resultados/suite_v050_final.json
"""
import json, os, subprocess, sys

def carrega(pasta, nome):
    c = os.path.join(pasta, "resultados", nome)
    return json.load(open(c)) if os.path.exists(c) else None

def main():
    pasta = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    res = {"versao": "0.5.0", "fontes": {}, "gates": {}, "contagens": {}}

    # 1) suítes já executadas
    for arq, nome in [("suite_som_v050.json", "som"),
                      ("suite_jepa_v050.json", "jepa"),
                      ("pensamento_v050.json", "pensamento"),
                      ("treino_v050.json", "treino_real"),
                      ("telemetria_v050.json", "telemetria")]:
        d = carrega(pasta, arq)
        if d is None:
            print(f"AVISO: {arq} ausente — rode o script correspondente antes")
            continue
        res["fontes"][nome] = arq
        if nome == "som":
            res["contagens"][nome] = d["resumo"]
        elif nome == "jepa":
            res["contagens"][nome] = d["resumo"]
        elif nome == "pensamento":
            res["contagens"][nome] = d["resumo"]
        elif nome == "treino_real":
            res["gates"].update({f"treino.{k}": v for k, v in d["gates"].items()})
            res["contagens"][nome] = {
                "perda_a": [d["fases"]["a"]["perda_inicial"], d["fases"]["a"]["perda_final"]],
                "ce_b": [d["fases"]["b"]["perda_inicial"], d["fases"]["b"]["perda_final"]],
            }
        elif nome == "telemetria":
            for n, s in d["demos"].items():
                if isinstance(s, dict):
                    res["gates"].update({f"tel.{n}.{g[5:]}": v for g, v in s.items() if g.startswith("gate_")})

    # gates embutidos das suítes
    for nome, arq, chave_gates in [("som", "suite_som_v050.json", None), ("jepa", "suite_jepa_v050.json", None)]:
        d = carrega(pasta, arq)
        if d:
            for comp, s in d.get("suites", d.get("variantes", {})).items():
                for g, v in s.items():
                    if g.startswith("gate_"):
                        res["gates"][f"{nome}.{comp}.{g[5:]}"] = v

    # 2) suíte V legada (41)
    d = carrega(pasta, "suite_v.json")
    if d:
        res["fontes"]["v_legada"] = "suite_v.json"
        vs = {k: v.get("ok") for k, v in d.items() if k.startswith("V") and isinstance(v, dict)}
        res["contagens"]["v_legada"] = {
            "bloqueadoras_ok": all(vs.get(k, False) for k in
                                   ("V0_modulo", "V1_config", "V4_mascara", "V9_stiefel", "V10_nfe", "V13_mtp_nivel", "V14_ponte")),
            "n_verdes": sum(1 for v in vs.values() if v), "n_total": len(vs)}

    # 3) testes cargo (contagem rápida sem re-executar: usa o binário de teste)
    try:
        saida = subprocess.run(
            ["bash", "-c",
             f"cd '{pasta}' && export PATH=\"$HOME/.cargo/bin:$PATH\" && "
             "cargo test --release --lib 2>&1 | grep -E 'test result' | tail -1"],
            capture_output=True, text=True, timeout=400)
        linha = saida.stdout.strip()
        # "test result: ok. 38 passed; 0 failed; ..."
        partes = linha.split()
        npass = int(partes[3]) if len(partes) > 3 else 0
        nfail = int(partes[5].rstrip(";")) if len(partes) > 5 else -1
        res["contagens"]["cargo_testes"] = {"linha": linha, "passaram": npass, "falharam": nfail}
        res["gates"]["cargo.suite_completa"] = nfail == 0 and npass >= 38
    except Exception as e:
        res["contagens"]["cargo_testes"] = {"erro": str(e)}

    # 4) veredito final
    ok = sum(1 for v in res["gates"].values() if v)
    tot = len(res["gates"])
    suites_ok = all(
        res["contagens"].get(n, {}).get("todos_verdes", False) or
        res["contagens"].get(n, {}).get("todas_verdes", False)
        for n in ("som", "jepa", "pensamento")
    )
    res["veredito_final"] = {
        "gates_ok": ok, "gates_totais": tot,
        "suites_componentes_verdes": suites_ok,
        "v_legada_ok": res["contagens"].get("v_legada", {}).get("bloqueadoras_ok") is True,
        "APROVADO": ok == tot and suites_ok and res["contagens"].get("v_legada", {}).get("bloqueadoras_ok") is True,
    }
    print(f"=== SUÍTE v0.5.0 CONSOLIDADA ===")
    print(f"  gates agregados: {ok}/{tot}")
    for n in ("som", "jepa", "pensamento"):
        c = res["contagens"].get(n, {})
        print(f"  suíte {n}: {c}")
    print(f"  V legada: {res['contagens'].get('v_legada')}")
    print(f"  cargo: {res['contagens'].get('cargo_testes', {}).get('linha', '?')}")
    print(f"  VEREDITO: {'APROVADO' if res['veredito_final']['APROVADO'] else 'REPROVADO'}")

    with open(os.path.join(pasta, "resultados", "suite_v050_final.json"), "w") as f:
        json.dump(res, f, indent=1, ensure_ascii=False)
    print("salvo: resultados/suite_v050_final.json")
    if not res["veredito_final"]["APROVADO"]:
        sys.exit(1)

if __name__ == "__main__":
    main()