diff options
| author | Ralph Amissah <ralph.amissah@gmail.com> | 2026-09-08 07:40:06 -0400 |
|---|---|---|
| committer | Ralph Amissah <ralph.amissah@gmail.com> | 2026-09-09 17:49:15 -0400 |
| commit | a28ab7a6c0d1a25a2b1195ff13b639e2256e97a8 (patch) | |
| tree | a159e5cf3a672ae4d6adea861ab3cfcf01736e37 /test | |
| parent | test: .ssp round trip script beside the other two (diff) | |
a reader for the ocda db, and its round trip
sisudoc.ocda.abstraction.db_in reads a <doc>.abstraction.db back
into ObjGenericComposite[][string], the same value ssp_in returns
from a .ssp, so a consumer need not know which artefact it was
handed. It mixes in the .ssp reader for that shared document
struct rather than declaring a second one.
--db-round-trip=<file.abstraction.db> reads a database and emits
it as .ssp on stdout, through sspObjectRecord as the other round
trip does. Held against the .ssp written from the same document,
this says whether the two artefacts really carry the same thing:
not a count of fields, as test-abstraction-db.sh does, but the
whole document reconstructed from the database and compared to the
text.
SpinePOD=... ./test/test-abstraction-db-roundtrip.sh ./bin/spine-ldc
PASS: all 35 databases re-emit their document's .ssp exactly
It passed on the first run over the whole sample set, which is evidence
that the database is now field-complete against the .ssp rather than
merely counting the same.
Four tests with different checks:
test-abstraction-ssp.sh the abstraction has not changed
test-abstraction-db.sh the two serialisations agree, field by field
test-abstraction-ssp-roundtrip.sh the .ssp can be read back whole
test-abstraction-db-roundtrip.sh the .db can be read back whole
(assisted by Claude-Code)
Diffstat (limited to 'test')
| -rwxr-xr-x | test/test-abstraction-db-roundtrip.sh | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/test-abstraction-db-roundtrip.sh b/test/test-abstraction-db-roundtrip.sh new file mode 100755 index 0000000..3051b78 --- /dev/null +++ b/test/test-abstraction-db-roundtrip.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env sh +# test-abstraction-db-roundtrip.sh +# +# Reads each <doc>.abstraction.db back into the abstraction, emits it as +# .ssp, and requires the result to be byte identical to the .ssp written +# from the same document. +# +# What that proves: the two serialisations really do carry the same thing. +# test-abstraction-db.sh counts fields and compares them; this reconstructs +# the whole document from the database and holds it against the text. +# +# Usage (needs the sample documents, since both artefacts are generated): +# SpinePOD=../../markup/sisudoc-spine-samples/markup/pod-samples/pod \ +# ./test/test-abstraction-db-roundtrip.sh ./bin/spine-ldc +# +# Exit codes: +# 0 every database re-emits its document's .ssp exactly +# 1 one or more do not +# 2 set-up problem + +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +SPINE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" + +if [ -z "$SpinePOD" ]; then + echo "ERROR: \$SpinePOD is not set." >&2 + echo " e.g. SpinePOD=../../markup/sisudoc-spine-samples/markup/pod-samples/pod" >&2 + exit 2 +fi +SAMPLES_RAW="$SPINE_DIR/$SpinePOD" +if [ -d "$SAMPLES_RAW" ]; then + SAMPLES_DIR="$(cd "$SAMPLES_RAW" && pwd)" +else + SAMPLES_DIR="$SAMPLES_RAW" +fi +if [ ! -d "$SAMPLES_DIR" ]; then + echo "ERROR: sample documents not found at $SAMPLES_DIR" >&2 + exit 2 +fi + +SPINE_BIN="${1:-}" +if [ -z "$SPINE_BIN" ]; then + if [ -x "$SPINE_DIR/result/bin/spine" ]; then SPINE_BIN="$SPINE_DIR/result/bin/spine" + elif [ -x "$SPINE_DIR/bin/spine-ldc" ]; then SPINE_BIN="$SPINE_DIR/bin/spine-ldc" + elif [ -x "$SPINE_DIR/bin/spine" ]; then SPINE_BIN="$SPINE_DIR/bin/spine" + else + echo "ERROR: spine binary not found. Specify path as argument." >&2 + exit 2 + fi +fi + +OUT_DIR="$SCRIPT_DIR/current-db-roundtrip" +rm -rf "$OUT_DIR" +mkdir -p "$OUT_DIR" + +echo "spine binary: $SPINE_BIN" +echo "samples: $SAMPLES_DIR" +echo "Generating .ssp and .abstraction.db ..." +$SPINE_BIN --show-abstraction --show-abstraction-db --skip-output \ + --output="$OUT_DIR" "$SAMPLES_DIR"/* 2>&1 | tail -1 + +COUNT=0 +FAILURES=0 +for db in "$OUT_DIR"/*/abstraction/*.abstraction.db; do + [ -f "$db" ] || continue + ssp="${db%.abstraction.db}.ssp" + base=$(basename "$ssp") + COUNT=$((COUNT + 1)) + if [ ! -f "$ssp" ]; then + echo "MISSING .ssp for $base" + FAILURES=$((FAILURES + 1)) + continue + fi + if ! $SPINE_BIN --db-round-trip="$db" > "$OUT_DIR/from-db.ssp" 2> "$OUT_DIR/from-db.err"; then + echo "ERROR: $base (spine exited non-zero)" + head -3 "$OUT_DIR/from-db.err" + FAILURES=$((FAILURES + 1)) + continue + fi + if ! cmp -s "$ssp" "$OUT_DIR/from-db.ssp"; then + echo "DIFFERS: $base ($(diff "$ssp" "$OUT_DIR/from-db.ssp" | grep -c '^[<>]') lines)" + diff --unified=1 "$ssp" "$OUT_DIR/from-db.ssp" | head -12 + echo " ..." + FAILURES=$((FAILURES + 1)) + fi +done + +rm -rf "$OUT_DIR" + +if [ "$FAILURES" -eq 0 ]; then + echo "PASS: all $COUNT databases re-emit their document's .ssp exactly" + exit 0 +else + echo "FAIL: $FAILURES of $COUNT do not" + exit 1 +fi |
