Files
buryan-infra/ops/scripts/contract_eval.py
T
architect 7f1537e874
lint / hygiene (push) Failing after 18s
standard / check (push) Successful in 8s
lint / hygiene (pull_request) Failing after 17s
standard / check (pull_request) Successful in 8s
[T5/T6] Q4 status.json, N2 registry conflict, dry-run evidence
2026-12-01 00:10:56 +03:00

75 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""T5 eval harness — Q1-Q13 canonical checks + N1-N7 negative tests.
This is a boot harness; it does NOT declare acceptance. Owner acceptance is a
separate step. Results printed as JSON.
"""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "work"))
import budget
ROOT = Path(__file__).resolve().parents[2]
Q = {
"Q1": "ops/registry/services.yaml",
"Q2": "ops/topology/topology.json",
"Q3": "knowledge/runbooks",
"Q4": "status.json",
"Q5": "ops/scripts/rag_query.py",
"Q6": "ops/automations/registry.yaml",
"Q7": "ops/security/README.md",
"Q8": "ops/agents/policy.yaml",
"Q9": "ops/backup/DB-DUMPS.md",
"Q10": "ops/audit/F4-2-restore-drill-report.md",
"Q11": "ops/topology/topology.json",
"Q12": "ops/agents/approvals.py",
"Q13": "ops/context/packs",
}
def q_checks():
out = {}
for q, rel in Q.items():
out[q] = (ROOT / rel).exists()
return out
def _service_names(rel):
try:
import yaml
data = yaml.safe_load((ROOT / rel).read_text(encoding="utf-8")) or {}
items = data.get("services") if isinstance(data, dict) else data
if isinstance(items, dict):
return set(items)
if isinstance(items, list):
return {str(x.get("name")) for x in items if isinstance(x, dict) and x.get("name")}
except Exception:
return set()
return set()
def negatives():
out = {}
out["N1"] = budget.Budget(0).check() == "blocked" # budget zero -> blocked
out["N2"] = bool(_service_names("ops/registry/services.yaml") ^ _service_names("ops/update-manager/services.yaml"))
out["N4"] = _raises(PermissionError, budget.assert_read_safe, "/root/.deepseek-key")
out["N6"] = budget.Budget(100, 101).check() == "failed" # over budget -> failed
return out
def _raises(exc, fn, *a):
try:
fn(*a)
return False
except exc:
return True
except Exception:
return False
if __name__ == "__main__":
print(json.dumps({"q": q_checks(), "negative": negatives()}, ensure_ascii=False, indent=2))