I refactored InternalEventMiddleware in GitLab AI Gateway by moving it from a crowded base module into a dedicated middleware file, with tests moved alongside it.
This was part of an ongoing cleanup effort to make middleware easier to locate, test, and maintain without breaking existing imports.
What I shipped in MR !2291:
- extracted middleware into
ai_gateway/api/middleware/internal_event.py, - split and updated tests into the middleware test module,
- kept compatibility by re-exporting where needed.
During review, I fixed a circular import and logger-related test failures flagged by maintainers, then merged after final approval.
Links: MR !2291 • Issue #859