#!/usr/bin/env bash # Row 56 byte-identity check. Runs `mosaic-task.mjs list` and `show` from a # baseline tree and a candidate tree against the same seeded data roots and # compares stdout, stderr and exit codes byte for byte. It also checks that # neither tree changed the data root. # Usage: byte-check.sh BASE_TREE CAND_TREE WORK_DIR (WORK_DIR must not exist) set -euo pipefail BASE="$(cd "$1" && pwd)"; CAND="$(cd "$2" && pwd)"; W="$3" HERE="$(cd "$(dirname "$0")" && pwd)" [ ! -e "$W" ] || { echo "byte-check: $W exists" >&2; exit 4; } mkdir -p "$W/out"; W="$(cd "$W" && pwd)" "$HERE/seed.sh" "$W/data" mkdir -p "$W/empty" conf() { printf '{"configVersion":1,"environment":"development","dataRoot":"%s","execution":{"backend":"docker","provider":"zai","model":"m"}}\n' "$2" > "$W/$1.json"; } conf seeded "$W/data"; conf empty "$W/empty"; conf absent "$W/no-such-root" snapshot() { (cd "$W/data" && find . -printf '%p %y %s %T@ %l\n' | sort && find . -type f -print0 | sort -z | xargs -0 sha256sum); } snapshot > "$W/before.txt" CASES=( "seeded list" "empty list" "absent list" "seeded show r-20260101T000000Z-aaaaaa" "seeded show r-20260101T000100Z-bbbbbb" "seeded show r-20260101T000200Z-cccccc" "seeded show r-20260101T000300Z-dddddd" "seeded show r-20260101T000400Z-eeeeee" "seeded show r-20260101T000500Z-ffffff" "seeded show r-20260101T000700Z-hhhhhh" "seeded show r-20260101T000800Z-iiiiii" "seeded show r-zz.weird_name-1" "seeded show r-missing" "seeded show ../escape" "seeded show" "absent show r-20260101T000000Z-aaaaaa" ) for tree in base cand; do root="$BASE"; [ "$tree" = cand ] && root="$CAND" i=0 for c in "${CASES[@]}"; do i=$((i + 1)) read -r cfg op arg <<<"$c" o="$W/out/$tree/$(printf '%02d' "$i")" mkdir -p "$o" printf '%s\n' "$c" > "$o/case" rc=0 (cd "$root" && env -u NODE_OPTIONS MOSAIC_CONFIG="$W/$cfg.json" node scripts/mosaic-task.mjs "$op" ${arg:+"$arg"} >"$o/stdout" 2>"$o/stderr") || rc=$? printf '%s\n' "$rc" > "$o/exit" [ -f "$o/stdout" ] && [ -f "$o/stderr" ] || { echo "byte-check: case $i ($c) left no output in $o" >&2; exit 4; } done done snapshot > "$W/after.txt" status=0 if diff -r "$W/out/base" "$W/out/cand" > "$W/diff.txt"; then echo "byte-check: ${#CASES[@]} cases, stdout, stderr and exit identical" else echo "byte-check: DIFFERENCES (see $W/diff.txt)"; status=1 fi if cmp -s "$W/before.txt" "$W/after.txt"; then echo "byte-check: data root unchanged" else echo "byte-check: DATA ROOT CHANGED"; status=1 fi exit "$status"