Skip to content

Appending server_url for project_id resolve#101

Merged
mshriver merged 1 commit intoibutsu:mainfrom
akhil-jha:fix_project_uuid_resolve
Jan 27, 2026
Merged

Appending server_url for project_id resolve#101
mshriver merged 1 commit intoibutsu:mainfrom
akhil-jha:fix_project_uuid_resolve

Conversation

@akhil-jha
Copy link

@akhil-jha akhil-jha commented Jan 13, 2026

To solve this

File "/iqe_venv/lib/python3.12/site-packages/pytest_ibutsu/pytest_plugin.py", line 641, in pytest_terminal_summary
f"✓ Results uploaded to: {summary['frontend_url']}/project/{plugin.project_uuid}/runs/{plugin.run.id}"

Summary by Sourcery

Resolve Ibutsu project UUIDs against the API endpoint instead of the raw server URL and handle missing projects gracefully.

Bug Fixes:

  • Normalize the Ibutsu server URL to point to the /api endpoint when resolving project IDs.
  • Handle 404 Not Found errors when looking up projects by name and fall back to the configured project value.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Normalizes the Ibutsu server URL for API calls and adds graceful handling when a project name cannot be resolved via the Ibutsu API, falling back to the original project value while logging a warning.

Sequence diagram for project_uuid resolution with 404 handling

sequenceDiagram
    actor Tester
    participant PytestIbutsuPlugin
    participant Configuration
    participant ApiClient
    participant ProjectApi

    Tester ->> PytestIbutsuPlugin: request project_uuid
    activate PytestIbutsuPlugin
    PytestIbutsuPlugin ->> PytestIbutsuPlugin: normalize ibutsu_server to server_url
    PytestIbutsuPlugin ->> Configuration: create(access_token, server_url)
    activate Configuration
    Configuration -->> PytestIbutsuPlugin: config
    deactivate Configuration

    PytestIbutsuPlugin ->> ApiClient: create(config)
    activate ApiClient
    ApiClient -->> PytestIbutsuPlugin: api_client
    deactivate ApiClient

    PytestIbutsuPlugin ->> ProjectApi: create(api_client)
    activate ProjectApi
    PytestIbutsuPlugin ->> ProjectApi: get_project_list(filter name=project_value)

    alt Project name not found
        ProjectApi -->> PytestIbutsuPlugin: raise NotFoundException
        PytestIbutsuPlugin ->> PytestIbutsuPlugin: log warning
        PytestIbutsuPlugin -->> Tester: return project_value
    else Project list returned
        ProjectApi -->> PytestIbutsuPlugin: response with projects
        PytestIbutsuPlugin ->> PytestIbutsuPlugin: check projects list
        PytestIbutsuPlugin -->> Tester: return resolved_uuid from first project id
    end

    deactivate ProjectApi
    deactivate PytestIbutsuPlugin
Loading

Class diagram for updated project_uuid resolution logic

classDiagram
    class PytestIbutsuPlugin {
        - string ibutsu_token
        - string ibutsu_server
        + string project_uuid()
    }

    class Configuration {
        + Configuration(access_token, host)
    }

    class ApiClient {
        + ApiClient(configuration)
    }

    class ProjectApi {
        + ProjectApi(api_client)
        + get_project_list(filter)
    }

    class NotFoundException {
    }

    PytestIbutsuPlugin --> Configuration : creates
    Configuration --> ApiClient : used_by
    ApiClient --> ProjectApi : passed_to
    PytestIbutsuPlugin --> ProjectApi : uses
    ProjectApi --> NotFoundException : may_raise
Loading

Flow diagram for normalized server_url and project_id resolution

flowchart TD
    A[Start project_uuid resolution] --> B[Read ibutsu_server]
    B --> C{Ends with /?}
    C -- Yes --> D[Remove trailing /]
    C -- No --> E[Keep as is]
    D --> F{Ends with /api?}
    E --> F
    F -- No --> G[Append /api]
    F -- Yes --> H[Keep server_url]
    G --> I[Create Configuration with access_token and normalized server_url]
    H --> I
    I --> J[Create ApiClient and ProjectApi]
    J --> K[Call get_project_list with filter name=project_value]
    K --> L{NotFoundException raised?}
    L -- Yes --> M[Log warning Could not find project_value on server]
    M --> N[Return original project_value]
    L -- No --> O{response.projects exists and length > 0?}
    O -- Yes --> P[resolved_uuid = first project id]
    P --> Q[Return resolved_uuid]
    O -- No --> R[Return project_value]
    N --> S[End]
    Q --> S
    R --> S
Loading

File-Level Changes

Change Details Files
Normalize Ibutsu server URL before constructing the API client configuration.
  • Strip a trailing slash from the configured server URL if present.
  • Append '/api' to the server URL if it does not already end with '/api'.
  • Use the normalized URL as the host when constructing the Ibutsu API Configuration.
src/pytest_ibutsu/pytest_plugin.py
Handle missing projects when resolving project UUIDs from the Ibutsu API.
  • Import NotFoundException from the Ibutsu client exceptions module.
  • Wrap the project list request in a try/except for NotFoundException.
  • Log a warning when the project name is not found (404) and return the original project value instead of failing.
src/pytest_ibutsu/pytest_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
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 left some high level feedback:

  • The server_url normalization assumes the API root ends exactly with /api, which would break hosts that already use a versioned path like /api/v1; consider using urllib.parse to inspect/normalize the path more robustly instead of relying on endswith('/api').
  • When falling back to returning project_value on NotFoundException, it might be helpful to include the server_url in the warning log so users can more easily diagnose misconfigured endpoints or typos in the project name.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `server_url` normalization assumes the API root ends exactly with `/api`, which would break hosts that already use a versioned path like `/api/v1`; consider using `urllib.parse` to inspect/normalize the path more robustly instead of relying on `endswith('/api')`.
- When falling back to returning `project_value` on `NotFoundException`, it might be helpful to include the `server_url` in the warning log so users can more easily diagnose misconfigured endpoints or typos in the project name.

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.

@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 54.54545% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.15%. Comparing base (3b876f0) to head (08f2e42).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/pytest_ibutsu/api_config.py 62.50% 4 Missing and 2 partials ⚠️
src/pytest_ibutsu/pytest_plugin.py 0.00% 4 Missing ⚠️

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #101      +/-   ##
==========================================
- Coverage   68.65%   68.15%   -0.51%     
==========================================
  Files           6        7       +1     
  Lines         820      829       +9     
  Branches      140      140              
==========================================
+ Hits          563      565       +2     
- Misses        230      235       +5     
- Partials       27       29       +2     
Flag Coverage Δ
unittests 68.15% <54.54%> (-0.51%) ⬇️

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

Files with missing lines Coverage Δ
src/pytest_ibutsu/sender.py 72.80% <100.00%> (-1.09%) ⬇️
src/pytest_ibutsu/pytest_plugin.py 67.71% <0.00%> (-0.43%) ⬇️
src/pytest_ibutsu/api_config.py 62.50% <62.50%> (ø)

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 3b876f0...08f2e42. Read the comment docs.

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

@akhil-jha akhil-jha force-pushed the fix_project_uuid_resolve branch 2 times, most recently from 3f41a70 to eb6ff3d Compare January 13, 2026 08:35
@akhil-jha
Copy link
Author

@mshriver

@mshriver
Copy link
Contributor

mshriver commented Jan 19, 2026

Second issue with this 'feature' - the URL provided for IBUTSU_MODE is the API endpoint, which may be a different CNAME.

Consider: including IBUTSU_UI envvar that would be used for the reporting.

Not blocking for this MR, should be a separate scope.

@akhil-jha akhil-jha force-pushed the fix_project_uuid_resolve branch 3 times, most recently from d179e56 to e20c291 Compare January 22, 2026 10:49
@akhil-jha akhil-jha force-pushed the fix_project_uuid_resolve branch from e20c291 to 08f2e42 Compare January 22, 2026 11:12
@akhil-jha
Copy link
Author

Changing in ibutsu client Configuration class manually isnt allowed as it is generated by the regeneration script. Changing that would be of no use as next regeneration would revert it. We can change the regeneration script, but maybe thats too big of a change?
Instead lets wrap around the class and update the url? @mshriver

@mshriver mshriver merged commit a7912eb into ibutsu:main Jan 27, 2026
6 of 8 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