vellum-ai 0.10.9__py3-none-any.whl → 0.11.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- vellum/__init__.py +16 -0
- vellum/client/core/client_wrapper.py +1 -1
- vellum/client/types/__init__.py +28 -0
- vellum/client/types/test_suite_run_exec_config.py +7 -1
- vellum/client/types/test_suite_run_exec_config_request.py +8 -0
- vellum/client/types/test_suite_run_prompt_sandbox_history_item_exec_config.py +31 -0
- vellum/client/types/test_suite_run_prompt_sandbox_history_item_exec_config_data.py +27 -0
- vellum/client/types/test_suite_run_prompt_sandbox_history_item_exec_config_data_request.py +27 -0
- vellum/client/types/test_suite_run_prompt_sandbox_history_item_exec_config_request.py +31 -0
- vellum/client/types/test_suite_run_workflow_sandbox_history_item_exec_config.py +31 -0
- vellum/client/types/test_suite_run_workflow_sandbox_history_item_exec_config_data.py +27 -0
- vellum/client/types/test_suite_run_workflow_sandbox_history_item_exec_config_data_request.py +27 -0
- vellum/client/types/test_suite_run_workflow_sandbox_history_item_exec_config_request.py +31 -0
- vellum/evaluations/resources.py +7 -12
- vellum/evaluations/utils/env.py +1 -3
- vellum/evaluations/utils/paginator.py +0 -1
- vellum/evaluations/utils/typing.py +1 -1
- vellum/evaluations/utils/uuid.py +1 -1
- vellum/plugins/vellum_mypy.py +3 -1
- vellum/types/test_suite_run_prompt_sandbox_history_item_exec_config.py +3 -0
- vellum/types/test_suite_run_prompt_sandbox_history_item_exec_config_data.py +3 -0
- vellum/types/test_suite_run_prompt_sandbox_history_item_exec_config_data_request.py +3 -0
- vellum/types/test_suite_run_prompt_sandbox_history_item_exec_config_request.py +3 -0
- vellum/types/test_suite_run_workflow_sandbox_history_item_exec_config.py +3 -0
- vellum/types/test_suite_run_workflow_sandbox_history_item_exec_config_data.py +3 -0
- vellum/types/test_suite_run_workflow_sandbox_history_item_exec_config_data_request.py +3 -0
- vellum/types/test_suite_run_workflow_sandbox_history_item_exec_config_request.py +3 -0
- vellum/workflows/context.py +42 -0
- vellum/workflows/events/node.py +7 -6
- vellum/workflows/events/tests/test_event.py +0 -1
- vellum/workflows/events/types.py +0 -1
- vellum/workflows/events/workflow.py +19 -1
- vellum/workflows/nodes/bases/base.py +17 -56
- vellum/workflows/nodes/bases/tests/test_base_node.py +0 -1
- vellum/workflows/nodes/core/inline_subworkflow_node/node.py +13 -7
- vellum/workflows/nodes/core/templating_node/node.py +1 -0
- vellum/workflows/nodes/core/try_node/node.py +2 -2
- vellum/workflows/nodes/core/try_node/tests/test_node.py +1 -3
- vellum/workflows/nodes/displayable/api_node/node.py +3 -2
- vellum/workflows/nodes/displayable/bases/api_node/node.py +1 -1
- vellum/workflows/nodes/displayable/bases/base_prompt_node/node.py +0 -1
- vellum/workflows/nodes/displayable/bases/inline_prompt_node/node.py +9 -1
- vellum/workflows/nodes/displayable/bases/prompt_deployment_node.py +12 -2
- vellum/workflows/nodes/displayable/bases/search_node.py +0 -1
- vellum/workflows/nodes/displayable/code_execution_node/tests/test_code_execution_node.py +0 -1
- vellum/workflows/nodes/displayable/code_execution_node/utils.py +3 -2
- vellum/workflows/nodes/displayable/conditional_node/node.py +1 -1
- vellum/workflows/nodes/displayable/guardrail_node/node.py +0 -1
- vellum/workflows/nodes/displayable/inline_prompt_node/node.py +1 -0
- vellum/workflows/nodes/displayable/prompt_deployment_node/node.py +3 -1
- vellum/workflows/nodes/displayable/search_node/node.py +1 -0
- vellum/workflows/nodes/displayable/subworkflow_deployment_node/node.py +13 -3
- vellum/workflows/nodes/displayable/tests/test_inline_text_prompt_node.py +10 -7
- vellum/workflows/nodes/displayable/tests/test_search_node_wth_text_output.py +0 -1
- vellum/workflows/nodes/displayable/tests/test_text_prompt_deployment_node.py +1 -1
- vellum/workflows/outputs/base.py +2 -4
- vellum/workflows/ports/node_ports.py +1 -1
- vellum/workflows/runner/runner.py +167 -202
- vellum/workflows/state/base.py +0 -2
- vellum/workflows/types/core.py +1 -0
- vellum/workflows/types/tests/test_utils.py +1 -0
- vellum/workflows/types/utils.py +0 -1
- vellum/workflows/utils/functions.py +74 -0
- vellum/workflows/utils/tests/test_functions.py +171 -0
- vellum/workflows/utils/tests/test_vellum_variables.py +0 -1
- vellum/workflows/utils/vellum_variables.py +2 -2
- vellum/workflows/workflows/base.py +74 -34
- vellum/workflows/workflows/event_filters.py +7 -12
- {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.1.dist-info}/METADATA +1 -1
- {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.1.dist-info}/RECORD +122 -99
- vellum_cli/__init__.py +147 -13
- vellum_cli/config.py +0 -1
- vellum_cli/image_push.py +1 -1
- vellum_cli/pull.py +31 -19
- vellum_cli/push.py +9 -10
- vellum_cli/tests/__init__.py +0 -0
- vellum_cli/tests/conftest.py +40 -0
- vellum_cli/tests/test_main.py +11 -0
- vellum_cli/tests/test_pull.py +143 -71
- vellum_cli/tests/test_push.py +173 -0
- vellum_ee/workflows/display/base.py +1 -0
- vellum_ee/workflows/display/nodes/base_node_display.py +3 -2
- vellum_ee/workflows/display/nodes/base_node_vellum_display.py +2 -2
- vellum_ee/workflows/display/nodes/get_node_display_class.py +1 -1
- vellum_ee/workflows/display/nodes/tests/test_base_node_display.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/__init__.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/api_node.py +54 -58
- vellum_ee/workflows/display/nodes/vellum/conditional_node.py +39 -22
- vellum_ee/workflows/display/nodes/vellum/error_node.py +3 -3
- vellum_ee/workflows/display/nodes/vellum/final_output_node.py +0 -2
- vellum_ee/workflows/display/nodes/vellum/guardrail_node.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/inline_prompt_node.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/inline_subworkflow_node.py +4 -2
- vellum_ee/workflows/display/nodes/vellum/map_node.py +11 -5
- vellum_ee/workflows/display/nodes/vellum/merge_node.py +2 -2
- vellum_ee/workflows/display/nodes/vellum/note_node.py +1 -3
- vellum_ee/workflows/display/nodes/vellum/prompt_deployment_node.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/search_node.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/subworkflow_deployment_node.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/templating_node.py +1 -1
- vellum_ee/workflows/display/nodes/vellum/tests/test_utils.py +5 -5
- vellum_ee/workflows/display/nodes/vellum/utils.py +30 -10
- vellum_ee/workflows/display/tests/test_vellum_workflow_display.py +45 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_api_node_serialization.py +42 -25
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_conditional_node_serialization.py +13 -39
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_guardrail_node_serialization.py +2 -2
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_inline_subworkflow_serialization.py +62 -58
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_map_node_serialization.py +25 -4
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_merge_node_serialization.py +2 -1
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_prompt_deployment_serialization.py +2 -2
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_subworkflow_deployment_serialization.py +2 -2
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_terminal_node_serialization.py +1 -1
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_try_node_serialization.py +2 -1
- vellum_ee/workflows/display/tests/workflow_serialization/test_complex_terminal_node_serialization.py +2 -2
- vellum_ee/workflows/display/types.py +4 -4
- vellum_ee/workflows/display/utils/vellum.py +2 -6
- vellum_ee/workflows/display/vellum.py +1 -1
- vellum_ee/workflows/display/workflows/get_vellum_workflow_display_class.py +4 -1
- vellum_ee/workflows/display/workflows/vellum_workflow_display.py +12 -5
- vellum/workflows/runner/types.py +0 -16
- {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.1.dist-info}/LICENSE +0 -0
- {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.1.dist-info}/WHEEL +0 -0
- {vellum_ai-0.10.9.dist-info → vellum_ai-0.11.1.dist-info}/entry_points.txt +0 -0
vellum_cli/tests/test_pull.py
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
import pytest
|
2
2
|
import io
|
3
|
+
import json
|
3
4
|
import os
|
4
|
-
import shutil
|
5
5
|
import tempfile
|
6
6
|
from uuid import uuid4
|
7
7
|
import zipfile
|
8
|
-
from typing import Generator, Tuple
|
9
8
|
|
10
|
-
import
|
9
|
+
from click.testing import CliRunner
|
11
10
|
|
12
|
-
from vellum_cli
|
11
|
+
from vellum_cli import main as cli_main
|
13
12
|
|
14
13
|
|
15
|
-
def
|
14
|
+
def _zip_file_map(file_map: dict[str, str]) -> bytes:
|
16
15
|
# Create an in-memory bytes buffer to store the zip
|
17
16
|
zip_buffer = io.BytesIO()
|
18
17
|
|
@@ -28,47 +27,60 @@ def zip_file_map(file_map: dict[str, str]) -> bytes:
|
|
28
27
|
return zip_bytes
|
29
28
|
|
30
29
|
|
31
|
-
@pytest.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
"vellum": {
|
43
|
-
"workflows": [
|
44
|
-
{
|
45
|
-
"module": module,
|
46
|
-
"workflow_sandbox_id": str(uuid4()),
|
47
|
-
}
|
48
|
-
]
|
49
|
-
}
|
50
|
-
}
|
51
|
-
},
|
52
|
-
f,
|
53
|
-
)
|
30
|
+
@pytest.mark.parametrize(
|
31
|
+
"base_command",
|
32
|
+
[
|
33
|
+
["pull"],
|
34
|
+
["workflows", "pull"],
|
35
|
+
],
|
36
|
+
ids=["pull", "workflows_pull"],
|
37
|
+
)
|
38
|
+
def test_pull(vellum_client, mock_module, base_command):
|
39
|
+
# GIVEN a module on the user's filesystem
|
40
|
+
temp_dir, module, _ = mock_module
|
54
41
|
|
55
|
-
|
42
|
+
# AND the workflow pull API call returns a zip file
|
43
|
+
vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
|
56
44
|
|
57
|
-
|
58
|
-
|
45
|
+
# WHEN the user runs the pull command
|
46
|
+
runner = CliRunner()
|
47
|
+
result = runner.invoke(cli_main, base_command + [module])
|
48
|
+
|
49
|
+
# THEN the command returns successfully
|
50
|
+
assert result.exit_code == 0
|
51
|
+
|
52
|
+
# AND the workflow.py file is written to the module directory
|
53
|
+
workflow_py = os.path.join(temp_dir, *module.split("."), "workflow.py")
|
54
|
+
assert os.path.exists(workflow_py)
|
55
|
+
with open(workflow_py) as f:
|
56
|
+
assert f.read() == "print('hello')"
|
59
57
|
|
60
58
|
|
61
|
-
def
|
59
|
+
def test_pull__second_module(vellum_client, mock_module):
|
62
60
|
# GIVEN a module on the user's filesystem
|
63
|
-
temp_dir, module = mock_module
|
61
|
+
temp_dir, module, set_pyproject_toml = mock_module
|
64
62
|
|
65
63
|
# AND the workflow pull API call returns a zip file
|
66
|
-
vellum_client.workflows.pull.return_value = iter([
|
64
|
+
vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
|
65
|
+
|
66
|
+
# AND the module we're about to pull is configured second
|
67
|
+
set_pyproject_toml(
|
68
|
+
{
|
69
|
+
"workflows": [
|
70
|
+
{"module": "another.module", "workflow_sandbox_id": str(uuid4())},
|
71
|
+
{"module": module, "workflow_sandbox_id": str(uuid4())},
|
72
|
+
]
|
73
|
+
}
|
74
|
+
)
|
67
75
|
|
68
76
|
# WHEN the user runs the pull command
|
69
|
-
|
77
|
+
runner = CliRunner()
|
78
|
+
result = runner.invoke(cli_main, ["pull", module])
|
70
79
|
|
71
|
-
# THEN the
|
80
|
+
# THEN the command returns successfully
|
81
|
+
assert result.exit_code == 0
|
82
|
+
|
83
|
+
# AND the workflow.py file is written to the module directory
|
72
84
|
workflow_py = os.path.join(temp_dir, *module.split("."), "workflow.py")
|
73
85
|
assert os.path.exists(workflow_py)
|
74
86
|
with open(workflow_py) as f:
|
@@ -80,7 +92,7 @@ def test_pull__sandbox_id_with_no_config(vellum_client):
|
|
80
92
|
workflow_sandbox_id = "87654321-0000-0000-0000-000000000000"
|
81
93
|
|
82
94
|
# AND the workflow pull API call returns a zip file
|
83
|
-
vellum_client.workflows.pull.return_value = iter([
|
95
|
+
vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
|
84
96
|
|
85
97
|
# AND we are currently in a new directory
|
86
98
|
current_dir = os.getcwd()
|
@@ -88,23 +100,73 @@ def test_pull__sandbox_id_with_no_config(vellum_client):
|
|
88
100
|
os.chdir(temp_dir)
|
89
101
|
|
90
102
|
# WHEN the user runs the pull command with the workflow sandbox id and no module
|
91
|
-
|
103
|
+
runner = CliRunner()
|
104
|
+
result = runner.invoke(cli_main, ["workflows", "pull", "--workflow-sandbox-id", workflow_sandbox_id])
|
92
105
|
os.chdir(current_dir)
|
93
106
|
|
94
|
-
# THEN the
|
107
|
+
# THEN the command returns successfully
|
108
|
+
assert result.exit_code == 0
|
109
|
+
|
110
|
+
# AND the pull api is called with the workflow sandbox id
|
95
111
|
vellum_client.workflows.pull.assert_called_once()
|
96
112
|
workflow_py = os.path.join(temp_dir, "workflow_87654321", "workflow.py")
|
97
113
|
assert os.path.exists(workflow_py)
|
98
114
|
with open(workflow_py) as f:
|
99
115
|
assert f.read() == "print('hello')"
|
100
116
|
|
117
|
+
# AND the vellum.lock.json file is created
|
118
|
+
vellum_lock_json = os.path.join(temp_dir, "vellum.lock.json")
|
119
|
+
assert os.path.exists(vellum_lock_json)
|
120
|
+
with open(vellum_lock_json) as f:
|
121
|
+
lock_data = json.loads(f.read())
|
122
|
+
assert lock_data == {
|
123
|
+
"version": "1.0",
|
124
|
+
"workflows": [
|
125
|
+
{
|
126
|
+
"module": "workflow_87654321",
|
127
|
+
"workflow_sandbox_id": "87654321-0000-0000-0000-000000000000",
|
128
|
+
"ignore": None,
|
129
|
+
"deployments": [],
|
130
|
+
}
|
131
|
+
],
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
def test_pull__sandbox_id_with_other_workflow_configured(vellum_client, mock_module):
|
136
|
+
# GIVEN a pyproject.toml with a workflow configured
|
137
|
+
temp_dir, _, _ = mock_module
|
138
|
+
|
139
|
+
# AND a different workflow sandbox id
|
140
|
+
workflow_sandbox_id = "87654321-0000-0000-0000-000000000000"
|
141
|
+
|
142
|
+
# AND the workflow pull API call returns a zip file
|
143
|
+
vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
|
144
|
+
|
145
|
+
# WHEN the user runs the pull command with the new workflow sandbox id
|
146
|
+
runner = CliRunner()
|
147
|
+
result = runner.invoke(cli_main, ["workflows", "pull", "--workflow-sandbox-id", workflow_sandbox_id])
|
148
|
+
|
149
|
+
# THEN the command returns successfully
|
150
|
+
assert result.exit_code == 0
|
151
|
+
|
152
|
+
# AND the pull api is called with the new workflow sandbox id
|
153
|
+
vellum_client.workflows.pull.assert_called_once()
|
154
|
+
call_args = vellum_client.workflows.pull.call_args.args
|
155
|
+
assert call_args[0] == workflow_sandbox_id
|
156
|
+
|
157
|
+
# AND the workflow.py file is written to the module directory
|
158
|
+
workflow_py = os.path.join(temp_dir, "workflow_87654321", "workflow.py")
|
159
|
+
assert os.path.exists(workflow_py)
|
160
|
+
with open(workflow_py) as f:
|
161
|
+
assert f.read() == "print('hello')"
|
162
|
+
|
101
163
|
|
102
164
|
def test_pull__remove_missing_files(vellum_client, mock_module):
|
103
165
|
# GIVEN a module on the user's filesystem
|
104
|
-
temp_dir, module = mock_module
|
166
|
+
temp_dir, module, _ = mock_module
|
105
167
|
|
106
168
|
# AND the workflow pull API call returns a zip file
|
107
|
-
vellum_client.workflows.pull.return_value = iter([
|
169
|
+
vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
|
108
170
|
|
109
171
|
# AND there is already a different file in the module directory
|
110
172
|
other_file_path = os.path.join(temp_dir, *module.split("."), "other_file.py")
|
@@ -113,9 +175,13 @@ def test_pull__remove_missing_files(vellum_client, mock_module):
|
|
113
175
|
f.write("print('hello')")
|
114
176
|
|
115
177
|
# WHEN the user runs the pull command
|
116
|
-
|
178
|
+
runner = CliRunner()
|
179
|
+
result = runner.invoke(cli_main, ["pull", module])
|
180
|
+
|
181
|
+
# THEN the command returns successfully
|
182
|
+
assert result.exit_code == 0
|
117
183
|
|
118
|
-
#
|
184
|
+
# AND the workflow.py file is written to the module directory
|
119
185
|
assert os.path.exists(os.path.join(temp_dir, *module.split("."), "workflow.py"))
|
120
186
|
with open(os.path.join(temp_dir, *module.split("."), "workflow.py")) as f:
|
121
187
|
assert f.read() == "print('hello')"
|
@@ -126,10 +192,10 @@ def test_pull__remove_missing_files(vellum_client, mock_module):
|
|
126
192
|
|
127
193
|
def test_pull__remove_missing_files__ignore_pattern(vellum_client, mock_module):
|
128
194
|
# GIVEN a module on the user's filesystem
|
129
|
-
temp_dir, module = mock_module
|
195
|
+
temp_dir, module, set_pyproject_toml = mock_module
|
130
196
|
|
131
197
|
# AND the workflow pull API call returns a zip file
|
132
|
-
vellum_client.workflows.pull.return_value = iter([
|
198
|
+
vellum_client.workflows.pull.return_value = iter([_zip_file_map({"workflow.py": "print('hello')"})])
|
133
199
|
|
134
200
|
# AND there is already a different file in the module directory
|
135
201
|
other_file_path = os.path.join(temp_dir, *module.split("."), "other_file.py")
|
@@ -144,28 +210,26 @@ def test_pull__remove_missing_files__ignore_pattern(vellum_client, mock_module):
|
|
144
210
|
f.write("print('hello')")
|
145
211
|
|
146
212
|
# AND the ignore pattern is set to tests
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
"
|
152
|
-
|
153
|
-
|
154
|
-
"module": module,
|
155
|
-
"workflow_sandbox_id": str(uuid4()),
|
156
|
-
"ignore": "tests/*",
|
157
|
-
}
|
158
|
-
]
|
159
|
-
}
|
213
|
+
set_pyproject_toml(
|
214
|
+
{
|
215
|
+
"workflows": [
|
216
|
+
{
|
217
|
+
"module": module,
|
218
|
+
"workflow_sandbox_id": str(uuid4()),
|
219
|
+
"ignore": "tests/*",
|
160
220
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
221
|
+
]
|
222
|
+
}
|
223
|
+
)
|
164
224
|
|
165
225
|
# WHEN the user runs the pull command
|
166
|
-
|
226
|
+
runner = CliRunner()
|
227
|
+
result = runner.invoke(cli_main, ["pull", module])
|
228
|
+
|
229
|
+
# THEN the command returns successfully
|
230
|
+
assert result.exit_code == 0
|
167
231
|
|
168
|
-
#
|
232
|
+
# AND the workflow.py file is written to the module directory
|
169
233
|
assert os.path.exists(os.path.join(temp_dir, *module.split("."), "workflow.py"))
|
170
234
|
with open(os.path.join(temp_dir, *module.split("."), "workflow.py")) as f:
|
171
235
|
assert f.read() == "print('hello')"
|
@@ -179,17 +243,21 @@ def test_pull__remove_missing_files__ignore_pattern(vellum_client, mock_module):
|
|
179
243
|
|
180
244
|
def test_pull__include_json(vellum_client, mock_module):
|
181
245
|
# GIVEN a module on the user's filesystem
|
182
|
-
_, module = mock_module
|
246
|
+
_, module, __ = mock_module
|
183
247
|
|
184
248
|
# AND the workflow pull API call returns a zip file
|
185
249
|
vellum_client.workflows.pull.return_value = iter(
|
186
|
-
[
|
250
|
+
[_zip_file_map({"workflow.py": "print('hello')", "workflow.json": "{}"})]
|
187
251
|
)
|
188
252
|
|
189
253
|
# WHEN the user runs the pull command
|
190
|
-
|
254
|
+
runner = CliRunner()
|
255
|
+
result = runner.invoke(cli_main, ["pull", module, "--include-json"])
|
191
256
|
|
192
|
-
# THEN the
|
257
|
+
# THEN the command returns successfully
|
258
|
+
assert result.exit_code == 0
|
259
|
+
|
260
|
+
# AND the pull api is called with include_json=True
|
193
261
|
vellum_client.workflows.pull.assert_called_once()
|
194
262
|
call_args = vellum_client.workflows.pull.call_args.kwargs
|
195
263
|
assert call_args["request_options"]["additional_query_parameters"] == {"include_json": True}
|
@@ -197,17 +265,21 @@ def test_pull__include_json(vellum_client, mock_module):
|
|
197
265
|
|
198
266
|
def test_pull__exclude_code(vellum_client, mock_module):
|
199
267
|
# GIVEN a module on the user's filesystem
|
200
|
-
_, module = mock_module
|
268
|
+
_, module, __ = mock_module
|
201
269
|
|
202
270
|
# AND the workflow pull API call returns a zip file
|
203
271
|
vellum_client.workflows.pull.return_value = iter(
|
204
|
-
[
|
272
|
+
[_zip_file_map({"workflow.py": "print('hello')", "workflow.json": "{}"})]
|
205
273
|
)
|
206
274
|
|
207
275
|
# WHEN the user runs the pull command
|
208
|
-
|
276
|
+
runner = CliRunner()
|
277
|
+
result = runner.invoke(cli_main, ["pull", module, "--exclude-code"])
|
278
|
+
|
279
|
+
# THEN the command returns successfully
|
280
|
+
assert result.exit_code == 0
|
209
281
|
|
210
|
-
#
|
282
|
+
# AND the pull api is called with exclude_code=True
|
211
283
|
vellum_client.workflows.pull.assert_called_once()
|
212
284
|
call_args = vellum_client.workflows.pull.call_args.kwargs
|
213
285
|
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(
|
104
|
-
|
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]):
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import pytest
|
2
2
|
from uuid import UUID
|
3
3
|
|
4
|
-
from vellum_ee.workflows.display.nodes.base_node_display import BaseNodeDisplay
|
5
4
|
from vellum.workflows.nodes.bases import BaseNode
|
5
|
+
from vellum_ee.workflows.display.nodes.base_node_display import BaseNodeDisplay
|
6
6
|
|
7
7
|
|
8
8
|
@pytest.fixture
|