fix(cli/tests/dm): bind relay to 127.0.0.2 + dm-06 → --since filter
Two fixes needed to make the DM harness actually pass end-to-end:
1. Bind the loopback relay to 127.0.0.2 instead of 127.0.0.1.
Quartz's `RelayTag.parse` (called from `ChatMessageRelayListEvent.
relays()`) rejects any URL for which `isLocalHost()` returns true —
the substring check matches `"127.0.0.1"` among others. That means a
kind:10050 event whose `relay` tag reads `ws://127.0.0.1:8090/`
silently parses to an empty relay list, and `RecipientRelayFetcher`
reports `dmInbox == []`. Under strict mode `dm send` then correctly
refuses with `no_dm_relays` — hiding an otherwise-valid test setup.
`127.0.0.2` is the cleanest fix: still pure loopback (no network
traffic, no config needed), not matched by `isLocalHost()`, and
Linux binds any IP in 127.0.0.0/8 without setup. The Marmot harness
is unaffected because its tests never depend on parsing their own
kind:10051/10002 relay tags back out — they hit the bootstrap
fallback path.
marmot/setup.sh's `start_local_relay` now reads `${RELAY_HOST:-
127.0.0.1}` so both harnesses can share it; the DM harness sets
`RELAY_HOST=127.0.0.2` by default and exposes `--host` as an escape
hatch.
2. Replace dm-06 cursor-advance check with `--since` filter check.
The original assertion ("second no-flag `dm list` returns 0") was
wrong for the actual design: `filterGiftWrapsToPubkey` always
subtracts a 2-day lookback from `since` (required to catch NIP-59's
randomised `created_at`), so a repeat no-flag query legitimately
re-pulls everything in the last two days. The cursor advances the
scan window for efficiency, not for idempotency. dm-06 now verifies
`--since` actually filters: query with `--since <newest + 2 days +
1 hour>` — after the filter's lookback subtraction, the effective
floor lands past every message, and the list comes back empty.
Also: added `protoc` to the DM preflight checks so the missing-dep
error comes before 4 failed cargo retries.
Result on this machine: 6/6 pass, two clean runs in a row.
This commit is contained in:
@@ -27,11 +27,16 @@ AMY_BIN="$REPO_ROOT/cli/build/install/amy/bin/amy"
|
||||
# Share the nostr-rs-relay checkout with the Marmot harness to avoid
|
||||
# rebuilding it twice. Override RELAY_REPO / RELAY_DATA if you want full
|
||||
# isolation between runs.
|
||||
# Bind the loopback relay to 127.0.0.2 rather than 127.0.0.1 so Quartz's
|
||||
# `isLocalHost()` filter doesn't silently strip it out of the kind:10050
|
||||
# inbox events during recipient-relay resolution. 127.0.0.2 is still pure
|
||||
# loopback — no network traffic, no config needed.
|
||||
RELAY_HOST="${RELAY_HOST:-127.0.0.2}"
|
||||
RELAY_REPO="${RELAY_REPO:-$TESTS_DIR/marmot/state-headless/nostr-rs-relay}"
|
||||
RELAY_BIN="$RELAY_REPO/target/release/nostr-rs-relay"
|
||||
RELAY_DATA="$STATE_DIR/relay"
|
||||
RELAY_PORT="${RELAY_PORT:-8090}"
|
||||
RELAY_URL="ws://127.0.0.1:$RELAY_PORT"
|
||||
RELAY_URL="ws://$RELAY_HOST:$RELAY_PORT"
|
||||
NO_BUILD=0
|
||||
|
||||
A_NPUB=""
|
||||
@@ -41,7 +46,8 @@ D_HEX=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--port) RELAY_PORT="$2"; RELAY_URL="ws://127.0.0.1:$RELAY_PORT"; shift ;;
|
||||
--port) RELAY_PORT="$2"; RELAY_URL="ws://$RELAY_HOST:$RELAY_PORT"; shift ;;
|
||||
--host) RELAY_HOST="$2"; RELAY_URL="ws://$RELAY_HOST:$RELAY_PORT"; shift ;;
|
||||
--no-build) NO_BUILD=1 ;;
|
||||
-h|--help)
|
||||
sed -n '3,12p' "${BASH_SOURCE[0]}" | sed 's/^# \?//'
|
||||
@@ -97,4 +103,4 @@ test_02_dm_list_surfaces_history
|
||||
test_03_dm_send_rejects_no_inbox
|
||||
test_04_dm_send_allow_fallback
|
||||
test_05_dm_file_reference_round_trip
|
||||
test_06_dm_list_cursor_advance
|
||||
test_06_dm_list_since_filter
|
||||
|
||||
+27
-17
@@ -192,29 +192,39 @@ test_05_dm_file_reference_round_trip() {
|
||||
record_result "$id" pass
|
||||
}
|
||||
|
||||
test_06_dm_list_cursor_advance() {
|
||||
banner "DM-06 — no-flag dm list advances the giftWrapSince cursor"
|
||||
local id="dm-06 cursor advance"
|
||||
test_06_dm_list_since_filter() {
|
||||
banner "DM-06 — --since filters out older messages"
|
||||
local id="dm-06 since filter"
|
||||
|
||||
# First no-flag list: drains everything and advances the cursor to now.
|
||||
local first_out first_count
|
||||
first_out=$(amy_json_d dm list --timeout 5) || {
|
||||
record_result "$id" fail "first dm list failed"; return
|
||||
# Baseline: a --peer query (stateless) should surface every message so
|
||||
# far. We need at least one to have a meaningful window to slide past.
|
||||
local baseline baseline_count
|
||||
baseline=$(amy_json_d dm list --peer "$A_NPUB" --timeout 5) || {
|
||||
record_result "$id" fail "baseline dm list failed"; return
|
||||
}
|
||||
first_count=$(printf '%s' "$first_out" | jq -r '.messages | length')
|
||||
info "first dm list returned $first_count message(s)"
|
||||
baseline_count=$(printf '%s' "$baseline" | jq -r '.messages | length')
|
||||
info "baseline messages with A: $baseline_count"
|
||||
if [[ "$baseline_count" -lt 1 ]]; then
|
||||
record_result "$id" fail "no messages to filter — earlier tests didn't populate"; return
|
||||
fi
|
||||
|
||||
# Second no-flag list: nothing new should land.
|
||||
local second_out second_count
|
||||
second_out=$(amy_json_d dm list --timeout 5) || {
|
||||
record_result "$id" fail "second dm list failed"; return
|
||||
# Now query with --since set to a timestamp 2 days after the newest
|
||||
# message. filterGiftWrapsToPubkey subtracts its own two-day lookback
|
||||
# window, so the effective `since` lands right after the newest event
|
||||
# — nothing should come back.
|
||||
local newest
|
||||
newest=$(printf '%s' "$baseline" | jq -r '[.messages[].created_at] | max')
|
||||
local future=$(( newest + 2 * 24 * 60 * 60 + 3600 ))
|
||||
local after after_count
|
||||
after=$(amy_json_d dm list --peer "$A_NPUB" --since "$future" --timeout 5) || {
|
||||
record_result "$id" fail "since-query failed"; return
|
||||
}
|
||||
second_count=$(printf '%s' "$second_out" | jq -r '.messages | length')
|
||||
info "second dm list returned $second_count message(s)"
|
||||
after_count=$(printf '%s' "$after" | jq -r '.messages | length')
|
||||
info "after --since $future: $after_count message(s)"
|
||||
|
||||
if [[ "$first_count" -ge 1 && "$second_count" -eq 0 ]]; then
|
||||
if [[ "$after_count" -eq 0 ]]; then
|
||||
record_result "$id" pass
|
||||
else
|
||||
record_result "$id" fail "expected first>=1, second==0; got first=$first_count second=$second_count"
|
||||
record_result "$id" fail "expected 0 after future --since; got $after_count"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user