#!/usr/bin/env bash # Deterministic transport-only contract tests; no live pane or model access. set -euo pipefail HERE=$(cd -- "$(dirname -- "$0")" && pwd) TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT mkdir "$TMP/bin" cat > "$TMP/bin/tmux" <<'FAKE' #!/usr/bin/env bash [ "${1:-}" != -L ] || shift 2 printf '%s\n' "$1" >> "$CALLS" case "$1" in display-message) [ "$FAIL_OP" != target ] || exit 1; printf '%%7\n' ;; load-buffer) cat > "$PAYLOAD"; [ "$FAIL_OP" != load ] || exit 1 ;; paste-buffer) [ "$FAIL_OP" != paste ] || exit 1 ;; send-keys) [ "$FAIL_OP" != key ] || exit 1 ;; capture-pane) echo 'ERROR: transport must not inspect application display' >&2; exit 99 ;; esac FAKE chmod +x "$TMP/bin/tmux" body=$'你好 transport\nsecond line' for mode in none target load paste key; do : > "$TMP/calls" set +e PATH="$TMP/bin:$PATH" CALLS="$TMP/calls" PAYLOAD="$TMP/payload" FAIL_OP="$mode" \ bash "$HERE/send-message.sh" -L isolated -t '=fixture' -r 999 -v -m "$body" > "$TMP/out" 2> "$TMP/err" rc=$? set -e expected=2; [ "$mode" != none ] || expected=0; [ "$mode" != target ] || expected=1 [ "$rc" -eq "$expected" ] ! grep -q capture-pane "$TMP/calls" keys=$(grep -c '^send-keys$' "$TMP/calls" || true) pastes=$(grep -c '^paste-buffer$' "$TMP/calls" || true) [ "$keys" -le 1 ] && [ "$pastes" -le 1 ] if [ "$mode" = none ]; then grep -qx 'transport dispatched; application acceptance unknown' "$TMP/out" [ "$keys" -eq 1 ] && [ "$pastes" -eq 1 ] [ "$(<"$TMP/payload")" = "$body" ] else ! grep -q 'transport dispatched' "$TMP/out" fi echo "PASS transport $mode exit=$rc paste=$pastes keys=$keys" done