Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions workflowai/core/domain/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,16 @@ def test_format_output_no_cost_latency():


class TestRunURL:
# The @patch decorator from unittest.mock temporarily replaces the value of an attribute
# during the execution of the decorated test function. The original value is restored
# after the test completes.

# To check what happens in different environemnt configurations, see env_test.py

# Here we patch WORKFLOWAI_APP_URL to test the direct app URL case
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
def test_run_url(self, run1: Run[_TestOutput]):
# The patched value is only active during this test method
assert run1.run_url == "https://workflowai.hello/_/agents/agent-id/runs/run-id"


Expand Down
2 changes: 1 addition & 1 deletion workflowai/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

WORKFLOWAI_DEFAULT_MODEL = os.getenv("WORKFLOWAI_DEFAULT_MODEL", "gemini-1.5-pro-latest")

WORKFLOWAI_API_URL = os.getenv("WORKFLOWAI_API_URL")
WORKFLOWAI_API_URL = os.getenv("WORKFLOWAI_API_URL", "https://run.workflowai.com")


def _default_app_url():
Expand Down
36 changes: 34 additions & 2 deletions workflowai/env_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
import importlib
import os
from typing import Optional
from unittest.mock import patch

import pytest

from .env import _default_app_url # pyright: ignore[reportPrivateUsage]
from workflowai import env


# Check what happens when the environment is fully empty
@patch.dict(os.environ, clear=True)
def test_default_app_url_clear_env():
# We need to reload the env module so that the environment variables are read again
importlib.reload(env)
assert env.WORKFLOWAI_API_URL == "https://run.workflowai.com"
assert env.WORKFLOWAI_APP_URL == "https://workflowai.com"


# Check with the default app url when an api url is provided
@patch.dict(os.environ, {"WORKFLOWAI_API_URL": "https://run.workflowai.dev"}, clear=True)
def test_default_app_url_dev_url():
importlib.reload(env)
assert env.WORKFLOWAI_API_URL == "https://run.workflowai.dev"
assert env.WORKFLOWAI_APP_URL == "https://workflowai.dev"


# Check the app url when both api url and app url are provided
@patch.dict(
os.environ,
{"WORKFLOWAI_API_URL": "https://run.workflowai.dev", "WORKFLOWAI_APP_URL": "https://workflowai.app"},
clear=True,
)
def test_with_app_url():
importlib.reload(env)
assert env.WORKFLOWAI_API_URL == "https://run.workflowai.dev"
assert env.WORKFLOWAI_APP_URL == "https://workflowai.app"


@pytest.mark.parametrize(
Expand All @@ -16,5 +47,6 @@
],
)
def test_default_app_url(api_url: Optional[str], expected: str):
# Importing here to avoid setting the environment variables before the test
with patch("workflowai.env.WORKFLOWAI_API_URL", api_url):
assert _default_app_url() == expected
assert env._default_app_url() == expected # pyright: ignore[reportPrivateUsage]