-
Notifications
You must be signed in to change notification settings - Fork 9.8k
fix(policies): preserve generated ToolGuard code #14378
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
83 changes: 83 additions & 0 deletions
83
src/backend/tests/unit/components/models_and_agents/policies/test_guard_sync_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,83 @@ | ||
| from copy import deepcopy | ||
|
|
||
| from lfx.components.models_and_agents.policies.guard_sync_utils import ( | ||
| GENERATED_GUARD_INFO_PREFIX, | ||
| sync_generated_guard_code_inputs, | ||
| ) | ||
|
|
||
|
|
||
| def _generated_field(name: str, value: str) -> dict: | ||
| return { | ||
| "type": "code", | ||
| "dynamic": True, | ||
| "info": f"{GENERATED_GUARD_INFO_PREFIX}{name}", | ||
| "value": value, | ||
| } | ||
|
|
||
|
|
||
| def test_sync_preserves_generated_fields_when_step2_directory_is_missing(tmp_path): | ||
| build_config = { | ||
| "result.json": _generated_field("result.json", "persisted result"), | ||
| "test_project/guard.py": _generated_field("test_project/guard.py", "persisted guard"), | ||
| "project": {"type": "str", "value": "test_project"}, | ||
| } | ||
| original_config = deepcopy(build_config) | ||
|
|
||
| result = sync_generated_guard_code_inputs( | ||
| build_config=build_config, | ||
| work_dir=tmp_path / "missing_project", | ||
| step2_subdir="Step_2", | ||
| project_name="test_project", | ||
| ) | ||
|
|
||
| assert result is build_config | ||
| assert result == original_config | ||
|
|
||
|
|
||
| def test_sync_preserves_generated_fields_when_step2_path_is_not_a_directory(tmp_path): | ||
| work_dir = tmp_path / "test_project" | ||
| work_dir.mkdir() | ||
| (work_dir / "Step_2").write_text("not a directory", encoding="utf-8") | ||
| build_config = { | ||
| "result.json": _generated_field("result.json", "persisted result"), | ||
| "test_project/guard.py": _generated_field("test_project/guard.py", "persisted guard"), | ||
| } | ||
| original_config = deepcopy(build_config) | ||
|
|
||
| result = sync_generated_guard_code_inputs( | ||
| build_config=build_config, | ||
| work_dir=work_dir, | ||
| step2_subdir="Step_2", | ||
| project_name="test_project", | ||
| ) | ||
|
|
||
| assert result == original_config | ||
|
|
||
|
|
||
| def test_sync_reconciles_generated_fields_when_step2_directory_exists(tmp_path): | ||
| work_dir = tmp_path / "test_project" | ||
| step2_dir = work_dir / "Step_2" | ||
| project_dir = step2_dir / "test_project" | ||
| project_dir.mkdir(parents=True) | ||
| (step2_dir / "result.json").write_text("fresh result", encoding="utf-8") | ||
| (project_dir / "guard.py").write_text("fresh guard", encoding="utf-8") | ||
| (step2_dir / "ignored.py").write_text("ignored", encoding="utf-8") | ||
|
|
||
| build_config = { | ||
| "result.json": _generated_field("result.json", "stale result"), | ||
| "test_project/stale.py": _generated_field("test_project/stale.py", "stale guard"), | ||
| "project": {"type": "str", "value": "test_project"}, | ||
| } | ||
|
|
||
| result = sync_generated_guard_code_inputs( | ||
| build_config=build_config, | ||
| work_dir=work_dir, | ||
| step2_subdir="Step_2", | ||
| project_name="test_project", | ||
| ) | ||
|
|
||
| assert result["result.json"]["value"] == "fresh result" | ||
| assert result["test_project/guard.py"]["value"] == "fresh guard" | ||
| assert "test_project/stale.py" not in result | ||
| assert "ignored.py" not in result | ||
| assert result["project"] == {"type": "str", "value": "test_project"} |
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
Oops, something went wrong.
Oops, something went wrong.
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.