Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions scripts/test-portal-bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,22 @@
#
# Exit codes:
# 0 = bridge accepted the CIMD URL and configured the 127.0.0.1 callback
# 1 = test infrastructure failure (stub didn't start, no TLS material, etc.)
# 1 = test infrastructure failure (stub didn't start, no TLS material, the
# bridge produced no output at all before the timeout, etc.)
# 2 = the bridge did not prove the client-metadata / callback configuration
#
# Bridge timeout (fixed 2026-10-21):
# The bridge step was hard-coded to 30s. `npx -y [email protected]` can
# spend longer than that resolving the package on a cold npx cache, and it
# writes nothing to stderr while it does. The bridge log was then empty and
# the assertion below reported exit 2 ("the bridge did not prove the
# configuration") when in reality the harness never gave the bridge a
# chance to prove anything. Observed on 2026-10-21: one cold run failed with
# a 0-byte bridge log, then three warm runs passed in 28s / 19s / 15s, so
# 30s sat right on the boundary. The timeout is now configurable
# (BRIDGE_TIMEOUT, default 120s) and an empty bridge log is classified as an
# infrastructure failure (exit 1) instead of a false assertion failure.
#
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
Expand All @@ -51,6 +64,15 @@ STUB_LOG="$WORK_DIR/stub.log"
BRIDGE_LOG="$WORK_DIR/bridge.log"
INIT_LOG="$WORK_DIR/init.log"
STUB_PID=""
# Cold `npx` resolution can take well over 30s and writes nothing meanwhile.
BRIDGE_TIMEOUT="${BRIDGE_TIMEOUT:-120}"
# GNU timeout treats 0 as "no deadline" and a non-integer is a usage error, so a
# stray BRIDGE_TIMEOUT could either hang forever or fail opaquely. Require a
# positive integer and fall back loudly rather than silently changing meaning.
if ! [[ "$BRIDGE_TIMEOUT" =~ ^[0-9]+$ ]] || (( BRIDGE_TIMEOUT < 1 )); then
echo "WARNING: BRIDGE_TIMEOUT='$BRIDGE_TIMEOUT' is not a positive integer; using 120s." >&2
BRIDGE_TIMEOUT=120
fi

cleanup() {
[[ -n "$STUB_PID" ]] && kill "$STUB_PID" 2>/dev/null || true
Expand Down Expand Up @@ -196,7 +218,12 @@ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":
# --host 127.0.0.1 must match the redirect_uri registered in the CIMD
# (the stub publishes 127.0.0.1; mcp-remote defaults to localhost on
# non-Windows). Fixed 2026-10-19.
timeout 30 bash -c "
# Capture the exit status. 124 is GNU timeout's "deadline reached" code. It is
# NOT swallowed: a timed-out bridge is an infrastructure failure even when it
# managed to write partial stderr before being killed, and without this the
# assertions below could mistake a truncated log for a real CIMD rejection.
BRIDGE_RC=0
timeout "$BRIDGE_TIMEOUT" bash -c "
cat '$WORK_DIR/init-request.json' | \
NODE_EXTRA_CA_CERTS='$TLS_DIR/cert.pem' \
npx -y [email protected] \
Expand All @@ -207,10 +234,33 @@ timeout 30 bash -c "
--host 127.0.0.1 \
--debug \
2>'$BRIDGE_LOG' > '$INIT_LOG'
" || true
" || BRIDGE_RC=$?

echo " Bridge exited (expected — no real MCP server or OAuth AS)"

if (( BRIDGE_RC == 124 )); then
echo "FAIL: the bridge hit the ${BRIDGE_TIMEOUT}s timeout (exit 124)."
echo " This is an infrastructure failure, not a CIMD rejection: a cold"
echo " \`npx -y [email protected]\` resolve writes nothing to stderr while"
echo " it downloads, so a truncated log is not evidence about the CIMD."
echo " Retry, or raise the budget: BRIDGE_TIMEOUT=300 $0"
exit 1
fi

# An empty bridge log means the harness never observed anything: a cold npx
# resolve, a crash before the first write, or a timeout kill. That is an
# infrastructure failure (exit 1), NOT evidence that the bridge rejected the
# client metadata document (exit 2). Classify it explicitly so a flaky cold
# start cannot masquerade as a real regression.
if [[ ! -s "$BRIDGE_LOG" ]]; then
Comment thread
codeant-ai[bot] marked this conversation as resolved.
Resolved
echo "FAIL: the bridge produced no output within ${BRIDGE_TIMEOUT}s."
echo " This is an infrastructure failure, not a CIMD rejection:"
echo " a cold \`npx -y [email protected]\` resolve can exceed the timeout"
echo " and writes nothing to stderr while it downloads."
echo " Retry, or raise the budget: BRIDGE_TIMEOUT=300 $0"
exit 1
fi

# mcp-remote must ACCEPT the client metadata document. If it ignored it
# (e.g. an http:// URL), the whole test would be vacuous.
CIMD_ACCEPTED=0
Expand Down
Loading