Files
tgcalls/tools/cli/run-negotiation-tests.sh
isaacandClaude Fable 5.1 120e384bbf v2: one-round negotiation and a DTLS-role backstop in 11.0.0
Two defects shared by every InstanceV2ReferenceImpl build, found in the
2026-10-11 Android log sample (getlogstgcalls/analysis/FINDINGS-android.md).

- Every call took two offer/answer rounds: both sides pre-create their audio
  transceiver with AddTransceiver, which FindAvailableTransceiverToReceive never
  associates with the caller's m=0, so the callee answered recvonly and
  re-offered its audio as a new m-section. network_reference_use_addtrack is
  now default on and covers the camera (addSendTransceiver): 2
  SetLocalDescription per call instead of 4, the callee's answer sendrecv, no
  glare window on every call. SetCodecPreferences is skipped on a transceiver
  AddTrack reused (it already has a mid; the peer negotiated its codec list).
- A rejected answer ("order of m-lines", the offer was replaced in flight) left
  the caller without a DTLS role, and it then answered the callee's colliding
  offer as a second DTLS client: handshake failure on a connected ICE path,
  every later SDP "Failed to set SSL role", no recovery (43 of 200 Android
  calls). sendLocalDescription() remembers that the peer answered setup:active
  and, when answering an offer in that state, sets passive on the created
  answer's transport descriptions and applies it from the CreateAnswer
  callback on the signaling thread, so nothing can land in between.

tools/cli: --video-late-caller-ms / --video-late-callee-ms attach one side's
camera N ms after start; network_reference_immediate_capture_renegotiation
(read only under TGCALLS_ALLOW_TEST_KNOBS, a CLI-only define) restores the
pre-2026-09-17 immediate offer so run-negotiation-tests.sh reproduces the
Android chain in-process. All four scenarios failed before and pass after;
mixed old/new pairings, mid-call cameras, mtproto and 30% signaling loss
checked.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-13 14:47:15 +04:00

69 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Negotiation regression tests for InstanceV2ReferenceImpl (11.0.0) on the in-process
# p2p harness. Each scenario runs one call and asserts on the engine log.
#
# ./submodules/TgVoipWebrtc/tgcalls/tools/cli/run-negotiation-tests.sh [path/to/tgcalls_cli]
#
# Scenarios:
# audio-one-round a plain call negotiates in ONE offer/answer: 2 SetLocalDescription in the
# whole log (one per side), 1 offer, the callee's answer sends audio.
# video-one-round the same with both cameras on at start.
# android-late-cam the Android app's shape: the caller's camera reaches the engine while its
# first offer is in flight and the engine offers immediately
# (network_reference_immediate_capture_renegotiation). The call must still
# connect, with no DTLS failure.
# android-glare as above, and the callee's camera lands right after it answered, so the
# callee re-offers while the caller's answer is being rejected and the caller
# has to answer the colliding offer without a DTLS role of its own.
set -u
CLI="${1:-./bazel-bin/submodules/TgVoipWebrtc/tgcalls/tools/cli/tgcalls_cli}"
if [ ! -x "$CLI" ]; then echo "no CLI at $CLI"; exit 2; fi
TMP="${TMPDIR:-/tmp}/tgcalls-negotiation-$$"; mkdir -p "$TMP"
fail=0
count() { grep -c -F -- "$1" "$2" 2>/dev/null || true; }
check() { # check <label> <actual> <expected>
if [ "$2" = "$3" ]; then echo " ok $1 = $2"; else echo " FAIL $1 = $2 (expected $3)"; fail=1; fi
}
run() { # run <name> <expected-exit> <cli args...>
local name="$1" wantExit="$2"; shift 2
local log="$TMP/$name.log" out="$TMP/$name.out"
echo "== $name"
"$CLI" --mode p2p --version 11.0.0 --duration 6 --log-file "$log" "$@" > "$out" 2>&1
local rc=$?
check "exit code" "$rc" "$wantExit"
LOG="$log"; OUT="$out"
}
IMMEDIATE='{"network_reference_immediate_capture_renegotiation":true}'
run audio-one-round 0
check "SetLocalDescription calls" "$(count 'Calling SetLocalDescription' "$LOG")" 2
check "offers sent" "$(count 'sendSignalingMessage: {"@type": "offer"' "$LOG")" 1
check "callee answer sends audio" "$(grep -F 'sendSignalingMessage: {"@type": "answer"' "$LOG" | grep -c 'a=sendrecv')" 1
run video-one-round 0 --video
check "SetLocalDescription calls" "$(count 'Calling SetLocalDescription' "$LOG")" 2
check "offers sent" "$(count 'sendSignalingMessage: {"@type": "offer"' "$LOG")" 1
check "SetLocalDescription failed" "$(count 'SetLocalDescription failed' "$LOG")" 0
check "video frames both ways" "$(grep -c 'Video frames: caller received [1-9][0-9]*, callee received [1-9]' "$OUT")" 1
run android-late-cam 0 --video-late-caller-ms 500 --delay 400-600 --custom-params "$IMMEDIATE"
check "DTLS transport error" "$(count 'DTLS transport error' "$LOG")" 0
check "Failed to set SSL role" "$(count 'Failed to set SSL role' "$LOG")" 0
check "callee received video" "$(grep -c 'Video frames: caller received [0-9]*, callee received [1-9]' "$OUT")" 1
# Timing (fixed 500 ms per signaling packet, so the SCTP handshake puts the first offer at the
# callee at ~2.5 s): the callee answers it at once and becomes the DTLS client; its camera at
# 2.8 s makes it re-offer before the caller's second offer (sent at 2.6 s, arriving ~3.1 s)
# lands, so that one is ignored as glare; the caller gets the stale answer (rejected, no role)
# and then the callee's offer, which it must answer as the DTLS server.
run android-glare 0 --duration 7 --video-late-caller-ms 2600 --video-late-callee-ms 2800 --delay 500-500 --custom-params "$IMMEDIATE" --custom-params2 "$IMMEDIATE"
check "DTLS transport error" "$(count 'DTLS transport error' "$LOG")" 0
check "Failed to set SSL role" "$(count 'Failed to set SSL role' "$LOG")" 0
check "video frames both ways" "$(grep -c 'Video frames: caller received [1-9][0-9]*, callee received [1-9]' "$OUT")" 1
if [ $fail = 0 ]; then echo "ALL PASS"; rm -rf "$TMP"; else echo "FAILURES (logs in $TMP)"; fi
exit $fail