summaryrefslogtreecommitdiff
path: root/test/run-stream-wav-parity.sh
blob: 67c66e43edeef8a5f73624e86cee697da08a26b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# Stream-vs-WAV decode-parity harness.
#
# Asserts CONTAINMENT: every signal in a committed WAV-mode golden
# (test/fixtures/*.expected.txt) is also decoded by `jt9 --stream`. Streaming
# legitimately finds MORE (the early nzhsym passes pick up low-SNR signals; see
# run-streaming-fixtures.sh) so the relation is "WAV goldens are a subset of
# stream decodes", NOT equality. This is the rigorous regression guard the
# decode-affecting later phases (8, 9) depend on.
#
# Identity is the decoded MESSAGE text. Empirically snr/dt/freq drift between
# the WAV and stream decode paths for the SAME signal (snr ±2 dB, dt ±0.05 s,
# freq ±3 Hz on these fixtures — the streaming early passes compute slightly
# different fine estimates), so the harness shows them as diagnostics but the
# pass/fail hinges only on message-set containment.
#
# Scope: FT8 and JT9 ONLY (stated, not silently capped). FST4W has no
# known-good decoder fixture and the EME/JT65 I/Q paths are
# pass-on-absence, so neither can anchor a parity golden.
#
# A NEGATIVE CONTROL gate proves the harness can fail: a golden carrying one
# synthetic impossible signal MUST be reported as a parity failure. Without it,
# a green run cannot distinguish "containment held" from "harness never fails".
#
# Usage:
#   test/run-stream-wav-parity.sh [build-dir]
#
# Where build-dir defaults to ./build and must contain a built jt9 binary.

set -euo pipefail

BUILD_DIR="${1:-build}"
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
JT9="$REPO_ROOT/$BUILD_DIR/jt9"
HARNESS="$REPO_ROOT/test/wav_to_stream_harness.py"

if [[ ! -x "$JT9" ]]; then
  echo "ERROR: jt9 binary not found or not executable: $JT9" >&2
  exit 2
fi
if [[ ! -f "$HARNESS" ]]; then
  echo "ERROR: harness not found: $HARNESS" >&2
  exit 2
fi

echo "Stream-vs-WAV decode-parity (containment; FT8/JT9 only)"
echo "  jt9:     $JT9"
echo "  harness: $HARNESS"

fail=0

# Format: <wav-path> <jt9-mode-name> <golden-path>
fixtures=(
  "samples/FT8/210703_133430.wav FT8 test/fixtures/ft8_210703_133430.expected.txt"
  "samples/JT9/130418_1742.wav JT9 test/fixtures/jt9_130418_1742.expected.txt"
)

for entry in "${fixtures[@]}"; do
  read -r wav mode golden <<< "$entry"
  wav_path="$REPO_ROOT/$wav"
  golden_path="$REPO_ROOT/$golden"
  echo ""
  if [[ ! -f "$wav_path" ]]; then
    echo "  SKIP: $wav (sample not present)"
    continue
  fi
  if [[ ! -f "$golden_path" ]]; then
    echo "  SKIP: $golden (golden not present)"
    continue
  fi
  if python3 "$HARNESS" "$JT9" "$wav_path" --mode "$mode" --parity "$golden_path"; then
    echo "  PASS: $mode parity (WAV goldens are a subset of stream decodes)"
  else
    echo "  FAIL: $mode parity — a WAV-confirmed signal was dropped"
    fail=1
  fi
done

# --- Negative control: prove the harness can FAIL ---------------------------
echo ""
echo "Negative control — a golden with one impossible signal MUST fail parity"
ng_wav="$REPO_ROOT/samples/FT8/210703_133430.wav"
ng_src="$REPO_ROOT/test/fixtures/ft8_210703_133430.expected.txt"
if [[ -f "$ng_wav" && -f "$ng_src" ]]; then
  tmp="$(mktemp)"
  trap 'rm -f "$tmp"' EXIT
  cat "$ng_src" > "$tmp"
  # A syntactically valid WSJT-X decode line whose message this audio can
  # never produce. The parser must report it as a dropped (MISSING) signal.
  printf '133430  -5  0.0 1500 ~  ZZ9ZZZ NOTREAL XX99\n' >> "$tmp"
  if python3 "$HARNESS" "$JT9" "$ng_wav" --mode FT8 --parity "$tmp" >/dev/null 2>&1; then
    echo "  FAIL: harness reported parity OK on a golden with an impossible signal (cannot discriminate)"
    fail=1
  else
    echo "  PASS: harness correctly flagged the impossible signal as dropped"
  fi
  rm -f "$tmp"
  trap - EXIT

  # An empty/truncated golden must NOT pass vacuously (0 signals ⊆ anything is
  # trivially true). The harness must fail it loudly so a corrupt baseline is
  # caught rather than masking future regressions.
  echo ""
  echo "Negative control 2 — an EMPTY golden MUST fail parity (no vacuous pass)"
  empty="$(mktemp)"
  trap 'rm -f "$empty"' EXIT
  : > "$empty"   # zero-byte golden
  if python3 "$HARNESS" "$JT9" "$ng_wav" --mode FT8 --parity "$empty" >/dev/null 2>&1; then
    echo "  FAIL: harness reported parity OK on an empty golden (vacuous pass)"
    fail=1
  else
    echo "  PASS: harness correctly rejected the empty golden"
  fi
  rm -f "$empty"
  trap - EXIT
else
  echo "  SKIP: FT8 sample/golden not present for the negative control"
fi

echo ""
if [[ "$fail" -eq 0 ]]; then
  echo "All stream-vs-WAV parity checks passed."
else
  echo "One or more stream-vs-WAV parity checks FAILED."
  exit 1
fi