Files
troupe-standup/wizard-work/sol/verify_troupe_sol_health.py
T

93 lines
3.4 KiB
Python

#!/usr/bin/env python3
# Q63 (2026-10-24): no committed gate invokes this file -- `git grep -F -n verify_troupe_sol_health.py HEAD
# -- '*.py' '*.sh' CHECK` matches nothing outside this file -- so it is a one-off
# artifact, run by hand against its subject, not a standing check.
"""CHECK (verdict) for the committed sol-profile-health artifact.
Re-derives the profile classification straight from /root/.hermes/profiles and
compares it against the copied artifact in this directory. Exit 0 = artifact
matches reality; nonzero = artifact is wrong or missing.
Usage: python3 verify_troupe_sol_health.py
"""
import json
import os
import re
import sys
PROFILES = "/root/.hermes/profiles"
ARTIFACT = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"sol-profile-health-2026-10-24.json")
def recompute():
out = {}
for name in os.listdir(PROFILES):
p = os.path.join(PROFILES, name)
if not os.path.isdir(p):
continue
cfg = os.path.join(p, "config.yaml")
has_cfg = os.path.isfile(cfg)
model = ""
if has_cfg:
try:
t = open(cfg, encoding="utf-8", errors="replace").read()
m = re.search(r"model:\s*\n\s*default:\s*(.+)", t)
if not m:
m = re.search(r"default:\s*(.+)", t)
model = m.group(1).strip() if m else ""
except Exception:
model = ""
if not has_cfg:
out[name] = "PLACEHOLDER"
elif model == "":
out[name] = "STALE"
else:
out[name] = "ACTIVE"
return out
def main():
failures = []
if not os.path.exists(ARTIFACT):
print("FAIL: committed artifact missing: " + ARTIFACT)
sys.exit(1)
with open(ARTIFACT, encoding="utf-8") as fh:
art = json.load(fh)
recorded = {e["name"]: e.get("status") for e in art.get("entries", [])}
expected = recompute()
for name, st in expected.items():
if recorded.get(name) != st:
failures.append("name %r recorded=%r expected=%r" % (name, recorded.get(name), st))
for name in recorded:
if name not in expected:
failures.append("extra name in artifact: %r" % name)
counts = {}
for s in expected.values():
counts[s] = counts.get(s, 0) + 1
if art.get("total") != len(expected):
failures.append("total mismatch: %r != %d" % (art.get("total"), len(expected)))
if art.get("ACTIVE") != counts.get("ACTIVE", 0):
failures.append("ACTIVE mismatch: %r != %d" % (art.get("ACTIVE"), counts.get("ACTIVE", 0)))
if art.get("STALE") != counts.get("STALE", 0):
failures.append("STALE mismatch: %r != %d" % (art.get("STALE"), counts.get("STALE", 0)))
if art.get("PLACEHOLDER") != counts.get("PLACEHOLDER", 0):
failures.append("PLACEHOLDER mismatch: %r != %d" % (art.get("PLACEHOLDER"), counts.get("PLACEHOLDER", 0)))
if failures:
print("FAIL: committed artifact does not match filesystem reality")
for f in failures:
print(" - " + f)
sys.exit(1)
print("PASS: committed sol-profile-health artifact verified against live profiles")
print(" total=%d ACTIVE=%d STALE=%d PLACEHOLDER=%d" % (
len(expected), counts.get("ACTIVE", 0), counts.get("STALE", 0), counts.get("PLACEHOLDER", 0)))
sys.exit(0)
if __name__ == "__main__":
main()