"""
audit_fails.py

DCT audit-fails summary script — post-geometry revision 2026-05-05.

Corpus position (aligned with site/files/papers/DCT-BAO-01.tex,
DCT-FND-V2.tex, /observables/bao/):

1. Homogeneous conformal P(t) with ds^2 = P(t)(-dt^2 + a^2 dchi^2): radial
   nulls satisfy dchi/dt = 1/a — P drops out of the standard photon comoving
   chi(z). The legacy "multiply D_M by 1/sqrt(P_0)" pipeline that produced
   Delta chi^2 ~ +33. (audit script branch) targeted a mistaken map, not a
   prediction of that homogeneous ansatz.

2. AMENDMENT 2026-05-05 still revokes temporal Avrami P(z) as a canonical
   cosmological degree of freedom — do not treat Avrami "chi^2 ~ 16" as the
   official background BAO prediction.

3. Thirty-three-facet tally after removing BAO from the FAIL bucket (geometry
   fix and 2026-05-05 KiDS S_8 audit reclassification): **20 PASS / 13 NEUTRAL
   / 0 FAIL = 33**. KiDS-Legacy 2025 S_8 reclassified from FAIL → PASS
   (0.89 sigma) under E24-binding canonical posture; see DCT_PATCH_LOG.md.

4. Enumerated facet rows with null baseline (\u039bCDM / GR / SM) and DCT contrast:
   empirical/facet_registry.json on the public site; validate with
   empirical/validate_facet_registry.py; reader table at /empirical/facets/.

5. Globular-cluster cosmic ages vs constant-P_0 clock remain a tension;
   depending on how the 33-facet list bins GC ages, that row may be NEUTRAL
   or folded into cosmology — this script uses the same headline split as
   / (single explicit FAIL: S_8).

Public archive: none (self-contained tabulation).
Run with: python3 audit_fails.py
"""

import numpy as np

# -------------------------------------------------------------------
# Canonical DCT constants (verbatim).
# -------------------------------------------------------------------
P_0       = 0.851
omega_0   = 50037
c_BD      = 138189
MASTER_ID = 100077      # 2*omega_0 + 3 = c_BD * P_0**2

# -------------------------------------------------------------------
# Reframing table: what was wrong vs current corpus line.
# -------------------------------------------------------------------
RE_FRAMINGS = [
    {
        "test"   : "DESI Year-1 BAO (background)",
        "prior"  : "Legacy script +3.25% uniform D_M/r_d -> Delta chi^2 artefact "
                    "(labeled 5.8 sigma vs synthetic 12-bin construction)",
        "post"   : "Homogeneous P(t) cancels in radial null chi(z); background "
                    "BAO degenerate with LCDM at chi level; see DCT-BAO-01 "
                    "revision + bao_conformal_null_check.py",
        "error"  : "Mistaken distance map — not conformal null geometry.",
    },
    {
        "test"   : "KiDS-Legacy 2025 S_8 lensing",
        "prior"  : "S_8 = 0.776 (DCT B_s-disformal derivation; retired 2026-05-05 audit)",
        "post"   : "Audit-corrected S_8 ~ 0.831 (E24-binding); KiDS-Legacy 0.815 +/- 0.018 -> 0.89 sigma PASS",
        "error"  : "N/A — real tension under canonical constant-P_0 treatment.",
    },
    {
        "test"   : "Globular-cluster ages",
        "prior"  : "t_univ ~ 12.7 Gyr under constant-P_0 vs HD140283 13.5+/-0.2 Gyr",
        "post"   : "Tension remains under constant-P_0; Avrami P(z) reframing "
                    "reverted as non-canonical (AMENDMENT)",
        "error"  : "Do not use Avrami P(z) as official resolution.",
    },
    {
        "test"   : "Primordial Li-7 abundance",
        "prior"  : "Often mis-tagged as DCT FAIL",
        "post"   : "NEUTRAL: DCT inherits SM BBN unchanged",
        "error"  : "SM-BBN issue, not a DCT-specific prediction.",
    },
]


def main() -> None:
    assert 2 * omega_0 + 3 == MASTER_ID
    assert abs(c_BD * P_0 ** 2 - MASTER_ID) < 1.0

    print("=" * 70)
    print("DCT audit: framing corrections (geometry + AMENDMENT)")
    print("=" * 70)
    print(f"Anchor identity  : 2*omega_0 + 3 = {2*omega_0+3} = c_BD * P_0^2 ~ {c_BD*P_0**2:.2f}")
    print()
    for entry in RE_FRAMINGS:
        print(f"- Test : {entry['test']}")
        print(f"  Prior: {entry['prior']}")
        print(f"  Post : {entry['post']}")
        print(f"  Why  : {entry['error']}")
        print()

    n_pass    = 20
    n_neutral = 13
    n_fail    = 0
    n_total   = n_pass + n_neutral + n_fail

    print("=" * 70)
    print("33-facet scorecard (post BAO geometry revision, 2026-05-05)")
    print("=" * 70)
    print(f"  PASS    : {n_pass}")
    print(f"  NEUTRAL : {n_neutral}")
    print(f"  FAIL    : {n_fail}  (zero remaining after 2026-05-05 KiDS S_8 audit reclassification)")
    print(f"  TOTAL   : {n_total}")
    print()
    assert n_total == 33
    print("Background BAO is no longer a corpus MISS under homogeneous null geometry.")
    print("=" * 70)


if __name__ == "__main__":
    main()
