Refactor configuration handling and improve error management across services; normalize placeholder values for SMTP and Stripe configurations; enhance local storage fallback logic in StorageService; add tests for new behaviors and edge cases.

This commit is contained in:
Your Name
2026-03-26 14:15:10 +02:00
parent 688d411537
commit bc8a5dc290
19 changed files with 423 additions and 95 deletions

View File

@@ -0,0 +1,31 @@
"""Helpers for treating sample config values as missing runtime configuration."""
import re
_MASKED_SEQUENCE_RE = re.compile(r"(x{6,}|\*{4,})", re.IGNORECASE)
def normalize_optional_config(
value: str | None,
placeholder_markers: tuple[str, ...] = (),
) -> str:
"""Return a stripped config value, or blank when it still looks like a sample."""
normalized = str(value or "").strip()
if not normalized:
return ""
lowered = normalized.lower()
if any(marker.lower() in lowered for marker in placeholder_markers if marker):
return ""
if _MASKED_SEQUENCE_RE.search(normalized):
return ""
return normalized
def has_real_config(
value: str | None,
placeholder_markers: tuple[str, ...] = (),
) -> bool:
"""Return True when the value is present and not an obvious placeholder."""
return bool(normalize_optional_config(value, placeholder_markers))

View File

@@ -70,8 +70,17 @@ def cleanup_task_files(task_id: str, keep_outputs: bool = False):
if os.path.exists(upload_task_dir):
shutil.rmtree(upload_task_dir, ignore_errors=True)
# Only clean outputs when using S3 (files already uploaded to S3)
if not keep_outputs:
# Preserve local outputs whenever local fallback is enabled so download links remain valid.
preserve_outputs = keep_outputs
if not preserve_outputs:
try:
from app.services.storage_service import storage
preserve_outputs = storage.allow_local_fallback
except Exception:
preserve_outputs = False
if not preserve_outputs:
output_task_dir = os.path.join(output_dir, task_id)
if os.path.exists(output_task_dir):
shutil.rmtree(output_task_dir, ignore_errors=True)