-
Notifications
You must be signed in to change notification settings - Fork 356
fix(healing): read YAML workflow files in process_workflow_file_with_markers #177
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
Open
RaphaelFakhri
wants to merge
1
commit into
browser-use:main
Choose a base branch
from
RaphaelFakhri:fix/variable-utils-yaml-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions
53
workflows/workflow_use/healing/tests/test_variable_utils.py
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,53 @@ | ||
| """Tests for the variable marker file utilities.""" | ||
|
|
||
| import json | ||
|
|
||
| import yaml | ||
|
|
||
| from workflow_use.healing.variable_utils import process_workflow_file_with_markers | ||
|
|
||
| WORKFLOW = { | ||
| 'name': 'Test Workflow', | ||
| 'description': 'Test', | ||
| 'version': '1.0', | ||
| 'steps': [ | ||
| {'type': 'input', 'target_text': 'Email', 'value': 'VAR:user_email:test@example.com'}, | ||
| {'type': 'extract', 'extractionGoal': 'Extract the result'}, | ||
| ], | ||
| 'input_schema': [], | ||
| } | ||
|
|
||
|
|
||
| def test_process_yaml_workflow_file(tmp_path): | ||
| """A .workflow.yaml file, the format the storage service writes, is processed in place.""" | ||
| path = tmp_path / 'test.workflow.yaml' | ||
| path.write_text(yaml.dump(WORKFLOW, sort_keys=False)) | ||
|
|
||
| process_workflow_file_with_markers(path) | ||
|
|
||
| saved = yaml.safe_load(path.read_text()) | ||
| assert saved['steps'][0]['value'] == '{user_email}' | ||
| assert [inp['name'] for inp in saved['input_schema']] == ['user_email'] | ||
|
|
||
|
|
||
| def test_process_json_workflow_file(tmp_path): | ||
| """A JSON workflow file still works and stays JSON.""" | ||
| path = tmp_path / 'test.workflow.json' | ||
| path.write_text(json.dumps(WORKFLOW)) | ||
|
|
||
| process_workflow_file_with_markers(path) | ||
|
|
||
| saved = json.loads(path.read_text()) | ||
| assert saved['steps'][0]['value'] == '{user_email}' | ||
|
|
||
|
|
||
| def test_yaml_input_to_json_output(tmp_path): | ||
| """The output format follows the output path extension.""" | ||
| source = tmp_path / 'test.workflow.yaml' | ||
| source.write_text(yaml.dump(WORKFLOW, sort_keys=False)) | ||
| output = tmp_path / 'out.json' | ||
|
|
||
| process_workflow_file_with_markers(source, output) | ||
|
|
||
| saved = json.loads(output.read_text()) | ||
| assert saved['steps'][0]['value'] == '{user_email}' |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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,19 +59,22 @@ 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. YAML is a superset of JSON, so this reads both formats. | ||||||
| with open(input_path, 'r') as f: | ||||||
| workflow_data = json.load(f) | ||||||
| workflow_data = yaml.safe_load(f) | ||||||
|
|
||||||
| workflow = WorkflowDefinitionSchema(**workflow_data) | ||||||
|
|
||||||
| # Extract variables from markers | ||||||
| extractor = VariableExtractor() | ||||||
| updated_workflow, extracted_inputs = extractor.process_workflow_with_markers(workflow) | ||||||
|
|
||||||
| # Save the updated workflow | ||||||
| # Save the updated workflow in the format that matches the output file extension | ||||||
| with open(output_path, 'w') as f: | ||||||
| json.dump(updated_workflow.model_dump(), f, indent=2) | ||||||
| if output_path.suffix.lower() in ('.yaml', '.yml'): | ||||||
| yaml.dump(updated_workflow.model_dump(mode='json'), f, default_flow_style=False, sort_keys=False) | ||||||
| else: | ||||||
| json.dump(updated_workflow.model_dump(), f, indent=2) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: YAML-to-JSON conversion still fails for valid YAML-native values such as unquoted dates in Prompt for AI agents
Suggested change
|
||||||
|
|
||||||
| print(f'Processed workflow: {input_path}') | ||||||
| if extracted_inputs: | ||||||
|
|
||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This loader changes valid YAML string scalars such as
yesandoninto booleans before schema validation, so hand-authored workflows can fail on required string fields. Use a YAML 1.2-compatible scalar resolver or normalize these fields before constructingWorkflowDefinitionSchema.Prompt for AI agents