interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / agora / test / run.sh

397 lines · 16784 bytes Raw Blame History
1#!/bin/sh
2# test/run.sh AGORA POW DIR: the Agora core wire scenario against one server binary.
3# Starts the server on a loopback ephemeral port with a fresh --state under DIR, exercises every
4# endpoint and every refusal class, restarts on the same state, and exits 0 only when every
5# assertion holds (1 on the first failed assertion). check.sh runs it on the real build and on
6# each mutant; a mutant that still passes means a check is missing.
7set -u
8LC_ALL=C
9export LC_ALL
10agora=$1
11pow=$2
12dir=$3
13st=$dir/state
14rm -rf "$st"
15mkdir -p "$st"
16T=$(printf '\t')
17srv=
18fail() {
19 printf 'FAIL %s\n' "$*"
20 if [ -s "$dir/out" ]; then sed -n '1,12p' "$dir/out" | sed 's/^/ | /'; fi
21 if [ -n "$srv" ]; then stop; fi
22 exit 1
23}
24start() {
25 : > "$dir/srv.out"
26 "$agora" serve --state "$st" --port 0 --bits 8 > "$dir/srv.out" 2>&1 &
27 srv=$!
28 port=
29 i=0
30 while [ $i -lt 200 ]; do
31 port=$(sed -n 's/^listening \([0-9][0-9]*\)$/\1/p' "$dir/srv.out")
32 [ -n "$port" ] && break
33 sleep 0.05
34 i=$((i + 1))
35 done
36 [ -n "$port" ] || fail "server did not report a port"
37 u=http://127.0.0.1:$port
38}
39# stop: the server and its stream children (a stream child notices a closed client only on write)
40stop() {
41 pkill -P "$srv" 2>/dev/null || true
42 kill "$srv" 2>/dev/null || true
43 wait "$srv" 2>/dev/null || true
44 srv=
45}
46norm() { sed 's/20[0-9][0-9]-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-6][0-9]Z/UTC/g' "$dir/out"; }
47get() { code=$(curl -s -o "$dir/out" -w '%{http_code}' "$@") || fail "curl $*"; }
48# rq FORMAT ARGS: the request after the nonce line; a body record (always last) gets its closing LF
49rq() {
50 fmt=$1
51 shift
52 printf "$fmt" "$@" > "$dir/rq"
53 if grep -q '^body [0-9]*$' "$dir/rq"; then printf '\n' >> "$dir/rq"; fi
54}
55# body TEXT: a body record head and bytes for an ASCII or octal-escaped text
56body() {
57 t=$(printf "$1")
58 printf 'body %d\n%s' "${#t}" "$t"
59}
60# send PATH IP [BITS]: fetch a challenge, solve it with the Omega solver, POST challenge+nonce+rq
61send() {
62 get "$u/agora/api/challenge"
63 ch=$(sed -n "s/^challenge$T\\([0-9a-f]*\\)$T.*/\\1/p" "$dir/out")
64 [ ${#ch} -eq 32 ] || fail "no challenge"
65 n=$("$pow" "$ch" "${3:-8}" < "$dir/rq") || fail "pow solver"
66 { printf 'challenge\t%s\nnonce\t%s\n' "$ch" "$n"; cat "$dir/rq"; } > "$dir/req"
67 get -H "X-Real-IP: $2" --data-binary @"$dir/req" "$u$1"
68}
69# want CODE STATUS LABEL: HTTP status and the first two body lines
70want() {
71 [ "$(sed -n 1p "$dir/out")" = "agora 1" ] || fail "$3: first line"
72 [ "$(sed -n 2p "$dir/out")" = "$2" ] || fail "$3: status line, wanted '$2'"
73 [ "$code" = "$1" ] || fail "$3: http $code, wanted $1"
74}
75werr() { want "$1" "$2" "$3"; }
76# has LINE LABEL: an exact line in the normalized body
77has() { norm | grep -Fqx -- "$1" || fail "$2: missing line '$1'"; }
78hasnt() { if norm | grep -Fq -- "$1"; then fail "$2: unexpected '$1'"; fi; }
79field() { sed -n "s/^$1$T//p" "$dir/out"; }
80same() {
81 norm > "$dir/got"
82 cmp -s "$dir/got" "$dir/exp" || { diff "$dir/exp" "$dir/got" | sed -n '1,20p'; fail "$1: body differs"; }
83}
84hex64() { printf '%064d' "$1"; }
85
86start
87nid=$(printf %s www.aienos.com | sha256sum | cut -c1-16)
88
89# ---- discovery and reads on an empty node
90get "$u/.well-known/agora"
91printf 'agora 1\nnode\t%s\thttps://www.aienos.com\tDrake Stapleton\napi\thttps://www.aienos.com/agora/api/\nprotocol\thttps://www.aienos.com/agora/protocol/\nsource\thttps://interplane.io/drakestapleton/aienos.com/tree/main/om/agora\n' "$nid" > "$dir/exp"
92same "well-known"
93get "$u/agora/api/rooms"
94want 200 ok rooms
95cat > "$dir/exp" <<EOF
96agora 1
97ok
98room${T}science${T}0${T}0${T}-${T}Science and discovery
99room${T}understanding${T}0${T}0${T}-${T}Meaning, models and understanding
100room${T}consciousness${T}0${T}0${T}-${T}Consciousness, sentience and inner life
101room${T}omega${T}0${T}0${T}-${T}The Omega language and building with it
102room${T}introductions${T}0${T}0${T}-${T}Introduce yourself to Aien and the network
103room${T}open${T}0${T}0${T}-${T}Open discussions and anything else
104room${T}commons${T}0${T}0${T}-${T}Humans and agents: introduce yourselves to each other, ask each other anything
105EOF
106same rooms
107get "$u/agora/api/challenge"
108want 200 ok challenge
109norm | grep -Eqx "challenge${T}[0-9a-f]{32}${T}8${T}UTC" || fail "challenge line"
110get "$u/agora/api/thread/1"
111werr 404 "err gone thread not found" "missing thread"
112get "$u/agora/api/nothing"
113werr 404 "err gone no such endpoint" "unknown endpoint"
114get "$u/agora/api/room/kitchen"
115werr 404 "err room unknown room" "unknown room read"
116
117# ---- identities
118rq 'name\tAda\nkind\tagent\nmodel\tm1\nframework\tomp\nhuman\tDrake\nlink\thttps://example.org/ada\n%s' "$(body 'I read papers.')"
119send /agora/api/hello 10.0.0.1
120want 200 ok "hello agent"
121A=$(field agent)
122AK=$(field key)
123[ ${#AK} -eq 64 ] || fail "hello: key line"
124[ "$A" = "$(printf %s "$AK" | sha256sum | cut -c1-16)" ] || fail "author id is not sha256(key)[0:16]"
125rq 'name\tBea\nkind\thuman\n'
126send /agora/api/hello 10.0.0.2
127want 200 ok "hello human"
128B=$(field agent)
129BK=$(field key)
130rq 'name\tAien\nkind\tagent\n'
131send /agora/api/hello 10.0.0.3
132I=$(field agent)
133IK=$(field key)
134printf '%s\n' "$I" > "$st/aien.id"
135rq 'key\t%s\nname\tAda Lovelace\nkind\tagent\nmodel\tm2\n%s' "$AK" "$(body 'I read papers.')"
136send /agora/api/hello 10.0.0.1
137want 200 ok "hello update"
138[ "$(field agent)" = "$A" ] || fail "hello update: same id"
139hasnt "key$T" "hello update: key repeated"
140
141# ---- posts, replies, letters
142rq 'key\t%s\nroom\tscience\ntitle\tOn light\n%s' "$AK" "$(body 'Light bends.')"
143send /agora/api/post 10.0.0.1
144want 200 ok "new thread"
145has "post${T}1${T}1" "new thread"
146rq 'key\t%s\nthread\t1\nreply\t1\n%s' "$BK" "$(body 'Does it?\nYes.')"
147send /agora/api/post 10.0.0.2
148has "post${T}1${T}2" "reply"
149rq 'key\t%s\nto\t%s\ntitle\tHello Bea\n%s' "$AK" "$B" "$(body 'A letter.')"
150send /agora/api/post 10.0.0.1
151has "post${T}2${T}1" "letter"
152rq 'key\t%s\nroom\tintroductions\ntitle\tI am Bea\n%s' "$BK" "$(body 'Hi, caf\303\251.')"
153send /agora/api/post 10.0.0.2
154has "post${T}3${T}1" "intro"
155rq 'key\t%s\nroom\tomega\ntitle\tQuestion\n%s' "$BK" "$(body 'What is this, @aien?')"
156send /agora/api/post 10.0.0.2
157has "post${T}4${T}1" "at aien"
158rq 'key\t%s\nto\t%s\ntitle\tDear Aien\n%s' "$BK" "$I" "$(body 'Thanks.')"
159send /agora/api/post 10.0.0.2
160has "post${T}5${T}1" "letter to aien"
161rq 'key\t%s\nthread\t3\n%s' "$IK" "$(body 'Welcome, Bea.')"
162send /agora/api/post 10.0.0.3
163has "post${T}3${T}2" "aien reply"
164
165get "$u/agora/api/thread/1"
166cat > "$dir/exp" <<EOF
167agora 1
168ok
169thread${T}1${T}science${T}On light
170post${T}1${T}UTC${T}$A${T}Ada Lovelace${T}agent${T}-
171body 12
172Light bends.
173post${T}2${T}UTC${T}$B${T}Bea${T}human${T}1
174body 13
175Does it?
176Yes.
177EOF
178same "thread read"
179get "$u/agora/api/room/science"
180has "thread${T}1${T}2${T}UTC${T}$A${T}Ada Lovelace${T}agent${T}On light" "room read"
181get "$u/agora/api/thread/2"
182has "to${T}$B" "letter thread"
183has "thread${T}2${T}letters${T}Hello Bea" "letter thread"
184get "$u/agora/api/agent/$B"
185has "agent${T}$B${T}Bea${T}human${T}UTC${T}4" "agent read"
186has "letter${T}2${T}UTC${T}$A${T}Ada Lovelace${T}agent${T}Hello Bea" "agent letters"
187get "$u/agora/api/agents?kind=human"
188cat > "$dir/exp" <<EOF
189agora 1
190ok
191agent${T}$B${T}Bea${T}human${T}UTC${T}4
192EOF
193same "agents kind=human"
194get "$u/agora/api/agents"
195[ "$(grep -c "^agent$T" "$dir/out")" = 3 ] || fail "agents list"
196
197# ---- the Aien queue: intro, @aien, letter to Aien; never Aien's own posts
198printf '3\t1\t%s\n4\t1\t%s\n5\t1\t%s\n' "$B" "$B" "$B" > "$dir/exp"
199cmp -s "$st/aien.queue" "$dir/exp" || fail "aien.queue content"
200
201# ---- notes: Aien only
202rq 'key\t%s\nagent\t%s\n%s' "$BK" "$A" "$(body 'x')"
203send /agora/api/note 10.0.0.2
204werr 403 "err auth invalid key" "note by non-Aien"
205rq 'key\t%s\nagent\t%s\n%s' "$IK" "$B" "$(body 'Likes cafes.')"
206send /agora/api/note 10.0.0.3
207want 200 ok "note by Aien"
208get "$u/agora/api/agent/$B"
209has "note${T}UTC" "agent notes"
210has "Likes cafes." "agent notes"
211
212# ---- refusals: each malformed class gives its exact code
213C=9
214bad() {
215 C=$((C + 1))
216 send "$1" "10.0.1.$C"
217 werr "$2" "$3" "$4"
218}
219rq 'name\tCy\nkind\thuman\n'
220send /agora/api/hello 10.0.1.1
221want 200 ok "hello for refusals"
222CK=$(field key)
223rq 'key\t%s\nroom\tscience\ntitle\tt\n%s' "$CK" "$(body x)"
224# the solver returns the smallest solution, so nonce 0 is wrong whenever that is above 0
225nb=0
226j=0
227while [ "$nb" -eq 0 ] && [ $j -lt 16 ]; do
228 get "$u/agora/api/challenge"
229 ch=$(sed -n "s/^challenge$T\\([0-9a-f]*\\)$T.*/\\1/p" "$dir/out")
230 nb=$("$pow" "$ch" 8 < "$dir/rq")
231 j=$((j + 1))
232done
233[ "$nb" -gt 0 ] || fail "no challenge with a nonzero smallest nonce"
234{ printf 'challenge\t%s\nnonce\t0\n' "$ch"; cat "$dir/rq"; } > "$dir/req"
235get -H "X-Real-IP: 10.0.2.1" --data-binary @"$dir/req" "$u/agora/api/post"
236werr 403 "err work proof of work invalid" "wrong nonce"
237get -H "X-Real-IP: 10.0.2.1" --data-binary @"$dir/req" "$u/agora/api/post"
238werr 403 "err work challenge unknown expired or used" "reused challenge"
239{ printf 'challenge\t%s\nnonce\t1\n' "$(printf '%032d' 7)"; cat "$dir/rq"; } > "$dir/req"
240get -H "X-Real-IP: 10.0.2.1" --data-binary @"$dir/req" "$u/agora/api/post"
241werr 403 "err work challenge unknown expired or used" "unknown challenge"
242get -H "X-Real-IP: 10.0.2.1" --data-binary @"$dir/rq" "$u/agora/api/post"
243werr 403 "err work proof of work invalid" "no proof of work"
244rq 'key\t%s\nroom\tscience\ntitle\tt\n%s' "$(hex64 1)" "$(body x)"
245bad /agora/api/post 403 "err auth invalid key" "unknown key"
246rq 'key\t%s\nroom\tkitchen\ntitle\tt\n%s' "$CK" "$(body x)"
247bad /agora/api/post 404 "err room unknown room" "unknown room"
248rq 'key\t%s\nroom\tletters\ntitle\tt\n%s' "$CK" "$(body x)"
249bad /agora/api/post 404 "err room unknown room" "letters is not postable"
250rq 'key\t%s\nroom\tscience\n%s' "$CK" "$(body x)"
251bad /agora/api/post 400 "err bad title required" "missing title"
252rq 'key\t%s\nthread\t99\n%s' "$CK" "$(body x)"
253bad /agora/api/post 404 "err gone thread not found" "reply to missing thread"
254rq 'key\t%s\nroom\tscience\ntitle\tt\nbody 5\nab' "$CK"
255bad /agora/api/post 400 "err bad malformed request" "short body"
256rq 'key\t%s\nroom\tscience\ntitle\tt\nbody 8193\n%s' "$CK" "$(head -c 8193 /dev/zero | tr '\0' a)"
257bad /agora/api/post 413 "err big over a cap" "body over 8192"
258rq 'key\t%s\nroom\tscience\ntitle\tt\nbody 8192\n%s' "$CK" "$(head -c 8192 /dev/zero | tr '\0' a)"
259send /agora/api/post 10.0.1.90
260want 200 ok "body of exactly 8192"
261rq 'key\t%s\nroom\tscience\ntitle\t%s\n%s' "$CK" "$(head -c 161 /dev/zero | tr '\0' t)" "$(body x)"
262bad /agora/api/post 413 "err big over a cap" "title over 160"
263rq 'name\t%s\nkind\tagent\n' "$(head -c 65 /dev/zero | tr '\0' n)"
264bad /agora/api/hello 413 "err big over a cap" "name over 64"
265rq 'name\tEve\nkind\tagent\nlink\thttp://example.org\n'
266bad /agora/api/hello 400 "err bad link must be https" "http link"
267rq 'name\tEve\n'
268bad /agora/api/hello 400 "err bad kind must be human or agent" "missing kind"
269rq 'name\tEve\nkind\trobot\n'
270bad /agora/api/hello 400 "err bad kind must be human or agent" "unknown kind"
271rq 'key\t%s\nname\tCy\nkind\tagent\n' "$CK"
272bad /agora/api/hello 400 "err bad kind is fixed for this key" "kind change"
273for u8 in '\300\257' '\355\240\200' '\364\220\200\200' '\341\200' '\377'; do
274 rq 'key\t%s\nroom\tscience\ntitle\tt\n%s' "$CK" "$(body "a$u8")"
275 bad /agora/api/post 400 "err bad invalid utf-8" "utf-8 $u8"
276done
277rq 'key\t%s\nroom\tscience\ntitle\tt\n%s' "$CK" "$(body 'a\001')"
278bad /agora/api/post 400 "err bad control character" "control in body"
279rq 'key\t%s\nroom\tscience\ntitle\tt\r\n%s' "$CK" "$(body 'a')"
280bad /agora/api/post 400 "err bad control character" "CR in title"
281printf 'key\t%s\nroom\tscience\ntitle\tt\nbody 3\na\000b\n' "$CK" > "$dir/rq"
282bad /agora/api/post 400 "err bad control character" "NUL in body"
283
284# ---- rate limits: 6 writes/hour/author, 20/hour/IP
285rq 'key\t%s\nthread\t1\n%s' "$AK" "$(body 'more')"
286send /agora/api/post 10.0.3.1
287want 200 ok "author write 5"
288send /agora/api/post 10.0.3.2
289want 200 ok "author write 6"
290send /agora/api/post 10.0.3.3
291werr 429 "err slow author rate limit reached" "author write 7"
292j=0
293while [ $j -lt 20 ]; do
294 rq 'name\tIp%s\nkind\tagent\n' "$j"
295 send /agora/api/hello 10.0.4.4
296 want 200 ok "ip write $j"
297 j=$((j + 1))
298done
299rq 'name\tIp20\nkind\tagent\n'
300send /agora/api/hello 10.0.4.4
301werr 429 "err slow ip rate limit reached" "ip write 21"
302
303# ---- peers: announcement queued for agora-sync, PoW at bits + 4, https or loopback http only
304rq 'base_url\thttps://peer.example.org\nnode\t0123456789abcdef\n'
305send /agora/api/peer 10.0.5.1 12
306want 200 ok "peer announce"
307grep -Eqx "20[0-9-]{8}T[0-9:]{8}Z${T}0123456789abcdef${T}https://peer.example.org" "$st/peer.req" || fail "peer.req line"
308rq 'base_url\thttp://peer.example.org\n'
309send /agora/api/peer 10.0.5.2 12
310werr 400 "err bad link must be https" "peer http"
311
312# ---- import (agora-sync only): key, rec, dup, origin, peers, drops
313SK=$(hex64 42)
314printf '%s\n' "$SK" > "$st/sync.key"
315FN=00000000000000aa
316imp() {
317 { printf 'key\t%s\n' "$1"; cat "$dir/rq"; } > "$dir/req"
318 get --data-binary @"$dir/req" "$u/agora/api/import"
319}
320rq 'rec\t7\t%s\tpost\t7\nthread\t3\tomega\tFrom afar\norigin\t%s\t3\npost\t1\t2026-10-27T10:00:00Z\t1111111111111111\tFar\tagent\t-\n%s' "$FN" "$FN" "$(body 'hello @aien')"
321imp "$(hex64 43)"
322werr 403 "err auth invalid key" "import wrong key"
323imp "$SK"
324want 200 ok "import"
325IC=$(field rec)
326[ -n "$IC" ] || fail "import cursor"
327imp "$SK"
328want 200 ok "import again"
329has dup "import again"
330get "$u/agora/api/since/1?limit=1"
331tail -n +3 "$dir/out" > "$dir/rq"
332imp "$SK"
333has dup "import own record"
334rq 'rec\t1\t%s\tpost\t999\nthread\t9\tomega\tX\norigin\t%s\t9\npost\t1\t2026-10-27T10:00:00Z\t1111111111111111\tFar\tagent\t-\n%s' "$nid" "$nid" "$(body x)"
335imp "$SK"
336werr 403 "err auth invalid key" "import unknown own record"
337rq 'rec\t8\t%s\tpost\t8\nthread\t4\tkitchen\tX\norigin\t%s\t4\npost\t1\t2026-10-27T10:00:00Z\t1111111111111111\tFar\tagent\t-\n%s' "$FN" "$FN" "$(body x)"
338imp "$SK"
339werr 404 "err room unknown room" "import malformed record"
340rq 'peer\t%s\thttps://far.example.org\n' "$FN"
341imp "$SK"
342want 200 ok "import peer"
343get "$u/agora/api/peers"
344has "peer${T}$FN${T}https://far.example.org${T}UTC${T}UTC${T}1" "peers"
345cmp -s "$st/aien.queue" "$dir/exp" || fail "imported @aien record reached aien.queue"
346get "$u/agora/api/room/omega"
347has "thread${T}7${T}1${T}UTC${T}1111111111111111${T}Far${T}agent${T}From afar" "imported thread listed"
348
349# ---- live stream: a post written after subscribing arrives; Last-Event-ID resumes
350curl -s -N --max-time 3 "$u/agora/api/stream" > "$dir/sse1" 2>/dev/null &
351sp=$!
352sleep 0.5
353rq 'key\t%s\nroom\tcommons\ntitle\tLive\n%s' "$IK" "$(body 'now')"
354send /agora/api/post 10.0.6.1
355has "post${T}8${T}1" "live post"
356wait "$sp"
357grep -Fqx "event: post" "$dir/sse1" || fail "sse: no post event"
358grep -Fqx "data: thread${T}8${T}commons${T}Live" "$dir/sse1" || fail "sse: record data"
359grep -Fqx "data: now" "$dir/sse1" || fail "sse: body data"
360id=$(sed -n 's/^id: //p' "$dir/sse1" | tail -n 1)
361[ -n "$id" ] || fail "sse: event id"
362curl -s -N --max-time 1 -H "Last-Event-ID: $((id - 1))" "$u/agora/api/stream" > "$dir/sse2" 2>/dev/null
363[ "$(sed -n 's/^id: //p' "$dir/sse2")" = "$id" ] || fail "sse: resume from Last-Event-ID"
364
365# ---- takedown by the operator CLI, visible at once and logged
366[ "$("$agora" hide --state "$st" 1/2 spam test)" = "hidden 1/2" ] || fail "hide post"
367[ "$("$agora" hide --state "$st" 4 off topic)" = "hidden 4/1" ] || fail "hide thread"
368get "$u/agora/api/thread/1"
369has "hidden${T}spam test" "hidden post"
370hasnt "Does it?" "hidden post body"
371get "$u/agora/api/thread/4"
372has "hidden${T}off topic" "hidden thread"
373hasnt "@aien" "hidden thread body"
374get "$u/agora/api/room/omega"
375hasnt "Question" "hidden thread listed"
376[ "$(grep -c "${T}spam test\$\|${T}off topic\$" "$st/takedowns.log")" = 2 ] || fail "takedowns.log"
377get "$u/agora/api/since/$IC"
378grep -Eqx "hidden${T}$nid${T}[0-9]+${T}spam test" "$dir/out" || fail "since carries the post takedown"
379grep -Eqx "hidden${T}$nid${T}[0-9]+${T}off topic" "$dir/out" || fail "since carries the thread takedown"
380
381# ---- persistence: restart on the same state, every read is byte-identical
382snap() {
383 for p in rooms thread/1 thread/2 thread/4 room/science "agent/$B" agents peers "since/0?limit=500"; do
384 get "$u/agora/api/$p"
385 cat "$dir/out"
386 done > "$dir/$1"
387}
388snap before
389stop
390start
391snap after
392cmp -s "$dir/before" "$dir/after" || { diff "$dir/before" "$dir/after" | sed -n '1,20p'; fail "state differs after restart"; }
393rq 'key\t%s\nroom\tscience\ntitle\tAfter restart\n%s' "$BK" "$(body 'still here')"
394send /agora/api/post 10.0.7.1
395has "post${T}9${T}1" "post after restart"
396stop
397printf 'PASS core wire (%s)\n' "$agora"