Fahad
2025-10-21 11:06:18 +04:00
parent d5790a9bfe
commit d36489fdc9
2 changed files with 37 additions and 20 deletions

View File

@@ -35,6 +35,14 @@ readonly DESKTOP_CONFIG_FLAG=".desktop_configured"
readonly LOG_DIR="logs" readonly LOG_DIR="logs"
readonly LOG_FILE="mcp_server.log" readonly LOG_FILE="mcp_server.log"
# Determine portable arguments for sed -i (GNU vs BSD)
declare -a SED_INPLACE_ARGS
if sed --version >/dev/null 2>&1; then
SED_INPLACE_ARGS=(-i)
else
SED_INPLACE_ARGS=(-i "")
fi
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Utility Functions # Utility Functions
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@@ -1057,14 +1065,6 @@ setup_env_file() {
cp .env.example .env cp .env.example .env
print_success "Created .env from .env.example" print_success "Created .env from .env.example"
# Detect sed version for cross-platform compatibility
local sed_cmd
if sed --version >/dev/null 2>&1; then
sed_cmd="sed -i" # GNU sed (Linux)
else
sed_cmd="sed -i ''" # BSD sed (macOS)
fi
# Update API keys from environment if present # Update API keys from environment if present
local api_keys=( local api_keys=(
"GEMINI_API_KEY:your_gemini_api_key_here" "GEMINI_API_KEY:your_gemini_api_key_here"
@@ -1080,7 +1080,7 @@ setup_env_file() {
local key_value="${!key_name:-}" local key_value="${!key_name:-}"
if [[ -n "$key_value" ]]; then if [[ -n "$key_value" ]]; then
$sed_cmd "s/$placeholder/$key_value/" .env sed "${SED_INPLACE_ARGS[@]}" "s/$placeholder/$key_value/" .env
print_success "Updated .env with $key_name from environment" print_success "Updated .env with $key_name from environment"
fi fi
done done
@@ -1100,16 +1100,8 @@ migrate_env_file() {
# Create backup # Create backup
cp .env .env.backup_$(date +%Y%m%d_%H%M%S) cp .env .env.backup_$(date +%Y%m%d_%H%M%S)
# Detect sed version for cross-platform compatibility
local sed_cmd
if sed --version >/dev/null 2>&1; then
sed_cmd="sed -i" # GNU sed (Linux)
else
sed_cmd="sed -i ''" # BSD sed (macOS)
fi
# Replace host.docker.internal with localhost # Replace host.docker.internal with localhost
$sed_cmd 's/host\.docker\.internal/localhost/g' .env sed "${SED_INPLACE_ARGS[@]}" 's/host\.docker\.internal/localhost/g' .env
print_success "Migrated Docker URLs to localhost in .env" print_success "Migrated Docker URLs to localhost in .env"
echo " (Backup saved as .env.backup_*)" echo " (Backup saved as .env.backup_*)"
@@ -2499,5 +2491,6 @@ main() {
# Script Entry Point # Script Entry Point
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Run main function with all arguments if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@" main "$@"
fi

View File

@@ -4,6 +4,7 @@ This test file ensures our pip detection improvements work correctly
and don't break existing functionality. and don't break existing functionality.
""" """
import os
import subprocess import subprocess
import tempfile import tempfile
from pathlib import Path from pathlib import Path
@@ -99,6 +100,29 @@ class TestPipDetectionFix:
for pattern in expected_diagnostic_patterns: for pattern in expected_diagnostic_patterns:
assert pattern in content, f"Enhanced diagnostic pattern '{pattern}' should be in script" assert pattern in content, f"Enhanced diagnostic pattern '{pattern}' should be in script"
def test_setup_env_file_does_not_create_bsd_backup(self, tmp_path):
"""Ensure setup_env_file avoids creating .env'' artifacts (BSD sed behavior)."""
script_path = Path("./run-server.sh").resolve()
# Prepare temp workspace with example env
env_example = Path(".env.example").read_text()
target_example = tmp_path / ".env.example"
target_example.write_text(env_example)
# Run setup_env_file inside isolated shell session
command = f"""
set -e
cd "{tmp_path}"
source "{script_path}"
setup_env_file
"""
env = os.environ.copy()
subprocess.run(["bash", "-lc", command], check=True, env=env, text=True)
artifacts = {p.name for p in tmp_path.glob(".env*")}
assert ".env''" not in artifacts, "setup_env_file should not create BSD sed backup artifacts"
assert ".env" in artifacts, ".env should be created from .env.example"
if __name__ == "__main__": if __name__ == "__main__":
pytest.main([__file__, "-v"]) pytest.main([__file__, "-v"])