Files
claudeandClaude Opus 5.5 487ff6ec48
test / test (push) Successful in 1m42s
Finite worlds with oceans at the edges
New setting strata_world_size: small, medium (default) or large (2000,
3200 or 4200 columns) or infinite. The size is fixed when a world is
created and kept in mod storage; worlds made before this (they already
have env_meta.txt) stay infinite.

- Past |x| = half every plane cell is strata_core:world_edge, an
  invisible, walkable, undiggable wall. is_protected refuses cells past
  it and creatures don't spawn there.
- The last 220 columns are the ocean biome: land eases to a sand beach,
  then the sea floor falls to y = -17 (still the surface layer). Sea
  water fills to SEA_LEVEL only past the beach, so it is held in and
  doesn't flow when woken.
- mg.set_world_size, mg.in_world, mg.ocean_t for other systems and tests.

Tests: 3 new cases in tests/world_size.lua (the stored size, the edge,
beach and sea shape in every size, and a generated shore that stays at
rest, with reach refused past the edge). The test world runs infinite.
106/106 pass, no ERROR lines. A probe server confirmed new worlds get
medium, keep it across restarts, and older worlds stay infinite.

Closes #23

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 01:29:33 -05:00

103 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Strata headless test runner.
#
# Builds a throwaway world in a scratch directory, installs the selftest
# worldmod into it, runs a dedicated server until the selftest calls
# core.request_shutdown, then checks the log. Exits non-zero on any FAIL
# or ERROR line, on a missing summary, or on timeout.
#
# Usage: tests/run.sh [scratch_dir]
# Env: LUANTI=<binary> STRATA_TEST_PORT=<udp port> STRATA_TEST_TIMEOUT=<s>
# STRATA_TEST_FILTER=<lua pattern on test names>
set -euo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SCRATCH="${1:-$(mktemp -d -t strata-test.XXXXXX)}"
PORT="${STRATA_TEST_PORT:-30777}"
TIMEOUT="${STRATA_TEST_TIMEOUT:-420}"
# Debian installs the binaries in /usr/games, which root's PATH lacks.
export PATH="$PATH:/usr/games"
if [[ -z "${LUANTI:-}" ]]; then
for bin in luanti luantiserver minetest minetestserver; do
if command -v "$bin" >/dev/null 2>&1; then
LUANTI="$bin"
break
fi
done
fi
if [[ -z "${LUANTI:-}" ]]; then
echo "run.sh: no luanti binary found (set LUANTI=...)" >&2
exit 2
fi
# The game id is the directory name, so expose the repo as games/strata
# whatever the checkout is called.
rm -rf "$SCRATCH/games" "$SCRATCH/world"
mkdir -p "$SCRATCH/games" "$SCRATCH/world/worldmods"
ln -s "$REPO" "$SCRATCH/games/strata"
cp -r "$REPO/tests/strata_selftest" "$SCRATCH/world/worldmods/"
cat > "$SCRATCH/world/world.mt" <<WMT
gameid = strata
backend = sqlite3
player_backend = sqlite3
auth_backend = sqlite3
mod_storage_backend = sqlite3
WMT
cat > "$SCRATCH/test.conf" <<CONF
mg_name = singlenode
fixed_map_seed = 1337
enable_damage = true
creative_mode = false
time_speed = 0
server_announce = false
max_block_generate_distance = 6
# With no player connected every block is "unused"; keep the test area
# loaded so a slow runner doesn't read it back as "ignore" mid-run.
server_unload_unused_data_timeout = 3600
# Most cases scan far from spawn; finite worlds are tested by switching
# the size at runtime (tests/world_size.lua).
strata_world_size = infinite
strata_selftest_filter = ${STRATA_TEST_FILTER:-}
CONF
# The dedicated-server builds (luantiserver) reject --server.
SERVER_FLAG=(--server)
[[ "$(basename "$LUANTI")" == *server ]] && SERVER_FLAG=()
LOG="$SCRATCH/server.log"
echo "run.sh: $LUANTI, world $SCRATCH/world, port $PORT"
set +e
MINETEST_GAME_PATH="$SCRATCH/games" timeout "$TIMEOUT" "$LUANTI" "${SERVER_FLAG[@]}" \
--world "$SCRATCH/world" --gameid strata --config "$SCRATCH/test.conf" \
--port "$PORT" --logfile "$SCRATCH/debug.txt" >"$LOG" 2>&1
status=$?
set -e
grep -E "^(TEST|FAIL)" "$LOG" || true
errors=$(grep -c "ERROR" "$LOG" || true)
fails=$(grep -c "^FAIL" "$LOG" || true)
if [[ $status -eq 124 ]]; then
echo "run.sh: server timed out after ${TIMEOUT}s" >&2
tail -n 30 "$LOG" >&2
exit 1
fi
if [[ "$errors" -gt 0 ]]; then
echo "run.sh: $errors ERROR line(s):" >&2
grep "ERROR" "$LOG" >&2
fi
if ! grep -q "^TEST summary" "$LOG"; then
echo "run.sh: no TEST summary (server exit $status)" >&2
tail -n 30 "$LOG" >&2
exit 1
fi
if [[ "$errors" -gt 0 || "$fails" -gt 0 || $status -ne 0 ]]; then
echo "run.sh: FAILED ($fails FAIL, $errors ERROR, exit $status)" >&2
exit 1
fi
echo "run.sh: OK"