Create Composite backend for non-prod curriculum API testing #5666
+60
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a
CompositeBackendthat accepts abackendand a list ofurl_prefixes to manage optional unstable backend connections in non-production settings.It also adds a test, and updates some existing tests that are testing prod-only scenarios to clarify that they are production only and do not use the composite backend.
References
Fixes #5584
Reviewer guidance
I leaned heavily on Claude to understand this area of the code base but used it more as a tool to investigate and orient myself, as well as practice some of the patterns. I wrote the code myself (although it did point out more than one error in my python syntax 😁 ), with the exception of updating the existing tests in test_recommendations.py (which I didn't think to do on my own).
I do have some questions about my approach, so I opened this as a draft PR to have a reference for what I was wondering about. I've intentionally left two separate commits so they can be compared.
In the first commit, I have an initial implementation of
CompositeBackendthat:I continued from there, but after writing tests for the first time, I realized (after reviewing the error message with Claude) that I wasn't able to create multiple backend instances.
In the second commit, you will see a different approach, which passes one backend, and a list of prefixes and the rest of my changes. It seems to still meet the same goals of the acceptance criteria. Is this second option better?
I did a bit of brainstorming with Claude about other possibilities and googled a bit about the "singleton pattern" (new to me!) but moving away from that seemed like there could potentially be other unforeseen consequences. And I don't feel confident in my ability to know what those might be :)
Look forward to thoughts!