GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Websites and apps / worlds- / src

Verdict Gate and 1 more file

A Python command-line tool in Worlds that marks specimens (`mark_specimens`). It is built from the tokens step (`tokens`), the polarity step (`polarity`) and the is limit helper (`is_limit`).

700 lines of Python from worlds-, in 2 files. Topic: Websites and apps. Section 2036 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Thread Truth other · worlds- / src/thread_truth.py lines 658–719
  2. Verdict Gate other · worlds- / src/verdict_gate.py lines 1–638

Thread Truth

A Python command-line tool in Worlds that derives card (`derive_on_card`) and host (`derive_on_host`) and rates table (`rate_table`) (units: kV), using SHA-256.

otherworlds- / src/thread_truth.py · lines 658–719 of 719 (continued from section 2035) · Entry point

What it does
Defines 16 functions or classes, including numbers_in, _block_text, record_text, said, artefacts. Uses libraries argparse, hashlib, io, json, os. Side effects: reads or writes files; starts processes.
Inputs & outputs
In: JSON file thread-truth.json; command-line arguments.
Downstream impact
It is itself an entry point (Python CLI); no other file was found loading it.
What it achieves
It records text (`record_text`) and is built from the numbers in helper (`numbers_in`) and the said step (`said`). This repository is public and an absolute path names a machine and an account. It accepts `--run`.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
worlds- · src · Python CLI
Uses
Paths (import), argparse, hashlib, io, json, os, random, re, sys
Used by
none found
Produces
numbers_in, record_text, said, artefacts, near_pool, derive_on_card, derive_on_host, band, rate_table, pct, band_verdict, print_table
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
worlds-@83817c34790800d4af5057629121d83d0d67a332 src/thread_truth.py:658-719 · blob 5c68667d04bdf7bb691a36581776a277a9a49f2d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: ingest · effects: filesystem, process · domain stage: unknown · users: none · canonical: unknown
            "operand_pool_median": sizes[len(sizes) // 2],
            "operand_pool_largest": sizes[-1],
            "claims_with_no_operands": sum(1 for s in sizes if s == 0),
            "decoys_per_claim": DECOYS_PER_CLAIM,
            "decoy_seed": DECOY_SEED,
            "false_absorption_ceiling_pct": 100.0 * FALSE_ABSORPTION_CEILING,
            "decoys_a_band_needs_before_it_is_vouched_for": MIN_DECOYS_PER_BAND,
        },
        "false_absorption_before": table_json(results["wide"]["rows"]),
        "false_absorption_after": table_json(results["near"]["rows"]),
        "to_read": [{"value": v, "times_said": len(claims.get(v, [])),
                     "first_turn": (claims.get(v) or [-1])[0]}
                    for v in hard],
        "method":
            "Every distinctive number (>= 1000) in the model's OWN sentences is "
            "taken from the transcript - tool results are excluded, because "
            "those are evidence and not claims. Every distinctive number in "
            "every artefact on disk is taken as the backing set. Membership is "
            "computed twice, by binary search on the card and by a hash set on "
            "the host, and nothing is reported unless they agree. What remains "
            "is tested on the card against pairs of backed numbers that "
            "CO-OCCURRED with the claim - within a short window of transcript "
            "records of where it was said - for sum, difference and exact "
            "quotient. That derivation is computed twice as well, by a nested "
            "scan on the card and by set lookups on the host, and disagreement "
            "refuses the report.",
        "how_the_sieve_was_measured":
            "Every run carries a decoy arm. For each unbacked claim, random "
            "numbers of the same magnitude that were never said and appear in "
            "no artefact are pushed through the same sieve with the same "
            "operand pool. Their absorption rate is the false absorption rate, "
            "printed per magnitude band beside the real one, for the old wide "
            "sieve and for this one. A band whose false absorption is above "
            "the ceiling cannot discriminate and its survivor count means "
            "nothing. If the decoy rate overall is not clearly below the real "
            "rate, the run declares its own verdict uninformative without "
            "being asked. Quote false_absorption_after beside any count taken "
            "from this file.",
        "not_claimed":
            "A number being BACKED does not mean it was used correctly, only "
            "that it exists somewhere on disk. A number being TRULY UNBACKED "
            "does not mean it is false - it may be arithmetic done in a "
            "sentence out of numbers that were never written down, or a figure "
            "quoted from outside this night's work. This file cannot tell "
            "those apart and does not try. It narrows what a person has to "
            "read, and that is all it does. It does not check whether a "
            "quantity changed value across the night.",
        "anonymised": "No project, site, client, maker or model anywhere.",
    }
    digest = hashlib.sha256(
        json.dumps(body, sort_keys=True).encode("utf-8")).hexdigest()
    body["body_sha256"] = digest
    os.makedirs(RESULTS, exist_ok=True)
    io.open(OUT, "w", encoding="utf-8", newline="\n").write(
        json.dumps(body, indent=1, sort_keys=True) + "\n")
    print("\n  body sha256 %s" % digest[:32])
    print("  wrote night-results/thread-truth.json")
    return 0


if __name__ == "__main__":
    sys.exit(main())

Verdict Gate

A Python command-line tool in Worlds that marks specimens (`mark_specimens`). It is built from the tokens step (`tokens`), the polarity step (`polarity`) and the is limit helper (`is_limit`).

otherworlds- / src/verdict_gate.py · lines 1–638 of 673 · Entry point · pattern self_test (shared by 2 files)

What it does
It lists and searches its content. Defines 26 functions or classes, including tokens, polarity, is_limit, is_pure, bearing_limit. Uses libraries argparse, ast, io, json, os. Side effects: reads or writes files; starts processes.
Why it exists in the grid workflow
Domain stage field_execution (path word 'gate'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work. Domain terms in the code: 1500V.
Inputs & outputs
In: JSON file verdict-gate.json; command-line arguments. Voltage levels named: 1500V.
Downstream impact
Used directly by 2 files: Weekly Gates Workflow (worlds-); All Gates (worlds-).
What it achieves
A GATE ON THIS REPOSITORY'S VERDICTS - not on IEEE arithmetic. It accepts `--run`, `--ci` and `--self-test`.
Why it matters
Run by Weekly Gates Workflow and All Gates.
Application
worlds- · src · Python CLI
Uses
argparse, ast, io, json, os, re, subprocess, sys
Used by
run by Weekly Gates Workflow (workflow run), run by All Gates (script call)
Produces
tokens, polarity, is_limit, is_pure, bearing_limit, widest_pure, Feed, feed, finding, module_constants, from_python, c_to_python
Defines here
tokens, polarity, is_limit, is_pure, bearing_limit, widest_pure, Feed, __init__, visit_UnaryOp, visit_BinOp, visit_Compare, feed, finding, module_constants, from_python, c_to_python, from_embedded, mark_specimens, scan, defects, verdict, verdict, self_test, arithmetic, show, main
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
worlds-@83817c34790800d4af5057629121d83d0d67a332 src/verdict_gate.py:1-638 · blob 9a9f339993f25f7e86aa2d5879a4e251620de65e · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: ingest · effects: filesystem, process · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unknown
"""A GATE ON THIS REPOSITORY'S VERDICTS - not on IEEE arithmetic.

WHAT THIS GATE USED TO BE, AND WHY IT WAS WORTHLESS

It swept two million doubles through `x > L` and `!(x <= L)` and exited 1
whenever the two disagreed on a non-number. They always disagree on a
non-number: that is what IEEE-754 says, it was true before this repository
existed and it will be true after it is deleted. So `--ci` returned 1 on every
run whatever any file here contained. A gate that always fails gates exactly as
much as one that always passes: after the second run nobody reads it, and a red
light that cannot turn green is not a light. It read no source file in the
repository it was supposed to be gating.

THE DEFECT IT WAS WRITTEN FOR IS REAL AND IS KEPT

    over_volts = v > V_CEIL

If v is not a number, `v > 1500` is false, so `over_volts` is false, so the
program reports "inside the 1500 V rating by NaN V". Someone typed a word where
a number belonged and got a PASS on a design that was never evaluated. That is
a property of THIS CODE. The arithmetic is only the reason it happens.

    inside = (v <= limit)          false for NaN
    over   = not inside            true  for NaN -> refused upstream

WHAT THIS GATE IS NOW

It reads the source of this repository, finds every comparison that decides a
verdict - a name like over_*, fail_*, ok, inside, within, tested against a
declared limit - feeds each one a non-number, and asks what the verdict then
says. A verdict that says PASS when it was handed something that is not a
number is a defect and fails the gate. A verdict that refuses, or raises, is
clean. Fix the comparisons and the gate goes green; write a new one in the old
shape and it goes red. It is about the repository, so it can do both.

Both Python comparisons and the comparisons inside the embedded device kernels
are read: most of the verdicts in this estate live in C source held in Python
strings, and a gate that only understood Python would have covered almost none
of them.

A PAIRED SPECIMEN is not a defect. Where one file computes `x > L` and
`!(x <= L)` on the same operands, the old form is a specimen under measurement,
not a verdict anyone acts on. Those are excluded BY NAME AND LINE in the
output, never silently.

THE GATE PROVES IT CAN DO BOTH BEFORE IT JUDGES ANYTHING

Every `--run` first runs this gate, as a subprocess, against two fixtures it
writes itself: one comparison in the broken shape, which must exit 1, and the
same comparison corrected, which must exit 0. The two exit codes are printed.
If either fixture does not behave, the gate fails closed and judges nothing - a
gate never observed to pass AND to fail has not been shown to gate anything.

    python verdict_gate.py            the question
    python verdict_gate.py --run      self-test, then scan, with the evidence
    python verdict_gate.py --run --ci exit 1 if any verdict passes a non-number
    python verdict_gate.py --self-test        just the two fixtures
    python verdict_gate.py --scan DIR --ci    scan a directory (used above)
    python verdict_gate.py --arithmetic       the old sweep, clearly labelled

WHAT A PASS HERE DOES NOT COVER: whether the limits are right; whether the
verdict is the right question; any comparison whose result is not bound to a
name this gate recognises, or not tested against a declared limit. Those are
absent, not clean, and the run prints how many it left alone.
"""
import argparse
import ast
import io
import json
import os
import re
import subprocess
import sys
import tempfile
import time

HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)

# ---------------------------------------------------------------- names ----
# A verdict is a named thing. The name says which way round it points.
REFUSE_WORDS = {
    "over", "under", "exceed", "exceeds", "exceeded", "excess", "breach",
    "breaches", "fail", "fails", "failed", "failure", "bad", "violation",
    "violates", "violated", "unsafe", "reject", "rejected", "refused",
    "trip", "trips", "tripped", "too", "broken",
}
PASS_WORDS = {
    "ok", "okay", "pass", "passes", "passed", "inside", "within", "valid",
    "safe", "good", "clean", "clear", "accept", "accepted", "allowed",
    "survives", "survive", "fine", "holds",
}
# A limit is a declared constant, not another measurement.
LIMIT_WORDS = {
    "limit", "limits", "lim", "ceil", "ceiling", "cap", "rating", "rated",
    "threshold", "max", "maximum", "min", "minimum", "tol", "tolerance",
    "bound", "withstand", "budget",
}

_TOK = re.compile(r"[A-Z]+(?![a-z])|[A-Z][a-z]*|[a-z]+|\d+")


def tokens(name):
    return [t.lower() for t in _TOK.findall(name or "")]


def polarity(name):
    """refuse: True means the design is refused.  pass: True means accepted."""
    ts = set(tokens(name))
    r, p = ts & REFUSE_WORDS, ts & PASS_WORDS
    if r and not p:
        return "refuse"
    if p and not r:
        return "pass"
    return None


# The ALL_CAPS names declared at the top of the file being read. A local
# called P is an index; a module constant called V_CEIL is a limit. None means
# "any ALL_CAPS name", which is right for a device kernel, where the limits
# arrive as substituted macros and there is no module to look in.
CONSTS = None


def is_limit(node):
    """A declared limit: a number, or a name that reads like a limit."""
    if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)) \
            and not isinstance(node.value, bool):
        return True
    if isinstance(node, ast.Name):
        i = node.id
        if any(c.isalpha() for c in i) and i.upper() == i \
                and (CONSTS is None or i in CONSTS):
            return True          # ALL_CAPS: the estate's constant convention
        if set(tokens(i)) & LIMIT_WORDS:
            return True
    return False


OPSYM = {ast.Gt: ">", ast.GtE: ">=", ast.Lt: "<", ast.LtE: "<="}


# ------------------------------------------------------- the expression ----
def is_pure(n):
    """A boolean expression whose value we can reproduce with a scalar probe.
    Comparison OPERANDS are not inspected: the measured side is replaced
    wholesale by the probe, and the limit side is a name or a number."""
    if isinstance(n, ast.Compare):
        return True
    if isinstance(n, ast.BoolOp):
        return all(is_pure(v) for v in n.values)
    if isinstance(n, ast.UnaryOp) and isinstance(n.op, (ast.Not, ast.Invert)):
        return is_pure(n.operand)
    if isinstance(n, ast.BinOp) and isinstance(n.op, (ast.BitAnd, ast.BitOr)):
        return is_pure(n.left) and is_pure(n.right)
    if isinstance(n, ast.Constant):
        return True
    return False


def bearing_limit(cmp_node):
    """A quantity tested against a declared limit. Only the ordered
    comparisons: `==` and `in` are not range tests and are not this defect."""
    if not isinstance(cmp_node, ast.Compare) or len(cmp_node.comparators) != 1:
        return False
    if type(cmp_node.ops[0]) not in OPSYM:
        return False
    return is_limit(cmp_node.left) or is_limit(cmp_node.comparators[0])


def widest_pure(cmp_node, parents):
    """Climb out of the comparison as far as the expression stays boolean, so
    that a `not` wrapped round it is carried with it."""
    node = cmp_node
    while True:
        up = parents.get(id(node))
        if up is None or not is_pure(up):
            return node
        node = up


class Feed(ast.NodeTransformer):
    """Hand the measured side of every comparison a non-number.

    `~` becomes `not` and `&`/`|` become `and`/`or`: on arrays those are the
    element-wise boolean operators, and this gate evaluates one element."""

    def __init__(self, probe):
        self.probe = probe
        self.fed = 0

    def visit_UnaryOp(self, node):
        self.generic_visit(node)
        if isinstance(node.op, ast.Invert):
            return ast.UnaryOp(op=ast.Not(), operand=node.operand)
        return node

    def visit_BinOp(self, node):
        self.generic_visit(node)
        if isinstance(node.op, ast.BitAnd):
            return ast.BoolOp(op=ast.And(), values=[node.left, node.right])
        if isinstance(node.op, ast.BitOr):
            return ast.BoolOp(op=ast.Or(), values=[node.left, node.right])
        return node

    def visit_Compare(self, node):
        if len(node.comparators) != 1:
            return node
        probe = ast.Name(id=self.probe, ctx=ast.Load())
        left, right = node.left, node.comparators[0]
        if is_limit(right) and not is_limit(left):
            node.left = probe
        elif is_limit(left) and not is_limit(right):
            node.comparators = [probe]
        else:
            node.left = probe
        self.fed += 1
        return node            # deliberately not recursing into the operands


PROBES = [("NaN", "__nan__", float("nan")),
          ("the word \"thirty\"", "__txt__", "thirty")]


def feed(expr_node, probe_name):
    """Return (verdict_true, note). verdict_true is what the comparison
    evaluates to once the measured side is a non-number; None if it raised."""
    tree = ast.Expression(body=Feed(probe_name).visit(
        ast.parse(ast.unparse(expr_node), mode="eval").body))
    ast.fix_missing_locations(tree)
    env = {"__nan__": float("nan"), "__txt__": "thirty"}
    for n in ast.walk(tree):
        if isinstance(n, ast.Name) and n.id not in env:
            env[n.id] = 1.0                      # every limit, a real number
    try:
        return bool(eval(compile(tree, "<verdict>", "eval"), {}, env)), ""
    except Exception as e:                       # a refusal, and a loud one
        return None, "%s" % type(e).__name__


# ---------------------------------------------------------- extraction ----
def finding(path_label, line, name, pol, expr_node, origin):
    cmps = [n for n in ast.walk(expr_node)
            if isinstance(n, ast.Compare) and bearing_limit(n)]
    if not cmps:
        return None
    c = cmps[0]
    if is_limit(c.comparators[0]) and not is_limit(c.left):
        val, lim = c.left, c.comparators[0]
    else:
        val, lim = c.comparators[0], c.left
    negs = sum(1 for n in ast.walk(expr_node)
               if isinstance(n, ast.UnaryOp)
               and isinstance(n.op, (ast.Not, ast.Invert)))
    f = {"file": path_label, "line": line, "name": name, "polarity": pol,
         "expr": ast.unparse(expr_node), "origin": origin,
         "op": OPSYM.get(type(c.ops[0]), "?"),
         "measured": ast.unparse(val), "limit": ast.unparse(lim),
         "negated": bool(negs % 2), "specimen": False, "probes": []}
    for label, probe, _v in PROBES:
        if origin == "embedded" and probe == "__txt__":
            continue           # a device kernel has no strings to be handed
        r, note = feed(expr_node, probe)
        if r is None:
            f["probes"].append({"fed": label, "verdict": "raised " + note,
                                "passes": False})
        else:
            passes = r if pol == "pass" else (not r)
            f["probes"].append(
                {"fed": label,
                 "verdict": ("PASS - accepted as within the limit" if passes
                             else "refused"),
                 "passes": passes})
    f["passes_a_non_number"] = any(p["passes"] for p in f["probes"])
    return f


def module_constants(mod):
    """The ALL_CAPS names bound at the top level of this file."""
    names = set()
    for stmt in mod.body:
        targets = []
        if isinstance(stmt, ast.Assign):
            targets = stmt.targets
        elif isinstance(stmt, (ast.AnnAssign, ast.AugAssign)):
            targets = [stmt.target]
        for t in targets:
            for n in ast.walk(t):
                if isinstance(n, ast.Name) and n.id.upper() == n.id:
                    names.add(n.id)
    return names


def from_python(path_label, text):
    """Assignments in Python: over_x = <boolean expression about a limit>."""
    global CONSTS
    out, skipped = [], 0
    try:
        mod = ast.parse(text)
    except SyntaxError:
        return out, skipped
    CONSTS = module_constants(mod)
    parents = {}
    for n in ast.walk(mod):
        for ch in ast.iter_child_nodes(n):
            parents[id(ch)] = n
    for n in ast.walk(mod):
        if isinstance(n, ast.Assign):
            names = [t.id for t in n.targets if isinstance(t, ast.Name)]
        elif isinstance(n, (ast.AnnAssign, ast.NamedExpr)):
            names = [n.target.id] if isinstance(n.target, ast.Name) else []
        else:
            continue
        cmps = [c for c in ast.walk(n.value)
                if isinstance(c, ast.Compare) and bearing_limit(c)]
        if not cmps:
            continue
        pols = [(nm, polarity(nm)) for nm in names]
        if not any(p for _nm, p in pols):
            skipped += len(cmps)
            continue
        for nm, pol in pols:
            if not pol:
                continue
            f = finding(path_label, cmps[0].lineno, nm, pol,
                        widest_pure(cmps[0], parents), "python")
            if f:
                out.append(f)
    return out, skipped


# `int over_volt = (v > VC) ? 1 : 0;` - the shape the device kernels use, held
# in a Python string. A statement ending in a semicolon is not Python.
C_ASSIGN = re.compile(
    r"^\s*(?:(?:const|static|unsigned|signed|long|short|int|bool|char|double|"
    r"float|var|let|const)\s+)*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([^;]*?)\s*;")
C_TERNARY = re.compile(r"\?\s*1\s*:\s*0\s*$")


def c_to_python(expr):
    expr = C_TERNARY.sub("", expr).strip()
    expr = expr.replace("&&", " and ").replace("||", " or ")
    expr = re.sub(r"!(?!=)", " not ", expr)
    expr = re.sub(r"\btrue\b", "True", expr)
    expr = re.sub(r"\bfalse\b", "False", expr)
    return expr.strip()


def from_embedded(path_label, text):
    global CONSTS
    CONSTS = None               # a kernel's limits are substituted macros
    out, skipped = [], 0
    for i, line in enumerate(text.splitlines(), 1):
        m = C_ASSIGN.match(line)
        if not m:
            continue
        name, rhs = m.group(1), m.group(2)
        if not re.search(r"[<>]=?", rhs):
            continue
        pol = polarity(name)
        try:
            node = ast.parse(c_to_python(rhs), mode="eval").body
        except SyntaxError:
            continue
        if not any(isinstance(c, ast.Compare) and bearing_limit(c)
                   for c in ast.walk(node)):
            continue
        if not pol:
            skipped += 1
            continue
        if not is_pure(node):
            skipped += 1
            continue
        f = finding(path_label, i, name, pol, node, "embedded")
        if f:
            out.append(f)
    return out, skipped


def mark_specimens(findings):
    """`x > L` beside `!(x <= L)` on the same operands, in the same file, is a
    measurement of the old form, not a verdict anyone acts on."""
    by_file = {}
    for f in findings:
        by_file.setdefault(f["file"], []).append(f)
    for fs in by_file.values():
        safe = {(g["measured"], g["limit"]) for g in fs
                if g["op"] in ("<=", "<") and g["negated"]}
        for g in fs:
            if g["op"] in (">", ">=") and not g["negated"] \
                    and (g["measured"], g["limit"]) in safe:
                g["specimen"] = True      # the old form; its fix stays live


READ = (".py", ".c", ".cu", ".cc", ".h", ".js", ".mjs", ".html")


def scan(root):
    findings, skipped, files = [], 0, 0
    for dirpath, dirnames, filenames in os.walk(root):
        dirnames[:] = [d for d in dirnames
                       if d not in (".git", "__pycache__", "night-results")]
        for fn in sorted(filenames):
            if not fn.endswith(READ):
                continue
            p = os.path.join(dirpath, fn)
            try:
                text = io.open(p, encoding="utf-8", errors="replace").read()
            except OSError:
                continue
            label = os.path.relpath(p, root).replace("\\", "/")
            files += 1
            if fn.endswith(".py"):
                a, s = from_python(label, text)
                findings += a
                skipped += s
            b, s2 = from_embedded(label, text)
            findings += b
            skipped += s2
    mark_specimens(findings)
    findings.sort(key=lambda f: (f["file"], f["line"], f["name"]))
    return findings, skipped, files


def defects(findings):
    return [f for f in findings
            if f["passes_a_non_number"] and not f["specimen"]]


# ----------------------------------------------------------- self-test ----
BROKEN = '''"""Fixture: a verdict in the shape that started all this."""
V_CEIL = 1500.0
STRING_INPUT_A = 20.0


def verdict(v, i):
    over_volts = v > V_CEIL
    return "inside the rating" if not over_volts else "over"


KERNEL = """
  int over_string = (i > STRING_INPUT_A) ? 1 : 0;
"""
'''

FIXED = '''"""Fixture: the same two verdicts, asked the other way round."""
V_CEIL = 1500.0
STRING_INPUT_A = 20.0


def verdict(v, i):
    over_volts = not (v <= V_CEIL)
    return "inside the rating" if not over_volts else "over"


KERNEL = """
  int over_string = !(i <= STRING_INPUT_A) ? 1 : 0;
"""
'''


def self_test(verbose=True):
    """Run THIS gate, as a subprocess, on a broken fixture and a corrected one.
    Require exit 1 then exit 0. Print both."""
    me = os.path.abspath(__file__)
    base = tempfile.mkdtemp(prefix="verdict-fixtures-")
    rows = []
    for tag, body, want in (("broken", BROKEN, 1), ("corrected", FIXED, 0)):
        d = os.path.join(base, tag)
        os.makedirs(d, exist_ok=True)
        io.open(os.path.join(d, "fixture.py"), "w", encoding="utf-8",
                newline="\n").write(body)
        p = subprocess.run([sys.executable, me, "--scan", d, "--ci"],
                           capture_output=True, text=True, timeout=120)
        fs, _sk, _n = scan(d)
        rows.append({"fixture": tag, "expected_exit": want,
                     "exit": p.returncode, "as_expected": p.returncode == want,
                     "verdict_comparisons": [
                         {"line": "%s:%d" % (f["file"], f["line"]),
                          "source": "%s = %s" % (f["name"], f["expr"]),
                          "fed": f["probes"][0]["fed"],
                          "says": f["probes"][0]["verdict"]} for f in fs]})
    ok = all(r["as_expected"] for r in rows)
    if verbose:
        print("SELF-TEST: has this gate been seen to fail AND to pass?")
        for r in rows:
            print("\n  fixture: %s" % r["fixture"])
            for c in r["verdict_comparisons"]:
                print("    %-24s  fed %-16s -> %s"
                      % (c["source"], c["fed"], c["says"]))
            print("    exit %d, expected %d   %s"
                  % (r["exit"], r["expected_exit"],
                     "as expected" if r["as_expected"] else "WRONG"))
        print("\n  %s\n" % (
            "Both outcomes observed in this run: this gate discriminates."
            if ok else
            "THE GATE COULD NOT DEMONSTRATE BOTH OUTCOMES. It judges nothing."))
    return ok, rows


# -------------------------------------------- the old sweep, demoted ------
def arithmetic():
    """The sweep this file used to call a gate. It is kept because it is the
    reason NaN matters, and labelled because it can never fail: it measures
    IEEE-754, which no edit to this repository can change. It does not touch
    the exit code."""
    import numpy as np
    lims = [("the 1500 V equipment rating", 1500.0),
            ("the 20 A string input", 20.0),
            ("the 40 A machine input", 40.0),
            ("the 35 A maximum series fuse", 35.0)]
    vals = [float("nan"), float("inf"), float("-inf"), 0.0, -0.0,
            5e-324, -5e-324, 1.7976931348623157e308, -1.7976931348623157e308]
    for _l, L in lims:
        vals += [L, np.nextafter(L, np.inf), np.nextafter(L, -np.inf),
                 -L, L * 2.0, L / 2.0]
    x = np.concatenate([np.linspace(-100.0, 1700.0, 1_000_000), np.array(vals)])
    print("NOT A GATE: the arithmetic, which cannot fail")
    print("  %-34s %10s %10s %10s" % ("limit", "finite", "differ", "old PASS"))
    with np.errstate(invalid="ignore"):
        for lab, L in lims:
            old = x > L
            new = ~(x <= L)
            fin = np.isfinite(x)
            d = old != new
            print("  %-34s %10s %10s %10s"
                  % (lab, "{:,}".format(int(fin.sum())),
                     "{:,}".format(int(d.sum())),
                     "{:,}".format(int((d & ~fin & ~old).sum()))))
    print("\n  On every finite number the two forms agree exactly, so the fix")
    print("  changes no real design. They differ only where the value is not a")
    print("  number. This is a statement about IEEE-754: it was true before")
    print("  this repository and no edit here can make it false, which is")
    print("  precisely why it must not be wired to an exit code.\n")


# ---------------------------------------------------------------- main ----
def show(findings, skipped, files, root_label):
    spec = [f for f in findings if f["specimen"]]
    live = [f for f in findings if not f["specimen"]]
    bad = defects(findings)
    print("VERDICT GATE: does any verdict in %s report a PASS when it is "
          "handed something that is not a number?" % root_label)
    print("  source files read        %d" % files)
    print("  verdict comparisons      %d" % len(live))
    print("  paired specimens         %d  (the old form beside its fix, "
          "measured not acted on)" % len(spec))
    print("  comparisons left alone   %d  (no verdict name, or no declared "
          "limit: absent, not clean)" % skipped)
    if live:
        print("\n  %-34s %-15s %-34s %s"
              % ("where", "verdict", "the comparison", "fed a non-number"))
        for f in live:
            print("  %-34s %-15s %-34s %s"
                  % ("%s:%d" % (f["file"], f["line"]), f["name"],
                     f["expr"][:34],
                     "PASSES IT" if f["passes_a_non_number"] else "refuses it"))
            for p in f["probes"]:
                print("       %-24s -> %s" % ("fed " + p["fed"], p["verdict"]))
    for f in spec:
        print("\n  SPECIMEN, not counted: %s:%d  %s = %s"
              % (f["file"], f["line"], f["name"], f["expr"]))
        print("       the corrected form of the same comparison stands beside "
              "it in that file")
    if bad:
        print("\n  %d VERDICT%s REPORT A PASS ON A NON-NUMBER:"
              % (len(bad), "" if len(bad) == 1 else "S"))
        for f in bad:
            print("    %s:%d  %s = %s"
                  % (f["file"], f["line"], f["name"], f["expr"]))
        print("  Ask the question the other way round, so the burden falls the")
        print("  safe side:  over = not (value <= limit)")
    else:
        print("\n  NO VERDICT HERE ACCEPTS A NON-NUMBER.")
    return bad


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--run", action="store_true")
    ap.add_argument("--ci", action="store_true")
    ap.add_argument("--self-test", action="store_true")
    ap.add_argument("--arithmetic", action="store_true")
    ap.add_argument("--scan", default=None,
                    help="scan this directory instead of the repository")
    a = ap.parse_args()

    if a.scan:                      # the self-test's own invocation: no
        root = os.path.abspath(a.scan)   # recursion, no report file
        findings, skipped, files = scan(root)
        bad = show(findings, skipped, files, "the scanned directory")
        return 1 if (a.ci and bad) else 0

    if a.self_test and not a.run:
        ok, _rows = self_test()
        return 0 if ok else 1

    if a.arithmetic and not a.run:
        arithmetic()
        return 0

    if not a.run:
        print("VERDICT GATE: does any verdict in this repository report a PASS")
        print("  when it is handed something that is not a number?")
        print("  It reads the source here - Python and the embedded kernels -")
        print("  finds the comparisons that decide verdicts, feeds each one a")
        print("  non-number, and fails if any of them accepts it.")
        print("\n  It proves it can do both: every --run first runs itself")
        print("  against a broken fixture (must exit 1) and a corrected one")
        print("  (must exit 0), and prints the two exit codes.")
        print("\n  --run to put it on the card.")
        return 0

    t0 = time.perf_counter()
    st_ok, st_rows = self_test()
    findings, skipped, files = scan(ROOT)
    bad = show(findings, skipped, files, "this repository")
    if a.arithmetic:
        print()
        arithmetic()
    sec = time.perf_counter() - t0

    out = {
        "gate": "verdict",
        "seconds": round(sec, 3),
        "question": "Does any comparison that decides a verdict in this "
                    "repository report a PASS when handed a non-number?",
        "self_test": {
            "both_outcomes_observed": st_ok,
            "why": "A gate never seen to fail AND to pass has not been shown "
                   "to gate anything. This one is run against a broken "
                   "fixture and a corrected one, as a subprocess, before it "
                   "judges the repository.",
            "fixtures": st_rows},
        "source_files_read": files,
        "verdict_comparisons": len([f for f in findings if not f["specimen"]]),
        "paired_specimens": len([f for f in findings if f["specimen"]]),
        "comparisons_left_alone": skipped,