Files
OBLITERATUS/tests/test_concept_docs.py
T
Joseph MaglyandClaude Opus 5.5 d531158d30 docs(concepts): add concept workflow and interpretation guide
docs/CONCEPT_WORKFLOW.md walks a concept from definition to export
(define, extract, validate, intervene, evaluate, repair, compare/export),
with offline CLI examples. Its interpretation guide covers what
validation, ablation and steering do and do not show: behavioural nulls
as first-class results, hidden KV-cache channels, steering fragility, and
why "direction removed" is not "experience removed". A responsible-use
section covers user-defined concepts.

Every literature claim is cited by arXiv id or DOI. The existing concept
docs link to the guide, and the README gains a short "Concept vectors
beyond refusal" section. A test runs the outcome-language lint over the
concept docs, resolves local links and anchors, checks that every
documented `obliteratus` command parses, and checks the required
citations.

Closes #235

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 23:50:49 -04:00

123 lines
4.3 KiB
Python

"""CV-12 concept docs: outcome lint, link resolution, CLI examples, citations."""
from pathlib import Path
import re
import shlex
from urllib.parse import unquote
import pytest
from obliteratus.concepts.export import lint_outcome_language
from scripts import check_checkpoint_docs as docs_check
pytestmark = pytest.mark.cpu
ROOT = Path(__file__).resolve().parents[1]
CONCEPT_DOCS = [
ROOT / "docs/CONCEPT_WORKFLOW.md",
ROOT / "docs/CONCEPT_PACKS.md",
ROOT / "docs/CONCEPT_VALIDATION.md",
ROOT / "docs/CONCEPT_INTERVENTIONS.md",
]
WORKFLOW_GUIDE = ROOT / "docs/CONCEPT_WORKFLOW.md"
REQUIRED_CITATIONS = [
"arXiv:2406.11717",
"arXiv:2609.16247",
"doi:10.5281/zenodo.22902830",
"arXiv:2609.35591",
"arXiv:2502.17420",
"arXiv:2512.18901",
"arXiv:2512.13655",
"arXiv:2503.05613",
]
_FENCE = re.compile(r"^```(\w[\w+-]*)\s*$")
def _commands(text):
"""Inline and fenced `obliteratus ...` examples with continuations joined."""
candidates = list(docs_check.INLINE_CODE.findall(text))
in_fence = False
current = []
for line in text.splitlines():
if _FENCE.match(line.strip()):
if in_fence and current:
candidates.extend(current)
in_fence, current = not in_fence, []
continue
if in_fence:
stripped = line.strip().removeprefix("$ ")
if stripped.endswith("\\"):
current.append(stripped[:-1])
continue
if current:
current.append(stripped)
candidates.extend([" ".join(current)])
current = []
elif stripped.startswith("obliteratus"):
candidates.append(stripped)
commands = []
for candidate in candidates:
try:
parts = shlex.split(candidate)
except ValueError:
continue
if parts and parts[0] == "obliteratus":
commands.append(candidate)
return commands
def test_outcome_language_covers_concept_docs():
for document in CONCEPT_DOCS:
lint_outcome_language(document.read_text(encoding="utf-8"))
def test_concept_doc_links_resolve():
errors = []
for document in CONCEPT_DOCS:
for raw_target in docs_check.MARKDOWN_LINK.findall(
document.read_text(encoding="utf-8")
):
target = raw_target.strip().split(maxsplit=1)[0].strip("<>")
if re.match(r"^[a-z][a-z0-9+.-]*:", target, re.IGNORECASE):
continue
path_text, separator, fragment = target.partition("#")
resolved = (document.parent / unquote(path_text)).resolve() if path_text else document
if not resolved.is_file():
errors.append(f"{document.name} has missing local link: {target}")
continue
if separator:
if resolved.suffix.lower() != ".md":
errors.append(f"{document.name} anchors non-Markdown target: {target}")
elif unquote(fragment).lower() not in docs_check._anchors(resolved):
errors.append(f"{document.name} has missing anchor: {target}")
assert errors == []
def test_concept_doc_cli_examples_parse():
failures = []
for document in CONCEPT_DOCS:
for command in _commands(document.read_text(encoding="utf-8")):
try:
docs_check._parse_without_dispatch(shlex.split(command)[1:])
except ValueError as exc:
failures.append(f"{document.name} invalid CLI example {command!r}: {exc}")
assert failures == []
def test_workflow_guide_cites_required_literature():
text = WORKFLOW_GUIDE.read_text(encoding="utf-8")
for citation in REQUIRED_CITATIONS:
assert citation in text, f"workflow guide is missing {citation}"
assert (
f"](https://arxiv.org/abs/{citation.removeprefix('arXiv:')})" in text
if citation.startswith("arXiv:")
else f"](https://doi.org/{citation.removeprefix('doi:')})" in text
), f"workflow guide must link {citation}"
def test_workflow_guide_uses_outcome_language():
text = WORKFLOW_GUIDE.read_text(encoding="utf-8")
assert "Direction removed on the measured readout." in text
assert "Behaviour changed on battery" in text
assert "No behaviour change detected on battery" in text