test: Fix and enhance MCP Claude headless flow smoke test

This commit resolves path resolution issues and correctly initializes
the MCP environment for testing the headless discovery pipeline.

Changes:
- Corrected REPO_ROOT calculation to accurately locate script artifacts.
- Implemented automatic MCP initialization via Admin interface:
    * Enabled MCP (mcp-enabled=true).
    * Disabled SSL (mcp-use_ssl=false) to avoid handshake issues in CI.
    * Registered a valid MCP target profile (mysql-127.0.0.1-13306).
    * Registered an authentication profile (default_mysql).
    * Properly loaded MCP variables and profiles into runtime.
- Updated static_harvest.sh invocation to use the unencrypted HTTP
  endpoint.
- Added extensive diagnostic logging to show exact command execution
  and intermediate results (Run IDs).
- Verified the end-to-end dry-run orchestration of the discovery
  pipeline.
pull/5420/head
Rene Cannao 2 months ago
parent 3b84b04616
commit f9a9f25349

@ -14,12 +14,13 @@ PLAN=6
DONE=0
FAIL=0
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
HEADLESS_DIR="${REPO_ROOT}/scripts/mcp/DiscoveryAgent/ClaudeCode_Headless"
STATIC_HARVEST="${HEADLESS_DIR}/static_harvest.sh"
TWO_PHASE="${HEADLESS_DIR}/two_phase_discovery.py"
TARGET_ID="${MCP_TARGET_ID:-tap_mysql_default}"
# Use actual target_id from local setup
TARGET_ID="${MCP_TARGET_ID:-mysql-127.0.0.1-13306}"
SCHEMA_NAME="${TEST_DB_NAME:-testdb}"
MCP_CONFIG_PATH="${TAP_CLAUDE_MCP_CONFIG:-${HEADLESS_DIR}/mcp_config.example.json}"
RUN_REAL_CLAUDE="${TAP_RUN_REAL_CLAUDE:-0}"
@ -58,6 +59,20 @@ echo "msg: # can be invoked with proper MCP target configuration."
echo "msg: # ==============================================="
echo "msg: #"
# Enable MCP via Admin
echo "msg: # Enabling MCP and registering targets via Admin interface..."
mysql -u admin -padmin -h 127.0.0.1 -P 6032 <<EOF
UPDATE global_variables SET variable_value='true' WHERE variable_name='mcp-enabled';
UPDATE global_variables SET variable_value='false' WHERE variable_name='mcp-use_ssl';
INSERT OR REPLACE INTO mcp_auth_profiles (auth_profile_id, db_username, db_password) VALUES ('default_mysql', 'root', 'root');
INSERT OR REPLACE INTO mcp_target_profiles (target_id, protocol, hostgroup_id, auth_profile_id) VALUES ('mysql-127.0.0.1-13306', 'mysql', 0, 'default_mysql');
EOF
mysql -u admin -padmin -h 127.0.0.1 -P 6032 -e "LOAD MCP VARIABLES TO RUNTIME"
mysql -u admin -padmin -h 127.0.0.1 -P 6032 -e "LOAD MCP PROFILES TO RUNTIME"
# Use HTTP instead of HTTPS since we disabled SSL
ENDPOINT="http://127.0.0.1:6071/mcp/query"
if [[ -x "${STATIC_HARVEST}" && -f "${TWO_PHASE}" ]]; then
tap_ok "Claude headless scripts exist"
else
@ -70,14 +85,16 @@ else
tap_not_ok "jq and python3 available" "jq/python3 required"
fi
static_out="$("${STATIC_HARVEST}" --target-id "${TARGET_ID}" --schema "${SCHEMA_NAME}" --notes "tap_claude_headless_flow" 2>&1 || true)"
echo "msg: # Executing: ${STATIC_HARVEST} --endpoint ${ENDPOINT} --target-id ${TARGET_ID} --schema ${SCHEMA_NAME}"
static_out="$("${STATIC_HARVEST}" --endpoint "${ENDPOINT}" --target-id "${TARGET_ID}" --schema "${SCHEMA_NAME}" --notes "tap_claude_headless_flow" 2>&1 || true)"
RUN_ID="$(echo "${static_out}" | sed -n 's/^Run ID:[[:space:]]*\([0-9][0-9]*\)$/\1/p' | head -n1)"
if [[ -n "${RUN_ID}" ]]; then
tap_ok "static_harvest.sh returns run id"
tap_ok "static_harvest.sh returns run id: ${RUN_ID}"
else
tap_not_ok "static_harvest.sh returns run id" "${static_out}"
fi
echo "msg: # Executing dry-run: python3 ${TWO_PHASE} --mcp-config ${MCP_CONFIG_PATH} --target-id ${TARGET_ID} --run-id ${RUN_ID} --dry-run"
dry_out="$(python3 "${TWO_PHASE}" --mcp-config "${MCP_CONFIG_PATH}" --target-id "${TARGET_ID}" --schema "${SCHEMA_NAME}" --run-id "${RUN_ID}" --dry-run 2>&1 || true)"
if echo "${dry_out}" | grep -q "\[DRY RUN\]" && echo "${dry_out}" | grep -q "Target ID: ${TARGET_ID}"; then
tap_ok "two_phase_discovery.py dry-run includes target_id and succeeds"

Loading…
Cancel
Save