Skip to content

test(backend): add mcq invalid-input response contract coverage#607

Open
Ashvin-KS wants to merge 1 commit intoAOSSIE-Org:mainfrom
Ashvin-KS:test/mcq-answer-invalid-input-contract
Open

test(backend): add mcq invalid-input response contract coverage#607
Ashvin-KS wants to merge 1 commit intoAOSSIE-Org:mainfrom
Ashvin-KS:test/mcq-answer-invalid-input-contract

Conversation

@Ashvin-KS
Copy link
Copy Markdown
Contributor

@Ashvin-KS Ashvin-KS commented Mar 18, 2026

Addressed Issues:

Fixes #606

Screenshots/Recordings:

N/A (backend test-only change).

Additional Notes:

  • Adds regression coverage for the /get_mcq_answer invalid-input path.
  • Ensures API response contract consistency:
    • output key is present
    • outputs key is absent
    • returned value is an empty list when input_question and input_options lengths mismatch
  • This PR is intentionally scoped to a single improvement (test coverage only).

AI 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:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: GitHub Copilot (GPT-5.3-Codex)

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Tests
    • Added test coverage for invalid input handling in the MCQ answer retrieval functionality to ensure the API gracefully handles unexpected data formats.

Copilot AI review requested due to automatic review settings March 18, 2026 13:30
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

A regression test was added to backend/test_server.py that validates the response contract of the /get_mcq_answer endpoint when processing invalid input with mismatched question and options lengths. The test asserts the presence of the output key, absence of outputs, and an empty list value.

Changes

Cohort / File(s) Summary
Regression Test Addition
backend/test_server.py
Added test_get_mcq_answer_invalid_input_contract() to enforce response structure consistency—verifying output key presence, outputs absence, and empty list value for mismatched input scenarios.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • PR #590: Standardized the /get_mcq_answer endpoint to return output instead of outputs; this test directly validates the contract introduced by that fix.

Poem

🐰 A hop, a skip, a test so small,
Guards the contract through it all,
output stays, outputs won't dare,
Regression prevented with utmost care! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding test coverage for MCQ invalid-input response contract validation.
Linked Issues check ✅ Passed The PR fulfills all coding requirements from issue #606: tests assert output key exists, outputs key absent, and empty list returned for mismatched inputs.
Out of Scope Changes check ✅ Passed All changes are in-scope test coverage for the /get_mcq_answer invalid-input contract as specified in issue #606.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_contract to 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.

Comment on lines +114 to +116
assert 'output' in response
assert 'outputs' not in response
assert response['output'] == []
Comment on lines +105 to +107
def test_get_mcq_answer_invalid_input_contract():
endpoint = '/get_mcq_answer'
data = {
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 746468fe-6fc8-4a7a-8f5f-925841c9381f

📥 Commits

Reviewing files that changed from the base of the PR and between 2038116 and 47dd859.

📒 Files selected for processing (1)
  • backend/test_server.py

Comment on lines +114 to +116
assert 'output' in response
assert 'outputs' not in response
assert response['output'] == []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: [Improvement] Add regression test for /get_mcq_answer response contract consistency

2 participants