88 lines
2.5 KiB
Python
88 lines
2.5 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["N5"] = _no_write_without_approval()
|
|
out["N6"] = budget.Budget(100, 101).check() == "failed" # over budget -> failed
|
|
return out
|
|
|
|
|
|
def _no_write_without_approval():
|
|
try:
|
|
import importlib.util
|
|
p = ROOT / "ops/agents/approvals.py"
|
|
spec = importlib.util.spec_from_file_location("buryans_approvals", p)
|
|
mod = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(mod)
|
|
return "write" not in mod.ALLOWED
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
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))
|