Skip to content

Conversation

@bradhe
Copy link
Contributor

@bradhe bradhe commented Jun 23, 2025

This PR adds the ability for Tower CLI to pass along it's current session to running Python apps when running in --local mode. An alternative implementation would be to read the session data eagerly; however, this is a bit more specific.

We also introduce a test for cases where an app can't be found in Tower.

bradhe added 2 commits June 23, 2025 16:45
This PR allows users to pass their current auth context into locally-ran apps.
This means that you'll authenticate with the server using your current session,
etc.
@bradhe bradhe requested review from Copilot and socksy June 23, 2025 15:28
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 enables the Tower SDK and CLI to propagate the current session JWT when running in --local mode and improves error handling for missing apps.

  • Extend Python TowerContext and _env_client to read and use TOWER_JWT for auth.
  • Introduce AppNotFoundError in Python and add a test for 404 responses in run_app.
  • Update Rust CLI do_run_local to inject TOWER_JWT into subprocess environment.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/tower/test_client.py Add test_raising_an_error_for_a_not_found_app to verify 404
src/tower/exceptions.py Introduce AppNotFoundError for missing apps
src/tower/_context.py Add jwt field and defaults for TOWER_URL and TOWER_ENVIRONMENT
src/tower/_client.py Catch 404 status and raise AppNotFoundError; support JWT auth
crates/tower-cmd/src/run.rs Pass environment and TOWER_JWT into local runs
Comments suppressed due to low confidence (2)

src/tower/_client.py:6

  • The docstring for run_app should be updated to document the new AppNotFoundError under the Raises: section so users know it can be thrown on a 404 response.
from ._context import TowerContext

tests/tower/test_client.py:335

  • [nitpick] The variable tower here refers to a client fixture; consider renaming it to client or api_client for clarity.
    tower = mock_api_config

raise RuntimeError(f"Error running app: {output.title}")
else:
return output.run
except UnexpectedStatus as e:
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

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

Currently this except block only handles 404 and otherwise swallows all other status codes, causing the function to return None. Consider re-raising non-404 statuses (e.g. raise) or mapping them to other exceptions to avoid silent failures.

Copilot uses AI. Check for mistakes.
bradhe and others added 3 commits June 23, 2025 19:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bradhe bradhe requested a review from konstantinoscs June 26, 2025 08:13
Copy link
Contributor

@konstantinoscs konstantinoscs left a comment

Choose a reason for hiding this comment

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

Took a quick look but anyway approving this as per the CTOs edict

@bradhe bradhe merged commit ffe7f67 into develop Jun 30, 2025
3 checks passed
@bradhe bradhe deleted the feature/tow-573-make-the-tower-sdk-use-the-local-session-for-with-tower-api branch June 30, 2025 14:13
bradhe added a commit that referenced this pull request Jul 1, 2025
* chore: Upgrade Tower API version

* Let Tower SDK use the local session when running in `--local` mode (#55)

* feat: Pass local context into local runs

This PR allows users to pass their current auth context into locally-ran apps.
This means that you'll authenticate with the server using your current session,
etc.

* chore: Raise an AppNotFoundError when we fail to find an app

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Add test for other error types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Bump version to v0.3.19

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
bradhe added a commit that referenced this pull request Jul 4, 2025
* chore: Upgrade Tower API version

* Let Tower SDK use the local session when running in `--local` mode (#55)

* feat: Pass local context into local runs

This PR allows users to pass their current auth context into locally-ran apps.
This means that you'll authenticate with the server using your current session,
etc.

* chore: Raise an AppNotFoundError when we fail to find an app

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Add test for other error types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Bump version to v0.3.19

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
bradhe added a commit that referenced this pull request Jul 4, 2025
* chore: Upgrade Tower API version

* Let Tower SDK use the local session when running in `--local` mode (#55)

* feat: Pass local context into local runs

This PR allows users to pass their current auth context into locally-ran apps.
This means that you'll authenticate with the server using your current session,
etc.

* chore: Raise an AppNotFoundError when we fail to find an app

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Add test for other error types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Bump version to v0.3.19

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
bradhe added a commit that referenced this pull request Jul 4, 2025
* chore: Upgrade Tower API version

* Let Tower SDK use the local session when running in `--local` mode (#55)

* feat: Pass local context into local runs

This PR allows users to pass their current auth context into locally-ran apps.
This means that you'll authenticate with the server using your current session,
etc.

* chore: Raise an AppNotFoundError when we fail to find an app

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Add test for other error types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Bump version to v0.3.19

* feat: move tower-cli to rustls

* fixing tests after api changes

* chore: Bump version to v0.3.20

* Release v0.3.19 (#56)

* chore: Upgrade Tower API version

* Let Tower SDK use the local session when running in `--local` mode (#55)

* feat: Pass local context into local runs

This PR allows users to pass their current auth context into locally-ran apps.
This means that you'll authenticate with the server using your current session,
etc.

* chore: Raise an AppNotFoundError when we fail to find an app

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update crates/tower-cmd/src/run.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Add test for other error types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Bump version to v0.3.19

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add flake.nix file to support nix ecosystem

* Extract out metadata and common build inputs

* Add to README and rename tower-cli target to simply tower

* Use the version.txt file instead of hardcoding version in nix flake

* chore: Fix broken API integration

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Konstantinos Stefanidis Vozikis <kons.ste@gmail.com>
Co-authored-by: Ben Lovell <ben.j.lovell@gmail.com>
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.

3 participants