Fixes the group id parsing

This commit is contained in:
Vitor Pamplona
2026-04-20 12:23:46 -04:00
parent 4ccabb01e6
commit 9766cc5901
2 changed files with 37 additions and 8 deletions
+29 -2
View File
@@ -143,6 +143,33 @@ expect_contains() {
return 1
}
# ------- JSON helpers --------------------------------------------------------
# Extract MLS group ID as lowercase hex from wn JSON output.
# Handles both formats:
# - plain hex string (from `groups list`)
# - {"value":{"vec":[...]}} serde struct (from `groups create`)
# - flat byte array [n, ...] (from some responses)
# Input: JSON string via stdin; optional 2nd arg = field name (default: mls_group_id)
jq_group_id() {
local field="${1:-mls_group_id}"
jq -r --arg f "$field" '
def byte2hex:
. as $n |
[($n / 16 | floor), ($n % 16)] |
map(if . < 10 then (48 + .) else (87 + .) end) |
implode;
(.result // .) |
.[$f] |
if type == "string" then .
elif (type == "object" and (.value.vec != null)) then
[.value.vec[] | byte2hex] | join("")
elif type == "array" then
[.[] | byte2hex] | join("")
else empty end
' 2>/dev/null || true
}
# ------- polling helpers -----------------------------------------------------
# wait_for_invite <B|C> <timeout-seconds>
@@ -154,10 +181,10 @@ wait_for_invite() {
while [[ $(date +%s) -lt $deadline ]]; do
if [[ "$who" == "B" ]]; then
gid=$(wn_b_json groups invites 2>/dev/null \
| jq -r '.[0].group_id // .[0].mls_group_id // empty' 2>/dev/null || true)
| jq -c '.[0] // empty' 2>/dev/null | jq_group_id || true)
else
gid=$(wn_c_json groups invites 2>/dev/null \
| jq -r '.[0].group_id // .[0].mls_group_id // empty' 2>/dev/null || true)
| jq -c '.[0] // empty' 2>/dev/null | jq_group_id || true)
fi
if [[ -n "${gid:-}" ]]; then
printf '%s\n' "$gid"
+8 -6
View File
@@ -379,7 +379,7 @@ test_03_wn_creates_group() {
local out gid
out=$(wn_b --json groups create "Interop-03" "$A_NPUB" 2>>"$LOG_FILE")
printf 'wn groups create raw output: %s\n' "$out" >>"$LOG_FILE"
gid=$(printf '%s' "$out" | jq -r '.group_id // .mls_group_id // empty' 2>/dev/null || true)
gid=$(printf '%s' "$out" | jq_group_id)
if [[ -z "$gid" ]]; then
fail_msg "could not parse group_id from 'wn groups create' output"
info "raw output: $out"
@@ -425,7 +425,7 @@ test_04_three_member_group() {
warn "GROUP_02 not set (Test 02 likely skipped/failed); creating new group here"
local out
out=$(wn_b --json groups create "Interop-04-bootstrap" "$A_NPUB" 2>>"$LOG_FILE")
gid=$(printf '%s' "$out" | jq -r '.group_id // .mls_group_id // empty' 2>/dev/null || true)
gid=$(printf '%s' "$out" | jq_group_id)
save_state GROUP_02 "$gid"
prompt_human "In Amethyst, accept the new group invite 'Interop-04-bootstrap'."
fi
@@ -469,8 +469,9 @@ test_05_wn_adds_amethyst_existing() {
step "B creates group with only C, then adds A"
local out gid
out=$(wn_b --json groups create "Interop-05" "$C_NPUB" 2>&1 | tee -a "$LOG_FILE")
gid=$(printf '%s' "$out" | jq -r '.group_id // .mls_group_id // empty')
out=$(wn_b --json groups create "Interop-05" "$C_NPUB" 2>>"$LOG_FILE")
printf 'wn groups create raw output: %s\n' "$out" >>"$LOG_FILE"
gid=$(printf '%s' "$out" | jq_group_id)
if [[ -z "$gid" ]]; then
fail_msg "could not create Interop-05"
record_result "05 wn adds Amethyst existing" fail "create failed"
@@ -748,8 +749,9 @@ test_12_offline_catchup() {
wn_c keys publish >/dev/null 2>&1 || true
sleep 3
local out gid
out=$(wn_b --json groups create "Interop-12" "$A_NPUB" 2>&1 | tee -a "$LOG_FILE")
gid=$(printf '%s' "$out" | jq -r '.group_id // .mls_group_id // empty')
out=$(wn_b --json groups create "Interop-12" "$A_NPUB" 2>>"$LOG_FILE")
printf 'wn groups create raw output: %s\n' "$out" >>"$LOG_FILE"
gid=$(printf '%s' "$out" | jq_group_id)
if [[ -z "$gid" ]]; then
fail_msg "could not create Interop-12"; record_result "12 offline catchup" fail "create failed"; return
fi