docs(thesis): resolve review findings and verify examples

This commit is contained in:
lda
2026-09-14 13:40:11 +07:00 Verified
parent 5495dc5656
commit 396caa63d6
8 changed files with 273 additions and 45 deletions
+43
View File
@@ -58,3 +58,46 @@ def test_abbreviations_compile_without_a_dummy_float(tmp_path: Path) -> None:
assert "API" in rendered
assert "Application Programming Interface" in rendered
assert "None 1" not in rendered
@pytest.mark.skipif(
any(shutil.which(tool) is None for tool in ("pandoc", "xelatex", "pdftotext")),
reason="Pandoc, XeLaTeX, and pdftotext are needed for the inline-code build",
)
def test_inline_identifier_moves_to_next_line_intact(tmp_path: Path) -> None:
"""A prose line ending must not split a callable's name into fragments."""
output = tmp_path / "inline.pdf"
identifier = "local.report.render_markdown_report"
result = subprocess.run(
[
"pandoc",
"--standalone",
"--pdf-engine=xelatex",
"--variable=geometry:textwidth=10cm",
"--variable=monofont:Libertinus Mono",
"--include-in-header",
str(THESIS / "header-includes.tex"),
"--output",
str(output),
],
# Shift the identifier along the line to expose both forced splitting
# and font-dependent automatic hyphenation near the right margin.
input="\n\n".join(
f"{'word ' * count}`{identifier}`." for count in range(1, 16)
),
text=True,
encoding="utf-8",
capture_output=True,
check=False,
timeout=90,
)
assert result.returncode == 0, result.stderr
rendered = subprocess.run(
["pdftotext", "-layout", str(output), "-"],
capture_output=True,
text=True,
encoding="utf-8",
check=True,
timeout=15,
).stdout
assert rendered.count(identifier) == 15
@@ -0,0 +1,28 @@
"""Exercise the comparison snippet when the optional LangGraph library exists."""
from pathlib import Path
import pytest
@pytest.mark.parametrize(
("text", "expected_report"),
[(" Notes ", "# Report\n\nNotes"), (" ", "")],
)
def test_langgraph_comparison_routes_updated_state(
text: str, expected_report: str
) -> None:
"""Check the rendered example without making LangGraph a product dependency."""
pytest.importorskip("langgraph.graph")
manuscript = (
Path(__file__).resolve().parents[2]
/ "docs/thesis/system-design-implementation.md"
).read_text(encoding="utf-8")
section = manuscript.split("<!-- langgraph-comparison -->", 1)[1]
snippet = section.split("```python\n", 1)[1].split("```", 1)[0]
namespace = {}
# This is trusted repository prose, executed exactly as displayed.
exec(compile(snippet, "thesis-langgraph-example", "exec"), namespace)
result = namespace["graph"].invoke({"text": text, "report": ""})
assert result["text"] == text.strip()
assert result["report"] == expected_report
@@ -10,9 +10,11 @@ from typing import Any, cast
import pytest
from wf_client import App, Deployment, Run
from wf_api.durable_context import durable_workflow_api
from wf_client import App, Deployment, Run, Schedule
from wf_client.protocols import WorkflowClientPort
from wf_config import load_workflow_config
from wf_scheduling.store import FileScheduleStore
from wf_server.config import build_workflow_server_from_workflow_config
ROOT = Path(__file__).resolve().parents[2]
@@ -32,7 +34,11 @@ async def test_thesis_python_session_preserves_report_and_repair(
config = load_workflow_config(ROOT / "examples/report_workflow/wf.config.json")
config.server.store.root = tmp_path / "store"
server = build_workflow_server_from_workflow_config(config)
app = App._from_port(cast(WorkflowClientPort, server.api))
# Enable real schedule persistence without starting a background scheduler:
# this session verifies registration, while another test exercises dispatch.
schedule_store = FileScheduleStore(config.server.store.root)
api = durable_workflow_api(server.context, schedule_store=schedule_store)
app = App._from_port(cast(WorkflowClientPort, api))
monkeypatch.chdir(ROOT)
manuscript = THESIS.read_text(encoding="utf-8")
@@ -84,3 +90,14 @@ async def test_thesis_python_session_preserves_report_and_repair(
for displayed in displayed_outputs:
assert displayed in diagnostic, "Displayed output differs from the session"
assert namespace["trace"].frames
schedule = namespace["schedule"]
assert isinstance(schedule, Schedule)
assert schedule.deployment_id == deployment.deployment_id
assert schedule.max_steps == 100
assert schedule.trigger["kind"] == "oneshot"
persisted = schedule_store.get_schedule(schedule.schedule_id)
assert persisted is not None
expression = persisted.input_bindings[0].expression
assert expression.kind == "literal"
assert expression.value == namespace["notes"]
assert namespace["history"]["occurrences"] == []