File size: 6,764 Bytes
06e4b6f | 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #!/usr/bin/env python3
"""77_suite_v010.py — v0.10.0: VEREDITO CONSOLIDADO das críticas Qwen3.8
(lote 3 — análise/prova/teste em r-35).
Herda os gates da v0.9.0 (suite_v090_final.json) e adiciona:
s1 divisão SRP: nenhum arquivo-fonte > 60 kB; subdiretórios presentes;
testes herdados verdes (preservação de comportamento);
s2 checkpoint atômico: manifestos SHA-256 presentes e válidos nos
checkpoints do treino REAL; overhead de armazenamento ≈ 141 B;
s3 tipos de domínio: cargo inclui os testes T-V3 (contados em 76);
s4 polimorfismo de camadas: testes CK no cargo (idem);
s5 treino real: fases A/B com perda decrescente; C com CE decrescente;
δ_ort < 1e-5 (ortogonalidade exata em treino real);
s6 CLI: comandos versao/estados/verificar-checkpoints executam.
Saída: resultados/suite_v010_final.json
"""
import json, os, subprocess, sys
PASTA = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
R = os.path.join(PASTA, "resultados")
def main():
rel = {"versao": "0.10.0", "blocos": {}, "gates": {}, "medicoes": {}}
def carrega(arq):
p = os.path.join(R, arq)
return json.load(open(p)) if os.path.exists(p) else None
# ---- legado v0.9.0
legado = carrega("suite_v090_final.json")
if legado:
g_legado = legado.get("gates", legado)
ok = sum(1 for v in g_legado.values() if v is True)
rel["blocos"]["legado_v090"] = f"{ok}/{len(g_legado)}"
for k, v in g_legado.items():
rel["gates"][f"legado_{k}"] = v
# ---- s1: divisão SRP
arquivos = []
for raiz, _, nfs in os.walk(os.path.join(PASTA, "src")):
for n in nfs:
if n.endswith(".rs"):
p = os.path.join(raiz, n)
arquivos.append((os.path.relpath(p, PASTA), os.path.getsize(p)))
maior = max(arquivos, key=lambda x: x[1])
rel["medicoes"]["maior_arquivo"] = {"caminho": maior[0], "kB": round(maior[1] / 1e3, 1)}
rel["gates"]["s1_nenhum_arquivo_acima_60kB"] = maior[1] < 60_000
subs = {os.path.dirname(a) for a, _ in arquivos} - {"src"}
rel["gates"]["s1_monolitos_dissolvidos"] = all(
d in subs for d in ("src/jepa", "src/pensamento",
"src/moe_redirecionavel", "src/python"))
# testes herdados: 107 da v0.9.0 continuam verdes (123/123 total)
r = subprocess.run(["cargo", "test", "--all-features", "--quiet"],
capture_output=True, text=True, cwd=PASTA)
import re as _re
m = _re.findall(r"test result: ok\. (\d+) passed", r.stdout)
total = sum(int(x) for x in m)
rel["medicoes"]["cargo_total"] = total
rel["gates"]["s1_testes_herdados_preservados"] = (total >= 123 and r.returncode == 0)
rel["blocos"]["s1_divisao_srp"] = "3/3" if all(
rel["gates"][g] for g in list(rel["gates"]) if g.startswith("s1_")) else "?"
# ---- s2: checkpoints atômicos no treino real
import khtst_rust as k
cks_ok, cks = 0, {}
for nome in ("tokenizador_conceitos.json", "gerador_conceitos.json"):
p = os.path.join(R, nome)
okc = os.path.exists(p) and k.checkpoint_valido(p)
cks_ok += int(okc)
man = k.checkpoint_manifesto(p) if os.path.exists(p) else None
cks[nome] = {"valido": okc,
"manifesto_bytes": len(man) if man else 0}
rel["gates"]["s2_checkpoints_sha256_validos"] = (cks_ok == 2)
rel["medicoes"]["checkpoints"] = cks
rel["blocos"]["s2_checkpoint_atomico"] = f"{cks_ok}/2"
# ---- s3+s4: testes novos T-V3 e CK contabilizados no cargo (via 76)
tel = carrega("telemetria_v010.json")
if tel:
n_novos = tel["testes"]["cargo_total"] - tel["testes"]["herdados_v090"]
rel["gates"]["s3s4_testes_novos_16"] = (n_novos >= 16)
rel["medicoes"]["testes_novos_v010"] = n_novos
rel["blocos"]["s3s4_tipos_trait"] = "1/1" if rel["gates"].get("s3s4_testes_novos_16") else "0/1"
# ---- s5: treino real v0.10.0
treino = {}
for f, chave in (("fase_a_v010.json", "a"), ("fase_b_v010.json", "b")):
d = carrega(f)
if d:
treino[chave] = d["resumo"]
d = carrega("treino_v090.json")
c = (d or {}).get("fases", {}).get("c", {})
g5 = []
g5.append(("s5a_faseA_perda_cai", treino.get("a", {}).get("perda_final", 1e9)
< treino.get("a", {}).get("perda_inicial", -1e9)))
g5.append(("s5b_faseB_perda_cai", treino.get("b", {}).get("perda_final", 1e9)
< treino.get("b", {}).get("perda_inicial", -1e9)))
g5.append(("s5c_faseC_ce_cai", c.get("ce_final", 1e9) < c.get("ce_inicial", -1e9)))
delta_ort = treino.get("a", {}).get("delta_ort_max", 1.0)
g5.append(("s5d_ortogonalidade_exata", delta_ort < 1e-5))
for nome, val in g5:
rel["gates"][nome] = val
rel["medicoes"]["treino_real"] = {
"a": {"perda_inicial": treino.get("a", {}).get("perda_inicial"),
"perda_final": treino.get("a", {}).get("perda_final"),
"delta_ort_max": delta_ort},
"b": {"perda_inicial": treino.get("b", {}).get("perda_inicial"),
"perda_final": treino.get("b", {}).get("perda_final")},
"c": {"ce_inicial": c.get("ce_inicial"), "ce_final": c.get("ce_final"),
"taxa_gatilho": c.get("taxa_gatilho_media")},
}
rel["blocos"]["s5_treino_real"] = f"{sum(1 for _, v in g5 if v)}/{len(g5)}"
# ---- s6: CLI
cli = os.path.join(PASTA, "scripts", "75_cli.py")
r1 = subprocess.run([sys.executable, cli, "versao"], capture_output=True, text=True)
r2 = subprocess.run([sys.executable, cli, "estados"], capture_output=True, text=True)
r3 = subprocess.run([sys.executable, cli, "verificar-checkpoints"],
capture_output=True, text=True)
rel["gates"]["s6_cli_comandos"] = all(
r.returncode == 0 for r in (r1, r2, r3)) and "0.10.0" in r1.stdout
rel["medicoes"]["cli"] = {"versao": r1.stdout.strip().splitlines()[0],
"checkpoints_relacionados": len(r3.stdout.strip().splitlines())}
rel["blocos"]["s6_cli"] = "1/1" if rel["gates"]["s6_cli_comandos"] else "0/1"
# ---- veredito
gates = rel["gates"]
ok = sum(1 for v in gates.values() if v is True)
rel["veredito"] = f"{ok}/{len(gates)} — " + (
"APROVADO" if ok == len(gates) else "REPROVADO")
saida = os.path.join(R, "suite_v010_final.json")
json.dump(rel, open(saida, "w"), indent=1, ensure_ascii=False)
print(f"OK: {saida}")
print("blocos:", json.dumps(rel["blocos"], ensure_ascii=False))
print("VEREDITO:", rel["veredito"])
falhas = [k for k, v in gates.items() if v is not True]
if falhas:
print("falhas:", falhas)
if __name__ == "__main__":
main()
|