diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1cb58dd..f464519 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,31 @@ jobs: # Published text names no one inside the team and points at no internal room or tracker. - run: uv run python scripts/public_words.py + okf-reference: + # OKF's own parser and viewer, at the commit onlyworlds.okf pins, read this package's export. + # tests/test_okf.py skips that check when OKF's code is not importable, so the gates above + # never run it. Here the code is fetched at the pinned commit and a skip is a failure. + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: astral-sh/setup-uv@v7 + - run: uv sync + - name: OKF's reference code at the pinned commit + run: | + REPO=$(uv run python -c "from onlyworlds import okf; print(okf.OKF_REPO)") + COMMIT=$(uv run python -c "from onlyworlds import okf; print(okf.OKF_COMMIT)") + echo "$REPO at $COMMIT" + git init -q "$RUNNER_TEMP/okf" + git -C "$RUNNER_TEMP/okf" fetch -q --depth 1 "$REPO" "$COMMIT" + git -C "$RUNNER_TEMP/okf" checkout -q FETCH_HEAD + test "$(git -C "$RUNNER_TEMP/okf" rev-parse HEAD)" = "$COMMIT" + - name: The reference check, where a skip fails + env: + OKF_REFERENCE_SRC: ${{ runner.temp }}/okf/src + run: | + uv run pytest -q -rs tests/test_okf.py::test_reference_parser_and_viewer | tee "$RUNNER_TEMP/okf.txt" + grep -q -E '^1 passed' "$RUNNER_TEMP/okf.txt" + wire: # keel's own OpenAPI document and the public demo world, read only, and a few writes to the # practice world (its published key, reset every night), each deleted again. Red here with diff --git a/tests/test_okf.py b/tests/test_okf.py index 9f1b7df..c1fa929 100644 --- a/tests/test_okf.py +++ b/tests/test_okf.py @@ -41,6 +41,7 @@ ROOT = Path(__file__).resolve().parents[1] HYPERION = ROOT / "codegen" / "schema-dist" / "example" / "hyperion" BODY_LINK = re.compile(r"\]\(([^)\s]+\.md)\)") +ELEMENT_ID = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") if os.environ.get("OKF_REFERENCE_SRC"): sys.path.insert(0, os.environ["OKF_REFERENCE_SRC"]) @@ -289,7 +290,10 @@ def test_refuses_existing_out_dir(tmp_path: Path) -> None: def test_reference_parser_and_viewer(bundle: Bundle, tmp_path: Path) -> None: """OKF's own code at the pinned commit: every concept parses and has a type, indexes carry no frontmatter but the root's okf_version, and the - viewer draws one edge per distinct linked pair.""" + viewer draws one edge per distinct linked pair: a link field's, or an + in-prose reference's (the export writes each as a link to the concept; + read here from the source's own text, any element id inside a markdown + link's target).""" for rel, data in bundle.files.items(): doc = OKFDocument.parse(data.decode("utf-8")) if rel.endswith("index.md"): @@ -304,9 +308,19 @@ def test_reference_parser_and_viewer(bundle: Bundle, tmp_path: Path) -> None: for t in link_ids(s, s["type"], name) if t != s["id"] } + prose = { + (s["id"], t) + for s in bundle.sources.values() + for value in s.values() + if isinstance(value, str) + for target in re.findall(r"\]\(([^)\s]+)\)", value) + for t in ELEMENT_ID.findall(target) + if t in bundle.sources and t != s["id"] + } + assert prose - pairs, "Hyperion carries in-prose references that no link field repeats" stats = generate_visualization(bundle.out, tmp_path / "viz.html") assert stats["concepts"] == len(bundle.sources) + 1 - assert stats["edges"] == len(pairs) + assert stats["edges"] == len(pairs | prose) # --- the legacy layout