Repository navigation
test(portal): stop the offline stub test flaking on a cold npx cache #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)" | ||
|
|
@@ -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 | ||
|
|
@@ -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] \ | ||
|
|
@@ -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 | ||
| 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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.