Skip to content

Resolve project name to UUID in S3 mode via IBUTSU_SERVER_URL#103

Closed
akhil-jha wants to merge 1 commit into
ibutsu:mainfrom
akhil-jha:return_uuid
Closed

Resolve project name to UUID in S3 mode via IBUTSU_SERVER_URL#103
akhil-jha wants to merge 1 commit into
ibutsu:mainfrom
akhil-jha:return_uuid

Conversation

@akhil-jha
Copy link
Copy Markdown

@akhil-jha akhil-jha commented May 29, 2026

Summary

  • Fix project_uuid to resolve project names to UUIDs regardless of upload mode (server/S3/archive)
  • Previously, S3 mode skipped UUID resolution entirely, returning the project name (e.g. insights-qe) instead of the actual UUID
  • Introduces IBUTSU_SERVER_URL env var as a fallback when not in server mode, enabling UUID resolution in S3 mode without changing the upload behavior

Problem

When running in S3 mode (IBUTSU_MODE=s3), the project_uuid property returned the project name as-is because it short-circuited with:

if not self.is_server_mode:
    return project_value

This caused downstream consumers (e.g. IQE metrics ibutsu_url label) to generate URLs like /project/insights-qe/runs/... instead of /project/<>/runs/....
Screenshot 2026-05-29 at 11 40 11 AM

Changes

  • Remove the early return for non-server mode
  • Check IBUTSU_SERVER_URL env var as fallback when self.ibutsu_server is empty
  • If neither server URL is available, log a warning and return the name (backward-compatible)
  • Add TestProjectUuid test class covering: valid UUID passthrough, S3 mode without server URL, S3 mode with server URL, server mode resolution, and empty response fallback

Dependency

app-interface MR 190001

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 29, 2026

Reviewer's Guide

Adds a project_uuid cached_property implementation that always resolves project names to UUIDs via the Ibutsu server when possible, using IBUTSU_SERVER_URL in S3 mode, and extends tests to cover the new resolution logic and environment handling.

Sequence diagram for resolving project name to UUID using IBUTSU_SERVER_URL

sequenceDiagram
    participant Plugin as PytestIbutsuPlugin
    participant Validator as validate_uuid_string
    participant Env as os_environ
    participant Config as create_api_configuration
    participant ProjectApi

    Plugin->>Validator: validate_uuid_string(project_value)
    alt project_value_is_uuid
        Validator-->>Plugin: True
        Plugin-->>Plugin: return project_value
    else project_value_is_name
        Validator-->>Plugin: False
        Plugin->>Env: get(IBUTSU_SERVER_URL, "")
        alt server_url_missing
            Env-->>Plugin: ""
            Plugin-->>Plugin: logger.warning(no server URL)
            Plugin-->>Plugin: return project_value
        else server_url_present
            Env-->>Plugin: server_url
            Plugin->>Config: create_api_configuration(server_url, ibutsu_token, use_ssl_ca_cert=False)
            Config-->>Plugin: configuration
            Plugin->>ProjectApi: ProjectApi(ApiClient(configuration))
            Plugin->>ProjectApi: get_project_list(filter=["name=project_value"])
            alt project_not_found_404
                ProjectApi-->>Plugin: NotFoundException
                Plugin-->>Plugin: logger.warning(project not found)
                Plugin-->>Plugin: return project_value
            else project_found
                ProjectApi-->>Plugin: response.projects
                Plugin-->>Plugin: return response.projects[0].id
            end
        end
    end
Loading

File-Level Changes

Change Details Files
Refine project_uuid resolution logic to use either the configured server URL or IBUTSU_SERVER_URL and gracefully fall back when resolution is not possible.
  • Return project value immediately when it is already a valid UUID, regardless of mode
  • Determine server_url from ibutsu_server or IBUTSU_SERVER_URL environment variable
  • Warn and return the original project value when no server URL is available
  • Use the resolved server_url when creating the API configuration and logging
  • Adjust NotFound handling log message to reference the effective server URL
src/pytest_ibutsu/pytest_plugin.py
Extend tests to cover project_uuid behavior in both server and S3 modes, including IBUTSU_SERVER_URL usage and fallback scenarios.
  • Ensure IBUTSU_SERVER_URL is isolated in the shared environment fixture
  • Add tests for project_uuid when project is already a UUID
  • Add test for S3 mode without IBUTSU_SERVER_URL falling back to project name
  • Add test for S3 mode with IBUTSU_SERVER_URL resolving project name to UUID via mocked API
  • Add test for server mode resolving project name to UUID
  • Add test for empty project list response causing fallback to project name
tests/test_plugin.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
Copy Markdown
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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_plugin.py" line_range="412-421" />
<code_context>
+    def test_project_uuid_server_returns_empty_list_falls_back(
</code_context>
<issue_to_address>
**issue (testing):** Add a test case for the NotFoundException (404) path when resolving project UUID

We currently only test the successful resolution and the empty-projects fallback paths. Please add a test where `ProjectApi.get_project_list` raises `NotFoundException` and assert that `plugin.project_uuid` falls back to the project name (and optionally that a warning is logged), so the 404-handling branch is covered and protected against regressions.
</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.

Comment thread tests/test_plugin.py
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.27%. Comparing base (4086c24) to head (5a1982a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #103      +/-   ##
==========================================
+ Coverage   68.15%   70.27%   +2.12%     
==========================================
  Files           7        7              
  Lines         829      831       +2     
  Branches      140      140              
==========================================
+ Hits          565      584      +19     
+ Misses        235      218      -17     
  Partials       29       29              
Flag Coverage Δ
unittests 70.27% <100.00%> (+2.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/pytest_ibutsu/pytest_plugin.py 73.20% <100.00%> (+5.49%) ⬆️

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 4086c24...5a1982a. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant