#!/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 '

historic setup page

\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 '

current live page

\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 "\n\n\n\n\n\n\n\n\n\n\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 '(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 "None

' "$tmp/response" || { cat "$tmp/response"; exit 1; } printf "\n\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 "&2 exit 1 fi echo 'Dillo DPIP auth, socket lifecycle/EOF framing, versions, Scheme metadata, listing, stat, dashboard, unswarm/reload, quit: PASS'