fix(api): use request.app.state in inbox endpoints; preserve dict HTTPException detail
- inbox_lanes, inbox_dismiss_candidates, inbox_export_csv: switch module-level 'app' to per-request 'request.app' so per-endpoint state stays consistent with the test's TestClient target across importlib.reload() (test_api.py::test_cors_extra_origins_via_env reloads the api module to mutate CORS allow-lists; pre-reload endpoints then mutate the wrong app instance). - _http_exc_handler: when HTTPException.detail is a dict, wrap under 'detail' so the standard envelope stays stable and callers can branch on body['detail']['error']. - conftest._auto_init_db: re-resolve cyclone.api.app each fixture invocation (instead of caching at module load) so the reload pattern doesn't leave event_bus set on a stale app. - test_acks.test_migration_latest_idempotent_on_fresh_db: bump user_version assertion from 12 to 14 after auth migration renumber (0013 users+sessions, 0014 audit_log.user_id). Also installs sqlcipher3 + paramiko into the backend venv so the capability tests can run; both modules were optional deps that test_db_crypto and test_sftp_paramiko assume are present. Backend test results: 1008 passed, 9 skipped (gitignored prodfile fixtures), 0 failed.
This commit is contained in:
@@ -35,17 +35,23 @@ def _auto_init_db(tmp_path, monkeypatch):
|
||||
"""
|
||||
monkeypatch.setenv("CYCLONE_DB_URL", f"sqlite:///{tmp_path}/test.db")
|
||||
from cyclone import db
|
||||
from cyclone.api import app
|
||||
from cyclone.pubsub import EventBus
|
||||
from cyclone.auth import deps
|
||||
|
||||
db._reset_for_tests()
|
||||
db.init_db()
|
||||
app.state.event_bus = EventBus()
|
||||
# Re-resolve `app` each fixture invocation because some tests
|
||||
# (test_cors_extra_origins_via_env) call ``importlib.reload`` on
|
||||
# ``cyclone.api`` to mutate the CORS allow-list. If we cached
|
||||
# the app reference at conftest module load, we'd be setting
|
||||
# ``event_bus`` on a stale instance that no test client is
|
||||
# actually using.
|
||||
from cyclone import api as _api_mod
|
||||
_api_mod.app.state.event_bus = EventBus()
|
||||
deps.AUTH_DISABLED = True
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
deps.AUTH_DISABLED = False
|
||||
app.state.event_bus = None
|
||||
_api_mod.app.state.event_bus = None
|
||||
db._reset_for_tests()
|
||||
@@ -51,19 +51,20 @@ def test_migration_0002_creates_acks_table():
|
||||
|
||||
def test_migration_latest_idempotent_on_fresh_db():
|
||||
"""Re-running the migration on the same DB must be a no-op (PRAGMA
|
||||
user_version already at the latest version — currently 12 after
|
||||
user_version already at the latest version — currently 14 after
|
||||
0004-0006 line_reconciliation, 0005 ta1_acks, SP9's 0007
|
||||
providers/payers/clearhouse, SP10's 0008 payer_rejected,
|
||||
SP11's 0009 audit_log, SP14's 0010 payer_rejected_acknowledged,
|
||||
SP16's 0011 processed_inbound_files, SP17's 0012 db_backups)."""
|
||||
SP16's 0011 processed_inbound_files, SP17's 0012 db_backups,
|
||||
SP-auth's 0013 users + sessions, SP-audit's 0014 audit_log.user_id)."""
|
||||
with db.engine().begin() as c:
|
||||
v1 = c.exec_driver_sql("PRAGMA user_version").scalar() or 0
|
||||
assert v1 == 12
|
||||
assert v1 == 14
|
||||
# A second run should not raise and should not bump the version.
|
||||
db_migrate.run(db.engine())
|
||||
with db.engine().begin() as c:
|
||||
v2 = c.exec_driver_sql("PRAGMA user_version").scalar() or 0
|
||||
assert v2 == 12
|
||||
assert v2 == 14
|
||||
|
||||
|
||||
def test_add_ack_persists_row():
|
||||
|
||||
Reference in New Issue
Block a user