feat: Implement v1.1.1 Phase 1 - Core Infrastructure
Phase 1 of v1.1.1 "Polish" release focusing on production readiness. Implements logging, connection pooling, validation, and error handling. Following specs in docs/design/v1.1.1/developer-qa.md and ADRs 052-055. **Structured Logging** (Q3, ADR-054) - RotatingFileHandler (10MB files, keep 10) - Correlation IDs for request tracing - All print statements replaced with logging - Context-aware correlation IDs (init/request) - Logs written to data/logs/starpunk.log **Database Connection Pooling** (Q2, ADR-053) - Connection pool with configurable size (default: 5) - Request-scoped connections via Flask g object - Pool statistics for monitoring - WAL mode enabled for concurrency - Backward compatible get_db() signature **Configuration Validation** (Q14, ADR-052) - Validates presence and type of all config values - Fail-fast startup with clear error messages - LOG_LEVEL enum validation - Type checking for strings, integers, paths - Non-zero exit status on errors **Centralized Error Handling** (Q4, ADR-055) - Moved handlers to starpunk/errors.py - Micropub spec-compliant JSON errors - HTML templates for browser requests - All errors logged with correlation IDs - MicropubError exception class **Database Module Reorganization** - Moved database.py to database/ package - Separated init.py, pool.py, schema.py - Maintains backward compatibility - Cleaner separation of concerns **Testing** - 580 tests passing - 1 pre-existing flaky test noted - No breaking changes to public API **Documentation** - CHANGELOG.md updated with v1.1.1 entry - Version bumped to 1.1.1 - Implementation report in docs/reports/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -111,6 +111,12 @@ def validate_config(app):
|
||||
"""
|
||||
Validate application configuration on startup
|
||||
|
||||
Per ADR-052 and developer Q&A Q14:
|
||||
- Validates at startup (fail fast)
|
||||
- Checks both presence and type of required values
|
||||
- Provides clear error messages
|
||||
- Exits with non-zero status on failure
|
||||
|
||||
Ensures required configuration is present based on mode (dev/production)
|
||||
and warns prominently if development mode is enabled.
|
||||
|
||||
@@ -118,8 +124,60 @@ def validate_config(app):
|
||||
app: Flask application instance
|
||||
|
||||
Raises:
|
||||
ValueError: If required configuration is missing
|
||||
ValueError: If required configuration is missing or invalid
|
||||
"""
|
||||
errors = []
|
||||
|
||||
# Validate required string fields
|
||||
required_strings = {
|
||||
'SITE_URL': app.config.get('SITE_URL'),
|
||||
'SITE_NAME': app.config.get('SITE_NAME'),
|
||||
'SITE_AUTHOR': app.config.get('SITE_AUTHOR'),
|
||||
'SESSION_SECRET': app.config.get('SESSION_SECRET'),
|
||||
'SECRET_KEY': app.config.get('SECRET_KEY'),
|
||||
}
|
||||
|
||||
for field, value in required_strings.items():
|
||||
if not value:
|
||||
errors.append(f"{field} is required but not set")
|
||||
elif not isinstance(value, str):
|
||||
errors.append(f"{field} must be a string, got {type(value).__name__}")
|
||||
|
||||
# Validate required integer fields
|
||||
required_ints = {
|
||||
'SESSION_LIFETIME': app.config.get('SESSION_LIFETIME'),
|
||||
'FEED_MAX_ITEMS': app.config.get('FEED_MAX_ITEMS'),
|
||||
'FEED_CACHE_SECONDS': app.config.get('FEED_CACHE_SECONDS'),
|
||||
}
|
||||
|
||||
for field, value in required_ints.items():
|
||||
if value is None:
|
||||
errors.append(f"{field} is required but not set")
|
||||
elif not isinstance(value, int):
|
||||
errors.append(f"{field} must be an integer, got {type(value).__name__}")
|
||||
elif value < 0:
|
||||
errors.append(f"{field} must be non-negative, got {value}")
|
||||
|
||||
# Validate required Path fields
|
||||
required_paths = {
|
||||
'DATA_PATH': app.config.get('DATA_PATH'),
|
||||
'NOTES_PATH': app.config.get('NOTES_PATH'),
|
||||
'DATABASE_PATH': app.config.get('DATABASE_PATH'),
|
||||
}
|
||||
|
||||
for field, value in required_paths.items():
|
||||
if not value:
|
||||
errors.append(f"{field} is required but not set")
|
||||
elif not isinstance(value, Path):
|
||||
errors.append(f"{field} must be a Path object, got {type(value).__name__}")
|
||||
|
||||
# Validate LOG_LEVEL
|
||||
log_level = app.config.get('LOG_LEVEL', 'INFO').upper()
|
||||
valid_log_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
|
||||
if log_level not in valid_log_levels:
|
||||
errors.append(f"LOG_LEVEL must be one of {valid_log_levels}, got '{log_level}'")
|
||||
|
||||
# Mode-specific validation
|
||||
dev_mode = app.config.get("DEV_MODE", False)
|
||||
|
||||
if dev_mode:
|
||||
@@ -133,14 +191,29 @@ def validate_config(app):
|
||||
|
||||
# Require DEV_ADMIN_ME in dev mode
|
||||
if not app.config.get("DEV_ADMIN_ME"):
|
||||
raise ValueError(
|
||||
errors.append(
|
||||
"DEV_MODE=true requires DEV_ADMIN_ME to be set. "
|
||||
"Set DEV_ADMIN_ME=https://your-dev-identity.example.com in .env"
|
||||
)
|
||||
else:
|
||||
# Production mode: ADMIN_ME is required
|
||||
if not app.config.get("ADMIN_ME"):
|
||||
raise ValueError(
|
||||
errors.append(
|
||||
"Production mode requires ADMIN_ME to be set. "
|
||||
"Set ADMIN_ME=https://your-site.com in .env"
|
||||
)
|
||||
|
||||
# If there are validation errors, fail fast with clear message
|
||||
if errors:
|
||||
error_msg = "\n".join([
|
||||
"=" * 70,
|
||||
"CONFIGURATION VALIDATION FAILED",
|
||||
"=" * 70,
|
||||
"The following configuration errors were found:",
|
||||
"",
|
||||
*[f" - {error}" for error in errors],
|
||||
"",
|
||||
"Please fix these errors in your .env file and restart.",
|
||||
"=" * 70
|
||||
])
|
||||
raise ValueError(error_msg)
|
||||
|
||||
Reference in New Issue
Block a user