fix: resolve Docker integration test failures in CI

Root cause analysis and fixes:

1. **MCP_MODE environment variable tests**
   - Issue: Tests were checking env vars after exec process replacement
   - Fix: Test actual HTTP server behavior instead of env vars
   - Changed tests to verify health endpoint responds in HTTP mode

2. **NODE_DB_PATH configuration tests**
   - Issue: Tests expected env var output but got initialization logs
   - Fix: Check process environment via /proc/1/environ
   - Added proper async handling for container startup

3. **Permission handling tests**
   - Issue: BusyBox sleep syntax and timing race conditions
   - Fix: Use detached containers with proper wait times
   - Check permissions after entrypoint completes

4. **Implementation improvements**
   - Export NODE_DB_PATH in entrypoint for visibility
   - Preserve env vars when switching to nodejs user
   - Add debug output option in n8n-mcp wrapper
   - Handle NODE_DB_PATH case preservation in parse-config.js

5. **Test infrastructure**
   - Created test-helpers.ts with proper async utilities
   - Use health checks instead of arbitrary sleep times
   - Test actual functionality rather than implementation details

These changes ensure tests verify the actual behavior (server running,
health endpoint responding) rather than checking internal implementation
details that aren't accessible after process replacement.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-07-31 14:08:21 +02:00
parent 8047297abc
commit 9cd5e42cb7
6 changed files with 131 additions and 27 deletions

View File

@@ -94,7 +94,8 @@ if [ "$(id -u)" = "0" ]; then
chown -R nodejs:nodejs /app/data
fi
# Switch to nodejs user with proper exec chain for signal propagation
exec su -s /bin/sh nodejs -c "exec $*"
# Preserve environment variables when switching user
exec su -s /bin/sh nodejs -c "export MCP_MODE='$MCP_MODE'; export NODE_DB_PATH='$NODE_DB_PATH'; export AUTH_TOKEN='$AUTH_TOKEN'; export AUTH_TOKEN_FILE='$AUTH_TOKEN_FILE'; exec $*"
fi
# Handle special commands
@@ -105,6 +106,11 @@ if [ "$1" = "n8n-mcp" ] && [ "$2" = "serve" ]; then
set -- node /app/dist/mcp/index.js "$@"
fi
# Export NODE_DB_PATH so it's visible to child processes
if [ -n "$DB_PATH" ]; then
export NODE_DB_PATH="$DB_PATH"
fi
# Execute the main command directly with exec
# This ensures our Node.js process becomes PID 1 and receives signals directly
if [ "$MCP_MODE" = "stdio" ]; then

View File

@@ -32,6 +32,11 @@ if [ "$1" = "serve" ]; then
# Validate remaining arguments
validate_args "$@"
# For testing purposes, output the environment variable if requested
if [ "$DEBUG_ENV" = "true" ]; then
echo "MCP_MODE=$MCP_MODE" >&2
fi
exec node /app/dist/mcp/index.js "$@"
else
# For non-serve commands, pass through without validation

View File

@@ -40,6 +40,11 @@ function sanitizeKey(key) {
return 'EMPTY_KEY';
}
// Special handling for NODE_DB_PATH to preserve exact casing
if (keyStr === 'NODE_DB_PATH') {
return 'NODE_DB_PATH';
}
const sanitized = keyStr
.toUpperCase()
.replace(/[^A-Z0-9]+/g, '_')