Files
SocialPub/tools/pasture/scenarios/writefreely.sh
T
thepraandClaude Opus 5.5 0aea550c6c Pasture: WriteFreely 0.17.2
WriteFreely joins the pasture, built from its release with openssl beside it (it makes each blog's keys with the
command); scenarios/writefreely.sh has alice follow a blog and receive its post as a titled Article, its edit and its
deletion, then unfollow: 13 checks, with no change to PrivaPub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
2026-10-06 00:28:11 +02:00

47 lines
3.5 KiB
Bash

# WriteFreely 0.17.2: alice follows a blog; a post there reaches her home as an Article with its title; its edit and its
# deletion follow; the unfollow; statistics. A blog follows nobody and takes no replies or likes, so nothing goes the
# other way. Driven through its API as wfuser, with the token peers/writefreely.sh got.
WF=https://writefreely.test:6443
WFT=$(cat "$here/.state/writefreely/wfuser.token" 2>/dev/null)
wf() { site writefreely.test -s -H "Authorization: Token $WFT" -H 'Content-Type: application/json' "$@"; }
# wf_sql <query>: from WriteFreely's SQLite, read in its volume
wf_sql() { python3 -c 'import sqlite3, sys; print("\n".join("|".join(map(str, r)) for r in sqlite3.connect(sys.argv[1]).execute(sys.argv[2])))' \
"$(podman volume inspect pasture-writefreely --format '{{.Mountpoint}}')/writefreely.db" "$1"; }
p_home_has() { curl -s -H "$PH" "$P/api/v1/timelines/home?limit=40" | j "print(next((s['id'] for s in d if '$1' in (s['content'] or '') or '$1' in ((s.get('privapub') or {}).get('title') or '')), ''))"; }
echo "writefreely"
[ "$(wf "$WF/api/me" | j "print(d['data']['username'])")" = "wfuser" ] && ok "WriteFreely token for wfuser" || { ko "WriteFreely token"; return 1; }
PT=$(privapub_token alice_wf)
PH="Authorization: Bearer $PT"
[ -n "$PT" ] && ok "PrivaPub token for alice_wf" || { ko "PrivaPub token for alice_wf"; return 1; }
run=$(date +%s)
echo " following the blog"
blog_on_p=$(curl -s -H "$PH" "$P/api/v2/search?q=wfuser@writefreely.test&resolve=true&type=accounts" | j "print(d['accounts'][0]['id'])")
[ -n "$blog_on_p" ] && ok "PrivaPub resolves the blog" || ko "PrivaPub cannot resolve the blog"
curl -s -o /dev/null -X POST -H "$PH" "$P/api/v1/accounts/$blog_on_p/follow"
until_true 45 '[ "$(curl -s -H "$PH" "$P/api/v1/accounts/relationships?id[]=$blog_on_p" | j "print(d[0][\"following\"])")" = "True" ]' \
&& ok "alice follows the blog (Accept arrived)" || ko "the blog's Accept never arrived"
echo " articles"
post=$(wf -X POST "$WF/api/collections/wfuser/posts" -d "{\"title\":\"A WriteFreely article $run\",\"body\":\"Written on a blog, $run.\"}")
post_id=$(echo "$post" | j "print(d['data']['id'])")
until_true 45 '[ -n "$(p_home_has "A WriteFreely article $run")" ]' && ok "the blog's post reaches alice's home" || ko "the blog's post never reached alice"
on_p=$(p_home_has "A WriteFreely article $run")
[ "$(curl -s -H "$PH" "$P/api/v1/statuses/$on_p" | j "print((d.get('privapub') or {}).get('title'))")" = "A WriteFreely article $run" ] \
&& ok "as an Article with its title" || ko "the article arrived without its title"
wf -o /dev/null -X POST "$WF/api/posts/$post_id" -d "{\"title\":\"A WriteFreely article $run\",\"body\":\"Written on a blog, $run, then edited.\"}"
until_true 45 '[ "$(curl -s -H "$PH" "$P/api/v1/statuses/$on_p" | j "print(\"then edited\" in d[\"content\"])")" = "True" ]' \
&& ok "its edit reaches PrivaPub" || ko "its edit never reached PrivaPub"
wf -o /dev/null -X DELETE "$WF/api/posts/$post_id"
until_true 45 '[ "$(curl -s -o /dev/null -w "%{http_code}" -H "$PH" "$P/api/v1/statuses/$on_p")" = "404" ]' \
&& ok "its deletion reaches PrivaPub" || ko "the deleted article still shows on PrivaPub"
echo " unfollow"
curl -s -o /dev/null -X POST -H "$PH" "$P/api/v1/accounts/$blog_on_p/unfollow"
until_true 45 '[ "$(wf_sql "select count(*) from remotefollows f join remoteusers u on u.id = f.remote_user_id where u.actor_id like '"'%alice_wf'"'")" = "0" ]' \
&& ok "alice's unfollow reaches the blog" || ko "the blog still counts alice"
echo " statistics"
stats_check writefreely.test writefreely