Skip to content

fix: push step condition to children to fix evaluation with artifacts#7627

Merged
vsukhin merged 6 commits into
mainfrom
copilot/fix-test-step-condition-evaluation-again
May 4, 2026
Merged

fix: push step condition to children to fix evaluation with artifacts#7627
vsukhin merged 6 commits into
mainfrom
copilot/fix-test-step-condition-evaluation-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

Pull request description

Step conditions like env.TEST are incorrectly evaluated as false when the step also defines artifacts, causing the entire step to be skipped.

Root cause: When a step has multiple operations (shell + artifacts), the processor wraps them in a non-flattenable group. The group's Start action evaluates the condition before the Container transition that loads scoped env vars (e.g., _0_TEST=trueTEST=true). So os.Getenv("TEST") returns "" at evaluation time. With a single operation (no artifacts), the group flattens and the Container transition naturally precedes the condition check.

# Works (single operation → group flattens)
- condition: env.TEST
  shell: echo "test"

# Broken (two operations → group doesn't flatten, condition evaluated too early)
- condition: env.TEST
  shell: echo "test"
  artifacts:
    paths: ["*.xml"]

Fix: Set the group condition to literal "true" so it always starts, and push the step condition down to each child operation via AppendConditions. Children evaluate the condition after their Container transition loads env vars.

  • processor.go: Group gets "true" when step has a condition; children receive the actual condition via AppendConditions (preserving operation-set conditions like "always" for artifacts)
  • groupstage.go: Virtual group Flatten() now propagates its condition to children, so nested step conditions aren't lost
  • processor_test.go: Regression test verifying condition ordering with artifacts

Checklist (choose whats happened)

  • breaking change! (describe)
  • tested locally
  • tested on cluster
  • added new dependencies
  • updated the docs
  • added a test

Breaking changes

Changes

  • Group stages with step conditions now use literal "true" and push the condition to children
  • Virtual group flattening propagates conditions to children before returning them

Fixes

  • Step condition incorrectly evaluated as skipped when step contains artifact definitions

Copilot AI linked an issue May 4, 2026 that may be closed by this pull request
Copilot AI and others added 3 commits May 4, 2026 11:25
…on ordering

When a step has both a condition (e.g., env.TEST) and artifacts, the
processor creates a group stage. The group's Start action is evaluated
before the Container transition that loads scoped environment variables.
This caused the condition to evaluate to false (empty env var) and skip
the entire step.

Fix: Set the group condition to literal 'true' so it always starts, and
push the step condition to each child operation via AppendConditions.
Also propagate virtual group conditions to children during Flatten so
nested step conditions work correctly.

Agent-Logs-Url: https://github.com/kubeshop/testkube/sessions/eee39f98-f969-4696-9cdf-7a0ff62c5f45

Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect evaluation of test step condition fix: push step condition to children to fix evaluation with artifacts May 4, 2026
Copilot finished work on behalf of vsukhin May 4, 2026 11:32
Copilot AI requested a review from vsukhin May 4, 2026 11:32
@vsukhin
Copy link
Copy Markdown
Collaborator

vsukhin commented May 4, 2026

@greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR fixes a bug where step conditions (e.g., condition: env.TEST) were always evaluated as false when the step also defined artifacts, causing the step to be incorrectly skipped. The root cause was that a multi-operation group's Start action evaluated the condition before the Container transition that loads scoped env vars. The fix sets the group condition to "true" so it always starts, then pushes the real condition down to each child operation via AppendConditions, where it is evaluated after the env var transition — a correct and well-targeted approach.

A secondary pre-existing bug is also silently fixed: the old SetCondition call was overwriting operation-level conditions like "always" on artifact steps; AppendConditions now correctly combines them.

Confidence Score: 5/5

Safe to merge — the fix is well-reasoned, targeted, and backed by a regression test. Only P2 findings remain.

No P0 or P1 issues found. The single P2 comment flags missing test coverage for the false-condition path, which is a non-blocking improvement. The core logic is correct and the changes are minimal in scope.

No files require special attention; the P2 is a test-coverage suggestion on processor_test.go.

Important Files Changed

Filename Overview
pkg/testworkflows/testworkflowprocessor/processor.go Core fix: group condition changed from the step condition to literal "true"; step condition pushed to children via AppendConditions (preserving operation-level conditions like "always"). Semantics when condition is false shift from "group skipped" to "group started, children skipped" — intentional but untested on the false path.
pkg/testworkflows/testworkflowprocessor/stage/groupstage.go Flatten() now propagates a virtual group's condition to its children before dissolving the group. Children are fully flattened before propagation, so no double-application risk. Correct and targeted fix.
pkg/testworkflows/testworkflowprocessor/presets/processor_test.go Adds a regression test that verifies group condition is "true" and children carry env.TEST after the fix. Covers only the happy path (TEST=true); the false-condition path is not tested.

Sequence Diagram

sequenceDiagram
    participant P as processor.go
    participant G as GroupStage (group)
    participant S as ShellStage (child)
    participant A as ArtifactsStage (child)
    participant E as Execution Engine

    Note over P,E: Step with condition:"env.TEST" + shell + artifacts

    P->>G: SetCondition("true")
    P->>S: AppendConditions("env.TEST")
    P->>A: AppendConditions("env.TEST")
    Note over A: combined: "env.TEST&&always"
    P->>G: Add(S), Add(A)

    E->>G: Declare (condition:"true")
    E->>G: Start (always fires)
    E->>S: Container transition (loads _0_TEST→TEST)
    E->>S: Evaluate condition "env.TEST" — correct timing
    E->>A: Evaluate condition "env.TEST&&always" — correct timing
Loading

Reviews (2): Last reviewed commit: "fix: go mod" | Re-trigger Greptile

@vsukhin
Copy link
Copy Markdown
Collaborator

vsukhin commented May 4, 2026

@copilot revert go.sum

Agent-Logs-Url: https://github.com/kubeshop/testkube/sessions/6ceb86f0-3eb8-4a71-8595-cb79d51e76da

Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 4, 2026

@copilot revert go.sum

Reverted in c609bc8.

Copilot finished work on behalf of vsukhin May 4, 2026 11:40
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
@vsukhin vsukhin marked this pull request as ready for review May 4, 2026 11:56
@vsukhin vsukhin requested a review from a team as a code owner May 4, 2026 11:56
@vsukhin vsukhin requested a review from caiomede-tk May 4, 2026 11:56
@vsukhin vsukhin merged commit 0f0873a into main May 4, 2026
23 of 24 checks passed
@vsukhin vsukhin deleted the copilot/fix-test-step-condition-evaluation-again branch May 4, 2026 13:48
vsukhin added a commit that referenced this pull request May 7, 2026
…#7627)

* Initial plan

* fix: push step condition to children instead of group to fix evaluation ordering

When a step has both a condition (e.g., env.TEST) and artifacts, the
processor creates a group stage. The group's Start action is evaluated
before the Container transition that loads scoped environment variables.
This caused the condition to evaluate to false (empty env var) and skip
the entire step.

Fix: Set the group condition to literal 'true' so it always starts, and
push the step condition to each child operation via AppendConditions.
Also propagate virtual group conditions to children during Flatten so
nested step conditions work correctly.

Agent-Logs-Url: https://github.com/kubeshop/testkube/sessions/eee39f98-f969-4696-9cdf-7a0ff62c5f45

Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>

* test: add regression test for condition evaluation with artifacts

Agent-Logs-Url: https://github.com/kubeshop/testkube/sessions/eee39f98-f969-4696-9cdf-7a0ff62c5f45

Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>

* fix: improve comment explaining group condition change

Agent-Logs-Url: https://github.com/kubeshop/testkube/sessions/eee39f98-f969-4696-9cdf-7a0ff62c5f45

Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>

* chore: revert go.sum to original state

Agent-Logs-Url: https://github.com/kubeshop/testkube/sessions/6ceb86f0-3eb8-4a71-8595-cb79d51e76da

Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>

* fix: go mod

Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>

---------

Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vsukhin <5984962+vsukhin@users.noreply.github.com>
Co-authored-by: Vladislav Sukhin <vladislav@kubeshop.io>
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
# Conflicts:
#	go.sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect evaluation of test step condition

3 participants