Skip to content

Set binary format in openapi spec#806

Merged
mshriver merged 2 commits intoibutsu:mainfrom
mshriver:fix-artifact-import
Jan 26, 2026
Merged

Set binary format in openapi spec#806
mshriver merged 2 commits intoibutsu:mainfrom
mshriver:fix-artifact-import

Conversation

@mshriver
Copy link
Contributor

@mshriver mshriver commented Jan 26, 2026

Summary by Sourcery

Ensure artifact file uploads are correctly described and validated as binary data in the OpenAPI schema and covered by an end-to-end HTTP upload test.

Bug Fixes:

  • Correct the OpenAPI artifact upload schema to mark the file field as binary so multipart uploads validate and work as intended.

Tests:

  • Add an end-to-end test that uploads an artifact via an actual HTTP multipart request through the Connexion validation layer and verifies it is persisted.

Copilot AI review requested due to automatic review settings January 26, 2026 14:54
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 26, 2026

Reviewer's Guide

Adds OpenAPI schema support for binary file uploads to the artifact upload endpoint and introduces an integration-style test that exercises the full HTTP multipart upload path through Connexion validation to ensure artifacts are stored correctly.

Sequence diagram for multipart artifact upload with OpenAPI binary format

sequenceDiagram
    actor Client
    participant ConnexionApp
    participant ArtifactController
    participant ArtifactStorage

    Client->>ConnexionApp: POST /api/artifact/upload
    activate ConnexionApp
    ConnexionApp->>ConnexionApp: Validate request via OpenAPI schema
    Note over ConnexionApp: field file type string<br/>format binary
    ConnexionApp->>ArtifactController: Forward validated multipart data
    deactivate ConnexionApp

    activate ArtifactController
    ArtifactController->>ArtifactStorage: Store file and metadata
    ArtifactStorage-->>ArtifactController: Storage result
    deactivate ArtifactController

    ArtifactController-->>Client: 201 Created with artifact info
Loading

File-Level Changes

Change Details Files
Ensure OpenAPI spec correctly models artifact file uploads as binary in multipart/form-data requests.
  • Update the artifact upload request body schema to declare the file property as a string with binary format
  • Align API contract with actual behavior of the upload endpoint and Connexion validation
backend/ibutsu_server/openapi/openapi.yaml
Add an end-to-end HTTP multipart upload test that runs through Connexion validation and verifies artifact persistence.
  • Introduce a new test that sends a real multipart/form-data POST to the /api/artifact endpoint using the Flask test client
  • Include auth header preparation, multipart form fields (resultId, filename, additionalMetadata, file), and binary file content in the request
  • Assert 201 response, validate response payload fields (filename, result_id, id), and confirm the artifact is persisted in the database with correct content and metadata
backend/tests/controllers/test_artifact_controller.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In test_upload_artifact_via_http, response.text and response.json() rely on Flask test client internals; consider using response.get_data(as_text=True) for debug output and response.get_json() for parsing to avoid attribute issues and keep it consistent with other tests.
  • The new HTTP upload test duplicates some setup logic from existing artifact upload tests (e.g., building headers, file content, and metadata); consider extracting a small helper or fixture to reduce repetition and make future changes to the upload contract easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_upload_artifact_via_http`, `response.text` and `response.json()` rely on Flask test client internals; consider using `response.get_data(as_text=True)` for debug output and `response.get_json()` for parsing to avoid attribute issues and keep it consistent with other tests.
- The new HTTP upload test duplicates some setup logic from existing artifact upload tests (e.g., building headers, file content, and metadata); consider extracting a small helper or fixture to reduce repetition and make future changes to the upload contract easier.

## Individual Comments

### Comment 1
<location> `backend/tests/controllers/test_artifact_controller.py:491-492` </location>
<code_context>
+    )
+
+    # Verify successful upload
+    assert response.status_code == 201, f"Response body: {response.text}"
+    response_data = response.json()
+    assert response_data["filename"] == "http-test.log"
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Using `response.text` in the failure message may not be reliable with the Flask test client

With the Flask test client, `response` often has `data`/`get_data()` but no `.text`, so this assertion can raise `AttributeError` when the status isn’t 201, obscuring the real failure. Use something like `f"Response body: {response.data!r}"` or `response.get_data(as_text=True)` instead so the failure message works reliably across environments.

```suggestion
    # Verify successful upload
    assert response.status_code == 201, f"Response body: {response.get_data(as_text=True)}"
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

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

This PR fixes the OpenAPI specification for file uploads in the artifact endpoint by adding the format: binary field specification. This ensures that the Connexion validation layer properly handles multipart file uploads.

Changes:

  • Added format: binary to the file field in the /api/artifact POST endpoint OpenAPI specification
  • Added a new test test_upload_artifact_via_http that validates the file upload through actual HTTP requests, ensuring the OpenAPI schema is correct

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backend/ibutsu_server/openapi/openapi.yaml Added format: binary to the file field specification in the artifact upload endpoint to properly handle binary file uploads in multipart/form-data requests
backend/tests/controllers/test_artifact_controller.py Added comprehensive HTTP-based test for artifact upload that validates the OpenAPI spec through Connexion's validation layer, complementing the existing test_request_context-based test

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

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.40%. Comparing base (7db2174) to head (fa32762).
⚠️ Report is 2 commits behind head on main.

❌ Your project status has failed because the head coverage (73.40%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #806   +/-   ##
=======================================
  Coverage   73.40%   73.40%           
=======================================
  Files         154      154           
  Lines        7557     7557           
  Branches      660      660           
=======================================
  Hits         5547     5547           
  Misses       1790     1790           
  Partials      220      220           

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7db2174...fa32762. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mshriver mshriver force-pushed the fix-artifact-import branch from 07a6c45 to 8b73da0 Compare January 26, 2026 16:27
@mshriver mshriver force-pushed the fix-artifact-import branch from 8b73da0 to 09aa68a Compare January 26, 2026 16:38
@mshriver mshriver merged commit f210c05 into ibutsu:main Jan 26, 2026
14 of 15 checks passed
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.

2 participants