-
Notifications
You must be signed in to change notification settings - Fork 42
Add python sdk unit tests and ci #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NiveditJain
merged 4 commits into
main
from
cursor/add-python-sdk-unit-tests-and-ci-8804
Aug 17, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
be007e5
Add tests and improve runtime validation for Python SDK
cursoragent c6186bb
python-sdk: add unit tests; fix Runtime node validation guards; add P…
cursoragent be29ded
chore: remove stray get-pip.py
cursoragent 6752dbb
fix(ci): install python-sdk package in test workflow; ruff fixes (rem…
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: Python SDK Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'python-sdk/**' | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'python-sdk/**' | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v2 | ||
| with: | ||
| cache: true | ||
|
|
||
| - name: Install dev dependencies with uv | ||
| working-directory: python-sdk | ||
| run: | | ||
| uv sync --group dev | ||
|
|
||
| - name: Install python-sdk package (editable) | ||
| working-directory: python-sdk | ||
| run: | | ||
| uv pip install -e . | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Run tests with pytest and coverage | ||
| working-directory: python-sdk | ||
| run: | | ||
| uv run pytest --cov=exospherehost --cov-report=xml --cov-report=term-missing -v --junitxml=pytest-report.xml | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Upload coverage reports to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| slug: exospherehost/exospherehost | ||
| files: python-sdk/coverage.xml | ||
| flags: python-sdk-unittests | ||
| name: python-sdk-coverage-report | ||
| fail_ci_if_error: true | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: python-sdk-test-results | ||
| path: python-sdk/pytest-report.xml | ||
| retention-days: 30 | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from exospherehost.node.BaseNode import BaseNode | ||
| from pydantic import BaseModel | ||
| import asyncio | ||
|
|
||
|
|
||
| class EchoNode(BaseNode): | ||
| class Inputs(BaseModel): | ||
| text: str | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class Outputs(BaseModel): | ||
| message: str | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class Secrets(BaseModel): | ||
| token: str | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async def execute(self) -> Outputs: | ||
| return self.Outputs(message=f"{self.inputs.text}:{self.secrets.token}") | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_base_node_execute_sets_inputs_and_returns_outputs(): | ||
| node = EchoNode() | ||
| inputs = EchoNode.Inputs(text="hello") | ||
| secrets = EchoNode.Secrets(token="tkn") | ||
| outputs = asyncio.run(node._execute(inputs, secrets)) | ||
|
|
||
| assert isinstance(outputs, EchoNode.Outputs) | ||
| assert outputs.message == "hello:tkn" | ||
| assert node.inputs == inputs | ||
| assert node.secrets == secrets | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import pytest | ||
| from pydantic import BaseModel | ||
| from exospherehost.runtime import Runtime | ||
| from exospherehost.node.BaseNode import BaseNode | ||
|
|
||
|
|
||
| class GoodNode(BaseNode): | ||
| class Inputs(BaseModel): | ||
| name: str | ||
|
|
||
| class Outputs(BaseModel): | ||
| message: str | ||
|
|
||
| class Secrets(BaseModel): | ||
| api_key: str | ||
|
|
||
| async def execute(self): | ||
| return self.Outputs(message=f"hi {self.inputs.name}") | ||
|
|
||
|
|
||
| class BadNodeWrongInputsBase(BaseNode): | ||
| Inputs = object # not a pydantic BaseModel | ||
| class Outputs(BaseModel): | ||
| message: str | ||
| class Secrets(BaseModel): | ||
| token: str | ||
| async def execute(self): | ||
| return self.Outputs(message="x") | ||
|
|
||
|
|
||
| class BadNodeWrongTypes(BaseNode): | ||
| class Inputs(BaseModel): | ||
| count: int | ||
| class Outputs(BaseModel): | ||
| ok: bool | ||
| class Secrets(BaseModel): | ||
| secret: bytes | ||
| async def execute(self): | ||
| return self.Outputs(ok=True) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| def test_runtime_missing_config_raises(monkeypatch): | ||
| # Ensure env vars not set | ||
| monkeypatch.delenv("EXOSPHERE_STATE_MANAGER_URI", raising=False) | ||
| monkeypatch.delenv("EXOSPHERE_API_KEY", raising=False) | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode]) | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_runtime_with_env_ok(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| rt = Runtime(namespace="ns", name="rt", nodes=[GoodNode]) | ||
| assert rt is not None | ||
|
|
||
|
|
||
| def test_runtime_invalid_params_raises(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode], batch_size=0) | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode], workers=0) | ||
|
|
||
|
|
||
| def test_node_validation_errors(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| with pytest.raises(ValueError) as e: | ||
| Runtime(namespace="ns", name="rt", nodes=[BadNodeWrongInputsBase]) | ||
| assert "Inputs class that inherits" in str(e.value) | ||
|
|
||
| with pytest.raises(ValueError) as e2: | ||
| Runtime(namespace="ns", name="rt", nodes=[BadNodeWrongTypes]) | ||
| msg = str(e2.value) | ||
| assert "Inputs field" in msg and "Outputs field" in msg and "Secrets field" in msg | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_duplicate_node_names_raise(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| class AnotherGood(BaseNode): | ||
| class Inputs(BaseModel): | ||
| name: str | ||
| class Outputs(BaseModel): | ||
| message: str | ||
| class Secrets(BaseModel): | ||
| api_key: str | ||
| async def execute(self): | ||
| return self.Outputs(message="ok") | ||
| AnotherGood.__name__ = "GoodNode" # force duplicate name | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode, AnotherGood]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
| import asyncio | ||
| from exospherehost.statemanager import StateManager, TriggerState | ||
|
|
||
|
|
||
| def test_trigger_requires_either_state_or_states(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| sm = StateManager(namespace="ns") | ||
| with pytest.raises(ValueError): | ||
| asyncio.run(sm.trigger("g")) | ||
|
|
||
|
|
||
| def test_trigger_rejects_both_state_and_states(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| sm = StateManager(namespace="ns") | ||
| state = TriggerState(identifier="id", inputs={}) | ||
| with pytest.raises(ValueError): | ||
| asyncio.run(sm.trigger("g", state=state, states=[state])) | ||
|
|
||
|
|
||
| def test_trigger_rejects_empty_states_list(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| sm = StateManager(namespace="ns") | ||
| with pytest.raises(ValueError): | ||
| asyncio.run(sm.trigger("g", states=[])) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.