---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Verify the 410 rule two ways, without hammering the live site. (1) EXHAUSTIVE logic check over all 13,441 rows: prove _is_permanently_gone() can never classify a live article as gone. No HTTP."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-09-25T16:54:11Z"
site: "main"
source_path: "copecheck/verify_410_safe.py"
---

# !/usr/bin/env python3

Source path: `copecheck/verify_410_safe.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-09-25T16:54:11Z`

```py
#!/usr/bin/env python3
"""Verify the 410 rule two ways, without hammering the live site.

(1) EXHAUSTIVE logic check over all 13,441 rows: prove _is_permanently_gone()
    can never classify a live article as gone. No HTTP, no load.
(2) GENTLE HTTP sample at low concurrency to confirm the wiring matches.
"""
import concurrent.futures as cf
import os
import sqlite3
import sys
import time
import urllib.error
import urllib.request

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
DB = os.path.join(HERE, "data", "copecheck.db")
BASE = "http://localhost:8096"

# Import the real predicate from the running app module.
import app as appmod  # noqa: E402

c = sqlite3.connect(f"file:{DB}?mode=ro", uri=True)
c.row_factory = sqlite3.Row

print("=" * 66)
print("(1) EXHAUSTIVE LOGIC CHECK over every article row")
print("=" * 66)

rows = c.execute(
    "SELECT slug, status, verdict_md, index_status FROM articles").fetchall()
print(f"rows evaluated: {len(rows)}")

live_misclassified = []
gone_count = 0
gone_but_indexable = []
gone_but_analysed = []

for r in rows:
    d = {"status": r["status"], "verdict_md": r["verdict_md"]}
    is_gone = appmod._is_permanently_gone(d)
    is_live = (r["status"] == "analysed"
               and (r["verdict_md"] or "").strip() != "")
    if is_gone:
        gone_count += 1
        if is_live:
            live_misclassified.append(r["slug"])
        if r["index_status"] in ("index", "trial_index"):
            gone_but_indexable.append(r["slug"])
        if r["status"] == "analysed":
            gone_but_analysed.append(r["slug"])

print(f"classified GONE (410): {gone_count}")
print(f"classified LIVE (200): {len(rows) - gone_count}")
print()
ok = True
for label, bad in (
    ("live articles misclassified as gone", live_misclassified),
    ("INDEXABLE articles classified as gone", gone_but_indexable),
    ("analysed articles classified as gone", gone_but_analysed),
):
    status = "OK" if not bad else f"*** {len(bad)} VIOLATIONS ***"
    print(f"  [{'PASS' if not bad else 'FAIL'}] {label}: {status}")
    if bad:
        ok = False
        for s in bad[:5]:
            print("      ", s)

# Adversarial inputs
print("\n  adversarial cases:")
cases = [
    ({"status": "analysed", "verdict_md": "## Verdict"}, False, "live article"),
    ({"status": "analysed", "verdict_md": ""}, False, "analysed, empty verdict"),
    ({"status": "pending", "verdict_md": "## Verdict"}, False, "pending WITH verdict"),
    ({"status": "pending", "verdict_md": ""}, True, "pending, no verdict"),
    ({"status": "pending", "verdict_md": "   "}, True, "pending, whitespace verdict"),
    ({"status": "quarantined", "verdict_md": "## V"}, True, "quarantined w/ verdict"),
    ({"status": "failed", "verdict_md": None}, True, "failed"),
    ({"status": None, "verdict_md": None}, False, "null status"),
    (None, False, "no row at all (unknown slug)"),
]
for payload, expected, label in cases:
    got = appmod._is_permanently_gone(payload)
    good = got == expected
    if not good:
        ok = False
    print(f"    [{'PASS' if good else 'FAIL'}] {label:<32} gone={got} "
          f"(expected {expected})")

print("\n" + "=" * 66)
print("(2) GENTLE HTTP SAMPLE (concurrency 4)")
print("=" * 66)


def code(slug):
    req = urllib.request.Request(f"{BASE}/v/{slug}",
                                 headers={"User-Agent": "CopeCheckProbe/1.0"})
    try:
        return urllib.request.urlopen(req, timeout=30).status
    except urllib.error.HTTPError as e:
        return e.code
    except Exception as e:
        return f"ERR:{type(e).__name__}"


def sample(label, sql, n, expect):
    slugs = [r["slug"] for r in c.execute(sql + f" LIMIT {n}").fetchall()]
    counts = {}
    with cf.ThreadPoolExecutor(4) as ex:
        for st in ex.map(code, slugs):
            counts[st] = counts.get(st, 0) + 1
    bad = {k: v for k, v in counts.items() if k not in expect}
    print(f"  [{'PASS' if not bad else 'FAIL'}] {label:<42} "
          f"n={len(slugs):<4} {dict(sorted(counts.items(), key=str))}")
    time.sleep(1)
    return not bad


hp = True
hp &= sample("indexable (expect 200)",
             "SELECT slug FROM articles WHERE index_status IN "
             "('index','trial_index') ORDER BY RANDOM()", 150, {200, 301})
hp &= sample("analysed w/ verdict (expect 200, never 410)",
             "SELECT slug FROM articles WHERE status='analysed' AND "
             "verdict_md IS NOT NULL AND trim(verdict_md)<>'' ORDER BY RANDOM()",
             150, {200, 301})
hp &= sample("quarantined (expect 410)",
             "SELECT slug FROM articles WHERE status='quarantined' "
             "ORDER BY RANDOM()", 100, {410})
hp &= sample("never-analysed (expect 410)",
             "SELECT slug FROM articles WHERE status='pending' AND "
             "(verdict_md IS NULL OR trim(verdict_md)='') ORDER BY RANDOM()",
             100, {410})

print("\n" + "=" * 66)
print("RESULT:", "ALL CHECKS PASSED" if (ok and hp) else "FAILURES PRESENT")
c.close()
sys.exit(0 if (ok and hp) else 1)
```
