vellum-ai 0.10.9__py3-none-any.whl → 0.11.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. vellum/client/core/client_wrapper.py +1 -1
  2. vellum/evaluations/resources.py +7 -12
  3. vellum/evaluations/utils/env.py +1 -3
  4. vellum/evaluations/utils/paginator.py +0 -1
  5. vellum/evaluations/utils/typing.py +1 -1
  6. vellum/evaluations/utils/uuid.py +1 -1
  7. vellum/plugins/vellum_mypy.py +3 -1
  8. vellum/workflows/events/node.py +7 -6
  9. vellum/workflows/events/tests/test_event.py +0 -1
  10. vellum/workflows/events/types.py +0 -1
  11. vellum/workflows/events/workflow.py +19 -1
  12. vellum/workflows/nodes/bases/base.py +17 -56
  13. vellum/workflows/nodes/bases/tests/test_base_node.py +0 -1
  14. vellum/workflows/nodes/core/templating_node/node.py +1 -0
  15. vellum/workflows/nodes/core/try_node/node.py +2 -2
  16. vellum/workflows/nodes/core/try_node/tests/test_node.py +1 -3
  17. vellum/workflows/nodes/displayable/bases/api_node/node.py +1 -1
  18. vellum/workflows/nodes/displayable/bases/base_prompt_node/node.py +0 -1
  19. vellum/workflows/nodes/displayable/bases/inline_prompt_node/node.py +0 -1
  20. vellum/workflows/nodes/displayable/bases/prompt_deployment_node.py +2 -1
  21. vellum/workflows/nodes/displayable/bases/search_node.py +0 -1
  22. vellum/workflows/nodes/displayable/code_execution_node/tests/test_code_execution_node.py +0 -1
  23. vellum/workflows/nodes/displayable/code_execution_node/utils.py +3 -2
  24. vellum/workflows/nodes/displayable/conditional_node/node.py +1 -1
  25. vellum/workflows/nodes/displayable/guardrail_node/node.py +0 -1
  26. vellum/workflows/nodes/displayable/inline_prompt_node/node.py +1 -0
  27. vellum/workflows/nodes/displayable/prompt_deployment_node/node.py +3 -1
  28. vellum/workflows/nodes/displayable/search_node/node.py +1 -0
  29. vellum/workflows/nodes/displayable/subworkflow_deployment_node/node.py +3 -2
  30. vellum/workflows/nodes/displayable/tests/test_inline_text_prompt_node.py +10 -7
  31. vellum/workflows/nodes/displayable/tests/test_search_node_wth_text_output.py +0 -1
  32. vellum/workflows/outputs/base.py +2 -4
  33. vellum/workflows/ports/node_ports.py +1 -1
  34. vellum/workflows/runner/runner.py +152 -191
  35. vellum/workflows/state/base.py +0 -2
  36. vellum/workflows/types/core.py +1 -0
  37. vellum/workflows/types/tests/test_utils.py +1 -0
  38. vellum/workflows/types/utils.py +0 -1
  39. vellum/workflows/utils/functions.py +74 -0
  40. vellum/workflows/utils/tests/test_functions.py +171 -0
  41. vellum/workflows/utils/tests/test_vellum_variables.py +0 -1
  42. vellum/workflows/utils/vellum_variables.py +2 -2
  43. vellum/workflows/workflows/base.py +74 -34
  44. vellum/workflows/workflows/event_filters.py +4 -12
  45. {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.0.dist-info}/METADATA +1 -1
  46. {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.0.dist-info}/RECORD +96 -90
  47. vellum_cli/__init__.py +147 -13
  48. vellum_cli/config.py +0 -1
  49. vellum_cli/image_push.py +1 -1
  50. vellum_cli/pull.py +29 -19
  51. vellum_cli/push.py +9 -10
  52. vellum_cli/tests/__init__.py +0 -0
  53. vellum_cli/tests/conftest.py +40 -0
  54. vellum_cli/tests/test_main.py +11 -0
  55. vellum_cli/tests/test_pull.py +125 -71
  56. vellum_cli/tests/test_push.py +173 -0
  57. vellum_ee/workflows/display/nodes/base_node_display.py +3 -2
  58. vellum_ee/workflows/display/nodes/base_node_vellum_display.py +2 -2
  59. vellum_ee/workflows/display/nodes/get_node_display_class.py +1 -1
  60. vellum_ee/workflows/display/nodes/tests/test_base_node_display.py +1 -1
  61. vellum_ee/workflows/display/nodes/vellum/__init__.py +1 -1
  62. vellum_ee/workflows/display/nodes/vellum/api_node.py +4 -7
  63. vellum_ee/workflows/display/nodes/vellum/conditional_node.py +39 -22
  64. vellum_ee/workflows/display/nodes/vellum/error_node.py +3 -3
  65. vellum_ee/workflows/display/nodes/vellum/final_output_node.py +0 -2
  66. vellum_ee/workflows/display/nodes/vellum/guardrail_node.py +1 -1
  67. vellum_ee/workflows/display/nodes/vellum/inline_prompt_node.py +1 -1
  68. vellum_ee/workflows/display/nodes/vellum/inline_subworkflow_node.py +4 -2
  69. vellum_ee/workflows/display/nodes/vellum/map_node.py +11 -5
  70. vellum_ee/workflows/display/nodes/vellum/merge_node.py +2 -2
  71. vellum_ee/workflows/display/nodes/vellum/note_node.py +1 -3
  72. vellum_ee/workflows/display/nodes/vellum/prompt_deployment_node.py +1 -1
  73. vellum_ee/workflows/display/nodes/vellum/search_node.py +1 -1
  74. vellum_ee/workflows/display/nodes/vellum/subworkflow_deployment_node.py +1 -1
  75. vellum_ee/workflows/display/nodes/vellum/templating_node.py +1 -1
  76. vellum_ee/workflows/display/nodes/vellum/tests/test_utils.py +5 -5
  77. vellum_ee/workflows/display/nodes/vellum/utils.py +4 -4
  78. vellum_ee/workflows/display/tests/test_vellum_workflow_display.py +45 -0
  79. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_api_node_serialization.py +13 -24
  80. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_conditional_node_serialization.py +13 -39
  81. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_guardrail_node_serialization.py +2 -2
  82. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_inline_subworkflow_serialization.py +62 -58
  83. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_map_node_serialization.py +25 -4
  84. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_merge_node_serialization.py +2 -1
  85. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_prompt_deployment_serialization.py +2 -2
  86. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_subworkflow_deployment_serialization.py +2 -2
  87. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_terminal_node_serialization.py +1 -1
  88. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_try_node_serialization.py +2 -1
  89. vellum_ee/workflows/display/tests/workflow_serialization/test_complex_terminal_node_serialization.py +2 -2
  90. vellum_ee/workflows/display/types.py +4 -4
  91. vellum_ee/workflows/display/utils/vellum.py +2 -6
  92. vellum_ee/workflows/display/workflows/get_vellum_workflow_display_class.py +4 -1
  93. vellum_ee/workflows/display/workflows/vellum_workflow_display.py +6 -2
  94. vellum/workflows/runner/types.py +0 -16
  95. {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.0.dist-info}/LICENSE +0 -0
  96. {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.0.dist-info}/WHEEL +0 -0
  97. {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.0.dist-info}/entry_points.txt +0 -0
vellum_cli/pull.py CHANGED
@@ -7,10 +7,28 @@ from typing import Optional
7
7
  from dotenv import load_dotenv
8
8
 
9
9
  from vellum.workflows.vellum_client import create_vellum_client
10
- from vellum_cli.config import WorkflowConfig, load_vellum_cli_config
10
+ from vellum_cli.config import VellumCliConfig, WorkflowConfig, load_vellum_cli_config
11
11
  from vellum_cli.logger import load_cli_logger
12
12
 
13
13
 
14
+ def resolve_workflow_config(
15
+ config: VellumCliConfig,
16
+ module: Optional[str] = None,
17
+ workflow_sandbox_id: Optional[str] = None,
18
+ ) -> Optional[WorkflowConfig]:
19
+ if module:
20
+ return next((w for w in config.workflows if w.module == module), None)
21
+ elif workflow_sandbox_id:
22
+ return WorkflowConfig(
23
+ workflow_sandbox_id=workflow_sandbox_id,
24
+ module=f"workflow_{workflow_sandbox_id.split('-')[0]}",
25
+ )
26
+ elif config.workflows:
27
+ return config.workflows[0]
28
+
29
+ return None
30
+
31
+
14
32
  def pull_command(
15
33
  module: Optional[str] = None,
16
34
  workflow_sandbox_id: Optional[str] = None,
@@ -21,24 +39,15 @@ def pull_command(
21
39
  logger = load_cli_logger()
22
40
  config = load_vellum_cli_config()
23
41
 
24
- workflow_config = (
25
- next((w for w in config.workflows if w.module == module), None)
26
- if module
27
- else (config.workflows[0] if config.workflows else None)
42
+ workflow_config = resolve_workflow_config(
43
+ config,
44
+ module,
45
+ workflow_sandbox_id,
28
46
  )
29
- save_lock_file = False
30
- if workflow_config is None:
31
- if module:
32
- raise ValueError(f"No workflow config for '{module}' found in project to pull.")
33
- elif workflow_sandbox_id:
34
- workflow_config = WorkflowConfig(
35
- workflow_sandbox_id=workflow_sandbox_id,
36
- module=f"workflow_{workflow_sandbox_id.split('-')[0]}",
37
- )
38
- config.workflows.append(workflow_config)
39
- save_lock_file = True
40
- else:
41
- raise ValueError("No workflow config found in project to pull from.")
47
+ save_lock_file = not module
48
+
49
+ if not workflow_config:
50
+ raise ValueError("No workflow config found in project to pull from.")
42
51
 
43
52
  if not workflow_config.workflow_sandbox_id:
44
53
  raise ValueError("No workflow sandbox ID found in project to pull from.")
@@ -92,7 +101,8 @@ def pull_command(
92
101
 
93
102
  if include_json:
94
103
  logger.warning(
95
- "The pulled JSON representation of the Workflow should be used for debugging purposely only. Its schema should be considered unstable and subject to change at any time."
104
+ """The pulled JSON representation of the Workflow should be used for debugging purposely only. \
105
+ Its schema should be considered unstable and subject to change at any time."""
96
106
  )
97
107
 
98
108
  if save_lock_file:
vellum_cli/push.py CHANGED
@@ -10,23 +10,22 @@ from dotenv import load_dotenv
10
10
 
11
11
  from vellum.resources.workflows.client import OMIT
12
12
  from vellum.types import WorkflowPushDeploymentConfigRequest
13
-
13
+ from vellum.workflows.utils.names import snake_to_title_case
14
+ from vellum.workflows.vellum_client import create_vellum_client
15
+ from vellum.workflows.workflows.base import BaseWorkflow
14
16
  from vellum_cli.config import WorkflowDeploymentConfig, load_vellum_cli_config
15
17
  from vellum_cli.logger import load_cli_logger
16
18
  from vellum_ee.workflows.display.workflows.get_vellum_workflow_display_class import get_workflow_display
17
19
  from vellum_ee.workflows.display.workflows.vellum_workflow_display import VellumWorkflowDisplay
18
- from vellum.workflows.utils.names import snake_to_title_case
19
- from vellum.workflows.vellum_client import create_vellum_client
20
- from vellum.workflows.workflows.base import BaseWorkflow
21
20
 
22
21
 
23
22
  def push_command(
24
- module: Optional[str],
25
- deploy: Optional[bool],
26
- deployment_label: Optional[str],
27
- deployment_name: Optional[str],
28
- deployment_description: Optional[str],
29
- release_tags: Optional[List[str]],
23
+ module: Optional[str] = None,
24
+ deploy: Optional[bool] = None,
25
+ deployment_label: Optional[str] = None,
26
+ deployment_name: Optional[str] = None,
27
+ deployment_description: Optional[str] = None,
28
+ release_tags: Optional[List[str]] = None,
30
29
  ) -> None:
31
30
  load_dotenv()
32
31
  logger = load_cli_logger()
File without changes
@@ -0,0 +1,40 @@
1
+ import pytest
2
+ import os
3
+ import shutil
4
+ import tempfile
5
+ from uuid import uuid4
6
+ from typing import Any, Callable, Dict, Generator, Tuple
7
+
8
+ import tomli_w
9
+
10
+
11
+ @pytest.fixture
12
+ def mock_module() -> Generator[Tuple[str, str, Callable[[Dict[str, Any]], None]], None, None]:
13
+ current_dir = os.getcwd()
14
+ temp_dir = tempfile.mkdtemp()
15
+ os.chdir(temp_dir)
16
+ module = "examples.mock"
17
+
18
+ def set_pyproject_toml(vellum_config: Dict[str, Any]) -> None:
19
+ pyproject_toml_path = os.path.join(temp_dir, "pyproject.toml")
20
+ with open(pyproject_toml_path, "wb") as f:
21
+ tomli_w.dump(
22
+ {"tool": {"vellum": vellum_config}},
23
+ f,
24
+ )
25
+
26
+ set_pyproject_toml(
27
+ {
28
+ "workflows": [
29
+ {
30
+ "module": module,
31
+ "workflow_sandbox_id": str(uuid4()),
32
+ }
33
+ ]
34
+ }
35
+ )
36
+
37
+ yield temp_dir, module, set_pyproject_toml
38
+
39
+ os.chdir(current_dir)
40
+ shutil.rmtree(temp_dir)
@@ -0,0 +1,11 @@
1
+ import subprocess
2
+
3
+
4
+ def test_cli__root():
5
+ """
6
+ A test sanity ensuring that the CLI is accessible
7
+ """
8
+
9
+ result = subprocess.run(["vellum", "--help"], capture_output=True)
10
+ assert result.returncode == 0
11
+ assert result.stdout.startswith(b"Usage: vellum")
@@ -1,18 +1,16 @@
1
1
  import pytest
2
2
  import io
3
3
  import os
4
- import shutil
5
4
  import tempfile
6
5
  from uuid import uuid4
7
6
  import zipfile
8
- from typing import Generator, Tuple
9
7
 
10
- import tomli_w
8
+ from click.testing import CliRunner
11
9
 
12
- from vellum_cli.pull import pull_command
10
+ from vellum_cli import main as cli_main
13
11
 
14
12
 
15
- def zip_file_map(file_map: dict[str, str]) -> bytes:
13
+ def _zip_file_map(file_map: dict[str, str]) -> bytes:
16
14
  # Create an in-memory bytes buffer to store the zip
17
15
  zip_buffer = io.BytesIO()
18
16
 
@@ -28,47 +26,60 @@ def zip_file_map(file_map: dict[str, str]) -> bytes:
28
26
  return zip_bytes
29
27
 
30
28
 
31
- @pytest.fixture
32
- def mock_module() -> Generator[Tuple[str, str], None, None]:
33
- current_dir = os.getcwd()
34
- temp_dir = tempfile.mkdtemp()
35
- os.chdir(temp_dir)
36
- module = "examples.mock"
37
-
38
- with open(os.path.join(temp_dir, "pyproject.toml"), "wb") as f:
39
- tomli_w.dump(
40
- {
41
- "tool": {
42
- "vellum": {
43
- "workflows": [
44
- {
45
- "module": module,
46
- "workflow_sandbox_id": str(uuid4()),
47
- }
48
- ]
49
- }
50
- }
51
- },
52
- f,
53
- )
29
+ @pytest.mark.parametrize(
30
+ "base_command",
31
+ [
32
+ ["pull"],
33
+ ["workflows", "pull"],
34
+ ],
35
+ ids=["pull", "workflows_pull"],
36
+ )
37
+ def test_pull(vellum_client, mock_module, base_command):
38
+ # GIVEN a module on the user's filesystem
39
+ temp_dir, module, _ = mock_module
54
40
 
55
- yield temp_dir, module
41
+ # AND the workflow pull API call returns a zip file
42
+ vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
56
43
 
57
- os.chdir(current_dir)
58
- shutil.rmtree(temp_dir)
44
+ # WHEN the user runs the pull command
45
+ runner = CliRunner()
46
+ result = runner.invoke(cli_main, base_command + [module])
59
47
 
48
+ # THEN the command returns successfully
49
+ assert result.exit_code == 0
60
50
 
61
- def test_pull(vellum_client, mock_module):
51
+ # AND the workflow.py file is written to the module directory
52
+ workflow_py = os.path.join(temp_dir, *module.split("."), "workflow.py")
53
+ assert os.path.exists(workflow_py)
54
+ with open(workflow_py) as f:
55
+ assert f.read() == "print('hello')"
56
+
57
+
58
+ def test_pull__second_module(vellum_client, mock_module):
62
59
  # GIVEN a module on the user's filesystem
63
- temp_dir, module = mock_module
60
+ temp_dir, module, set_pyproject_toml = mock_module
64
61
 
65
62
  # AND the workflow pull API call returns a zip file
66
- vellum_client.workflows.pull.return_value = iter([zip_file_map({"workflow.py": "print('hello')"})])
63
+ vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
64
+
65
+ # AND the module we're about to pull is configured second
66
+ set_pyproject_toml(
67
+ {
68
+ "workflows": [
69
+ {"module": "another.module", "workflow_sandbox_id": str(uuid4())},
70
+ {"module": module, "workflow_sandbox_id": str(uuid4())},
71
+ ]
72
+ }
73
+ )
67
74
 
68
75
  # WHEN the user runs the pull command
69
- pull_command(module)
76
+ runner = CliRunner()
77
+ result = runner.invoke(cli_main, ["pull", module])
70
78
 
71
- # THEN the workflow.py file is written to the module directory
79
+ # THEN the command returns successfully
80
+ assert result.exit_code == 0
81
+
82
+ # AND the workflow.py file is written to the module directory
72
83
  workflow_py = os.path.join(temp_dir, *module.split("."), "workflow.py")
73
84
  assert os.path.exists(workflow_py)
74
85
  with open(workflow_py) as f:
@@ -80,7 +91,7 @@ def test_pull__sandbox_id_with_no_config(vellum_client):
80
91
  workflow_sandbox_id = "87654321-0000-0000-0000-000000000000"
81
92
 
82
93
  # AND the workflow pull API call returns a zip file
83
- vellum_client.workflows.pull.return_value = iter([zip_file_map({"workflow.py": "print('hello')"})])
94
+ vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
84
95
 
85
96
  # AND we are currently in a new directory
86
97
  current_dir = os.getcwd()
@@ -88,10 +99,14 @@ def test_pull__sandbox_id_with_no_config(vellum_client):
88
99
  os.chdir(temp_dir)
89
100
 
90
101
  # WHEN the user runs the pull command with the workflow sandbox id and no module
91
- pull_command(workflow_sandbox_id=workflow_sandbox_id)
102
+ runner = CliRunner()
103
+ result = runner.invoke(cli_main, ["workflows", "pull", "--workflow-sandbox-id", workflow_sandbox_id])
92
104
  os.chdir(current_dir)
93
105
 
94
- # THEN the pull api is called with exclude_code=True
106
+ # THEN the command returns successfully
107
+ assert result.exit_code == 0
108
+
109
+ # AND the pull api is called with the workflow sandbox id
95
110
  vellum_client.workflows.pull.assert_called_once()
96
111
  workflow_py = os.path.join(temp_dir, "workflow_87654321", "workflow.py")
97
112
  assert os.path.exists(workflow_py)
@@ -99,12 +114,41 @@ def test_pull__sandbox_id_with_no_config(vellum_client):
99
114
  assert f.read() == "print('hello')"
100
115
 
101
116
 
117
+ def test_pull__sandbox_id_with_other_workflow_configured(vellum_client, mock_module):
118
+ # GIVEN a pyproject.toml with a workflow configured
119
+ temp_dir, _, _ = mock_module
120
+
121
+ # AND a different workflow sandbox id
122
+ workflow_sandbox_id = "87654321-0000-0000-0000-000000000000"
123
+
124
+ # AND the workflow pull API call returns a zip file
125
+ vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
126
+
127
+ # WHEN the user runs the pull command with the new workflow sandbox id
128
+ runner = CliRunner()
129
+ result = runner.invoke(cli_main, ["workflows", "pull", "--workflow-sandbox-id", workflow_sandbox_id])
130
+
131
+ # THEN the command returns successfully
132
+ assert result.exit_code == 0
133
+
134
+ # AND the pull api is called with the new workflow sandbox id
135
+ vellum_client.workflows.pull.assert_called_once()
136
+ call_args = vellum_client.workflows.pull.call_args.args
137
+ assert call_args[0] == workflow_sandbox_id
138
+
139
+ # AND the workflow.py file is written to the module directory
140
+ workflow_py = os.path.join(temp_dir, "workflow_87654321", "workflow.py")
141
+ assert os.path.exists(workflow_py)
142
+ with open(workflow_py) as f:
143
+ assert f.read() == "print('hello')"
144
+
145
+
102
146
  def test_pull__remove_missing_files(vellum_client, mock_module):
103
147
  # GIVEN a module on the user's filesystem
104
- temp_dir, module = mock_module
148
+ temp_dir, module, _ = mock_module
105
149
 
106
150
  # AND the workflow pull API call returns a zip file
107
- vellum_client.workflows.pull.return_value = iter([zip_file_map({"workflow.py": "print('hello')"})])
151
+ vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
108
152
 
109
153
  # AND there is already a different file in the module directory
110
154
  other_file_path = os.path.join(temp_dir, *module.split("."), "other_file.py")
@@ -113,9 +157,13 @@ def test_pull__remove_missing_files(vellum_client, mock_module):
113
157
  f.write("print('hello')")
114
158
 
115
159
  # WHEN the user runs the pull command
116
- pull_command(module)
160
+ runner = CliRunner()
161
+ result = runner.invoke(cli_main, ["pull", module])
162
+
163
+ # THEN the command returns successfully
164
+ assert result.exit_code == 0
117
165
 
118
- # THEN the workflow.py file is written to the module directory
166
+ # AND the workflow.py file is written to the module directory
119
167
  assert os.path.exists(os.path.join(temp_dir, *module.split("."), "workflow.py"))
120
168
  with open(os.path.join(temp_dir, *module.split("."), "workflow.py")) as f:
121
169
  assert f.read() == "print('hello')"
@@ -126,10 +174,10 @@ def test_pull__remove_missing_files(vellum_client, mock_module):
126
174
 
127
175
  def test_pull__remove_missing_files__ignore_pattern(vellum_client, mock_module):
128
176
  # GIVEN a module on the user's filesystem
129
- temp_dir, module = mock_module
177
+ temp_dir, module, set_pyproject_toml = mock_module
130
178
 
131
179
  # AND the workflow pull API call returns a zip file
132
- vellum_client.workflows.pull.return_value = iter([zip_file_map({"workflow.py": "print('hello')"})])
180
+ vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
133
181
 
134
182
  # AND there is already a different file in the module directory
135
183
  other_file_path = os.path.join(temp_dir, *module.split("."), "other_file.py")
@@ -144,28 +192,26 @@ def test_pull__remove_missing_files__ignore_pattern(vellum_client, mock_module):
144
192
  f.write("print('hello')")
145
193
 
146
194
  # AND the ignore pattern is set to tests
147
- with open(os.path.join(temp_dir, "pyproject.toml"), "wb") as f:
148
- tomli_w.dump(
149
- {
150
- "tool": {
151
- "vellum": {
152
- "workflows": [
153
- {
154
- "module": module,
155
- "workflow_sandbox_id": str(uuid4()),
156
- "ignore": "tests/*",
157
- }
158
- ]
159
- }
195
+ set_pyproject_toml(
196
+ {
197
+ "workflows": [
198
+ {
199
+ "module": module,
200
+ "workflow_sandbox_id": str(uuid4()),
201
+ "ignore": "tests/*",
160
202
  }
161
- },
162
- f,
163
- )
203
+ ]
204
+ }
205
+ )
164
206
 
165
207
  # WHEN the user runs the pull command
166
- pull_command(module)
208
+ runner = CliRunner()
209
+ result = runner.invoke(cli_main, ["pull", module])
210
+
211
+ # THEN the command returns successfully
212
+ assert result.exit_code == 0
167
213
 
168
- # THEN the workflow.py file is written to the module directory
214
+ # AND the workflow.py file is written to the module directory
169
215
  assert os.path.exists(os.path.join(temp_dir, *module.split("."), "workflow.py"))
170
216
  with open(os.path.join(temp_dir, *module.split("."), "workflow.py")) as f:
171
217
  assert f.read() == "print('hello')"
@@ -179,17 +225,21 @@ def test_pull__remove_missing_files__ignore_pattern(vellum_client, mock_module):
179
225
 
180
226
  def test_pull__include_json(vellum_client, mock_module):
181
227
  # GIVEN a module on the user's filesystem
182
- _, module = mock_module
228
+ _, module, __ = mock_module
183
229
 
184
230
  # AND the workflow pull API call returns a zip file
185
231
  vellum_client.workflows.pull.return_value = iter(
186
- [zip_file_map({"workflow.py": "print('hello')", "workflow.json": "{}"})]
232
+ [_zip_file_map({"workflow.py": "print('hello')", "workflow.json": "{}"})]
187
233
  )
188
234
 
189
235
  # WHEN the user runs the pull command
190
- pull_command(module, include_json=True)
236
+ runner = CliRunner()
237
+ result = runner.invoke(cli_main, ["pull", module, "--include-json"])
191
238
 
192
- # THEN the pull api is called with include_json=True
239
+ # THEN the command returns successfully
240
+ assert result.exit_code == 0
241
+
242
+ # AND the pull api is called with include_json=True
193
243
  vellum_client.workflows.pull.assert_called_once()
194
244
  call_args = vellum_client.workflows.pull.call_args.kwargs
195
245
  assert call_args["request_options"]["additional_query_parameters"] == {"include_json": True}
@@ -197,17 +247,21 @@ def test_pull__include_json(vellum_client, mock_module):
197
247
 
198
248
  def test_pull__exclude_code(vellum_client, mock_module):
199
249
  # GIVEN a module on the user's filesystem
200
- _, module = mock_module
250
+ _, module, __ = mock_module
201
251
 
202
252
  # AND the workflow pull API call returns a zip file
203
253
  vellum_client.workflows.pull.return_value = iter(
204
- [zip_file_map({"workflow.py": "print('hello')", "workflow.json": "{}"})]
254
+ [_zip_file_map({"workflow.py": "print('hello')", "workflow.json": "{}"})]
205
255
  )
206
256
 
207
257
  # WHEN the user runs the pull command
208
- pull_command(module, exclude_code=True)
258
+ runner = CliRunner()
259
+ result = runner.invoke(cli_main, ["pull", module, "--exclude-code"])
260
+
261
+ # THEN the command returns successfully
262
+ assert result.exit_code == 0
209
263
 
210
- # THEN the pull api is called with exclude_code=True
264
+ # AND the pull api is called with exclude_code=True
211
265
  vellum_client.workflows.pull.assert_called_once()
212
266
  call_args = vellum_client.workflows.pull.call_args.kwargs
213
267
  assert call_args["request_options"]["additional_query_parameters"] == {"exclude_code": True}
@@ -0,0 +1,173 @@
1
+ import pytest
2
+ import io
3
+ import json
4
+ import os
5
+ import tarfile
6
+ from uuid import uuid4
7
+
8
+ from click.testing import CliRunner
9
+
10
+ from vellum.client.types.workflow_push_response import WorkflowPushResponse
11
+ from vellum.evaluations.utils.uuid import is_valid_uuid
12
+ from vellum_cli import main as cli_main
13
+
14
+
15
+ def _extract_tar_gz(tar_gz_bytes: bytes) -> dict[str, str]:
16
+ files = {}
17
+ with tarfile.open(fileobj=io.BytesIO(tar_gz_bytes), mode="r:gz") as tar:
18
+ for member in tar.getmembers():
19
+ if not member.isfile():
20
+ continue
21
+ content = tar.extractfile(member)
22
+ if content is None:
23
+ continue
24
+
25
+ files[member.name] = content.read().decode("latin-1")
26
+
27
+ return files
28
+
29
+
30
+ def test_push__no_config(mock_module):
31
+ # GIVEN no config file set
32
+ _, _, set_pyproject_toml = mock_module
33
+ set_pyproject_toml({"workflows": []})
34
+
35
+ # WHEN calling `vellum push`
36
+ runner = CliRunner()
37
+ result = runner.invoke(cli_main, ["push"])
38
+
39
+ # THEN it should fail
40
+ assert result.exit_code == 1
41
+ assert result.exception
42
+ assert str(result.exception) == "No Workflows found in project to push."
43
+
44
+
45
+ def test_push__multiple_workflows_configured__no_module_specified(mock_module):
46
+ # GIVEN multiple workflows configured
47
+ _, _, set_pyproject_toml = mock_module
48
+ set_pyproject_toml({"workflows": [{"module": "examples.mock"}, {"module": "examples.mock2"}]})
49
+
50
+ # WHEN calling `vellum push` without a module specified
51
+ runner = CliRunner()
52
+ result = runner.invoke(cli_main, ["push"])
53
+
54
+ # THEN it should fail
55
+ assert result.exit_code == 1
56
+ assert result.exception
57
+ assert (
58
+ str(result.exception)
59
+ == "Multiple workflows found in project to push. Pushing only a single workflow is supported."
60
+ )
61
+
62
+
63
+ def test_push__multiple_workflows_configured__not_found_module(mock_module):
64
+ # GIVEN multiple workflows configured
65
+ _, module, set_pyproject_toml = mock_module
66
+ set_pyproject_toml({"workflows": [{"module": "examples.mock2"}, {"module": "examples.mock3"}]})
67
+
68
+ # WHEN calling `vellum push` with a module that doesn't exist
69
+ runner = CliRunner()
70
+ result = runner.invoke(cli_main, ["push", module])
71
+
72
+ # THEN it should fail
73
+ assert result.exit_code == 1
74
+ assert result.exception
75
+ assert str(result.exception) == f"No workflow config for '{module}' found in project to push."
76
+
77
+
78
+ @pytest.mark.parametrize(
79
+ "base_command",
80
+ [
81
+ ["push"],
82
+ ["workflows", "push"],
83
+ ],
84
+ ids=["push", "workflows_push"],
85
+ )
86
+ def test_push__happy_path(mock_module, vellum_client, base_command):
87
+ # GIVEN a single workflow configured
88
+ temp_dir, module, _ = mock_module
89
+
90
+ # AND a workflow exists in the module successfully
91
+ base_dir = os.path.join(temp_dir, *module.split("."))
92
+ os.makedirs(base_dir, exist_ok=True)
93
+ workflow_py_file_content = """\
94
+ from vellum.workflows import BaseWorkflow
95
+
96
+ class ExampleWorkflow(BaseWorkflow):
97
+ pass
98
+ """
99
+ with open(os.path.join(temp_dir, *module.split("."), "workflow.py"), "w") as f:
100
+ f.write(workflow_py_file_content)
101
+
102
+ # AND the push API call returns successfully
103
+ vellum_client.workflows.push.return_value = WorkflowPushResponse(
104
+ workflow_sandbox_id=str(uuid4()),
105
+ )
106
+
107
+ # WHEN calling `vellum push`
108
+ runner = CliRunner()
109
+ result = runner.invoke(cli_main, base_command + [module])
110
+
111
+ # THEN it should succeed
112
+ assert result.exit_code == 0
113
+
114
+ # AND we should have called the push API with the correct args
115
+ vellum_client.workflows.push.assert_called_once()
116
+ call_args = vellum_client.workflows.push.call_args.kwargs
117
+ assert json.loads(call_args["exec_config"])["workflow_raw_data"]["definition"]["name"] == "ExampleWorkflow"
118
+ assert call_args["label"] == "Mock"
119
+ assert is_valid_uuid(call_args["workflow_sandbox_id"])
120
+ assert call_args["artifact"].name == "examples__mock.tar.gz"
121
+ assert "deplyment_config" not in call_args
122
+
123
+ extracted_files = _extract_tar_gz(call_args["artifact"].read())
124
+ assert extracted_files["workflow.py"] == workflow_py_file_content
125
+
126
+
127
+ @pytest.mark.parametrize(
128
+ "base_command",
129
+ [
130
+ ["push"],
131
+ ["workflows", "push"],
132
+ ],
133
+ ids=["push", "workflows_push"],
134
+ )
135
+ def test_push__deployment(mock_module, vellum_client, base_command):
136
+ # GIVEN a single workflow configured
137
+ temp_dir, module, _ = mock_module
138
+
139
+ # AND a workflow exists in the module successfully
140
+ base_dir = os.path.join(temp_dir, *module.split("."))
141
+ os.makedirs(base_dir, exist_ok=True)
142
+ workflow_py_file_content = """\
143
+ from vellum.workflows import BaseWorkflow
144
+
145
+ class ExampleWorkflow(BaseWorkflow):
146
+ pass
147
+ """
148
+ with open(os.path.join(temp_dir, *module.split("."), "workflow.py"), "w") as f:
149
+ f.write(workflow_py_file_content)
150
+
151
+ # AND the push API call returns successfully
152
+ vellum_client.workflows.push.return_value = WorkflowPushResponse(
153
+ workflow_sandbox_id=str(uuid4()),
154
+ )
155
+
156
+ # WHEN calling `vellum push`
157
+ runner = CliRunner()
158
+ result = runner.invoke(cli_main, base_command + [module, "--deploy"])
159
+
160
+ # THEN it should succeed
161
+ assert result.exit_code == 0
162
+
163
+ # AND we should have called the push API with the correct args
164
+ vellum_client.workflows.push.assert_called_once()
165
+ call_args = vellum_client.workflows.push.call_args.kwargs
166
+ assert json.loads(call_args["exec_config"])["workflow_raw_data"]["definition"]["name"] == "ExampleWorkflow"
167
+ assert call_args["label"] == "Mock"
168
+ assert is_valid_uuid(call_args["workflow_sandbox_id"])
169
+ assert call_args["artifact"].name == "examples__mock.tar.gz"
170
+ assert call_args["deployment_config"] == "{}"
171
+
172
+ extracted_files = _extract_tar_gz(call_args["artifact"].read())
173
+ assert extracted_files["workflow.py"] == workflow_py_file_content
@@ -100,8 +100,9 @@ class BaseNodeDisplay(Generic[NodeType]):
100
100
  if origin is dict and isinstance(node_display_attribute, dict):
101
101
  if len(args) == 2:
102
102
  key_type, value_type = args
103
- if all(isinstance(k, key_type) and isinstance(v, value_type) for k, v in
104
- node_display_attribute.items()):
103
+ if all(
104
+ isinstance(k, key_type) and isinstance(v, value_type) for k, v in node_display_attribute.items()
105
+ ):
105
106
  return cast(_NodeDisplayAttrType, node_display_attribute)
106
107
  raise ValueError(f"Node {cls.__name__} must define an explicit {attribute} of type {attribute_type}.")
107
108
 
@@ -1,12 +1,12 @@
1
1
  from uuid import UUID
2
2
  from typing import ClassVar, Dict, Optional
3
3
 
4
+ from vellum.workflows.ports import Port
5
+ from vellum.workflows.types.generics import NodeType
4
6
  from vellum_ee.workflows.display.nodes.base_node_display import BaseNodeDisplay
5
7
  from vellum_ee.workflows.display.nodes.types import PortDisplay
6
8
  from vellum_ee.workflows.display.utils.uuids import uuid4_from_hash
7
9
  from vellum_ee.workflows.display.vellum import NodeDisplayData
8
- from vellum.workflows.ports import Port
9
- from vellum.workflows.types.generics import NodeType
10
10
 
11
11
 
12
12
  class BaseNodeVellumDisplay(BaseNodeDisplay[NodeType]):