Add --check command for configuration and connectivity validation

Adds `python -m app --check` which verifies:
- All required environment variables are set
- Matrix homeserver is reachable
- Bot access token is valid
- Bot is a member of the announcements room
- Database path is writable

Uses color-coded pass/fail output with actionable hints on failure.
Configures nio with a 10-second timeout and no retries so checks
complete quickly even against unreachable servers.

https://claude.ai/code/session_01DuzWyMMXvLMB4VxEwJyV4X
This commit is contained in:
Claude
2026-02-28 08:06:24 +00:00
parent 8a2ce2a480
commit d636b9ed0e
3 changed files with 230 additions and 2 deletions

View File

@@ -30,17 +30,30 @@ cp .env.example .env
Edit `.env` with your actual values (see [Environment Variables](#environment-variables) below).
### 2. Run locally
### 2. Verify your configuration
```bash
pip install -r requirements.txt
python -m app --check
```
This validates that all required environment variables are set, the Matrix homeserver is reachable, the bot token is valid, the bot has joined the announcements room, and the database path is writable. Fix any failing checks before starting the server.
### 3. Run locally
```bash
uvicorn app.main:app --host 0.0.0.0 --port 8000
```
### 3. Run with Docker
### 4. Run with Docker
```bash
docker build -t melora .
# Verify configuration first
docker run --rm --env-file .env melora python -m app --check
# Start the service
docker run -d \
--name melora \
--env-file .env \
@@ -220,7 +233,9 @@ Messages include both plain text and HTML (Matrix-flavored Markdown). New additi
Melora/
├── app/
│ ├── __init__.py
│ ├── __main__.py # CLI entry point (--check flag)
│ ├── main.py # FastAPI app, lifespan, startup
│ ├── check.py # Configuration and connectivity checker
│ ├── config.py # Environment variable loading
│ ├── database.py # Async SQLite for thread roots and dedup
│ ├── matrix.py # matrix-nio posting and thread management