---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Exhaustive safety check: no live article may return 410. Probes EVERY indexable article plus every analysed article over localhost. Read-only. \"\"\" import concurrent.futures as cf import os."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-09-25T16:52:16Z"
site: "main"
source_path: "copecheck/verify_410_safety.py"
---

# !/usr/bin/env python3

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

```py
#!/usr/bin/env python3
"""Exhaustive safety check: no live article may return 410.

Probes EVERY indexable article plus every analysed article over localhost.
Read-only.
"""
import concurrent.futures as cf
import os
import sqlite3
import sys
import urllib.error
import urllib.request

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

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


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


def run(label, sql, expect, forbid):
    rows = [r["slug"] for r in c.execute(sql).fetchall()]
    print(f"\n{label}: probing {len(rows)} URLs ...")
    bad, counts = [], {}
    with cf.ThreadPoolExecutor(24) as ex:
        for slug, st in ex.map(code, rows):
            counts[st] = counts.get(st, 0) + 1
            if st in forbid or (expect and st not in expect):
                bad.append((slug, st))
    print("   status distribution:", dict(sorted(counts.items(), key=str)))
    if bad:
        print(f"   *** {len(bad)} VIOLATIONS ***")
        for s, st in bad[:10]:
            print(f"     {st}  /v/{s}")
    else:
        print("   OK — no violations")
    return len(bad)


violations = 0

violations += run(
    "ALL INDEXABLE articles (must be 200, must NEVER be 410)",
    "SELECT slug FROM articles WHERE index_status IN ('index','trial_index')",
    expect={200, 301}, forbid={410, 404})

violations += run(
    "ALL analysed articles with a verdict (must never be 410)",
    "SELECT slug FROM articles WHERE status='analysed' "
    "AND verdict_md IS NOT NULL AND trim(verdict_md) <> ''",
    expect=None, forbid={410})

violations += run(
    "Quarantined / failed / unanalysed (should now be 410)",
    "SELECT slug FROM articles WHERE status IN ('quarantined','failed') "
    "OR (status='pending' AND (verdict_md IS NULL OR trim(verdict_md)=''))",
    expect={410}, forbid={200})

print("\n" + "=" * 60)
print("TOTAL VIOLATIONS:", violations)
c.close()
sys.exit(1 if violations else 0)
```
