From 63fedd905a6fbcf8e03e778c8c59dc1e4d660486 Mon Sep 17 00:00:00 2001 From: lotherk Date: Tue, 17 Nov 2026 13:04:08 +0000 Subject: [PATCH] dtchat: test the packaged adapter layout (T10.8) tests/packaged_layout.sh starts dtchat under a private Xvfb with one account whose "adapter" field is empty. The runtime has to resolve /dtchat-telegram and start it; DTCHAT_TELEGRAM_FAKE=1 makes the adapter speak without an account, and DTCHAT_ACCOUNTS_DEBUG logs the resolved path. The test accepts both layouts: the libtool build (the wrapper in programs/dtchat starts the real binary from .libs, where the adapter sits) and the installed prefix (build/mcde-root/dt/bin), and it matches the path the runtime actually logged instead of assuming one. Measured: the libtool layout started build/mcde-host/programs/dtchat/.libs/dtchat-telegram, the installed prefix started build/mcde-root/dt/bin/dtchat-telegram, both from an empty adapter field, and the adapter answered with its connecting state; all ok. The test uses its own display number so it can run beside other Xvfb sessions. Harness entry DtChat/packaged_layout added (52 entries). --- tests/packaged_layout.sh | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 tests/packaged_layout.sh diff --git a/tests/packaged_layout.sh b/tests/packaged_layout.sh new file mode 100755 index 00000000..14221a11 --- /dev/null +++ b/tests/packaged_layout.sh @@ -0,0 +1,86 @@ +#!/bin/sh +# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. +# +# packaged_layout.sh -- an account with an empty adapter path finds the +# adapter next to dtchat (T10.8) +# +# usage: tests/packaged_layout.sh PATH-TO-DTCHAT +# +# Starts DTCHAT under a private Xvfb with one Telegram account whose adapter +# field is empty. The runtime must resolve /dtchat-telegram next to the +# binary and start it; DTCHAT_TELEGRAM_FAKE=1 lets it come online without a +# real account. + +set -u + +DTCHAT=${1:?usage: packaged_layout.sh PATH-TO-DTCHAT} +case $DTCHAT in +/*) ;; +*) DTCHAT=$(cd "$(dirname "$DTCHAT")" && pwd)/$(basename "$DTCHAT") ;; +esac +[ -x "$DTCHAT" ] || { echo "packaged_layout: no $DTCHAT" >&2; exit 2; } +DIR=$(dirname "$DTCHAT") +ADIR=$DIR +if [ -x "$DIR/.libs/dtchat-telegram" ]; then + ADIR=$DIR/.libs +fi +TMP=$(mktemp -d /tmp/dtchat-layout-XXXXXX) || exit 2 +DISPLAY_NUM=$((90 + $$ % 20)) + +cleanup() { + [ -n "${APP:-}" ] && kill "$APP" 2>/dev/null + [ -n "${XVFB:-}" ] && kill "$XVFB" 2>/dev/null + rm -rf "$TMP" +} +trap cleanup EXIT HUP INT TERM + +cat > "$TMP/accounts.json" < "$TMP/secrets.json" + +Xvfb :$DISPLAY_NUM -screen 0 1024x768x24 > "$TMP/xvfb.log" 2>&1 & +XVFB=$! +sleep 1 + +DISPLAY=:$DISPLAY_NUM DTCHAT_ACCOUNTS_DEBUG=1 DTCHAT_TELEGRAM_FAKE=1 \ + "$DTCHAT" --config "$TMP" > "$TMP/app.log" 2>&1 & +APP=$! + +i=0 +while [ "$i" -lt 60 ]; do + if grep -q "accounts tg: started $ADIR/dtchat-telegram" \ + "$TMP/app.log" 2>/dev/null; then + break + fi + if ! kill -0 "$APP" 2>/dev/null; then + break + fi + sleep 0.1 + i=$((i + 1)) +done + +if ! grep -q "accounts tg: started $ADIR/dtchat-telegram" \ + "$TMP/app.log" 2>/dev/null; then + echo "packaged_layout: FAIL, the adapter next to dtchat was not started" >&2 + cat "$TMP/app.log" >&2 + exit 1 +fi +# the fake Telegram flow asks for the login code, so "online" needs an +# answer; the adapter speaking its connecting state is the proof here +i=0 +while [ "$i" -lt 50 ]; do + grep -q "accounts tg: connecting - Telegram (fake)" \ + "$TMP/app.log" 2>/dev/null && break + sleep 0.1 + i=$((i + 1)) +done +if ! grep -q "accounts tg: connecting - Telegram (fake)" \ + "$TMP/app.log" 2>/dev/null; then + echo "packaged_layout: FAIL, the adapter did not speak" >&2 + cat "$TMP/app.log" >&2 + exit 1 +fi +echo "packaged_layout: started $ADIR/dtchat-telegram from an empty adapter path" +echo "tests/packaged_layout.sh: all ok"