diff options
| author | Ralph Amissah <ralph.amissah@gmail.com> | 2026-09-21 12:00:43 -0400 |
|---|---|---|
| committer | Ralph Amissah <ralph.amissah@gmail.com> | 2026-09-22 14:54:35 -0400 |
| commit | 774302487c8595ec4383558e9d8387a6219ef2ed (patch) | |
| tree | 8a2001340c39e50f2f85b26cb5fabfb939c2b8a0 /test/test-abstraction-db-roundtrip.sh | |
| parent | digests: db digest taken once on file completion (diff) | |
test db: multilingual database test
one file holding several languages.
Both assumed <uid>.<lang>.ocda.db beside <uid>.<lang>.ssp, one for
one.
- test-abstraction-db.sh takes the language from the .ssp name, the
database from the stem, and scopes every query by the doc_id that
language resolves to: objects by doc_id, the four child tables
through their objects, metadata by doc_id, schema.version by doc_id
is null. It also checks what a per language loop cannot see, that the
languages a database holds are exactly the languages there are .ssp
files for.
- test-abstraction-db-roundtrip.sh asks for each language by name and
holds it against its own .ssp, and requires a database of more than
one language to refuse a round trip that names none: a reader quietly
emitting the first language would otherwise pass against the first
.ssp and say nothing about the other nine. Its language list comes
from the .ssp filenames, so it still needs no sqlite3.
databases (re-)emitting all .ssp files exactly.
(assisted by Claude-Code)
Diffstat (limited to 'test/test-abstraction-db-roundtrip.sh')
| -rwxr-xr-x | test/test-abstraction-db-roundtrip.sh | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/test/test-abstraction-db-roundtrip.sh b/test/test-abstraction-db-roundtrip.sh index 338f375..0ec7847 100755 --- a/test/test-abstraction-db-roundtrip.sh +++ b/test/test-abstraction-db-roundtrip.sh @@ -3,7 +3,10 @@ # # Reads each <doc>.ocda.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. +# from the same document. A database holds every language of its document, +# so each language is asked for by name (--lang) and held against its own +# .ssp, and a database of more than one language is required to refuse a +# round trip that names none. # # What that proves: the two serialisations really do carry the same thing. # test-abstraction-db.sh counts fields and compares them; this reconstructs @@ -61,37 +64,70 @@ $SPINE_BIN --show-abstraction --ocda-db --skip-output \ --output="$OUT_DIR" "$SAMPLES_DIR"/* 2>&1 | tail -1 COUNT=0 +DBS=0 FAILURES=0 -# the database sits beside the pod (pod/<uid>.ocda.db), the .ssp inside it -# (pod/<doc>/media/abstraction/<uid>.ssp) +# the database sits beside the pod (pod/<uid>.ocda.db), the .ssp files inside +# it (pod/<doc>/media/abstraction/<uid>.<lang>.ssp). +# +# A database holds every language of its document, so one database answers +# for as many .ssp files as the document has languages, and each has to be +# asked for by name: --lang says which language to emit. With no language +# named a database holding more than one refuses to choose, which is checked +# too - a round trip that quietly emitted the first language would pass +# against the first .ssp and say nothing about the other nine. for db in "$OUT_DIR"/pod/*.ocda.db; do [ -f "$db" ] || continue - base=$(basename "$db" .ocda.db) - ssp=$(find "$OUT_DIR/pod" -name "$base.ssp" 2>/dev/null | head -1) - COUNT=$((COUNT + 1)) - if [ ! -f "$ssp" ]; then - echo "MISSING .ssp for $base" + DBS=$((DBS + 1)) + stem=$(basename "$db" .ocda.db) + # the languages come from the .ssp files rather than from the database, so + # that this script needs no sqlite3: each .ssp is a language the database + # has to be able to re-emit. A language in the database with no .ssp beside + # it is the other direction, and test-abstraction-db.sh checks that. + langs=$(find "$OUT_DIR/pod" -name "$stem.*.ssp" 2>/dev/null \ + | sed "s|.*/$stem\.||; s|\.ssp$||" | sort) + if [ -z "$langs" ]; then + echo "MISSING .ssp for $stem" 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)) + n_langs=$(printf '%s\n' "$langs" | grep -c .) + for lang in $langs; do + base="$stem.$lang" + ssp="$(find "$OUT_DIR/pod" -name "$base.ssp" 2>/dev/null | head -1)" + COUNT=$((COUNT + 1)) + if [ ! -f "$ssp" ]; then + echo "MISSING .ssp for $base" + FAILURES=$((FAILURES + 1)) + continue + fi + if ! $SPINE_BIN --db-round-trip="$db" --lang="$lang" \ + > "$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 + # more than one language and none named: it must refuse rather than pick + if [ "$n_langs" -gt 1 ]; then + if $SPINE_BIN --db-round-trip="$db" > /dev/null 2> /dev/null; then + echo "$stem" + echo " ACCEPTED a round trip with no language named, holding $n_langs" + FAILURES=$((FAILURES + 1)) + fi fi done rm -rf "$OUT_DIR" if [ "$FAILURES" -eq 0 ]; then - echo "PASS: all $COUNT databases re-emit their document's .ssp exactly" + echo "PASS: $DBS databases re-emit all $COUNT of their documents' .ssp exactly" exit 0 else echo "FAIL: $FAILURES of $COUNT do not" |
