test(backend): add mcq invalid-input response contract coverage#607
test(backend): add mcq invalid-input response contract coverage#607Ashvin-KS wants to merge 1 commit intoAOSSIE-Org:mainfrom
Conversation
📝 WalkthroughWalkthroughA regression test was added to Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds backend regression coverage to enforce the /get_mcq_answer invalid-input response contract (mismatched input_question / input_options lengths), per issue #606.
Changes:
- Introduces
test_get_mcq_answer_invalid_input_contractto validate response shape and empty-list behavior for invalid input.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| assert 'output' in response | ||
| assert 'outputs' not in response | ||
| assert response['output'] == [] |
| def test_get_mcq_answer_invalid_input_contract(): | ||
| endpoint = '/get_mcq_answer' | ||
| data = { |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@backend/test_server.py`:
- Around line 114-116: The contract test expects the invalid-input response to
contain "output" (empty list) and not "outputs", but the handler in
backend/server.py returns {"outputs": []}; update the invalid-input branch in
the request handler (the branch that currently returns {"outputs": []}) to
return {"output": []} instead, ensuring the response key name matches the test
assertions in backend/test_server.py and remove the "outputs" key so the shape
aligns with the contract.
| assert 'output' in response | ||
| assert 'outputs' not in response | ||
| assert response['output'] == [] |
There was a problem hiding this comment.
Contract test is correct, but it currently conflicts with the handler’s invalid-input response shape.
Line 114-Line 116 enforce output/no outputs, but the invalid-input branch in backend/server.py (provided snippet, Line 126) currently returns {"outputs": []}. This will fail CI until the endpoint is aligned with the contract.
Proposed backend fix (root cause)
--- a/backend/server.py
+++ b/backend/server.py
@@
- if not input_questions or not input_options or len(input_questions) != len(input_options):
- return jsonify({"outputs": outputs})
+ if not input_questions or not input_options or len(input_questions) != len(input_options):
+ return jsonify({"output": outputs})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@backend/test_server.py` around lines 114 - 116, The contract test expects the
invalid-input response to contain "output" (empty list) and not "outputs", but
the handler in backend/server.py returns {"outputs": []}; update the
invalid-input branch in the request handler (the branch that currently returns
{"outputs": []}) to return {"output": []} instead, ensuring the response key
name matches the test assertions in backend/test_server.py and remove the
"outputs" key so the shape aligns with the contract.
Addressed Issues:
Fixes #606
Screenshots/Recordings:
N/A (backend test-only change).
Additional Notes:
/get_mcq_answerinvalid-input path.outputkey is presentoutputskey is absentinput_questionandinput_optionslengths mismatchAI Usage Disclosure:
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.
Check one of the checkboxes below:
I have used the following AI models and tools: GitHub Copilot (GPT-5.3-Codex)
Checklist
Summary by CodeRabbit