json-archive/tests/compression-integration/validate.sh
nobody 2ab1c31993
feat: transparently append to compressed archives
When appending to a compressed archive (gzip, brotli, zstd), the tool
now handles compression automatically. Since some compression formats don't
support appending to compressed files in place, we write a new
compressed file with all the data and atomically rename it to replace
the original (assuming there is enough space on that filesystem).

This means you can work with compressed archives the same way as
uncompressed ones. Point the tool at your .json.gz file and append
values. No manual decompression/recompression needed.
2025-11-30 17:09:49 -08:00

63 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Validate that compressed and decompressed archives produce the same results.
# Run this after run_all.sh to smoke test the outputs.
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
BINARY="$PROJECT_DIR/target/debug/json-archive"
echo "=== Validation ==="
errors=0
for format in gzip brotli zstd; do
dir="$SCRIPT_DIR/out/$format"
if [ ! -d "$dir" ]; then
echo "SKIP: $format (no output directory)"
continue
fi
# Find the compressed and uncompressed files
compressed=$(find "$dir" -name "*.gz" -o -name "*.br" -o -name "*.zst" | head -1)
uncompressed="$dir/test.json.archive"
if [ ! -f "$compressed" ] || [ ! -f "$uncompressed" ]; then
echo "SKIP: $format (missing files)"
continue
fi
# Compare state output
state_compressed=$("$BINARY" state "$compressed")
state_uncompressed=$("$BINARY" state "$uncompressed")
if [ "$state_compressed" = "$state_uncompressed" ]; then
echo "OK: $format - state matches"
else
echo "FAIL: $format - state differs"
errors=$((errors + 1))
fi
# Compare observation count from info
count_compressed=$("$BINARY" info "$compressed" --output json | python3 -c "import sys,json; print(json.load(sys.stdin)['observation_count'])")
count_uncompressed=$("$BINARY" info "$uncompressed" --output json | python3 -c "import sys,json; print(json.load(sys.stdin)['observation_count'])")
if [ "$count_compressed" = "$count_uncompressed" ]; then
echo "OK: $format - observation count matches ($count_compressed)"
else
echo "FAIL: $format - observation count differs ($count_compressed vs $count_uncompressed)"
errors=$((errors + 1))
fi
done
echo ""
if [ $errors -eq 0 ]; then
echo "All validations passed."
else
echo "$errors validation(s) failed."
exit 1
fi