chadtmiller.com/pds.js
An atproto PDS in JavaScript, for Cloudflare Workers and Node
0
0
#!/usr/bin/env bash
# Test permissioned data against the reference implementation, both directions:
# the reference's verifier over live pds.js output, and pds.js's verifier over
# fresh reference output. Requires a worktree of atproto at the spaces alpha
# (see README).
#
# npm run test:reference [-- --refresh-fixtures]
#
# --refresh-fixtures also rewrites test/fixtures/space-reference-*, which is how
# those fixtures track upstream.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
HERE="$REPO_ROOT/scripts/space-reference"
REF="${ATPROTO_REF:-$HOME/code/atproto-space-ref}"
UPSTREAM="${ATPROTO_UPSTREAM:-$HOME/code/atproto}"
PIN="${ATPROTO_PIN:-704b9e2ac}"
OURS="${OURS_DIR:-/tmp/pdsjs-space-artifacts}"
THEIRS="${THEIRS_DIR:-/tmp/ref-space-artifacts}"
REFRESH=0
[ "${1:-}" = "--refresh-fixtures" ] && REFRESH=1
if [ ! -d "$REF" ]; then
cat >&2 <<EOF
Reference worktree not found at $REF — create it with:
git -C "$UPSTREAM" worktree add "$REF" $PIN
cd "$REF" && pnpm install --frozen-lockfile
pnpm --filter '@atproto/space^...' run build
pnpm --filter '@atproto-labs/rolldown-plugin-bundle-manifest' run build
Override the location with ATPROTO_REF. The fixture-based checks in
test/space-reference.test.js run under plain 'npm test' and need none of this.
EOF
exit 1
fi
echo "reference: $REF ($(git -C "$REF" rev-parse --short HEAD))"
echo
# The reference-side tests run inside the worktree as scratch files; they are
# never committed to atproto.
cp "$HERE/ref-verify.test.ts" "$REF/packages/space/tests/pdsjs-verify.test.ts"
cp "$HERE/ref-generate.test.ts" "$REF/packages/space/tests/pdsjs-generate.test.ts"
cleanup() {
rm -f "$REF/packages/space/tests/pdsjs-verify.test.ts" \
"$REF/packages/space/tests/pdsjs-generate.test.ts"
}
trap cleanup EXIT
echo "── pds.js produces, reference verifies ─────────────────────────────"
( cd "$REPO_ROOT" && node scripts/space-reference/gen-artifacts.mjs "$OURS" )
# The atproto repo pins pnpm; npx fails there with EBADDEVENGINES.
( cd "$REF" && ARTIFACTS_DIR="$OURS" \
pnpm exec vitest run packages/space/tests/pdsjs-verify.test.ts )
echo
echo "── reference produces, pds.js verifies ─────────────────────────────"
( cd "$REF" && OUT_DIR="$THEIRS" \
pnpm exec vitest run packages/space/tests/pdsjs-generate.test.ts )
( cd "$REPO_ROOT" && REF_ARTIFACTS_DIR="$THEIRS" \
npx vitest run test/space-reference.test.js )
if [ "$REFRESH" = "1" ]; then
echo
echo "── refreshing committed fixtures ───────────────────────────────────"
cp "$THEIRS/repo.star" "$REPO_ROOT/test/fixtures/space-reference-repo.star"
REF_SHA="$(git -C "$REF" rev-parse HEAD)" \
node -e '
const fs = require("node:fs");
const m = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
m.generatedFrom = { repo: "bluesky-social/atproto", package: "@atproto/space@0.0.0-spaces-alpha-20261105160032", sha: process.env.REF_SHA };
fs.writeFileSync(process.argv[2], JSON.stringify(m, null, 2) + "\n");
' "$THEIRS/manifest.json" "$REPO_ROOT/test/fixtures/space-reference-manifest.json"
( cd "$REPO_ROOT" && git diff --stat -- test/fixtures )
fi
echo
echo "both directions pass"