diff --git a/docs/anatomy-linkedin/make_docx.py b/docs/anatomy-linkedin/make_docx.py deleted file mode 100644 index 8d7f1f9c8f9dd5e70603ac6bea5ace59ba446075..0000000000000000000000000000000000000000 --- a/docs/anatomy-linkedin/make_docx.py +++ /dev/null @@ -1,238 +0,0 @@ -from docx import Document -from docx.shared import Pt, RGBColor -from docx.enum.text import WD_ALIGN_PARAGRAPH - -# ---------- CONTENT BLOCKS (each one is copy-paste-ready, character-counted) ---------- - -HOOK_140 = ( - "We shipped an AI-governance page that recomputes a SHA-256 over the " - "published thesis bundle on every load. Drifts → red banner." -) # target ≤ 140 (desktop preview) - -HOOK_210 = ( - "Most \"AI governance\" pages are decoration. Ours recomputes a SHA-256 " - "over the entire upstream-published anatomy bundle on every page load. " - "One byte drifts, the banner flips red. No trust-us path." -) # target ≤ 210 (mobile fold) - -POST_FULL = """Most "AI governance" pages in production are decoration: a Notion link, a PDF on a shared drive, a screenshot of a SOC 2 badge. We just shipped the opposite. - -A11oy → /anatomy is a read-only viewer that vendors the entire upstream Ouroboros thesis anatomy bundle (CC-BY-4.0, github.com/szl-holdings/ouroboros-thesis) and proves byte-level parity with the published thesis on every page load. If one byte drifts, the banner flips from green to red and the page refuses to claim parity. There is no "trust us" code path. - -WHAT'S IN THE BUNDLE - -• 8 canonical figures (brain, wires, full-body, heart, blood/immune, skeleton, nervous, body-graph) as both vector PDF and 300dpi PNG — the operational schematic of a governed agent: AMARU cortex with a 9-axis conjunctive doctrine gate, YUYAY v3 13-axis AND gate (no averaging, sacred axes ≥ 0.95), YAWAR append-only ledger, HUKLLA T01–T10 tripwires, OTel/VSP nervous system, CHAKANA 21-edge M=0 lattice. - -• 7-chakra activation spine (root → crown) with per-chakra leader.md + result.md prose pulled verbatim from upstream — the actual kernel notes (tinygrad → KALLPA dispatch, DSPy → YACHAY retrieval, vLLM → RIMAY sampling), not marketing copy. - -• Real DOIs on every section: concept DOI 10.5281/zenodo.19944926 (always resolves to latest), v13 release 10.5281/zenodo.20195368. - -THE INTEGRITY MECHANISM (the part CTOs care about) - -In the browser, on every load: - -1. Fetch VENDOR.json::expected_files (canonical 14-file manifest). -2. For each filename in sorted order, fetch the bytes and concat sha256( filename || NUL || bytes || NUL ). -3. Compare the digest to VENDOR.json::upstream_sha. Match → green. Mismatch → red DRIFT banner with both hashes side-by-side. No SubtleCrypto → sentinel that never matches a real sha256. Fails closed, never silently green. - -Same construction as Sigstore cosign verify or Subresource Integrity, applied to a documentation bundle. - -WHY THIS MATTERS OPERATIONALLY - -• Auditors re-run the hash and get bit-for-bit reproducibility against the publication. -• CI can fail the build the moment someone "fixes a typo" in a vendored binary. -• Citations are stable — every chakra section deep-links to a resolvable Zenodo DOI, not a Notion page that 404s in six months. -• If you're claiming "auditable AI," these eight figures are the load-bearing primitives. Run a hash against your own published claims and see what happens. - -STACK - -React + Vite + TypeScript. PDF via with PNG fallback (CSP-aware). crypto.subtle.digest("SHA-256", …). No third-party hash libs — the proof is ~30 lines and inspectable in DevTools. - -Upstream thesis: github.com/szl-holdings/ouroboros-thesis""" - -POST_SHORT = """Most "AI governance" pages are decoration. Ours isn't. - -A11oy → /anatomy vendors the entire upstream Ouroboros thesis anatomy bundle (CC-BY-4.0) and recomputes a SHA-256 over the published binaries in the browser on every page load. One byte drifts, the banner flips red. No "trust us" path. - -In the bundle: -• 8 canonical figures (brain, wires, full-body, heart, blood/immune, skeleton, nervous, body-graph) — the operational schematic of a governed agent: AMARU cortex (9-axis doctrine gate), YUYAY v3 (13-axis AND gate, no averaging), YAWAR append-only ledger, HUKLLA tripwires, OTel/VSP nervous system. -• 7-chakra activation spine with per-kernel prose pulled verbatim from upstream. -• Real DOIs (concept 10.5281/zenodo.19944926, v13 10.5281/zenodo.20195368). - -The integrity proof is ~30 lines of crypto.subtle and inspectable in DevTools. Same construction as Sigstore cosign verify, applied to a documentation bundle. Auditors re-run the hash; CI fails the build the moment a vendored byte changes. - -If your governance claim can't survive a hash check, it's a brochure. - -Upstream: github.com/szl-holdings/ouroboros-thesis""" - -HASHTAGS = "#AIGovernance #AuditableAI #DecisionIntelligence #ReproducibleResearch #PlatformEngineering #SoftwareReceipts #SRE #OuroborosThesis #SZLHoldings" - -WARHACKER_BODY = """TO: Defense Unicorns — Warhacker (defenseunicorns.com/warhacker) -RE: Fixing the drones — accountable autonomy on small UAS -FROM: SZL Holdings · CC-BY-4.0 · DOI 10.5281/zenodo.19944926 - -PITCH - -Small-UAS autonomy isn't an airframe problem — it's an accountable-software problem. Closed binaries, no provenance, models that can't be re-run bit-for-bit after an engagement, "AI" decisions with no receipt. We built the substrate that fixes that — CC-BY-4.0, permanent DOI, drops into UDS / Big Bang, running live now. A JAG-defensible flight-data recorder for every kernel decision a drone makes. - -WHAT WE JUST SHIPPED - -/anatomy now embeds a live ops panel polling our amaru sidecar over a read-only proxy: chakras registered, receipts counter, scheduler ticks, bus publishes/failures, HUKLLA T01–T10 with pass/warn/trip dots, R0513 invariants + live kernel/brain hashes, chakana 21-edge lattice with the ouroboros edge in gold. Nothing is mocked — counters increment, tripwires flip, the cycle is visibly the only cycle. Same proxy + allowlist exposes drone-side state to a UDS dashboard with zero new auth. We also pulled the decorative AI hero images. Page shows only what we can prove. - -HOW IT FIXES THE DRONES - -1. Supply-chain integrity. SHA-256 recomputed over every vendored binary on load; one drifted byte and the banner flips red. Sigstore-class proof on the doctrine bundle. Ports as-is into Big Bang / UDS. - -2. Doctrine gate (YUYAY v3). 13-axis conjunctive AND — sacred axes (moralGrounding, measurabilityHonesty, ontologicalGrounding) ≥0.95, rest ≥0.90. No averaging. Technical implementation of DoD 3000.09 human-judgment. - -3. YAWAR receipts. Every evaluation appends a hash-chained receipt (seq, prev_hash, self_hash, params, result). Flight-data recorder for autonomy — replay the exact (input, model, doctrine) after any engagement. - -4. HUKLLA tripwires. T01–T10 cover registration, chain integrity, scheduler progress, wiring acyclicity, bus health, doctrine load, envelope size, proof freshness. Trip → halt. Stops the fleet on a quiet model swap or stale pin. - -5. R0513 OVERWATCH. Six invariants over the live receipt chain (KL drift, joint margin, mid-exec regate, M=0 rigidity, hash integrity, reserved). Read-only — halt stays with HUKLLA, so OVERWATCH is never an SPoF. - -6. Byte-identical replay. Each kernel is ≤10 lines and ships a 5× byte-identical replay SHA-256. After-action review is `python3 test_replay.py` and a hash compare. - -7. Minimization. Kernels are tiny (3.45% absorbed source, 50× reduction). Reviewable code, small SBOM, real audit pre-flight. - -WHAT TO DO WITH IT - -Vendor the bundle into your UDS / Big Bang package (hash self-check ports as-is). Put YUYAY v3 in front of any model emitting an action recommendation. Pipe autonomy decisions through YAWAR. Wire HUKLLA as CI gates AND runtime kill-switches — same definition both places. Adopt byte-identical replay for every kernel in an effects loop. If it can't replay, it can't fly. - -Nothing here is a slide.""" - -FIRST_COMMENT = """Direct links if anyone wants to dig in: - -• Upstream thesis (source of truth): github.com/szl-holdings/ouroboros-thesis -• Concept DOI (always latest): doi.org/10.5281/zenodo.19944926 -• v13 release DOI: doi.org/10.5281/zenodo.20195368 -• Anatomy bundle index (per-figure metadata + sha256 list): docs/anatomy/INDEX.md and docs/anatomy/figures.sha256 in the repo above - -Happy to walk through the in-browser integrity check construction if anyone wants the 30-line walkthrough.""" - -# ---------- DOC ---------- - -doc = Document() -style = doc.styles['Normal'] -style.font.name = 'Calibri' -style.font.size = Pt(11) - -def heading(text, level=1): - h = doc.add_heading(text, level=level) - for r in h.runs: - r.font.color.rgb = RGBColor(0x1A, 0x1A, 0x1A) - -def para(text, bold=False, italic=False, mono=False, size=11): - p = doc.add_paragraph() - r = p.add_run(text) - r.bold = bold - r.italic = italic - r.font.size = Pt(size) - if mono: - r.font.name = 'Consolas' - return p - -def block(text, label, limit_label): - n = len(text) - heading(f"{label} — {n} chars {limit_label}", level=2) - p = doc.add_paragraph() - r = p.add_run(text) - r.font.name = 'Consolas' - r.font.size = Pt(10) - doc.add_paragraph() # spacer - -title = doc.add_heading('LinkedIn post — A11oy /anatomy (CTO-facing, copy-paste pack)', level=0) -for r in title.runs: - r.font.color.rgb = RGBColor(0x1A, 0x1A, 0x1A) - -para( - 'Each block below is plain text, ready to copy directly into LinkedIn. ' - 'LinkedIn rules of thumb: ~140 chars visible in the desktop feed preview, ' - '~210 chars on mobile before the "see more" cut, 3,000 chars hard limit ' - 'on a post, and the first comment is the place to drop links so the ' - 'post body stays clean. Character counts are shown in each section heading.', - italic=True, -) - -heading('1. Above-the-fold hook (desktop preview, ≤140 chars)', 1) -para( - 'Use this as the opening line of the post so what appears before "see more" ' - 'in the desktop feed is the kill-shot. Then paste the FULL POST body below it.', - italic=True, -) -block(HOOK_140, 'HOOK — desktop preview', '(target ≤ 140)') - -heading('2. Above-the-fold hook (mobile, ≤210 chars)', 1) -para( - 'Slightly longer alternative if you care more about the mobile feed than ' - 'the desktop feed.', - italic=True, -) -block(HOOK_210, 'HOOK — mobile fold', '(target ≤ 210)') - -heading('3. FULL POST BODY (≤3,000 chars — LinkedIn hard limit)', 1) -para( - 'This is the main, technical, CTO-facing post. Plain text, no markdown — ' - 'LinkedIn does not render Markdown. Bullet glyphs (•) and arrows (→) ' - 'render fine. Triple-click the block below to select, then copy.', - italic=True, -) -block(POST_FULL, 'FULL POST', '(LinkedIn limit 3,000)') - -heading('4. SHORT POST (≤1,300 chars — higher reach variant)', 1) -para( - 'Use this if you want maximum dwell time / completion rate rather than ' - 'depth. LinkedIn\'s algorithm tends to reward posts read all the way through, ' - 'and shorter posts complete more often.', - italic=True, -) -block(POST_SHORT, 'SHORT POST', '(target ≤ 1,300)') - -doc.add_page_break() -heading('5. WARHACKER appendix — how this fixes the drones', 1) -para( - 'Long-form, CTO/PM-facing explanation of how the anatomy bundle maps onto ' - 'Defense Unicorns\' Warhacker push for accountable software on small UAS. ' - 'Plain text, copy-paste-ready into a LinkedIn article, a UDS / Big Bang ' - 'design doc, or an email to a program manager. References real Warhacker ' - 'context (defenseunicorns.com/warhacker) and concrete bundle primitives.', - italic=True, -) -block(WARHACKER_BODY, 'WARHACKER APPENDIX', '(article-length, no LinkedIn 3,000 limit)') -doc.add_page_break() - -heading('6. Hashtag block (paste at end of post or as first comment)', 1) -block(HASHTAGS, 'HASHTAGS', '') - -heading('7. First comment (link drop — keeps body clean)', 1) -para( - 'LinkedIn deprioritizes posts with external links in the body. Standard ' - 'practice: omit the GitHub/Zenodo URLs from the body and drop them as the ' - 'first comment within ~60 seconds of posting.', - italic=True, -) -block(FIRST_COMMENT, 'FIRST COMMENT', '') - -doc.add_page_break() - -heading('Suggested image stack (carousel order)', 1) -para('1. screenshots/a11oy_anatomy_top.jpg — green "Bundle integrity verified" banner. This is the kill-shot.') -para('2. agent-anatomy/anatomy_brain.png — AMARU cortex / 9-axis doctrine gate.') -para('3. agent-anatomy/anatomy_heart.png — YUYAY v3 13-axis conjunctive AND gate.') -para('4. agent-anatomy/anatomy_skeleton.png — 12-repo service topology.') -para('5. agent-anatomy/anatomy_nervous.png — OTel/VSP span propagation.') -para('6. agent-anatomy/anatomy_body_graph.png — master overlay (the "this is the system" hero).') - -heading('Posting tips', 1) -para('• Post Tue/Wed/Thu between 8–10am in your audience\'s timezone for engineering audiences.') -para('• First 60 seconds matter: drop the first comment with links, like your own post once, share to a relevant company page.') -para('• Reply to every comment in the first 2 hours — LinkedIn\'s algorithm treats comments as a stronger signal than likes.') -para('• If you cross-post: HN title can be sharper — "We made our AI-governance page verify itself with SHA-256 on every load." Lobste.rs: tag as `practices` and `crypto`.') -para('• Do NOT edit the post within the first hour; edits suppress reach.') - -# Print char counts so they show up in the run log too -for lbl, txt in [('HOOK_140', HOOK_140), ('HOOK_210', HOOK_210), ('POST_FULL', POST_FULL), ('POST_SHORT', POST_SHORT), ('FIRST_COMMENT', FIRST_COMMENT), ('HASHTAGS', HASHTAGS)]: - print(f"{lbl}: {len(txt)} chars") - -doc.save('exports/a11oy_anatomy_linkedin_post.docx') -print('wrote exports/a11oy_anatomy_linkedin_post.docx') diff --git a/kipu_qillqaq/__init__.py b/kipu_qillqaq/__init__.py deleted file mode 100644 index 15b6c5bb02f888eb5321c60469141188a5def25f..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/__init__.py +++ /dev/null @@ -1,40 +0,0 @@ -"""kipu_qillqaq — KIPU receipt-cell substrate + QILLQAQ genome (config + module loading) engine. - -HONEST NAMING (no mysticism): - * KIPU is a content-addressed receipt-cell pool with LMDB (or JSON-file fallback) - persistence, an in-process pub/sub event bus, and Reed-Solomon erasure coding for - durability. It is NOT "holographic QEC". Reed-Solomon is the well-understood MDS - erasure code used by RAID-6, CD/DVD, QR codes, and Backblaze. See coding.py. - * QILLQAQ is a declarative engine: it reads organ `genome.toml` files (parsed with the - stdlib `tomllib`), validates them against a schema, and boots `OrganAgent` instances. - "DNA" here is shorthand for *config*; "boot from DNA" means *parse config + load a - module/handler*. There is no biology and no magic. - -Author: Yachay (SZL Holdings). License: Apache-2.0. -""" - -__version__ = "0.1.0" - -from .cell import ReceiptCell, content_address -from .coding import ReedSolomonCoder, decode_shards, encode_cell -from .events import EventBus -from .genome import Genome, GenomeError, load_genome, validate_genome -from .pool import KipuPool -from .transcribe import OrganAgent, QillqaqEngine - -__all__ = [ - "__version__", - "ReceiptCell", - "content_address", - "KipuPool", - "EventBus", - "ReedSolomonCoder", - "encode_cell", - "decode_shards", - "Genome", - "GenomeError", - "load_genome", - "validate_genome", - "OrganAgent", - "QillqaqEngine", -] diff --git a/kipu_qillqaq/cell.py b/kipu_qillqaq/cell.py deleted file mode 100644 index d1d825ce36e9c5d7971b362da0ace04000f994b7..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/cell.py +++ /dev/null @@ -1,83 +0,0 @@ -"""ReceiptCell — a content-addressed receipt (a "knot" in the KIPU). - -A ReceiptCell is an immutable record of one act: who wrote it, what organ, what kind of -receipt, the payload, the timestamp, and an optional pointer to parent cells (forming a -content-addressed DAG like git/IPLD). The content address is the SHA-256 of the canonical -JSON of the cell's *content* fields (everything except the address itself). -""" - -from __future__ import annotations - -import hashlib -import json -import time -from dataclasses import asdict, dataclass, field -from typing import Any - - -def _canonical(obj: Any) -> bytes: - """Deterministic JSON encoding for hashing (sorted keys, no whitespace drift).""" - return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8") - - -def content_address(content: dict) -> str: - """SHA-256 hex content address of a cell's content dict. Pure function.""" - return hashlib.sha256(_canonical(content)).hexdigest() - - -@dataclass(frozen=True) -class ReceiptCell: - """An immutable, content-addressed receipt cell. - - `cid` is derived from the content fields and is the cell's identity in the pool. - """ - - organ: str - kind: str - payload: dict - author: str = "Yachay" - ts: float = field(default_factory=lambda: time.time()) - parents: tuple = () # tuple of parent CIDs -> DAG edges - cid: str = "" # filled in __post_init__ - - def __post_init__(self): - if not self.cid: - object.__setattr__(self, "cid", content_address(self._content())) - - def _content(self) -> dict: - return { - "organ": self.organ, - "kind": self.kind, - "payload": self.payload, - "author": self.author, - "ts": self.ts, - "parents": list(self.parents), - } - - def verify(self) -> bool: - """Chain-verify: recompute the content address and compare. True iff intact.""" - return self.cid == content_address(self._content()) - - def to_dict(self) -> dict: - d = asdict(self) - d["parents"] = list(self.parents) - return d - - @classmethod - def from_dict(cls, d: dict) -> "ReceiptCell": - return cls( - organ=d["organ"], - kind=d["kind"], - payload=d["payload"], - author=d.get("author", "Yachay"), - ts=d["ts"], - parents=tuple(d.get("parents", ())), - cid=d.get("cid", ""), - ) - - def to_bytes(self) -> bytes: - return _canonical(self.to_dict()) - - @classmethod - def from_bytes(cls, b: bytes) -> "ReceiptCell": - return cls.from_dict(json.loads(b.decode("utf-8"))) diff --git a/kipu_qillqaq/coding.py b/kipu_qillqaq/coding.py deleted file mode 100644 index 6cf5fed30f4e87377d4696fd6de46a5af5d8da50..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/coding.py +++ /dev/null @@ -1,185 +0,0 @@ -"""Reed-Solomon erasure coding for KIPU receipt-cell durability. - -HONEST NAMING: this is Reed-Solomon (Reed & Solomon, 1960) — the same MDS erasure code -used by RAID-6, CD/DVD/Blu-ray, QR codes, and Backblaze's storage pods. It is NOT -"holographic quantum error correction". An (n, k) RS code splits data into k data shards -plus (n-k) parity shards; ANY k of the n shards reconstruct the original. We default to -RS(10, 6): 6 data + 4 parity, surviving loss of any 4 of 10 shards (40% loss tolerance). - -Implementation strategy (open-source only, graceful): - * If the `reedsolo` package is installed, use it (battle-tested GF(2^8) RS). - * Otherwise use a self-contained pure-Python RS over GF(2^8) implemented here so the - package works with zero non-stdlib deps. Same (n, k) semantics either way. -""" - -from __future__ import annotations - -from typing import Optional - -# --------------------------------------------------------------------------- -# GF(2^8) arithmetic (pure-python fallback), primitive polynomial 0x11d. -# --------------------------------------------------------------------------- -_EXP = [0] * 512 -_LOG = [0] * 256 - - -def _init_tables() -> None: - x = 1 - for i in range(255): - _EXP[i] = x - _LOG[x] = i - x <<= 1 - if x & 0x100: - x ^= 0x11D - for i in range(255, 512): - _EXP[i] = _EXP[i - 255] - - -_init_tables() - - -def _gf_mul(a: int, b: int) -> int: - if a == 0 or b == 0: - return 0 - return _EXP[_LOG[a] + _LOG[b]] - - -def _gf_div(a: int, b: int) -> int: - if b == 0: - raise ZeroDivisionError("GF division by zero") - if a == 0: - return 0 - return _EXP[(_LOG[a] - _LOG[b]) % 255] - - -class _PureRS: - """Minimal systematic RS(n,k) over GF(2^8) using a Vandermonde parity matrix. - - Encodes per-byte across k data shards into (n-k) parity shards. Decodes by solving the - linear system over GF(2^8) for any k available shards (data or parity). MDS: any k of n - suffice. This is a clean, dependency-free reference implementation. - """ - - def __init__(self, n: int, k: int): - if not (0 < k < n <= 255): - raise ValueError("require 0 < k < n <= 255") - self.n, self.k = n, k - # Vandermonde matrix V[i][j] = (i+1)^j for i in [0, n), j in [0, k). - # Rows 0..k-1 used as-is is NOT identity, so we keep full Vandermonde and solve - # generally on decode (no systematic assumption needed for correctness). - self.V = [[_gf_pow(i + 1, j) for j in range(k)] for i in range(n)] - - def encode(self, data_shards: list[bytes]) -> list[bytes]: - assert len(data_shards) == self.k - length = len(data_shards[0]) - assert all(len(s) == length for s in data_shards) - out = [bytearray(length) for _ in range(self.n)] - for pos in range(length): - col = [data_shards[j][pos] for j in range(self.k)] - for i in range(self.n): - acc = 0 - row = self.V[i] - for j in range(self.k): - acc ^= _gf_mul(row[j], col[j]) - out[i][pos] = acc - return [bytes(b) for b in out] - - def decode(self, shards: list[Optional[bytes]]) -> list[bytes]: - """shards: list of length n; None = lost. Returns reconstructed k data shards.""" - present = [(i, s) for i, s in enumerate(shards) if s is not None] - if len(present) < self.k: - raise ValueError(f"need >= {self.k} shards, have {len(present)}") - idx = [i for i, _ in present[: self.k]] - sub = [self.V[i][:] for i in idx] - length = len(present[0][1]) - recovered = [bytearray(length) for _ in range(self.k)] - for pos in range(length): - vec = [present[t][1][pos] for t in range(self.k)] - sol = _solve_gf(sub, vec) - for j in range(self.k): - recovered[j][pos] = sol[j] - return [bytes(b) for b in recovered] - - -def _gf_pow(a: int, p: int) -> int: - r = 1 - for _ in range(p): - r = _gf_mul(r, a) - return r - - -def _solve_gf(matrix: list[list[int]], vec: list[int]) -> list[int]: - """Gaussian elimination over GF(2^8). matrix is k x k, vec length k.""" - k = len(vec) - m = [row[:] + [vec[i]] for i, row in enumerate(matrix)] - for col in range(k): - piv = next((r for r in range(col, k) if m[r][col] != 0), None) - if piv is None: - raise ValueError("singular matrix") - m[col], m[piv] = m[piv], m[col] - inv = _gf_div(1, m[col][col]) - m[col] = [_gf_mul(x, inv) for x in m[col]] - for r in range(k): - if r != col and m[r][col] != 0: - f = m[r][col] - m[r] = [a ^ _gf_mul(f, b) for a, b in zip(m[r], m[col])] - return [m[i][k] for i in range(k)] - - -class ReedSolomonCoder: - """(n, k) Reed-Solomon erasure coder. Default RS(10, 6) -> tolerate 4/10 lost.""" - - def __init__(self, n: int = 10, k: int = 6): - self.n, self.k = n, k - self._backend = "pure" - self._impl = _PureRS(n, k) - try: - import reedsolo # type: ignore # noqa: F401 - - self._backend = "reedsolo" - except Exception: - pass - - @property - def backend(self) -> str: - return self._backend - - def _split(self, data: bytes) -> tuple[list[bytes], int]: - orig_len = len(data) - shard_len = (orig_len + self.k - 1) // self.k - padded = data + b"\x00" * (shard_len * self.k - orig_len) - shards = [padded[i * shard_len : (i + 1) * shard_len] for i in range(self.k)] - return shards, orig_len - - def encode(self, data: bytes) -> tuple[list[bytes], int]: - """Return (n shards, original_length). Reconstruct from any k shards.""" - data_shards, orig_len = self._split(data) - all_shards = self._impl.encode(data_shards) - return all_shards, orig_len - - def decode(self, shards: list[Optional[bytes]], orig_len: int) -> bytes: - data_shards = self._impl.decode(shards) - return b"".join(data_shards)[:orig_len] - - -def encode_cell(cell_bytes: bytes, n: int = 10, k: int = 6) -> dict: - """Encode a serialized cell into RS shards. Returns a portable shard manifest.""" - coder = ReedSolomonCoder(n, k) - shards, orig_len = coder.encode(cell_bytes) - return { - "code": f"RS({n},{k})", - "backend": coder.backend, - "orig_len": orig_len, - "n": n, - "k": k, - "loss_tolerance": (n - k) / n, - "shards": [s.hex() for s in shards], - } - - -def decode_shards(manifest: dict) -> bytes: - """Reconstruct original cell bytes from a shard manifest with up to (n-k) losses.""" - n, k = manifest["n"], manifest["k"] - coder = ReedSolomonCoder(n, k) - shards = [bytes.fromhex(s) if s is not None else None for s in manifest["shards"]] - return coder.decode(shards, manifest["orig_len"]) diff --git a/kipu_qillqaq/events.py b/kipu_qillqaq/events.py deleted file mode 100644 index 72f851fdc4df6e6d8cee7111d5249ee15c64019d..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/events.py +++ /dev/null @@ -1,45 +0,0 @@ -"""EventBus — a minimal in-process publish/subscribe event bus. - -No external broker. Subscribers register a callback for a topic (or "*" for all). When the -pool commits a cell it publishes a ("write", cell) event; reads publish ("read", cid). -This is the pub/sub layer of the KIPU substrate — organs subscribe to react to each -other's receipts without polling. -""" - -from __future__ import annotations - -import threading -from collections import defaultdict -from typing import Any, Callable - - -class EventBus: - def __init__(self) -> None: - self._subs: dict[str, list[Callable[[str, Any], None]]] = defaultdict(list) - self._lock = threading.RLock() - - def subscribe(self, topic: str, callback: Callable[[str, Any], None]) -> Callable[[], None]: - """Register `callback(topic, payload)`. Returns an unsubscribe function.""" - with self._lock: - self._subs[topic].append(callback) - - def _unsub() -> None: - with self._lock: - if callback in self._subs[topic]: - self._subs[topic].remove(callback) - - return _unsub - - def publish(self, topic: str, payload: Any) -> int: - """Deliver to subscribers of `topic` and of "*". Returns count delivered.""" - with self._lock: - targets = list(self._subs.get(topic, [])) + list(self._subs.get("*", [])) - n = 0 - for cb in targets: - try: - cb(topic, payload) - n += 1 - except Exception: - # A misbehaving subscriber must not break the bus. - pass - return n diff --git a/kipu_qillqaq/genome.py b/kipu_qillqaq/genome.py deleted file mode 100644 index 4647cfe1061d386b990cf617933d6b00111f5d70..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/genome.py +++ /dev/null @@ -1,110 +0,0 @@ -"""QILLQAQ genome — declarative organ config parsed with stdlib `tomllib`. - -HONEST NAMING: a "genome" here is a TOML config file describing an organ's identity, the -receipt KINDS it is allowed to read/write on the KIPU substrate, and which Python handler -(module:callable) implements its loop. "Boot from DNA" = parse TOML + import a module. -No biology, no magic. tomllib is the Python 3.11+ standard library TOML parser. - -Schema (validated below): - [organ] name (str, required), quechua (str), function (str, required) - [role] loop (str, required) -- human description of the organ's loop - [reads] kinds (list[str], required) -- receipt KINDS this organ may read - [writes] kinds (list[str], required) -- receipt KINDS this organ may write - [boot] handler (str "module:callable", required), enabled (bool, default true) - [meta] any free-form table (optional) -""" - -from __future__ import annotations - -from dataclasses import dataclass, field -from pathlib import Path -from typing import Any - -import tomllib - - -class GenomeError(ValueError): - """Raised when a genome.toml fails schema validation.""" - - -@dataclass -class Genome: - name: str - quechua: str - function: str - loop: str - reads: list[str] - writes: list[str] - handler: str # "module:callable" - enabled: bool = True - meta: dict = field(default_factory=dict) - raw: dict = field(default_factory=dict) - - def may_write(self, kind: str) -> bool: - return kind in self.writes - - def may_read(self, kind: str) -> bool: - return kind in self.reads - - -def _require(table: dict, key: str, typ: type, where: str) -> Any: - if key not in table: - raise GenomeError(f"[{where}] missing required key '{key}'") - val = table[key] - if not isinstance(val, typ): - raise GenomeError(f"[{where}] key '{key}' must be {typ.__name__}, got {type(val).__name__}") - return val - - -def validate_genome(data: dict) -> Genome: - """Validate a parsed TOML dict against the genome schema. Returns a Genome or raises.""" - if "organ" not in data: - raise GenomeError("missing [organ] table") - organ = data["organ"] - name = _require(organ, "name", str, "organ") - function = _require(organ, "function", str, "organ") - quechua = organ.get("quechua", "") - - if "role" not in data: - raise GenomeError("missing [role] table") - loop = _require(data["role"], "loop", str, "role") - - if "reads" not in data: - raise GenomeError("missing [reads] table") - reads = _require(data["reads"], "kinds", list, "reads") - if not all(isinstance(x, str) for x in reads): - raise GenomeError("[reads] kinds must be a list of strings") - - if "writes" not in data: - raise GenomeError("missing [writes] table") - writes = _require(data["writes"], "kinds", list, "writes") - if not all(isinstance(x, str) for x in writes): - raise GenomeError("[writes] kinds must be a list of strings") - - if "boot" not in data: - raise GenomeError("missing [boot] table") - handler = _require(data["boot"], "handler", str, "boot") - if ":" not in handler: - raise GenomeError("[boot] handler must be 'module:callable'") - enabled = bool(data["boot"].get("enabled", True)) - - return Genome( - name=name, - quechua=quechua, - function=function, - loop=loop, - reads=reads, - writes=writes, - handler=handler, - enabled=enabled, - meta=data.get("meta", {}), - raw=data, - ) - - -def load_genome(path: str | Path) -> Genome: - """Parse a genome.toml file with tomllib and validate it. Returns a Genome.""" - p = Path(path) - with open(p, "rb") as f: - data = tomllib.load(f) - return validate_genome(data) diff --git a/kipu_qillqaq/handlers.py b/kipu_qillqaq/handlers.py deleted file mode 100644 index a18411d55413671a41238d2fe8159f2d199c238d..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/handlers.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Default reference handlers for OrganAgents. - -A genome's [boot] handler points at "module:callable". For organs whose real runtime code -lives elsewhere (amaru/, rosie/, sentra/ repos), the genome can point at one of these -generic reference handlers so the agent has a working, gated step() out of the box. - -Each handler receives the bound OrganAgent and returns a dict summary of what it did. They -only ever write receipt KINDS the genome authorizes (the OrganAgent.write() gate enforces -this), so a handler cannot exceed its declared role. -""" - -from __future__ import annotations - -import time - - -def echo(agent, message: str = "alive") -> dict: - """Write a single heartbeat receipt of the organ's first authorized write-kind.""" - kind = agent.genome.writes[0] - cid = agent.write(kind, {"message": message, "ts": time.time()}) - return {"organ": agent.genome.name, "wrote_kind": kind, "cid": cid} - - -def reconcile(agent) -> dict: - """No-op reconcile: report current authorization surface. Writes nothing.""" - return { - "organ": agent.genome.name, - "reads": agent.genome.reads, - "writes": agent.genome.writes, - "reconciled": True, - } diff --git a/kipu_qillqaq/pool.py b/kipu_qillqaq/pool.py deleted file mode 100644 index 1caf91ffa317622bdf67beac89443f1dd2fb6781..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/pool.py +++ /dev/null @@ -1,137 +0,0 @@ -"""KipuPool — the shared, content-addressed receipt-cell substrate. - -Every organ reads/writes ReceiptCells here. Each write: - 1. computes/verifies the content address (cid), - 2. persists the cell (LMDB if available, else a JSON-file store — same API), - 3. optionally stores a Reed-Solomon shard manifest for durability, - 4. publishes a ("write", cell) event on the in-process EventBus. - -Each read publishes a ("read", cid) event and emits a read-receipt cell, so there is no -silent access. This is a Linda-style tuple space + event sourcing + content addressing. -HONEST: durability is Reed-Solomon erasure coding, not "holographic QEC". -""" - -from __future__ import annotations - -import json -import os -import threading -from pathlib import Path -from typing import Iterable, Optional - -from .cell import ReceiptCell -from .coding import decode_shards, encode_cell -from .events import EventBus - - -class _Store: - """Key-value persistence: LMDB backend if installed, else JSON-file fallback.""" - - def __init__(self, path: str): - self.path = path - self.backend = "json" - self._lmdb = None - self._lock = threading.RLock() - try: - import lmdb # type: ignore - - os.makedirs(path, exist_ok=True) - self._lmdb = lmdb.open(path, map_size=256 * 1024 * 1024) - self.backend = "lmdb" - except Exception: - self._file = Path(path) - self._file.parent.mkdir(parents=True, exist_ok=True) - if not self._file.exists(): - self._file.write_text("{}") - - def put(self, key: str, value: bytes) -> None: - with self._lock: - if self.backend == "lmdb": - with self._lmdb.begin(write=True) as txn: - txn.put(key.encode(), value) - else: - d = json.loads(self._file.read_text()) - d[key] = value.decode("utf-8") - self._file.write_text(json.dumps(d)) - - def get(self, key: str) -> Optional[bytes]: - with self._lock: - if self.backend == "lmdb": - with self._lmdb.begin() as txn: - v = txn.get(key.encode()) - return bytes(v) if v is not None else None - d = json.loads(self._file.read_text()) - v = d.get(key) - return v.encode("utf-8") if v is not None else None - - def keys(self) -> Iterable[str]: - with self._lock: - if self.backend == "lmdb": - with self._lmdb.begin() as txn: - return [k.decode() for k, _ in txn.cursor()] - return list(json.loads(self._file.read_text()).keys()) - - -class KipuPool: - """The shared receipt-cell substrate.""" - - def __init__(self, path: str = "/tmp/kipu", durability: bool = True, - rs_n: int = 10, rs_k: int = 6): - self.bus = EventBus() - self._cells = _Store(os.path.join(path, "cells")) - self._shards = _Store(os.path.join(path, "shards")) - self.durability = durability - self.rs_n, self.rs_k = rs_n, rs_k - - @property - def store_backend(self) -> str: - return self._cells.backend - - def write(self, cell: ReceiptCell) -> str: - """Persist a cell, optionally RS-encode it, publish a write event. Returns cid.""" - if not cell.verify(): - raise ValueError("ReceiptCell failed content-address verification") - cb = cell.to_bytes() - self._cells.put(cell.cid, cb) - if self.durability: - manifest = encode_cell(cb, self.rs_n, self.rs_k) - self._shards.put(cell.cid, json.dumps(manifest).encode()) - self.bus.publish("write", cell) - self.bus.publish(f"organ:{cell.organ}", cell) - return cell.cid - - def read(self, cid: str, reader: str = "anon", emit_receipt: bool = True) -> Optional[ReceiptCell]: - """Read a cell by cid. Publishes a read event and (optionally) a read-receipt.""" - raw = self._cells.get(cid) - cell = ReceiptCell.from_bytes(raw) if raw is not None else None - self.bus.publish("read", {"cid": cid, "reader": reader, "hit": cell is not None}) - if emit_receipt and cell is not None: - rr = ReceiptCell(organ=reader, kind="read_receipt", - payload={"read_cid": cid}, parents=(cid,)) - self._cells.put(rr.cid, rr.to_bytes()) - return cell - - def recover(self, cid: str, drop: Optional[list[int]] = None) -> Optional[ReceiptCell]: - """Recover a cell from its Reed-Solomon shards, optionally simulating lost shards.""" - raw = self._shards.get(cid) - if raw is None: - return None - manifest = json.loads(raw.decode()) - if drop: - shards = list(manifest["shards"]) - for i in drop: - shards[i] = None - manifest = {**manifest, "shards": shards} - cb = decode_shards(manifest) - return ReceiptCell.from_bytes(cb) - - def all_cids(self) -> list[str]: - return list(self._cells.keys()) - - def stats(self) -> dict: - return { - "store_backend": self._cells.backend, - "cells": len(list(self._cells.keys())), - "durability": self.durability, - "rs_code": f"RS({self.rs_n},{self.rs_k})", - } diff --git a/kipu_qillqaq/transcribe.py b/kipu_qillqaq/transcribe.py deleted file mode 100644 index 9622b3c6275801ad42c9c48cd45a92e6ea2ac4a4..0000000000000000000000000000000000000000 --- a/kipu_qillqaq/transcribe.py +++ /dev/null @@ -1,123 +0,0 @@ -"""QILLQAQ transcription engine — boot OrganAgents from declarative genome.toml files. - -HONEST NAMING: "transcription" = read TOML config, import a handler module, instantiate an -agent. "boot from DNA" = config-driven module loading (like a plugin registry or a -Kubernetes operator reconciling a CRD). No biology. - -An OrganAgent: - * holds its Genome (the validated config), - * is bound to a shared KipuPool, - * exposes write()/read() that are GATED by the genome's allowed receipt kinds, - * runs its handler (a module:callable) when stepped, if one resolves. - -If a handler module cannot be imported (e.g. the organ's real code isn't present), the -agent still boots in "declared" mode: it can read/write receipts but has no step logic. -This keeps the engine usable as pure substrate wiring without every organ's code on path. -""" - -from __future__ import annotations - -import importlib -from pathlib import Path -from typing import Callable, Optional - -from .cell import ReceiptCell -from .genome import Genome, GenomeError, load_genome -from .pool import KipuPool - - -class OrganAgent: - def __init__(self, genome: Genome, pool: KipuPool): - self.genome = genome - self.pool = pool - self.handler: Optional[Callable] = None - self.handler_status = "unbound" - self._resolve_handler() - - def _resolve_handler(self) -> None: - mod_name, _, attr = self.genome.handler.partition(":") - try: - mod = importlib.import_module(mod_name) - self.handler = getattr(mod, attr) - self.handler_status = "bound" - except Exception as e: - self.handler = None - self.handler_status = f"declared (handler import failed: {type(e).__name__})" - - def write(self, kind: str, payload: dict, parents: tuple = ()) -> str: - if not self.genome.may_write(kind): - raise PermissionError( - f"organ '{self.genome.name}' genome does not authorize writing kind '{kind}' " - f"(allowed: {self.genome.writes})" - ) - cell = ReceiptCell(organ=self.genome.name, kind=kind, payload=payload, parents=parents) - return self.pool.write(cell) - - def read(self, cid: str) -> Optional[ReceiptCell]: - cell = self.pool.read(cid, reader=self.genome.name) - if cell is not None and not self.genome.may_read(cell.kind): - raise PermissionError( - f"organ '{self.genome.name}' genome does not authorize reading kind '{cell.kind}' " - f"(allowed: {self.genome.reads})" - ) - return cell - - def step(self, *args, **kwargs): - """Invoke the bound handler if present. Handler signature: handler(agent, *a, **k).""" - if self.handler is None: - return None - return self.handler(self, *args, **kwargs) - - def info(self) -> dict: - return { - "name": self.genome.name, - "quechua": self.genome.quechua, - "function": self.genome.function, - "reads": self.genome.reads, - "writes": self.genome.writes, - "handler": self.genome.handler, - "handler_status": self.handler_status, - "enabled": self.genome.enabled, - } - - -class QillqaqEngine: - """Reads a directory of genome.toml files and boots an OrganAgent for each.""" - - def __init__(self, pool: Optional[KipuPool] = None): - self.pool = pool or KipuPool() - self.agents: dict[str, OrganAgent] = {} - self.errors: dict[str, str] = {} - - def boot_file(self, path: str | Path) -> Optional[OrganAgent]: - try: - genome = load_genome(path) - except GenomeError as e: - self.errors[str(path)] = str(e) - return None - if not genome.enabled: - return None - agent = OrganAgent(genome, self.pool) - self.agents[genome.name] = agent - return agent - - def boot_dir(self, directory: str | Path, pattern: str = "*.toml") -> dict[str, OrganAgent]: - """Boot every genome file in a directory. Returns {organ_name: agent}.""" - d = Path(directory) - for f in sorted(d.glob(pattern)): - self.boot_file(f) - return self.agents - - def boot_packaged(self) -> dict[str, OrganAgent]: - """Boot the genome.toml files bundled inside the installed package.""" - here = Path(__file__).parent / "genomes" - return self.boot_dir(here) - - def manifest(self) -> dict: - return { - "engine": "QILLQAQ", - "pool": self.pool.stats(), - "organs": {name: a.info() for name, a in self.agents.items()}, - "errors": self.errors, - "count": len(self.agents), - } diff --git a/packages/inference/__init__.py b/packages/inference/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/packages/inference/src/__init__.py b/packages/inference/src/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/packages/inference/src/voters/__init__.py b/packages/inference/src/voters/__init__.py deleted file mode 100644 index 36d4f1a7257c0413d271600577bf6315383c119b..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/__init__.py +++ /dev/null @@ -1,117 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -voters/__init__.py — Registry of all 13 a11oy v4 ensemble voters. - -Sovereign-default: qwen-local is ALWAYS first and never removed. -Cloud voters: off by default, activate via env var + explicit voters list. -""" -from __future__ import annotations - -from typing import Dict, List - -from .base_voter import BaseVoter, VOTER_INPUT_SCHEMA, VOTER_OUTPUT_SCHEMA - -# ── Existing 4 voters ───────────────────────────────────────────────────────── -from .qwen_local import QwenLocalVoter -from .hf_inference_voter import ( - HFInferenceLlamaVoter, - HFInferenceMistralVoter, - HFInferenceQwenVoter, -) - -# ── 9 new voters (feat/llm-roster-expansion-9-voters) ──────────────────────── -from .deepseek_r1 import DeepSeekR1Voter -from .kimi_k2 import KimiK2Voter -from .glm_4_6 import GLM46Voter -from .hermes_4_405b import Hermes4405BVoter -from .minimax_m2 import MiniMaxM2Voter -from .step_3_7_flash import Step37FlashVoter -from .nomos_1 import Nomos1Voter -from .nemotron_super_49b import NemotronSuper49BVoter -from .xiaomi_mimo import XiaomiMiMoVoter - -# Ordered: sovereign-default first, then existing HF voters, then 9 new voters -_ALL_VOTER_INSTANCES: List[BaseVoter] = [ - QwenLocalVoter(), # sovereign-default: always in pool - HFInferenceLlamaVoter(), - HFInferenceMistralVoter(), - HFInferenceQwenVoter(), - # --- 9 new voters --- - DeepSeekR1Voter(), - KimiK2Voter(), - GLM46Voter(), - Hermes4405BVoter(), - MiniMaxM2Voter(), - Step37FlashVoter(), - Nomos1Voter(), - NemotronSuper49BVoter(), - XiaomiMiMoVoter(), -] - -_VOTER_MAP: Dict[str, BaseVoter] = {v.VOTER_ID: v for v in _ALL_VOTER_INSTANCES} - -VOTER_COUNT = len(_ALL_VOTER_INSTANCES) # 13 - - -def get_all_voters() -> List[BaseVoter]: - """Return all 13 registered voter instances.""" - return list(_ALL_VOTER_INSTANCES) - - -def get_voter(voter_id: str) -> BaseVoter | None: - """Look up a voter by ID.""" - return _VOTER_MAP.get(voter_id) - - -def resolve_voters(requested: List[str] | None) -> List[BaseVoter]: - """Return voters to run for a given request. - - If `requested` is None/empty → only qwen-local (sovereign-default). - Otherwise → intersection of requested IDs with the registry, preserving order. - qwen-local is always prepended as the sovereign floor. - """ - sovereign = _VOTER_MAP["qwen-local"] - if not requested: - return [sovereign] - out: List[BaseVoter] = [] - seen = set() - # sovereign-default always first - out.append(sovereign) - seen.add("qwen-local") - for vid in requested: - if vid in seen: - continue - voter = _VOTER_MAP.get(vid) - if voter is not None: - out.append(voter) - seen.add(vid) - return out - - -__all__ = [ - "BaseVoter", - "VOTER_INPUT_SCHEMA", - "VOTER_OUTPUT_SCHEMA", - "VOTER_COUNT", - "get_all_voters", - "get_voter", - "resolve_voters", - # Individual voter classes - "QwenLocalVoter", - "HFInferenceLlamaVoter", - "HFInferenceMistralVoter", - "HFInferenceQwenVoter", - "DeepSeekR1Voter", - "KimiK2Voter", - "GLM46Voter", - "Hermes4405BVoter", - "MiniMaxM2Voter", - "Step37FlashVoter", - "Nomos1Voter", - "NemotronSuper49BVoter", - "XiaomiMiMoVoter", -] diff --git a/packages/inference/src/voters/base_voter.py b/packages/inference/src/voters/base_voter.py deleted file mode 100644 index f67518e2d11f99947eae9854f04e8dc88b3825fb..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/base_voter.py +++ /dev/null @@ -1,187 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 -# Doctrine v11 LOCKED 749/14/163. Λ = Conjecture 1 (NOT a theorem; 163 sorries). -# Authored by Yachay (CTO). DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -base_voter.py — Abstract base class for all a11oy v4 multi-LLM ensemble voters. - -Every voter MUST: - - Declare a VOTER_ID (str), ENV_VARS (list[str]), LICENSE, PROVIDER, CONTEXT_WINDOW - - Implement _call(prompt, **kwargs) -> str (raw model text completion) - - Never fabricate a response when unavailable; return {status: "unavailable"} instead. - -Voter is OFF by default. Only activates when: - 1. Caller explicitly lists it in the `voters` field of /agent/ask - 2. At least one of its ENV_VARS is present in os.environ - -Λ-aggregator: untouched (Conjecture 1, 163 sorries). Provenance entries appended. -""" -from __future__ import annotations - -import abc -import asyncio -import os -import time -from typing import Any, Dict, List, Optional - - -# --------------------------------------------------------------------------- -# JSON Schema for voter input/output (additionalProperties: false) -# --------------------------------------------------------------------------- - -VOTER_INPUT_SCHEMA: Dict[str, Any] = { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "title": "VoterInput", - "required": ["prompt"], - "additionalProperties": False, - "properties": { - "prompt": {"type": "string", "description": "The user prompt to route to this voter."}, - "system": {"type": "string", "description": "Optional system prompt override."}, - "max_tokens": {"type": "integer", "default": 512, "minimum": 1, "maximum": 8192}, - "temperature": {"type": "number", "default": 0.7, "minimum": 0.0, "maximum": 2.0}, - }, -} - -VOTER_OUTPUT_SCHEMA: Dict[str, Any] = { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "title": "VoterOutput", - "additionalProperties": False, - "properties": { - "voter_id": {"type": "string"}, - "status": {"type": "string", "enum": ["ok", "unavailable", "error"]}, - "text": {"type": ["string", "null"]}, - "reason": {"type": ["string", "null"]}, - "latency_ms": {"type": ["number", "null"]}, - "provenance": { - "type": "object", - "additionalProperties": False, - "properties": { - "provider": {"type": "string"}, - "model_id": {"type": "string"}, - "license": {"type": "string"}, - "env_var_used": {"type": ["string", "null"]}, - "timestamp_utc": {"type": "string"}, - }, - }, - }, -} - - -class BaseVoter(abc.ABC): - """Abstract base voter for the a11oy v4 multi-LLM ensemble.""" - - # Subclasses MUST override: - VOTER_ID: str = "" - ENV_VARS: List[str] = [] # First present one is used - LICENSE: str = "" - PROVIDER: str = "" - CONTEXT_WINDOW: int = 4096 - MODEL_ID: str = "" - BFCL_SCORE: Optional[str] = None # e.g. "#1" or None - - def is_available(self) -> bool: - """True iff at least one required env var is present.""" - return any(os.environ.get(v) for v in self.ENV_VARS) - - def _active_env_var(self) -> Optional[str]: - """Return the first present env var name (not the value).""" - for v in self.ENV_VARS: - if os.environ.get(v): - return v - return None - - @abc.abstractmethod - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - """Perform the actual LLM call. Must return a non-empty string. - Raise any exception on failure; the wrapper handles it. - """ - ... - - async def vote( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> Dict[str, Any]: - """Entry point called by the aggregator. Never raises. - - If the env var is missing → returns {status: "unavailable"}. - If the call fails → returns {status: "error"}. - If success → returns {status: "ok", text: }. - """ - import datetime - - env_var_used = self._active_env_var() - provenance = { - "provider": self.PROVIDER, - "model_id": self.MODEL_ID, - "license": self.LICENSE, - "env_var_used": env_var_used, - "timestamp_utc": datetime.datetime.now(datetime.timezone.utc).isoformat().replace("+00:00", "Z"), - } - - if not self.is_available(): - return { - "voter_id": self.VOTER_ID, - "status": "unavailable", - "text": None, - "reason": ( - f"token_not_present — none of {self.ENV_VARS} found in runtime env; " - "set the env var to activate this voter." - ), - "latency_ms": None, - "provenance": provenance, - } - - t0 = time.monotonic() - try: - text = await self._call( - prompt=prompt, - system=system, - max_tokens=max_tokens, - temperature=temperature, - **kwargs, - ) - return { - "voter_id": self.VOTER_ID, - "status": "ok", - "text": text, - "reason": None, - "latency_ms": round((time.monotonic() - t0) * 1000, 1), - "provenance": provenance, - } - except Exception as exc: - return { - "voter_id": self.VOTER_ID, - "status": "error", - "text": None, - "reason": f"{type(exc).__name__}: {exc}", - "latency_ms": round((time.monotonic() - t0) * 1000, 1), - "provenance": provenance, - } - - def metadata(self) -> Dict[str, Any]: - """Return voter metadata for /agent/voters endpoint.""" - avail = self.is_available() - return { - "voter_id": self.VOTER_ID, - "status": "available" if avail else "token_required", - "provider": self.PROVIDER, - "license": self.LICENSE, - "context_window": self.CONTEXT_WINDOW, - "bfcl_score": self.BFCL_SCORE, - "env_vars": self.ENV_VARS, - "model_id": self.MODEL_ID, - } diff --git a/packages/inference/src/voters/deepseek_r1.py b/packages/inference/src/voters/deepseek_r1.py deleted file mode 100644 index f69c073a6e22b37b54f062545fc744cc535b904f..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/deepseek_r1.py +++ /dev/null @@ -1,80 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -deepseek_r1.py — DeepSeek-R1 voter. - -Backend: DeepSeek API (primary) or HF Inference (secondary). -Env vars: DEEPSEEK_API_KEY or HF_TOKEN. -Off by default — activate by listing "deepseek-r1" in voters and having the env var. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class DeepSeekR1Voter(BaseVoter): - VOTER_ID = "deepseek-r1" - ENV_VARS = ["DEEPSEEK_API_KEY", "HF_TOKEN"] - LICENSE = "MIT (open weights)" - PROVIDER = "DeepSeek API / HuggingFace Inference" - CONTEXT_WINDOW = 65536 - MODEL_ID = "deepseek-ai/DeepSeek-R1" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - deepseek_key = os.environ.get("DEEPSEEK_API_KEY") - if deepseek_key: - # DeepSeek API (OpenAI-compat) - url = "https://api.deepseek.com/v1/chat/completions" - headers = { - "Authorization": f"Bearer {deepseek_key}", - "Content-Type": "application/json", - } - payload = { - "model": "deepseek-reasoner", - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - else: - # Fallback: HF Inference API - hf_token = os.environ.get("HF_TOKEN", "") - url = "https://api-inference.huggingface.co/v1/chat/completions" - headers = { - "Authorization": f"Bearer {hf_token}", - "Content-Type": "application/json", - } - payload = { - "model": self.MODEL_ID, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - # Strip ... blocks from reasoning output if present - text = data["choices"][0]["message"]["content"] - return text diff --git a/packages/inference/src/voters/glm_4_6.py b/packages/inference/src/voters/glm_4_6.py deleted file mode 100644 index 6cd01ba37904fc41402ae0e369525cd103870d88..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/glm_4_6.py +++ /dev/null @@ -1,76 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -glm_4_6.py — GLM-4.6 voter (Zhipu AI / z.ai). - -Backend: z.ai (primary) or OpenRouter (secondary). -Env vars: ZAI_API_KEY or OPENROUTER_API_KEY. -BFCL #1 function caller. Off by default. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class GLM46Voter(BaseVoter): - VOTER_ID = "glm-4.6" - ENV_VARS = ["ZAI_API_KEY", "OPENROUTER_API_KEY"] - LICENSE = "Open weights" - PROVIDER = "Zhipu AI (z.ai) / OpenRouter" - CONTEXT_WINDOW = 131072 - MODEL_ID = "THUDM/GLM-4.6-9B-Chat" - BFCL_SCORE = "#1" - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - zai_key = os.environ.get("ZAI_API_KEY") - openrouter_key = os.environ.get("OPENROUTER_API_KEY") - - if zai_key: - url = "https://open.bigmodel.cn/api/paas/v4/chat/completions" - headers = { - "Authorization": f"Bearer {zai_key}", - "Content-Type": "application/json", - } - model = "glm-4" - else: - url = "https://openrouter.ai/api/v1/chat/completions" - headers = { - "Authorization": f"Bearer {openrouter_key}", - "Content-Type": "application/json", - "HTTP-Referer": "https://szlholdings.com", - "X-Title": "a11oy-ensemble", - } - model = "thudm/glm-4.6-9b" - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/packages/inference/src/voters/hermes_4_405b.py b/packages/inference/src/voters/hermes_4_405b.py deleted file mode 100644 index 8354e2456abca7ba484a0cc9152995c3b6936b62..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/hermes_4_405b.py +++ /dev/null @@ -1,79 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -hermes_4_405b.py — Hermes-4-405B voter (Nous Research). - -Backend: Nous Research Portal (primary), OpenRouter (secondary), HF (tertiary). -Env vars: NOUS_API_KEY or HF_TOKEN. -Hybrid reasoning + ChatML. Off by default. -""" -from __future__ import annotations - -import os -import re -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class Hermes4405BVoter(BaseVoter): - VOTER_ID = "hermes-4-405b" - ENV_VARS = ["NOUS_API_KEY", "HF_TOKEN"] - LICENSE = "Open weights (Llama 3.1 base)" - PROVIDER = "Nous Research / OpenRouter / HuggingFace" - CONTEXT_WINDOW = 131072 - MODEL_ID = "NousResearch/Hermes-4-405B" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - nous_key = os.environ.get("NOUS_API_KEY") - hf_token = os.environ.get("HF_TOKEN") - - if nous_key: - url = "https://inference.nous.systems/v1/chat/completions" - headers = { - "Authorization": f"Bearer {nous_key}", - "Content-Type": "application/json", - } - model = "hermes-4-405b" - else: - # HF Inference fallback - url = "https://api-inference.huggingface.co/v1/chat/completions" - headers = { - "Authorization": f"Bearer {hf_token}", - "Content-Type": "application/json", - } - model = self.MODEL_ID - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - text = data["choices"][0]["message"]["content"] - # Strip ... blocks from hybrid reasoning output - text = re.sub(r".*?", "", text, flags=re.DOTALL).strip() - return text diff --git a/packages/inference/src/voters/hf_inference_voter.py b/packages/inference/src/voters/hf_inference_voter.py deleted file mode 100644 index cdfc89c8bbda54d80acdd0f836cf1a32534b8299..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/hf_inference_voter.py +++ /dev/null @@ -1,82 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -hf_inference_voter.py — Three HF Inference free-tier voters: - - hf-inference-llama (Meta-Llama-3.1-70B-Instruct) - - hf-inference-mistral (Mistral-7B-Instruct-v0.3) - - hf-inference-qwen (Qwen2.5-72B-Instruct via HF) - -All three use HF_TOKEN. Off by default; activate by including voter_id in -the `voters` list AND having HF_TOKEN in the env. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - -HF_INFERENCE_BASE = "https://api-inference.huggingface.co/models" - - -class _HFInferenceBaseVoter(BaseVoter): - ENV_VARS = ["HF_TOKEN"] - LICENSE = "various-open" - PROVIDER = "HuggingFace Inference API" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - token = os.environ.get("HF_TOKEN", "") - headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"} - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - payload = { - "model": self.MODEL_ID, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - url = "https://api-inference.huggingface.co/v1/chat/completions" - async with httpx.AsyncClient(timeout=30.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] - - -class HFInferenceLlamaVoter(_HFInferenceBaseVoter): - VOTER_ID = "hf-inference-llama" - LICENSE = "Llama 3 Community" - PROVIDER = "HuggingFace Inference API (Meta-Llama)" - CONTEXT_WINDOW = 131072 - MODEL_ID = "meta-llama/Meta-Llama-3.1-70B-Instruct" - - -class HFInferenceMistralVoter(_HFInferenceBaseVoter): - VOTER_ID = "hf-inference-mistral" - LICENSE = "Apache-2.0" - PROVIDER = "HuggingFace Inference API (Mistral)" - CONTEXT_WINDOW = 32768 - MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3" - - -class HFInferenceQwenVoter(_HFInferenceBaseVoter): - VOTER_ID = "hf-inference-qwen" - LICENSE = "Apache-2.0" - PROVIDER = "HuggingFace Inference API (Qwen)" - CONTEXT_WINDOW = 131072 - MODEL_ID = "Qwen/Qwen2.5-72B-Instruct" diff --git a/packages/inference/src/voters/kimi_k2.py b/packages/inference/src/voters/kimi_k2.py deleted file mode 100644 index 2ab0240df101f3237ae812fe6335acfc123cc3a9..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/kimi_k2.py +++ /dev/null @@ -1,77 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -kimi_k2.py — Kimi K2 voter (Moonshot AI). - -Backend: Moonshot API (primary) or OpenRouter (secondary). -Env vars: MOONSHOT_API_KEY or OPENROUTER_API_KEY. -200k+ context window, top-tier tool calling. -Off by default — activate by listing "kimi-k2" in voters. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class KimiK2Voter(BaseVoter): - VOTER_ID = "kimi-k2" - ENV_VARS = ["MOONSHOT_API_KEY", "OPENROUTER_API_KEY"] - LICENSE = "Open weights" - PROVIDER = "Moonshot AI / OpenRouter" - CONTEXT_WINDOW = 200000 - MODEL_ID = "moonshot-ai/kimi-k2" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - moonshot_key = os.environ.get("MOONSHOT_API_KEY") - openrouter_key = os.environ.get("OPENROUTER_API_KEY") - - if moonshot_key: - url = "https://api.moonshot.cn/v1/chat/completions" - headers = { - "Authorization": f"Bearer {moonshot_key}", - "Content-Type": "application/json", - } - model = "kimi-k2-0711-preview" - else: - url = "https://openrouter.ai/api/v1/chat/completions" - headers = { - "Authorization": f"Bearer {openrouter_key}", - "Content-Type": "application/json", - "HTTP-Referer": "https://szlholdings.com", - "X-Title": "a11oy-ensemble", - } - model = "moonshotai/kimi-k2" - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/packages/inference/src/voters/minimax_m2.py b/packages/inference/src/voters/minimax_m2.py deleted file mode 100644 index 7254b0c89889cea1bc5abe5d2a038306b3d9212c..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/minimax_m2.py +++ /dev/null @@ -1,76 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -minimax_m2.py — MiniMax-M2 voter. - -Backend: MiniMax API (primary) or OpenRouter (secondary). -Env vars: MINIMAX_API_KEY or OPENROUTER_API_KEY. -1M context window. Off by default. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class MiniMaxM2Voter(BaseVoter): - VOTER_ID = "minimax-m2" - ENV_VARS = ["MINIMAX_API_KEY", "OPENROUTER_API_KEY"] - LICENSE = "Open weights" - PROVIDER = "MiniMax / OpenRouter" - CONTEXT_WINDOW = 1000000 - MODEL_ID = "MiniMaxAI/MiniMax-M2" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - minimax_key = os.environ.get("MINIMAX_API_KEY") - openrouter_key = os.environ.get("OPENROUTER_API_KEY") - - if minimax_key: - url = "https://api.minimax.chat/v1/text/chatcompletion_v2" - headers = { - "Authorization": f"Bearer {minimax_key}", - "Content-Type": "application/json", - } - model = "MiniMax-M2" - else: - url = "https://openrouter.ai/api/v1/chat/completions" - headers = { - "Authorization": f"Bearer {openrouter_key}", - "Content-Type": "application/json", - "HTTP-Referer": "https://szlholdings.com", - "X-Title": "a11oy-ensemble", - } - model = "minimax/minimax-m2" - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/packages/inference/src/voters/nemotron_super_49b.py b/packages/inference/src/voters/nemotron_super_49b.py deleted file mode 100644 index 3bc1a8c886f4c29702bda9a132de194636511b2d..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/nemotron_super_49b.py +++ /dev/null @@ -1,64 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -nemotron_super_49b.py — Nemotron-Super-49B voter (NVIDIA NIM). - -Backend: NVIDIA NIM API exclusively. -Env var: NVIDIA_API_KEY. -NVIDIA-optimized, "Palantir-class" reasoning. Off by default. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class NemotronSuper49BVoter(BaseVoter): - VOTER_ID = "nemotron-super-49b" - ENV_VARS = ["NVIDIA_API_KEY"] - LICENSE = "NVIDIA Open Model License" - PROVIDER = "NVIDIA NIM" - CONTEXT_WINDOW = 131072 - MODEL_ID = "nvidia/llama-3.3-nemotron-super-49b-v1" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - nvidia_key = os.environ.get("NVIDIA_API_KEY", "") - - url = "https://integrate.api.nvidia.com/v1/chat/completions" - headers = { - "Authorization": f"Bearer {nvidia_key}", - "Content-Type": "application/json", - } - payload = { - "model": self.MODEL_ID, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - "stream": False, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/packages/inference/src/voters/nomos_1.py b/packages/inference/src/voters/nomos_1.py deleted file mode 100644 index fb7c1b3c09b285896f8158fa93ce979be7fb081c..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/nomos_1.py +++ /dev/null @@ -1,75 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -nomos_1.py — Nomos-1 voter (Nous Research). - -Backend: Nous Research Portal (primary) or HF Inference (secondary). -Env vars: NOUS_API_KEY or HF_TOKEN. -30B SOTA mathematician — critical for Lean kernel work. -Off by default. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class Nomos1Voter(BaseVoter): - VOTER_ID = "nomos-1" - ENV_VARS = ["NOUS_API_KEY", "HF_TOKEN"] - LICENSE = "Open weights" - PROVIDER = "Nous Research / HuggingFace" - CONTEXT_WINDOW = 32768 - MODEL_ID = "NousResearch/Nomos-1-30B" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - nous_key = os.environ.get("NOUS_API_KEY") - hf_token = os.environ.get("HF_TOKEN") - - if nous_key: - url = "https://inference.nous.systems/v1/chat/completions" - headers = { - "Authorization": f"Bearer {nous_key}", - "Content-Type": "application/json", - } - model = "nomos-1" - else: - url = "https://api-inference.huggingface.co/v1/chat/completions" - headers = { - "Authorization": f"Bearer {hf_token}", - "Content-Type": "application/json", - } - model = self.MODEL_ID - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/packages/inference/src/voters/qwen_local.py b/packages/inference/src/voters/qwen_local.py deleted file mode 100644 index 23722d36c40aec86e107217d44262231998f4c3c..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/qwen_local.py +++ /dev/null @@ -1,73 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -qwen_local.py — SOVEREIGN DEFAULT voter. - -Qwen-local is the floor: it ALWAYS participates regardless of any env var. -When the local vLLM endpoint is unreachable it degrades to a clearly-labelled -deterministic stub — never a hallucinated completion. - -Sovereign-default: qwen-local is ALWAYS in the voter pool. The aggregator may -receive a stub response, but it never gets silence from the sovereign floor. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class QwenLocalVoter(BaseVoter): - VOTER_ID = "qwen-local" - ENV_VARS = [] # No env var required — sovereign default - LICENSE = "Apache-2.0" - PROVIDER = "local-vLLM" - CONTEXT_WINDOW = 32768 - MODEL_ID = "Qwen/Qwen2.5-72B-Instruct" - BFCL_SCORE = None - - # Sovereign-default: always available - def is_available(self) -> bool: - return True - - def _active_env_var(self): - return None # No env var needed - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - vllm_url = os.environ.get("QWEN_LOCAL_URL", "http://127.0.0.1:8000/v1/chat/completions") - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - payload = { - "model": self.MODEL_ID, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - try: - async with httpx.AsyncClient(timeout=30.0) as client: - resp = await client.post(vllm_url, json=payload) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] - except Exception: - # Sovereign-default stub — clearly labelled, never fabricated - return ( - f"[qwen-local · STUB · local vLLM unreachable] " - f"Deterministic stub response for: {prompt[:80]!r}. " - f"Deploy a local vLLM serving {self.MODEL_ID} at QWEN_LOCAL_URL to enable real inference." - ) diff --git a/packages/inference/src/voters/step_3_7_flash.py b/packages/inference/src/voters/step_3_7_flash.py deleted file mode 100644 index 4a4b56c48c1d5046a7d751ee9605f2902221bb82..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/step_3_7_flash.py +++ /dev/null @@ -1,76 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -step_3_7_flash.py — Step-3.7-Flash voter (StepFun / 阶跃星辰). - -Backend: StepFun API (primary) or OpenRouter (secondary). -Env vars: STEPFUN_API_KEY or OPENROUTER_API_KEY. -198B MoE vision-language model. Off by default. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class Step37FlashVoter(BaseVoter): - VOTER_ID = "step-3.7-flash" - ENV_VARS = ["STEPFUN_API_KEY", "OPENROUTER_API_KEY"] - LICENSE = "Open weights" - PROVIDER = "StepFun / OpenRouter" - CONTEXT_WINDOW = 32768 - MODEL_ID = "stepfun-ai/step-3.7-flash" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - stepfun_key = os.environ.get("STEPFUN_API_KEY") - openrouter_key = os.environ.get("OPENROUTER_API_KEY") - - if stepfun_key: - url = "https://api.stepfun.com/v1/chat/completions" - headers = { - "Authorization": f"Bearer {stepfun_key}", - "Content-Type": "application/json", - } - model = "step-3-7b-flash" - else: - url = "https://openrouter.ai/api/v1/chat/completions" - headers = { - "Authorization": f"Bearer {openrouter_key}", - "Content-Type": "application/json", - "HTTP-Referer": "https://szlholdings.com", - "X-Title": "a11oy-ensemble", - } - model = "stepfun-ai/step-3-7b-flash" - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/packages/inference/src/voters/xiaomi_mimo.py b/packages/inference/src/voters/xiaomi_mimo.py deleted file mode 100644 index 13c9dd0cdaf981c460fb327fa247ef9a2a1209e8..0000000000000000000000000000000000000000 --- a/packages/inference/src/voters/xiaomi_mimo.py +++ /dev/null @@ -1,76 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -xiaomi_mimo.py — Xiaomi MiMo voter. - -Backend: Nous Research Portal (primary) or direct Xiaomi endpoint (secondary). -Env vars: XIAOMI_API_KEY or NOUS_API_KEY. -Strong Chinese model. Off by default. -""" -from __future__ import annotations - -import os -from typing import Any, Optional - -import httpx - -from .base_voter import BaseVoter - - -class XiaomiMiMoVoter(BaseVoter): - VOTER_ID = "xiaomi-mimo" - ENV_VARS = ["XIAOMI_API_KEY", "NOUS_API_KEY"] - LICENSE = "Open weights (Apache-2.0)" - PROVIDER = "Nous Research / Xiaomi direct" - CONTEXT_WINDOW = 131072 - MODEL_ID = "XiaomiMiMo/MiMo-7B-RL" - BFCL_SCORE = None - - async def _call( - self, - prompt: str, - system: Optional[str] = None, - max_tokens: int = 512, - temperature: float = 0.7, - **kwargs: Any, - ) -> str: - messages = [] - if system: - messages.append({"role": "system", "content": system}) - messages.append({"role": "user", "content": prompt}) - - xiaomi_key = os.environ.get("XIAOMI_API_KEY") - nous_key = os.environ.get("NOUS_API_KEY") - - if xiaomi_key: - # Xiaomi direct API (OpenAI-compat) - url = "https://api.xiaomi-mimo.com/v1/chat/completions" - headers = { - "Authorization": f"Bearer {xiaomi_key}", - "Content-Type": "application/json", - } - model = "mimo-7b-rl" - else: - # Nous Portal fallback - url = "https://inference.nous.systems/v1/chat/completions" - headers = { - "Authorization": f"Bearer {nous_key}", - "Content-Type": "application/json", - } - model = "xiaomi-mimo-7b" - - payload = { - "model": model, - "messages": messages, - "max_tokens": max_tokens, - "temperature": temperature, - } - - async with httpx.AsyncClient(timeout=60.0) as client: - resp = await client.post(url, json=payload, headers=headers) - resp.raise_for_status() - data = resp.json() - return data["choices"][0]["message"]["content"] diff --git a/resilience/status_feed.py b/resilience/status_feed.py deleted file mode 100644 index 66985bb262347295f57e6d5d1a523875ba01e836..0000000000000000000000000000000000000000 --- a/resilience/status_feed.py +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 · Doctrine v12 (additive). Yachay. -""" -status_feed — internal health -> public status_feed.json (fail-closed allow-list). -Reads Prometheus + active Alertmanager alerts + degradation receipts; emits ONLY the -szl.status_feed/v1 schema. Anything not explicitly mapped is dropped (never leaked). - -Honest anti-cover-up: driven by the SAME Prometheus signals as the internal dashboard, -so the public page can never claim green while internally red. v11 LOCKED untouched. -""" -from datetime import datetime, timezone - -# allow-list: internal flagship -> public component -PUBLIC_COMPONENT = { - "a11oy": "Governance & Brand", "amaru": "Memory / Cortex", - "sentra": "Immune / Policy", "vessels": "Maritime & Receipts", - "rosie": "Companion", "killinchu": "Drone Ops", - "lean-kernel": "Proof Kernel", -} -# Keys that MUST NEVER appear in the public feed (defense in depth; allow-list already -# drops them). We match on KEY NAMES (not a substring of the whole blob) so legitimate -# component copy like "Receipts"/"Companion" is never falsely flagged. -_NEVER_PUBLISH_KEYS = frozenset({ - "provider", "model", "tripwire", "khipu_node", "digest", - "hostname", "ip", "secret", "token", "breaker", "circuit", -}) - - -def _coarse_status(up: bool, degraded: bool, partial: bool) -> str: - if not up: return "major_outage" - if partial: return "partial_outage" - if degraded: return "degraded" - return "operational" - - -def build_feed(metrics: dict, alerts: list[dict]) -> dict: - components = [] - for fl, comp in PUBLIC_COMPONENT.items(): - up = metrics.get(f"szl_up::{fl}", 0) == 1 - degraded = any(a for a in alerts - if a.get("flagship") == fl and a.get("impact") == "degraded") - components.append({ - "name": comp, - "status": _coarse_status(up, degraded, partial=False), - "uptime_30d": round(metrics.get(f"szl_uptime_30d::{fl}", 0.0), 2), - }) - # AI Responses component derived from router tiers (impact only, no provider names) - router_degraded = (metrics.get("szl_router_tier::T0_cache", 0) - + metrics.get("szl_router_tier::T1_small", 0)) > 0 - components.append({"name": "AI Responses", - "status": "degraded" if router_degraded else "operational", - "note": "Responses may be slower than usual." if router_degraded else None}) - - overall = "operational" - if any(c["status"] == "major_outage" for c in components): overall = "major_outage" - elif any(c["status"] == "partial_outage" for c in components): overall = "partial_outage" - elif any(c["status"] == "degraded" for c in components): overall = "degraded" - - feed = {"schema": "szl.status_feed/v1", - "generated_at": datetime.now(timezone.utc).isoformat(), - "overall": overall, "components": components, - "active_incidents": _public_incidents(alerts), - "scheduled_maintenance": []} - _assert_no_leak(feed) # fail-closed: refuse to emit if any banned key present - return feed - - -def _public_incidents(alerts): - out = [] - for a in alerts: - if not a.get("customer_impacting"): # only customer-impacting alerts go public - continue - out.append({"id": a["incident_id"], "title": a["public_title"], # pre-sanitized - "impact": a["impact"], "started_at": a["started_at"], - "latest_update": a["public_update"]}) - return out - - -def _assert_no_leak(node) -> None: - """Recursively assert no banned KEY appears anywhere in the feed (fail-closed).""" - if isinstance(node, dict): - for k, v in node.items(): - if str(k).lower() in _NEVER_PUBLISH_KEYS: - raise RuntimeError( - f"status_feed leak guard tripped on key '{k}' — refusing to publish") - _assert_no_leak(v) - elif isinstance(node, (list, tuple)): - for item in node: - _assert_no_leak(item) diff --git a/resilience/szl_breaker.py b/resilience/szl_breaker.py deleted file mode 100644 index af6a7f816e267b597ce7eaa3c63c373079597024..0000000000000000000000000000000000000000 --- a/resilience/szl_breaker.py +++ /dev/null @@ -1,129 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 SZL Holdings · Doctrine v12 (additive over v11 LOCKED). Yachay. -""" -szl_breaker — Hystrix-style circuit breakers for every external SZL call. - -pybreaker = state machine (CLOSED/OPEN/HALF-OPEN). -tenacity = bounded retry w/ exponential backoff + full jitter. -We add: per-call timeout, named fallback, and a Khipu degradation receipt - on every OPEN transition and every fallback execution. - -ADDITIVE only: this wraps calls; it never alters the 13-axis Yuyay gate, the -Lambda aggregator, or any LOCKED number (749/14/163, replay-hash bacf5443…631fc5). - -HONEST: receipt signature is DSSE PLACEHOLDER (Sigstore CI not wired, v11 §9). - Khipu DAG ingest reuses szl_wire.ingest_receipt (in-memory ring + S3 mirror). -""" -from __future__ import annotations - -import functools -from concurrent.futures import ThreadPoolExecutor -from concurrent.futures import TimeoutError as FutureTimeout -from datetime import datetime, timezone -from typing import Any, Callable - -import pybreaker -from tenacity import ( - retry, - retry_if_exception_type, - stop_after_attempt, - wait_exponential_jitter, -) - -try: - from szl_wire import SIGNATURE_PLACEHOLDER, ingest_receipt # reuse the live DAG -except Exception: # edge / standalone import - SIGNATURE_PLACEHOLDER = "PLACEHOLDER — Sigstore CI not wired (Doctrine v12)" - def ingest_receipt(receipt: dict) -> dict: # local fallback writer - return {"receipt": receipt, "note": "local-only ingest (no szl_wire)"} - -_POOL = ThreadPoolExecutor(max_workers=16) - - -def _emit_degradation(breaker_name: str, flagship: str, failure_mode: str, - fallback_tier: str, state: str, traceparent: str | None) -> None: - """Append a szl.degradation.receipt/v1 to the canonical Khipu DAG (RUWAY-only path).""" - ingest_receipt({ - "schema": "szl.degradation.receipt/v1", - "event_id": f"deg-{datetime.now(timezone.utc).isoformat()}-{flagship}-{breaker_name}", - "flagship": flagship, - "failure_mode": failure_mode, - "circuit": breaker_name, - "breaker_state": state, - "fallback_tier_served": fallback_tier, - "detected_at": datetime.now(timezone.utc).isoformat(), - "user_visible": True, - "traceparent": traceparent, - "doctrine": "v12", - "dsse": {"sig": SIGNATURE_PLACEHOLDER, "keyid": "PENDING"}, - }) - - -class KhipuListener(pybreaker.CircuitBreakerListener): - """Emit a Khipu receipt on every breaker state transition (honest audit trail).""" - def __init__(self, name: str, flagship: str, failure_mode: str, fallback_tier: str): - self.name, self.flagship = name, flagship - self.failure_mode, self.fallback_tier = failure_mode, fallback_tier - def state_change(self, cb, old, new): - _emit_degradation(self.name, self.flagship, self.failure_mode, - self.fallback_tier, str(new.name).upper(), None) - - -def make_breaker(name: str, flagship: str, failure_mode: str, fallback_tier: str, - fail_max: int = 5, reset_timeout_s: int = 15) -> pybreaker.CircuitBreaker: - return pybreaker.CircuitBreaker( - fail_max=fail_max, - reset_timeout=reset_timeout_s, - listeners=[KhipuListener(name, flagship, failure_mode, fallback_tier)], - name=name, - ) - - -def guarded_call(breaker: pybreaker.CircuitBreaker, *, flagship: str, failure_mode: str, - fallback_tier: str, timeout_s: float, retry_budget: int, - fallback: Callable[[], Any], traceparent: str | None = None): - """ - Decorator: wraps an external call with breaker + timeout + bounded retry + fallback. - On OPEN (short-circuit) or exhausted retries, runs `fallback` and emits a Khipu receipt. - """ - def deco(fn: Callable[..., Any]) -> Callable[..., Any]: - @retry(stop=stop_after_attempt(max(1, retry_budget + 1)), - wait=wait_exponential_jitter(initial=1, max=300), - retry=retry_if_exception_type(Exception), reraise=True) - def _attempt(*a, **k): - fut = _POOL.submit(fn, *a, **k) - try: - return fut.result(timeout=timeout_s) # per-call hard timeout - except FutureTimeout: - raise TimeoutError(f"{breaker.name} exceeded {timeout_s}s") - - @functools.wraps(fn) - def wrapper(*a, **k): - try: - return breaker.call(_attempt, *a, **k) # breaker tracks success/fail - except pybreaker.CircuitBreakerError: # OPEN → short-circuit - _emit_degradation(breaker.name, flagship, failure_mode, - fallback_tier, "OPEN", traceparent) - return fallback() - except Exception: # retries exhausted - _emit_degradation(breaker.name, flagship, failure_mode, - fallback_tier, "FALLBACK", traceparent) - return fallback() - return wrapper - return deco - - -# Breaker registry helper (names match OBSERVABILITY_DASHBOARD §3 + CIRCUIT_BREAKER_LAYER §1) -REGISTRY = {} - -def register(name: str, flagship: str, failure_mode: str, fallback_tier: str, - fail_max: int = 5, reset_timeout_s: int = 15) -> pybreaker.CircuitBreaker: - b = make_breaker(name, flagship, failure_mode, fallback_tier, fail_max, reset_timeout_s) - REGISTRY[name] = b - return b - - -def breaker_states() -> dict[str, int]: - """For /healthz: 0=CLOSED, 1=HALF_OPEN, 2=OPEN per registered breaker.""" - m = {"closed": 0, "half-open": 1, "open": 2} - return {n: m.get(str(b.current_state).lower(), -1) for n, b in REGISTRY.items()} diff --git a/resilience/szl_exporter.py b/resilience/szl_exporter.py deleted file mode 100644 index 32d266f28b7702424c8f14a26ca1a837cf61d0b2..0000000000000000000000000000000000000000 --- a/resilience/szl_exporter.py +++ /dev/null @@ -1,93 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 SZL Holdings · Doctrine v12 (additive). Yachay. -""" -szl_exporter — scrapes each Space's honest in-process state and re-exposes it as -Prometheus metrics for the single-pane Grafana dashboard (OBSERVABILITY_DASHBOARD.md). - -Reads /api//healthz, /v1/mesh/state, /v1/brain/sockets, vessels ledger, -lean-kernel /api/lean/theorems. - -HONEST: it reports what the Spaces actually expose. Where a Space has no metric yet -(e.g. a static Space has no latency histogram), the series is simply absent, not faked. -The in-process buses + Khipu DAG are in-memory ring buffers (per szl_wire.py); the -durable record is the S3 mirror (BACKUP_AND_RECOVERY.md). v11 LOCKED numbers untouched. -""" -import time - -import httpx -from prometheus_client import Gauge, start_http_server - -SPACES = { - "a11oy": "https://szlholdings-a11oy.hf.space", - "amaru": "https://szlholdings-amaru.hf.space", - "sentra": "https://szlholdings-sentra.hf.space", - "vessels": "https://szlholdings-vessels.hf.space", - "rosie": "https://szlholdings-rosie.hf.space", - "killinchu": "https://szlholdings-killinchu.hf.space", - "lean-kernel": "https://szlholdings-lean-kernel.hf.space", -} - -up = Gauge("szl_up", "flagship up (1) or down (0)", ["flagship"]) -dag_depth = Gauge("szl_khipu_dag_depth", "Khipu DAG depth (ring buffer)", ["chain"]) -integ = Gauge("szl_khipu_integrity_ok", "Khipu integrity (1 ok / 0 mismatch)", ["chain"]) -lean_dec = Gauge("szl_lean_declarations", "lean-kernel total declarations (live build)") -lean_sry = Gauge("szl_lean_sorry", "lean-kernel sorry count (live build)") -lean_axi = Gauge("szl_lean_axiom", "lean-kernel axiom count (live build)") - -# LOCKED reference (Doctrine v11/v12) — surfaced alongside the live build, never edited. -LOCKED = Gauge("szl_lean_locked_reference", "Doctrine LOCKED reference numbers", ["kind"]) - - -def _recompute_integrity(nodes: list[dict]) -> int: - """Honest hash-chain check: digest must equal sha256(receipt sorted-json || parents).""" - import hashlib - import json - prev = None - for n in nodes: - h = hashlib.sha256() - h.update(json.dumps(n.get("receipt", {}), sort_keys=True).encode()) - for p in n.get("parents", []): - h.update(p.encode()) - if n.get("digest") and n["digest"] != h.hexdigest(): - return 0 - prev = n.get("digest") - return 1 - - -def scrape_once(): - for name, base in SPACES.items(): - try: - h = httpx.get(f"{base}/api/{name}/healthz", timeout=10) - up.labels(name).set(1 if h.status_code == 200 else 0) - except Exception: - up.labels(name).set(0) # honest: probe failed -> down - - # Khipu DAG depth + integrity from vessels ledger read-view - try: - led = httpx.get(f"{SPACES['vessels']}/api/vessels/v1/receipts/ledger", timeout=10).json() - nodes = led.get("nodes", []) - dag_depth.labels("canonical").set(len(nodes)) - integ.labels("canonical").set(_recompute_integrity(nodes)) - except Exception: - integ.labels("canonical").set(0) - - # Lean-kernel live build numbers (surfaced next to LOCKED reference) - try: - th = httpx.get(f"{SPACES['lean-kernel']}/api/lean/theorems", timeout=15).json()["summary"] - lean_dec.set(th.get("total_declarations", 0)) - lean_sry.set(th.get("sorry", 0)) - lean_axi.set(th.get("axiom", 0)) - except Exception: - pass - - # LOCKED reference (never edited): 749 declarations / 14 unique axioms / 163 sorries - LOCKED.labels("declarations").set(749) - LOCKED.labels("unique_axioms").set(14) - LOCKED.labels("sorries").set(163) - - -if __name__ == "__main__": - start_http_server(9100) # Prometheus scrapes :9100/metrics - while True: - scrape_once() - time.sleep(15) diff --git a/scripts/audit_github_access_permissions.py b/scripts/audit_github_access_permissions.py deleted file mode 100644 index bcb42279052b9ddfe19116b7d5642cf3c1e02994..0000000000000000000000000000000000000000 --- a/scripts/audit_github_access_permissions.py +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/env python3 -"""Read-only GitHub access audit for cross-repo execution readiness. - -This script observes the current gh authentication context and target-repo -viewer permissions from docs/github-enterprise-access-checklist.json. It never -pushes, opens pull requests, edits repos, mutates teams, or calls write-method -GitHub APIs. -""" - -from __future__ import annotations - -import argparse -import json -import subprocess -import sys -from datetime import datetime, timezone -from pathlib import Path -from typing import Any - - -REPO_ROOT = Path(__file__).resolve().parents[1] -CHECKLIST = REPO_ROOT / "docs" / "github-enterprise-access-checklist.json" -PERMISSION_RANK = { - "": 0, - "NONE": 0, - "READ": 1, - "TRIAGE": 1, - "WRITE": 2, - "MAINTAIN": 3, - "ADMIN": 4, -} -WRITE_READY = {"WRITE", "MAINTAIN", "ADMIN"} -ALLOWED_STATUSES = {"write-ready", "read-only", "unavailable", "error"} - - -def run_gh(args: list[str]) -> tuple[int, str, str]: - command = ["gh", *args] - completed = subprocess.run( - command, - cwd=REPO_ROOT, - text=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - check=False, - ) - return completed.returncode, completed.stdout.strip(), completed.stderr.strip() - - -def sanitize_error(value: str) -> str: - return value.replace("\n", " ")[:500] - - -def permission_meets_minimum(viewer_permission: str, minimum: str) -> bool: - minimum = minimum.upper() - viewer = viewer_permission.upper() - if minimum == "WRITE": - return viewer in WRITE_READY - return PERMISSION_RANK.get(viewer, 0) >= PERMISSION_RANK.get(minimum, 0) - - -def repo_status(viewer_permission: str, exit_code: int) -> str: - if exit_code != 0: - return "unavailable" - permission = viewer_permission.upper() - if permission in WRITE_READY: - return "write-ready" - return "read-only" - - -def audit(checklist_path: Path) -> dict[str, Any]: - checklist = json.loads(checklist_path.read_text(encoding="utf-8")) - - auth_code, auth_stdout, auth_stderr = run_gh(["auth", "status"]) - user_code, user_stdout, user_stderr = run_gh(["api", "user", "-q", ".login"]) - viewer = { - "login": user_stdout if user_code == 0 else None, - "source": "gh api user -q .login", - "error": sanitize_error(user_stderr) if user_code != 0 else None, - } - - repos = [] - for target in checklist.get("targetRepos", []): - repo = target["repo"] - command_args = [ - "repo", - "view", - repo, - "--json", - "viewerPermission,nameWithOwner,isPrivate,defaultBranchRef", - ] - code, stdout, stderr = run_gh(command_args) - viewer_permission = "" - raw: dict[str, Any] | None = None - if code == 0 and stdout: - try: - raw = json.loads(stdout) - viewer_permission = str(raw.get("viewerPermission") or "") - except json.JSONDecodeError: - code = 1 - stderr = "gh returned non-JSON output" - - minimum = target.get("minimumPermission", "write") - meets = permission_meets_minimum(viewer_permission, minimum) - repos.append( - { - "repo": repo, - "minimumPermission": minimum, - "viewerPermission": viewer_permission or None, - "meetsMinimumPermission": meets, - "phaseUnlocked": target.get("phaseUnlocked"), - "currentFallback": target.get("currentFallback"), - "ghCommand": "gh " + " ".join(command_args), - "status": repo_status(viewer_permission, code) if code == 0 else "unavailable", - "error": sanitize_error(stderr) if code != 0 else None, - "isPrivate": raw.get("isPrivate") if raw else None, - "defaultBranch": raw.get("defaultBranchRef", {}).get("name") if raw and raw.get("defaultBranchRef") else None, - } - ) - - summary = { - "total": len(repos), - "writeReady": sum(1 for repo in repos if repo["status"] == "write-ready"), - "readOnly": sum(1 for repo in repos if repo["status"] == "read-only"), - "unavailable": sum(1 for repo in repos if repo["status"] == "unavailable"), - "errors": sum(1 for repo in repos if repo["status"] == "error"), - } - - return { - "schemaVersion": 1, - "generatedAt": datetime.now(timezone.utc).isoformat(), - "checklistPath": str(checklist_path.relative_to(REPO_ROOT)), - "viewer": viewer, - "auth": { - "ghAuthStatusExitCode": auth_code, - "authenticated": auth_code == 0, - "stdout": auth_stdout, - "error": sanitize_error(auth_stderr) if auth_code != 0 else None, - }, - "repos": repos, - "summary": summary, - "failureBoundaries": checklist.get("doctrineBoundaries", []), - } - - -def validate_output(data: dict[str, Any]) -> list[str]: - errors: list[str] = [] - required_top = {"schemaVersion", "generatedAt", "checklistPath", "viewer", "auth", "repos", "summary", "failureBoundaries"} - missing = sorted(required_top - data.keys()) - if missing: - errors.append(f"missing top-level fields: {', '.join(missing)}") - - repos = data.get("repos", []) - if not isinstance(repos, list) or not repos: - errors.append("repos must be a non-empty list") - repos = [] - - for repo in repos: - status = repo.get("status") - if status not in ALLOWED_STATUSES: - errors.append(f"{repo.get('repo', '')}: unknown status {status!r}") - if repo.get("minimumPermission") == "write": - permission = str(repo.get("viewerPermission") or "").upper() - expected = permission in WRITE_READY - if bool(repo.get("meetsMinimumPermission")) != expected: - errors.append(f"{repo.get('repo', '')}: meetsMinimumPermission does not match viewerPermission") - command = str(repo.get("ghCommand") or "") - if not command.startswith("gh repo view "): - errors.append(f"{repo.get('repo', '')}: ghCommand must be read-only repo view") - - return errors - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--checklist", default=str(CHECKLIST), help="Path to access checklist JSON") - parser.add_argument("--output", required=True, help="Where to write audit JSON") - parser.add_argument("--validate", action="store_true", help="Validate the emitted output shape") - args = parser.parse_args() - - checklist_path = Path(args.checklist) - if not checklist_path.is_absolute(): - checklist_path = REPO_ROOT / checklist_path - output_path = Path(args.output) - if not output_path.is_absolute(): - output_path = REPO_ROOT / output_path - - data = audit(checklist_path) - output_path.parent.mkdir(parents=True, exist_ok=True) - output_path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8") - - if args.validate: - errors = validate_output(data) - if errors: - print("GitHub access live audit output validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Wrote GitHub access audit: {output_path}") - print( - "Summary: " - f"{data['summary']['writeReady']} write-ready, " - f"{data['summary']['readOnly']} read-only, " - f"{data['summary']['unavailable']} unavailable" - ) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/audit_huggingface_ecosystem.py b/scripts/audit_huggingface_ecosystem.py deleted file mode 100644 index 8235953c61b67194aeea5a2060864dd2de8172be..0000000000000000000000000000000000000000 --- a/scripts/audit_huggingface_ecosystem.py +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env python3 -"""Generate a GitHub-backed Hugging Face ecosystem manifest for SZLHOLDINGS.""" - -from __future__ import annotations - -import argparse -import json -import urllib.request -from pathlib import Path -from typing import Any - - -REPO_ROOT = Path.cwd() -DEFAULT_OUTPUT = REPO_ROOT / "docs" / "huggingface-ecosystem-manifest.json" -ORG = "SZLHOLDINGS" -OBSERVED_AT = "2026-05-30T03:43:04Z" - - -def fetch_json(url: str) -> Any: - with urllib.request.urlopen(url, timeout=30) as response: - return json.load(response) - - -def api_items(kind: str) -> list[dict[str, Any]]: - data = fetch_json(f"https://huggingface.co/api/{kind}?author={ORG}&limit=100") - if not isinstance(data, list): - raise TypeError(f"Expected list from Hugging Face {kind} API") - return sorted(data, key=lambda item: item.get("id", "")) - - -def item_summary(item: dict[str, Any], repo_type: str) -> dict[str, Any]: - item_id = item.get("id") or item.get("modelId") - tags = item.get("tags") or [] - card = item.get("cardData") or {} - return { - "id": item_id, - "repoType": repo_type, - "private": bool(item.get("private", False)), - "gated": bool(item.get("gated", False)), - "disabled": bool(item.get("disabled", False)), - "sdk": item.get("sdk"), - "license": card.get("license") or next((tag.removeprefix("license:") for tag in tags if isinstance(tag, str) and tag.startswith("license:")), None), - "sha": item.get("sha"), - "lastModified": item.get("lastModified"), - "createdAt": item.get("createdAt"), - "tags": tags, - "claimStatus": "generated-mirror" if item_id == "SZLHOLDINGS/a11oy-v19-substrate" else "inventory", - "evidenceUrls": [ - f"https://huggingface.co/{item_id}", - ], - "unsafeFlags": unsafe_flags(str(item_id), repo_type, tags, card), - } - - -def unsafe_flags(item_id: str, repo_type: str, tags: list[Any], card: dict[str, Any]) -> list[str]: - flags: list[str] = [] - text = json.dumps({"id": item_id, "tags": tags, "card": card}, sort_keys=True).lower() - if any(name in text for name in ["kora", "lumina", "paragon", "lyte"]): - flags.append("stale-product-name-review") - if item_id in { - "SZLHOLDINGS/counsel-source", - "SZLHOLDINGS/terra-source", - "SZLHOLDINGS/carlota-jo-source", - }: - flags.append("funded-roadmap-scaffold-not-active-demo") - if item_id == "SZLHOLDINGS/SZLHOLDINGS": - flags.append("org-profile-duplicate-review") - if repo_type == "space" and any(fragment in item_id for fragment in ["deep-dive", "platform"]): - flags.append("space-card-should-link-github-commit") - return flags - - -def build_manifest() -> dict[str, Any]: - models = [item_summary(item, "model") for item in api_items("models")] - datasets = [item_summary(item, "dataset") for item in api_items("datasets")] - spaces = [item_summary(item, "space") for item in api_items("spaces")] - counts = { - "models": len(models), - "datasets": len(datasets), - "spaces": len(spaces), - } - return { - "schemaVersion": 1, - "generatedBy": "scripts/audit_huggingface_ecosystem.py", - "observedAt": OBSERVED_AT, - "org": ORG, - "canonicalGitHubRepo": "https://github.com/szl-holdings/a11oy", - "canonicalRule": "GitHub releases, CI, manifests, checksums, and DOI records are canonical; Hugging Face is a generated discovery and diligence mirror.", - "publicApiEndpoints": [ - f"https://huggingface.co/api/models?author={ORG}&limit=100", - f"https://huggingface.co/api/datasets?author={ORG}&limit=100", - f"https://huggingface.co/api/spaces?author={ORG}&limit=100", - ], - "counts": counts, - "canonicalNumbers": { - "hfSpaces": counts["spaces"], - "hfDatasets": counts["datasets"], - "hfModels": counts["models"], - "githubPublicRepos": 19, - "leanDeclarations": 217, - "leanAxioms": 12, - "leanSorries": 7, - "anchorFormulaGates": "35/35", - "benchmarkBaseline": "8.3% (1/12)", - }, - "guardrails": [ - "Do not present Counsel, Terra, or Carlota Jo as active demo surfaces.", - "Do not use KORA, LUMINA, PARAGON, or active Lyte framing.", - "Do not claim zero-sorry or all-green Lean proof status without current machine-readable proof evidence.", - "Do not claim signed UDS release assets exist unless tarball, signature, sha256, and public key assets are present and verify.", - ], - "inventory": { - "models": models, - "datasets": datasets, - "spaces": spaces, - }, - "recommendedActions": [ - { - "target": "SZLHOLDINGS/a11oy-v19-substrate", - "action": "Republish from dist/huggingface/a11oy after every GitHub canonical-source change.", - }, - { - "target": "SZLHOLDINGS/SZLHOLDINGS", - "action": "Replace duplicate org-profile model/dataset copy with generated counts and GitHub source links, or deprecate.", - }, - { - "target": "source mirrors", - "action": "Add generated card section: GitHub repo, exact commit, release/CI, DOI, claim status, limitations.", - }, - { - "target": "counsel-source/terra-source/carlota-jo-source", - "action": "Mark funded-roadmap scaffold and remove from active-demo collections until funded.", - }, - ], - } - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", default=str(DEFAULT_OUTPUT)) - parser.add_argument("--check", action="store_true") - args = parser.parse_args() - output = Path(args.output) - rendered = json.dumps(build_manifest(), indent=2, sort_keys=False) + "\n" - if args.check: - if not output.exists() or output.read_text(encoding="utf-8") != rendered: - print(f"Hugging Face ecosystem manifest is stale: {output}") - return 1 - print(f"Hugging Face ecosystem manifest is current: {output.relative_to(REPO_ROOT)}") - return 0 - output.parent.mkdir(parents=True, exist_ok=True) - output.write_text(rendered, encoding="utf-8") - print(f"Wrote Hugging Face ecosystem manifest: {output.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/build_ecosystem_readiness.py b/scripts/build_ecosystem_readiness.py deleted file mode 100644 index 65c138cced9249ea3b5b4a5f6d632f0dfa4c56f2..0000000000000000000000000000000000000000 --- a/scripts/build_ecosystem_readiness.py +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/env python3 -"""Build the deterministic SZL ecosystem readiness report. - -The report is intentionally offline by default. It converts the curated -ecosystem registry into a reviewable investor/UDS readiness packet and adds the -current claim guardrails observed during the GitHub deep dive. Live GitHub -status is useful for operators, but reproducible CI should not depend on network -calls. -""" - -from __future__ import annotations - -import argparse -import json -from pathlib import Path - - -REPO_ROOT = Path.cwd() -REGISTRY_PATH = REPO_ROOT / "docs" / "ecosystem-registry.json" -DEFAULT_OUTPUT = REPO_ROOT / "docs" / "ecosystem-readiness-report.json" -OBSERVED_AT = "2026-05-30" -LIVE_AUDIT_NOTES = { - "a11oy": [ - "Live main has seven policy gate files under packages/policy/src/gates and ten theorem-runtime manifest entries; larger gate counts require merged PR evidence.", - "uds-v0.3.0 release currently carries SBOM assets only, not signed binary payload assets.", - ], - "vessels": [ - "uds-v0.3.0 release was observed with zero release assets; use uds-v0.2.0 for signed-asset demonstration until v0.3.x assets land.", - "GHCR manifest checks returned an authentication challenge in this environment; package availability needs owner-side push or visibility confirmation.", - ], - "lutar-lean": [ - "Competition-math benchmark public language must stay raw-score and reproducible; cite only what an upstream proof report verifies.", - ], -} - - -ACTIVE_DEMO_REPOS = { - "a11oy", - "amaru", - "sentra", - "rosie", - "ouroboros", - "lutar-lean", - "ouroboros-thesis", - "uds-mesh", - "vsp-otel", - "vessels", - "agi-forecast", - "szl-trust", - "szl-brand", - "szl-cookbook", - ".github", - "platform", -} - -EXCLUDED_UNTIL_FUNDED = {"counsel", "terra", "carlota-jo"} - -FUNCTIONAL_STATUS = { - "a11oy": "demo-ready", - "vessels": "demo-ready", - "amaru": "supporting", - "sentra": "supporting", - "rosie": "supporting", - "ouroboros": "supporting", - "uds-mesh": "supporting", - "vsp-otel": "supporting", - "agi-forecast": "supporting", - "szl-trust": "supporting", - "szl-brand": "supporting", - "szl-cookbook": "supporting", - ".github": "supporting", - "platform": "supporting", - "lutar-lean": "needs-upstream-fix", - "ouroboros-thesis": "needs-upstream-fix", - "counsel": "scaffold-excluded", - "terra": "scaffold-excluded", - "carlota-jo": "scaffold-excluded", -} - -SHOWCASE_LABELS = { - "a11oy": "Operational hub and UDS/Zarf-compatible payload publisher", - "platform": "Canonical product integration monorepo and runtime evidence surface", - "ouroboros": "Bounded-loop runtime and governance receipt spine", - "lutar-lean": "Lean 4 proof substrate; cite exact closed modules and current CI", - "ouroboros-thesis": "DOI-pinned thesis and public claim taxonomy", - "rosie": "Khipu receipt DAG and CSS-ingress orchestration", - "amaru": "Receipt minting, append-only provenance, and anchoring component", - "sentra": "Telemetry, posture drift, and incident-command evidence component", - "uds-mesh": "UDS/Zarf mesh pointer manifest and bundle topology", - "vsp-otel": "OpenTelemetry exporter for Lambda-axis spans and receipt hashes", - "szl-cookbook": "Operator recipes and governed-AI development patterns", - "agi-forecast": "Governance trajectory forecast scenarios", - "vessels": "Maritime vertical demo wedge with governed alert trails", - "szl-trust": "Public trust and replay artifact ledger", - "szl-brand": "Brand, anatomy, social previews, and visual doctrine", - ".github": "Organization profile, reusable workflows, templates, and checks", - "counsel": "Funded-roadmap legal vertical scaffold", - "terra": "Funded-roadmap real-estate vertical scaffold", - "carlota-jo": "Funded-roadmap advisory services scaffold", -} - -EVIDENCE = { - "a11oy": [ - "README.md", - "docs/PROVENANCE.md", - "docs/INVESTOR_DEMO.md", - "artifacts/a11oy-uds/README.md", - "deploy/MANIFEST.json", - ".github/workflows/doctrine.yml", - ".github/workflows/operational.yml", - ".github/workflows/huggingface.yml", - "https://github.com/szl-holdings/a11oy/releases/tag/v1.0.1", - "https://github.com/szl-holdings/a11oy/releases/tag/uds-v0.2.0", - ], - "platform": [ - "https://github.com/szl-holdings/platform", - "https://github.com/szl-holdings/platform/releases/tag/v1.0.0-codex-kernel", - ], - "ouroboros": [ - "https://github.com/szl-holdings/ouroboros", - "https://github.com/szl-holdings/ouroboros/releases/tag/v6.3.0", - ], - "lutar-lean": [ - "https://github.com/szl-holdings/lutar-lean", - "https://github.com/szl-holdings/lutar-lean/releases/tag/lutar-v18.0.0", - "https://doi.org/10.5281/zenodo.20434308", - ], - "ouroboros-thesis": [ - "https://github.com/szl-holdings/ouroboros-thesis", - "https://doi.org/10.5281/zenodo.20434276", - "https://doi.org/10.5281/zenodo.19944926", - ], - "rosie": [ - "https://github.com/szl-holdings/rosie", - "https://github.com/szl-holdings/rosie/releases/tag/v1.0.1", - "https://github.com/szl-holdings/rosie/releases/tag/uds-v0.2.0", - ], - "amaru": [ - "https://github.com/szl-holdings/amaru", - "https://github.com/szl-holdings/amaru/releases/tag/uds-v0.2.0", - ], - "sentra": [ - "https://github.com/szl-holdings/sentra", - "https://github.com/szl-holdings/sentra/releases/tag/uds-v0.2.0", - ], - "uds-mesh": [ - "https://github.com/szl-holdings/uds-mesh", - "https://github.com/szl-holdings/uds-mesh/releases/tag/uds-v0.2.0", - ], - "vsp-otel": [ - "https://github.com/szl-holdings/vsp-otel", - "https://github.com/szl-holdings/vsp-otel/releases/tag/v0.1.0", - ], - "szl-cookbook": [ - "https://github.com/szl-holdings/szl-cookbook", - "https://github.com/szl-holdings/szl-cookbook/releases/tag/v0.1.0", - ], - "agi-forecast": [ - "https://github.com/szl-holdings/agi-forecast", - "https://github.com/szl-holdings/agi-forecast/releases/tag/v0.1.0", - ], - "vessels": [ - "https://github.com/szl-holdings/vessels", - "https://github.com/szl-holdings/vessels/releases/tag/uds-v0.2.0", - ], - "szl-trust": [ - "https://github.com/szl-holdings/szl-trust", - ], - "szl-brand": [ - "https://github.com/szl-holdings/szl-brand", - "https://github.com/szl-holdings/szl-brand/releases/tag/v0.1.0", - ], - ".github": [ - "https://github.com/szl-holdings/.github", - ], - "counsel": ["https://github.com/szl-holdings/counsel"], - "terra": ["https://github.com/szl-holdings/terra"], - "carlota-jo": ["https://github.com/szl-holdings/carlota-jo"], -} - -CAVEATS = { - "lutar-lean": [ - "Latest observed Lean kernel CI needs upstream repair before broad 'all green' or 'zero sorry' copy is repeated.", - "Use exact theorem/module references for formal claims.", - ], - "ouroboros-thesis": [ - "Thesis v18.0 DOI is the current citation anchor; GitHub release list reconciliation remains an upstream action.", - "Treat the thesis as the claim taxonomy, not blanket runtime proof.", - ], - "platform": [ - "Use as canonical integration evidence; keep production-readiness claims scoped to current CI and release artifacts.", - ], - "vessels": [ - "Use as the active vertical demo wedge; avoid implying every vertical scaffold is funded or production-ready.", - ], -} - - -def repo_entry(repo: dict[str, object]) -> dict[str, object]: - name = str(repo["name"]) - status = FUNCTIONAL_STATUS.get(name, "roadmap") - active = name in ACTIVE_DEMO_REPOS and name not in EXCLUDED_UNTIL_FUNDED - return { - "name": name, - "tier": repo.get("tier"), - "readiness": repo.get("readiness"), - "functionalDemoStatus": status, - "activeShowcase": active, - "showcaseLabel": SHOWCASE_LABELS.get(name, repo.get("role", "")), - "role": repo.get("role"), - "github": repo.get("github"), - "defaultBranch": repo.get("defaultBranch"), - "evidence": EVIDENCE.get(name, [repo.get("github")]), - "guardrails": CAVEATS.get(name, []), - "liveAuditNotes": LIVE_AUDIT_NOTES.get(name, []), - } - - -def build_report() -> dict[str, object]: - registry = json.loads(REGISTRY_PATH.read_text(encoding="utf-8")) - repos = [repo_entry(repo) for repo in registry["repos"]] - status_counts: dict[str, int] = {} - for repo in repos: - status = str(repo["functionalDemoStatus"]) - status_counts[status] = status_counts.get(status, 0) + 1 - - return { - "schemaVersion": 1, - "generatedBy": "scripts/build_ecosystem_readiness.py", - "observedAt": OBSERVED_AT, - "canonicalHub": registry["canonicalHub"], - "huggingFaceTarget": registry["huggingFaceTarget"], - "thesis": registry["thesis"], - "namingPolicy": { - "activeProductNames": [ - "a11oy", - "amaru", - "sentra", - "rosie", - "ouroboros", - "lutar-lean", - "ouroboros-thesis", - "uds-mesh", - "vsp-otel", - "vessels", - "agi-forecast", - "szl-trust", - "szl-brand", - "szl-cookbook", - "platform", - ], - "excludedUntilFunded": sorted(EXCLUDED_UNTIL_FUNDED), - "retiredOrDisallowedInShowcase": ["KORA", "LUMINA", "PARAGON", "Lyte"], - }, - "claimGuardrails": [ - "GitHub releases, workflows, manifests, checksums, and DOI records are canonical.", - "Hugging Face is a generated diligence mirror, not the source of release truth.", - "Counsel, Terra, and Carlota Jo are intentionally excluded from active-demo scope until funded.", - "Do not repeat broad all-green or zero-sorry proof claims without a current machine-readable proof report.", - "Do not repeat inflated benchmark closure claims; keep public language raw-score and reproducible, citing only what upstream proof reports verify.", - "Do not describe SBOM-only or empty UDS v0.3.0 releases as signed binary payload releases.", - "Do not describe unmerged G36-G40 or broader gate totals as live A11oy main runtime gates.", - "Use Defense Unicorns UDS/Zarf-compatible phrasing; do not imply Defense Unicorns endorsement or catalog acceptance.", - ], - "runtimeManifestSummary": { - "path": "docs/theorem-runtime-manifest.json", - "trackedEntries": 10, - "verifiedRuntimeEntries": 8, - "stagedOrRoadmapEntries": 2, - }, - "statusCounts": status_counts, - "repos": repos, - } - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", default=str(DEFAULT_OUTPUT)) - parser.add_argument("--check", action="store_true", help="fail if output is stale") - args = parser.parse_args() - - output = Path(args.output) - report = build_report() - rendered = json.dumps(report, indent=2, sort_keys=False) + "\n" - - if args.check: - if not output.exists(): - print(f"Missing readiness report: {output}") - return 1 - current = output.read_text(encoding="utf-8") - if current != rendered: - print(f"Readiness report is stale: {output}") - return 1 - print(f"Readiness report is current: {output.relative_to(REPO_ROOT)}") - return 0 - - output.parent.mkdir(parents=True, exist_ok=True) - output.write_text(rendered, encoding="utf-8") - print(f"Wrote ecosystem readiness report: {output.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/build_ecosystem_stage_matrix.py b/scripts/build_ecosystem_stage_matrix.py deleted file mode 100644 index e7bce036574042c042c881e4d4d248240721b76e..0000000000000000000000000000000000000000 --- a/scripts/build_ecosystem_stage_matrix.py +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env python3 -"""Build the SZL ecosystem stage matrix. - -The matrix is intentionally conservative: it records what is operational, -verified, staged, blocked, or excluded without turning roadmap items into -shipping claims. -""" - -from __future__ import annotations - -import argparse -import json -from pathlib import Path - - -REPO_ROOT = Path.cwd() -READINESS = REPO_ROOT / "docs" / "ecosystem-readiness-report.json" -THEOREMS = REPO_ROOT / "docs" / "theorem-runtime-manifest.json" -HF = REPO_ROOT / "docs" / "huggingface-ecosystem-manifest.json" -DEFAULT_OUTPUT = REPO_ROOT / "docs" / "ecosystem-stage-matrix.json" -OBSERVED_AT = "2026-05-30" - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def stage_for_repo(repo: dict) -> str: - status = repo["functionalDemoStatus"] - if status == "demo-ready": - return "operational" - if status == "supporting": - return "supporting-operational" - if status == "needs-upstream-fix": - return "blocked-upstream" - if status == "scaffold-excluded": - return "excluded-until-funded" - return "roadmap" - - -def build_matrix() -> dict: - readiness = load_json(READINESS) - theorem_manifest = load_json(THEOREMS) - hf = load_json(HF) - - repos = [] - for repo in readiness["repos"]: - repos.append({ - "name": repo["name"], - "stage": stage_for_repo(repo), - "tier": repo["tier"], - "github": repo["github"], - "activeShowcase": repo["activeShowcase"], - "evidence": repo["evidence"], - "guardrails": repo["guardrails"], - "nextAction": next_action_for_repo(repo), - }) - - formulas = [] - for entry in theorem_manifest["entries"]: - formulas.append({ - "id": entry["id"], - "formula": entry["formula"], - "stage": formula_stage(entry["claimStatus"]), - "claimStatus": entry["claimStatus"], - "runtimeFile": entry["runtimeFile"], - "testFile": entry["testFile"], - "validationCommand": entry["validationCommand"], - "caveat": entry["caveat"], - }) - - hf_items = [] - for repo_type, items in hf["inventory"].items(): - for item in items: - hf_items.append({ - "id": item["id"], - "repoType": repo_type[:-1] if repo_type.endswith("s") else repo_type, - "stage": "generated-mirror" if item["id"] == "SZLHOLDINGS/a11oy-v19-substrate" else "inventory", - "private": item["private"], - "unsafeFlags": item["unsafeFlags"], - "evidenceUrls": item["evidenceUrls"], - }) - - return { - "schemaVersion": 1, - "generatedBy": "scripts/build_ecosystem_stage_matrix.py", - "observedAt": OBSERVED_AT, - "doctrine": { - "noFakeGreen": True, - "noFakeSignedAssets": True, - "githubCanonical": True, - "hfGeneratedMirror": True, - "excludedUntilFunded": ["carlota-jo", "counsel", "terra"], - }, - "stageDefinitions": { - "operational": "Code/tests/docs support an active demo path in GitHub.", - "supporting-operational": "Supports the demo as library, proof, receipt, telemetry, brand, trust, or workflow infrastructure.", - "blocked-upstream": "Requires upstream proof/CI/release correction before broad claims.", - "proxy-ready": "Patch/artifact exists but target repo write or owner action is required.", - "release-payload": "Included in checksummed/signed or generated payload artifacts.", - "generated-mirror": "Published/generated Hugging Face mirror of GitHub-backed content.", - "staged": "Prepared but not public/verified/live enough for active claims.", - "excluded-until-funded": "Visible scaffold, intentionally outside active-demo scope.", - }, - "canonicalNumbers": { - "githubPublicRepos": len(readiness["repos"]), - "hfModels": hf["counts"]["models"], - "hfDatasets": hf["counts"]["datasets"], - "hfSpaces": hf["counts"]["spaces"], - "theoremRuntimeEntries": len(theorem_manifest["entries"]), - }, - "repositories": repos, - "formulas": formulas, - "huggingFace": hf_items, - "uds": { - "stage": "operator-proof-point", - "evidence": [ - "artifacts/a11oy-uds/README.md", - "artifacts/a11oy-uds/docs/OPERATOR-QUICKSTART.md", - "docs/UDS_FRONTIER_GAP_MAP.md", - "deploy/MANIFEST.json" - ], - "blockedForCatalogGrade": [ - "Signed tar.zst/signature/sha256/pubkey assets must exist and verify for each v0.3.x release.", - "UDS Package CR / Helm / monitor / network policy integration is not complete for A11oy catalog-grade packaging.", - "Multi-repo mesh capstone requires real a11oy/amaru/sentra/rosie/vessels assets." - ] - } - } - - -def formula_stage(status: str) -> str: - if status == "verified-runtime": - return "operational" - if status.startswith("lean-backed"): - return "blocked-upstream" if "needs" in status else "supporting-operational" - if status == "historical-roadmap": - return "roadmap" - return "staged" - - -def next_action_for_repo(repo: dict) -> str: - name = repo["name"] - status = repo["functionalDemoStatus"] - if name == "a11oy": - return "Merge/proxy runtime hardening branches and republish HF payload from GitHub." - if name == "lutar-lean": - return "Apply kernel-green proxy patch in Lean-enabled runner; keep 7 sorries honest." - if name == "agi-forecast": - return "Merge FG-S1-S4 pipeline and competition-math v2 harness; preserve the recorded raw-score baseline unless a rerun proves improvement." - if name in {"amaru", "rosie", "sentra", "uds-mesh", "vessels"}: - return "Land repo-specific receipt/formula/UDS patches via proxy; do not fake signed assets." - if status == "scaffold-excluded": - return "Keep excluded until funded; do not market as active demo." - return "Keep GitHub evidence current and link from generated HF surfaces." - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", default=str(DEFAULT_OUTPUT)) - parser.add_argument("--check", action="store_true") - args = parser.parse_args() - - rendered = json.dumps(build_matrix(), indent=2) + "\n" - output = Path(args.output) - if args.check: - if not output.exists() or output.read_text(encoding="utf-8") != rendered: - print(f"Ecosystem stage matrix is stale: {output}") - return 1 - print(f"Ecosystem stage matrix is current: {output.relative_to(REPO_ROOT)}") - return 0 - output.parent.mkdir(parents=True, exist_ok=True) - output.write_text(rendered, encoding="utf-8") - print(f"Wrote ecosystem stage matrix: {output.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/build_operational_payload.py b/scripts/build_operational_payload.py deleted file mode 100644 index 52aa9a0d8baf5728a96407dedd7fb57845d3bb0d..0000000000000000000000000000000000000000 --- a/scripts/build_operational_payload.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/env python3 -"""Build or verify the A11oy operational payload tarball.""" - -from __future__ import annotations - -import argparse -import gzip -import hashlib -import io -import json -import shutil -import tarfile -from pathlib import Path - - -REPO_ROOT = Path.cwd() -DIST_DIR = REPO_ROOT / "dist" / "payload" -STAGE_DIR = DIST_DIR / "stage" / "a11oy-operational-payload" -ARCHIVE = DIST_DIR / "a11oy-operational-payload.tar.gz" -SHA256 = DIST_DIR / "a11oy-operational-payload.tar.gz.sha256" - - -def sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as handle: - for chunk in iter(lambda: handle.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def copy_file(source: str, target: str) -> None: - destination = STAGE_DIR / target - destination.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(REPO_ROOT / source, destination) - - -def copy_tree(source: str, target: str) -> None: - destination = STAGE_DIR / target - if destination.exists(): - shutil.rmtree(destination) - shutil.copytree(REPO_ROOT / source, destination) - - -def collect_stage_files() -> list[Path]: - return sorted(path for path in STAGE_DIR.rglob("*") if path.is_file()) - - -def write_stage_manifest() -> None: - files = [] - for path in collect_stage_files(): - rel = path.relative_to(STAGE_DIR).as_posix() - if rel == "PAYLOAD-MANIFEST.json": - continue - files.append( - { - "path": rel, - "size": path.stat().st_size, - "sha256": sha256_file(path), - } - ) - - aggregate_input = "\n".join( - f"{entry['path']}\0{entry['size']}\0{entry['sha256']}" for entry in files - ).encode("utf-8") - - manifest = { - "manifestVersion": 1, - "name": "a11oy-operational-payload", - "sourceRepository": "https://github.com/szl-holdings/a11oy", - "fileCount": len(files), - "aggregateSha256": hashlib.sha256(aggregate_input).hexdigest(), - "files": files, - "verification": { - "doctrine": [ - "pnpm test:doctrine", - "pnpm typecheck:doctrine", - "pnpm build:doctrine", - "pnpm ecosystem:audit", - "pnpm ecosystem:os:audit", - ], - "payload": [ - "pnpm payload:verify", - "pnpm payload:bundle:verify", - ], - }, - } - - (STAGE_DIR / "PAYLOAD-MANIFEST.json").write_text( - json.dumps(manifest, indent=2) + "\n", - encoding="utf-8", - ) - - -def stage_payload() -> None: - if STAGE_DIR.exists(): - shutil.rmtree(STAGE_DIR) - STAGE_DIR.mkdir(parents=True) - - for source in [ - "README.md", - "ROADMAP.md", - "CHANGELOG.md", - "LICENSE", - "CITATION.cff", - "package.json", - "pnpm-lock.yaml", - "pnpm-workspace.yaml", - "tsconfig.base.json", - ]: - copy_file(source, source) - - if (REPO_ROOT / "NOTICE").exists(): - copy_file("NOTICE", "NOTICE") - - for source in [ - "docs/org-repo-map.md", - "docs/ECOSYSTEM.md", - "docs/PROVENANCE.md", - "docs/SERIES_A_DILIGENCE.md", - "docs/SERIES_A_MARKET_EVIDENCE.md", - "docs/SUBSTRATE_REALITY_MAP.md", - "docs/INVESTOR_DEMO.md", - "docs/WARHACKER_UDS_PROOF_POINT.md", - "docs/PERPLEXITY_BRIEF.md", - "docs/ecosystem-registry.json", - "docs/ecosystem-readiness-report.json", - "docs/huggingface.md", - "docs/regulatory_to_lambda.md", - "benchmarks", - ".github/workflows/doctrine.yml", - ".github/workflows/huggingface.yml", - "scripts", - "deploy", - "huggingface", - "dist/huggingface/a11oy", - "web/packages/a11oy-core/package.json", - "web/packages/a11oy-core/tsconfig.json", - "web/packages/a11oy-core/src", - "web/packages/a11oy-core/dist", - "web/packages/a11oy-connection/package.json", - "web/packages/a11oy-connection/tsconfig.json", - "web/packages/a11oy-connection/src", - "web/packages/a11oy-connection/dist", - ]: - target = source - if source == "dist/huggingface/a11oy": - target = "publish/huggingface/a11oy" - if (REPO_ROOT / source).is_dir(): - copy_tree(source, target) - else: - copy_file(source, target) - - write_stage_manifest() - - -def deterministic_tar() -> None: - DIST_DIR.mkdir(parents=True, exist_ok=True) - with ARCHIVE.open("wb") as raw: - with gzip.GzipFile(fileobj=raw, mode="wb", filename="", mtime=0) as gz: - with tarfile.open(fileobj=gz, mode="w", format=tarfile.PAX_FORMAT) as tar: - for path in collect_stage_files(): - rel = path.relative_to(STAGE_DIR.parent).as_posix() - data = path.read_bytes() - info = tarfile.TarInfo(rel) - info.size = len(data) - info.mtime = 0 - info.uid = 0 - info.gid = 0 - info.uname = "" - info.gname = "" - info.mode = 0o644 - tar.addfile(info, io.BytesIO(data)) - - digest = sha256_file(ARCHIVE) - SHA256.write_text(f"{digest} {ARCHIVE.name}\n", encoding="utf-8") - - -def verify_bundle() -> int: - if not ARCHIVE.exists() or not SHA256.exists(): - print("Operational payload bundle is missing. Run: pnpm payload:bundle") - return 1 - - expected = SHA256.read_text(encoding="utf-8").split()[0] - actual = sha256_file(ARCHIVE) - if expected != actual: - print(f"Bundle checksum mismatch: expected {expected}, got {actual}") - return 1 - - required = { - "a11oy-operational-payload/PAYLOAD-MANIFEST.json", - "a11oy-operational-payload/deploy/MANIFEST.json", - "a11oy-operational-payload/publish/huggingface/a11oy/README.md", - "a11oy-operational-payload/publish/huggingface/a11oy/DEMO_RECEIPT_SAMPLE.jsonl", - "a11oy-operational-payload/web/packages/a11oy-core/dist/index.js", - "a11oy-operational-payload/web/packages/a11oy-connection/dist/index.js", - } - - with tarfile.open(ARCHIVE, mode="r:gz") as tar: - names = set(tar.getnames()) - missing = sorted(required - names) - if missing: - print("Bundle is missing required files:") - for name in missing: - print(f" - {name}") - return 1 - - print(f"Verified operational payload bundle: {ARCHIVE.relative_to(REPO_ROOT)}") - return 0 - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--verify", action="store_true") - args = parser.parse_args() - - if args.verify: - return verify_bundle() - - stage_payload() - deterministic_tar() - print(f"Built operational payload bundle: {ARCHIVE.relative_to(REPO_ROOT)}") - print(f"Wrote checksum sidecar: {SHA256.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/ecosystem_audit.py b/scripts/ecosystem_audit.py deleted file mode 100644 index 074a01f53ecf070b0ee9e37bef0a9b7fc00d013c..0000000000000000000000000000000000000000 --- a/scripts/ecosystem_audit.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the tracked SZL ecosystem registry and optional local checkouts.""" - -from __future__ import annotations - -import argparse -import json -import subprocess -from pathlib import Path - - -REPO_ROOT = Path.cwd() -REGISTRY_PATH = REPO_ROOT / "docs" / "ecosystem-registry.json" -LOCAL_ROOT = REPO_ROOT / ".repos" / "szl-holdings" - - -def git_head(path: Path) -> str | None: - try: - return subprocess.check_output( - ["git", "-C", str(path), "rev-parse", "--short=12", "HEAD"], - text=True, - stderr=subprocess.DEVNULL, - ).strip() - except (subprocess.CalledProcessError, FileNotFoundError): - return None - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--require-local", action="store_true") - args = parser.parse_args() - - registry = json.loads(REGISTRY_PATH.read_text(encoding="utf-8")) - repos = registry.get("repos", []) - names = [repo["name"] for repo in repos] - - errors: list[str] = [] - if registry.get("canonicalHub") != "a11oy": - errors.append("canonicalHub must be a11oy") - if len(names) != len(set(names)): - errors.append("repo names must be unique") - if len(repos) < 19: - errors.append("registry should cover all 19 visible public org repos") - - for repo in repos: - for field in ["name", "tier", "readiness", "role", "github", "defaultBranch"]: - if not repo.get(field): - errors.append(f"{repo.get('name', '')} missing {field}") - if not str(repo.get("github", "")).startswith("https://github.com/szl-holdings/"): - errors.append(f"{repo.get('name')} has non-SZL GitHub URL") - - local_name = repo["name"] - local_path = LOCAL_ROOT / local_name - if local_name == ".github": - local_path = LOCAL_ROOT / ".github" - if args.require_local and not (local_path / ".git").exists(): - errors.append(f"missing local checkout: {local_path}") - - if errors: - print("Ecosystem audit failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Ecosystem audit passed: {len(repos)} repos tracked") - if LOCAL_ROOT.exists(): - present = 0 - for repo in repos: - local_path = LOCAL_ROOT / repo["name"] - if repo["name"] == ".github": - local_path = LOCAL_ROOT / ".github" - head = git_head(local_path) - if head: - present += 1 - print(f"Local checkouts present: {present}/{len(repos)} under {LOCAL_ROOT}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/payload_manifest.py b/scripts/payload_manifest.py deleted file mode 100644 index 5aabfd61ccf12efc43be799643f10d42599ccaa8..0000000000000000000000000000000000000000 --- a/scripts/payload_manifest.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python3 -"""Build or verify deterministic SHA-256 manifests for payload directories.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -from pathlib import Path - - -def sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as handle: - for chunk in iter(lambda: handle.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def collect_files(root: Path, output: Path) -> list[dict[str, object]]: - files: list[dict[str, object]] = [] - output = output.resolve() - - for path in sorted(root.rglob("*")): - if not path.is_file(): - continue - if path.resolve() == output: - continue - - rel = path.relative_to(root).as_posix() - files.append( - { - "path": rel, - "size": path.stat().st_size, - "sha256": sha256_file(path), - } - ) - - return files - - -def build_manifest(root: Path, output: Path) -> dict[str, object]: - files = collect_files(root, output) - aggregate_input = "\n".join( - f"{entry['path']}\0{entry['size']}\0{entry['sha256']}" for entry in files - ).encode("utf-8") - - return { - "manifestVersion": 1, - "payloadRoot": root.name, - "generator": "scripts/payload_manifest.py", - "fileCount": len(files), - "aggregateSha256": hashlib.sha256(aggregate_input).hexdigest(), - "files": files, - } - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("payload_dir", type=Path) - parser.add_argument("--output", required=True, type=Path) - parser.add_argument("--verify", action="store_true") - args = parser.parse_args() - - root = args.payload_dir.resolve() - output = args.output.resolve() - manifest = build_manifest(root, output) - serialized = json.dumps(manifest, indent=2, sort_keys=False) + "\n" - - if args.verify: - existing = output.read_text(encoding="utf-8") - if existing != serialized: - rel_output = output.relative_to(Path.cwd()) if output.is_relative_to(Path.cwd()) else output - print(f"Payload manifest is stale: {rel_output}") - print( - "Run: python3 scripts/payload_manifest.py " - f"{args.payload_dir} --output {args.output}" - ) - return 1 - print(f"Verified payload manifest: {output.relative_to(Path.cwd())}") - return 0 - - output.write_text(serialized, encoding="utf-8") - print(f"Wrote payload manifest: {output.relative_to(Path.cwd())}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/prepare_huggingface_payload.py b/scripts/prepare_huggingface_payload.py deleted file mode 100644 index 38f5014cbbaa9875be60b0446ed024a758b5c714..0000000000000000000000000000000000000000 --- a/scripts/prepare_huggingface_payload.py +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env python3 -"""Prepare the Hugging Face payload directory from tracked source files.""" - -from __future__ import annotations - -import json -import shutil -import subprocess -from pathlib import Path - - -REPO_ROOT = Path.cwd() -OUT_DIR = REPO_ROOT / "dist" / "huggingface" / "a11oy" - - -def git_value(*args: str, fallback: str = "unknown") -> str: - try: - return subprocess.check_output( - ["git", *args], - cwd=REPO_ROOT, - text=True, - stderr=subprocess.DEVNULL, - ).strip() - except (subprocess.CalledProcessError, FileNotFoundError): - return fallback - - -def copy_text(source: str, target: str) -> None: - destination = OUT_DIR / target - destination.parent.mkdir(parents=True, exist_ok=True) - destination.write_text((REPO_ROOT / source).read_text(encoding="utf-8"), encoding="utf-8") - - -def copy_tree(source: str, target: str) -> None: - destination = OUT_DIR / target - if destination.exists(): - shutil.rmtree(destination) - shutil.copytree(REPO_ROOT / source, destination) - - -def main() -> int: - if OUT_DIR.exists(): - shutil.rmtree(OUT_DIR) - OUT_DIR.mkdir(parents=True) - - files = [ - ("huggingface/README.md", "README.md"), - ("huggingface/SHOWCASE.md", "SHOWCASE.md"), - ("huggingface/INVESTOR_BRIEF.md", "INVESTOR_BRIEF.md"), - ("huggingface/VERIFICATION.md", "VERIFICATION.md"), - ("huggingface/INNOVATIONS_DEEP_DIVE.md", "INNOVATIONS_DEEP_DIVE.md"), - ("huggingface/INTEGRATION_QUICKSTART.md", "INTEGRATION_QUICKSTART.md"), - ("huggingface/DEMO_RECEIPT_SAMPLE.jsonl", "DEMO_RECEIPT_SAMPLE.jsonl"), - ("LICENSE", "LICENSE"), - ("CITATION.cff", "CITATION.cff"), - ("README.md", "source/README.md"), - ("ROADMAP.md", "source/ROADMAP.md"), - ("CHANGELOG.md", "source/CHANGELOG.md"), - ("docs/org-repo-map.md", "source/docs/org-repo-map.md"), - ("docs/regulatory_to_lambda.md", "source/docs/regulatory_to_lambda.md"), - ("docs/huggingface.md", "source/docs/huggingface.md"), - ("docs/huggingface-ecosystem-manifest.json", "source/docs/huggingface-ecosystem-manifest.json"), - ("docs/huggingface-ecosystem-manifest.schema.json", "source/docs/huggingface-ecosystem-manifest.schema.json"), - ("docs/ecosystem-registry.json", "source/docs/ecosystem-registry.json"), - ("docs/PROVENANCE.md", "source/docs/PROVENANCE.md"), - ("docs/SERIES_A_DILIGENCE.md", "source/docs/SERIES_A_DILIGENCE.md"), - ("docs/SERIES_A_MARKET_EVIDENCE.md", "source/docs/SERIES_A_MARKET_EVIDENCE.md"), - ("docs/SUBSTRATE_REALITY_MAP.md", "source/docs/SUBSTRATE_REALITY_MAP.md"), - ("docs/INVESTOR_DEMO.md", "source/docs/INVESTOR_DEMO.md"), - ("docs/WARHACKER_UDS_PROOF_POINT.md", "source/docs/WARHACKER_UDS_PROOF_POINT.md"), - ("docs/PERPLEXITY_BRIEF.md", "source/docs/PERPLEXITY_BRIEF.md"), - ("docs/ECOSYSTEM.md", "source/docs/ECOSYSTEM.md"), - ("docs/ecosystem-readiness-report.json", "source/docs/ecosystem-readiness-report.json"), - ("deploy/MANIFEST.json", "payloads/deploy/MANIFEST.json"), - ("deploy/zarf.yaml", "payloads/deploy/zarf.yaml"), - ("deploy/attestations.jsonl", "payloads/deploy/attestations.jsonl"), - ("docs/huggingface-ecosystem-manifest.json", "HF_ECOSYSTEM_MANIFEST.json"), - ("package.json", "build/package.json"), - ("pnpm-lock.yaml", "build/pnpm-lock.yaml"), - ("pnpm-workspace.yaml", "build/pnpm-workspace.yaml"), - ("tsconfig.base.json", "build/tsconfig.base.json"), - ] - - for source, target in files: - copy_text(source, target) - - if (REPO_ROOT / "NOTICE").exists(): - copy_text("NOTICE", "NOTICE") - - copy_tree("deploy/manifests", "payloads/deploy/manifests") - copy_tree("huggingface/test-results", "test-results") - - metadata = { - "name": "a11oy", - "owner": "szl-holdings", - "sourceRepository": "https://github.com/szl-holdings/a11oy", - "sourceCommit": git_value("rev-parse", "HEAD"), - "sourceBranch": git_value("rev-parse", "--abbrev-ref", "HEAD"), - "doctrineCommands": [ - "pnpm test:doctrine", - "pnpm typecheck:doctrine", - "pnpm build:doctrine", - "pnpm ecosystem:audit", - "pnpm ecosystem:readiness", - "pnpm hf:ecosystem:audit", - "pnpm payload:verify", - "pnpm payload:huggingface", - "pnpm payload:bundle", - "pnpm payload:bundle:verify", - ], - "activeShowcaseRepos": [ - "a11oy", - "amaru", - "sentra", - "rosie", - "ouroboros", - "lutar-lean", - "ouroboros-thesis", - "uds-mesh", - "vsp-otel", - "vessels", - "agi-forecast", - "szl-trust", - "szl-brand", - "szl-cookbook", - ".github", - "platform", - ], - "excludedUntilFunded": ["carlota-jo", "counsel", "terra"], - "retiredOrDisallowedNames": ["KORA", "LUMINA", "PARAGON", "Lyte"], - "payloads": [ - { - "name": "deploy", - "manifest": "payloads/deploy/MANIFEST.json", - "zarf": "payloads/deploy/zarf.yaml", - "kubernetesManifests": "payloads/deploy/manifests/", - } - ], - "demoReceiptSample": "DEMO_RECEIPT_SAMPLE.jsonl", - "publishHygiene": { - "deleteStaleRemoteFiles": True, - "staleLegacyFiles": ["EVAL_TRACE_SAMPLE.jsonl"], - }, - } - - (OUT_DIR / "a11oy-metadata.json").write_text( - json.dumps(metadata, indent=2) + "\n", - encoding="utf-8", - ) - print(f"Prepared Hugging Face payload at {OUT_DIR.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/publish_huggingface_payload.py b/scripts/publish_huggingface_payload.py deleted file mode 100644 index 88cf069e0902289371d5e4d34faeba3ca9680adf..0000000000000000000000000000000000000000 --- a/scripts/publish_huggingface_payload.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 -"""Publish the prepared A11oy Hugging Face payload. - -Requires HF_TOKEN in the environment. The token is never printed. -""" - -from __future__ import annotations - -import argparse -import os -from pathlib import Path - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--repo-id", default="SZLHOLDINGS/a11oy-v19-substrate") - parser.add_argument("--repo-type", default="model") - parser.add_argument("--folder", default="dist/huggingface/a11oy") - parser.add_argument( - "--no-delete-stale", - action="store_true", - help="upload without pruning remote files absent from the generated payload", - ) - args = parser.parse_args() - - token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN") - if not token: - print("Missing HF_TOKEN. Add it as a GitHub Actions secret or export it locally.") - return 2 - - folder = Path(args.folder) - if not folder.exists(): - print(f"Missing payload folder: {folder}. Run `pnpm payload:huggingface` first.") - return 1 - - try: - from huggingface_hub import CommitOperationDelete, HfApi - except ImportError: - print("Missing huggingface_hub. Install with: python -m pip install --upgrade huggingface_hub") - return 2 - - api = HfApi(token=token) - api.create_repo(repo_id=args.repo_id, repo_type=args.repo_type, exist_ok=True) - - if not args.no_delete_stale: - local_files = { - path.relative_to(folder).as_posix() - for path in folder.rglob("*") - if path.is_file() - } - remote_files = set(api.list_repo_files(repo_id=args.repo_id, repo_type=args.repo_type)) - stale_files = sorted(remote_files - local_files) - if stale_files: - operations = [CommitOperationDelete(path_in_repo=path) for path in stale_files] - api.create_commit( - repo_id=args.repo_id, - repo_type=args.repo_type, - operations=operations, - commit_message="prune stale a11oy payload files", - ) - print(f"Pruned {len(stale_files)} stale Hugging Face files") - - api.upload_folder( - repo_id=args.repo_id, - repo_type=args.repo_type, - folder_path=str(folder), - commit_message="publish a11oy operational payload", - ) - print(f"Published Hugging Face payload to {args.repo_type}:{args.repo_id}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/validate_action_contract_manifest.py b/scripts/validate_action_contract_manifest.py deleted file mode 100644 index b947420c31366fd41a63e7ac901d515cfe8ef5f7..0000000000000000000000000000000000000000 --- a/scripts/validate_action_contract_manifest.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the original A11oy action-contract manifest.""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -CONTRACT_PATH = REPO_ROOT / "docs" / "action-contract-manifest.json" -PATTERNS_PATH = REPO_ROOT / "docs" / "public-pattern-source-manifest.json" - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def main() -> int: - errors: list[str] = [] - contract = load_json(CONTRACT_PATH) - patterns = load_json(PATTERNS_PATH) - pattern_ids = {pattern["id"] for pattern in patterns.get("patterns", [])} - - if contract.get("schemaVersion") != "a11oy.action-contract.v0.1": - errors.append("schemaVersion must be a11oy.action-contract.v0.1") - - if contract.get("claimStatus") not in {"roadmap", "verified-runtime", "release-payload"}: - errors.append("claimStatus must be roadmap, verified-runtime, or release-payload") - - clean_room = contract.get("cleanRoom", {}) - if clean_room.get("copyingRule") != "pattern-only": - errors.append("cleanRoom.copyingRule must be pattern-only") - if "endorsement" not in clean_room.get("endorsementBoundary", "").lower(): - errors.append("cleanRoom.endorsementBoundary must reject implied endorsement") - for pattern_id in clean_room.get("sourcePatternIds", []): - if pattern_id not in pattern_ids: - errors.append(f"unknown source pattern ID: {pattern_id}") - - identity = contract.get("identity", {}) - for field in ["actorId", "actorKind", "sessionId", "signerVerifier"]: - if not identity.get(field): - errors.append(f"identity.{field} is required") - - policy = contract.get("policy", {}) - for field in ["policyDocumentRef", "policyHash", "mandatoryAxes", "minimumLambdaCoverage", "approvalGate"]: - if field not in policy: - errors.append(f"policy.{field} is required") - policy_ref = policy.get("policyDocumentRef") - if policy_ref and not (REPO_ROOT / policy_ref).exists(): - errors.append(f"policyDocumentRef does not exist: {policy_ref}") - if not isinstance(policy.get("mandatoryAxes", []), list) or not policy.get("mandatoryAxes"): - errors.append("policy.mandatoryAxes must be a non-empty list") - if float(policy.get("minimumLambdaCoverage", 0)) < 0.0: - errors.append("policy.minimumLambdaCoverage must be non-negative") - - evidence = contract.get("evidence", {}) - for collection in ["manifestRefs", "attestationRefs", "testCommands", "localEvidenceRefs", "claimRefs"]: - if not isinstance(evidence.get(collection), list): - errors.append(f"evidence.{collection} must be a list") - for collection in ["manifestRefs", "attestationRefs", "localEvidenceRefs", "claimRefs"]: - for ref in evidence.get(collection, []): - if not (REPO_ROOT / ref).exists(): - errors.append(f"evidence ref does not exist: {ref}") - - receipt_sinks = contract.get("receiptSinks", {}) - if receipt_sinks.get("chainMode") != "hash-chain": - errors.append("receiptSinks.chainMode must be hash-chain") - if int(receipt_sinks.get("retentionDays", 0)) < 365: - errors.append("receiptSinks.retentionDays must be at least 365") - for field in ["primaryJsonl", "payloadBundlePath", "udsManifestRef"]: - if not receipt_sinks.get(field): - errors.append(f"receiptSinks.{field} is required") - - replay = contract.get("replayBounds", {}) - if not replay.get("idempotencyKey"): - errors.append("replayBounds.idempotencyKey is required") - if int(replay.get("maxReplays", 0)) < 1: - errors.append("replayBounds.maxReplays must be >= 1") - if int(replay.get("replayWindowSeconds", 0)) < 1: - errors.append("replayBounds.replayWindowSeconds must be >= 1") - for ref in replay.get("deterministicInputs", []): - if not (REPO_ROOT / ref).exists(): - errors.append(f"deterministic input does not exist: {ref}") - - egress = contract.get("egressLimits", {}) - if egress.get("defaultDeny") is not True: - errors.append("egressLimits.defaultDeny must be true") - denied = set(egress.get("deniedCapabilities", [])) - for capability in ["secret-export", "private-repo-ingestion", "self-approval"]: - if capability not in denied: - errors.append(f"egressLimits.deniedCapabilities missing {capability}") - - uds = contract.get("udsProofPoint", {}) - forbidden_text = " ".join(uds.get("forbiddenClaims", [])).lower() - for phrase in ["endorsed", "catalog accepted", "deploys to every uds"]: - if phrase not in forbidden_text: - errors.append(f"udsProofPoint.forbiddenClaims missing boundary phrase: {phrase}") - if "proof point" not in uds.get("wording", "").lower(): - errors.append("udsProofPoint.wording must use proof point language") - - if errors: - print("Action contract manifest validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {CONTRACT_PATH.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_anatomy_formula_runtime_map.py b/scripts/validate_anatomy_formula_runtime_map.py deleted file mode 100644 index 3906d99e89b1de783686c28f76051283ba8ea537..0000000000000000000000000000000000000000 --- a/scripts/validate_anatomy_formula_runtime_map.py +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the anatomy/formula/runtime map. - -The validator is intentionally lightweight and offline. It verifies that the -map has the expected structure, that referenced theorem-runtime IDs exist, and -that active local runtime/test paths are present in this checkout. -""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -MAP_PATH = REPO_ROOT / "docs" / "anatomy-formula-runtime-map.json" -THEOREM_MANIFEST_PATH = REPO_ROOT / "docs" / "theorem-runtime-manifest.json" - -ALLOWED_CLAIM_STATUSES = { - "verified-runtime", - "release-payload", - "lean-backed-current-green", - "lean-backed-needs-upstream-ci", - "lean-backed-needs-runtime", - "thesis-anchor", - "historical", - "historical-roadmap", - "roadmap", -} - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def main() -> int: - errors: list[str] = [] - data = load_json(MAP_PATH) - theorem_manifest = load_json(THEOREM_MANIFEST_PATH) - theorem_ids = {entry["id"] for entry in theorem_manifest.get("entries", [])} - - required_top = { - "schemaVersion", - "generatedBy", - "observedAt", - "canonicalHub", - "canonicalRule", - "autonomousLearningDoctrine", - "organs", - } - missing_top = sorted(required_top - data.keys()) - if missing_top: - errors.append(f"missing top-level fields: {', '.join(missing_top)}") - - if data.get("canonicalHub") != "a11oy": - errors.append("canonicalHub must be a11oy") - - doctrine = data.get("autonomousLearningDoctrine", {}) - if doctrine.get("promotionModel") != "human_promotion_required": - errors.append("autonomousLearningDoctrine.promotionModel must require human promotion") - forbidden_modes = set(doctrine.get("forbiddenModes", [])) - for mode in ["self_approve", "self_promote", "deploy", "publish"]: - if mode not in forbidden_modes: - errors.append(f"autonomousLearningDoctrine.forbiddenModes missing {mode}") - - organs = data.get("organs", []) - if not isinstance(organs, list) or not organs: - errors.append("organs must be a non-empty list") - - repos = set() - required_organ = { - "repo", - "anatomyRole", - "formulaRuntime", - "theoremAnchors", - "receiptSurface", - "testEvidence", - "udsStage", - "hfStage", - "claimStatus", - "autonomousLearningRole", - "gaps", - } - - for organ in organs: - repo = organ.get("repo", "") - if repo in repos: - errors.append(f"duplicate organ repo: {repo}") - repos.add(repo) - - missing = sorted(required_organ - organ.keys()) - if missing: - errors.append(f"{repo}: missing fields: {', '.join(missing)}") - - status = organ.get("claimStatus") - if status not in ALLOWED_CLAIM_STATUSES: - errors.append(f"{repo}: unsupported claimStatus {status!r}") - - for collection_name in [ - "formulaRuntime", - "theoremAnchors", - "receiptSurface", - "testEvidence", - "gaps", - ]: - if not isinstance(organ.get(collection_name), list): - errors.append(f"{repo}: {collection_name} must be a list") - - for formula in organ.get("formulaRuntime", []): - formula_status = formula.get("claimStatus") - if formula_status not in ALLOWED_CLAIM_STATUSES: - errors.append( - f"{repo}/{formula.get('formula', '')}: unsupported claimStatus {formula_status!r}" - ) - - manifest_id = formula.get("theoremRuntimeManifestId") - if manifest_id is not None and manifest_id not in theorem_ids: - errors.append( - f"{repo}/{formula.get('formula', '')}: unknown theoremRuntimeManifestId {manifest_id}" - ) - - runtime_file = formula.get("runtimeFile") - if runtime_file and not (REPO_ROOT / runtime_file).exists(): - errors.append( - f"{repo}/{formula.get('formula', '')}: runtimeFile does not exist: {runtime_file}" - ) - - required_repos = {"a11oy", "lutar-lean", "ouroboros-thesis", "agi-forecast"} - missing_repos = sorted(required_repos - repos) - if missing_repos: - errors.append(f"missing required organ repos: {', '.join(missing_repos)}") - - if errors: - print("Anatomy/formula/runtime map validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {MAP_PATH.relative_to(REPO_ROOT)} ({len(organs)} organs)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_benchmark_map.py b/scripts/validate_benchmark_map.py deleted file mode 100644 index b86a3e6499250f75e167606b0dfbdb48015310ec..0000000000000000000000000000000000000000 --- a/scripts/validate_benchmark_map.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the doctrine-safe benchmark map.""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -BENCHMARK_MAP = REPO_ROOT / "benchmarks" / "benchmark-map.json" -THEOREM_MANIFEST = REPO_ROOT / "docs" / "theorem-runtime-manifest.json" - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def main() -> int: - errors: list[str] = [] - data = load_json(BENCHMARK_MAP) - theorem_manifest = load_json(THEOREM_MANIFEST) - theorem_ids = {entry["id"] for entry in theorem_manifest.get("entries", [])} - - if data.get("publication", {}).get("publishMode") != "mirror-not-canonical": - errors.append("publication.publishMode must be mirror-not-canonical") - - entries = data.get("entries") - if not isinstance(entries, list) or not entries: - errors.append("entries must be a non-empty list") - entries = [] - - for entry in entries: - entry_id = entry.get("id", "") - if "mathcomp" in entry_id.lower(): - scoring = entry.get("scoring", {}) - if scoring.get("scoreType") != "raw_points": - errors.append(f"{entry_id}: competition-math benchmark entries must use raw_points") - - honesty = entry.get("honesty", {}) - disallowed = set(honesty.get("disallowedClaims", [])) - for phrase in ["solved the benchmark", "beat the benchmark", "AGI proven"]: - if phrase not in disallowed: - errors.append(f"{entry_id}: disallowedClaims missing {phrase!r}") - - allowed_claim = honesty.get("allowedClaim", "").lower() - if "cracked" in allowed_claim or "solved" in allowed_claim: - errors.append(f"{entry_id}: allowedClaim contains unsupported benchmark language") - - corpus = entry.get("corpus", {}) - if corpus.get("sealed") and corpus.get("digestStatus") != "sealed": - errors.append(f"{entry_id}: sealed corpus must have digestStatus=sealed") - - judges = entry.get("judges", []) - judge_ids = {judge.get("id") for judge in judges} - for required_judge in ["raw_grader", "proof_judge", "provenance_judge"]: - if required_judge not in judge_ids: - errors.append(f"{entry_id}: missing judge {required_judge}") - - receipts = entry.get("receipts", {}) - if receipts.get("required") is not True: - errors.append(f"{entry_id}: receipts.required must be true") - if receipts.get("chain") != "hash_chain": - errors.append(f"{entry_id}: receipts.chain must be hash_chain") - - for route in entry.get("formulaRoutes", []): - manifest_id = route.get("theoremRuntimeManifestId") - if manifest_id not in theorem_ids: - errors.append(f"{entry_id}: unknown formula route manifest ID {manifest_id}") - - gates = set(entry.get("ciGates", [])) - for gate in [ - "validate-benchmark-map", - "verify-formula-routes", - "reject-unsupported-benchmark-claims", - ]: - if gate not in gates: - errors.append(f"{entry_id}: missing CI gate {gate}") - - if errors: - print("Benchmark map validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {BENCHMARK_MAP.relative_to(REPO_ROOT)} ({len(entries)} entries)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_controls_evidence_map.py b/scripts/validate_controls_evidence_map.py deleted file mode 100644 index b73a2c7aacd79e14694a013c46b5bf4fb53b5b5f..0000000000000000000000000000000000000000 --- a/scripts/validate_controls_evidence_map.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the original A11oy controls evidence map.""" - -from __future__ import annotations - -import json -import re -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -MAP_PATH = REPO_ROOT / "docs" / "controls-evidence-map.json" - -ALLOWED_STATUSES = { - "verified-runtime", - "release-payload", - "lean-backed-current-green", - "lean-backed-needs-upstream-ci", - "thesis-anchor", - "historical", - "roadmap", -} -CONTROL_ID = re.compile(r"^A11OY-CE-\d{3}$") -FORBIDDEN_HF = {"canonical", "source-of-truth"} -FORBIDDEN_UDS = {"catalog-grade", "catalog-accepted", "endorsed"} - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def main() -> int: - errors: list[str] = [] - data = load_json(MAP_PATH) - - if "no external control catalog" not in data.get("cleanRoomRule", "").lower(): - errors.append("cleanRoomRule must reject copied external control catalogs") - - controls = data.get("controls", []) - if not isinstance(controls, list) or len(controls) < 5: - errors.append("controls must contain at least five controls") - controls = [] - - seen: set[str] = set() - required_fields = { - "controlId", - "title", - "description", - "claimStatus", - "evidencePaths", - "validationCommands", - "receiptHook", - "hfExposure", - "udsExposure", - "invariants", - } - - for control in controls: - control_id = control.get("controlId", "") - if control_id in seen: - errors.append(f"duplicate controlId: {control_id}") - seen.add(control_id) - - if not CONTROL_ID.match(control_id): - errors.append(f"{control_id}: controlId must match A11OY-CE-###") - - missing = sorted(required_fields - control.keys()) - if missing: - errors.append(f"{control_id}: missing fields: {', '.join(missing)}") - - status = control.get("claimStatus") - if status not in ALLOWED_STATUSES: - errors.append(f"{control_id}: unsupported claimStatus {status!r}") - - evidence_paths = control.get("evidencePaths", []) - if not isinstance(evidence_paths, list) or not evidence_paths: - errors.append(f"{control_id}: evidencePaths must be a non-empty list") - for evidence in evidence_paths: - if not (REPO_ROOT / evidence).exists(): - errors.append(f"{control_id}: evidence path does not exist: {evidence}") - - commands = control.get("validationCommands", []) - if not isinstance(commands, list) or not commands: - errors.append(f"{control_id}: validationCommands must be a non-empty list") - - receipt_hook = control.get("receiptHook", {}) - if not receipt_hook.get("eventType") or not receipt_hook.get("status"): - errors.append(f"{control_id}: receiptHook requires eventType and status") - if receipt_hook.get("status") not in {"runtime-available", "roadmap", "staged"}: - errors.append(f"{control_id}: unsupported receiptHook.status {receipt_hook.get('status')!r}") - - if status == "verified-runtime" and receipt_hook.get("status") != "runtime-available": - errors.append(f"{control_id}: verified-runtime controls need runtime-available receipt hook") - - hf_exposure = control.get("hfExposure", "").lower() - if hf_exposure in FORBIDDEN_HF: - errors.append(f"{control_id}: hfExposure cannot be canonical/source-of-truth") - - uds_exposure = control.get("udsExposure", "").lower() - if uds_exposure in FORBIDDEN_UDS: - errors.append(f"{control_id}: udsExposure cannot imply catalog/endorsement") - - invariants = control.get("invariants", []) - if not isinstance(invariants, list) or not invariants: - errors.append(f"{control_id}: invariants must be a non-empty list") - - required = {"A11OY-CE-001", "A11OY-CE-002", "A11OY-CE-005", "A11OY-CE-008"} - missing_required = sorted(required - seen) - if missing_required: - errors.append(f"missing required controls: {', '.join(missing_required)}") - - if errors: - print("Controls evidence map validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {MAP_PATH.relative_to(REPO_ROOT)} ({len(controls)} controls)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_cross_repo_handoff_manifest.py b/scripts/validate_cross_repo_handoff_manifest.py deleted file mode 100644 index 1876de5d3fb2a594734fd9e1ff8b4294d5aacdec..0000000000000000000000000000000000000000 --- a/scripts/validate_cross_repo_handoff_manifest.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the cross-repo handoff manifest.""" - -from __future__ import annotations - -import hashlib -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -MANIFEST = REPO_ROOT / "docs" / "cross-repo-handoff-manifest.json" -ACCESS = REPO_ROOT / "docs" / "github-enterprise-access-checklist.json" - -ALLOWED_ACCESS_STATES = {"blocked-by-access", "write-ready"} -ALLOWED_HANDOFF_STATES = { - "ready-for-owner-apply", - "needs-target-runner", - "blocked-by-access", - "complete", -} -ALLOWED_CLAIM_STATUSES = { - "verified-runtime", - "release-payload", - "lean-backed-needs-upstream-ci", - "roadmap", -} -FORBIDDEN_COMPLETE_PHRASES = [ - "production-ready", - "all green", - "zero sorry", - "catalog accepted", - "endorsed", - "deployed to target repo", -] - - -def sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as handle: - for chunk in iter(lambda: handle.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def main() -> int: - errors: list[str] = [] - manifest = json.loads(MANIFEST.read_text(encoding="utf-8")) - access = json.loads(ACCESS.read_text(encoding="utf-8")) - target_repos = {entry["repo"] for entry in access.get("targetRepos", [])} - - rule = manifest.get("canonicalRule", "").lower() - if "not complete until" not in rule or "target repo" not in rule: - errors.append("canonicalRule must say handoffs are not complete until target repo evidence exists") - - forbidden_claims = {claim.lower() for claim in manifest.get("forbiddenClaims", [])} - for phrase in FORBIDDEN_COMPLETE_PHRASES: - if phrase not in forbidden_claims: - errors.append(f"forbiddenClaims missing {phrase!r}") - - handoffs = manifest.get("handoffs", []) - if not isinstance(handoffs, list) or not handoffs: - errors.append("handoffs must be a non-empty list") - handoffs = [] - - seen: set[str] = set() - required_fields = { - "handoffId", - "targetRepo", - "targetBranch", - "patchPath", - "statusPath", - "patchSha256", - "accessState", - "handoffState", - "localValidation", - "targetValidationRequired", - "completionRequires", - "claimStatus", - } - - for handoff in handoffs: - handoff_id = handoff.get("handoffId", "") - if handoff_id in seen: - errors.append(f"duplicate handoffId: {handoff_id}") - seen.add(handoff_id) - - missing = sorted(required_fields - handoff.keys()) - if missing: - errors.append(f"{handoff_id}: missing fields: {', '.join(missing)}") - - target_repo = handoff.get("targetRepo") - if target_repo not in target_repos: - errors.append(f"{handoff_id}: targetRepo not in access checklist: {target_repo}") - - if handoff.get("accessState") not in ALLOWED_ACCESS_STATES: - errors.append(f"{handoff_id}: unsupported accessState {handoff.get('accessState')!r}") - if handoff.get("handoffState") not in ALLOWED_HANDOFF_STATES: - errors.append(f"{handoff_id}: unsupported handoffState {handoff.get('handoffState')!r}") - if handoff.get("claimStatus") not in ALLOWED_CLAIM_STATUSES: - errors.append(f"{handoff_id}: unsupported claimStatus {handoff.get('claimStatus')!r}") - - patch_path = REPO_ROOT / str(handoff.get("patchPath", "")) - status_path = REPO_ROOT / str(handoff.get("statusPath", "")) - if not patch_path.exists(): - errors.append(f"{handoff_id}: patchPath does not exist: {handoff.get('patchPath')}") - else: - actual = sha256_file(patch_path) - if actual != handoff.get("patchSha256"): - errors.append(f"{handoff_id}: patchSha256 mismatch: expected {handoff.get('patchSha256')}, got {actual}") - if not status_path.exists(): - errors.append(f"{handoff_id}: statusPath does not exist: {handoff.get('statusPath')}") - - for list_field in ["localValidation", "targetValidationRequired", "completionRequires"]: - if not isinstance(handoff.get(list_field), list) or not handoff.get(list_field): - errors.append(f"{handoff_id}: {list_field} must be a non-empty list") - - if handoff.get("handoffState") == "complete": - completion = " ".join(handoff.get("completionRequires", [])).lower() - if "target ci green" not in completion or "target pr" not in completion: - errors.append(f"{handoff_id}: complete handoff requires target PR and target CI evidence") - - if target_repo == "szl-holdings/lutar-lean": - target_validation = " ".join(handoff.get("targetValidationRequired", [])).lower() - if "lake build" not in target_validation: - errors.append(f"{handoff_id}: lutar-lean handoff must require lake build") - - if errors: - print("Cross-repo handoff manifest validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {MANIFEST.relative_to(REPO_ROOT)} ({len(handoffs)} handoffs)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_github_access_checklist.py b/scripts/validate_github_access_checklist.py deleted file mode 100644 index 727e6d80a73432aec8b3097b206fe6eb0cf5932f..0000000000000000000000000000000000000000 --- a/scripts/validate_github_access_checklist.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the GitHub Enterprise access checklist.""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -CHECKLIST = REPO_ROOT / "docs" / "github-enterprise-access-checklist.json" - - -def main() -> int: - errors: list[str] = [] - data = json.loads(CHECKLIST.read_text(encoding="utf-8")) - - if data.get("seatsAloneGrantWriteAccess") is not False: - errors.append("seatsAloneGrantWriteAccess must be false") - - if data.get("currentKnownWritableRepo") != "szl-holdings/a11oy": - errors.append("currentKnownWritableRepo must be szl-holdings/a11oy") - - rule = data.get("canonicalRule", "").lower() - for phrase in ["accepted org membership", "repo/team write permission", "token or github app scope"]: - if phrase not in rule: - errors.append(f"canonicalRule must mention {phrase!r}") - - scopes = " ".join(data.get("requiredTokenScopes", [])).lower() - for required in ["contents: read and write", "sso authorization"]: - if required not in scopes: - errors.append(f"requiredTokenScopes must mention {required!r}") - - checks = data.get("readOnlyChecks", []) - if not isinstance(checks, list) or not checks: - errors.append("readOnlyChecks must be a non-empty list") - for command in checks: - if not isinstance(command, str) or not command.startswith("gh "): - errors.append(f"readOnlyChecks must use gh read-only commands, got {command!r}") - forbidden = [" pr create", " pr merge", " issue create", " repo edit", " api -X PATCH", " api -X POST", " api -X PUT", " api -X DELETE"] - if any(token in command for token in forbidden): - errors.append(f"readOnlyChecks contains write-like command: {command}") - - targets = data.get("targetRepos", []) - if not isinstance(targets, list) or len(targets) < 8: - errors.append("targetRepos must include the sibling repos needed for cross-repo phases") - targets = [] - - repos = set() - for target in targets: - repo = target.get("repo") - if repo in repos: - errors.append(f"duplicate target repo: {repo}") - repos.add(repo) - if target.get("minimumPermission") != "write": - errors.append(f"{repo}: minimumPermission must be write") - for field in ["phaseUnlocked", "currentFallback"]: - if not target.get(field): - errors.append(f"{repo}: missing {field}") - - for required_repo in [ - "szl-holdings/.github", - "szl-holdings/lutar-lean", - "szl-holdings/agi-forecast", - "szl-holdings/uds-mesh", - "szl-holdings/vessels", - ]: - if required_repo not in repos: - errors.append(f"missing target repo: {required_repo}") - - boundaries = " ".join(data.get("doctrineBoundaries", [])).lower() - for phrase in ["do not commit tokens", "do not claim all lean green", "do not claim defense unicorns endorsement"]: - if phrase not in boundaries: - errors.append(f"doctrineBoundaries must include {phrase!r}") - - if errors: - print("GitHub access checklist validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {CHECKLIST.relative_to(REPO_ROOT)} ({len(targets)} target repos)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_hf_test_results_manifest.py b/scripts/validate_hf_test_results_manifest.py deleted file mode 100644 index 68b7d28e87ce57b47f9d13a61a30e3962cc43427..0000000000000000000000000000000000000000 --- a/scripts/validate_hf_test_results_manifest.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the staged Hugging Face test-results manifest.""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -MANIFEST_PATH = REPO_ROOT / "huggingface" / "test-results" / "MANIFEST.json" -BENCHMARK_MAP = REPO_ROOT / "benchmarks" / "benchmark-map.json" - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def main() -> int: - errors: list[str] = [] - manifest = load_json(MANIFEST_PATH) - benchmark_map = load_json(BENCHMARK_MAP) - - publication = manifest.get("publication", {}) - if publication.get("repo_type") != "dataset": - errors.append("publication.repo_type must be dataset") - if publication.get("publish_mode") != "mirror-not-canonical": - errors.append("publication.publish_mode must be mirror-not-canonical") - if publication.get("canonical_source") != "https://github.com/szl-holdings/a11oy": - errors.append("publication.canonical_source must point to a11oy GitHub") - - if manifest.get("claim_status") != "staged-no-live-score": - errors.append("claim_status must remain staged-no-live-score until sealed results exist") - - disallowed = {claim.lower() for claim in manifest.get("disallowed_claims", [])} - for phrase in ["solved the benchmark", "beat the benchmark", "agi proven", "hf is canonical"]: - if phrase not in disallowed: - errors.append(f"disallowed_claims missing {phrase!r}") - - allowed_text = " ".join(manifest.get("allowed_public_wording", [])).lower() - for forbidden in ["cracked", "solved", "leaderboard"]: - if forbidden in allowed_text: - errors.append(f"allowed_public_wording contains unsupported word {forbidden!r}") - - benchmark_ref = manifest.get("benchmark_map", {}) - if benchmark_ref.get("path") != "benchmarks/benchmark-map.json": - errors.append("benchmark_map.path must be benchmarks/benchmark-map.json") - entry_id = benchmark_ref.get("entry_id") - map_entry_ids = {entry.get("id") for entry in benchmark_map.get("entries", [])} - if entry_id not in map_entry_ids: - errors.append(f"benchmark_map.entry_id not found in benchmark map: {entry_id}") - - corpus = manifest.get("corpus", {}) - if corpus.get("sealed") is not False: - errors.append("corpus.sealed must be false in staged manifest") - if corpus.get("problem_text_included") is not False: - errors.append("corpus.problem_text_included must be false") - if int(corpus.get("problem_count", -1)) != 0: - errors.append("corpus.problem_count must be 0 until corpus is sealed") - - runs = manifest.get("runs", []) - if runs: - errors.append("runs must be empty until a sealed receipt-backed run exists") - - # Guard against accidentally adding live-looking result/receipt files before - # the benchmark doctrine gates are implemented. - for forbidden_dir in [ - REPO_ROOT / "huggingface" / "test-results" / "results", - REPO_ROOT / "huggingface" / "test-results" / "receipts", - ]: - if forbidden_dir.exists() and any(forbidden_dir.rglob("*")): - errors.append(f"{forbidden_dir.relative_to(REPO_ROOT)} must remain empty in staged manifest") - - commands = manifest.get("validation", {}).get("commands", []) - for command in ["npm run hf:test-results:audit", "npm run benchmark:audit"]: - if command not in commands: - errors.append(f"validation.commands missing {command}") - - if errors: - print("HF test-results manifest validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {MANIFEST_PATH.relative_to(REPO_ROOT)}") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_phase_completion_manifest.py b/scripts/validate_phase_completion_manifest.py deleted file mode 100644 index 268cc28135265d88f4ecd7e4cafca079be29e7cc..0000000000000000000000000000000000000000 --- a/scripts/validate_phase_completion_manifest.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python3 -"""Validate A11oy phase completion manifest.""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - - -REPO_ROOT = Path(__file__).resolve().parents[1] -MANIFEST = REPO_ROOT / "docs" / "phase-completion-manifest.json" -REPORT = REPO_ROOT / "docs" / "PHASE_COMPLETION_REPORT.md" - -ALLOWED_STATUSES = { - "complete-for-current-branch", - "runtime-helper-complete", - "runtime-helper-complete-harness-staged", - "schema-complete-no-live-score", - "access-pending-handoff-queued", - "generated-payload-ready", -} - - -def main() -> int: - errors: list[str] = [] - data = json.loads(MANIFEST.read_text(encoding="utf-8")) - - if not REPORT.exists(): - errors.append("PHASE_COMPLETION_REPORT.md is missing") - - rule = data.get("canonicalRule", "").lower() - if "sibling repo phases remain access-pending" not in rule: - errors.append("canonicalRule must keep sibling repo phases access-pending") - if data.get("a11oyLocalStatus") != "complete-for-current-branch": - errors.append("a11oyLocalStatus must be complete-for-current-branch") - if data.get("crossRepoStatus") != "access-pending-handoff-queued": - errors.append("crossRepoStatus must be access-pending-handoff-queued") - - forbidden = " ".join(data.get("forbiddenClaims", [])).lower() - for phrase in ["zero sorry", "solved the benchmark", "uds catalog accepted", "hf is canonical"]: - if phrase not in forbidden: - errors.append(f"forbiddenClaims missing {phrase!r}") - - phases = data.get("phases", []) - if not isinstance(phases, list) or len(phases) < 7: - errors.append("phases must contain at least seven phase entries") - phases = [] - - seen: set[str] = set() - for phase in phases: - phase_id = phase.get("id", "") - if phase_id in seen: - errors.append(f"duplicate phase id: {phase_id}") - seen.add(phase_id) - if phase.get("status") not in ALLOWED_STATUSES: - errors.append(f"{phase_id}: unsupported status {phase.get('status')!r}") - artifacts = phase.get("artifacts", []) - if not isinstance(artifacts, list) or not artifacts: - errors.append(f"{phase_id}: artifacts must be non-empty") - for artifact in artifacts: - if not (REPO_ROOT / artifact).exists(): - errors.append(f"{phase_id}: artifact does not exist: {artifact}") - commands = phase.get("validationCommands", []) - if not isinstance(commands, list) or not commands: - errors.append(f"{phase_id}: validationCommands must be non-empty") - - requires = " ".join(data.get("completionRequiresForSiblingRepos", [])).lower() - for phrase in ["target repo write-ready access", "target ci green"]: - if phrase not in requires: - errors.append(f"completionRequiresForSiblingRepos missing {phrase!r}") - - if errors: - print("Phase completion manifest validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {MANIFEST.relative_to(REPO_ROOT)} ({len(phases)} phases)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_public_pattern_manifest.py b/scripts/validate_public_pattern_manifest.py deleted file mode 100644 index 2e5c22b83179a3ef3cea5d244531d84861ebd4ab..0000000000000000000000000000000000000000 --- a/scripts/validate_public_pattern_manifest.py +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the public-pattern synthesis manifest. - -The manifest is a clean-room guardrail: public sources can inspire original -SZL/A11oy work, but private/unlicensed copying is not allowed. -""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path -from urllib.parse import urlparse - - -REPO_ROOT = Path(__file__).resolve().parents[1] -MANIFEST_PATH = REPO_ROOT / "docs" / "public-pattern-source-manifest.json" - -ALLOWED_STATUSES = { - "verified-runtime", - "release-payload", - "lean-backed-current-green", - "lean-backed-needs-upstream-ci", - "thesis-anchor", - "historical", - "roadmap", -} - - -def load_json(path: Path) -> dict: - return json.loads(path.read_text(encoding="utf-8")) - - -def is_public_url(value: str) -> bool: - parsed = urlparse(value) - return parsed.scheme in {"https", "http"} and bool(parsed.netloc) - - -def main() -> int: - errors: list[str] = [] - manifest = load_json(MANIFEST_PATH) - - if manifest.get("privateIngestionAllowed") is not False: - errors.append("privateIngestionAllowed must be false") - - copying_rule = manifest.get("copyingRule", "").lower() - for required in ["pattern-only", "no upstream code", "private material"]: - if required not in copying_rule: - errors.append(f"copyingRule must include {required!r}") - - if "endorsement" not in manifest.get("endorsementBoundary", "").lower(): - errors.append("endorsementBoundary must explicitly reject implied endorsement") - - queues = manifest.get("sourceQueues", []) - if not isinstance(queues, list) or not queues: - errors.append("sourceQueues must be a non-empty list") - queues = [] - - queue_ids: set[str] = set() - for queue in queues: - queue_id = queue.get("id", "") - if queue_id in queue_ids: - errors.append(f"duplicate source queue id: {queue_id}") - queue_ids.add(queue_id) - - public_url = queue.get("publicUrl") - if not isinstance(public_url, str) or not is_public_url(public_url): - errors.append(f"{queue_id}: publicUrl must be an http(s) URL") - - audit_mode = queue.get("auditMode", "") - if "public" not in audit_mode and "authorized" not in audit_mode: - errors.append(f"{queue_id}: auditMode must be public/authorized scoped") - - patterns = manifest.get("patterns", []) - if not isinstance(patterns, list) or not patterns: - errors.append("patterns must be a non-empty list") - patterns = [] - - pattern_ids: set[str] = set() - required_pattern_fields = { - "id", - "name", - "sourceQueueIds", - "publicSourceCategories", - "licenseCaveat", - "a11oyTransform", - "localEvidence", - "validationCommands", - "claimStatus", - } - for pattern in patterns: - pattern_id = pattern.get("id", "") - if pattern_id in pattern_ids: - errors.append(f"duplicate pattern id: {pattern_id}") - pattern_ids.add(pattern_id) - - missing = sorted(required_pattern_fields - pattern.keys()) - if missing: - errors.append(f"{pattern_id}: missing fields: {', '.join(missing)}") - - if pattern.get("claimStatus") not in ALLOWED_STATUSES: - errors.append(f"{pattern_id}: unsupported claimStatus {pattern.get('claimStatus')!r}") - - for queue_id in pattern.get("sourceQueueIds", []): - if queue_id not in queue_ids: - errors.append(f"{pattern_id}: unknown sourceQueueId {queue_id}") - - license_caveat = pattern.get("licenseCaveat", "").lower() - if not any(token in license_caveat for token in ["copy", "license", "redistribute"]): - errors.append(f"{pattern_id}: licenseCaveat must state copying/license boundary") - - transform = pattern.get("a11oyTransform", "").lower() - if "a11oy" not in transform and "szl" not in transform: - errors.append(f"{pattern_id}: a11oyTransform must describe original SZL/A11oy work") - - local_evidence = pattern.get("localEvidence", []) - if not isinstance(local_evidence, list) or not local_evidence: - errors.append(f"{pattern_id}: localEvidence must be a non-empty list") - for evidence in local_evidence: - # URLs are allowed as evidence, but local paths should exist when - # they are part of this checkout. - if isinstance(evidence, str) and not is_public_url(evidence): - if not (REPO_ROOT / evidence).exists(): - errors.append(f"{pattern_id}: local evidence path does not exist: {evidence}") - - commands = pattern.get("validationCommands", []) - if not isinstance(commands, list) or not commands: - errors.append(f"{pattern_id}: validationCommands must be a non-empty list") - - if errors: - print("Public pattern manifest validation failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Validated {MANIFEST_PATH.relative_to(REPO_ROOT)} ({len(patterns)} patterns)") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/scripts/validate_theorem_runtime_manifest.py b/scripts/validate_theorem_runtime_manifest.py deleted file mode 100644 index a0b863a941e38538e4974ebec3765906478add1a..0000000000000000000000000000000000000000 --- a/scripts/validate_theorem_runtime_manifest.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python3 -"""Validate the A11oy theorem-to-runtime manifest.""" - -from __future__ import annotations - -import argparse -import json -from pathlib import Path - - -REPO_ROOT = Path.cwd() -MANIFEST = REPO_ROOT / "docs" / "theorem-runtime-manifest.json" -VALID_STATUSES = { - "verified-runtime", - "lean-backed-current-green", - "lean-backed-needs-upstream-ci", - "lean-backed-needs-runtime", - "historical-roadmap", - "roadmap", - # staged-advisory: honest, NOT-proven status (SZL Doctrine v11). The gate - # ships enforced:false/severity:warning while its Lean proof is pending, so - # it must never be counted as proven. Honesty semantics enforced below. - "staged-advisory", -} - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--manifest", default=str(MANIFEST)) - args = parser.parse_args() - path = Path(args.manifest) - data = json.loads(path.read_text(encoding="utf-8")) - errors: list[str] = [] - - seen = set() - for entry in data.get("entries", []): - entry_id = entry.get("id") - if not entry_id: - errors.append("entry missing id") - continue - if entry_id in seen: - errors.append(f"duplicate entry id: {entry_id}") - seen.add(entry_id) - - status = entry.get("claimStatus") - if status not in VALID_STATUSES: - errors.append(f"{entry_id}: invalid claimStatus {status}") - - for field in ["runtimeFile", "exportFile", "testFile"]: - value = entry.get(field) - if value and not (REPO_ROOT / value).exists(): - errors.append(f"{entry_id}: missing {field} path {value}") - - if status == "verified-runtime" and not entry.get("validationCommand"): - errors.append(f"{entry_id}: verified-runtime requires validationCommand") - - if status == "staged-advisory": - # Honesty guard (SZL Doctrine v11): staged-advisory entries are NOT - # proven. They must self-identify as advisory and carry a caveat so - # they can never be silently promoted into a proven claim. - if entry.get("stagedAdvisory") is not True: - errors.append( - f"{entry_id}: staged-advisory requires stagedAdvisory: true" - ) - if not entry.get("caveat"): - errors.append( - f"{entry_id}: staged-advisory requires a caveat" - ) - if entry.get("leanStatus") in {"proven", "verified", "lean-proven"}: - errors.append( - f"{entry_id}: staged-advisory cannot have leanStatus " - f"{entry.get('leanStatus')!r} (not yet proven)" - ) - - if errors: - print("Theorem runtime manifest failed:") - for error in errors: - print(f" - {error}") - return 1 - - print(f"Theorem runtime manifest OK: {len(seen)} entries") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/tests/test_be_hardening.py b/tests/test_be_hardening.py deleted file mode 100644 index 1b5fd0fd7ce6a7e4ce66ee6e6e61aafe13411aa7..0000000000000000000000000000000000000000 --- a/tests/test_be_hardening.py +++ /dev/null @@ -1,163 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 -# Doctrine v11 LOCKED 749/14/163 @ c7c0ba17 · Λ = Conjecture 1. -""" -test_be_hardening.py — real HTTP tests for the backend hardening surface. - -Uses FastAPI's TestClient against a freshly hardened app. NO mocks: the Khipu -store writes to a real temp SQLite DB, the rate limiter counts real requests, -and OpenAPI is the real auto-generated schema. Restart durability is proven by -constructing a second DurableKhipu over the same on-disk path. - -Run: pytest -q test_be_hardening.py -""" -from __future__ import annotations - -import os -import tempfile - -import pytest -from fastapi import FastAPI -from fastapi.testclient import TestClient - -import szl_be_hardening as H - -ORGAN = "testorgan" - - -@pytest.fixture() -def client(tmp_path): - app = FastAPI(title="hardening-test", version="0.0.0") - db_path = os.path.join(tmp_path, "khipu_test.sqlite3") - report = H.harden(app, organ=ORGAN, khipu_path=db_path) - assert report.get("ok") is True - c = TestClient(app) - c._db_path = db_path # type: ignore[attr-defined] - return c - - -# ---- 4: health probes ------------------------------------------------------ -def test_healthz_liveness(client): - r = client.get("/healthz") - assert r.status_code == 200 - body = r.json() - assert body["status"] == "ok" - assert body["doctrine"] == "v11" - assert body["lock"] == "749/14/163" - - -def test_readyz_checks_chain(client): - r = client.get(f"/api/{ORGAN}/v1/readyz") - assert r.status_code == 200 - body = r.json() - assert body["status"] == "ready" - assert body["khipu_chain_ok"] is True - assert body["khipu_durable"] is True - assert body["khipu_backend"] == "sqlite" - - -# ---- 1: real input validation (pydantic) ----------------------------------- -def test_echo_valid(client): - r = client.post(f"/api/{ORGAN}/v1/be/echo", json={"message": "hi"}) - assert r.status_code == 200 - assert r.json()["echo"] == "hi" - - -def test_echo_rejects_raw_dict_extra_fields(client): - r = client.post(f"/api/{ORGAN}/v1/be/echo", json={"message": "hi", "evil": 1}) - assert r.status_code == 422 - assert r.json()["error"]["code"] == "validation_error" - assert r.json()["error"]["doctrine"] == "v11" - - -def test_echo_rejects_missing_field(client): - r = client.post(f"/api/{ORGAN}/v1/be/echo", json={}) - assert r.status_code == 422 - assert r.json()["error"]["doctrine"] == "v11" - - -# ---- 6: error envelopes ---------------------------------------------------- -def test_error_envelope_on_404(client): - r = client.get("/api/nope/v1/does-not-exist") - assert r.status_code == 404 - err = r.json()["error"] - assert set(err.keys()) >= {"code", "message", "trace_id", "doctrine"} - assert err["doctrine"] == "v11" - - -def test_trace_headers_present(client): - r = client.get("/healthz") - assert r.headers.get("X-Trace-Id") - assert r.headers.get("X-Span-Id") - - -# ---- 3: real OpenAPI ------------------------------------------------------- -def test_openapi_served_at_organ_path(client): - r = client.get(f"/api/{ORGAN}/openapi.json") - assert r.status_code == 200 - spec = r.json() - assert spec["openapi"].startswith("3.") - # real generated paths include our hardening endpoints - assert any("/khipu/verify" in p for p in spec["paths"]) - assert any("/echo" in p for p in spec["paths"]) - - -# ---- 7: durable persistence (survives restart) ----------------------------- -def test_khipu_append_and_verify(client): - r = client.post(f"/api/{ORGAN}/v1/be/khipu/append", - json={"action": "test.action", "payload": {"k": 1}}) - assert r.status_code == 200 - assert r.json()["ok"] is True - v = client.get(f"/api/{ORGAN}/v1/be/khipu/verify").json() - assert v["ok"] is True - assert v["depth"] >= 1 - assert v["durable"] is True - - -def test_khipu_survives_restart(client): - # append two receipts via the live API - for i in range(2): - client.post(f"/api/{ORGAN}/v1/be/khipu/append", - json={"action": f"a{i}", "payload": {"i": i}}) - depth_before = client.get(f"/api/{ORGAN}/v1/be/khipu/verify").json()["depth"] - assert depth_before >= 2 - # simulate a process restart: brand-new store over the SAME on-disk path - reopened = H.DurableKhipu(ORGAN, path=client._db_path) - ok, depth, brk = reopened.verify() - assert ok is True - assert depth == depth_before # receipts survived - assert brk == -1 - - -def test_khipu_append_rejects_bad_body(client): - r = client.post(f"/api/{ORGAN}/v1/be/khipu/append", json={"payload": {}}) - assert r.status_code == 422 # missing required 'action' - - -# ---- 9: honest footer matches the exact v11 lock --------------------------- -def test_honest_footer_exact_lock(client): - body = client.get("/honest").json() - lock = body["doctrine_lock"] - assert lock["doctrine"] == "v11" - assert lock["state"] == "LOCKED" - assert (lock["declarations"], lock["axioms"], lock["sorries"]) == (749, 14, 163) - assert lock["commit"] == "c7c0ba17" - assert lock["lambda"] == "Conjecture 1" - assert body["footer"] == "Doctrine v11 LOCKED 749/14/163 @ c7c0ba17 · Λ = Conjecture 1" - - -# ---- 2: rate limiting (60/min/IP) ------------------------------------------ -def test_rate_limit_enforced(): - # isolated app/client so other tests' requests don't pollute the window - app = FastAPI() - with tempfile.TemporaryDirectory() as d: - H.harden(app, organ="rl", khipu_path=os.path.join(d, "k.sqlite3")) - c = TestClient(app) - statuses = [c.get("/healthz").status_code for _ in range(H.RATE_LIMIT_PER_MIN + 5)] - assert 429 in statuses, "expected at least one 429 after exceeding 60/min" - assert statuses[:H.RATE_LIMIT_PER_MIN] == [200] * H.RATE_LIMIT_PER_MIN - # the 429 body is the uniform error envelope - last = c.get("/healthz") - assert last.status_code == 429 - assert last.json()["error"]["code"] == "rate_limited" - assert last.json()["error"]["doctrine"] == "v11" diff --git a/tests/test_conduction_aphasia.py b/tests/test_conduction_aphasia.py deleted file mode 100644 index 99a3c88c7e2ea83abb7e56b41b9e0b2c4ca9b6c4..0000000000000000000000000000000000000000 --- a/tests/test_conduction_aphasia.py +++ /dev/null @@ -1,319 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 -# Authored by Yachay (CTO). Co-Authored-By: Perplexity Computer Agent. -# Doctrine v11 LOCKED 749/14/163 · Λ Conjecture 1 · SLSA L1 honest -""" -tests/test_conduction_aphasia.py — pytest suite for the Conduction-Aphasia Detector. - -Three core tests (per task spec): - 1. Single observation below threshold -> no alert - 2. N consecutive observations above threshold -> alert fires - 3. Receipt is signed and has all required fields (lutar_anchor, neuro_citation, etc.) - -Hickok citation: Hickok, Houde, Rong 2011, Neuron 69:407-422. -DOI 10.1016/j.neuron.2011.01.019 -""" -from __future__ import annotations - -import sys -import types -import os - -import pytest - -REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if REPO_ROOT not in sys.path: - sys.path.insert(0, REPO_ROOT) - -# Stub szl_dsse if not present -for _mod in ("szl_dsse",): - if _mod not in sys.modules: - stub = types.ModuleType(_mod) - stub.sign_payload = lambda x, **kw: {"signed": False, "signatures": [], "honesty": "UNSIGNED stub"} - stub.signing_available = lambda: False - sys.modules[_mod] = stub - -import conduction_aphasia as ca - - -def fresh_state(tau: float = 0.30, window: int = 3) -> ca._ConductionState: - return ca._ConductionState(tau=tau, window=window) - - -# --------------------------------------------------------------------------- -# Test 1 — Single observation below threshold -> no alert -# --------------------------------------------------------------------------- - -class TestBelowThreshold: - """A single observation with delta <= tau must not breach or raise an alert.""" - - def test_cosine_identical_inputs_no_breach(self): - state = fresh_state(tau=0.30, window=3) - receipt = state.observe("t1", [1.0, 0.5, 0.2], [1.0, 0.5, 0.2], metric="cosine") - assert receipt["breach"] is False - assert receipt["delta"] == pytest.approx(0.0, abs=1e-9) - assert receipt["alert_level"] == ca.ALERT_NORMAL - assert receipt["consecutive_breaches"] == 0 - - def test_l2_small_perturbation_no_breach(self): - state = fresh_state(tau=0.30, window=3) - receipt = state.observe("t2", [0.8, 0.6, 0.0], [0.81, 0.59, 0.01], metric="l2") - assert receipt["breach"] is False - assert receipt["delta"] < 0.30 - assert receipt["alert_level"] == ca.ALERT_NORMAL - - def test_hash_hamming_identical_no_breach(self): - state = fresh_state(tau=0.30, window=3) - receipt = state.observe("t3", "hello world", "hello world", metric="hash_hamming") - assert receipt["breach"] is False - assert receipt["delta"] == pytest.approx(0.0, abs=1e-9) - - def test_status_shows_normal_after_clean(self): - state = fresh_state() - state.observe("t_clean", [1.0], [1.0], metric="cosine") - status = state.status() - assert status["current_alert_level"] == ca.ALERT_NORMAL - assert status["consecutive_breaches"] == 0 - - -# --------------------------------------------------------------------------- -# Test 2 — N consecutive observations above threshold -> alert fires -# --------------------------------------------------------------------------- - -class TestConsecutiveBreachesFireAlert: - - def _high_pair(self): - return [1.0, 0.0, 0.0], [0.0, 0.0, 1.0] # orthogonal -> cosine dist = 1.0 - - def test_n_consecutive_fire_conduction_alert(self): - state = fresh_state(tau=0.30, window=3) - p, a = self._high_pair() - receipts = [state.observe(f"tick_{i}", p, a, metric="cosine") for i in range(3)] - assert receipts[0]["alert_level"] == ca.ALERT_WATCHING - assert receipts[1]["alert_level"] == ca.ALERT_WATCHING - assert receipts[2]["alert_level"] == ca.ALERT_CONDUCTION - assert receipts[2]["breach"] is True - assert receipts[2]["consecutive_breaches"] == 3 - - def test_status_after_n_breaches_is_alert(self): - state = fresh_state(tau=0.30, window=3) - p, a = self._high_pair() - for i in range(3): - state.observe(f"tick_s_{i}", p, a, metric="cosine") - status = state.status() - assert status["current_alert_level"] == ca.ALERT_CONDUCTION - assert status["last_alert_at"] is not None - - def test_streak_resets_on_clean(self): - state = fresh_state(tau=0.30, window=3) - p, a = self._high_pair() - for i in range(2): - state.observe(f"breach_{i}", p, a, metric="cosine") - state.observe("clean", [1.0], [1.0], metric="cosine") - assert state._breach_streak == 0 - - def test_n_minus_one_only_watching(self): - state = fresh_state(tau=0.30, window=3) - p, a = self._high_pair() - for i in range(2): - state.observe(f"tick_{i}", p, a, metric="cosine") - assert state.status()["current_alert_level"] == ca.ALERT_WATCHING - - def test_window_of_1_fires_immediately(self): - state = fresh_state(tau=0.05, window=1) - p, a = self._high_pair() - r = state.observe("immediate", p, a, metric="cosine") - assert r["alert_level"] == ca.ALERT_CONDUCTION - - def test_breach_with_l2_metric(self): - state = fresh_state(tau=0.10, window=3) - p = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] - a = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0] - for i in range(3): - state.observe(f"l2_{i}", p, a, metric="l2") - assert state._current_alert == ca.ALERT_CONDUCTION - - -# --------------------------------------------------------------------------- -# Test 3 — Receipt has all required fields, lutar_anchor, neuro_citation -# --------------------------------------------------------------------------- - -class TestReceiptSchema: - REQUIRED_FIELDS = [ - "receipt_id", "kind", "tick_id", "predicted_hash", "actual_hash", - "delta", "metric", "threshold_tau", "breach", "alert_level", - "consecutive_breaches", "doctrine_v", "neuro_citation", - "lutar_anchor", "signed_by", "sig", "ts", - ] - - def _get_receipt(self, **kw): - state = fresh_state() - return state.observe( - tick_id=kw.get("tick_id", "schema_test"), - predicted_sensory=kw.get("predicted_sensory", [0.5, 0.5]), - actual_sensory=kw.get("actual_sensory", [0.5, 0.5]), - metric=kw.get("metric", "cosine"), - ) - - def test_all_required_fields_present(self): - r = self._get_receipt() - for field in self.REQUIRED_FIELDS: - assert field in r, f"Missing required field: {field}" - - def test_lutar_anchor_value(self): - r = self._get_receipt() - assert r["lutar_anchor"] == "A37_InternalFeedbackIntegrity" - - def test_neuro_citation_has_hickok_doi(self): - r = self._get_receipt() - nc = r["neuro_citation"] - assert isinstance(nc, dict) - assert nc.get("doi") == "10.1016/j.neuron.2011.01.019" - - def test_neuro_citation_has_label(self): - r = self._get_receipt() - nc = r["neuro_citation"] - assert "Hickok" in nc.get("label", "") - assert "2011" in nc.get("label", "") - - def test_kind_is_conduction_observation(self): - assert self._get_receipt()["kind"] == "conduction_observation" - - def test_doctrine_v_is_11(self): - assert self._get_receipt()["doctrine_v"] == "11" - - def test_signed_by_is_yachay(self): - assert self._get_receipt()["signed_by"] == "yachay" - - def test_predicted_hash_format(self): - r = self._get_receipt(predicted_sensory=[0.1, 0.2]) - assert r["predicted_hash"].startswith("sha256:") - - def test_actual_hash_format(self): - r = self._get_receipt(actual_sensory=[0.4, 0.5]) - assert r["actual_hash"].startswith("sha256:") - - def test_receipt_ids_unique(self): - state = fresh_state() - r1 = state.observe("t_a", [1.0], [1.0], "cosine") - r2 = state.observe("t_b", [1.0], [1.0], "cosine") - assert r1["receipt_id"] != r2["receipt_id"] - - def test_receipts_ring_newest_first(self): - state = fresh_state() - for i in range(3): - state.observe(f"order_{i}", [float(i)], [float(i)], "cosine") - receipts = state.receipts() - assert receipts[0]["tick_id"] == "order_2" - assert receipts[2]["tick_id"] == "order_0" - - -# --------------------------------------------------------------------------- -# Test 4 — Metric math -# --------------------------------------------------------------------------- - -class TestMetricComputation: - def test_cosine_identical_zero(self): - assert ca._cosine_delta([1.0, 0.5], [1.0, 0.5]) == pytest.approx(0.0, abs=1e-9) - - def test_cosine_orthogonal_one(self): - assert ca._cosine_delta([1.0, 0.0], [0.0, 1.0]) == pytest.approx(1.0, abs=1e-9) - - def test_l2_identical_zero(self): - assert ca._l2_delta([3.0, 4.0], [3.0, 4.0]) == pytest.approx(0.0, abs=1e-9) - - def test_l2_pythagorean(self): - assert ca._l2_delta([0.0, 0.0], [3.0, 4.0]) == pytest.approx(5.0, abs=1e-9) - - def test_hamming_identical_zero(self): - assert ca._hash_hamming_delta("abc", "abc") == pytest.approx(0.0, abs=1e-9) - - def test_hamming_different_positive(self): - d = ca._hash_hamming_delta("abc", "xyz") - assert 0.0 < d <= 1.0 - - -# --------------------------------------------------------------------------- -# Test 5 — FastAPI HTTP contract -# --------------------------------------------------------------------------- - -class TestFastAPIEndpoints: - @pytest.fixture(autouse=True) - def _setup(self): - try: - from fastapi import FastAPI - from fastapi.testclient import TestClient - except ImportError: - pytest.skip("FastAPI / httpx not installed") - ca.reset_state(tau=0.30, window=3) - app = FastAPI() - ca.register(app, ns="a11oy") - self.client = TestClient(app) - yield - - def test_status_200_doctrine_v(self): - r = self.client.get("/api/a11oy/v4/conduction/status") - assert r.status_code == 200 - d = r.json() - assert d["doctrine_v"] == "11" - assert "threshold_tau" in d - - def test_observe_below_no_breach(self): - r = self.client.post("/api/a11oy/v4/conduction/observe", json={ - "tick_id": "http_t1", "predicted_sensory": [1.0, 1.0], - "actual_sensory": [1.0, 1.0], "metric": "cosine"}) - assert r.status_code == 200 - d = r.json() - assert d["breach"] is False - assert d["alert_level"] == "normal" - - def test_observe_high_delta_breach(self): - r = self.client.post("/api/a11oy/v4/conduction/observe", json={ - "tick_id": "http_breach", "predicted_sensory": [1.0, 0.0, 0.0], - "actual_sensory": [0.0, 0.0, 1.0], "metric": "cosine"}) - assert r.status_code == 200 - assert r.json()["breach"] is True - - def test_n_consecutive_fires_conduction_alert(self): - for i in range(3): - self.client.post("/api/a11oy/v4/conduction/observe", json={ - "tick_id": f"alert_{i}", "predicted_sensory": [1.0, 0.0, 0.0], - "actual_sensory": [0.0, 0.0, 1.0], "metric": "cosine"}) - status = self.client.get("/api/a11oy/v4/conduction/status").json() - assert status["current_alert_level"] == "conduction_alert" - - def test_receipts_returns_list(self): - self.client.post("/api/a11oy/v4/conduction/observe", json={ - "tick_id": "rec_1", "predicted_sensory": [0.5], - "actual_sensory": [0.5], "metric": "cosine"}) - r = self.client.get("/api/a11oy/v4/conduction/receipts?limit=5") - assert r.status_code == 200 - d = r.json() - assert isinstance(d["receipts"], list) - assert len(d["receipts"]) >= 1 - - def test_receipt_has_lutar_anchor_and_doi(self): - self.client.post("/api/a11oy/v4/conduction/observe", json={ - "tick_id": "schema_http", "predicted_sensory": [1.0], - "actual_sensory": [1.0], "metric": "cosine"}) - d = self.client.get("/api/a11oy/v4/conduction/receipts?limit=1").json() - rec = d["receipts"][0] - assert rec["lutar_anchor"] == "A37_InternalFeedbackIntegrity" - assert rec["neuro_citation"]["doi"] == "10.1016/j.neuron.2011.01.019" - - def test_demo_endpoint_injects_high_delta(self): - r = self.client.post("/api/a11oy/v4/conduction/demo") - assert r.status_code == 200 - d = r.json() - assert d.get("demo") is True - assert d["delta"] > 0.0 - - def test_conduction_html_has_doi(self): - r = self.client.get("/conduction") - assert r.status_code == 200 - assert "10.1016/j.neuron.2011.01.019" in r.text - assert "A37" in r.text - - def test_status_has_neuro_citation(self): - d = self.client.get("/api/a11oy/v4/conduction/status").json() - assert d["neuro_citation"]["doi"] == "10.1016/j.neuron.2011.01.019" diff --git a/tests/test_dsse_real_signing.py b/tests/test_dsse_real_signing.py deleted file mode 100644 index 6ce81945a0433fa8786065a2b127dc5e63f54745..0000000000000000000000000000000000000000 --- a/tests/test_dsse_real_signing.py +++ /dev/null @@ -1,160 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 -# Authored by Yachay (CTO). Co-Authored-By: Perplexity Computer Agent. -# Doctrine v11 LOCKED 749/14/163 · Λ Conjecture 1 · SLSA L1+L2 -""" -tests/test_dsse_real_signing.py — proves the DSSE signer flips from -`signatures: []` (honest UNSIGNED) to a REAL ECDSA-P256-SHA256 signature -the moment the SZL_COSIGN_PRIVATE_KEY_PEM secret is present, and that the -resulting signature verifies against the matching public key. - -HONESTY / SAFETY - - No real org private key is ever required, embedded, or baked into CI. - - The "present-secret" test GENERATES its own ephemeral P-256 key at runtime, - sets the env var to it, signs, and verifies against THAT key's public half. - - The real-org-secret round-trip is `skipif`-guarded: it runs ONLY if a real - SZL_COSIGN_PRIVATE_KEY_PEM / SZL_COSIGN_PRIVATE_PEM is already in the env - (e.g. a developer's local shell). It is never satisfied by CI defaults. -""" -from __future__ import annotations - -import base64 -import importlib -import os -import sys - -import pytest - -REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if REPO_ROOT not in sys.path: - sys.path.insert(0, REPO_ROOT) - -cryptography = pytest.importorskip("cryptography") -from cryptography.hazmat.primitives import serialization -from cryptography.hazmat.primitives.asymmetric import ec -from cryptography.hazmat.primitives import hashes -from cryptography.exceptions import InvalidSignature - -import szl_dsse - -_PRIV_ENV = "SZL_COSIGN_PRIVATE_KEY_PEM" -_LEGACY_ENV = "SZL_COSIGN_PRIVATE_PEM" - - -def _gen_ephemeral_keypair(): - """Generate a fresh, test-only ECDSA P-256 keypair (plain PKCS#8 PEM).""" - priv = ec.generate_private_key(ec.SECP256R1()) - priv_pem = priv.private_bytes( - encoding=serialization.Encoding.PEM, - format=serialization.PrivateFormat.PKCS8, - encryption_algorithm=serialization.NoEncryption(), - ).decode("utf-8") - pub_pem = priv.public_key().public_bytes( - encoding=serialization.Encoding.PEM, - format=serialization.PublicFormat.SubjectPublicKeyInfo, - ).decode("utf-8") - return priv_pem, pub_pem - - -@pytest.fixture(autouse=True) -def _clean_env(monkeypatch): - """Ensure no ambient secret leaks between tests unless a test sets one.""" - yield - - -def test_unsigned_fallback_when_secret_absent(monkeypatch): - """No secret -> signatures:[] + honesty:UNSIGNED, never fabricated.""" - monkeypatch.delenv(_PRIV_ENV, raising=False) - monkeypatch.delenv(_LEGACY_ENV, raising=False) - importlib.reload(szl_dsse) - env = szl_dsse.sign_payload({"hello": "world"}) - assert env["signatures"] == [] - assert env["signed"] is False - assert "UNSIGNED" in env["honesty"] - assert szl_dsse.signing_available() is False - - -def test_real_signature_with_ephemeral_key_verifies(monkeypatch): - """Secret present (ephemeral test key) -> REAL signature that verifies - against the matching public key via raw cryptography AND via the module's - own verify path when the embedded public key is swapped to the test key.""" - priv_pem, pub_pem = _gen_ephemeral_keypair() - monkeypatch.delenv(_LEGACY_ENV, raising=False) - monkeypatch.setenv(_PRIV_ENV, priv_pem) - importlib.reload(szl_dsse) - - assert szl_dsse.signing_available() is True - env = szl_dsse.sign_payload({"hello": "world", "n": 42}) - - # Flipped from [] to a real signature - assert env["signed"] is True - assert len(env["signatures"]) == 1 - sig_entry = env["signatures"][0] - assert sig_entry["keyid"] == szl_dsse.KEYID - assert "REAL" in env["honesty"] - - # 1) Verify the signature against the test public key with raw cryptography, - # reconstructing the exact DSSE PAE bytes the signer used. - body = base64.b64decode(env["payload"]) - msg = szl_dsse.pae(env["payloadType"], body) - pub = serialization.load_pem_public_key(pub_pem.encode("utf-8")) - sig = base64.b64decode(sig_entry["sig"]) - pub.verify(sig, msg, ec.ECDSA(hashes.SHA256())) # raises InvalidSignature on failure - - # 2) Module verify path: point the embedded public key at the test public - # key and confirm verify_envelope() validates the just-made signature. - monkeypatch.setattr(szl_dsse, "COSIGN_PUBLIC_PEM", pub_pem, raising=True) - verdict = szl_dsse.verify_envelope(env) - assert verdict["verified"] is True - - -def test_tampered_payload_fails_verification(monkeypatch): - """A tampered payload must NOT verify (signature binds the payload).""" - priv_pem, pub_pem = _gen_ephemeral_keypair() - monkeypatch.delenv(_LEGACY_ENV, raising=False) - monkeypatch.setenv(_PRIV_ENV, priv_pem) - importlib.reload(szl_dsse) - - env = szl_dsse.sign_payload({"amount": 1}) - body = szl_dsse.canonical_json({"amount": 1000000}) # tamper - msg = szl_dsse.pae(env["payloadType"], body) - pub = serialization.load_pem_public_key(pub_pem.encode("utf-8")) - sig = base64.b64decode(env["signatures"][0]["sig"]) - with pytest.raises(InvalidSignature): - pub.verify(sig, msg, ec.ECDSA(hashes.SHA256())) - - -def test_legacy_env_var_still_works(monkeypatch): - """Backward-compat: the legacy SZL_COSIGN_PRIVATE_PEM name still signs.""" - priv_pem, _pub_pem = _gen_ephemeral_keypair() - monkeypatch.delenv(_PRIV_ENV, raising=False) - monkeypatch.setenv(_LEGACY_ENV, priv_pem) - importlib.reload(szl_dsse) - env = szl_dsse.sign_payload({"compat": True}) - assert env["signed"] is True - assert len(env["signatures"]) == 1 - - -@pytest.mark.skipif( - not (os.environ.get(_PRIV_ENV) or os.environ.get(_LEGACY_ENV)), - reason="real cosign private key not present in env; skip real-key round-trip " - "(the private key is never baked into CI)", -) -def test_real_org_key_roundtrip_if_present(): - """OPT-IN: if a real org private key is in the env, the produced signature - must verify against the module's embedded (published) public key.""" - importlib.reload(szl_dsse) - assert szl_dsse.signing_available() is True - env = szl_dsse.sign_payload({"real": "org-key-roundtrip"}) - assert env["signed"] is True - verdict = szl_dsse.verify_envelope(env) - assert verdict["verified"] is True, verdict - - -@pytest.fixture(autouse=True) -def _restore_module(): - yield - # Restore a clean module state for any downstream tests - for _n in (_PRIV_ENV, _LEGACY_ENV): - os.environ.pop(_n, None) - importlib.reload(szl_dsse) diff --git a/tests/test_formulas/__init__.py b/tests/test_formulas/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/tests/test_formulas/test_bloom_filter.py b/tests/test_formulas/test_bloom_filter.py deleted file mode 100644 index f62cb6cf4da17a8d6c49a846b0169cd979915aef..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_bloom_filter.py +++ /dev/null @@ -1,36 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.bloom_filter (Bloom 1970, FN-free). thesis_v22.pdf §2.""" -from a11oy.formulas import bloom_filter - - -def test_no_false_negatives(): - bf = bloom_filter.BloomFilter(expected_n=1000, target_fp=1e-3) - keys = [f"receipt-{i}" for i in range(500)] - for k in keys: - bf.add(k) - for k in keys: - assert bf.definitely_absent(k) is False # FN-free guarantee - - -def test_absent_is_safe_to_bypass(): - bf = bloom_filter.BloomFilter(expected_n=1000, target_fp=1e-4) - bf.add("seen") - assert bf.definitely_absent("never-inserted-xyz") is True - - -def test_rotation_preserves_membership(): - bf = bloom_filter.BloomFilter(expected_n=100, target_fp=1e-3) - bf.add("old") - bf.rotate() - bf.add("new") - # both still readable across the two live generations - assert bf.definitely_absent("old") is False - assert bf.definitely_absent("new") is False - - -def test_stats_schema(): - bf = bloom_filter.BloomFilter(expected_n=100, target_fp=1e-3) - bf.add("x") - s = bf.stats() - assert s["citation"] == "thesis_v22.pdf §2" - assert "query_after_insert" in s["lean_theorem"] diff --git a/tests/test_formulas/test_bls_aggregate.py b/tests/test_formulas/test_bls_aggregate.py deleted file mode 100644 index ad7a5169849f4480694189583de6d7c388fe6dcc..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_bls_aggregate.py +++ /dev/null @@ -1,27 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.bls_aggregate (BLS12-381). thesis_v22.pdf §2. - -If py_ecc is present, exercise a real aggregate verify; otherwise assert the HONEST -error path (no fabricated 'verified'). -""" -from a11oy.formulas import bls_aggregate - - -def test_honest_or_real(): - v = bls_aggregate.BLSAggregate() - if not v.available: - out = v.verify_same_message([b"pk"], b"msg", b"sig") - assert out["ok"] is False - assert "honest_error" in out - return - # real path - sk1 = v.keygen(b"\x01" * 32); sk2 = v.keygen(b"\x02" * 32) - msg = b"khipu-root" - s1 = v.sign(sk1["sk"], msg)["signature"] - s2 = v.sign(sk2["sk"], msg)["signature"] - agg = v.aggregate([s1, s2])["aggregate_signature"] - out = v.verify_same_message([sk1["pk"], sk2["pk"]], msg, agg) - assert out["verified"] is True - assert out["pairings_used"] == 2 - assert out["pairings_naive"] == 4 - assert out["citation"] == "thesis_v22.pdf §2" diff --git a/tests/test_formulas/test_byzantine_quorum.py b/tests/test_formulas/test_byzantine_quorum.py deleted file mode 100644 index ff748d07296f6549f25d47a3987db718907762cc..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_byzantine_quorum.py +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.byzantine_quorum (n>=3f+1). thesis_v22.pdf §2.""" -import pytest -from a11oy.formulas import byzantine_quorum as bq - - -def test_max_faults(): - assert [bq.max_byzantine_faults(n) for n in (1, 3, 4, 5, 6, 7, 10)] == [0, 0, 1, 1, 1, 2, 3] - - -def test_quorum_size(): - assert [bq.quorum_size(f) for f in (0, 1, 2, 3)] == [1, 3, 5, 7] - - -def test_threshold_5_organ_mesh(): - out = bq.quorum_threshold(5, 1) - assert out["value"] == 3 - assert out["bft_feasible"] is True - assert out["citation"] == "thesis_v22.pdf §2" - - -def test_infeasible_when_too_few(): - out = bq.quorum_threshold(3, 1) # 3 < 3*1+1=4 - assert out["bft_feasible"] is False - - -def test_invalid(): - with pytest.raises(ValueError): - bq.quorum_threshold(0) diff --git a/tests/test_formulas/test_hnsw_retrieval.py b/tests/test_formulas/test_hnsw_retrieval.py deleted file mode 100644 index 1a44db3ca63ecb06db063c833a881bc1849333b0..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_hnsw_retrieval.py +++ /dev/null @@ -1,23 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.hnsw_retrieval (amaru-owned, honest delegate). thesis_v22.pdf §2.""" -from a11oy.formulas import hnsw_retrieval as h - - -def test_status_honest(): - s = h.status() - assert s["owner_organ"] == "amaru" - assert s["citation"] == "thesis_v22.pdf §2" - assert isinstance(s["backend_available"], bool) - - -def test_real_index_when_faiss_present(): - if not h.backend_available(): - # honest: no fabrication when FAISS absent - assert h.build_hnsw_index(None) is None or True - return - import numpy as np - emb = np.random.rand(50, 8).astype("float32") - idx = h.build_hnsw_index(emb) - assert idx is not None - res = h.search_hnsw(idx, emb[:1], 5) - assert res is not None diff --git a/tests/test_formulas/test_holevo_bound.py b/tests/test_formulas/test_holevo_bound.py deleted file mode 100644 index 79d4676bad5df7b8dba2f1b93d27d3f002817e8f..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_holevo_bound.py +++ /dev/null @@ -1,41 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.holevo_bound (Holevo 1973). thesis_v22.pdf §2.""" -import math -import pytest -from a11oy.formulas import holevo_bound as hb - - -def test_capacity_binding_bound(): - out = hb.holevo_capacity(dim=4, snr=1.0) # log2(4)=2 vs log2(2)=1 -> binding=1 - assert abs(out["value"] - 1.0) < 1e-9 - assert out["binding_bound_bits"] == out["value"] - - -def test_capacity_dim_binds_when_low_dim(): - out = hb.holevo_capacity(dim=2, snr=100.0) # log2(2)=1 vs log2(101)~6.66 -> binding=1 - assert abs(out["value"] - 1.0) < 1e-9 - - -def test_chi_zero_for_identical_states(): - # identical pure states -> chi = 0 - spec = [1.0, 0.0] - chi = hb.holevo_chi([0.5, 0.5], [spec, spec]) - assert abs(chi) < 1e-9 - - -def test_chi_orthogonal_pure_states(): - # two orthogonal pure states, equal prob -> chi = 1 bit - chi = hb.holevo_chi([0.5, 0.5], [[1.0, 0.0], [0.0, 1.0]]) - assert abs(chi - 1.0) < 1e-9 - - -def test_schema(): - out = hb.holevo_capacity(8, 3.0) - assert out["citation"] == "thesis_v22.pdf §2" - assert "Holevo" in out["lean_theorem"] - - -@pytest.mark.parametrize("dim,snr", [(0, 1.0), (2, -1.0)]) -def test_invalid(dim, snr): - with pytest.raises(ValueError): - hb.holevo_capacity(dim, snr) diff --git a/tests/test_formulas/test_kalman.py b/tests/test_formulas/test_kalman.py deleted file mode 100644 index 55186ad20ad95b38d97ecddbc93055491f9413ec..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_kalman.py +++ /dev/null @@ -1,28 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.kalman (Kalman 1960). thesis_v22.pdf §2.""" -from a11oy.formulas import kalman - - -def test_scalar_variance_never_increases(): - k = kalman.ScalarKalman(process_var=1e-3, meas_var=1e-1, init_var=1.0) - for z in [0.9, 0.92, 0.88, 0.91, 0.9]: - out = k.update(z) - assert out["posterior_le_prior"] is True - assert out["gain_in_unit_interval"] is True - - -def test_scalar_tracks_constant(): - k = kalman.ScalarKalman(init_value=0.0) - for _ in range(100): - out = k.update(0.85) - assert abs(out["value"] - 0.85) < 0.05 - - -def test_tracker_smooths_noise(): - kt = kalman.KalmanTracker(meas_var=4.0, init_pos=0.0) - noisy = [0, 5, -3, 8, 2, 6, 1, 7] - last = None - for z in noisy: - last = kt.step(z) - assert last["citation"] == "thesis_v22.pdf §2" - assert "posterior_le_prior" in last["lean_theorem"] diff --git a/tests/test_formulas/test_pac_bayes.py b/tests/test_formulas/test_pac_bayes.py deleted file mode 100644 index d37ba0467234ec20e9d26ec68c2ad6c709c32c91..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_pac_bayes.py +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 -"""Tests for a11oy.formulas.pac_bayes (Catoni/McAllester). thesis_v22.pdf §2.""" -import math -import pytest -from a11oy.formulas import pac_bayes - - -def test_halfwidth_shrinks_with_n(): - hw_small = pac_bayes.pac_bayes_halfwidth(100, 0.05) - hw_large = pac_bayes.pac_bayes_halfwidth(10000, 0.05) - assert hw_large < hw_small - - -def test_halfwidth_matches_closed_form(): - n, eps, kl = 1000, 0.05, 0.0 - expected = math.sqrt((kl + math.log(2 * math.sqrt(n) / eps)) / (2 * n)) - assert abs(pac_bayes.pac_bayes_halfwidth(n, eps, kl) - expected) < 1e-12 - - -def test_kl_increases_bound(): - assert pac_bayes.pac_bayes_halfwidth(1000, 0.05, 2.0) > pac_bayes.pac_bayes_halfwidth(1000, 0.05, 0.0) - - -def test_bound_schema_and_clamp(): - out = pac_bayes.pac_bayes_bound(0.95, 100, 0.05) - assert out["value"] <= 1.0 - assert out["citation"] == "thesis_v22.pdf §2" - assert "PACBayes.lean" in out["lean_theorem"] - - -@pytest.mark.parametrize("n,eps", [(0, 0.05), (100, 0.0), (100, 1.0)]) -def test_invalid_inputs(n, eps): - with pytest.raises(ValueError): - pac_bayes.pac_bayes_halfwidth(n, eps) diff --git a/tests/test_formulas/test_reidemeister.py b/tests/test_formulas/test_reidemeister.py deleted file mode 100644 index 823d3e2a4c1afe217f6eb1e0380265d6abdac8cc..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_reidemeister.py +++ /dev/null @@ -1,26 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.reidemeister (knot moves). thesis_v22.pdf §2.""" -from a11oy.formulas import reidemeister as r - - -def test_r2_poke_cancels(): - assert r.reduced_word([1, -1]) == () - - -def test_r1_kink_cancels(): - assert r.reduced_word([2, 2]) == () - - -def test_nested_reduction(): - assert r.reduced_word([3, 1, -1, -3]) == () - - -def test_unknot_detection(): - out = r.is_unknot([1, -1, 2, 2]) - assert out["value"] is True - - -def test_distinct_words_not_certified(): - out = r.equivalent([1, 2, 3], [1, 2]) - assert out["equivalent"] is False - assert out["citation"] == "thesis_v22.pdf §2" diff --git a/tests/test_formulas/test_welford.py b/tests/test_formulas/test_welford.py deleted file mode 100644 index bb782f2576207ac9539ae999696bdcf1c13e402c..0000000000000000000000000000000000000000 --- a/tests/test_formulas/test_welford.py +++ /dev/null @@ -1,36 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -"""Tests for a11oy.formulas.welford (Welford 1962). thesis_v22.pdf §2.""" -import statistics -from a11oy.formulas import welford - - -def test_mean_variance_matches_numpy_style(): - data = [10.0, 12.0, 23.0, 23.0, 16.0, 23.0, 21.0, 16.0] - w = welford.Welford() - for x in data: - w.update(x) - assert abs(w.mean - statistics.mean(data)) < 1e-9 - assert abs(w.variance - statistics.variance(data)) < 1e-9 - - -def test_zero_variance_before_two_samples(): - w = welford.Welford() - w.update(5.0) - assert w.variance == 0.0 - assert w.zscore(99.0) == 0.0 - - -def test_anomaly_flag(): - w = welford.Welford(z_threshold=3.0) - for _ in range(50): - w.update(100.0) - w.update(100.5) - assert w.is_anomaly(1000.0) is True - - -def test_observe_schema(): - w = welford.Welford() - out = w.observe(1.0) - assert out["citation"] == "thesis_v22.pdf §2" - assert "welford_mean_exact" in out["lean_theorem"] - assert out["count"] == 1 diff --git a/tests/test_hickok_ingest.py b/tests/test_hickok_ingest.py deleted file mode 100644 index 144bef63ffa9c3664651238f85e797d262a3f5e3..0000000000000000000000000000000000000000 --- a/tests/test_hickok_ingest.py +++ /dev/null @@ -1,162 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11 LOCKED 749/14/163 -# Authored by Yachay (CTO) — Co-Authored-By: Perplexity Computer Agent. -""" -tests/test_hickok_ingest.py — pytest suite for the Hickok cognitive-neuroscience -ingest (Lutar Anchors A36/A37/A38). - -Required tests (Task G): - (1) dorsal routes an imperative intent - (2) ventral routes an interrogative intent - (3) Spt delta ≤ ε for matched inputs - (4) WHEN returns the phase mechanism string ("low_freq_phase_Heschl") - (5) WHAT returns the gamma mechanism string ("gamma_planum_temporale") - -Plus additive coverage: ambiguous → dual gate-fail (A36), neuro_citations present -on every receipt (Task E), and the dual-stream router middleware classification. -""" -from __future__ import annotations - -import pytest -from fastapi import FastAPI, Request -from fastapi.responses import JSONResponse -from fastapi.testclient import TestClient - -import a11oy_v4_hickok as H - -EPSILON = 1e-3 - - -@pytest.fixture(scope="module") -def client() -> TestClient: - app = FastAPI() - - # Routes the dual-stream router middleware watches (stubbed so we can assert - # the middleware classification headers without standing up the real agent). - @app.post("/api/a11oy/v4/agent/ask") - async def _ask(request: Request): # noqa: ANN202 - body = await request.json() - return JSONResponse({"echo": body}) - - @app.post("/api/a11oy/v4/predict") - async def _predict(request: Request): # noqa: ANN202 - body = await request.json() - return JSONResponse({"echo": body}) - - status = H.register(app, "a11oy") - assert status["registered"] is True - return TestClient(app) - - -# --------------------------------------------------------------------------- -# (1) dorsal routes an imperative intent -# --------------------------------------------------------------------------- -def test_dorsal_routes_imperative(client: TestClient) -> None: - r = client.post("/api/a11oy/v4/dorsal", json={"intent": "sign the receipt"}) - assert r.status_code == 200 - data = r.json() - assert data["lutar_anchor"] == "A36" - assert "motor_pathway" in data - assert data["classification"]["stream"] == "dorsal" - assert data["classification"]["gate_pass"] is True - # neuro_citations present with the dual-stream DOI (Task E) - assert {"doi": "10.1038/nrn2113"} in data["neuro_citations"] - assert data["signed_receipt_id"] - - -# --------------------------------------------------------------------------- -# (2) ventral routes an interrogative intent -# --------------------------------------------------------------------------- -def test_ventral_routes_interrogative(client: TestClient) -> None: - r = client.post("/api/a11oy/v4/ventral", json={"intent": "what does this mean?"}) - assert r.status_code == 200 - data = r.json() - assert data["lutar_anchor"] == "A36" - assert "meaning" in data - assert data["classification"]["stream"] == "ventral" - assert data["classification"]["gate_pass"] is True - assert {"doi": "10.1038/nrn2113"} in data["neuro_citations"] - - -# --------------------------------------------------------------------------- -# (3) Spt delta ≤ ε for matched inputs -# --------------------------------------------------------------------------- -def test_spt_delta_within_epsilon_for_matched(client: TestClient) -> None: - r = client.post("/api/a11oy/v4/spt", - json={"sensory_target": 1.0, "motor_plan": 1.0}) - assert r.status_code == 200 - data = r.json() - assert data["delta"] <= EPSILON - assert {"doi": "10.1152/jn.91344.2008"} in data["neuro_citations"] - # A mismatched pair must produce a strictly larger delta. - r2 = client.post("/api/a11oy/v4/spt", - json={"sensory_target": 1.0, "motor_plan": 9.0}) - assert r2.json()["delta"] > EPSILON - - -# --------------------------------------------------------------------------- -# (4) WHEN returns the phase mechanism string -# --------------------------------------------------------------------------- -def test_when_returns_phase_mechanism(client: TestClient) -> None: - r = client.post("/api/a11oy/v4/when", json={"stream": "left-Heschl"}) - assert r.status_code == 200 - data = r.json() - assert data["mechanism"] == "low_freq_phase_Heschl" - assert "phase_prediction" in data - assert {"doi": "10.1101/474718"} in data["neuro_citations"] - - -# --------------------------------------------------------------------------- -# (5) WHAT returns the gamma mechanism string -# --------------------------------------------------------------------------- -def test_what_returns_gamma_mechanism(client: TestClient) -> None: - r = client.post("/api/a11oy/v4/what", json={"stream": "planum-temporale"}) - assert r.status_code == 200 - data = r.json() - assert data["mechanism"] == "gamma_planum_temporale" - assert "semantic_prediction" in data - assert {"doi": "10.1101/474718"} in data["neuro_citations"] - - -# --------------------------------------------------------------------------- -# Additive coverage -# --------------------------------------------------------------------------- -def test_ambiguous_intent_is_dual_gate_fail() -> None: - """A36 says EXACTLY one stream — an ambiguous intent is `dual` and fails.""" - cls = H.classify_stream("banana table widget") - assert cls["stream"] == "dual" - assert cls["gate_pass"] is False - assert cls["lutar_anchor"] == "A36" - - -def test_dual_stream_router_middleware_headers(client: TestClient) -> None: - """The middleware classifies /agent/ask + /predict and writes A36 headers, - while preserving the request body for the downstream handler.""" - r = client.post("/api/a11oy/v4/agent/ask", json={"intent": "deploy the build"}) - assert r.json()["echo"] == {"intent": "deploy the build"} # body preserved - assert r.headers.get("X-A11oy-Stream") == "dorsal" - assert r.headers.get("X-A11oy-Stream-Gate") == "pass" - assert r.headers.get("X-A11oy-Stream-Anchor") == "A36" - - r2 = client.post("/api/a11oy/v4/predict", json={"intent": "why does this fail?"}) - assert r2.headers.get("X-A11oy-Stream") == "ventral" - - r3 = client.post("/api/a11oy/v4/agent/ask", json={"intent": "xyzzy plugh"}) - assert r3.headers.get("X-A11oy-Stream") == "dual" - assert r3.headers.get("X-A11oy-Stream-Gate") == "fail" - - -def test_every_receipt_carries_neuro_citations() -> None: - """Task E: sign_khipu_receipt injects neuro_citations (default []) on the receipt.""" - signed = H._sign("probe", {"x": 1}, [H.CITE_DUAL_STREAM], stream="dorsal") - assert "neuro_citations" in signed["receipt"] - cites = signed["receipt"]["neuro_citations"] - assert isinstance(cites, list) and len(cites) >= 1 - assert all("doi" in c and "label" in c for c in cites) - - -def test_dsse_default_empty_neuro_citations() -> None: - """Task E: a receipt signed with no citations gets an empty list, not an error.""" - import szl_dsse as dsse - out = dsse.sign_khipu_receipt({"organ": "test", "action": "noop"}) - assert out["receipt"]["neuro_citations"] == [] diff --git a/tests/test_parity_gaps.py b/tests/test_parity_gaps.py deleted file mode 100644 index bea4f01031a378cec362225490c5dde5e07a5c2b..0000000000000000000000000000000000000000 --- a/tests/test_parity_gaps.py +++ /dev/null @@ -1,438 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11 -# Co-Authored-By: Perplexity Computer Agent -# Signed-off-by: Stephen P. Lutar Jr. -""" -Tests for szl_parity_gaps — parity gap closure + differentiator endpoints. - -Coverage: - GAP-A: /api/a11oy/v1/compliance/export - GAP-B: /api/a11oy/v1/lineage - GAP-C: /api/a11oy/v1/policy/validate - DIFF-1: /api/a11oy/v1/receipts/replay - DIFF-2: /api/a11oy/v1/lambda/score -""" -from __future__ import annotations -import json -import math -import pytest -from fastapi import FastAPI -from fastapi.testclient import TestClient - -import sys, os -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -import szl_parity_gaps as pg - -# --------------------------------------------------------------------------- -# Minimal gate manifest stubs for tests -# --------------------------------------------------------------------------- -_STUB_GATES = [ - {"name": "thresholdPolicySeverity", "file": "thresholdPolicySeverity_gate.ts", - "description": "Threshold gate", "lean_theorem": "ThresholdAxiom", - "lean_file": "Lutar/LambdaInvariant/Boundary.lean", "lean_verified": True}, - {"name": "adversarialRobustness", "file": "adversarialRobustness_gate.ts", - "description": "Adversarial robustness", "lean_theorem": "", "lean_verified": False}, - {"name": "hashChainIntegrity", "file": "hashChainIntegrity_gate.ts", - "description": "Hash chain", "lean_theorem": "", "lean_verified": False}, - {"name": "merkleDagBatch", "file": "merkleDagBatch_gate.ts", - "description": "Merkle DAG", "lean_theorem": "", "lean_verified": False}, - {"name": "doctrineCompleteness", "file": "doctrineCompleteness_gate.ts", - "description": "Doctrine completeness", "lean_theorem": "", "lean_verified": False}, - {"name": "constructiveTransparency", "file": "constructiveTransparency_gate.ts", - "description": "Transparency", "lean_theorem": "", "lean_verified": False}, - {"name": "soundnessAxiom", "file": "soundnessAxiom_gate.ts", - "description": "Soundness", "lean_theorem": "", "lean_verified": False}, - {"name": "deterministicReplay", "file": "deterministicReplay_gate.ts", - "description": "Deterministic replay", "lean_theorem": "", "lean_verified": False}, - {"name": "certifiedRobustness", "file": "certifiedRobustness_gate.ts", - "description": "Certified robustness", "lean_theorem": "", "lean_verified": False}, - {"name": "bekensteinBound", "file": "bekensteinBound_gate.ts", - "description": "Bekenstein", "lean_theorem": "", "lean_verified": False}, - {"name": "composability", "file": "composability_gate.ts", - "description": "Composability", "lean_theorem": "", "lean_verified": False}, - {"name": "crossRegionPolicy", "file": "crossRegionPolicy_gate.ts", - "description": "Cross-region", "lean_theorem": "", "lean_verified": False}, - {"name": "witnessQuorum", "file": "witnessQuorum_gate.ts", - "description": "Witness quorum", "lean_theorem": "", "lean_verified": False}, - {"name": "humanEscalation", "file": "humanEscalation_gate.ts", - "description": "Human escalation", "lean_theorem": "", "lean_verified": False}, - {"name": "provenance", "file": "provenance_gate.ts", - "description": "Provenance", "lean_theorem": "", "lean_verified": False}, -] -_STUB_BY_NAME = {g["name"]: g for g in _STUB_GATES} - - -@pytest.fixture(scope="module") -def client(): - app = FastAPI() - pg.register(app, _STUB_GATES, _STUB_BY_NAME) - return TestClient(app, raise_server_exceptions=True) - - -# --------------------------------------------------------------------------- -# GAP-A: Compliance Evidence Export -# --------------------------------------------------------------------------- -class TestComplianceExport: - def test_eu_ai_act_200(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=eu-ai-act") - assert r.status_code == 200 - d = r.json() - assert d["framework"] == "eu-ai-act" - assert d["schema"] == "szl.compliance.export.v1" - assert isinstance(d["controls"], list) - assert len(d["controls"]) > 0 - assert d["doctrine"] == "v11" - - def test_nist_ai_rmf_200(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=nist-ai-rmf") - assert r.status_code == 200 - assert r.json()["framework"] == "nist-ai-rmf" - - def test_iso_42001_200(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=iso-42001") - assert r.status_code == 200 - assert r.json()["framework"] == "iso-42001" - - def test_soc2_200(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=soc2") - assert r.status_code == 200 - assert r.json()["framework"] == "soc2" - - def test_unknown_framework_400(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=fedramp-high") - assert r.status_code == 400 - d = r.json() - assert "available" in d - - def test_controls_have_gate_evidence(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=eu-ai-act") - d = r.json() - for ctrl in d["controls"]: - assert "gate_evidence" in ctrl - assert isinstance(ctrl["gate_evidence"], list) - - def test_lambda_conjecture_labelled(self, client): - r = client.get("/api/a11oy/v1/compliance/export?framework=eu-ai-act") - d = r.json() - assert "Conjecture" in d["lambda"] - - def test_default_framework_is_eu_ai_act(self, client): - r = client.get("/api/a11oy/v1/compliance/export") - assert r.status_code == 200 - assert r.json()["framework"] == "eu-ai-act" - - -# --------------------------------------------------------------------------- -# GAP-B: Decision Lineage Query -# --------------------------------------------------------------------------- -class TestDecisionLineage: - def test_lineage_200(self, client): - r = client.get("/api/a11oy/v1/lineage") - assert r.status_code == 200 - d = r.json() - assert d["schema"] == "szl.lineage.v1" - assert "nodes" in d - assert d["doctrine"] == "v11" - - def test_lineage_empty_on_cold_dag(self, client): - """On a cold start with no real DAG the endpoint returns honest empty nodes.""" - r = client.get("/api/a11oy/v1/lineage?limit=10") - d = r.json() - # Either empty (cold start) or has nodes (if DAG populated) - assert isinstance(d["nodes"], list) - assert "returned" in d - - def test_lineage_limit_honoured(self, client): - r = client.get("/api/a11oy/v1/lineage?limit=5") - d = r.json() - assert d["limit"] == 5 - assert len(d["nodes"]) <= 5 - - def test_lineage_limit_capped_at_200(self, client): - r = client.get("/api/a11oy/v1/lineage?limit=9999") - d = r.json() - assert d["limit"] == 200 - - def test_lineage_leader_parity_refs(self, client): - r = client.get("/api/a11oy/v1/lineage") - d = r.json() - lp = d.get("leader_parity", {}) - assert "palantir" in " ".join(lp.values()).lower() - - -# --------------------------------------------------------------------------- -# GAP-C: Policy-as-Code Validation -# --------------------------------------------------------------------------- -class TestPolicyValidate: - def test_valid_policy(self, client): - payload = { - "name": "test-policy", - "gates": ["thresholdPolicySeverity", "adversarialRobustness"], - "lambda_floor": 0.90, - "min_witnesses": 2, - "severity": "medium", - } - r = client.post("/api/a11oy/v1/policy/validate", json=payload) - assert r.status_code == 200 - d = r.json() - assert d["valid"] is True - assert d["violations"] == [] - - def test_missing_name_invalid(self, client): - payload = {"gates": ["thresholdPolicySeverity"]} - r = client.post("/api/a11oy/v1/policy/validate", json=payload) - assert r.status_code == 200 - d = r.json() - assert d["valid"] is False - assert any(v["field"] == "name" for v in d["violations"]) - - def test_unknown_gate_invalid(self, client): - payload = {"name": "test", "gates": ["nonexistent_gate_xyz"]} - r = client.post("/api/a11oy/v1/policy/validate", json=payload) - assert r.status_code == 200 - d = r.json() - assert d["valid"] is False - assert any("Unknown gates" in v["message"] for v in d["violations"]) - - def test_lambda_floor_out_of_range(self, client): - payload = {"name": "test", "gates": ["thresholdPolicySeverity"], - "lambda_floor": 1.5} - r = client.post("/api/a11oy/v1/policy/validate", json=payload) - assert r.status_code == 200 - d = r.json() - assert d["valid"] is False - assert any("lambda_floor" in v["field"] for v in d["violations"]) - - def test_capital_severity_quorum_check(self, client): - payload = {"name": "test", "gates": ["thresholdPolicySeverity"], - "severity": "capital", "min_witnesses": 2} - r = client.post("/api/a11oy/v1/policy/validate", json=payload) - assert r.status_code == 200 - d = r.json() - # capital requires 3-of-N quorum - assert d["required_quorum"] == 3 - assert d["valid"] is False - - def test_gate_coverage_reported(self, client): - payload = {"name": "test", "gates": ["thresholdPolicySeverity"]} - r = client.post("/api/a11oy/v1/policy/validate", json=payload) - d = r.json() - assert "gate_coverage" in d - assert d["gate_coverage"]["known"] >= 1 - - def test_invalid_json_400(self, client): - r = client.post("/api/a11oy/v1/policy/validate", - content=b"not json", headers={"Content-Type": "application/json"}) - assert r.status_code == 400 - - -# --------------------------------------------------------------------------- -# DIFF-1: Receipt Replay -# --------------------------------------------------------------------------- -class TestReceiptReplay: - def test_replay_allow(self, client): - payload = { - "action": { - "severity": "medium", - "confidence": 0.85, - "actionId": "replay-test-001", - "witnesses": [ - {"id": "w1", "role": "op", "attested": True}, - {"id": "w2", "role": "auditor", "attested": True}, - ], - }, - "gate": "thresholdPolicySeverity", - } - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - assert r.status_code == 200 - d = r.json() - assert d["schema"] == "szl.receipt.replay.v1" - assert d["replay_decision"] in ("allow", "deny") - assert "replay_receipt_hash" in d - assert "determinism_note" in d - - def test_replay_deny_low_confidence(self, client): - payload = { - "action": { - "severity": "high", - "confidence": 0.5, - "actionId": "replay-deny-001", - "witnesses": [{"id": "w1", "role": "op", "attested": True}], - }, - "gate": "thresholdPolicySeverity", - } - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - assert r.status_code == 200 - d = r.json() - assert d["replay_decision"] == "deny" - - def test_replay_hash_comparison(self, client): - payload = { - "action": {"severity": "medium", "confidence": 0.85, "actionId": "a", - "witnesses": [{"id": "w1", "attested": True}, - {"id": "w2", "attested": True}]}, - "original_receipt_hash": "deadbeef1234567890", - "gate": "thresholdPolicySeverity", - } - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - d = r.json() - assert "hashes_match" in d - # Hashes won't match (different hash), but the field must be present - assert d["hashes_match"] is False # deadbeef won't match real sha256 - - def test_replay_unknown_gate_400(self, client): - payload = {"action": {"severity": "medium"}, "gate": "nonexistent_gate_xyz"} - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - assert r.status_code == 400 - - def test_replay_no_action_400(self, client): - payload = {"gate": "thresholdPolicySeverity"} - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - assert r.status_code == 400 - - def test_replay_dsse_envelope_present(self, client): - payload = { - "action": {"severity": "medium", "confidence": 0.85, "actionId": "a", - "witnesses": [{"id": "w1", "attested": True}, - {"id": "w2", "attested": True}]}, - "gate": "thresholdPolicySeverity", - } - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - d = r.json() - assert "replay_dsse" in d - # replay_dsse may wrap a {receipt, dsse} or a {payloadType, ...} envelope - env = d["replay_dsse"] - has_payload_type = "payloadType" in env - has_nested_dsse = "dsse" in env or "receipt" in env - assert has_payload_type or has_nested_dsse, f"unexpected dsse shape: {list(env.keys())}" - - def test_replay_differentiator_note_present(self, client): - payload = { - "action": {"severity": "medium", "confidence": 0.85, "actionId": "a", - "witnesses": [{"id": "w1", "attested": True}, - {"id": "w2", "attested": True}]}, - } - r = client.post("/api/a11oy/v1/receipts/replay", json=payload) - d = r.json() - assert "differentiator" in d - - -# --------------------------------------------------------------------------- -# DIFF-2: Λ-Gated Decision Scoring -# --------------------------------------------------------------------------- -class TestLambdaScore: - _PERFECT = {a: 1.0 for a in pg.CANONICAL_AXES} - _TYPICAL = {a: 0.91 for a in pg.CANONICAL_AXES} - _ZERO_ONE = {**{a: 0.91 for a in pg.CANONICAL_AXES}, "soundness": 0.0} - - def test_perfect_axes_lambda_one(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._PERFECT}) - assert r.status_code == 200 - d = r.json() - assert abs(d["lambda"] - 1.0) < 1e-6 - assert d["gate_pass"] is True - - def test_typical_axes_lambda_in_range(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._TYPICAL}) - d = r.json() - lv = d["lambda"] - assert 0.8 < lv < 1.0 - - def test_zero_axis_zero_pinning(self, client): - """A2: zero-pinning — Λ = 0 when any positive-weight axis is 0.""" - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._ZERO_ONE}) - d = r.json() - assert d["lambda"] == 0.0 - assert d["zero_pinned"] is True - assert d["gate_pass"] is False - - def test_gate_pass_with_high_floor(self, client): - r = client.post("/api/a11oy/v1/lambda/score", - json={"axes": self._TYPICAL, "lambda_floor": 0.99}) - d = r.json() - assert d["gate_pass"] is False - - def test_gate_decision_deny(self, client): - r = client.post("/api/a11oy/v1/lambda/score", - json={"axes": self._ZERO_ONE, "lambda_floor": 0.90}) - d = r.json() - assert d["gate_decision"] == "deny" - - def test_schema_correct(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._TYPICAL}) - d = r.json() - assert d["schema"] == "szl.lambda.score.v1" - assert d["doctrine"] == "v11" - - def test_lean_citation_conjecture(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._TYPICAL}) - d = r.json() - lc = d["lean_citation"] - assert "Conjecture 1" in lc["status"] - assert "NOT a closed theorem" in lc["status"] - - def test_axes_breakdown_present(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._TYPICAL}) - d = r.json() - assert len(d["axes_computed"]) == 9 - - def test_missing_axes_flagged(self, client): - r = client.post("/api/a11oy/v1/lambda/score", - json={"axes": {"soundness": 0.9}}) - d = r.json() - assert len(d["missing_axes"]) == 8 - - def test_monotonicity_a1(self, client): - """A1: raising one axis while others fixed should not decrease Λ.""" - base = {a: 0.80 for a in pg.CANONICAL_AXES} - high = {**base, "soundness": 0.95} - r_base = client.post("/api/a11oy/v1/lambda/score", json={"axes": base}) - r_high = client.post("/api/a11oy/v1/lambda/score", json={"axes": high}) - assert r_high.json()["lambda"] >= r_base.json()["lambda"] - - def test_no_action_400(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"lambda_floor": 0.9}) - assert r.status_code == 400 - - def test_differentiator_note_present(self, client): - r = client.post("/api/a11oy/v1/lambda/score", json={"axes": self._TYPICAL}) - d = r.json() - assert "differentiator" in d - - -# --------------------------------------------------------------------------- -# Lambda computation unit tests (no HTTP) -# --------------------------------------------------------------------------- -class TestLambdaComputation: - def test_perfect_is_one(self): - axes = {a: 1.0 for a in pg.CANONICAL_AXES} - result = pg._compute_lambda(axes) - assert abs(result["lambda"] - 1.0) < 1e-9 - - def test_zero_pinning(self): - axes = {a: 0.9 for a in pg.CANONICAL_AXES} - axes["soundness"] = 0.0 - result = pg._compute_lambda(axes) - assert result["lambda"] == 0.0 - assert result["zero_pinned"] is True - - def test_monotonicity(self): - base = {a: 0.80 for a in pg.CANONICAL_AXES} - high = {**base, "calibration": 0.99} - r_base = pg._compute_lambda(base) - r_high = pg._compute_lambda(high) - assert r_high["lambda"] >= r_base["lambda"] - - def test_symmetry(self): - """A4 corollary: all-equal axes → Λ = that value (geometric = arithmetic for equal values).""" - axes = {a: 0.90 for a in pg.CANONICAL_AXES} - result = pg._compute_lambda(axes) - assert abs(result["lambda"] - 0.90) < 1e-6 - - def test_weights_normalised(self): - """Custom weights that don't sum to 1 should still give valid Λ ∈ [0,1].""" - axes = {a: 0.90 for a in pg.CANONICAL_AXES} - weights = {a: 2.0 for a in pg.CANONICAL_AXES} # sum = 18, not 1 - result = pg._compute_lambda(axes, weights) - assert 0.0 <= result["lambda"] <= 1.0 + 1e-9 diff --git a/tests/test_v4_agent_voters.py b/tests/test_v4_agent_voters.py deleted file mode 100644 index 674aaf5907b50525dc16ef3ee40c4e93e39a3bde..0000000000000000000000000000000000000000 --- a/tests/test_v4_agent_voters.py +++ /dev/null @@ -1,277 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# © 2026 Lutar, Stephen P. — SZL Holdings -# Doctrine v11 LOCKED 749/14/163. Authored by Yachay (CTO). -# DCO: Signed-off-by: Yachay -# Co-Authored-By: Perplexity Computer Agent -""" -tests/test_v4_agent_voters.py — pytest tests for the a11oy v4 multi-LLM ensemble. - -Tests: - 1. Voter with missing env var returns {status: "unavailable"} — not an error. - 2. /api/a11oy/v4/agent/voters returns all 13 voters. - 3. /api/a11oy/v4/agent/ask with explicit voters list respects the filter. - -All tests are hermetic: no real LLM calls, no real env vars needed. -""" -from __future__ import annotations - -import asyncio -import json -import os -import sys -from pathlib import Path -from typing import Any, Dict, List -from unittest.mock import AsyncMock, patch - -import pytest - -# Ensure repo root is on path -_REPO = Path(__file__).parent.parent.resolve() -if str(_REPO) not in sys.path: - sys.path.insert(0, str(_REPO)) - -# --------------------------------------------------------------------------- -# Imports under test -# --------------------------------------------------------------------------- -from packages.inference.src.voters import ( - get_all_voters, - get_voter, - resolve_voters, - VOTER_COUNT, -) -from packages.inference.src.voters.deepseek_r1 import DeepSeekR1Voter -from packages.inference.src.voters.kimi_k2 import KimiK2Voter -from packages.inference.src.voters.nemotron_super_49b import NemotronSuper49BVoter - - -# --------------------------------------------------------------------------- -# Test 1: Voter with missing env var returns {status: "unavailable"} -# --------------------------------------------------------------------------- - -@pytest.mark.asyncio -async def test_missing_env_var_returns_unavailable(): - """A cloud voter with no env var must return status='unavailable', not raise.""" - # Use DeepSeekR1Voter — requires DEEPSEEK_API_KEY or HF_TOKEN - voter = DeepSeekR1Voter() - - # Guarantee both env vars are absent for this test - env_patch = {k: None for k in voter.ENV_VARS} - with patch.dict(os.environ, {}, clear=False): - for k in voter.ENV_VARS: - os.environ.pop(k, None) - - assert not voter.is_available(), "voter should be unavailable without env vars" - - result = await voter.vote(prompt="hello world") - - assert result["status"] == "unavailable", ( - f"Expected 'unavailable', got {result['status']!r}" - ) - assert result["voter_id"] == "deepseek-r1" - assert result["text"] is None - assert "token_not_present" in result["reason"] - # latency_ms is None when unavailable - assert result["latency_ms"] is None - - -@pytest.mark.asyncio -async def test_multiple_voters_missing_env_return_unavailable(): - """Several new voters with no env vars must all return 'unavailable', not raise.""" - voters_to_check = [ - KimiK2Voter(), - NemotronSuper49BVoter(), - ] - for voter in voters_to_check: - for k in voter.ENV_VARS: - os.environ.pop(k, None) - - result = await voter.vote(prompt="test") - assert result["status"] == "unavailable", ( - f"{voter.VOTER_ID}: expected 'unavailable', got {result['status']!r}" - ) - assert result["text"] is None - assert "token_not_present" in result["reason"] - - -# --------------------------------------------------------------------------- -# Test 2: /api/a11oy/v4/agent/voters returns all 13 voters -# --------------------------------------------------------------------------- - -def test_voter_count_is_13(): - """Registry must contain exactly 13 voters.""" - assert VOTER_COUNT == 13, f"Expected 13 voters, got {VOTER_COUNT}" - - -def test_all_voters_have_required_fields(): - """Every voter must expose required metadata fields.""" - voters = get_all_voters() - assert len(voters) == 13 - - required_fields = {"voter_id", "status", "provider", "license", "context_window", "env_vars", "model_id"} - for v in voters: - meta = v.metadata() - for field in required_fields: - assert field in meta, f"{v.VOTER_ID}: missing metadata field '{field}'" - assert meta["status"] in ("available", "token_required"), ( - f"{v.VOTER_ID}: invalid status {meta['status']!r}" - ) - - -def test_sovereign_default_always_available(): - """qwen-local (sovereign-default) must always be available regardless of env vars.""" - qwen = get_voter("qwen-local") - assert qwen is not None, "qwen-local voter not found in registry" - assert qwen.is_available(), "qwen-local (sovereign-default) must always be available" - assert qwen.metadata()["status"] == "available" - - -def test_all_13_voter_ids_present(): - """All 13 voter IDs must be in the registry.""" - expected_ids = { - # Original 4 - "qwen-local", - "hf-inference-llama", - "hf-inference-mistral", - "hf-inference-qwen", - # 9 new voters - "deepseek-r1", - "kimi-k2", - "glm-4.6", - "hermes-4-405b", - "minimax-m2", - "step-3.7-flash", - "nomos-1", - "nemotron-super-49b", - "xiaomi-mimo", - } - actual_ids = {v.VOTER_ID for v in get_all_voters()} - assert actual_ids == expected_ids, ( - f"Voter ID mismatch.\nExpected: {sorted(expected_ids)}\nGot: {sorted(actual_ids)}" - ) - - -def test_voters_endpoint_response_shape(): - """Simulate the /agent/voters endpoint response and validate its shape.""" - import a11oy_v4_agent as agent_mod - from packages.inference.src.voters import VOTER_INPUT_SCHEMA, VOTER_OUTPUT_SCHEMA - - voters = get_all_voters() - response = { - "count": len(voters), - "voters": [v.metadata() for v in voters], - "sovereign_default": "qwen-local", - "doctrine": {"version": "v11", "declarations": 749, "axioms": 14, "sorries": 163}, - } - - assert response["count"] == 13 - assert response["sovereign_default"] == "qwen-local" - assert len(response["voters"]) == 13 - # Doctrine pins intact - assert response["doctrine"]["declarations"] == 749 - assert response["doctrine"]["axioms"] == 14 - assert response["doctrine"]["sorries"] == 163 - - -# --------------------------------------------------------------------------- -# Test 3: /agent/ask with explicit voters list respects the filter -# --------------------------------------------------------------------------- - -@pytest.mark.asyncio -async def test_ask_respects_voters_filter(): - """/agent/ask with voters=["qwen-local","deepseek-r1"] runs exactly those two.""" - from packages.inference.src.voters import resolve_voters - - # Only request two voters - requested = ["qwen-local", "deepseek-r1"] - voters = resolve_voters(requested) - - voter_ids = [v.VOTER_ID for v in voters] - assert "qwen-local" in voter_ids, "sovereign-default qwen-local must always be included" - assert "deepseek-r1" in voter_ids, "explicitly requested deepseek-r1 must be included" - # Other voters must not be present - for vid in voter_ids: - assert vid in requested, f"Unexpected voter {vid!r} in resolved list" - - -@pytest.mark.asyncio -async def test_ask_sovereign_always_present_even_without_list(): - """When no voters list is given, only qwen-local (sovereign-default) runs.""" - voters = resolve_voters(None) - assert len(voters) == 1 - assert voters[0].VOTER_ID == "qwen-local" - - -@pytest.mark.asyncio -async def test_ask_deepseek_unavailable_when_no_key(): - """When deepseek-r1 is in voters list but DEEPSEEK_API_KEY absent → - vote returns 'unavailable', not an exception.""" - from packages.inference.src.voters import resolve_voters - - # Clear env vars - for k in ["DEEPSEEK_API_KEY", "HF_TOKEN"]: - os.environ.pop(k, None) - - requested = ["qwen-local", "deepseek-r1"] - voters = resolve_voters(requested) - - # Run only deepseek (skip qwen to avoid vLLM stub noise) - ds_voter = next(v for v in voters if v.VOTER_ID == "deepseek-r1") - result = await ds_voter.vote(prompt="test prompt") - - assert result["status"] == "unavailable" - assert result["voter_id"] == "deepseek-r1" - assert "token_not_present" in result["reason"] - - -@pytest.mark.asyncio -async def test_unknown_voter_id_silently_skipped(): - """An unknown voter ID in the voters list is silently skipped (no KeyError).""" - voters = resolve_voters(["qwen-local", "nonexistent-voter-xyz"]) - voter_ids = [v.VOTER_ID for v in voters] - assert "qwen-local" in voter_ids - assert "nonexistent-voter-xyz" not in voter_ids - - -@pytest.mark.asyncio -async def test_lambda_aggregator_no_ok_votes(): - """Λ-aggregator must handle zero ok-status votes gracefully.""" - import a11oy_v4_agent as agent_mod - - votes = [ - {"voter_id": "deepseek-r1", "status": "unavailable", "text": None, "reason": "token_not_present"}, - {"voter_id": "kimi-k2", "status": "unavailable", "text": None, "reason": "token_not_present"}, - ] - agg = agent_mod._lambda_aggregate(votes) - assert agg["winner_id"] is None - assert agg["lambda_score"] == 0.0 - - -@pytest.mark.asyncio -async def test_lambda_aggregator_single_ok_vote(): - """Λ-aggregator with one ok vote returns that voter as winner.""" - import a11oy_v4_agent as agent_mod - - votes = [ - {"voter_id": "qwen-local", "status": "ok", "text": "Hello from qwen-local!", "reason": None}, - {"voter_id": "deepseek-r1", "status": "unavailable", "text": None, "reason": "token_not_present"}, - ] - agg = agent_mod._lambda_aggregate(votes) - assert agg["winner_id"] == "qwen-local" - assert 0.0 < agg["lambda_score"] <= 1.0 - assert len(agg["provenance_entries"]) == 1 - - -@pytest.mark.asyncio -async def test_qwen_local_returns_stub_when_vllm_unreachable(): - """qwen-local must return a stub (not raise) when local vLLM is unreachable.""" - qwen = get_voter("qwen-local") - assert qwen is not None - - # Override QWEN_LOCAL_URL to an unreachable endpoint - with patch.dict(os.environ, {"QWEN_LOCAL_URL": "http://127.0.0.1:19999/v1/chat/completions"}): - result = await qwen.vote(prompt="test") - - # qwen-local never fails — it degrades to a stub - assert result["status"] == "ok" - assert result["text"] is not None - assert "STUB" in result["text"] or "stub" in result["text"].lower() or len(result["text"]) > 0 diff --git a/tests/test_zero_cdn_guard.py b/tests/test_zero_cdn_guard.py deleted file mode 100644 index 79c2e365651ca5232924493471d222cc2343ad06..0000000000000000000000000000000000000000 --- a/tests/test_zero_cdn_guard.py +++ /dev/null @@ -1,100 +0,0 @@ -""" -test_zero_cdn_guard.py — DEV-WIRE-A (2026-06-09) - -Doctrine guard: the operator console + every vendored JS asset MUST be 0 runtime CDN. -All third-party libraries are vendored in-image under static-vendor/ and referenced with -relative `