Files
odysseus/tests/test_shutdown_signal.py
T
pewdiepie-archdaemonandClaude Opus 5.5 eb940f24a3 feat(photo-editor): NL editor planner, image ops, email/gallery server
Server-side photo editor: natural-language editor agent route
(/api/editor/agent), photo_editor tool family + style guide, image-op
provider proxy with progress, email server hardening, gallery/hwfit
routes, and graceful shutdown.

Source: vendor/photocraft (ad1cff44) editor-server files, merged onto
upstream/dev (a8c147b2). Conflict resolution documented in
pr_work/B_conflicts.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 11:57:00 +00:00

52 lines
1.8 KiB
Python

"""Graceful-shutdown signalling tests (HARNESS-owned).
SSE / streaming responses never complete on their own, so uvicorn's graceful
shutdown would wait for an open browser stream up to the whole
``timeout_graceful_shutdown`` window. src.shutdown is a process-wide flag that
the SIGTERM/SIGINT handler flips and every streaming generator checks, so a
restart ends open streams promptly while ordinary in-flight requests still
finish.
"""
from pathlib import Path
from src import shutdown
ROOT = Path(__file__).resolve().parent.parent
def test_request_shutdown_is_sticky_and_resettable():
shutdown.reset()
try:
assert shutdown.is_shutting_down() is False
shutdown.request_shutdown()
assert shutdown.is_shutting_down() is True
# idempotent
shutdown.request_shutdown()
assert shutdown.is_shutting_down() is True
finally:
shutdown.reset()
assert shutdown.is_shutting_down() is False
def test_app_installs_its_own_shutdown_handler():
src = (ROOT / "app.py").read_text(encoding="utf-8")
# This uvicorn version has no install_signal_handlers kwarg, so app.py wraps
# server.handle_exit (which capture_signals wires SIGINT/SIGTERM to).
assert "install_signal_handlers=False" not in src
assert "server.handle_exit = _handle_shutdown_signal" in src
assert "_shutdown.request_shutdown()" in src
assert "server.run()" in src
def test_streaming_generators_check_the_shutdown_flag():
# editor bridge SSE + chat stream/resume + research + email events + shell.
for rel in (
"routes/editor_agent_routes.py",
"routes/chat_routes.py",
"routes/research/research_routes.py",
"routes/email/email_routes.py",
"routes/shell_routes.py",
):
src = (ROOT / rel).read_text(encoding="utf-8")
assert "_shutdown.is_shutting_down()" in src, rel