I refactored InternalEventMiddleware in GitLab AI Gateway. I moved it out of a crowded base module into its own middleware file, and moved its tests with it.
This was part of a wider cleanup to make middleware easier to find, test, and maintain, without breaking existing imports.
What I shipped in MR !2291:
- moved the middleware into
ai_gateway/api/middleware/internal_event.py,
- split and updated the tests in the middleware test module,
- kept old imports working by re-exporting where needed.
During review, maintainers flagged a circular import and some logger-related test failures. I fixed both, and the MR merged after final approval.
I followed up with two more merged MRs:
- !2726 extracted
DistributedTraceMiddleware into its own file in the same way,
- !4586 added tests that validate every flow config YAML file.
Links: MR !2291 • Issue #859 • MR !2726 • MR !4586