# -*- coding: utf-8 -*-
"""Recomputes every counted number in article.md from the data files and checks that the exact string is in the text.
Usage: python verify_numbers.py     (exit code 1 if anything is missing or different)
"""
import json, collections, statistics as st, datetime as dt, sys, re
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
J = lambda n: json.loads((ROOT / 'data' / n).read_text(encoding='utf-8'))
snap, lag, fc, cna, cv = J('nvd_kev_snapshot.json'), J('kev_lag.json'), J('forecast.json'), J('cna_counts.json'), J('cvss_cohorts.json')
ex, ais = J('extra_stats.json'), J('kev_ai_stack.json')
POST = (ROOT / 'linkedin-post.md').read_text(encoding='utf-8') if (ROOT / 'linkedin-post.md').exists() else None     # optional
ART = (ROOT / 'article.md').read_text(encoding='utf-8')
NM, NQ, rows = snap['nvd_monthly'], snap['nvd_quarterly'], lag['rows']
KM = collections.Counter(r['kevAdded'][:7] for r in rows)
n = lambda v, d=0: f'{v:,.{d}f}'
checks = []
def chk(label, value, *needles):
    for s in needles: checks.append((label, value, s, s in ART))
def msum(d, a, b): return sum(v for k, v in d.items() if a <= k <= b)
def kq(y, q): return sum(KM[f'{y}-{m:02d}'] for m in range(3 * q - 2, 3 * q + 1))

# ---- NVD
q325, q326 = NQ['2025Q3'], NQ['2026Q3']
chk('NVD Q3', (q325, q326), f'{n(q325)} → {n(q326)} (×{q326 / q325:.2f})', '36,952 CVE records, 3.15 times', f'its additions increased by {100 * (326 / 225 - 1):.0f}% while CVE records increased by {100 * (107068 / 42659 - 1):.0f}%')
jn25, jn26, cy25 = msum(NM, '2025-01', '2025-11'), msum(NM, '2026-01', '2026-11'), msum(NM, '2025-01', '2025-12')
chk('NVD Jan-Nov', (jn25, jn26), f'{n(jn25)} → {n(jn26)} (×{jn26 / jn25:.2f})', f'{n(jn26)} records, {jn26 / cy25:.1f} times the whole of 2025 ({n(cy25)})')
for m, s in (('2026-07', '9,771 in July'), ('2026-08', '12,255 in August'), ('2026-09', '14,926 in September'), ('2026-10', '17,050 in October'), ('2026-11', '17,226 in November')):
    chk('NVD ' + m, NM[m], s); assert n(NM[m]) in s
chk('2025 monthly avg', cy25 / 12, f'({n(cy25 / 12)})'); chk('largest 2025 quarter', NQ['2025Q4'], f'had {n(NQ["2025Q4"])})')
assert all(NM[m] > NQ[f'2025Q{q}'] for m in ('2026-09', '2026-10', '2026-11') for q in (1, 2, 3, 4))
ms = sorted(NM); mm = {k: 100 * (NM[k] / NM[p] - 1) for p, k in zip(ms, ms[1:])}
chk('m/m growth', {k: round(mm[k], 1) for k in ms[-5:]}, f'{mm["2026-07"]:.0f}% in July, {mm["2026-08"]:.0f}% in August and {mm["2026-09"]:.0f}% in September', f'{mm["2026-10"]:.0f}% in October and {mm["2026-11"]:.0f}% in November')
chk('per-day Nov vs Oct', round(100 * ((NM['2026-11'] / 30) / (NM['2026-10'] / 31) - 1), 1), 'November was 4% above October')
assert all(NM[f'2026-{m:02d}'] > NM[f'2026-{m - 1:02d}'] for m in range(5, 12))
to_sep15 = msum(NM, '2026-01', '2026-08') + snap['nvd_2026_to_sep15']; chk('cumulative to 15 Sep', to_sep15, 'passed 66,000 in mid-September'); assert 65000 < to_sep15 < 66000 < msum(NM, '2026-01', '2026-09')
assert msum(NM, '2026-01', '2026-10') < 100000 < jn26
for y, (a, b, c) in {2026: (15152, 20688, 36952)}.items(): chk('NVD 2026 quarters', (NQ['2026Q1'], NQ['2026Q2'], NQ['2026Q3']), f'NVD gives {n(NQ["2026Q1"])}, {n(NQ["2026Q2"])} and {n(NQ["2026Q3"])}')
chk('QoQ Q3', round(100 * (36962 / 20696 - 1), 1), '78.6% above Q2')

# ---- CNA table (noRejected)
Q = cna['kwartaly']
def by(q):
    r = collections.Counter()
    for x in Q[q].values(): r[x['sourceName']] += x['noRejected']
    return r
a, b, q4, q1, q2 = by('2025Q3'), by('2026Q3'), by('2025Q4'), by('2026Q1'), by('2026Q2')
six = [('GitHub', 'GitHub, Inc.'), ('Linux kernel (kernel.org)', 'kernel.org'), ('VulnCheck', 'VulnCheck'), ('Oracle', 'Oracle'), ('Microsoft', 'Microsoft Corporation'), ('Chrome', 'Chrome')]
tot = sum(b.values()) - sum(a.values()); s6a = s6b = 0
for lab, k in six:
    chk('CNA ' + lab, (a[k], b[k]), f'| {lab} | {n(a[k])} | {n(b[k])} | +{n(b[k] - a[k])} | {100 * (b[k] - a[k]) / tot:.1f}% |'); s6a += a[k]; s6b += b[k]
chk('six together', (s6a, s6b), f'| **{n(s6a)}** | **{n(s6b)}** | **+{n(s6b - s6a)}** | **{100 * (s6b - s6a) / tot:.1f}%** |')
active = sum(1 for v in b.values() if v > 0)
chk('active sources', active, f'{active} such sources', f'All other sources | {n(sum(a.values()) - s6a)} | {n(sum(b.values()) - s6b)} | +{n(tot - (s6b - s6a))} | {100 * (tot - (s6b - s6a)) / tot:.1f}% |')
chk('wave 1', (q4['GitHub, Inc.'], q1['GitHub, Inc.'], q4['VulnCheck'], q1['VulnCheck']), f'from {n(q4["GitHub, Inc."])} records to {n(q1["GitHub, Inc."])}', f'from {n(q4["VulnCheck"])} to {n(q1["VulnCheck"])}')
chk('wave 2', 0, f'Chrome went from {n(q1["Chrome"])} records to {n(q2["Chrome"])} in Q2', f'Oracle ({n(q2["Oracle"])} → {n(b["Oracle"])})', f'Microsoft ({n(q2["Microsoft Corporation"])} → {n(b["Microsoft Corporation"])})', f'from {n(q2["kernel.org"])} to {n(b["kernel.org"])}')
chk('Mozilla', 0, f'{q4["Mozilla Corporation"]} records in Q4 2025, {q1["Mozilla Corporation"]} in Q1 2026 and {b["Mozilla Corporation"]} in Q3 2026')
anth = [k for k in b if 'nthropic' in k]; chk('Anthropic CNA Q3', sum(b[k] for k in anth), "Anthropic's CNA published three records in Q3 and OpenAI's none"); assert sum(b[k] for k in anth) == 3 and not any('OpenAI' in k and v > 0 for k, v in b.items())
wp = cv['wordpress']; chk('WordPress', wp, f'{n(wp["2025Q3"]["rekordy"])} records in Q3 2025 ({wp["2025Q3"]["udzial_procent"]:.1f}% of the quarter) and {n(wp["2026Q3"]["rekordy"])} a year later ({wp["2026Q3"]["udzial_procent"]:.1f}%)', f'{100 * (wp["2026Q3"]["rekordy"] - wp["2025Q3"]["rekordy"]) / tot:.1f}% of the total growth')

# ---- KEV
chk('KEV catalog', (lag['catalogVersion'], lag['count']), f'catalog version {lag["catalogVersion"]}, {n(lag["count"])} entries')
chk('KEV Q3', (kq(2025, 3), kq(2026, 3)), f'{kq(2025, 3)} → {kq(2026, 3)} (×{kq(2026, 3) / kq(2025, 3):.2f})')
k25, k26 = msum(KM, '2025-01', '2025-11'), msum(KM, '2026-01', '2026-11')
chk('KEV Jan-Nov', (k25, k26), f'{k25} → {k26} (×{k26 / k25:.2f})', f'{k26} additions against {k25} (×{k26 / k25:.2f})')
pass  # the ratio of the two headline flows was removed from the article
chk('KEV autumn', [KM[m] for m in ('2026-09', '2026-10', '2026-11')], '43, 36 and 44 additions', f'({n(msum(KM, "2025-01", "2025-12") / 12, 1)})')
assert kq(2025, 3) == min(kq(y, q) for y, q in ((2025, 1), (2025, 2), (2025, 3), (2025, 4), (2026, 1), (2026, 2), (2026, 3)))
ends = {'2025Q1': '2025-05-31', '2025Q2': '2025-08-31', '2025Q3': '2025-11-30', '2026Q1': '2026-05-31', '2026Q2': '2026-08-31', '2026Q3': '2026-11-30'}
coh = {k: sum(1 for x in v if x['kevAdded'] and x['kevAdded'] <= ends[k]) for k, v in snap['kev_cohorts'].items()}
now = {k: len(v) for k, v in snap['kev_cohorts'].items()}
assert all(coh[k] == cv['kohorty'][k]['w_kev_w_oknie'] for k in coh), 'cohorts differ between the two routes'
c25, c26 = sum(coh[f'2025Q{i}'] for i in (1, 2, 3)), sum(coh[f'2026Q{i}'] for i in (1, 2, 3)); v25, v26 = sum(NQ[f'2025Q{i}'] for i in (1, 2, 3)), sum(NQ[f'2026Q{i}'] for i in (1, 2, 3))
chk('cohorts', (c25, c26), f'{c25} of {n(v25)} ({1000 * c25 / v25:.1f} per 1,000)', f'{c26} of {n(v26)} ({1000 * c26 / v26:.1f} per 1,000)', f'Cohorts grew {100 * (c26 / c25 - 1):.0f}% while CVEs grew {100 * (v26 / v25 - 1):.0f}%')
gains = sorted(round(100 * (now[k] / coh[k] - 1)) for k in ('2025Q1', '2025Q2', '2025Q3')); chk('cohort later gains', gains, f'gained {gains[0]}% to {gains[-1]}%')
chk('CISA H1 2026', kq(2026, 1) + kq(2026, 2), f"against CISA's {kq(2026, 1) + kq(2026, 2)}")
kern = [r for r in rows if r['product'] == 'Kernel' and '2026-01-01' <= r['kevAdded'] <= '2026-11-30']
chk('kernel in KEV', (len(kern), sum(1 for r in kern if r['cve'].startswith('CVE-2026'))), 'added nine kernel vulnerabilities', 'four of them with 2026 identifiers'); assert (len(kern), sum(1 for r in kern if r['cve'].startswith('CVE-2026'))) == (9, 4)
AI = {'Langflow': 5, 'LiteLLM': 4, 'Ray': 1, 'MLflow': 1, 'GPUStack': 1, 'MONAI Label': 1}
ai = lambda a, b: [r for r in rows if r['product'] in AI and a <= r['kevAdded'] <= b]
ai26 = ai('2026-01-01', '2026-11-30'); assert collections.Counter(r['product'] for r in ai26) == AI
chk('AI stack in KEV', (len(ai('2024-01-01', '2024-12-31')), len(ai('2025-01-01', '2025-12-31')), len(ai26)),
    f'| 2024 | {len(ai("2024-01-01", "2024-12-31"))} | {msum(KM, "2024-01", "2024-12")} |', f'| 2025 | {len(ai("2025-01-01", "2025-12-31"))} | {msum(KM, "2025-01", "2025-12")} |', f'| January–November 2026 | {len(ai26)} | {k26} |', 'That is 4% of')
assert round(100 * len(ai26) / k26) == 4 and len(ai26) + sum(1 for r in rows if r['product'] in ('n8n', 'Marimo') and '2026-01-01' <= r['kevAdded'] <= '2026-11-30') == 15
chk('entries since Jan 2024', ais['entries_since_2024'], f'the {ais["entries_since_2024"]} entries added since January 2024')
assert ais['strict'] == 14 and ais['adjacent'] == 2 and ais['entries_since_2024'] == sum(1 for r in rows if r['kevAdded'] >= '2024-01-01')
for y in (2023, 2024, 2025, 2026):
    L = sorted(r['lagDays'] for r in rows if f'{y}-01-01' <= r['kevAdded'] <= f'{y}-11-30' and r['cvePublished'] >= f'{y - 1}-01-01'); m = len(L); sh = lambda d: 100 * sum(1 for x in L if x <= d) / m
    chk(f'lag {y}', (m, st.median(L)), f'| {y} | {m} | {st.median(L):g} ({ex["lag_fresh_by_year"][str(y)]["ci95"][0]:g}–{ex["lag_fresh_by_year"][str(y)]["ci95"][1]:g}) | {sh(0):.1f}% | {sh(7):.1f}% | {sh(30):.1f}% |')
L26 = [r['lagDays'] for r in rows if '2026-01-01' <= r['kevAdded'] <= '2026-11-30']; chk('lag 2026 all entries', (len(L26), st.median(L26)), "With all 326 of this year's CISA entries included, old CVEs too, the median is 11 days"); assert (len(L26), st.median(L26)) == (326, 11)
L22 = [r['lagDays'] for r in rows if '2022-01-01' <= r['kevAdded'] <= '2022-11-30' and r['cvePublished'] >= '2021-01-01']; chk('lag 2022', st.median(L22), 'its median was 46 days'); assert st.median(L22) == 46
dd = lambda a, b: collections.Counter((dt.date.fromisoformat(r['kevDue']) - dt.date.fromisoformat(r['kevAdded'])).days for r in rows if a <= r['kevAdded'] <= b)
d25, d15, dq3, don = dd('2025-01-01', '2025-12-31'), dd('2026-01-01', '2026-05-31'), dd('2026-07-01', '2026-09-30'), dd('2026-10-01', '2026-11-30')
dj = dd('2026-06-01', '2026-06-30'); d45 = dd('2026-04-01', '2026-05-31'); assert d45[21] == 0
due_days = lambda r: (dt.date.fromisoformat(r['kevDue']) - dt.date.fromisoformat(r['kevAdded'])).days
first3 = min(r['kevAdded'] for r in rows if r['kevAdded'] >= '2026-01-01' and due_days(r) == 3); first14 = min(r['kevAdded'] for r in rows if r['kevAdded'] >= '2026-01-01' and due_days(r) == 14)
assert (first3, first14) == ('2026-01-27', '2026-03-09')
chk('due date chronology', (first3, first14), 'dated 27 January 2026 and the first 14-day one 9 March', f'In June, {dj[3]} of {sum(dj.values())} had 3 days and {dj[14]} had 14')
chk('due dates', 0, f'{d25[21]} of {sum(d25.values())} entries had 21 days', f'Of the {sum(d15.values())} entries from January to May 2026, {d15[14]} had 14 days, {d15[21]} had 21 and {d15[3]} had 3', f'{dq3[3]} of {sum(dq3.values())} had 3 days and {dq3[14]} had 14', f'{don[3]} of {sum(don.values())} had 3 days')
opt = [r for r in rows if r['vendor'] == 'Optimizely'][0]; chk('Optimizely KEV', (opt['cve'], opt['kevAdded'], opt['kevDue']), 'CVE-2026-132224, entered KEV on 24 November with a due date of 27 November'); assert (opt['cve'], opt['kevAdded'], opt['kevDue']) == ('CVE-2026-132224', '2026-11-24', '2026-11-27')

# ---- CVSS
A = cv['reguly']['A_artykul_nvd_potem_inne']['2026Q3']; six_q = cv['szesc_kwartalow']
chk('CVSS Q3 2026', A, f'{n(A["wysokie_i_krytyczne"])} of {n(A["cve"])} new CVEs, or {A["udzial_procent"]}%', '70 of the 20,583 high- or critical-scored Q3 records were in KEV, or 0.34%, against a base rate of 0.21%'); assert A['kev_wysokie_i_krytyczne'] == 70 and A['kev_procent_wysokich_i_krytycznych'] == 0.34
chk('CVSS signal', six_q, f'({six_q["kev_procent_wsrod_nich"]:.2f}% against {six_q["kev_procent_wsrod_pozostalych"]:.2f}%)', f'{six_q["kev_ponizej_wysokiej"]} of the 299 were rated below high')
cf = ex['cvss_filter']; assert cf['q3_2026']['base_rate_pct'] == 0.21
chk('CVSS recall', cf, f'{cf["six_quarters"]["kev_high_critical"]} of the 299 vulnerabilities that reached KEV were rated high or critical: {cf["six_quarters"]["recall_pct"]:.0f}%')
shares = [cv['reguly'][r]['2026Q3']['udzial_procent'] for r in cv['reguly']]; miss = [sum(sum(cv['reguly'][r][q]['kev_ponizej_wysokiej'].values()) for q in cv['reguly'][r]) for r in cv['reguly']]
chk('CVSS rules', (shares, miss), f'between {min(shares)}% and {max(shares)}%', f'between {min(miss)} and {max(miss)} of 299'); assert sum(cv['reguly']['A_artykul_nvd_potem_inne'][q]['kev_w_oknie'] for q in coh) == 299
pc = cv['pokrycie_ocen']; chk('NVD own score coverage', (pc['2026Q3']['procent_rekordow_z_ocena_NVD'], pc['2025Q3']['procent_rekordow_z_ocena_NVD']), 'on 9% of Q3 2026 records, against 37% a year earlier'); chk('kernel unscored', A['bez_oceny'], '1,930 records, all from kernel.org')

# ---- forecast (pooled weight sets) and robustness numbers
c, ce, pz, b = fc['results']['pooled'], fc['results']['central'], fc['results']['pessimist'], fc['baselines']
chk('FY26 baselines', b, f'| {n(b["fy26_nvd"])} | my weights, simulated |', f'| {b["fy26_kev"]} | my weights, simulated |')
cov1 = [fc['results'][k]['calls']['nvd_fy27_in_140k_325k'] for k in ('central', 'pessimist', 'optimist')]
cov2 = [fc['results'][k]['calls']['kev_fy27_in_260_700'] for k in ('central', 'pessimist', 'optimist')]
assert min(cov1) >= 0.90 and min(cov2) >= 0.90, (cov1, cov2)
chk('interval coverage', (cov1, cov2), f'({100 * min(cov1):.0f}% to {100 * max(cov1):.0f}% for call 1, {100 * min(cov2):.0f}% to {100 * max(cov2):.0f}% for call 2)')
chk('narrow interval', (ce['calls']['nvd_fy27_in_155k_325k'], pz['calls']['nvd_fy27_in_155k_325k']),
    f'is {100 * ce["calls"]["nvd_fy27_in_155k_325k"]:.0f}% on my central weights and {100 * pz["calls"]["nvd_fy27_in_155k_325k"]:.0f}% on the pessimistic ones')
chk('80% ranges', (c['nvd_fy27']['p10'], c['nvd_fy27']['p90']), f'{n(round(c["nvd_fy27"]["p10"], -3))} to {n(round(c["nvd_fy27"]["p90"], -3))} CVE records and {c["kev_fy27"]["p10"]} to {c["kev_fy27"]["p90"]} KEV additions')
chk('medians', (c['nvd_fy27']['p50'], c['kev_fy27']['p50']), f'The median for CVE records is {n(round(c["nvd_fy27"]["p50"], -3))} and for KEV additions {c["kev_fy27"]["p50"]}')
chk('less sure', c['calls'], f'({n(3 * cy25)}): {100 * c["calls"]["nvd_fy27_at_least_3x_cy2025"]:.0f}%', f"346: {100 * c['calls']['kev_fy27_more_than_fy26']:.0f}%",
    f'(15,000–20,000): {100 * c["calls"]["nvd_autumn27_15k_to_20k"]:.0f}%. Above 22,000: {100 * c["calls"]["nvd_autumn27_above_22k"]:.0f}%')
m = fc['model']
assert m['weights']['central'] == [.10, .13, .40, .12, .25] and abs(sum(m['weights']['pessimist'][:2]) - .40) < 1e-9 and m['kev_end_level']['median'] == 34.0
chk('KEV constants', m['kev_end_level'], 'a median of 34 additions a month', f'the twelve-month mean of {b["fy26_kev"] / 12:.1f}', "the last three months' 41")
sp = ex['spikes']; under = sorted((x[1] for x in sp['four_largest_spikes'] if x[1] < 1), reverse=True)
assert len(under) == 3 and sp['independent_years_2017_2025'] == 9
chk('spikes', sp, f'(at {under[0]}, {under[1]} and {under[2]} of it)', f'was {sp["largest_spike_before_2026"]} times the level before it', f'Q3 2026 was {sp["current_spike_2026Q3"]} times')
ac = ex['ai_stack_call']; assert 0.89 <= ac['P(X>=4) mean13 shape3'] <= 0.93 and 0.68 <= ac['P(X>=8) mean13 shape3'] <= 0.74
bl = (b['fy26_nvd'] * 140000 / c['nvd_fy27']['p50'], b['fy26_nvd'] * 325000 / c['nvd_fy27']['p50'], b['fy26_kev'] * 260 / c['kev_fy27']['p50'], b['fy26_kev'] * 700 / c['kev_fy27']['p50'])
chk('naive baseline', bl, f'({n(round(bl[0], -3))} to {n(round(bl[1], -4))} CVE records, {bl[2]:.0f} to {bl[3]:.0f} KEV additions)')
scored = A['cve'] - A['bez_oceny']; chk('CVSS scored-only share', scored, f'Among the {n(scored)} records that had a CVSS 3 or 4 score at all, it is {100 * A["wysokie_i_krytyczne"] / scored:.1f}%')
bh = collections.Counter(); [bh.update(cv['reguly']['A_artykul_nvd_potem_inne'][q]['kev_ponizej_wysokiej']) for q in cv['reguly']['A_artykul_nvd_potem_inne']]
assert dict(bh) == {'MEDIUM': 34, 'LOW': 1}; chk('below high breakdown', dict(bh), '(34 medium, one low, none of them unscored)')
W = m['weights']; assert W['pessimist'] == [.20, .20, .35, .10, .15] and W['optimist'] == [.05, .08, .32, .15, .40] and m['n'] == 200000 and m['nvd_monthly_noise_sigma'] == 0.12 and m['kev_end_level']['sigma_log'] == 0.45 and m['kev_start_level'] == 35.0
chk('forecast parameters', W, 'central 10/13/40/12/25, pessimistic 20/20/35/10/15, optimistic 5/8/32/15/40', 'it gives 87% in place of 92%'); assert abs(ac['P(X>=4) mean13 shape3'] - 0.916) < 0.002 and abs(ac['P(X>=4) mean13 shape2'] - 0.865) < 0.002      # 92% and 87% (0.8651)
chk('reservations', NM['2026-10'] + NM['2026-11'], f'October and November together published {n(NM["2026-10"] + NM["2026-11"])}')
assert abs((1 - 0.9 ** 4 - 4 * 0.1 * 0.9 ** 3) - 0.05) < 0.005        # two or more misses out of four honest 90% calls: about 1 in 20
fwc = ex['fixed_window_cohorts']; a30, b30 = fwc['jan_sep_within_30']; r9, r3 = fwc['jan_sep_within_30_ratio_ci95'], fwc['q3_within_30_ratio_ci95']
chk('30-day cohorts', fwc, f'{a30} listings in 2025 and {b30} in 2026: ×{r9[0]}, with a 95% interval of {r9[1]} to {r9[2]}, against ×{fwc["jan_sep_cve_ratio"]} for CVE records',
    f'it is {fwc["by_quarter"]["2025Q3"]["within_30"]} and {fwc["by_quarter"]["2026Q3"]["within_30"]}: ×{r3[0]}, with an interval of {r3[1]:.1f} to {r3[2]:.1f}')
assert r3[1] < fwc['q3_cve_ratio'] < r3[2] and r9[2] < fwc['jan_sep_cve_ratio']
import math as _m
def _rr(x, nx, y, ny):
    r = (y / ny) / (x / nx); se = _m.sqrt(1 / x + 1 / y); return r, r * _m.exp(-1.96 * se), r * _m.exp(1.96 * se)
bq = fwc['by_quarter']; r9 = _rr(a30, sum(bq[f'2025Q{i}']['cve'] for i in (1, 2, 3)), b30, sum(bq[f'2026Q{i}']['cve'] for i in (1, 2, 3))); r3q = _rr(bq['2025Q3']['within_30'], bq['2025Q3']['cve'], bq['2026Q3']['within_30'], bq['2026Q3']['cve'])
chk('rate ratios', (r9, r3q), f'{r9[0]:.2f} times as likely to be listed within 30 days as a year earlier over January to September (interval {r9[1]:.2f} to {r9[2]:.2f}), and {r3q[0]:.2f} times in Q3 alone ({r3q[1]:.2f} to {r3q[2]:.2f})')
t12 = [r['lagDays'] for r in rows if '2025-12-01' <= r['kevAdded'] <= '2026-11-30' and r['cvePublished'] >= '2025-01-01']; assert st.median(t12) == 6
assert sum(1 for r in ais['rows'] if r['aiStack'] == 'strict' and '2025-12-01' <= r['kevAdded'] <= '2026-11-30') == 13     # trailing-12-month baselines of calls 3 and 4
ly = ex['lag_fresh_by_year']
for y in ('2023', '2024', '2025', '2026'):
    chk('lag interval ' + y, ly[y], f'| {y} | {ly[y]["n"]} | {ly[y]["median"]:g} ({ly[y]["ci95"][0]:g}–{ly[y]["ci95"][1]:g}) |')
al, dz = ex['all_2026_additions'], ex['day_zero_2026']; tv = dict(dz['top_vendors'])
chk('all 2026 additions', al, f'the median is 11 days, {al["over_30_days_pct"]:.0f}% were listed more than 30 days after the CVE and {al["over_365_days_pct"]:.0f}% more than a year after')
chk('day zero', dz, f'Of the {dz["n"]} fresh entries listed on or before CVE day in 2026, {dz["same_day"]} were listed on the day itself and {tv["Microsoft"] + tv["Cisco"]} belong to Microsoft or Cisco')
kp = ex['kev_pace']; assert round((kp['jan_may_2026_mean'] * 5 + kp['jun_aug_2026_mean'] * 3) / 8) == 25 and kp['sep_nov_2026'] / 3 == 41
chk('KEV pace', kp, 'from about 25 additions a month (January to August) to 41 (September to November)')
vc_q = lambda q: sum(x['noRejected'] for x in Q[q].values() if x['sourceName'] == 'VulnCheck')
chk('VulnCheck Q3', (vc_q('2026Q2'), vc_q('2026Q3')), f'({n(vc_q("2026Q2"))} → {n(vc_q("2026Q3"))})')
ai2 = collections.Counter(r['product'] for r in ais['rows'] if r['aiStack'] == 'strict' and r['kevAdded'] >= '2026-01-01'); assert ai2['Langflow'] + ai2['LiteLLM'] == 9
chk('AI clustering', dict(ai2), 'Nine of the thirteen are two products')

# ---- LinkedIn post and infographic agree with the article
INFO = (ROOT / 'img' / 'infographic.html').read_text(encoding='utf-8') if (ROOT / 'img' / 'infographic.html').exists() else None
def chk_in(text, name, label, *needles):
    if text is None: return
    for s_ in needles: checks.append((f'{name}: {label}', None, s_, s_ in text))
chk_in(POST, 'post', 'totals', f'NVD added {n(jn26)} CVE records, up {100 * (jn26 / jn25 - 1):.0f}% year over year', f'CISA added {k26} vulnerabilities', f'up {100 * (k26 / k25 - 1):.0f}%.', f'{n(q326)} records against {n(q325)}', 'from 51 to 100')
chk_in(POST, 'post', 'findings', '61% of the year-over-year increase in Q3 records', 'account for 8% of that increase', f'({ly["2026"]["n"]} of the {k26})', 'was 6 days. The same months and the same rule give 4 days in 2023, 6 in 2024 and 9 in 2025', 'About 1 in 5 of those 278',
       '56% of NVD records carried a high or critical CVSS rating', '0.34% were in KEV by 30 November', f'{cf["six_quarters"]["recall_pct"]:.0f}% of the CVEs that reached KEV carried that rating', '0 in 2024, 1 in 2025, 13 in 2026', '78 of its 100 Q3 KEV entries carried three-day deadlines')
chk_in(POST, 'post', 'calls', f'140,000 to 325,000 new CVE records in NVD (last 12 months: {n(b["fy26_nvd"])})', f'260 to 700 additions to CISA KEV (last 12 months: {b["fy26_kev"]})', 'A median of 14 days or less', 'CVEs published since 1 January 2026')
chk_in(INFO, 'image', 'numbers', f'{n(jn26)} new CVEs.', f'<span class="hl">{k26}</span>', f'Jan–Nov 2026: {n(jn26)} · ×{jn26 / jn25:.1f}', f'Jan–Nov 2026: {k26} · ×{k26 / k25:.2f}', f'<b>×{jn26 / jn25:.1f}</b>',
       f'>avg {n(cy25 / 12)}<', f'>avg {msum(KM, "2025-01", "2025-12") / 12:.1f}<', '56% of Q3 CVEs clear that bar · 0.34% of those reached KEV', 'DATA AS OF 1 DEC 2026')
assert round(100 * dz['n'] / dz['of_fresh']) == 22 and round(100 * A['wysokie_i_krytyczne'] / A['cve']) == 56

bad = [x for x in checks if not x[3]]
for label, value, s, ok in checks: print(('OK  ' if ok else 'MISS'), label, '|', s)
print(f'\n{len(checks) - len(bad)} of {len(checks)} strings found (article, post, image)')
sys.exit(1 if bad else 0)
