#!/usr/bin/env bash # Fixture tests for tools/corpus_engine.py (agent-scale slice E). # Covers page reachability, link/anchor integrity, exact metadata, doorway # bounds, retired authority/startup wording, dependencies, and generated-page # owners. set -euo pipefail cd "$(dirname "$0")/.." || exit 1 if ! command -v python3 >/dev/null 2>&1; then echo "FAIL: python3 required" exit 1 fi engine=tools/corpus_engine.py fail=0 tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT # Minimal valid doorway + law target for Design refs. setup_base() { local root=$1 mkdir -p "$root/wiki/vision" "$root/wiki/process" "$root/prompts" cat > "$root/DESIGN.md" <<'EOF' # DESIGN This file contains no unique game law. See the wiki. EOF # 3 lines — under 100 cat > "$root/wiki/vision/law.md" <<'EOF' # Law page ``` Type: law ``` ## Justification and legibility The promise is legible. EOF cat > "$root/wiki/SUMMARY.md" <<'EOF' # Summary - [Law](vision/law.md) - [Good spec](process/good.md) EOF cat > "$root/wiki/process/good.md" <<'EOF' # Spec: good ``` Type: spec Status: READY Stage: Process Design: - wiki/vision/law.md#justification-and-legibility Depends on: none ``` ## Acceptance criteria 1. Exists. EOF cat > "$root/AGENT.md" <<'EOF' # agent EOF cat > "$root/README.md" <<'EOF' # readme EOF } assert_fails() { local name=$1 shift local out if out=$(python3 "$engine" "$@" 2>&1); then echo "FAIL fixture $name: expected non-zero exit" echo "$out" fail=1 else echo " ok fails: $name" fi } assert_ok() { local name=$1 shift local out if out=$(python3 "$engine" "$@" 2>&1); then echo " ok passes: $name" else echo "FAIL fixture $name: expected success" echo "$out" fail=1 fi } echo "=== fixture: clean tree ===" root=$tmp/clean setup_base "$root" assert_ok clean --root "$root" --all echo "=== fixture: orphan page ===" root=$tmp/orphan setup_base "$root" cat > "$root/wiki/process/orphan.md" <<'EOF' # orphan ``` Type: knowledge ``` EOF assert_fails orphan --root "$root" --wiki out=$(python3 "$engine" --root "$root" --wiki 2>&1 || true) echo "$out" | grep -q 'orphan page' || { echo "FAIL: orphan message missing" fail=1 } echo "=== fixture: broken link ===" root=$tmp/broken setup_base "$root" echo '[x](missing-page.md)' >> "$root/wiki/process/good.md" assert_fails broken --root "$root" --wiki out=$(python3 "$engine" --root "$root" --wiki 2>&1 || true) echo "$out" | grep -q 'broken link' || { echo "FAIL: broken link message missing" fail=1 } echo "=== fixture: missing Design anchor ===" root=$tmp/anchor setup_base "$root" cat > "$root/wiki/process/good.md" <<'EOF' # Spec: bad anchor ``` Type: spec Status: READY Stage: Process Design: - wiki/vision/law.md#does-not-exist-anchor Depends on: none ``` ## Acceptance criteria 1. Exists. EOF assert_fails anchor --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'Design reference anchor does not exist' || { echo "FAIL: missing-anchor message missing" echo "$out" fail=1 } echo "=== fixture: bad Status enum ===" root=$tmp/status setup_base "$root" cat > "$root/wiki/process/good.md" <<'EOF' # Spec: bad status ``` Type: spec Status: WONKY Stage: Process Design: - wiki/vision/law.md#justification-and-legibility Depends on: none ``` ## Acceptance criteria 1. Exists. EOF assert_fails status --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q "Status 'WONKY'" || { echo "FAIL: bad status message missing" echo "$out" fail=1 } echo "=== fixture: structured dependency target ===" root=$tmp/depends-target setup_base "$root" cat > "$root/wiki/process/good.md" <<'EOF' # Spec: missing dependency target ``` Type: spec Status: READY Stage: Process Design: - wiki/vision/law.md#justification-and-legibility Depends on: - wiki/process/missing.md#behavior ``` ## Acceptance criteria 1. Exists. EOF assert_fails depends-target --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'Depends on target does not exist' || { echo "FAIL: missing dependency-target message missing" echo "$out" fail=1 } echo "=== fixture: structured dependency anchor ===" root=$tmp/depends-anchor setup_base "$root" cat > "$root/wiki/process/good.md" <<'EOF' # Spec: missing dependency anchor ``` Type: spec Status: READY Stage: Process Design: - wiki/vision/law.md#justification-and-legibility Depends on: - wiki/vision/law.md#missing-dependency-anchor ``` ## Acceptance criteria 1. Exists. EOF assert_fails depends-anchor --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'Depends on anchor does not exist' || { echo "FAIL: missing dependency-anchor message missing" echo "$out" fail=1 } echo "=== fixture: prose dependency field ===" root=$tmp/depends-prose setup_base "$root" cat > "$root/wiki/process/good.md" <<'EOF' # Spec: prose dependency ``` Type: spec Status: READY Stage: Process Design: - wiki/vision/law.md#justification-and-legibility Depends on: vision/law.md (read this first) ``` ## Acceptance criteria 1. Exists. EOF assert_fails depends-prose --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q "Depends on field must be 'none' or a structured reference list" || { echo "FAIL: prose dependency message missing" echo "$out" fail=1 } echo "=== fixture: duplicate Type declaration ===" root=$tmp/duplicate-type setup_base "$root" cat >> "$root/wiki/process/good.md" <<'EOF' ``` Type: law ``` EOF assert_fails duplicate-type --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'must declare exactly one supported Type' || { echo "FAIL: duplicate Type message missing" echo "$out" fail=1 } echo "=== fixture: generated page without owner ===" root=$tmp/generated-owner setup_base "$root" cat > "$root/wiki/process/generated.md" <<'EOF' # Generated page ``` Type: knowledge Generated: tools/does-not-exist.sh ``` EOF assert_fails generated-owner --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'Generated target does not exist' || { echo "FAIL: generated-owner message missing" echo "$out" fail=1 } echo "=== fixture: oversized doorway ===" root=$tmp/doorway-size setup_base "$root" { echo '# DESIGN' echo echo 'This file contains no unique game law. See the wiki.' i=0 while [ "$i" -lt 101 ]; do echo 'navigation filler' i=$((i + 1)) done } > "$root/DESIGN.md" assert_fails doorway-size --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'doorway grew past 100 lines' || { echo "FAIL: doorway-size message missing" echo "$out" fail=1 } echo "=== fixture: binding doorway structure ===" root=$tmp/doorway-binding setup_base "$root" cat >> "$root/DESIGN.md" <<'EOF' ## Acceptance criteria EOF assert_fails doorway-binding --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'contains binding-page structure' || { echo "FAIL: binding-doorway message missing" echo "$out" fail=1 } echo "=== fixture: retired authority language ===" root=$tmp/retired-authority setup_base "$root" echo 'DESIGN.md is the constitution.' >> "$root/README.md" assert_fails retired-authority --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'retired single-file-authority language' || { echo "FAIL: retired-authority message missing" echo "$out" fail=1 } echo "=== fixture: superseded material-first startup claim ===" root=$tmp/material-first-startup setup_base "$root" cat >> "$root/wiki/SUMMARY.md" <<'EOF' - [View knowledge](process/view-knowledge.md) EOF cat > "$root/wiki/process/view-knowledge.md" <<'EOF' # View knowledge ``` Type: knowledge ``` The material render is the opening default; F3 flips to the sensorium. EOF assert_fails material-first-startup --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q 'superseded material-first startup claim' || { echo "FAIL: material-first startup diagnostic missing" echo "$out" fail=1 } cat > "$root/wiki/process/view-knowledge.md" <<'EOF' # View knowledge ``` Type: knowledge ``` The superseded staging said the material render is the opening default and F3 flips to the sensorium. This is historical context only; DIGITAL is home now. EOF assert_ok material-first-history --root "$root" --corpus echo "=== fixture: retired live-runtime Rust symbol ===" root=$tmp/retired-runtime-rust setup_base "$root" mkdir -p "$root/crates/core/src" cat > "$root/crates/core/src/lib.rs" <<'EOF' // Stale call path: submit_ops_job queues this work. pub fn current_runtime() {} EOF assert_fails retired-runtime-rust --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q "contains retired live-runtime symbol 'submit_ops_job'" || { echo "FAIL: retired-runtime Rust diagnostic missing" echo "$out" fail=1 } echo "=== fixture: retired live-runtime authority claim ===" root=$tmp/retired-runtime-authority setup_base "$root" cat >> "$root/wiki/process/good.md" <<'EOF' The active runtime queues each operation as a `PendingOpsJob`. EOF assert_fails retired-runtime-authority --root "$root" --corpus out=$(python3 "$engine" --root "$root" --corpus 2>&1 || true) echo "$out" | grep -q "names retired live-runtime symbol 'PendingOpsJob' without explicit historical context" || { echo "FAIL: retired-runtime authority diagnostic missing" echo "$out" fail=1 } echo "=== fixture: explicit retired history and legacy migration names ===" root=$tmp/retired-runtime-history setup_base "$root" cat >> "$root/wiki/process/good.md" <<'EOF' The retired `PendingOpsJob` model is kept here as superseded history only. EOF mkdir -p "$root/crates/core/src" cat > "$root/crates/core/src/lib.rs" <<'EOF' struct LegacyPendingOpsJob; enum LegacyOpsJobKind { Retired } EOF assert_ok retired-runtime-history --root "$root" --corpus if [ "$fail" -ne 0 ]; then echo "corpus engine fixtures: FAILED" exit 1 fi echo "corpus engine fixtures: OK"