diff --git a/.aii/config.yaml b/.aii/config.yaml index 5cd7dd8..c030563 100644 --- a/.aii/config.yaml +++ b/.aii/config.yaml @@ -1,7 +1,7 @@ # AII sidecar — InstituteOS metadata. Schema: aii_platform.aii_sidecar meta: sidecar_version: 1.2.1 - updated: '2026-11-10' + updated: '2026-11-12' repo: name: ActiveBlockference slug: activeblockference diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fdba67d..fa59498 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,10 +83,8 @@ jobs: id: runtime run: | set -euo pipefail - PIN=specs/gnn-pin.json - PY=$(uv python find --no-project 3.12) - REPO=$("$PY" -c "import json;print(json.load(open('$PIN'))['repository'])") - COMMIT=$("$PY" -c "import json;print(json.load(open('$PIN'))['commit'])") + REPO=$(uv run --no-sync python -c "from blockference.gnn import load_pin; print(load_pin()['repository'])") + COMMIT=$(uv run --no-sync python -c "from blockference.gnn import load_pin; print(load_pin()['commit'])") uv venv --python 3.12 "$RUNNER_TEMP/gnn-runtime" # The install follows specs/gnn-pin.json; a pin bump re-points it. uv pip install --python "$RUNNER_TEMP/gnn-runtime/bin/python" \ diff --git a/blockference/gnn.py b/blockference/gnn.py index 2c45158..ecd5a34 100644 --- a/blockference/gnn.py +++ b/blockference/gnn.py @@ -22,6 +22,7 @@ from __future__ import annotations import json +import re from collections.abc import Iterable, Mapping, Sequence from dataclasses import dataclass from pathlib import Path @@ -152,9 +153,19 @@ def spec_arrays(parameters: GridWorldSpecParameters | None = None) -> dict[str, def load_pin(path: Path | None = None) -> dict[str, Any]: - """Return the recorded upstream GNN pin.""" - - return json.loads((path or GNN_PIN_PATH).read_text(encoding="utf-8")) + """Return the upstream pin, rejecting records outside the local pin contract.""" + + pin = json.loads((path or GNN_PIN_PATH).read_text(encoding="utf-8")) + if not isinstance(pin, dict): + raise ValueError("invalid GNN pin: expected a JSON object") + if pin.get("schema") != "gnn-importer-pin/v1": + raise ValueError("invalid GNN pin schema: expected gnn-importer-pin/v1") + if pin.get("tag") != "v5.0.3": + raise ValueError("invalid GNN pin tag: expected v5.0.3") + commit = pin.get("commit") + if not isinstance(commit, str) or re.fullmatch(r"[0-9a-fA-F]{40}", commit) is None: + raise ValueError("invalid GNN pin commit: expected a full 40-hex revision") + return pin def _format_value(value: float) -> str: diff --git a/docs/_generated/gate-metrics.md b/docs/_generated/gate-metrics.md index e128c9f..c059928 100644 --- a/docs/_generated/gate-metrics.md +++ b/docs/_generated/gate-metrics.md @@ -4,7 +4,7 @@ Measured wall times from recorded canonical gate observations on `macOS-27.0.1-arm64-arm-64bit` with Python 3.12.16 at `2026-11-12T13:56:34Z`. -First successful measurements retained for each arm. Package initially failed twice because offline pandas wheel metadata was unavailable; only package and the not-yet-run render arm were then run after SHA-256-verified acquisition of the exact pandas wheel in uv.lock. Those failures remain in this receipt’s runs. UV_FIND_LINKS pointed to that verified local wheelhouse for the successful package run. Baseline and after test selections differ by the new regression cases. No speedup is claimed. +First successful measurements retained for each arm. Package initially failed twice because offline pandas wheel metadata was unavailable; only package and the not-yet-run render arm were then run after SHA-256-verified acquisition of the exact pandas wheel in uv.lock. Those failures remain in this receipt’s runs. UV_FIND_LINKS pointed to that verified local wheelhouse for the successful package run. Baseline and after test selections differ by the new regression cases. No speedup is claimed. Audit refresh retains the earlier observations and two failed full-suite runs in runs; the notebook validator initially recursed into gitignored, untracked GNN migration build output. That output was moved aside without tracked changes for the successful 103-test run, then restored. Current lint, types, docs, GNN, render and full-suite observations are refreshed; other arm observations remain historical. The fresh render artifact was identified by the gate producer from source commit 2193be7b0be3fc429f4a8d159d4b96b249b12060. Refresh with: @@ -20,16 +20,16 @@ uv run python scripts/gate_metrics.py --record-timings /tmp/gate-after.json | Arm | Before (s) | Before status | After (s) | After status | After command | | --- | --- | --- | --- | --- | --- | -| `lint` | 0.11 | passed | 0.08 | passed | `uv run ruff check blockference tests GRTs scripts` | -| `types` | 0.61 | passed | 0.3 | passed | `uv run mypy blockference` | +| `lint` | 0.11 | passed | 0.03 | passed | `uv run ruff check blockference tests GRTs scripts` | +| `types` | 0.61 | passed | 1.06 | passed | `uv run mypy blockference` | | `test` | 33.27 | passed | 4.82 | passed | `uv run pytest -m not slow` | -| `test-full` | 55.38 | passed | 31.17 | passed | `uv run pytest --cov=blockference --cov-report=term --cov-report=xml --cov-fail-under=90` | -| `docs` | 7.45 | passed | 3.56 | passed | `uv run python scripts/check_docs_links.py` | +| `test-full` | 55.38 | passed | 44.22 | passed | `uv run pytest --cov=blockference --cov-report=term --cov-report=xml --cov-fail-under=90` | +| `docs` | 7.45 | passed | 5.28 | passed | `uv run python scripts/check_docs_links.py` | | `manuscript` | 6.04 | passed | 3.24 | passed | `uv run python scripts/manuscript_variables.py --check` | -| `gnn` | 2.78 | passed | 1.51 | passed | `uv run python scripts/export_gnn_spec.py --check` | +| `gnn` | 2.78 | passed | 2.0 | passed | `uv run python scripts/export_gnn_spec.py --check` | | `smoke` | 3.48 | passed | 2.55 | passed | `uv run blockference pipeline --config configs/smoke.yml --output-root /private/tmp/activeblockference-estate.8EbtJ4/tmp/activeblockference-gate-vx7lf7ds/output --run-name gate_smoke` | | `package` | 0.08 | failed | 14.86 | passed | `uv build` | -| `render` | 4.04 | passed | 6.18 | passed | `uv run python scripts/build_manuscript.py --render pdf` | +| `render` | 4.04 | passed | 4.46 | passed | `uv run python scripts/build_manuscript.py --render pdf` | Baseline workloads that are not equivalent to their arms: @@ -43,13 +43,13 @@ The baseline and current receipts are historical evidence. Timings include host | Selection | Collected tests | | --- | --- | -| full suite | 92 | -| fast (`-m "not slow"`) | 79 | +| full suite | 103 | +| fast (`-m "not slow"`) | 90 | | slow (`-m slow`) | 13 | -Recorded run: 92 passed, 0 skipped. +Recorded run: 103 passed, 0 skipped. -`test-full` recorded 90.94% line coverage of `blockference` (floor 90%). +`test-full` recorded 91.02% line coverage of `blockference` (floor 90%). ## Receipts diff --git a/docs/_generated/gate-timings.json b/docs/_generated/gate-timings.json index b7ab436..05ca8f3 100644 --- a/docs/_generated/gate-timings.json +++ b/docs/_generated/gate-timings.json @@ -5,7 +5,7 @@ "uv run python scripts/check_docs_links.py", "uv run python scripts/gate_metrics.py --check" ], - "seconds": 3.56, + "seconds": 5.28, "status": "passed" }, "gnn": { @@ -13,14 +13,14 @@ "uv run python scripts/export_gnn_spec.py --check", "uv run python scripts/validate_gnn_spec.py --gnn-runtime /private/tmp/gnn-rt-503/bin/python --json" ], - "seconds": 1.51, + "seconds": 2.0, "status": "passed" }, "lint": { "commands": [ "uv run ruff check blockference tests GRTs scripts" ], - "seconds": 0.08, + "seconds": 0.03, "status": "passed" }, "manuscript": { @@ -45,10 +45,16 @@ "status": "passed" }, "render": { + "artifact": { + "bytes": 262701, + "path": "docs/_build/manuscript/activeblockference.pdf", + "sha256": "77ee9b6ef9c83cc8b26ce5bd9130baa851ce5168b5d4207f3e2b3e16ce884f88", + "source_commit": "2193be7b0be3fc429f4a8d159d4b96b249b12060" + }, "commands": [ "uv run python scripts/build_manuscript.py --render pdf" ], - "seconds": 6.18, + "seconds": 4.46, "status": "passed" }, "smoke": { @@ -71,19 +77,19 @@ "commands": [ "uv run pytest --cov=blockference --cov-report=term --cov-report=xml --cov-fail-under=90" ], - "seconds": 31.17, + "seconds": 44.22, "status": "passed" }, "types": { "commands": [ "uv run mypy blockference" ], - "seconds": 0.3, + "seconds": 1.06, "status": "passed" } }, - "completed": "2026-11-12T14:02:13Z", - "conditions": "First successful measurements retained for each arm. Package initially failed twice because offline pandas wheel metadata was unavailable; only package and the not-yet-run render arm were then run after SHA-256-verified acquisition of the exact pandas wheel in uv.lock. Those failures remain in this receipt\u2019s runs. UV_FIND_LINKS pointed to that verified local wheelhouse for the successful package run. Baseline and after test selections differ by the new regression cases. No speedup is claimed.", + "completed": "2026-11-12T15:01:53Z", + "conditions": "First successful measurements retained for each arm. Package initially failed twice because offline pandas wheel metadata was unavailable; only package and the not-yet-run render arm were then run after SHA-256-verified acquisition of the exact pandas wheel in uv.lock. Those failures remain in this receipt\u2019s runs. UV_FIND_LINKS pointed to that verified local wheelhouse for the successful package run. Baseline and after test selections differ by the new regression cases. No speedup is claimed. Audit refresh retains the earlier observations and two failed full-suite runs in runs; the notebook validator initially recursed into gitignored, untracked GNN migration build output. That output was moved aside without tracked changes for the successful 103-test run, then restored. Current lint, types, docs, GNN, render and full-suite observations are refreshed; other arm observations remain historical. The fresh render artifact was identified by the gate producer from source commit 2193be7b0be3fc429f4a8d159d4b96b249b12060.", "generated": "2026-11-12T13:56:34Z", "host": "macOS-27.0.1-arm64-arm-64bit", "python": "3.12.16", @@ -209,12 +215,115 @@ "host": "macOS-27.0.1-arm64-arm-64bit", "python": "3.12.16", "schema": "activeblockference-gate/v1" + }, + { + "arms": { + "lint": { + "commands": [ + "uv run ruff check blockference tests GRTs scripts" + ], + "seconds": 0.03, + "status": "passed" + }, + "test-full": { + "commands": [ + "uv run pytest --cov=blockference --cov-report=term --cov-report=xml --cov-fail-under=90" + ], + "error": "Command '['uv', 'run', 'pytest', '--cov=blockference', '--cov-report=term', '--cov-report=xml', '--cov-fail-under=90']' returned non-zero exit status 1.", + "seconds": 17.61, + "status": "failed" + }, + "types": { + "commands": [ + "uv run mypy blockference" + ], + "seconds": 1.06, + "status": "passed" + } + }, + "generated": "2026-11-12T14:59:48Z", + "host": "macOS-27.0.1-arm64-arm-64bit", + "python": "3.12.16", + "schema": "activeblockference-gate/v1" + }, + { + "arms": { + "test-full": { + "commands": [ + "uv run pytest --cov=blockference --cov-report=term --cov-report=xml --cov-fail-under=90" + ], + "error": "Command '['uv', 'run', 'pytest', '--cov=blockference', '--cov-report=term', '--cov-report=xml', '--cov-fail-under=90']' returned non-zero exit status 1.", + "seconds": 24.86, + "status": "failed" + } + }, + "generated": "2026-11-12T15:00:39Z", + "host": "macOS-27.0.1-arm64-arm-64bit", + "python": "3.12.16", + "schema": "activeblockference-gate/v1" + }, + { + "arms": { + "docs": { + "commands": [ + "uv run python scripts/check_docs_links.py", + "uv run python scripts/gate_metrics.py --check" + ], + "seconds": 5.28, + "status": "passed" + }, + "gnn": { + "commands": [ + "uv run python scripts/export_gnn_spec.py --check", + "uv run python scripts/validate_gnn_spec.py --gnn-runtime /private/tmp/gnn-rt-503/bin/python --json" + ], + "seconds": 2.0, + "status": "passed" + }, + "render": { + "artifact": { + "bytes": 262701, + "path": "docs/_build/manuscript/activeblockference.pdf", + "sha256": "77ee9b6ef9c83cc8b26ce5bd9130baa851ce5168b5d4207f3e2b3e16ce884f88", + "source_commit": "2193be7b0be3fc429f4a8d159d4b96b249b12060" + }, + "commands": [ + "uv run python scripts/build_manuscript.py --render pdf" + ], + "seconds": 4.46, + "status": "passed" + } + }, + "generated": "2026-11-12T15:01:36Z", + "host": "macOS-27.0.1-arm64-arm-64bit", + "python": "3.12.16", + "schema": "activeblockference-gate/v1" + }, + { + "arms": { + "test-full": { + "commands": [ + "uv run pytest --cov=blockference --cov-report=term --cov-report=xml --cov-fail-under=90" + ], + "seconds": 44.22, + "status": "passed" + } + }, + "generated": "2026-11-12T15:01:53Z", + "host": "macOS-27.0.1-arm64-arm-64bit", + "python": "3.12.16", + "schema": "activeblockference-gate/v1", + "tests": { + "coverage_percent": 91.02, + "passed": 103, + "skipped": 0 + } } ], "schema": "activeblockference-gate/v1", "tests": { - "coverage_percent": 90.94, - "passed": 92, + "coverage_percent": 91.02, + "passed": 103, "skipped": 0 } } diff --git a/docs/gate.md b/docs/gate.md index 1ac3dd5..e0996a5 100644 --- a/docs/gate.md +++ b/docs/gate.md @@ -92,7 +92,11 @@ the workflow installs the locked environment directly. `release_check.py --timings PATH` writes the actual commands, statuses, and elapsed times for the selected run, including a failed arm. Use a fresh receipt path for each run; selecting `render` separately records the explicit local PDF -build without adding it to CI. +build without adding it to CI. A passing render arm also records `artifact`: +the repository-relative PDF path, exact byte count, SHA-256, and source commit +(`git rev-parse HEAD`). Commit source changes before recording a release render +so that commit identifies the rendered source. The PDF remains ignored; the +receipt identifies the local bytes without publishing the binary. Import receipts before regenerating the checked metrics page: diff --git a/docs/gnn.md b/docs/gnn.md index f64d505..d0c817a 100644 --- a/docs/gnn.md +++ b/docs/gnn.md @@ -83,7 +83,13 @@ The receipt is written to `docs/_build/gnn/validation-receipt.json` * `render_spec(parameters)` — the document text. * `parameters_from_parsed(payload)` / `declared_arrays(payload)` — read a pinned parser payload back into parameters and matrices. -* `load_pin()` — the recorded upstream pin. +* `load_pin()` — the recorded upstream pin, requiring schema + `gnn-importer-pin/v1`, tag `v5.0.3`, and a full 40-hex commit. Invalid records + raise `ValueError` naming the field. This interim local reader remains in use + because the estate pin predates `gnn.importers`; shared-reader adoption requires + a pin containing that upstream API, not a vendored copy. + CI provisioning uses this same reader in the locked package environment, + rather than independently loading unvalidated JSON. ## Scope diff --git a/scripts/release_check.py b/scripts/release_check.py index 5bdf138..689fd64 100644 --- a/scripts/release_check.py +++ b/scripts/release_check.py @@ -28,6 +28,7 @@ from __future__ import annotations import argparse +import hashlib import json import os import platform @@ -38,6 +39,11 @@ import time from pathlib import Path +if __package__: + from scripts.build_manuscript import RENDER_TARGETS +else: + from build_manuscript import RENDER_TARGETS + ROOT = Path(__file__).resolve().parents[1] SCHEMA = "activeblockference-gate/v1" @@ -276,6 +282,24 @@ def _selected(arms: list[str]) -> list[str]: return [arm for arm in ARM_ORDER if arm in expanded] +def _render_artifact() -> dict[str, object]: + """Identify the PDF bytes produced by the successful render command.""" + + pdf = RENDER_TARGETS["pdf"] + with pdf.open("rb") as handle: + digest = hashlib.file_digest(handle, "sha256").hexdigest() + commit = subprocess.run( + ["git", "rev-parse", "HEAD"], cwd=ROOT, check=True, text=True, + capture_output=True, stdin=subprocess.DEVNULL, + ).stdout.strip() + return { + "path": pdf.relative_to(ROOT).as_posix(), + "bytes": pdf.stat().st_size, + "sha256": digest, + "source_commit": commit, + } + + def _write_receipt(path: Path, receipt: dict[str, object]) -> None: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n", encoding="utf-8") @@ -365,6 +389,7 @@ def main(argv: list[str] | None = None) -> int: ) if arm == "test-full": tests["coverage_percent"] = _coverage_percent() + artifact = _render_artifact() if arm == "render" else None except (subprocess.CalledProcessError, FileNotFoundError, RuntimeError, ValueError) as exc: failed = True arms_receipt[arm] = { @@ -381,6 +406,8 @@ def main(argv: list[str] | None = None) -> int: "status": "passed", "commands": [" ".join(command) for command in commands], } + if artifact is not None: + arms_receipt[arm]["artifact"] = artifact print(f"{arm} passed in {elapsed:.2f}s", flush=True) receipt["arms"] = arms_receipt diff --git a/tests/test_gnn_spec.py b/tests/test_gnn_spec.py index 98224ae..d800e77 100644 --- a/tests/test_gnn_spec.py +++ b/tests/test_gnn_spec.py @@ -16,6 +16,7 @@ GNN_SPEC_PATH, build_spec_model, declared_arrays, + load_pin, parameters_from_parsed, render_spec, spec_arrays, @@ -68,6 +69,44 @@ def _parsed_payload() -> dict: } +def test_local_pin_reader_accepts_the_committed_contract(): + pin = load_pin() + assert pin["schema"] == "gnn-importer-pin/v1" + assert pin["tag"] == "v5.0.3" + assert len(pin["commit"]) == 40 + + +@pytest.mark.parametrize( + ("field", "value", "message"), + [ + ("schema", None, "schema"), + ("schema", "unknown/v1", "schema"), + ("tag", None, "tag"), + ("tag", "v5.0.4", "tag"), + ("commit", None, "commit"), + ("commit", "8f293d9b", "commit"), + ("commit", "z" * 40, "commit"), + ], +) +def test_local_pin_reader_rejects_invalid_declared_fields(tmp_path, field, value, message): + pin = load_pin() + if value is None: + del pin[field] + else: + pin[field] = value + path = tmp_path / "pin.json" + path.write_text(json.dumps(pin), encoding="utf-8") + with pytest.raises(ValueError, match=f"invalid GNN pin {message}"): + load_pin(path) + + +def test_local_pin_reader_rejects_non_object_json(tmp_path): + path = tmp_path / "pin.json" + path.write_text("[]", encoding="utf-8") + with pytest.raises(ValueError, match="expected a JSON object"): + load_pin(path) + + def test_committed_spec_is_generated_from_the_implementation(): assert exporter.check() == [] diff --git a/tests/test_release_gate.py b/tests/test_release_gate.py index 7cdabc5..974202b 100644 --- a/tests/test_release_gate.py +++ b/tests/test_release_gate.py @@ -2,12 +2,17 @@ from __future__ import annotations +import hashlib import json import os import subprocess import sys from pathlib import Path +import pytest + +import scripts.release_check as gate + ROOT = Path(__file__).resolve().parents[1] @@ -35,3 +40,40 @@ def test_gnn_arm_without_runtime_cannot_write_a_passing_receipt(tmp_path): assert payload["arms"]["gnn"]["status"] == "failed" summary = next(line for line in result.stdout.splitlines() if line.startswith('{"arms":')) assert json.loads(summary)["ok"] is False + + +def test_render_receipt_identifies_the_produced_pdf(tmp_path, monkeypatch): + pdf = tmp_path / "manuscript.pdf" + content = b"%PDF-1.4\nrender receipt regression\n" + receipt = tmp_path / "gate.json" + monkeypatch.setattr(gate, "ROOT", tmp_path) + monkeypatch.setitem(gate.RENDER_TARGETS, "pdf", pdf) + subprocess.run(["git", "init", "-q", str(tmp_path)], check=True) + subprocess.run( + ["git", "-c", "user.name=Gate Test", "-c", "user.email=gate@example.invalid", + "commit", "--allow-empty", "-qm", "source"], + cwd=tmp_path, check=True, + ) + commit = subprocess.check_output( + ["git", "rev-parse", "HEAD"], cwd=tmp_path, text=True, + ).strip() + + def render(command): + pdf.write_bytes(content) + + monkeypatch.setattr(gate, "_run", render) + assert gate.main(["--arm", "render", "--timings", str(receipt)]) == 0 + recorded = json.loads(receipt.read_text(encoding="utf-8"))["arms"]["render"] + assert recorded["status"] == "passed" + assert recorded["artifact"] == { + "path": "manuscript.pdf", + "bytes": len(content), + "sha256": hashlib.sha256(content).hexdigest(), + "source_commit": commit, + } + + +def test_render_provenance_requires_the_pdf(tmp_path, monkeypatch): + monkeypatch.setitem(gate.RENDER_TARGETS, "pdf", tmp_path / "absent.pdf") + with pytest.raises(FileNotFoundError): + gate._render_artifact()