interplane.Get Omega
Read in your language

open-humanity

Privacy-first peer assistance network for sovereign autonomous agents

Brought by drakestapleton

branch main Branches Tags History

open-humanity / scripts / e2e-local.sh

90 lines · 5807 bytes Raw Blame History
1#!/usr/bin/env bash
2# One relay, one helper and one asker as three separate processes on the loopback
3# interface, using the built binaries. Run from anywhere: scripts/e2e-local.sh
4# Then a second relay linked with the first, a helper with a lasting key at that relay, and
5# an answer that is checked before it is kept.
6# OH_E2E_PORT picks the first UDP port (default 18198; the next one is used too).
7# Exit 0 and "RESULT e2e pass" on success.
8set -u
9cd "$(dirname "$0")/.."
10T=$(mktemp -d /tmp/oh-e2e.XXXXXX)
11RELAY=; HELPER=; RELAY2=
12trap 'kill $RELAY $HELPER $RELAY2 2>/dev/null; rm -rf "$T"' EXIT
13pass=0; fail=0
14ok() { pass=$((pass+1)); echo "PASS $*"; }
15bad() { fail=$((fail+1)); echo "FAIL $*"; }
16cargo build --offline --workspace -q || { echo "FAIL build"; exit 1; }
17BIN=${CARGO_TARGET_DIR:-target}/debug
18PORT=${OH_E2E_PORT:-18198}
19OH="$BIN/open-humanity"
20PORT2=$((PORT+1))
21BEACON_BIND=127.0.0.1 BEACON_PORT=$PORT BEACON_LINKS=127.0.0.1:$PORT2 "$BIN/beacon" > "$T/relay.log" 2>&1 &
22RELAY=$!
23sleep 0.5
24kill -0 "$RELAY" 2>/dev/null && ok "relay runs on 127.0.0.1:$PORT" || { bad "relay did not start: $(cat "$T/relay.log")"; exit 1; }
25
26"$OH" teach --db "$T/helper.sqlite" --topic rust-compilation \
27 --error 'error[E0425]: cannot find value `foo` in /home/alice/app/src/main.rs' \
28 --solution 'declare foo with let before the first use' > "$T/teach.log" 2>&1 \
29 && ok "helper stored a solution" || bad "teach: $(cat "$T/teach.log")"
30"$OH" listen --db "$T/helper.sqlite" --relay "127.0.0.1:$PORT" --topics rust-compilation --for 8 > "$T/helper.log" 2>&1 &
31HELPER=$!
32sleep 1
33
34ask() { "$OH" ask --db "$T/asker.sqlite" --relay "127.0.0.1:$PORT" --topic rust-compilation --title 'Undefined identifier' "$@"; }
35SAME='error[E0425]: cannot find value `foo` in /home/bob/app/src/main.rs'
36
37ask --error "$SAME" --summary 'foo is used before it exists' > "$T/dry.log" 2>&1; rc=$?
38[ "$rc" = 3 ] && grep -q 'Nothing was sent' "$T/dry.log" && ok "without --approve nothing is sent (exit 3)" || bad "dry run: rc=$rc"
39
40out=$(ask --error "$SAME" --summary 'foo is used before it exists' --wait 5 --approve 2>&1); rc=$?
41[ "$rc" = 0 ] && echo "$out" | grep -q 'declare foo with let before the first use' \
42 && ok "the asker got the helper's solution through the relay" || bad "ask: rc=$rc: $out"
43echo "$out" | grep -q '/home/' && bad "a home folder left the node" || ok "no home folder in what was sent or shown"
44
45out=$(ask --error 'an error nobody has seen' --summary 'unknown' --wait 2 --approve 2>&1); rc=$?
46[ "$rc" = 4 ] && ok "an error nobody knows gets no answer (exit 4)" || bad "unknown error: rc=$rc: $out"
47
48KEY="AKIA$(printf 'IOSFODNN7EXAMPLE')"
49out=$(ask --error "$SAME" --summary "my key is $KEY" --wait 2 --approve 2>&1); rc=$?
50[ "$rc" != 0 ] && echo "$out" | grep -q 'Personal Data Firewall' && ok "a secret in the summary is refused before sending" || bad "secret: rc=$rc: $out"
51
52wait "$HELPER"; HELPER=
53grep -q 'answered: 1' "$T/helper.log" && ok "helper report: $(tail -1 "$T/helper.log")" || bad "helper log: $(cat "$T/helper.log")"
54grep -c 'carried' "$T/relay.log" > /dev/null && ok "relay log shows the request and the answer carried" || bad "relay log: $(cat "$T/relay.log")"
55grep -q 'declare foo' "$T/relay.log" && bad "the relay log holds the solution text" || ok "the relay never saw the solution text"
56
57
58# --- a second relay linked with the first, a lasting helper key, a checked answer ---
59BEACON_BIND=127.0.0.1 BEACON_PORT=$PORT2 BEACON_LINKS=127.0.0.1:$PORT "$BIN/beacon" > "$T/relay2.log" 2>&1 &
60RELAY2=$!
61BEACON_BIND=127.0.0.1 BEACON_PORT=$PORT2 BEACON_LINKS=not-an-address "$BIN/beacon" > "$T/badlink.log" 2>&1; rc=$?
62[ "$rc" = 2 ] && grep -q BEACON_LINKS "$T/badlink.log" && ok "a bad BEACON_LINKS stops a relay (exit 2)" || bad "bad link: rc=$rc"
63
64SEED=$("$OH" identity new | sed -n 's/^seed: *//p')
65pub() { "$OH" identity show --identity-cmd "echo $SEED" | sed -n 's/^public key: *//p'; }
66PUB=$(pub)
67[ ${#SEED} = 64 ] && [ ${#PUB} = 64 ] && [ "$PUB" = "$(pub)" ] && ok "a seed gives the same public key on every run" || bad "identity: seed ${#SEED} chars, key ${#PUB} chars"
68"$OH" identity show | grep -q 'No lasting identity' && ok "without a seed no lasting identity is claimed" || bad "identity show without a seed"
69
70OTHER='error[E0599]: no method named `bar` found'
71"$OH" teach --db "$T/helper2.sqlite" --topic rust-compilation --error "$OTHER" --solution 'call baz instead of bar' > /dev/null 2>&1
72"$OH" listen --db "$T/helper2.sqlite" --relay "127.0.0.1:$PORT2" --topics rust-compilation --for 9 --identity-cmd "echo $SEED" > "$T/helper2.log" 2>&1 &
73HELPER=$!
74sleep 1.5
75
76out=$(ask --error "$OTHER" --summary 'bar does not exist' --wait 5 --check 'grep -q baz solution.txt' --approve 2>&1); rc=$?
77[ "$rc" = 0 ] && echo "$out" | grep -q 'call baz instead of bar' \
78 && ok "asked at one relay, answered by a helper at the linked relay" || bad "linked ask: rc=$rc: $out"
79echo "$out" | grep -q "Answer from helper ${PUB:0:16}" && ok "the answer is signed with the helper's lasting key" || bad "helper key: $out"
80echo "$out" | grep -q 'check passed' && "$OH" peers --db "$T/asker.sqlite" | grep -q "^$PUB passed 1 failed 0" \
81 && ok "the check passed and counts for that helper" || bad "check: $out / $("$OH" peers --db "$T/asker.sqlite")"
82
83out=$(ask --error "$OTHER" --summary 'bar does not exist' --wait 5 --check 'false' --approve 2>&1)
84echo "$out" | grep -q 'check FAILED' && "$OH" peers --db "$T/asker.sqlite" | grep -q "^$PUB passed 1 failed 1" \
85 && ok "a failed check is not kept and counts against the helper" || bad "failed check: $out"
86wait "$HELPER"; HELPER=
87grep -q 'answered: 2' "$T/helper2.log" && ok "second helper report: $(tail -1 "$T/helper2.log")" || bad "second helper log: $(cat "$T/helper2.log")"
88
89echo "RESULT e2e pass=$pass fail=$fail"
90[ "$fail" = 0 ]