fix(qa): make the quality harness work from a fresh clone
The harness resolved workflows and referenced skills only under
~/.hermes/skills/, so the commands documented in the README ("Quick
start") and in CONTRIBUTING ("Local checks before a PR") produced a
meaningless result on a fresh clone: every workflow scored 0, the gates
reported REPROVADO and the meta-tests failed.
- wf_quality_harness.py: resolve each workflow from the repo
(workflows/<name>.md) first, then from the installed skills dir; resolve
referenced skills from the vendored skills/ tree as well. Report the real
per-workflow cap instead of a fixed 100 (scores were shown as >100%).
- test_quality.py: G3 compared the current score against 2x its own final
value, so it could never pass and made the documented command exit 1.
Moved G3 into the --strict family alongside G2, and updated the stale
docstring (364.1 / 3 workflows -> 1613.2 / 4).
- test_tests.py: meta-test 3 pointed at a path that does not exist in the
repo, so it was skipped in silence (false green). It now resolves the
same path the harness uses and FAILS when the workflow is missing; also
guards the None harness result that previously crashed test 2.
Verified from the clone: harness exit 0, score 1613.2 (matches the
committed snapshot exactly on CPython 3.10 and 3.11); test_quality exit 0
(APROVADO G1,G4,G5); test_tests exit 0 with both mutations detected.
This commit is contained in:
1 parent
c17192c9fe
commit
eba8bb1d94
3 files changed
+123
-56
No files matched your search
+53
-22
@@ -3,22 +3,33 @@
|
||||
test_tests.py — 'teste dos testes' (meta-testes) do wf_quality_harness.
|
||||
|
||||
Prova que o harness REALMENTE mede qualidade:
|
||||
1. Baseline registrado em snapshots/baseline-364.json (score 364.1 total).
|
||||
2. Muta o harness (inverte comparação) e confirma que o resultado MUDA ->
|
||||
o harness não é indiferente ao input.
|
||||
3. Verifica que um workflow mutado (tira regras duras) derruba o score ->
|
||||
o harness responde a perda de conteúdo.
|
||||
1. Baseline registrado em snapshots/baseline-final.json (score 1613.2).
|
||||
2. Muta o harness (zera o anti_slop) e confirma que o score CAI -> o
|
||||
harness não é indiferente ao input.
|
||||
3. Muta um workflow (tira 'Regras duras') e confirma que o score CAI ->
|
||||
o harness responde a perda de conteúdo. Se o workflow não for
|
||||
encontrado, isso é FALHA, não skip: meta-teste que não roda é falso
|
||||
verde.
|
||||
4. Re-verifica o estado real: score atual >= baseline (não-regressão).
|
||||
|
||||
Exit 0 = testes dos testes OK e não-regressão verificada.
|
||||
Exit 1 = falhou (meta-teste ou regressão real).
|
||||
"""
|
||||
import json, os, shutil, subprocess, sys, tempfile
|
||||
import json, os, shutil, subprocess, sys, tempfile, importlib.util
|
||||
|
||||
WF_QA = os.path.dirname(os.path.abspath(__file__))
|
||||
HARNESS = os.path.join(WF_QA, "wf_quality_harness.py")
|
||||
SNAPSHOT = os.path.join(WF_QA, "snapshots", "baseline-final.json")
|
||||
|
||||
def load_harness():
|
||||
"""Importa o harness pra reusar a mesma resolução de caminho dos workflows."""
|
||||
spec = importlib.util.spec_from_file_location("wfq_harness", HARNESS)
|
||||
if spec is None or spec.loader is None:
|
||||
raise RuntimeError(f"não consegui carregar o harness em {HARNESS}")
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
def run_harness():
|
||||
r = subprocess.run([sys.executable, HARNESS, "--json"], capture_output=True, text=True)
|
||||
if r.returncode != 0:
|
||||
@@ -41,6 +52,13 @@ def main():
|
||||
if cur < baseline:
|
||||
fails.append(f"REGRESSÃO REAL: atual {cur:.1f} < baseline {baseline:.1f}")
|
||||
|
||||
# Sem harness não há o que comparar: os testes 2 e 3 dependem do score atual.
|
||||
if res is None:
|
||||
print("\nFALHAS META-TESTE:")
|
||||
for f in fails:
|
||||
print(" -", f)
|
||||
sys.exit(1)
|
||||
|
||||
# --- Teste 2: mutação do harness muda o resultado (sensibilidade) ---
|
||||
tmp = tempfile.mkdtemp(prefix="wfqamut_")
|
||||
try:
|
||||
@@ -66,23 +84,36 @@ def main():
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
|
||||
# --- Teste 3: workflow mutado (remove Regras duras) derruba score ---
|
||||
wk = os.path.join(os.path.dirname(WF_QA), "wf-frontend", "SKILL.md")
|
||||
if os.path.exists(wk):
|
||||
# Resolve o mesmo caminho que o harness usa (clone do repo ou instalado).
|
||||
# Um meta-teste que não roda é falso verde: se o arquivo não for achado,
|
||||
# isso é FALHA, não skip.
|
||||
try:
|
||||
h = load_harness()
|
||||
wk = h.resolve_workflow("wf-frontend", h.WORKFLOWS["wf-frontend"])
|
||||
except Exception as e:
|
||||
h, wk = None, None
|
||||
fails.append(f"não consegui resolver o workflow wf-frontend: {e}")
|
||||
if h is not None and wk is None:
|
||||
fails.append("workflow wf-frontend não encontrado (nem workflows/wf-frontend.md no repo nem instalado) — meta-teste 3 não pôde rodar")
|
||||
if wk is not None:
|
||||
orig = open(wk, encoding="utf-8").read()
|
||||
ctx = tempfile.mkdtemp(prefix="wfqamutwf_")
|
||||
backup = os.path.join(ctx, "backup.md")
|
||||
shutil.copy(wk, backup)
|
||||
try:
|
||||
removed = orig.replace("## Regras duras", "## Regras_duras_mutadas")
|
||||
open(wk, "w", encoding="utf-8").write(removed)
|
||||
r2, _ = run_harness()
|
||||
if r2 is None or r2["total"] >= res["total"]:
|
||||
fails.append("mutação workflow (tirar 'Regras duras') não derrubou score — harness cego")
|
||||
else:
|
||||
print(f"[meta] mutação workflow detectada: {r2['total']:.1f} < {res['total']:.1f} OK")
|
||||
finally:
|
||||
shutil.copy(backup, wk)
|
||||
shutil.rmtree(ctx, ignore_errors=True)
|
||||
if "## Regras duras" not in orig:
|
||||
fails.append(f"'{wk}' não tem '## Regras duras' — meta-teste 3 não consegue mutar")
|
||||
else:
|
||||
ctx = tempfile.mkdtemp(prefix="wfqamutwf_")
|
||||
backup = os.path.join(ctx, "backup.md")
|
||||
shutil.copy(wk, backup)
|
||||
try:
|
||||
removed = orig.replace("## Regras duras", "## Regras_duras_mutadas")
|
||||
open(wk, "w", encoding="utf-8").write(removed)
|
||||
r2, _ = run_harness()
|
||||
if r2 is None or r2["total"] >= res["total"]:
|
||||
fails.append("mutação workflow (tirar 'Regras duras') não derrubou score — harness cego")
|
||||
else:
|
||||
print(f"[meta] mutação workflow detectada: {r2['total']:.1f} < {res['total']:.1f} OK")
|
||||
finally:
|
||||
shutil.copy(backup, wk)
|
||||
shutil.rmtree(ctx, ignore_errors=True)
|
||||
|
||||
print()
|
||||
if fails:
|
||||
|
||||
Reference in new issue
Block a user