174e82a / test/sync.sh
diff --cc test/sync.sh
index fa95b3e,c8c61b4..e4bfa8d
--- a/test/sync.sh
+++ b/test/sync.sh
@@@ -78,8 -89,24 +90,25 @@@ node "$cli" sync --data "$scratch/b" --
git -C "$scratch/clone" fetch -q origin
test "$(git -C "$scratch/clone" rev-parse origin/main)" = "$head2"
git -C "$scratch/clone" merge-base --is-ancestor "$head1" "$head2"
+curl -fsS "http://127.0.0.1:$portB/feed" | grep -F 'Pushed 1 commit'
+ # (2b) A post published on A replicates to B through sync: B holds it in
+ # posts/ (not records/), serves it on /feed, and a re-pull stores nothing.
+ postText='Feed replication reaches node B'
+ node "$cli" post --data "$scratch/a" --text "$postText" >/dev/null
+ syncOut=$(node "$cli" sync --data "$scratch/b" --url "http://127.0.0.1:$portA")
+ printf '%s' "$syncOut" | grep -F '"posts":1' >/dev/null
+ grep -rF "$postText" "$scratch/b/posts" >/dev/null
+ if grep -rF "$postText" "$scratch/b/records" >/dev/null 2>&1; then
+ printf 'Post leaked into records/\n' >&2
+ exit 1
+ fi
+ feed_serves "$postText"
+ again=$(node "$cli" sync --data "$scratch/b" --url "http://127.0.0.1:$portA")
+ printf '%s' "$again" | grep -F '"stored":0' >/dev/null
+ printf '%s' "$again" | grep -F '"fetched":0' >/dev/null
+ printf '%s' "$again" | grep -F '"posts":0' >/dev/null
+
restart_b() {
kill "$serverB" 2>/dev/null || :
wait "$serverB" 2>/dev/null || :
@@@ -128,18 -155,21 +157,36 @@@ node "$cli" sync --data "$scratch/b" --
git -C "$scratch/clone" fetch -q origin
test "$(git -C "$scratch/clone" rev-parse origin/main)" = "$head3"
git -C "$scratch/clone" merge-base --is-ancestor "$head2" "$head3"
+ # The post interleaved with the chain sync is still held and served.
+ grep -rF "$postText" "$scratch/b/posts" >/dev/null
+ feed_serves "$postText"
+
+ # (3c) A tampered post offered over sync is rejected; the original post
+ # and the previous selection keep serving after a restart.
+ start_shim tamper-post
+ if node "$cli" sync --data "$scratch/b" --url "http://127.0.0.1:$shimPort" 2>"$scratch/reject-post.err"; then
+ printf 'Sync accepted a tampered post\n' >&2
+ exit 1
+ fi
+ grep -F 'tampered post' "$scratch/shim.tamper-post.log"
+ stop_shim
+ restart_b
+ git clone -q "$(cat "$scratch/urlb")" "$scratch/still-old-3"
+ test "$(git -C "$scratch/still-old-3" rev-parse HEAD)" = "$head3"
+ feed_serves "$postText"
++
+post=$(node "$cli" post --data "$scratch/a" --text "Post composed on A" |
+ node -pe 'JSON.parse(require("node:fs").readFileSync(0)).id')
+node "$cli" sync --data "$scratch/b" --url "http://127.0.0.1:$portA" >/dev/null
+node "$cli" post --data "$scratch/b" --reply-to "$post" --text "Reply composed on B" >/dev/null
+for attempt in 1 2; do
+ node "$cli" sync --data "$scratch/a" --url "http://127.0.0.1:$portB" >/dev/null
+ node "$cli" sync --data "$scratch/b" --url "http://127.0.0.1:$portA" >/dev/null
+done
+for port in "$portA" "$portB"; do
+ feed=$(curl -fsS "http://127.0.0.1:$port/feed")
+ test "$(printf '%s' "$feed" | grep -c 'Post composed on A')" -eq 1
+ test "$(printf '%s' "$feed" | grep -c 'Reply composed on B')" -eq 1
+ test "$(printf '%s' "$feed" | grep -c 'Pushed 1 commit')" -eq 1
+done
printf 'PASS: peer sync served %s, propagated %s, rejected corrupt data, and retried to %s.\n' "$head1" "$head2" "$head3"
Git ยท Social feed