-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun-integration-tests.sh
More file actions
executable file
Β·176 lines (151 loc) Β· 6.67 KB
/
run-integration-tests.sh
File metadata and controls
executable file
Β·176 lines (151 loc) Β· 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
# Run integration tests - orchestrates the complete test workflow
# This script mimics the GitHub Actions workflow for local execution
#
# By default, this script runs integration tests in BOTH modes:
# 1. Default mode (monitoring tools disabled) - tests the user experience
# 2. Monitoring mode (monitoring tools enabled) - tests session_* tools
#
# Environment Variables:
# MCP_MODE - MCP transport mode (default: stdio, also: http)
# HTTP_HOST - Server host for HTTP mode (default: localhost)
# HTTP_PORT - Server port for HTTP mode (default: 3000)
# TIMEOUT_SECONDS - Request timeout (default: 30)
# ENABLE_MONITORING_TOOLS - Force a specific mode instead of running both:
# "true" = only run with monitoring tools enabled
# "false" = only run with monitoring tools disabled
# unset = run BOTH modes (default)
#
# Usage:
# ./run-integration-tests.sh # Run in BOTH modes (recommended)
# ENABLE_MONITORING_TOOLS=false ./run-integration-tests.sh # Only default mode
# ENABLE_MONITORING_TOOLS=true ./run-integration-tests.sh # Only monitoring mode
# MCP_MODE=http ./run-integration-tests.sh # Run using HTTP transport
# ./run-integration-tests.sh --tools session_end # Filter to specific tools
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLIENT_DIR="$(dirname "$SCRIPT_DIR")"
SERVER_DIR="$(dirname "$CLIENT_DIR")/server"
# Set default environment variables
export MCP_MODE="${MCP_MODE:-stdio}"
export HTTP_HOST="${HTTP_HOST:-localhost}"
export HTTP_PORT="${HTTP_PORT:-3000}"
export TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-30}"
export URL_SCHEME="${URL_SCHEME:-http}"
# Determine which modes to run
# If ENABLE_MONITORING_TOOLS is explicitly set, run only that mode
# Otherwise, run both modes
RUN_DEFAULT_MODE=true
RUN_MONITORING_MODE=true
RUN_ANNOTATION_MODE=true
if [ -n "${ENABLE_MONITORING_TOOLS+x}" ]; then
# Variable is explicitly set (even if empty)
if [ "$ENABLE_MONITORING_TOOLS" = "true" ]; then
RUN_DEFAULT_MODE=false
RUN_MONITORING_MODE=true
RUN_ANNOTATION_MODE=false
echo "π§ Mode: Monitoring tools ONLY (ENABLE_MONITORING_TOOLS=true)"
else
RUN_DEFAULT_MODE=true
RUN_MONITORING_MODE=false
RUN_ANNOTATION_MODE=false
echo "π§ Mode: Default mode ONLY (ENABLE_MONITORING_TOOLS=false)"
fi
elif [ -n "${ENABLE_ANNOTATION_TOOLS+x}" ]; then
if [ "$ENABLE_ANNOTATION_TOOLS" = "true" ]; then
RUN_DEFAULT_MODE=false
RUN_MONITORING_MODE=false
RUN_ANNOTATION_MODE=true
echo "π§ Mode: Annotation tools ONLY (ENABLE_ANNOTATION_TOOLS=true)"
fi
else
echo "π§ Mode: Running ALL modes (default + monitoring + annotation)"
fi
# Check if --no-install-packs was passed
SKIP_PACK_INSTALL=false
for arg in "$@"; do
if [ "$arg" = "--no-install-packs" ]; then
SKIP_PACK_INSTALL=true
break
fi
done
echo "π Starting CodeQL MCP Integration Tests"
echo "MCP Mode: $MCP_MODE"
if [ "$MCP_MODE" = "http" ]; then
echo "Server URL: $URL_SCHEME://$HTTP_HOST:$HTTP_PORT/mcp"
fi
# Step 1: Build and bundle the server code
echo "π¦ Building CodeQL MCP server bundle..."
cd "$SERVER_DIR"
npm run rebuild:esbuild
npm run bundle
# Step 2: Install CodeQL packs (only once for both modes, skip if --no-install-packs)
if [ "$SKIP_PACK_INSTALL" = true ]; then
echo "π¦ Skipping CodeQL pack installation (--no-install-packs)"
else
echo "π¦ Installing CodeQL pack dependencies..."
"$SERVER_DIR/scripts/install-packs.sh"
fi
cd "$CLIENT_DIR"
# For HTTP mode, set the server URL for the client
if [ "$MCP_MODE" = "http" ]; then
export MCP_SERVER_URL="$URL_SCHEME://$HTTP_HOST:$HTTP_PORT/mcp"
fi
# Function to run tests in a specific mode
run_tests_in_mode() {
local mode_name="$1"
local enable_monitoring="$2"
shift 2
echo ""
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "π§ͺ Running integration tests: $mode_name"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
# Set the monitoring tools flag for this run
export ENABLE_MONITORING_TOOLS="$enable_monitoring"
if [ "$MCP_MODE" = "http" ]; then
# HTTP mode: start server in background, run tests, stop server
echo "π Starting MCP server (monitoring=$enable_monitoring)..."
"$SCRIPT_DIR/start-server.sh"
# Wait for server startup
echo "β³ Waiting for server startup..."
"$SCRIPT_DIR/wait-for-server.sh"
else
# stdio mode: client spawns server directly via StdioClientTransport
echo "π‘ Using stdio transport (client spawns server directly)"
fi
# Run the integration tests (skip pack installation since we already did it)
echo "π§ͺ Running tests..."
node src/ql-mcp-client.js integration-tests --no-install-packs "$@"
if [ "$MCP_MODE" = "http" ]; then
# Stop the server before next mode
echo "π Stopping server..."
"$SCRIPT_DIR/stop-server.sh"
fi
}
# Trap to ensure cleanup happens even if script fails
cleanup() {
echo "π§Ή Cleaning up..."
if [ "$MCP_MODE" = "http" ]; then
"$SCRIPT_DIR/stop-server.sh" 2>/dev/null || true
fi
}
trap cleanup EXIT
# Shift past any mode-specific args we've handled, pass rest to test runner
EXTRA_ARGS=("$@")
# Run tests in requested modes
if [ "$RUN_DEFAULT_MODE" = true ]; then
run_tests_in_mode "DEFAULT MODE (user experience)" "false" "${EXTRA_ARGS[@]}"
fi
if [ "$RUN_MONITORING_MODE" = true ]; then
run_tests_in_mode "MONITORING MODE (session_* tools)" "true" "${EXTRA_ARGS[@]}"
fi
if [ "$RUN_ANNOTATION_MODE" = true ]; then
# Annotation mode enables annotation, audit, and cache tools
export ENABLE_ANNOTATION_TOOLS="true"
run_tests_in_mode "ANNOTATION MODE (annotation_*, audit_*, query_results_cache_* tools)" "false" "${EXTRA_ARGS[@]}"
unset ENABLE_ANNOTATION_TOOLS
fi
echo ""
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β
All integration tests completed successfully!"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"