From 14b9d40a9d545fd2b204a8232c9fa310deafab9f Mon Sep 17 00:00:00 2001 From: Ishaan Samantray Date: Sun, 31 May 2026 23:15:43 -0400 Subject: [PATCH] fix(variable_utils): parse YAML workflow files with yaml.safe_load process_workflow_file_with_markers() hardcoded json.load() but WorkflowStorageService always writes *.workflow.yaml files, causing JSONDecodeError on every normal workflow. Now branches on file suffix to use yaml.safe_load for .yaml/.yml and json.load otherwise. Fixes #156 --- workflows/tests/test_variable_utils_yaml.py | 19 +++++++++++++++++++ .../workflow_use/healing/variable_utils.py | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 workflows/tests/test_variable_utils_yaml.py diff --git a/workflows/tests/test_variable_utils_yaml.py b/workflows/tests/test_variable_utils_yaml.py new file mode 100644 index 00000000..e79f0033 --- /dev/null +++ b/workflows/tests/test_variable_utils_yaml.py @@ -0,0 +1,19 @@ +"""Test that process_workflow_file_with_markers handles YAML workflow files.""" + +import json +from pathlib import Path + +import pytest + +from workflow_use.healing.variable_utils import process_workflow_file_with_markers + +_FIXTURE = Path(__file__).parent / 'test_go_back.workflow.yaml' + + +def test_process_yaml_workflow_does_not_raise(tmp_path): + """YAML workflow files must be parsed without JSONDecodeError.""" + output_file = tmp_path / 'output.json' + result = process_workflow_file_with_markers(_FIXTURE, output_path=output_file) + assert output_file.exists() + data = json.loads(output_file.read_text()) + assert data['name'] == 'Test Go Back' diff --git a/workflows/workflow_use/healing/variable_utils.py b/workflows/workflow_use/healing/variable_utils.py index 298f5451..647408ed 100644 --- a/workflows/workflow_use/healing/variable_utils.py +++ b/workflows/workflow_use/healing/variable_utils.py @@ -4,6 +4,8 @@ from pathlib import Path from typing import Optional +import yaml + from workflow_use.healing.variable_extractor import VariableExtractor from workflow_use.schema.views import WorkflowDefinitionSchema @@ -57,9 +59,12 @@ def process_workflow_file_with_markers( input_path = Path(input_path) output_path = Path(output_path) if output_path else input_path - # Load the workflow + # Load the workflow — storage service persists as YAML; fall back to JSON with open(input_path, 'r') as f: - workflow_data = json.load(f) + if input_path.suffix in {'.yaml', '.yml'}: + workflow_data = yaml.safe_load(f) + else: + workflow_data = json.load(f) workflow = WorkflowDefinitionSchema(**workflow_data)