Files
dat-thang/tests/test_dpi.sh
T
divorce b735900f2e 0.0.002
ddat interop with dat js
cable interop with cabal js
ddat's frontend = dat-thang
cable fe = cable-thang
dillo support based on cel's dillo-dat
bootstrap node
xplatform support

Signed-off-by: divo <418@cryspace.space>
2026-10-19 00:17:02 -04:00

72 lines
4.6 KiB
Bash

#!/bin/sh
set -eu
dat_dpi=${1:-build/linux/dat.dpi}
dat=${2:-build/linux/dat}
socket_probe=${3:-build/linux/test_dpi_socket}
tmp=$(mktemp -d /tmp/datgpt-dpi.XXXXXX)
trap 'rm -rf "$tmp"' EXIT HUP INT TERM
export HOME="$tmp/home"
mkdir -p "$HOME/.dillo" "$tmp/archive/docs/adir" "$tmp/archive/docs/zdir"
printf '12345 abcdef1234567890\n' > "$HOME/.dillo/dpid_comm_keys"
"$dat" create "$tmp/archive" --yes >/dev/null
archive_address=$("$dat" url / "$tmp/archive")
printf '((title "Dillo parity") (description "Scheme metadata") (url "%s") (unsafe (begin (display "EXECUTED"))))\n' \
"$archive_address" > "$tmp/archive/dat.scm"
printf 'nested entry\n' > "$tmp/archive/docs/nested.txt"
printf 'a entry\n' > "$tmp/archive/docs/a.txt"
printf 'z entry\n' > "$tmp/archive/docs/z.txt"
printf '<h1>historic setup page</h1>\n' > "$tmp/archive/index.html"
"$dat" sync "$tmp/archive" >/dev/null
old_version=$("$dat" log "$tmp/archive" | awk '$NF == "index.html" { version = $1 } END { print version }')
old_address=$("$dat" url "$old_version" / "$tmp/archive")
printf '<h1>current live page</h1>\n' > "$tmp/archive/index.html"
"$dat" sync "$tmp/archive" >/dev/null
new_version=$("$dat" log "$tmp/archive" | awk '$NF == "index.html" { version = $1 } END { print version }')
new_address=$("$dat" url "$new_version" / "$tmp/archive")
latest_address=$("$dat" url / "$tmp/archive")
archive_root=${latest_address%/}
listing_address="${archive_root}/docs/"
parent_address="${archive_root}/docs/../"
stat_address="${archive_root}/index.html?stat=1"
key=$(od -An -vtx1 "$tmp/archive/.dat/metadata.key" | tr -d ' \n')
unswarm_address="dpi:/dat/?key=${key}&reload=dpi:/dat/&unswarm=unswarm"
cache="$HOME/.dillo/dat/archives/${key%${key#??}}/${key#??}"
mkdir -p "$cache"
cp -R "$tmp/archive/." "$cache/"
printf "<cmd='auth' msg='abcdef1234567890' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='dpi:/dat/' '>\n<cmd='open_url' url='%s' '>\n<cmd='open_url' url='dpi:/dat/' '>\n<cmd='DpiBye' '>\n" \
"$old_address" "$new_address" "$latest_address" "$listing_address" "$parent_address" "$stat_address" "$unswarm_address" |
"$dat_dpi" --stdio-test > "$tmp/response"
grep -q 'start_send_page' "$tmp/response" || { cat "$tmp/response"; exit 1; }
if grep -q '^HTTP/1\.[01] ' "$tmp/response"; then
cat "$tmp/response"
echo 'Dillo DPIP response must start with MIME headers, not an HTTP status line' >&2
exit 1
fi
grep -q 'historic setup page' "$tmp/response" || { cat "$tmp/response"; exit 1; }
grep -q 'current live page' "$tmp/response" || { cat "$tmp/response"; exit 1; }
test "$(grep -o 'current live page' "$tmp/response" | wc -l)" -eq 3
grep -q 'nested.txt' "$tmp/response" || { cat "$tmp/response"; exit 1; }
grep -q 'data:image/png;base64,' "$tmp/response" || { cat "$tmp/response"; exit 1; }
listing_order=$(grep -oE '<a href="[^"]+">(zdir|adir|z.txt|nested.txt|a.txt)' "$tmp/response" | sed -E 's/.*>(.*)$/\1/' | tr '\n' ' ')
test "$listing_order" = 'zdir adir z.txt nested.txt a.txt ' || { cat "$tmp/response"; exit 1; }
grep -q 'Dillo parity' "$tmp/response" || { cat "$tmp/response"; exit 1; }
if grep -q 'EXECUTED' "$tmp/response"; then cat "$tmp/response"; echo 'archive dat.scm was evaluated' >&2; exit 1; fi
grep -q '"directory": false' "$tmp/response" || { cat "$tmp/response"; exit 1; }
grep -q 'dpi:/dat/' "$tmp/response" || { cat "$tmp/response"; exit 1; }
grep -q "<cmd='reload_request' url='dpi:/dat/'" "$tmp/response" || { cat "$tmp/response"; exit 1; }
grep -q 'unswarming archive' "$tmp/response" || { cat "$tmp/response"; exit 1; }
grep -q '<p>None</p>' "$tmp/response" || { cat "$tmp/response"; exit 1; }
printf "<cmd='auth' msg='abcdef1234567890' '>\n<cmd='open_url' url='dpi:/dat/?quit=Quit' '>\n" |
"$dat_dpi" --stdio-test > "$tmp/quit-response"
grep -q 'Quitting' "$tmp/quit-response" || { cat "$tmp/quit-response"; exit 1; }
"$socket_probe" "$dat_dpi" "$latest_address" > "$tmp/socket-response"
grep -q "<cmd='start_send_page' url='" "$tmp/socket-response" || { cat "$tmp/socket-response"; exit 1; }
grep -q '^Content-Type: text/html' "$tmp/socket-response" || { cat "$tmp/socket-response"; exit 1; }
grep -q 'current live page' "$tmp/socket-response" || { cat "$tmp/socket-response"; exit 1; }
if grep -q '^Content-Length:' "$tmp/socket-response"; then
cat "$tmp/socket-response"
echo 'historical Dillo DPIP pages are terminated by closing the request socket, not Content-Length' >&2
exit 1
fi
echo 'Dillo DPIP auth, socket lifecycle/EOF framing, versions, Scheme metadata, listing, stat, dashboard, unswarm/reload, quit: PASS'