fix: support conditions on function steps#162
Open
Ruari-Phipps wants to merge 4 commits into
Open
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
Coverage Report
Changed file coverage
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds end-to-end sync support for conditions on function steps in ADK flows, ensuring conditions are correctly pulled from the platform, represented locally, and pushed back using the proper step-condition protobuf APIs (rather than the no-code condition endpoints).
Changes:
- Extend
FunctionStepto carryconditions, including extraction fromgoto_step()/exit_flow()patterns and condition subresource diffing. - Update platform projection parsing and sync command ordering so function-step conditions round-trip reliably and use the correct create/update/delete APIs.
- Add/extend unit tests and update the bundled test project fixtures to cover YAML/JSON round-trips and push behavior (including the stub-code two-phase push).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/poly/utils.py | Import ordering adjustment. |
| src/poly/tests/test_projects/test_project/test_project.json | Updates test projection fixture to include function-step conditions and updated code. |
| src/poly/tests/test_projects/test_project/flows/test_flow/function_steps/process_payment.py | Updates fixture function-step code to include goto_step() call. |
| src/poly/tests/resources_test.py | Adds tests for goto_step/goto_flow extraction and function-step condition extraction behavior. |
| src/poly/tests/project_test.py | Adds tests validating stub-code behavior for new function steps with conditions. |
| src/poly/resources/resource_utils.py | Adds reusable regex extractors for goto_step() and goto_flow() calls. |
| src/poly/resources/function.py | Switches validation to use the new extract_go_to_steps/flows helpers. |
| src/poly/resources/flows.py | Core implementation: condition API routing via parent_is_no_code_step, adds FunctionStep.conditions, extracts conditions from function-step code, and emits condition subresource commands. |
| src/poly/project.py | Implements two-phase push (stub code first) for new function steps with conditions to avoid backend duplicate conditions. |
| src/poly/handlers/sync_client.py | Pulls conditions for both flow steps and function steps; includes Condition in sync priority ordering. |
| src/poly/handlers/platform_api.py | Import ordering adjustment. |
Comments suppressed due to low confidence (1)
src/poly/resources/flows.py:1274
build_delete_proto/build_create_protocan returnDeleteStepCondition/CreateStepConditionwhenparent_is_no_code_stepis false, but the return type annotations are stillDeleteNoCodeCondition/CreateNoCodeCondition. Update these annotations (and any related docstrings) to reflect the actual union return types so type checking and IDE tooling stay accurate.
def build_delete_proto(self) -> DeleteNoCodeCondition:
"""Create a proto for deleting the condition."""
if self.parent_is_no_code_step:
return DeleteNoCodeCondition(
flow_id=self.flow_id,
step_id=self.step_id,
condition_id=self.resource_id,
)
return DeleteStepCondition(
flow_id=self.flow_id,
step_id=self.step_id,
condition_id=self.resource_id,
)
def build_create_proto(self) -> CreateNoCodeCondition:
"""Create a proto for creating the condition."""
if self.parent_is_no_code_step:
return CreateNoCodeCondition(
flow_id=self.flow_id,
step_id=self.step_id,
condition_id=self.resource_id,
**self._get_condition_type_proto(),
)
return CreateStepCondition(
flow_id=self.flow_id,
step_id=self.step_id,
condition_id=self.resource_id,
**self._get_condition_type_proto(),
)
| condition_name_map = { | ||
| cond.name: cond | ||
| for cond in known_conditions | ||
| if cond.command_type != ConditionType.EXIT_FLOW |
Comment on lines
+1544
to
+1548
| child_step=child_step_id, | ||
| position=known_condition.position if known_condition else None, | ||
| ingress=known_condition.ingress if known_condition else None, | ||
| exit_flow_position=None, | ||
| parent_is_no_code_step=False, |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds full sync support for flow conditions on function steps, including pull, push, YAML serialization, and the correct Agent Studio protobuf APIs (
CreateStepCondition/UpdateStepCondition/DeleteStepConditioninstead of the no-code condition endpoints).Motivation
Function steps can define branching via
goto_step()in their Python code, but the ADK only handled conditions for no-code steps. Conditions on function steps were dropped on pull and could not be pushed reliably. The backend also auto-creates conditions fromgoto_step()calls, which caused duplicate labels when pushing explicit conditions alongside real function code.Changes
conditionsfield toFunctionStepwith YAML read/write andgoto_step()extraction (mirroringFlowStep)step_conditionprotos; no-code step conditions unchangedparent_is_no_code_steponConditionto select the correct create/update/delete APIpasscode first, then update with real code to avoid backend duplicate conditionsConditionin sync ordering so conditions are created before dependent updatessync_clientTest strategy
poly <command>)Checklist
ruff check .andruff format --check .passpytestpassespolyCLI interface (or migration path documented)Screenshots / Logs
N/A
Made with Cursor