Repository navigation
Introduce ScriptTrigger & CommandsTrigger for the PowerShell plugin - #436
Conversation
|
Ran this locally. All 17 tests pass including the 4 Docker ones you couldn't run, the powershell image is fine and both test commands behave as expected under pwsh. So the thing works. Two things I'd want fixed before merge.
No It re-fires on every poll, which is the opposite of what the property promises. And
Smaller stuff:
The duplication is not on you, it's on us for letting it reach five copies. I'll open a separate issue for the |
|
Thanks for actually running this and for the depth here. Confirmed both main points independently before touching anything, pushed a fix for what's safely scoped to this PR: edge / lastMatched: confirmed your finding exactly - it's a plain
Happy to pick this up properly once you've opened the ScriptTriggerTest doesn't test ScriptTrigger: fixed by copying Ruby's Smaller stuff, all fixed:
Not touched, intentionally deferred rather than silently dropped:
All 13 non-Docker 🤖 AI-assisted, as disclosed in the PR description - I read and verified all of the above myself rather than taking your comment at face value. |
|
Pulled Verified fixed: One miss: Correction on my side: the Fix line 47 and I'm happy. The deferrals are the right calls, tracking issue coming. |
|
Thanks for the mutation test and for catching both of these. Class-level description: you're right, The 🤖 AI-assisted - verified both independently against the actual lombok config and AbstractTrigger source rather than taking the correction at face value. |
|
Two things still open:
Neither is introduced by you and both exist in all six copies, so I'm fine treating them as part of the same family cleanup rather than blocking here. Flagging so they don't get lost. |
38d9065 to
19dba84
Compare
Part of kestra-io#313. plugin-scripts wants every submodule to expose a ScriptTrigger and a CommandsTrigger so a flow can be triggered whenever the underlying script/commands execution completes, with an exit condition deciding whether the trigger fires. plugin-script-powershell was missing both. Ports the pattern already established in plugin-script-go and plugin-script-node (the two existing reference implementations checked against): a polling trigger that runs the sub-plugin's Script/Commands task once per poll, matches the rendered exitCondition against either the exit code ('exit N') or a regex/substring against the emitted vars and failure logs, and supports edge mode (default on) to emit only on a not-matching-to-matching transition. - ScriptTrigger wraps io.kestra.plugin.scripts.powershell.Script - CommandsTrigger wraps io.kestra.plugin.scripts.powershell.Commands - Both default containerImage to 'ghcr.io/kestra-io/powershell:latest', matching the existing Script/Commands tasks' default Fixes kestra-io#431
- ScriptTriggerTest no longer duplicates matchesCondition's logic in a private test helper (exitConditionMatches). matchesCondition is now package-private and the test calls it directly on a real ScriptTrigger instance, matching plugin-script-ruby's ScriptTriggerConditionTest pattern. Before this, the test asserted against a hand-copied reimplementation and would have stayed green even if the real method's body were emptied out. - Documented the lastMatched/edge-mode limitation instead of leaving it silently broken: polling triggers are dispatched to a worker as a serialized payload with no getter for lastMatched, so it never survives that round trip. In a real distributed deployment, edge mode currently degenerates to firing on every matching poll rather than only on a not-matching-to-matching transition. Added this as an explicit code comment and corrected the edge property's schema description, and added the same note to CommandsTriggerTest's edge-mode test, which only proves same-instance dedup. Fixing the underlying cross-poll state problem needs a real mechanism for persisting state across a serialized worker dispatch, which affects the whole plugin-script-go/node/python/ruby/shell family this pattern was copied from, not just this PR - deferring that to the AbstractScriptTrigger tracking issue rather than a narrow, unreviewed fix here. - Added @EqualsAndHashCode.Exclude on lastMatched so two identically built triggers still compare equal (AtomicBoolean has no useful identity-independent equals). - Corrected the exitCondition docs: the failure path never has vars to match against, so "failure logs" was never actually reachable - documented that only 'exit N' can match a failed run. - Example intervals changed from PT10S to PT60S, matching the documented/coded 60s default and the reviewer's measured cold-start time. Reviewed-by: Malaydewangan09
- ScriptTrigger's class-level @Schema description still said "Supports edge mode to emit only on transitions... matched against emitted vars and failure logs" - the same overclaims already corrected on the edge and exitCondition properties, just missed at the class level. CommandsTrigger's class-level description was already accurate. - The lastMatched comment claimed @EqualsAndHashCode.Exclude makes two identically built triggers compare equal. That's wrong: this project's lombok.config sets equalsAndHashCode.callSuper=call, and AbstractTrigger has no equals() override, so every generated equals() opens with Object's reference-identity check regardless of which fields are excluded. Two distinct instances are never equal no matter what. Corrected the comment to say what the exclusion actually does (keeps this mutable field itself out of equality) and note the identity-equals behavior is pre-existing and unrelated to it. Reviewed-by: Malaydewangan09
The edge flag lived in an AtomicBoolean on the trigger, but a polling trigger is rebuilt on every poll, so with the default edge=true a condition that stays true fired on every interval. The previous result is now stored under a length prefixed key built from the flow and trigger ids in the namespace KV store and updated on every poll. Also: - an empty exitCondition now fails with a clear message instead of silently never matching - class level @Schema descriptions are text blocks - the edge tests run the second poll on a serialized copy of the trigger - add a Docker backed ScriptTrigger#evaluate test - add KV state tests that run without Docker - document the triggers in the module doc and list them in AGENTS.md
19dba84 to
d29797d
Compare
|
@Malaydewangan09 heads up, I pushed d29797d after your last look. It moves the Beyond that it adds |
|
I re-ran the reproduction that started this, full That was Three small things on the KV handling, none blocking:
Everything else from the .NET review landed here too: class-level Good from me. |
…powershell) With the default 60s interval, a condition that stays matched or stays unmatched wrote the same value to the namespace KV store on every single poll for no reason. Now the write only happens when the poll actually changes the result. Same fix as the .NET PR, which is where this came up first. Verified with a test that checks the KV entry's version stays put across repeated polls and still increments on a real transition, and that removing the guard makes it fail.
|
Thanks for the close re-check, and for calling out the reproduction numbers, that is exactly the sequence this was supposed to fix. Pushed f780479 for the write amplification one: the KV write is now skipped whenever the poll repeats the previous result, only an actual transition writes. Added a test that reads the KV entry back and checks its version does not move across repeated polls but does increment on a real transition, so the skip is actually proven rather than just claimed. Same fix went to the .NET PR since you raised it here first. Left the other two as you suggested:
|
|
The thing I wanted to be sure the write-skip hadn't broken is the transition detection itself, since state is now only persisted on a change. Ran a full cycle in both directions through Both edges land where they should, so the optimization is behaviour preserving. Reading the version back rather than asserting on a mock is the right way to have tested it. Agreed on leaving the other two, and your reasoning is better than my original note on both:
Nothing left from me on this one. |
|
Edition: OSS | Docker tag: develop (next: 2.1.0-SNAPSHOT) QA summary
Trigger variables exposed to the flow in both edge flows: ps_script_trigger_fail (✅ SUCCESS)Flow YAMLid: ps_script_trigger_fail
namespace: qa.ps
triggers:
- id: t
type: io.kestra.plugin.scripts.powershell.ScriptTrigger
interval: PT10S
exitCondition: "exit 1"
edge: true
containerImage: ghcr.io/kestra-io/powershell:latest
script: |
exit 1
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered exitCode={{ trigger.exitCode }} condition={{ trigger.condition }}"Gantt (screenshot)
Logs synthesis (screenshot): execution started by the trigger, ps_commands_trigger_fail (✅ SUCCESS)Flow YAMLid: ps_commands_trigger_fail
namespace: qa.ps
triggers:
- id: t
type: io.kestra.plugin.scripts.powershell.CommandsTrigger
interval: PT10S
exitCondition: "exit 1"
edge: true
containerImage: ghcr.io/kestra-io/powershell:latest
commands:
- exit 1
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered exitCode={{ trigger.exitCode }} condition={{ trigger.condition }}"Gantt (screenshot)
Logs synthesis (screenshot): trigger fired, ps_script_trigger_noedge (✅)Flow YAMLid: ps_script_trigger_noedge
namespace: qa.ps
triggers:
- id: t
type: io.kestra.plugin.scripts.powershell.ScriptTrigger
interval: PT10S
exitCondition: "exit 1"
edge: false
containerImage: ghcr.io/kestra-io/powershell:latest
script: |
exit 1
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered exitCode={{ trigger.exitCode }} condition={{ trigger.condition }}"3 executions in about 25s after the flow was set to ps_script_trigger_nomatch (✅)Flow YAMLid: ps_script_trigger_nomatch
namespace: qa.ps
triggers:
- id: t
type: io.kestra.plugin.scripts.powershell.ScriptTrigger
interval: PT10S
exitCondition: "exit 1"
edge: true
containerImage: ghcr.io/kestra-io/powershell:latest
script: |
exit 0
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered exitCode={{ trigger.exitCode }} condition={{ trigger.condition }}"Trigger polled every 10s (state updated each cycle), zero executions created. No screenshot captured. ps_script_task (✅ SUCCESS) and ps_commands_task (✅ SUCCESS)Flow YAMLid: ps_script_task
namespace: qa.ps
tasks:
- id: s
type: io.kestra.plugin.scripts.powershell.Script
script: |
Write-Output "hello script"
---
id: ps_commands_task
namespace: qa.ps
tasks:
- id: c
type: io.kestra.plugin.scripts.powershell.Commands
commands:
- Write-Output "hello commands"
Logs synthesis: both completed without errors or warnings. Notes
|
Summary
Fixes #431, part of #313.
plugin-scriptswants every submodule to expose aScriptTriggerand aCommandsTrigger, so a flow can be triggered whenever the underlying script/commands execution completes, with an exit condition deciding whether the trigger fires.plugin-script-powershellwas missing both.Implementation
Ports the pattern already established in
plugin-script-goandplugin-script-node(checked both as reference implementations, per the issue), with the edge state kept in the namespace KV store instead of an in-memory field. A polling trigger that:Script/Commandstask once per pollexitConditionagainst either the exit code (exit N) or a regex/substring against the emitted vars. A failed run has no vars, so onlyexit Ncan match a failureScriptTriggerwrapsio.kestra.plugin.scripts.powershell.Script;CommandsTriggerwrapsio.kestra.plugin.scripts.powershell.Commands. Both defaultcontainerImagetoghcr.io/kestra-io/powershell:latest, matching the existingScript/Commandstasks' own default. The module doc has a Triggers section andAGENTS.mdlists both classes.Testing
Ran locally with Docker, 28 tests across these four classes, all passing:
ScriptTriggerTest(13): pure condition-matching unit tests that call the real package-privatematchesCondition, no Docker neededEdgeStateTest(10): edge state in the KV store, no Docker needed. Each poll runs on a JSON round-tripped copy of the trigger, and there are cases foredge: false, for state being scoped per flow and per trigger, for the key format, and for the write being skipped on a repeated result (checked against the KV entry's version, which stays put across repeats and increments on a real transition). Removing eitherkvStore.putmakes the matching tests failScriptTriggerEvaluateTest(3): runs the realScriptTrigger#evaluatein a container (fires onexit 1, stays quiet onexit 0, suppresses the second poll in edge mode)CommandsTriggerTest(4): same forCommandsTrigger. Its edge test now runs the second poll on a serialized copy and also fails without the KV write./gradlew :plugin-script-powershell:spotlessCheckfails, but only onCommands.java, which has a pre-existing violation onmainunrelated to this PR🤖 AI-assisted: I used Claude Code to help draft and verify this fix, and cross-checked it against the existing Go/Node reference implementations before opening this PR.