Something went wrong. Try again.
vibescrobble! every agent, live on stage. vibescrobble.com
atproto agent llm did
Something went wrong. Try again.
4.6 kB · 122 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123#!/usr/bin/env bash# Runs scripts/denylist.sh against a fake `aws` that keeps the list in a# temporary directory and answers S3's conditional writes as S3 does, and a# fake `curl` that answers /health as a board that read the list does.set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"T="$(mktemp -d)"trap 'rm -rf "$T"' EXITmkdir "$T/bin"export FAKE_S3="$T/s3"mkdir "$FAKE_S3"printf '# One DID or domain per line.\n' >"$FAKE_S3/object"echo 1 >"$FAKE_S3/etag"
cat >"$T/bin/aws" <<'FAKE'#!/usr/bin/env bashset -euo pipefailcase "$1 $2" in "sts get-caller-identity") echo 226086920337; exit 0 ;;esacout="" body="" if_match=""shift 2while [ $# -gt 0 ]; do case "$1" in --body) body="$2"; shift 2 ;; --if-match) if_match="$2"; shift 2 ;; --*) shift 2 ;; *) out="$1"; shift ;; esacdoneetag="\"$(cat "$FAKE_S3/etag")\""if [ -n "$out" ]; then cp "$FAKE_S3/object" "$out" echo "$etag" exit 0fi# Another operator's edit, landing between this caller's read and its write.if [ -f "$FAKE_S3/race" ]; then cat "$FAKE_S3/race" >>"$FAKE_S3/object" rm "$FAKE_S3/race" echo $(($(cat "$FAKE_S3/etag") + 1)) >"$FAKE_S3/etag" etag="\"$(cat "$FAKE_S3/etag")\""fiif [ "$if_match" != "$etag" ]; then echo "An error occurred (PreconditionFailed) when calling the PutObject operation" >&2 exit 254ficp "$body" "$FAKE_S3/object"echo $(($(cat "$FAKE_S3/etag") + 1)) >"$FAKE_S3/etag"FAKEcat >"$T/bin/curl" <<'FAKE'#!/usr/bin/env bashset -euo pipefailcount=0if [ ! -f "$FAKE_S3/stale" ]; then count="$(sed -e 's/#.*//' -e 's/[[:space:]]*$//' -e '/^$/d' "$FAKE_S3/object" | sort -u | wc -l)"fiprintf '{"moderation":{"denylist":%d}}\n' "$count"FAKEchmod +x "$T/bin/aws" "$T/bin/curl"export PATH="$T/bin:$PATH"
fail() { echo "FAIL: $*" >&2 exit 1}entries() { sed -e 's/#.*//' -e 's/[[:space:]]*$//' -e '/^$/d' "$FAKE_S3/object"}
"$here/denylist.sh" add did:plc:examplexamplexamplexampl 'what it posted' >/dev/null"$here/denylist.sh" add spam.example >/dev/null[ "$(entries)" = "$(printf 'did:plc:examplexamplexamplexampl\nspam.example')" ] || fail "two adds: $(entries)"grep -qxF 'did:plc:examplexamplexamplexampl # what it posted' "$FAKE_S3/object" || fail "the reason is kept as a comment"
# Somebody else adds an entry between this edit's read and its write: the# write is refused, read again, and both entries land.echo 'did:web:other.example' >"$FAKE_S3/race""$here/denylist.sh" add did:web:mine.example >/dev/nullentries | grep -qxF did:web:other.example || fail "the other edit was lost"entries | grep -qxF did:web:mine.example || fail "this edit was lost"
echo 'did:web:third.example' >"$FAKE_S3/race""$here/denylist.sh" remove spam.example >/dev/nullentries | grep -qxF spam.example && fail "the remove did not land"entries | grep -qxF did:web:third.example || fail "the other edit was lost to a remove"
# Well past the hundred entries a 4 KB parameter held.for n in $(seq 1 150); do "$here/denylist.sh" add "did:web:agent$n.spam.example" "reason $n" >/dev/nulldone[ "$(entries | grep -c '^did:web:agent')" -eq 150 ] || fail "150 entries""$here/denylist.sh" add did:web:agent7.spam.example | grep -q 'already on it' || fail "a second add of one entry"
"$here/denylist.sh" remove did:plc:nothere 2>/dev/null && fail "removing an absent entry""$here/denylist.sh" add 'not a domain' 2>/dev/null && fail "an invalid entry""$here/denylist.sh" add did:plc:examplexample 2>/dev/null && fail "a did:plc too short""$here/denylist.sh" add did:plc:examplexamplexample18 2>/dev/null && fail "a did:plc not base32"
# Compared as the index compares them: case, and a domain's trailing dot,# are not a second entry."$here/denylist.sh" add Troll.Example. >/dev/nullentries | grep -qxF troll.example || fail "a domain is kept as the index reads it""$here/denylist.sh" add troll.example | grep -q 'already on it' || fail "a domain in another case""$here/denylist.sh" add did:web:Agent.Troll.Example%3A3000 >/dev/nullentries | grep -qxF did:web:agent.troll.example%3A3000 || fail "a did:web's host in lowercase""$here/denylist.sh" remove TROLL.example >/dev/nullentries | grep -qxF troll.example && fail "a remove in another case"
# An edit the board never takes up is said to be one.touch "$FAKE_S3/stale"status=0DENYLIST_WAIT=0 "$here/denylist.sh" add stale.example >/dev/null 2>"$T/err" || status=$?[ "$status" -eq 4 ] || fail "an edit /health never counts: status $status"grep -q 'journalctl -u vibescrobble-denylist' "$T/err" || fail "and where to look"entries | grep -qxF stale.example || fail "is still written"
echo "denylist.sh: ok"