lawsynth/services/api/tests/lifespan_test.py
caelum0x bd58228c14 feat: complete manifest services layer — decomposed modules + Rust gateway
Build the manifest's full decomposed services architecture as real, tested code:
- scheduler: 16 modules (queue/pool/policy/quota/placement/recovery + metrics/
  events/backoff/health/fairness/shutdown + honest nats seam) — 130 tests
- worker: 16 modules (execute/lease/resources/limits + heartbeat/events/telemetry/
  sandbox/recovery/cleanup/upload/artifacts + honest plugins seam) — 52 tests
- api: 20 modules (auth/authz/middleware + per-resource handlers + telemetry/
  facades), app.py now a thin composition root — 98 tests
- gateway: new std-only Rust reverse-proxy crate (proxy/routing/auth/cors/
  rate_limit/retry/timeouts/health/metrics/events/tracing + honest tls seam) — 110 tests

Every one of the 3,161 manifest files now exists. Extractions are behavior-
preserving (all prior tests green); new modules add real capability; nats/tls/
plugins/sandbox are honest documented seams, not fakes.

Rust workspace 352->605 tests; API 35->98. clippy -D warnings + fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-17 19:55:26 +03:00

50 lines
1.4 KiB
Python

"""Unit tests for the HTTP-process lifecycle owner."""
from __future__ import annotations
import pytest
from lawsynth_api.lifespan import ApiLifespan
from lawsynth_server.settings import Settings as ServerSettings
def _settings(tmp_path) -> ServerSettings:
return ServerSettings(
database_url=f"sqlite:///{tmp_path / 'metadata.sqlite3'}",
object_root=tmp_path / "objects",
tokens={},
max_upload_bytes=1024,
)
def test_application_is_available_until_closed(tmp_path):
lifespan = ApiLifespan(_settings(tmp_path))
assert lifespan.application is not None
lifespan.close()
with pytest.raises(RuntimeError):
_ = lifespan.application
def test_close_is_idempotent(tmp_path):
lifespan = ApiLifespan(_settings(tmp_path))
lifespan.close()
lifespan.close() # second close must not raise
def test_context_manager_closes_on_exit(tmp_path):
with ApiLifespan(_settings(tmp_path)) as lifespan:
assert lifespan.application is not None
with pytest.raises(RuntimeError):
_ = lifespan.application
def test_accepts_injected_application(tmp_path):
from lawsynth_server.app import Application
domain = Application(_settings(tmp_path))
lifespan = ApiLifespan(_settings(tmp_path), domain)
try:
assert lifespan.application is domain
finally:
lifespan.close()