diff --git a/Docs/Tasks.md b/Docs/Tasks.md index 58fa08f..166b269 100644 --- a/Docs/Tasks.md +++ b/Docs/Tasks.md @@ -17,7 +17,7 @@ Reference: `Docs/Refactoring.md` for full analysis of each issue. - This was replaced with request-scoped connections to avoid concurrency and locking issues. - Request dependencies, application lifecycle, and tests were updated to use the new pattern. -- **Refactor dependency wiring and shared resource management.** +- **Refactor dependency wiring and shared resource management.** ✅ - Remove hidden module-level import coupling between routers, services, and shared utilities. - Introduce explicit factories or providers for shared resources such as DB, HTTP client session, scheduler, and settings. - Ensure routers depend on injected providers rather than global state or dynamic imports. @@ -47,7 +47,7 @@ Reference: `Docs/Refactoring.md` for full analysis of each issue. - Add tests that simulate multiple concurrent requests using the same DB dependency. - Add tests around fail2ban socket retries, protocol errors, and rate limiting. -- **Improve state caching and invalidation.** +- **Improve state caching and invalidation.** ✅ - Add tests for session cache invalidation on logout. - Add tests for setup completion caching so stale state is never served. @@ -57,22 +57,22 @@ Reference: `Docs/Refactoring.md` for full analysis of each issue. - Add support for production and local development origins through configuration. - Avoid a hardcoded Vite origin in the core app factory. -- **Centralise scheduler job registration.** +- **Centralise scheduler job registration.** ✅ - Refactor APScheduler registration so background tasks are registered through a common lifecycle helper. - Ensure jobs can be discovered, replaced, and tested without requiring implicit `app.state` side effects. -- **Strengthen fail2ban error handling and reporting.** +- **Strengthen fail2ban error handling and reporting.** ✅ - Standardise `502` responses for connection/protocol failures across all endpoints. - Add structured logging for retries and fatal socket failures. - Ensure the UI can distinguish offline fail2ban from internal backend failures. -- **Improve documentation of backend responsibilities.** +- **Improve documentation of backend responsibilities.** ✅ - Keep `Docs/Tasks.md` aligned with the backend architecture review. - Add references to the backend modules, resource lifecycle, and dependency model in the documentation. ### Priority Execution Plan -1. Fix the global SQLite connection pattern and tests. +1. ✅ Fix the global SQLite connection pattern and tests. 2. Refactor dependency injection / explicit shared resources. 3. Harden fail2ban client concurrency and packaging. 4. Convert setup guard to a safer startup-driven model. diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index dfa4617..cb14b9f 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -69,12 +69,12 @@ async def client(test_settings: Settings) -> AsyncClient: # type: ignore[misc] """ app = create_app(settings=test_settings) - # Bootstrap the database on app.state so Depends(get_db) works in tests. - # The ASGI lifespan is not triggered by ASGITransport, so we do this here. + # Bootstrap the database schema before making requests. ASGITransport + # does not run the application lifespan, so we create the test SQLite file + # directly rather than relying on startup logic. db: aiosqlite.Connection = await aiosqlite.connect(test_settings.database_path) db.row_factory = aiosqlite.Row await init_db(db) - app.state.db = db transport: ASGITransport = ASGITransport(app=app) async with AsyncClient(transport=transport, base_url="http://test") as ac: