46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""Local-only WSGI entry point for the recovered test environment."""
|
|
|
|
import socket
|
|
from pathlib import Path
|
|
|
|
import ai_config
|
|
import config
|
|
|
|
|
|
# Use the local MySQL account authenticated through the Unix socket. This keeps
|
|
# the cloud database credentials intact in config.py but unused by this process.
|
|
_db_password = Path(__file__).with_name(".local-test-db-password").read_text(
|
|
encoding="ascii"
|
|
).strip()
|
|
|
|
config.DB_CONFIG.update(
|
|
{
|
|
"user": "dy_test",
|
|
"password": _db_password,
|
|
"unix_socket": "/run/mysqld/mysqld.sock",
|
|
}
|
|
)
|
|
|
|
# Retain the source configuration in its original files while making accidental
|
|
# AI API use fail locally before a request can leave this machine.
|
|
ai_config.DEEPSEEK_API_KEY = ""
|
|
ai_config.DEEPSEEK_BASE_URL = "http://127.0.0.1:9"
|
|
ai_config.DEEPSEEK_MODEL = "disabled-in-local-test"
|
|
|
|
_create_connection = socket.create_connection
|
|
_local_hosts = {"127.0.0.1", "::1", "localhost"}
|
|
|
|
|
|
def _local_only_connection(address, *args, **kwargs):
|
|
host = address[0] if isinstance(address, tuple) else address
|
|
if host not in _local_hosts:
|
|
raise OSError("External network access is disabled in the local test environment")
|
|
return _create_connection(address, *args, **kwargs)
|
|
|
|
|
|
socket.create_connection = _local_only_connection
|
|
|
|
from app import app
|
|
|
|
app.config["LOCAL_TEST_MODE"] = True
|