Skip to content

test: add integration tests for file upload endpoint#236

Open
himanshu748 wants to merge 3 commits intojenkinsci:mainfrom
himanshu748:test/file-upload-integration-224
Open

test: add integration tests for file upload endpoint#236
himanshu748 wants to merge 3 commits intojenkinsci:mainfrom
himanshu748:test/file-upload-integration-224

Conversation

@himanshu748
Copy link

Summary

Closes #224

Adds 11 integration tests for POST /sessions/{session_id}/message/upload — the endpoint had unit tests but zero integration coverage.

Test Cases

Test Status Code Scenario
Text file (.txt) upload 200 Valid session, message + file
Code file (.py) upload 200 Exercises text-file path for code
Image file (.png) upload 200 PNG magic bytes, valid session
Nonexistent session 404 Session ID doesn't exist
Empty message, no files 422 Validation rejects empty request
Unsupported .zip file 400 File type not in allow-list
File exceeds 5 MB limit 400 Size validation triggers
Files only, empty message 200 Default prompt used
Multiple files 200 Two files in single request
Full lifecycle 201/200/200/404 Create -> upload -> delete -> verify 404

Approach

  • Exercises the real file_service layer (file type detection, size validation, text extraction, image base64 encoding)
  • Mocks only llm_provider and get_relevant_documents (same pattern as existing test_chatbot.py)
  • Uses memory.reset_sessions() autouse fixture for test isolation
  • No changes to production code

…#224)

Add 11 integration tests for POST /sessions/{session_id}/message/upload:
- Text file upload (200 with reply)
- Code file upload (.py, 200)
- Image file upload (PNG, 200)
- Nonexistent session (404)
- Empty message without files (422)
- Unsupported file type .zip (400)
- File exceeding 5 MB limit (400)
- Files-only with empty message (200 with default prompt)
- Multiple files in single request (200)
- Full lifecycle: create -> upload -> delete -> verify 404

Uses real file_service layer; mocks only LLM and RAG retrieval.
Copilot AI review requested due to automatic review settings March 3, 2026 05:33
@himanshu748 himanshu748 requested a review from a team as a code owner March 3, 2026 05:33
Copy link

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 integration coverage for the multipart file-upload chatbot endpoint (POST /sessions/{session_id}/message/upload) to complement existing unit tests and close #224.

Changes:

  • Introduces a new integration test module covering successful uploads for text/code/image files.
  • Adds integration coverage for error handling (404 for missing session, 422 for empty request, 400 for unsupported type / oversize payload).
  • Adds edge/lifecycle coverage (files-only requests, multi-file uploads, create→upload→delete→verify 404).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +5
"""Integration tests for file upload endpoint POST /sessions/{session_id}/message/upload.

Issue #224 — exercises the upload route end-to-end through the real
file_service layer while mocking only the LLM and RAG retrieval.
"""
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The PR description says this adds 11 integration tests, but this file defines 10 test_* functions. Please update the PR description (or add the missing test case) so the stated coverage matches what’s actually included.

Copilot uses AI. Check for mistakes.
Comment on lines +149 to +155
def test_upload_file_too_large_returns_400(client):
"""Upload a text file exceeding 5 MB — expect 400 size limit."""
session_id = _create_session(client)

large_content = b"x" * (6 * 1024 * 1024) # 6 MB
files = [("files", ("huge.txt", BytesIO(large_content), "text/plain"))]
resp = client.post(
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

This test hard-codes a 6 MB payload and assumes the limit is 5 MB. To avoid slowing the suite and to keep the test robust if limits change, build the payload based on the configured constant (e.g., max_text_size + 1 byte) rather than a fixed 6 MB value.

Copilot uses AI. Check for mistakes.
Address Copilot review feedback:
- Import MAX_TEXT_FILE_SIZE from file_service instead of hard-coding 6 MB
- Payload is now MAX_TEXT_FILE_SIZE + 1 byte (robust if limit changes)
- Correct test count: 10 test functions (PR description said 11)
@himanshu748
Copy link
Author

Addressed both review items in fa3883c:

  1. Test count: Corrected — there are 10 test functions, not 11 as the summary originally stated. Apologies for the mismatch.
  2. Hard-coded file size: Replaced 6 * 1024 * 1024 with MAX_TEXT_FILE_SIZE + 1 imported from api.services.file_service. The test now stays correct if the limit is ever changed.

@berviantoleo
Copy link
Contributor

berviantoleo commented Mar 3, 2026

Please read the policy regarding AI (https://www.jenkins.io/projects/gsoc/ai-usage-policy/). This is your first and last warning.

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

Labels

tests This PR adds/removes/updates test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tests] Add integration tests for file upload endpoint POST /sessions/{session_id}/message/upload

3 participants