Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions script/install.d/01a-system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# -----------------------------------------------------------------------------
# Description:
# Configure system limits and parameters.
#

# Fix ENOSPC (Error No Space) issue for Node.js file watching
# This commonly occurs when development tools exceed inotify limits
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
current_limit=$(cat /proc/sys/fs/inotify/max_user_watches 2>/dev/null || echo "0")
recommended_limit=524288

if [ "$current_limit" -lt "$recommended_limit" ]; then
echo "Current inotify limit: $current_limit"
echo "Setting inotify limit to: $recommended_limit"

# Add to sysctl configuration if not already present
sysctl_config="/etc/sysctl.d/99-dotfiles.conf"
if ! grep -q "fs.inotify.max_user_watches" "$sysctl_config" 2>/dev/null; then
echo "fs.inotify.max_user_watches=$recommended_limit" | sudo tee -a "$sysctl_config" > /dev/null
echo "Added inotify configuration to $sysctl_config"
fi

# Apply the setting immediately
echo "$recommended_limit" | sudo tee /proc/sys/fs/inotify/max_user_watches > /dev/null

# Verify the change
new_limit=$(cat /proc/sys/fs/inotify/max_user_watches 2>/dev/null || echo "0")
echo "New inotify limit: $new_limit"
else
echo "inotify limit already sufficient: $current_limit"
fi
else
echo -e "${YELLOW}Skipping: inotify configuration not needed on $OSTYPE${NC}"
fi
57 changes: 57 additions & 0 deletions tests/test_system_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
#
# Test system configuration for ENOSPC fix
#
import subprocess
import pytest
import os


def test_inotify_limit_sufficient():
"""Test that inotify limit is set to prevent ENOSPC errors."""
if os.name != 'posix':
pytest.skip("inotify configuration only applies to Linux systems")

try:
with open('/proc/sys/fs/inotify/max_user_watches', 'r') as f:
current_limit = int(f.read().strip())
except (FileNotFoundError, ValueError):
pytest.skip("inotify configuration not available on this system")

# The minimum recommended limit to prevent ENOSPC errors
min_recommended_limit = 524288

assert current_limit >= min_recommended_limit, \
f"inotify limit ({current_limit}) is below recommended minimum ({min_recommended_limit}) to prevent ENOSPC"


def test_system_script_exists():
"""Test that the system configuration script exists and is executable."""
script_path = "/home/runner/work/dotfiles/dotfiles/script/install.d/01a-system.sh"

assert os.path.exists(script_path), "System configuration script does not exist"
assert os.access(script_path, os.X_OK), "System configuration script is not executable"


def test_system_script_runs_without_error():
"""Test that the system configuration script runs without errors."""
script_path = "/home/runner/work/dotfiles/dotfiles/script/install.d/01a-system.sh"

# Set environment to skip color codes for clean output
env = os.environ.copy()
env['TERM'] = 'dumb'

try:
result = subprocess.run(
['bash', script_path],
capture_output=True,
text=True,
timeout=30,
env=env
)

assert result.returncode == 0, \
f"System script failed with return code {result.returncode}. stderr: {result.stderr}"

except subprocess.TimeoutExpired:
pytest.fail("System script timed out")