Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ missing the bridge document that multi-hop surfaces.
```python
from context_runtime import ContextRuntime, SourceRef

docs = [] # your documents; empty here so the tour runs offline
rt = ContextRuntime.default(docs) # offline: stub model + in-memory store

# RUN — the core abstraction (plan → build_context → execute → verify)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_readme_tour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""The README's published API tour must run exactly as written, offline.

The test extracts the first python block under "## 30-second tour" and executes it verbatim in a fresh namespace
(no edits, no extra setup), so the README cannot drift from the API again.
"""
from __future__ import annotations

import contextlib
import io
import re
from pathlib import Path

README = Path(__file__).resolve().parent.parent / "README.md"


def _python_block(heading: str) -> str:
text = README.read_text(encoding="utf-8")
m = re.search(rf"^## {re.escape(heading)}\n(.*?)(?=^## )", text, re.S | re.M)
assert m, f"README has no '## {heading}' section"
blocks = re.findall(r"```python\n(.*?)```", m.group(1), re.S)
assert blocks, f"no python block under '## {heading}'"
return blocks[0]


def test_readme_30_second_tour_runs_verbatim():
code = _python_block("30-second tour")
out = io.StringIO()
with contextlib.redirect_stdout(out):
exec(compile(code, "README.md (30-second tour)", "exec"), {"__name__": "__readme_tour__"})
printed = [line for line in out.getvalue().splitlines() if line.strip()]
assert len(printed) >= 3, printed # RUN, EXPLAIN and SIMULATE each print a line
Loading