Repository navigation
Introduce ScriptTrigger & CommandsTrigger for the .NET plugin - #435
fdelbrayelle merged 5 commits into
Conversation
58614bf to
4c23436
Compare
|
Heads up for whoever reviews this: it is the same code as the PowerShell (#436), Deno (#434) and Bun (#433) ports, and those reviews found issues that apply here unchanged, so I ported the fixes before review (4c23436, rebased onto current main).
Left as in the sibling PRs, and open to changing once decided for the family: 🤖 AI-assisted, as noted in the description. Update: the edge limitation described above is fixed in 3cd505f. The state now lives in the namespace KV store, and I have since run the container-backed tests locally (28 across the four trigger test classes, all passing). |
fdelbrayelle
left a comment
There was a problem hiding this comment.
Kestra Plugin Code Review
Business Requirements — partial
The PR delivers a ScriptTrigger and CommandsTrigger for plugin-script-dotnet, addressing the core ask of #424/#313 (poll the underlying Script/Commands task, emit an execution when a condition matches). However, neither issue's stated commandPattern / argumentsPattern properties nor the exitCode != 0 expression-style exitCondition syntax shown in both issues' example YAML are implemented — only a literal exit N or regex/substring match against emitted vars is supported. This mirrors the precedent already merged in plugin-script-go and plugin-script-node (neither implements commandPattern/argumentsPattern either), so it's a pre-existing, repo-wide scope reduction rather than something unique to this PR — flagging for visibility, not blocking on it alone.
Kestra Guidelines — 5 findings
- 🔴 Edge-mode dedup does not work as documented/defaulted (see inline, both trigger files)
- 🟠 Missing
@ToString.Excludeon mutablelastMatchedfield (both trigger files) - 🟠 Class-level
@Schema(description = ...)uses a single-line string instead of a text block (both trigger files) - 🟠 Package how-to doc not updated with a
## Triggerssection (cross-cutting, see below) - 🟠
AGENTS.mdnot updated to list the new trigger classes (cross-cutting, see below)
Cross-cutting (not anchorable to the new-file diff):
-
🟠 [Guidelines] Package how-to doc missing Triggers section
Problem:plugin-script-dotnet/src/main/resources/doc/io.kestra.plugin.scripts.dotnet.mddocuments onlyScript/Commandsunder## Tasks; it has no## Triggerssection for the two new trigger classes this PR adds.
Fix: add a## Triggerssection listingScriptTrigger/CommandsTrigger, their key properties (exitCondition,edge,interval,containerImage) and outputs, per the "Plugin How-To Doc" guideline ("when a task, trigger... is added... update the matching section"). Note:plugin-script-go's andplugin-script-node's docs have the same gap — worth a follow-up across the repo, but this PR is the one adding new trigger surface right now. -
🟠 [Guidelines] AGENTS.md not updated for new trigger classes
Problem:AGENTS.md§"Key Plugin Classes" →plugin-script-dotnetstill lists onlyCommands/Script; the two newScriptTrigger/CommandsTriggerclasses aren't listed, so an agent readingAGENTS.mdwon't know they exist.
Fix: addio.kestra.plugin.scripts.dotnet.ScriptTriggerandio.kestra.plugin.scripts.dotnet.CommandsTriggerto theplugin-script-dotnetentry (same gap exists forgo/node, but keep this PR's own module in sync per the "Must Do" AGENTS.md rule).
Security (OWASP Top 10:2025 + KPS) — ✅ No issues found
No secret fields, no HTTP calls, no manual shell string concatenation (commands/script are handed to the existing Commands/Script tasks unchanged), no deserialization or XML parsing. Broad catch (Exception e) in evaluate() logs via runContext.logger().warn(..., e) without leaking any secret-shaped data.
Performance — ✅ No issues found
Per-poll synchronous container execution matches the existing go/node pattern; the only dynamically-compiled Pattern is the user-supplied exitCondition regex, which is unavoidable per-evaluation compilation for a feature that accepts arbitrary user regex — the static exit-code pattern is correctly hoisted to a static final. No unbounded collections or leaked resources introduced.
Verdict: REQUEST CHANGES
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-dotnet 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.dotnet.Script - CommandsTrigger wraps io.kestra.plugin.scripts.dotnet.Commands - Both default containerImage to 'mcr.microsoft.com/dotnet/sdk:10.0', matching the existing Script/Commands tasks' default Fixes kestra-io#424
…/CommandsTrigger (dotnet) The same code was reviewed on the PowerShell, Deno and Bun PRs and the findings apply here unchanged, so this ports them before review. - ScriptTriggerTest no longer asserts against a private copy of the matching logic. matchesCondition is package-private and the tests call it on a real ScriptTrigger (CsvSource table for exit codes). - Documented the edge mode limitation instead of leaving it silently broken: lastMatched is a plain field that does not survive the worker's serialize/deserialize round trip, so in a distributed deployment edge mode fires on every matching poll. Code comment, corrected schema descriptions, and a note on the edge test that only proves same-instance dedup. The real fix needs a cross-poll state mechanism shared by the whole plugin family and is tracked separately. - Removed the "failure logs" claim from the docs: a failed run passes null vars, so only 'exit N' can match a failure. - @EqualsAndHashCode.Exclude on lastMatched, with a comment that says only what the exclusion does (equals already falls back to object identity via AbstractTrigger and callSuper=call). - Example intervals PT10S -> PT60S, matching the coded default.
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 from the review: - class level @Schema descriptions are text blocks - an empty exitCondition now fails with a clear message instead of silently never matching - 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
4c23436 to
3cd505f
Compare
|
@InnoxCodes Thanks for the fixes — most of #pullrequestreview-5266633325 is addressed (KV-store edge dedup,
Can you take a pass at these two? |
|
Thanks for checking back. Both of these were actually already done in 3cd505f, the same commit you called the KV-store dedup fixed in:
Both are still there on the current head (55d02e7, after your merge from main just now). Let me know if something did not come through on your side, happy to double check. |
…dotnet) Malaydewangan09 flagged this on the PowerShell PR: 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. 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.
|
Verified against
One correction on your last comment: One new (non-blocking) finding from the fix itself: Otherwise LGTM from my side. |
|
Thanks for the thorough re-verification, and for catching the stale wording, fixed that inline comment. Good catch on the duplication too, and you are right that it is new: those seven items were identical before too (same pattern already existed for the exit-code matching and the failure extraction), but the KV fix added I held off on a shared base class in this PR for one reason: the exact same duplicated shape now exists identically in the sibling PowerShell PR (#436), since it got the same fix for the same review comment, and Bun (#433) had it before merging too. Pulling it into a shared base only in this PR would leave dotnet structurally different from its siblings for no functional reason, and a real fix should cover the whole family in one place, either an Happy to open a tracking issue for it if one does not already exist. Let me know if you would rather I take a pass at the extraction here instead. |
|
Edition: OSS | Docker tag: develop (next: 2.1.0-SNAPSHOT) QA results: all 6 scenarios pass
Flows were created through the API, results checked via API and UI (Gantt screenshots in the gallery). Flow 1: dotnet_script_trigger (✅ SUCCESS)Flow YAMLid: dotnet_script_trigger
namespace: qa.dotnet
triggers:
- id: script_failure
type: io.kestra.plugin.scripts.dotnet.ScriptTrigger
interval: PT10S
exitCondition: "exit 1"
edge: true
containerImage: mcr.microsoft.com/dotnet/sdk:10.0
script: |
System.Environment.Exit(1);
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered with exitCode={{ trigger.exitCode }} (condition={{ trigger.condition }})"Gantt (screenshot)
Logs: Flow 2: dotnet_commands_trigger (✅ SUCCESS)Flow YAMLid: dotnet_commands_trigger
namespace: qa.dotnet
triggers:
- id: commands_failure
type: io.kestra.plugin.scripts.dotnet.CommandsTrigger
interval: PT10S
exitCondition: "exit 1"
edge: true
containerImage: mcr.microsoft.com/dotnet/sdk:10.0
commands:
- dotnet run --project missing
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered with exitCode={{ trigger.exitCode }} (condition={{ trigger.condition }})"Gantt (screenshot)
Logs: Flow 3: dotnet_script_trigger_noedge (✅ SUCCESS)Flow YAMLid: dotnet_script_trigger_noedge
namespace: qa.dotnet
triggers:
- id: script_failure
type: io.kestra.plugin.scripts.dotnet.ScriptTrigger
interval: PT10S
exitCondition: "exit 1"
edge: false
containerImage: mcr.microsoft.com/dotnet/sdk:10.0
script: |
System.Environment.Exit(1);
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered with exitCode={{ trigger.exitCode }} (condition={{ trigger.condition }})"Same as flow 1 with Flow 4: dotnet_script_trigger_nomatch (✅ no execution)Flow YAMLid: dotnet_script_trigger_nomatch
namespace: qa.dotnet
triggers:
- id: script_failure
type: io.kestra.plugin.scripts.dotnet.ScriptTrigger
interval: PT10S
exitCondition: "exit 1"
edge: true
containerImage: mcr.microsoft.com/dotnet/sdk:10.0
script: |
System.Environment.Exit(0);
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: "Triggered with exitCode={{ trigger.exitCode }} (condition={{ trigger.condition }})"Script exits 0, condition is Flow 5: dotnet_script_task (✅ SUCCESS, non-regression)Flow YAMLid: dotnet_script_task
namespace: qa.dotnet
tasks:
- id: s
type: io.kestra.plugin.scripts.dotnet.Script
script: |
System.Console.WriteLine("hello from dotnet script");Gantt (screenshot)
Logs: Flow 6: dotnet_commands_task (✅ SUCCESS, non-regression)Flow YAMLid: dotnet_commands_task
namespace: qa.dotnet
tasks:
- id: c
type: io.kestra.plugin.scripts.dotnet.Commands
commands:
- dotnet --version
Logs: Notes
|
Summary
Fixes #424, 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-dotnetwas 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.dotnet.Script;CommandsTriggerwrapsio.kestra.plugin.scripts.dotnet.Commands. Both defaultcontainerImagetomcr.microsoft.com/dotnet/sdk:10.0, 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 also fails without the KV write./gradlew :plugin-script-dotnet:spotlessCheckfails, but only onScript.java, which has a pre-existing import-order 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.