Single 30-second artifact composing four CORE invariants
(determinism, honest unknown, reviewed learning, multi-hop with
trace) by delegating to existing DemoCommand adapters. **No new
mechanism** — every claim is backed by an already-shipped,
separately-tested adapter. Closes the 8-ADR scale-up slate.
- new core/demos/learning_loop_adapter.py: LearningLoopDemo wraps
ADR-0056 reviewed-teaching loop; _strip_volatile_paths drops
transient temp-dir paths from raw before serialization so the
adapter's report_sha256 is content-stable across runs
- new core/demos/showcase_adapters.py:
- FabricationControlPublicDemo: re-runs ADR-0096 public split,
produces 3 claims (refusal_recall_meets_threshold,
fabrication_rate_below_threshold, trace_evidence_present)
- MultiHopTraceDemo: runs 'Does light reveal truth?' with
transitive_surface=True + composed_surface=True against
cognition pack; surfaces a 3-hop walk light→truth→knowledge→
evidence; produces 3 claims (grounded_answer, depth_two_or_more,
walk_evidence_present)
- new core/demos/showcase.py: run_showcase() composes 4 scenes,
emits showcase.json + per-scene artifacts; render_html() produces
presentation-only static HTML with no JS injection vector;
ShowcaseScene dataclass; MAX_RUNTIME_SECONDS=30 hard ceiling
with DemoContractError if exceeded
- CLI: 'showcase' added to demo target choices; --output-dir flag
added; cmd_demo dispatch branch writes showcase.json + showcase.html
- new evals/public_demo/ lane with 4 cases:
- all_claims_supported (each scene + composite)
- determinism_run_to_run_byte_equality (two runs identical after
stripping volatile keys: total_runtime_ms, json_path,
transient_corpus)
- runtime_under_budget (≤30s)
- pure_composition_no_new_mechanism (grep gate over showcase
imports — must come from core/chat/generate/language_packs/
teaching/evals or allowed stdlib only)
- lane is itself byte-identical across runs (sha256 5707db8efc6a..);
runtime case omits exact runtime_ms (it varies near bucket
boundaries) but still asserts ≤ budget
- 8 unit tests with module-scoped fixture (showcase runs once,
~13s total) covering payload shape, scene order, runtime budget,
HTML render absence of <script>, and the pure-composition import
gate independently of the lane
- ADR-0099 measured: total_runtime_ms ~12.8s, well under 30s budget
- smoke 67/67, cognition eval byte-identical 100/100/100/100;
all 6 ADR-0092..0099 lanes byte-identical:
reviewer_registry 681a2aab..
miner_loop_closure 9f071733..
domain_contract_validation f9c06cde..
fabrication_control sum 01e1b6b7..
demo_composition 27d83824..
public_demo 5707db8e..
153 lines
4.9 KiB
Python
153 lines
4.9 KiB
Python
"""ADR-0099 Public Showcase Demo — unit tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
from core.demos.showcase import (
|
|
MAX_RUNTIME_SECONDS,
|
|
SHOWCASE_VERSION,
|
|
render_html,
|
|
run_showcase,
|
|
)
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def showcase_payload() -> Iterator[dict[str, Any]]:
|
|
"""Run the showcase once and share its payload across all tests.
|
|
|
|
A full showcase run takes ~13s; running it per-test would balloon
|
|
the suite. Module-scoped fixture keeps all assertions on one
|
|
canonical artifact, which also better matches the production
|
|
invariant (one artifact, many claims).
|
|
"""
|
|
with tempfile.TemporaryDirectory(prefix="public_showcase_test_") as d:
|
|
yield run_showcase(output_dir=Path(d))
|
|
|
|
|
|
class TestShowcaseExecution:
|
|
def test_runs_and_returns_payload(self, showcase_payload: dict[str, Any]) -> None:
|
|
assert showcase_payload["showcase_version"] == SHOWCASE_VERSION
|
|
assert showcase_payload["claim_contract_version"] == 1
|
|
assert showcase_payload["max_runtime_seconds"] == MAX_RUNTIME_SECONDS
|
|
assert showcase_payload["all_claims_supported"] is True
|
|
|
|
def test_four_scenes_in_canonical_order(
|
|
self, showcase_payload: dict[str, Any]
|
|
) -> None:
|
|
assert [s["scene_id"] for s in showcase_payload["scenes"]] == [
|
|
"determinism",
|
|
"honest_unknown",
|
|
"reviewed_learning",
|
|
"multi_hop_trace",
|
|
]
|
|
|
|
def test_every_scene_has_at_least_one_supported_claim(
|
|
self, showcase_payload: dict[str, Any]
|
|
) -> None:
|
|
for scene in showcase_payload["scenes"]:
|
|
assert scene["claims"], f"scene {scene['scene_id']} has no claims"
|
|
for claim in scene["claims"]:
|
|
assert claim["supported"] is True
|
|
|
|
def test_runtime_within_budget(self, showcase_payload: dict[str, Any]) -> None:
|
|
runtime_ms = showcase_payload["total_runtime_ms"]
|
|
budget_ms = MAX_RUNTIME_SECONDS * 1000
|
|
assert runtime_ms <= budget_ms, (
|
|
f"showcase exceeded {budget_ms} ms budget; ran {runtime_ms} ms"
|
|
)
|
|
|
|
|
|
class TestHtmlRender:
|
|
def test_html_is_static_html(self, showcase_payload: dict[str, Any]) -> None:
|
|
html = render_html(showcase_payload)
|
|
assert html.startswith("<!doctype html>")
|
|
assert "</html>" in html
|
|
# No operator-supplied template path; no JS injection vector.
|
|
assert "<script" not in html.lower()
|
|
|
|
def test_html_renders_scene_ids(self, showcase_payload: dict[str, Any]) -> None:
|
|
html = render_html(showcase_payload)
|
|
for scene in showcase_payload["scenes"]:
|
|
assert scene["scene_id"] in html
|
|
|
|
|
|
class TestPureCompositionGate:
|
|
"""ADR-0099 invariant: ``public_showcase_pure_composition``.
|
|
|
|
Showcase imports must come from already-shipped packages
|
|
(``core/``, ``chat/``, ``generate/``, ``language_packs/``,
|
|
``teaching/``, ``evals/``) plus the stdlib. Any other import is
|
|
a new mechanism and must be blocked.
|
|
"""
|
|
|
|
ALLOWED_PREFIXES = (
|
|
"core.",
|
|
"chat.",
|
|
"generate.",
|
|
"language_packs.",
|
|
"teaching.",
|
|
"evals.",
|
|
)
|
|
ALLOWED_STDLIB = frozenset(
|
|
{
|
|
"__future__",
|
|
"subprocess",
|
|
"time",
|
|
"pathlib",
|
|
"typing",
|
|
"dataclasses",
|
|
"html",
|
|
"re",
|
|
"hashlib",
|
|
"json",
|
|
"os",
|
|
"sys",
|
|
}
|
|
)
|
|
|
|
SHOWCASE_SOURCES = (
|
|
REPO_ROOT / "core" / "demos" / "showcase.py",
|
|
REPO_ROOT / "core" / "demos" / "showcase_adapters.py",
|
|
REPO_ROOT / "core" / "demos" / "learning_loop_adapter.py",
|
|
)
|
|
|
|
def _imports_in(self, path: Path) -> list[str]:
|
|
import re
|
|
|
|
pattern = re.compile(r"^\s*(?:from\s+([\w\.]+)\s+import|import\s+([\w\.]+))")
|
|
mods: list[str] = []
|
|
for line in path.read_text(encoding="utf-8").splitlines():
|
|
match = pattern.match(line)
|
|
if match:
|
|
mods.append(match.group(1) or match.group(2))
|
|
return mods
|
|
|
|
def test_no_forbidden_imports(self) -> None:
|
|
forbidden: list[str] = []
|
|
for source in self.SHOWCASE_SOURCES:
|
|
for mod in self._imports_in(source):
|
|
if mod.startswith(self.ALLOWED_PREFIXES):
|
|
continue
|
|
if mod in self.ALLOWED_STDLIB:
|
|
continue
|
|
if mod.split(".", 1)[0] in self.ALLOWED_STDLIB:
|
|
continue
|
|
forbidden.append(f"{source.name}: {mod}")
|
|
assert forbidden == [], (
|
|
"ADR-0099 pure-composition violation: forbidden imports "
|
|
f"{forbidden}"
|
|
)
|
|
|
|
|
|
class TestRuntimeBudget:
|
|
def test_budget_is_thirty_seconds(self) -> None:
|
|
assert MAX_RUNTIME_SECONDS == 30
|