96 lines
3.2 KiB
Python
96 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""CHECK for sol-profile-health artifact.
|
|
|
|
Re-derives the profile classification straight from the filesystem and
|
|
compares it against the recorded values in the artifact. Exit 0 = artifact
|
|
matches reality; nonzero = artifact is wrong or missing.
|
|
|
|
Usage: python3 check_sol_profile_health.py (exit code is the verdict)
|
|
"""
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
PROFILES = "/root/.hermes/profiles"
|
|
ARTIFACT = "/root/.hermes/wizard-outputs/sol/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: artifact missing: " + ARTIFACT)
|
|
sys.exit(1)
|
|
|
|
with open(ARTIFACT, encoding="utf-8") as fh:
|
|
art = json.load(fh)
|
|
|
|
recorded = {}
|
|
for e in art.get("entries", []):
|
|
recorded[e["name"]] = e.get("status")
|
|
|
|
expected = recompute()
|
|
|
|
# Every name must be present on both sides with identical status.
|
|
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)
|
|
|
|
# Summary cross-check.
|
|
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 count mismatch: %r != %d" % (art.get("ACTIVE"), counts.get("ACTIVE", 0)))
|
|
if art.get("STALE") != counts.get("STALE", 0):
|
|
failures.append("STALE count mismatch: %r != %d" % (art.get("STALE"), counts.get("STALE", 0)))
|
|
if art.get("PLACEHOLDER") != counts.get("PLACEHOLDER", 0):
|
|
failures.append("PLACEHOLDER count mismatch: %r != %d" % (art.get("PLACEHOLDER"), counts.get("PLACEHOLDER", 0)))
|
|
|
|
if failures:
|
|
print("FAIL: artifact does not match filesystem reality")
|
|
for f in failures:
|
|
print(" - " + f)
|
|
sys.exit(1)
|
|
|
|
print("PASS: sol-profile-health artifact verified against filesystem")
|
|
print(" total=%d ACTIVE=%d STALE=%d PLACEHOLDER=%d" % (
|
|
len(expected), counts.get("ACTIVE", 0), counts.get("STALE", 0), counts.get("PLACEHOLDER", 0)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|