test(sync): 添加真实 S-04 生产栈验收

This commit is contained in:
2026-09-09 12:30:00 +08:00
parent d8f416818f
commit b6864f7524
5 changed files with 407 additions and 4 deletions
+10 -1
View File
@@ -33,8 +33,17 @@ def main():
db.add_user(args.username or input("用户名: "), getpass.getpass("密码(至少12字符): "))
elif args.command == "serve":
import uvicorn
host = os.environ.get("SYNC_HOST", "0.0.0.0")
if host not in {"0.0.0.0", "127.0.0.1", "::1"}:
raise SystemExit("SYNC_HOST 仅允许通配或本机回环地址")
try:
port = int(os.environ.get("SYNC_PORT", "8080"))
except ValueError as error:
raise SystemExit("SYNC_PORT 必须为有效端口") from error
if not 1 <= port <= 65535:
raise SystemExit("SYNC_PORT 必须为有效端口")
uvicorn.run("sync_server.__main__:application", factory=True, workers=args.workers,
host="0.0.0.0", port=8080, access_log=False)
host=host, port=port, access_log=False)
elif args.command == "cleanup-uploads":
from .maintenance import cleanup_expired_uploads
print(cleanup_expired_uploads(db, Path(os.environ["SYNC_STAGING_DIR"])))
+6 -2
View File
@@ -11,7 +11,7 @@ from contextlib import asynccontextmanager
import logging
from pathlib import Path
from fastapi import FastAPI, Header, Query, Request
from fastapi import FastAPI, Header, Query, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse, FileResponse
from starlette.background import BackgroundTask
@@ -59,6 +59,7 @@ def create_app(db: Database, objects, staging: Path, *, quota=1024**3, clock=tim
app = FastAPI(title="OpenNexus Sync", version="1.0.0", lifespan=lifespan)
app.state.database = db
worker_id = secrets.token_hex(8)
@app.exception_handler(SyncError)
async def error(_request, exc):
@@ -95,7 +96,10 @@ def create_app(db: Database, objects, staging: Path, *, quota=1024**3, clock=tim
return {"access_token": access, "refresh_token": refresh, "expires_in": 900, "device_id": device_id}
@app.get("/health")
def health():
def health(response: Response):
# An ephemeral identifier lets deployment probes prove that both
# configured workers receive traffic without exposing host identity.
response.headers["X-OpenNexus-Worker"] = worker_id
return {"status": "ok"}
def readiness_probe():