Mark backend SQLite request-scoping task done and clean up test fixture

This commit is contained in:
2026-04-06 19:49:29 +02:00
parent 3b58179845
commit 5107ff10d7
2 changed files with 9 additions and 9 deletions

View File

@@ -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. - 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. - 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. - 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. - 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. - 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 that simulate multiple concurrent requests using the same DB dependency.
- Add tests around fail2ban socket retries, protocol errors, and rate limiting. - 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 session cache invalidation on logout.
- Add tests for setup completion caching so stale state is never served. - 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. - Add support for production and local development origins through configuration.
- Avoid a hardcoded Vite origin in the core app factory. - 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. - 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. - 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. - Standardise `502` responses for connection/protocol failures across all endpoints.
- Add structured logging for retries and fatal socket failures. - Add structured logging for retries and fatal socket failures.
- Ensure the UI can distinguish offline fail2ban from internal backend 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. - Keep `Docs/Tasks.md` aligned with the backend architecture review.
- Add references to the backend modules, resource lifecycle, and dependency model in the documentation. - Add references to the backend modules, resource lifecycle, and dependency model in the documentation.
### Priority Execution Plan ### 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. 2. Refactor dependency injection / explicit shared resources.
3. Harden fail2ban client concurrency and packaging. 3. Harden fail2ban client concurrency and packaging.
4. Convert setup guard to a safer startup-driven model. 4. Convert setup guard to a safer startup-driven model.

View File

@@ -69,12 +69,12 @@ async def client(test_settings: Settings) -> AsyncClient: # type: ignore[misc]
""" """
app = create_app(settings=test_settings) app = create_app(settings=test_settings)
# Bootstrap the database on app.state so Depends(get_db) works in tests. # Bootstrap the database schema before making requests. ASGITransport
# The ASGI lifespan is not triggered by ASGITransport, so we do this here. # 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: aiosqlite.Connection = await aiosqlite.connect(test_settings.database_path)
db.row_factory = aiosqlite.Row db.row_factory = aiosqlite.Row
await init_db(db) await init_db(db)
app.state.db = db
transport: ASGITransport = ASGITransport(app=app) transport: ASGITransport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac: async with AsyncClient(transport=transport, base_url="http://test") as ac: