Files
weval-l99/v140b_nr_live.py
2026-04-24 04:38:58 +02:00

57 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""V140b - Fetch NR from live /api/l99-honest.php instead of stale truth-registry snapshot"""
import sys
src, dst = sys.argv[1], sys.argv[2]
with open(src, "r", encoding="utf-8") as f:
c = f.read()
if "V140B-NR-LIVE" in c:
print("ALREADY", file=sys.stderr)
sys.exit(0)
# Find the NR block in __v139LoadTruthStrip and replace with live fetch
old = """ const nrEl = document.getElementById('v140-nonreg');
if (nrEl && d.nonreg) {
const s = d.nonreg.score;
const t = d.nonreg.total;
const pct = t ? Math.round((s/t)*100) : 0;
const badgeColor = pct >= 99 ? '#10b981' : pct >= 95 ? '#f59e0b' : '#ef4444';
nrEl.innerHTML = '&middot; NR <strong style="color:' + badgeColor + '">' + s + '/' + t + '</strong>';
nrEl.title = 'Non-régression score: ' + s + '/' + t + ' (' + pct + '%)';
}"""
new = """ // V140B-NR-LIVE: fetch fresh NR from l99-honest.php (truth-registry may be stale snapshot)
try {
const nrResp = await fetch('/api/l99-honest.php', {cache: 'no-store'});
if (nrResp.ok) {
const nrData = await nrResp.json();
const nrEl = document.getElementById('v140-nonreg');
if (nrEl && nrData.combined) {
const s = nrData.combined.pass;
const t = nrData.combined.total;
const pct = t ? Math.round((s/t)*100) : 0;
const badgeColor = pct >= 99 ? '#10b981' : pct >= 95 ? '#f59e0b' : '#ef4444';
nrEl.innerHTML = '&middot; NR <strong style="color:' + badgeColor + '">' + s + '/' + t + '</strong>';
nrEl.title = 'Non-régression live: ' + s + '/' + t + ' (' + pct + '%) · source: /api/l99-honest.php · ts: ' + (nrData.ts || 'n/a');
}
}
} catch(_) {
// fallback: use snapshot from truth-registry
const nrEl = document.getElementById('v140-nonreg');
if (nrEl && d.nonreg) {
const s = d.nonreg.score, t = d.nonreg.total, pct = t ? Math.round((s/t)*100) : 0;
const badgeColor = pct >= 99 ? '#10b981' : pct >= 95 ? '#f59e0b' : '#ef4444';
nrEl.innerHTML = '&middot; NR <strong style="color:' + badgeColor + '">' + s + '/' + t + '</strong> <span style="color:var(--mu);font-size:8px">(snapshot)</span>';
nrEl.title = 'NR (snapshot truth-registry, peut être stale): ' + s + '/' + t + ' (' + pct + '%)';
}
}"""
if old not in c:
print("anchor missing", file=sys.stderr)
sys.exit(1)
c = c.replace(old, new, 1)
with open(dst, "w", encoding="utf-8") as f:
f.write(c)
print(f"OK size={len(c)}", file=sys.stderr)