core/tests/test_articulation_bench.py
Shay 4670e391ec feat(phase5+bench): cross-pack supersede + articulation benchmark suite
Phase 5 (ADR-0067 follow-up):
  teaching/cross_pack_supersede.py — supersede_cross_pack_chain()
  CLI: core teaching supersede ... --cross-pack
    --subject-pack-id ... --object-pack-id ...
  Strict per-chain residency, anti-leakage, byte-identical rollback
  on any post-append re-load failure.  9 new tests.

Articulation benchmark suite (Phase 4 capability proof):
  benchmarks/articulation.py — 5 sub-benches
    [1] breadth        — every intent shape (9 + OOV + cross-pack)
    [2] determinism    — N reruns / unique-surface count
    [3] footprint      — psutil RSS profile across T turns
    [4] cross-topic    — thread context across mixed subjects
    [5] ollama-compare — opt-in side-by-side with local Ollama
  CLI: core bench --suite articulation
    --runs N (det rerun count)
    --turns N (footprint sample window)
    --ollama-model MODEL --ollama-reruns N
  Full operator preamble + JSON report path.
  10 new tests cover the bench shape (psutil import-skipped).

Documentation:
  benchmarks/README.md — full operator manual: catalogue of every
    bench suite, how to read good/neutral/bad results for each sub-
    bench, why CORE vs Ollama comparisons are valid on the
    determinism axis and not on linguistic quality, workflow guide.
  README.md — articulation bench listed in the live-demo grid and
    quick-start examples.

Reference run (llama3:8b, 100 turns, 5 reruns):
  determinism_all_identical=True
  per-turn ΔRSS ≈ 23 KiB
  CORE byte_identical_on_every_prompt=True
  Ollama unique_surfaces≥2 on every prompt

Verification:
  18 new tests pass
  Full lane: 2116 passed, 2 skipped, 0 failed in 2:38
2026-05-18 17:44:59 -07:00

149 lines
5.1 KiB
Python

"""Smoke + contract tests for the articulation benchmark suite.
These are tests for the **bench itself** — not the underlying runtime
behaviour, which is exercised by the cognition lane. The bench is
load-bearing for the post-Phase-4 capability claims, so each sub-
bench gets a focused test that pins the shape of its report.
"""
from __future__ import annotations
import pytest
from benchmarks.articulation import (
INTENT_PROBE_PROMPTS,
CROSS_TOPIC_PROMPTS,
bench_breadth,
bench_cross_topic,
bench_determinism,
bench_footprint,
bench_ollama_compare,
run_articulation_suite,
)
# ---------------------------------------------------------------------------
# Breadth
# ---------------------------------------------------------------------------
@pytest.fixture(scope="module")
def breadth_report():
return bench_breadth()
def test_breadth_covers_every_supported_intent_shape(breadth_report) -> None:
labels = [p.label for p in breadth_report]
expected = [label for label, _ in INTENT_PROBE_PROMPTS]
assert labels == expected
def test_breadth_emits_per_prompt_grounding_tag(breadth_report) -> None:
for p in breadth_report:
assert p.grounding_source in {
"vault", "teaching", "pack", "partial", "oov", "none",
}
def test_breadth_oov_prompt_routes_oov(breadth_report) -> None:
oov = next(p for p in breadth_report if p.label == "OOV_FALLBACK")
assert oov.grounding_source == "oov"
# The OOV invitation always names the unfamiliar token; the
# ``PackMutationProposal`` callout follows but may be truncated
# by the snippet limit.
assert "photosynthesis" in oov.surface_snippet
assert "haven't learned" in oov.surface_snippet
def test_breadth_cross_pack_verification_routes_teaching(breadth_report) -> None:
cp = next(
p for p in breadth_report
if p.label == "CROSS_PACK_VERIFICATION"
)
assert cp.grounding_source == "teaching"
assert "cross-pack-grounded" in cp.surface_snippet
# ---------------------------------------------------------------------------
# Determinism
# ---------------------------------------------------------------------------
def test_determinism_byte_identical_across_runs() -> None:
cases, all_identical = bench_determinism(runs=5)
assert all_identical is True
for c in cases:
assert c.unique_surfaces == 1, (
f"prompt {c.prompt!r} produced {c.unique_surfaces} unique "
f"surfaces across {c.runs} runs"
)
# ---------------------------------------------------------------------------
# Footprint
# ---------------------------------------------------------------------------
def test_footprint_emits_samples_and_bounds() -> None:
pytest.importorskip("psutil")
samples, start, peak, end, per_turn = bench_footprint(
turns=20, sample_every=10,
)
assert len(samples) >= 2 # start + at least one mid/end sample
assert peak >= start
assert end >= 0
# Per-turn ΔRSS must be a small number; if it's huge we have a leak.
# 1 MiB / turn is a hard ceiling for the smoke test.
assert abs(per_turn) < 1_048_576, (
f"per-turn ΔRSS too large ({per_turn} bytes); possible leak"
)
# ---------------------------------------------------------------------------
# Cross-topic
# ---------------------------------------------------------------------------
def test_cross_topic_visits_every_prompt() -> None:
turns, _fires = bench_cross_topic()
assert len(turns) == len(CROSS_TOPIC_PROMPTS)
for i, t in enumerate(turns):
assert t.turn == i
assert t.prompt == CROSS_TOPIC_PROMPTS[i]
# Every cross-topic turn either grounds via a recognised tier
# or returns ``none`` — never a raw exception escape.
assert t.grounding_source in {
"vault", "teaching", "pack", "partial", "oov", "none",
}
# ---------------------------------------------------------------------------
# Ollama (skipped when binary absent)
# ---------------------------------------------------------------------------
def test_ollama_compare_skips_cleanly_when_no_model_specified() -> None:
"""Calling without ``model`` argument is the documented opt-out."""
result = bench_ollama_compare(model=None)
assert result["status"] == "skipped"
# ---------------------------------------------------------------------------
# Orchestrator
# ---------------------------------------------------------------------------
def test_run_articulation_suite_emits_shaped_report() -> None:
pytest.importorskip("psutil")
report = run_articulation_suite(
determinism_runs=3, footprint_turns=10,
footprint_sample_every=5, ollama_model=None,
)
d = report.as_dict()
assert isinstance(d["breadth"], list) and len(d["breadth"]) > 0
assert isinstance(d["determinism"], list)
assert d["determinism_all_identical"] is True
assert isinstance(d["footprint_samples"], list)
assert d["ollama"]["status"] == "skipped"
# Cross-topic walk runs every entry.
assert len(d["cross_topic"]) == len(CROSS_TOPIC_PROMPTS)