|
| 1 | +#!/bin/bash |
| 2 | +# Test: mcpc works under the Bun runtime |
| 3 | +# Skipped automatically if bun is not installed. |
| 4 | +# |
| 5 | +# When run standalone this sets MCPC to use bun directly. |
| 6 | +# When run via `./run.sh --runtime bun`, E2E_RUNTIME=bun is already set by the |
| 7 | +# runner and framework.sh picks it up; the explicit override below is a no-op. |
| 8 | + |
| 9 | +source "$(dirname "$0")/../../lib/framework.sh" |
| 10 | +test_init "basic/bun" |
| 11 | + |
| 12 | +# Skip entire test suite if bun is not available |
| 13 | +if ! command -v bun &>/dev/null; then |
| 14 | + echo "# Bun not installed, skipping" |
| 15 | + test_case "bun runtime (skipped - bun not installed)" |
| 16 | + test_skip "bun not installed" |
| 17 | + test_done |
| 18 | +fi |
| 19 | + |
| 20 | +BUN_VERSION=$(bun --version) |
| 21 | +echo "# Bun version: $BUN_VERSION" |
| 22 | + |
| 23 | +# Ensure all mcpc invocations in this file use bun (for standalone runs) |
| 24 | +MCPC="bun $PROJECT_ROOT/dist/cli/index.js" |
| 25 | + |
| 26 | +# Start test server (still uses Node/tsx - it's the remote MCP server, not the client) |
| 27 | +start_test_server |
| 28 | + |
| 29 | +# Test: --version works under Bun |
| 30 | +test_case "bun: --version works" |
| 31 | +run_mcpc --version |
| 32 | +assert_success |
| 33 | +if [[ ! "$STDOUT" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then |
| 34 | + test_fail "version should be semver format, got: $STDOUT" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | +test_pass |
| 38 | + |
| 39 | +# Test: --help works under Bun |
| 40 | +test_case "bun: --help works" |
| 41 | +run_mcpc --help |
| 42 | +assert_success |
| 43 | +assert_contains "$STDOUT" "Usage:" |
| 44 | +assert_contains "$STDOUT" "mcpc" |
| 45 | +test_pass |
| 46 | + |
| 47 | +# Test: --json output works under Bun |
| 48 | +test_case "bun: --version --json works" |
| 49 | +run_mcpc --version --json |
| 50 | +assert_success |
| 51 | +assert_json_valid "$STDOUT" |
| 52 | +assert_json "$STDOUT" '.version' |
| 53 | +test_pass |
| 54 | + |
| 55 | +# Test: tools-list via direct connection |
| 56 | +test_case "bun: tools-list (direct connection)" |
| 57 | +run_xmcpc "$TEST_SERVER_URL" tools-list |
| 58 | +assert_success |
| 59 | +assert_contains "$STDOUT" "echo" |
| 60 | +test_pass |
| 61 | + |
| 62 | +# Test: tools-call via direct connection |
| 63 | +test_case "bun: tools-call (direct connection)" |
| 64 | +run_mcpc "$TEST_SERVER_URL" tools-call echo 'message:=hello from bun' |
| 65 | +assert_success |
| 66 | +assert_contains "$STDOUT" "hello from bun" |
| 67 | +test_pass |
| 68 | + |
| 69 | +# Test: resources-list via direct connection |
| 70 | +test_case "bun: resources-list (direct connection)" |
| 71 | +run_xmcpc "$TEST_SERVER_URL" resources-list |
| 72 | +assert_success |
| 73 | +test_pass |
| 74 | + |
| 75 | +# Test: JSON mode via direct connection |
| 76 | +test_case "bun: tools-list --json (direct connection)" |
| 77 | +run_mcpc --json "$TEST_SERVER_URL" tools-list |
| 78 | +assert_success |
| 79 | +assert_json_valid "$STDOUT" |
| 80 | +test_pass |
| 81 | + |
| 82 | +# ============================================================================= |
| 83 | +# Keychain path: create a session with a bearer token. |
| 84 | +# mcpc stores the token in the OS keychain (via @napi-rs/keyring) on connect, |
| 85 | +# then reads it back on every subsequent command. This exercises the native |
| 86 | +# keyring add-on under the Bun runtime. |
| 87 | +# ============================================================================= |
| 88 | + |
| 89 | +test_case "bun: session with bearer token (keychain write)" |
| 90 | +SESSION=$(session_name "bearer") |
| 91 | +run_mcpc "$TEST_SERVER_URL" --header "Authorization: Bearer testtoken-bun-$$" connect "$SESSION" |
| 92 | +assert_success |
| 93 | +test_pass |
| 94 | + |
| 95 | +test_case "bun: session tools-list (keychain read)" |
| 96 | +run_xmcpc "$SESSION" tools-list |
| 97 | +assert_success |
| 98 | +assert_contains "$STDOUT" "echo" |
| 99 | +test_pass |
| 100 | + |
| 101 | +test_case "bun: session tools-call (keychain read)" |
| 102 | +run_mcpc "$SESSION" tools-call echo 'message:=hello from bun session' |
| 103 | +assert_success |
| 104 | +assert_contains "$STDOUT" "hello from bun session" |
| 105 | +test_pass |
| 106 | + |
| 107 | +test_case "bun: session close" |
| 108 | +run_mcpc "$SESSION" close |
| 109 | +assert_success |
| 110 | +test_pass |
| 111 | + |
| 112 | +test_done |
0 commit comments