Place names for --region, an expiry reminder, and e2e checks through the UI
--region takes a place name as well as a code ("Bonn", "Köln", "cologne",
"name:dub" to force a name that looks like a code). The node uses the same
GeoNames list as the browser (internal/places), follows the place's cell plus
any cell within 40 km, and prints what each name became.
The node reminds the owner on its terminal, once a day per listing, about
every listing with 5 days or less left (the UI marks the same range). The
sign-in token is never in the line.
scripts/e2e/ui.ts drives the real bundle in jsdom against real nodes: a buyer
writes from a listing page, the owner reads and answers in their own page and
the buyer's page shows the verified answer; a node with no region gets its
first one by place name in the browser and keeps it over a restart. e2e.sh
also checks --region by name and the reminder, and keeps its scratch files in
the checkout's .tmp.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
+49
-1
@@ -9,7 +9,8 @@ ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
||||
[ -d "$ROOT/web/node_modules" ] || { echo "web dependencies missing: run 'cd web && npm ci' first"; exit 1; }
|
||||
(cd "$ROOT" && go build -o bin/allmende ./cmd/allmende) || exit 1
|
||||
BIN=$ROOT/bin/allmende
|
||||
W=$(mktemp -d "${TMPDIR:-/tmp}/allmende-e2e.XXXXXX")
|
||||
mkdir -p "$ROOT/.tmp" # scratch space inside the checkout (git ignores it), not /tmp
|
||||
W=$(mktemp -d "${TMPDIR:-$ROOT/.tmp}/allmende-e2e.XXXXXX")
|
||||
A=$W/a; B=$W/b
|
||||
PIDS=()
|
||||
cleanup() {
|
||||
@@ -119,6 +120,11 @@ ok "buyer's browser code verified and read the grant from B"
|
||||
node $BUYER read http://127.0.0.1:18102 $AUTHOR $ID $(node -e 'console.log("77".repeat(32))') | grep -q . && bad "another thread key saw a reply"
|
||||
ok "a different thread key sees nothing"
|
||||
|
||||
echo "== the same through the web UI: a real page for the buyer on B, one for the owner on A"
|
||||
UI=$ROOT/scripts/e2e/ui.ts
|
||||
node $UI buyer http://127.0.0.1:18102 http://127.0.0.1:18101 $TOKEN $AUTHOR $ID > $W/ui-buyer.txt 2>&1 \
|
||||
&& { sed 's/^OK /PASS: UI: /' $W/ui-buyer.txt; } || { cat $W/ui-buyer.txt; bad "the buyer flow through the web UI"; }
|
||||
|
||||
echo "== recover on A (simulate a stolen machine)"
|
||||
OLD_DEVICE=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["device"])')
|
||||
kill ${PIDS[0]}; wait ${PIDS[0]} 2>/dev/null
|
||||
@@ -176,4 +182,46 @@ wait_for "X restarted" 10 curl -sf http://127.0.0.1:18104/api/v1/status
|
||||
wait_for "X reconnects from its remembered peers" 30 check ge 1 peers 18104
|
||||
ok "X rejoined the network with no bootstrap configured"
|
||||
|
||||
echo "== regions: chosen by place name in the browser, even the first one"
|
||||
D=$W/d
|
||||
$BIN init --data $D >/dev/null || bad "init D"
|
||||
# No --region: the node starts empty and says what to do.
|
||||
$BIN run --data $D --no-mdns --no-default-bootstrap --difficulty $DIFF --http 127.0.0.1:18106 \
|
||||
--listen /ip4/127.0.0.1/tcp/14106 2> $W/d.log &
|
||||
DPID=$!; PIDS+=($DPID)
|
||||
wait_for "D http" 10 curl -sf http://127.0.0.1:18106/api/v1/status
|
||||
grep -q "follows no region yet" $W/d.log && ok "a node without a region starts and tells the owner what to do" || bad "no hint for the owner"
|
||||
DTOKEN=$(cat $D/admin.token)
|
||||
node $UI regions http://127.0.0.1:18106 $DTOKEN > $W/ui-regions.txt 2>&1 \
|
||||
&& { sed 's/^OK /PASS: UI: /' $W/ui-regions.txt; } || { cat $W/ui-regions.txt; bad "choosing the first region through the web UI"; }
|
||||
[ -s $D/regions.json ] && ok "the choice is saved in the data directory" || bad "regions.json missing"
|
||||
kill $DPID; wait $DPID 2>/dev/null
|
||||
$BIN run --data $D --no-mdns --no-default-bootstrap --difficulty $DIFF --http 127.0.0.1:18106 \
|
||||
--listen /ip4/127.0.0.1/tcp/14106 2> $W/d2.log &
|
||||
DPID=$!; PIDS+=($DPID)
|
||||
wait_for "D restarted" 10 curl -sf http://127.0.0.1:18106/api/v1/status
|
||||
curl -s http://127.0.0.1:18106/api/v1/status | grep -q '"regions":\["u1j"' && ok "after a restart without --region it still follows what the browser chose" || bad "regions were lost on restart"
|
||||
|
||||
echo "== --region takes place names"
|
||||
$BIN run --data $W/nope --region Atlantisxyz 2>&1 | grep -q "neither a region code" && ok "an unknown place is refused with a hint" || bad "unknown place was not refused"
|
||||
E=$W/e
|
||||
$BIN init --data $E >/dev/null || bad "init E"
|
||||
$BIN run --data $E --region cologne --no-mdns --no-default-bootstrap --difficulty $DIFF --http 127.0.0.1:18107 \
|
||||
--listen /ip4/127.0.0.1/tcp/14107 2> $W/e.log &
|
||||
PIDS+=($!)
|
||||
wait_for "E http" 10 curl -sf http://127.0.0.1:18107/api/v1/status
|
||||
grep -q 'Köln (Cologne)' $W/e.log && ok "'cologne' is announced as Köln, with the cells it follows" || bad "no note about what the name turned into"
|
||||
curl -s http://127.0.0.1:18107/api/v1/status | grep -q '"regions":\["u1h"' && ok "Cologne's own cell (u1h) comes first" || bad "wrong region for cologne: $(curl -s http://127.0.0.1:18107/api/v1/status)"
|
||||
|
||||
echo "== a listing that runs out soon is reminded on the owner's terminal"
|
||||
SOON='{"kind":"rent","category":"room","geohash":"u1jjjj","price":{"amount_cents":50000,"currency":"EUR","period":"month"},"title":"Zimmer, nur noch kurz","expires_in_days":3}'
|
||||
curl -s -o /dev/null -w "%{http_code}" -X POST -H "Authorization: Bearer $DTOKEN" -d "$SOON" http://127.0.0.1:18106/api/v1/listings | grep -qE "^(200|201)$" || bad "could not publish the short listing on D"
|
||||
wait_for "D's terminal reminds about the listing" 60 grep -q 'a listing runs out soon' $W/d2.log
|
||||
grep 'a listing runs out soon' $W/d2.log | grep -q 'listing="Zimmer, nur noch kurz"' && ok "the reminder names the listing" || bad "reminder does not name the listing"
|
||||
grep 'a listing runs out soon' $W/d2.log | grep -q 'left="3 days"' && ok "and says how long is left" || bad "reminder does not say how long is left"
|
||||
grep 'a listing runs out soon' $W/d2.log | grep -q "renew=http://127.0.0.1:18106/#/mine" && ok "and links to where to renew" || bad "reminder has no link"
|
||||
grep 'a listing runs out soon' $W/d2.log | grep -q "$DTOKEN" && bad "the sign-in token leaked into the log"
|
||||
ok "the reminder does not carry the sign-in token"
|
||||
grep -q "Helle Wohnung" $W/d2.log && bad "a listing with plenty of time left was reminded"
|
||||
|
||||
echo "ALL E2E CHECKS PASSED"
|
||||
|
||||
Reference in New Issue
Block a user