mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 06:15:09 +00:00
* chore: stop tests and rigs writing to shared paths Two shared-state problems, both of which show up as a permanently dirty checkout or an unreproducible test failure. test_display_dirty_tracking.py builds a real DisplayManager, whose _snapshot_path defaults to the fixed /tmp/led_matrix_preview.png that the web UI reads. Every pytest process on the machine shares that one file, so two concurrent runs -- CI shards, a second worktree, an agent running the suite alongside -- overwrite each other's snapshot and the mtime assertions stop meaning anything. The module fixture now points it at a session-unique temp path; the individual tests that care still override it further. To be clear about what this does and does not fix: this is a real shared-path hazard, but it is NOT the cause of the intermittent 15-test failure in that module. That turned out to be the emulator's fixed TCP port, fixed in the follow-up commit. This change stands on its own merits. web_interface/app.py writes data/plugin_operations.json, data/plugin_state.json and data/operation_history.json as the web interface runs, into a directory that ships tracked (data/.gitkeep) and was otherwise unignored. So every rig that ever opened the web UI -- and every test run that constructs the app -- left three untracked files behind and a permanently dirty `git status`. Only data/.gitkeep is tracked under data/, so the negation keeps it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * test: stop the emulator binding a fixed port, so concurrent runs can't collide This is the cause of the intermittent full-suite failures we have been chasing: runs of identical code landing anywhere between 100 and 130 failures, while every implicated test passed in isolation. Six test modules set EMULATOR=true and build a real DisplayManager. The repo's emulator_config.json selects the "browser" adapter, which binds TCP port 8888 to serve the dev preview. That port is a machine-wide singleton, so a second pytest process -- a CI shard, another worktree, an agent running the suite alongside -- loses the bind. RGBMatrix construction then raises, DisplayManager catches it and falls back to `self.matrix = None`, and every test that subsequently touches the matrix dies with AttributeError: 'NoneType' object has no attribute 'SwapOnVSync' which names neither a port nor a socket, and points at the wrong file entirely. Because test_display_dirty_tracking's fixture is module-scoped, all 15 of its matrix-touching tests fail together or not at all -- the 15-test swing that made the totals look random. Demonstrated rather than assumed. Holding 0.0.0.0:8888 from a separate process and running test_display_dirty_tracking.py: without this change 15 failed, 6 passed with this change 21 passed The "raw" adapter renders in memory and binds nothing. Only display_adapter is overridden, in a throwaway config written per pytest process; the repo's emulator_config.json is untouched and `run.py -e` still opens the browser preview on 8888. Nothing in the suite referenced the adapter, and the tests wrap SwapOnVSync on the matrix object itself, so they are indifferent to what sits underneath. allow_adapter_fallback is forced off -- falling back would land us on the browser adapter and its fixed port, which is the whole problem. CONFIG_PATH is a bare relative filename resolved against the CWD, so it is set to an absolute path: the previous behaviour depended on where pytest was invoked from, and silently wrote a default config into whatever directory that was. Verified no regressions: full suite on this branch and with origin/main's versions of the touched files, same machine, back to back -- 115 failed / 4347 passed on both sides, zero failures unique to either. That 115 is the pre-existing Windows-environment baseline (POSIX file modes, fcntl, shell scripts, Linux-only binaries); CI on Linux remains authoritative. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: mark the shell entry points executable Eleven scripts shipped as 100644, so `./scripts/install/configure_web_sudo.sh` fails with "Permission denied" and only works if you know to prefix `bash`. That one matters most: the web UI's own error hint, added in #560, tells users to run exactly that path when a system action fails for want of passwordless sudo, and following that instruction verbatim did not work. All eleven carry a shebang and are invoked directly, never sourced. The two sourced libraries -- lib_lowmem.sh and lib_systemd_render.sh -- are deliberately left non-executable, which is what distinguishes a library from an entry point. Mode bits only, no content: 11 files changed, 0 insertions, 0 deletions. Applied with `git update-index --chmod=+x` because this checkout is on Windows, where core.fileMode is off and the working-tree bit is not tracked. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
168 lines
8.1 KiB
Bash
Executable File
168 lines
8.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Web Interface Diagnostic Script
|
|
# Run this on your Raspberry Pi to diagnose web interface issues
|
|
|
|
echo "╔══════════════════════════════════════════════════════════════╗"
|
|
echo "║ LED Matrix Web Interface Diagnostic Tool ║"
|
|
echo "╚══════════════════════════════════════════════════════════════╝"
|
|
echo ""
|
|
|
|
# Color codes for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Get script directory and project root (parent of scripts/)
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}1. SERVICE STATUS${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
if sudo systemctl is-active --quiet ledmatrix-web; then
|
|
echo -e "${GREEN}✓ Service is RUNNING${NC}"
|
|
sudo systemctl status ledmatrix-web --no-pager | head -n 15
|
|
else
|
|
echo -e "${RED}✗ Service is NOT RUNNING${NC}"
|
|
sudo systemctl status ledmatrix-web --no-pager | head -n 15
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}2. CONFIGURATION CHECK${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
|
|
# Check if config file exists
|
|
if [ -f "$PROJECT_DIR/config/config.json" ]; then
|
|
echo -e "${GREEN}✓ Config file found${NC}"
|
|
|
|
# Check web_display_autostart setting
|
|
AUTOSTART=$(grep -o '"web_display_autostart"[[:space:]]*:[[:space:]]*[a-z]*' "$PROJECT_DIR/config/config.json" | grep -o '[a-z]*$')
|
|
|
|
if [ "$AUTOSTART" == "true" ]; then
|
|
echo -e "${GREEN}✓ web_display_autostart: true${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠ web_display_autostart: ${AUTOSTART:-not set}${NC}"
|
|
echo -e "${YELLOW} Web interface will not start unless this is set to true${NC}"
|
|
fi
|
|
else
|
|
echo -e "${RED}✗ Config file not found at: $PROJECT_DIR/config/config.json${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}3. FILE STRUCTURE CHECK${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
|
|
# Check critical files
|
|
declare -a REQUIRED_FILES=(
|
|
"web_interface/app.py"
|
|
"web_interface/start.py"
|
|
"web_interface/requirements.txt"
|
|
"web_interface/blueprints/api_v3.py"
|
|
"web_interface/blueprints/pages_v3.py"
|
|
"scripts/utils/start_web_conditionally.py"
|
|
)
|
|
|
|
ALL_FILES_OK=true
|
|
for file in "${REQUIRED_FILES[@]}"; do
|
|
if [ -f "$PROJECT_DIR/$file" ]; then
|
|
echo -e "${GREEN}✓${NC} $file"
|
|
else
|
|
echo -e "${RED}✗${NC} $file ${RED}(MISSING)${NC}"
|
|
ALL_FILES_OK=false
|
|
fi
|
|
done
|
|
|
|
if [ "$ALL_FILES_OK" = true ]; then
|
|
echo -e "\n${GREEN}✓ All required files present${NC}"
|
|
else
|
|
echo -e "\n${RED}✗ Some files are missing - reorganization may be incomplete${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}4. PYTHON IMPORT TEST${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
|
|
# Test Python imports
|
|
echo -n "Testing Flask app import... "
|
|
IMPORT_OUTPUT=$(python3 -c "import sys; sys.path.insert(0, '$PROJECT_DIR'); from web_interface.app import app; print('OK')" 2>&1)
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}✓ SUCCESS${NC}"
|
|
else
|
|
echo -e "${RED}✗ FAILED${NC}"
|
|
echo -e "${RED}Error details:${NC}"
|
|
echo "$IMPORT_OUTPUT"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}5. NETWORK STATUS${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
|
|
# Check if port 5000 is in use
|
|
if sudo netstat -tlnp 2>/dev/null | grep -q ":5000 " || sudo ss -tlnp 2>/dev/null | grep -q ":5000 "; then
|
|
echo -e "${GREEN}✓ Port 5000 is in use (web interface may be running)${NC}"
|
|
if command -v netstat &> /dev/null; then
|
|
sudo netstat -tlnp | grep ":5000 "
|
|
else
|
|
sudo ss -tlnp | grep ":5000 "
|
|
fi
|
|
else
|
|
echo -e "${YELLOW}⚠ Port 5000 is not in use (web interface not listening)${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}6. RECENT SERVICE LOGS (Last 30 lines)${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
sudo journalctl -u ledmatrix-web -n 30 --no-pager
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}7. RECOMMENDATIONS${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
|
|
# Provide recommendations based on findings
|
|
if ! sudo systemctl is-active --quiet ledmatrix-web; then
|
|
echo -e "${YELLOW}→ Service is not running. Try:${NC}"
|
|
echo " sudo systemctl start ledmatrix-web"
|
|
fi
|
|
|
|
if [ "$AUTOSTART" != "true" ]; then
|
|
echo -e "${YELLOW}→ Enable web_display_autostart in config/config.json${NC}"
|
|
fi
|
|
|
|
if [ "$ALL_FILES_OK" = false ]; then
|
|
echo -e "${YELLOW}→ Some files are missing. You may need to:${NC}"
|
|
echo " - Check git status: git status"
|
|
echo " - Restore files: git checkout ."
|
|
echo " - Or re-run the reorganization"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN}QUICK COMMANDS:${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
echo "View live logs:"
|
|
echo " sudo journalctl -u ledmatrix-web -f"
|
|
echo ""
|
|
echo "Restart service:"
|
|
echo " sudo systemctl restart ledmatrix-web"
|
|
echo ""
|
|
echo "Test manual startup:"
|
|
echo " cd $PROJECT_DIR && python3 web_interface/start.py"
|
|
echo ""
|
|
echo "Check service status:"
|
|
echo " sudo systemctl status ledmatrix-web"
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
|