Spec explorer data endpoint, spec file finder, browser render test (failing)

- Add spec-explorer-data-by-slug helper with _SPEC_SLUG_MAP
- _find_spec_file searches spec/, web/, shared/sx/ref/ directories
- defpage specs-explore-page uses :data for server-side data fetch
- test_evaluator_renders_in_browser: failing test for client-side rendering
  (client re-evaluates defpage content, find-spec unavailable — pre-existing)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 17:36:21 +00:00
parent 71c2003a60
commit fac97883f9
6 changed files with 100 additions and 15 deletions

View File

@@ -159,18 +159,35 @@ def _reference_data(slug: str) -> dict:
return build_reference_data(slug, raw, detail_keys)
def _read_spec_file(filename: str) -> str:
"""Read a spec .sx file from the ref directory. Pure I/O — metadata lives in .sx."""
def _find_spec_file(filename: str) -> str | None:
"""Find a spec .sx file across spec/, web/, shared/sx/ref/ directories."""
import os
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
if not os.path.isdir(ref_dir):
ref_dir = "/app/shared/sx/ref"
filepath = os.path.join(ref_dir, filename)
base = os.path.join(os.path.dirname(__file__), "..", "..")
search_dirs = [
os.path.join(base, "spec"),
os.path.join(base, "web"),
os.path.join(base, "shared", "sx", "ref"),
"/app/spec",
"/app/web",
"/app/shared/sx/ref",
]
for d in search_dirs:
path = os.path.join(d, filename)
if os.path.isfile(path):
return path
return None
def _read_spec_file(filename: str) -> str:
"""Read a spec .sx file. Pure I/O — metadata lives in .sx."""
filepath = _find_spec_file(filename)
if not filepath:
return ";; spec file not found: " + filename
try:
with open(filepath, encoding="utf-8") as f:
return f.read()
except FileNotFoundError:
return ";; spec file not found"
except (FileNotFoundError, TypeError):
return ";; spec file not found: " + filename
# ---------------------------------------------------------------------------
@@ -332,7 +349,7 @@ def _collect_symbols(expr) -> set[str]:
_SPEC_SLUG_MAP = {
"parser": ("parser.sx", "Parser", "Tokenization and parsing"),
"evaluator": ("eval.sx", "Evaluator", "Tree-walking evaluation"),
"evaluator": ("evaluator.sx", "Evaluator", "CEK machine evaluator"),
"primitives": ("primitives.sx", "Primitives", "Built-in pure functions"),
"render": ("render.sx", "Renderer", "Three rendering modes"),
"special-forms": ("special-forms.sx", "Special Forms", "Special form dispatch"),
@@ -374,10 +391,9 @@ def _spec_explorer_data(filename: str, title: str = "", desc: str = "") -> dict
return None
# Read the raw source
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
if not os.path.isdir(ref_dir):
ref_dir = "/app/shared/sx/ref"
filepath = os.path.join(ref_dir, filename)
filepath = _find_spec_file(filename)
if not filepath:
return None
try:
with open(filepath, encoding="utf-8") as f:
source = f.read()