sots-engine/tests/game_design/build_and_run.sh
alex f177a5fdd0 lane D2: hull size + the defence-platform flag; the ship census reproduces 480/480
The two derived words the per-player turn record's ship census counts by, and
the design serializers that three lanes had been told did not exist.

HOW DESIGNS PERSIST. Game::ShipDesign derives from Game::ShipDesignDef and
reaches IStreamable through adjustor thunks, so a design is written by TWO
serializers: the base emits FAIDes/DHide/DWep/DName and exactly three section
frames (command, mission, engine on the wire), the derived one appends Dtc, the
Dwgv flag and, only when that flag is set, a weapon-group frame. The earlier
"the writer makes no stream call at all" note named an address that is in no
vftable at all. Corrected in shapes.h.

THREE sections, not five. The "two reserved slots" were Dtc and Dwgv swept into
the section list by the reference reader's catch-all tail; the constructor
builds a three-element array. design.h's comment is corrected and the fixture
loader now accepts 3-5 raw_slots so old fixtures still load; the array keeps
five inert entries deliberately, since touching the slot enum reaches rules.cpp
and another lane's tests for no behavioural gain.

DWep and Dwgv are bools, not ints -- both writers call the bool primitive. With
four-character tags a bool item and an int item are the same size on the wire
and 0/1 the same bytes, so no save can tell them apart. Byte-neutral: the typed
round trip is still byte-identical on all 11 saves at 100% named coverage.

HULL SIZE is the section_class of the last resolved section in memory slot
order, mapped Destroyer/Cruiser/Dreadnought -> 0/1/2 case-insensitively, with
absent or unrecognised meaning 0 rather than an error. The DEFENCE-PLATFORM
flag is one bit of a 64-bit role-flag word OR-ed across the design's sections.
Neither is on the wire; both are rebuilt from the section catalog.

MEASURED, not assumed: the new game_design_census test rebuilds the six census
counters per player and compares them against the record the game archived for
each save's own frame. 11 saves, 503 designs, 480 leaves, 0 mismatched, 0 ships
with an unresolvable design, 0 designs where first- and last-resolved section
disagree on hull size. COVERAGE IS THIN AND THE TEST SAYS SO: only 32 of the
480 leaves are nonzero, and three of the six census leaves (both cruiser rows
and dreadnought platforms) are never exercised by any save in the corpus -- the
test prints the per-leaf nonzero counts and names them unexercised rather than
verified.

Nothing is wired into the turn record: src/app is another lane's this cycle, so
this is evaluated and reported, not written.

host ctest 43/43 (was 42/42; +1, skips cleanly without the env). With a data
root set, game_data_realdata and mars_text_realdata fail identically on main --
both are the absent Locale/EN/Strings.csv, not this change. clean-room OK.
Reference readers fixed openly in the RE repo: save_reader 49/49,
design rules 32/32, stock_designs.json regenerated (raw_slots 5->3 and dWep
int->bool are the only field changes across all 127 designs).
2026-09-08 12:44:41 -04:00

76 lines
3.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Self-contained build + test for src/game/design (plain g++, no CMake needed).
#
# tests/game_design/build_and_run.sh
#
# Always builds and runs the unit tests (hand-written mini catalog). When
# SOTS_DATA_DIR points at an extracted sots.gob tree AND SOTS_DESIGNS_JSON at
# the owner's stock_designs.json (designs decoded from real saves) it also
# runs the real-data test (every save design must validate, DOpts must equal
# applied_techs, tech gating must show exactly the hidden-rider warnings),
# dumps our findings per design and, if the reference validator is reachable
# (SOTS_DESIGN_RULES_DIR, default ~/sots-re/verify/design-rules), diffs them
# design by design with oracle/compare.py.
#
# Env: CXX (g++), PYTHON (python3), BUILD_DIR (tests/game_design/build),
# SOTS_DATA_DIR, SOTS_DESIGNS_JSON, SOTS_DESIGN_RULES_DIR.
set -euo pipefail
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
ROOT=$(cd "$HERE/../.." && pwd)
BUILD=${BUILD_DIR:-$HERE/build}
CXX=${CXX:-g++}
PYTHON=${PYTHON:-python3}
FLAGS=(-std=c++17 -O2 -Wall -Wextra -Wpedantic -Werror -I"$ROOT/src" -I"$HERE")
LIB=(
"$ROOT/src/mars/parse/blocks.cpp" "$ROOT/src/mars/parse/value.cpp"
"$ROOT/src/mars/text/value.cpp" "$ROOT/src/mars/text/flat_kv.cpp"
"$ROOT/src/mars/text/manifest.cpp" "$ROOT/src/mars/text/csv.cpp"
"$ROOT/src/game/data/common.cpp" "$ROOT/src/game/data/block.cpp"
"$ROOT/src/game/data/weapon.cpp" "$ROOT/src/game/data/shipsection.cpp"
"$ROOT/src/game/data/turrets.cpp" "$ROOT/src/game/data/techtree.cpp"
"$ROOT/src/game/data/strings.cpp" "$ROOT/src/game/data/catalog.cpp"
"$ROOT/src/game/design/design.cpp" "$ROOT/src/game/design/rules.cpp"
"$ROOT/src/game/design/stats.cpp" "$ROOT/src/game/design/defaults.cpp"
"$ROOT/src/game/design/hull.cpp"
)
mkdir -p "$BUILD"
echo "== building unit tests"
"$CXX" "${FLAGS[@]}" "${LIB[@]}" "$HERE/test_main.cpp" "$HERE/mini_catalog.cpp" "$HERE/test_structure.cpp" \
"$HERE/test_banks.cpp" "$HERE/test_tech.cpp" "$HERE/test_stats.cpp" "$HERE/test_hull.cpp" "$HERE/test_json.cpp" -o "$BUILD/unit_tests"
echo "== running unit tests"
"$BUILD/unit_tests"
if [ -z "${SOTS_DATA_DIR:-}" ] || [ -z "${SOTS_DESIGNS_JSON:-}" ]; then
echo "== SOTS_DATA_DIR / SOTS_DESIGNS_JSON not set: skipping real-data tests"
exit 0
fi
if [ ! -d "$SOTS_DATA_DIR" ]; then
echo "== SOTS_DATA_DIR=$SOTS_DATA_DIR is not a directory" >&2
exit 1
fi
if [ ! -f "$SOTS_DESIGNS_JSON" ]; then
echo "== SOTS_DESIGNS_JSON=$SOTS_DESIGNS_JSON is not a file" >&2
exit 1
fi
echo "== building real-data tools"
"$CXX" "${FLAGS[@]}" "${LIB[@]}" "$HERE/stock_designs.cpp" "$HERE/realdata_test.cpp" -o "$BUILD/realdata_test"
"$CXX" "${FLAGS[@]}" "${LIB[@]}" "$HERE/stock_designs.cpp" "$HERE/dump_designs.cpp" -o "$BUILD/dump_designs"
echo "== real-data: every save design through the rules"
"$BUILD/realdata_test"
echo "== dumping findings"
"$BUILD/dump_designs" "$SOTS_DATA_DIR" "$SOTS_DESIGNS_JSON" "$BUILD/designs.json"
ORACLE=${SOTS_DESIGN_RULES_DIR:-$HOME/sots-re/verify/design-rules}
if [ ! -f "$ORACLE/design_rules.py" ]; then
echo "== reference validator not found at $ORACLE (set SOTS_DESIGN_RULES_DIR): skipping comparison"
exit 0
fi
echo "== comparing with the reference validator"
read -ra PY <<< "$PYTHON" # PYTHON may be a command with arguments ("uv run python3")
exec "${PY[@]}" "$HERE/oracle/compare.py" "$BUILD/designs.json" "$SOTS_DESIGNS_JSON" "$ORACLE"