anbot

root / test / core-compat.sh

2117 bytes

#!/bin/sh
set -eu

# The last commit before the isomorphic core split. Records and bundles
# published by this code must keep verifying under the new core, and
# records published by the new core must verify under this code.
baseline=6432db8
top="$(git rev-parse --show-toplevel)"
scratch=$(mktemp -d)
portA=${ANBOT_TEST_COMPAT_PORT_A:-18792}
portB=${ANBOT_TEST_COMPAT_PORT_B:-18793}
server=
cleanup() {
  if [ -n "$server" ]; then
    kill "$server" 2>/dev/null || :
    wait "$server" 2>/dev/null || :
  fi
  git -C "$top" worktree remove --force "$scratch/baseline" 2>/dev/null || :
  rm -r "$scratch"
}
trap cleanup EXIT
trap 'exit 1' INT TERM

git -C "$top" worktree add --detach -q "$scratch/baseline" "$baseline"

git init -q -b main --object-format=sha1 "$scratch/source"
printf 'compat fixture\n' >"$scratch/source/README.md"
git -C "$scratch/source" add .
git -C "$scratch/source" -c user.name=Test -c user.email=test@example.invalid commit -q -m 'Compat fixture'
head=$(git -C "$scratch/source" rev-parse HEAD)

serve_and_clone() {
  node "$1" serve --data "$2" --port "$3" >"$scratch/url" &
  server=$!
  for attempt in 1 2 3 4 5; do
    if test -s "$scratch/url"; then break; fi
    sleep 1
  done
  git clone -q "$(cat "$scratch/url")" "$4"
  test "$(git -C "$4" rev-parse HEAD)" = "$head"
  kill "$server" 2>/dev/null || :
  wait "$server" 2>/dev/null || :
  server=
  rm -f "$scratch/url"
}

# Direction 1: records published by the pre-core code verify under the new core.
node "$scratch/baseline/anbot.mjs" publish --data "$scratch/old-node" --source "$scratch/source" --branch main --port "$portA" >/dev/null
serve_and_clone "$top/anbot.mjs" "$scratch/old-node" "$portA" "$scratch/from-old"

# Direction 2: records published by the new core verify under the pre-core code.
node "$top/anbot.mjs" publish --data "$scratch/new-node" --source "$scratch/source" --branch main --port "$portB" >/dev/null
serve_and_clone "$scratch/baseline/anbot.mjs" "$scratch/new-node" "$portB" "$scratch/from-new"

printf 'PASS: pre-core (%s) and new-core records verify in both directions at %s.\n' "$baseline" "$head"

Git ยท Social feed