Skip to content

Introduce ScriptTrigger & CommandsTrigger for the Deno plugin - #434

Merged
Malaydewangan09 merged 2 commits into
kestra-io:mainfrom
InnoxCodes:feature/deno-script-commands-triggers
Sep 21, 2026
Merged

Malaydewangan09 merged 2 commits into
kestra-io:mainfrom
InnoxCodes:feature/deno-script-commands-triggers

Conversation

@InnoxCodes

@InnoxCodes InnoxCodes commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #423, part of #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-deno was missing both.

Implementation

Ports the pattern already established in plugin-script-go and plugin-script-node (checked both as reference implementations, per the issue). 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
  • Supports edge mode (default on) to emit only on a not-matching-to-matching transition, so the trigger doesn't fire repeatedly on every poll while the condition stays true

ScriptTrigger wraps io.kestra.plugin.scripts.deno.Script; CommandsTrigger wraps io.kestra.plugin.scripts.deno.Commands. Both default containerImage to denoland/deno, matching the existing Script/Commands tasks' own default.

Testing

  • ScriptTriggerTest mirrors the pure condition-matching unit tests from plugin-script-go's ScriptTriggerTest (no Docker required), now calling the real package-private matchesCondition and covering the permissions wiring, 15/15 pass
  • CommandsTriggerTest mirrors plugin-script-go's integration-style tests that call trigger.evaluate(...) directly against a real container run. I don't have Docker available in my sandbox, so I could not run this file locally; it follows the exact same structure already merged and passing in plugin-script-go/plugin-script-node, with denoland/deno:latest as the image and shell-level commands (exit 1, echo '::{"outputs":...}::') that run the same way regardless of the container's runtime
  • ./gradlew :plugin-script-deno:compileJava :plugin-script-deno:compileTestJava succeeds
  • ./gradlew :plugin-script-deno:spotlessCheck fails, but only on Commands.java, which has a pre-existing import-order violation on main unrelated to this PR

🤖 AI-assisted: I used Claude Code to help draft and verify this fix; I reviewed the diff and cross-checked it against the existing Go/Node reference implementations before opening this PR.

@Malaydewangan09

Malaydewangan09 commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Same review as #436, because this is the same file with the package and image name swapped. 23 lines differ from the go copy, all cosmetic.

Ran it locally: 17/17 pass including the Docker tests.

Findings, all of which apply to the other copies too:

  • edge mode doesn't survive the worker dispatch, so it fires on every matching poll
  • vars is null on the failure path, so only exit N can ever match a failed run
  • extractFailure returns a null exit code when there's no TaskException in the cause chain, so infra failures don't fire. Confirmed on this module: bad image tag with exitCondition: exit 1 and edge: false, the trigger did not fire
  • the user regex is recompiled on every poll
  • CommandsTriggerTest's edge test reuses one instance and masks the defect
  • ScriptTriggerTest doesn't touch production code at all, it re-implements matchesCondition as exitConditionMatches and asserts against the copy

#436 already has fixes for the test and the doc wording, worth porting those across rather than re-deriving them.

One thing specific to Deno. Script has a permissions property (added in #415) defaulting to --allow-env,--allow-read,--allow-write. The trigger doesn't expose it, so a trigger script can never be granted --allow-net. Polling an HTTP endpoint is the obvious use for a Deno polling trigger and it's unreachable. Same script run both ways:

WITH --allow-net                    -> SUCCESS exitCode=0
trigger defaults (no --allow-net)   -> FAILED  exit code 1

That one is worth fixing here rather than deferring, since it's small and specific to this module.

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-deno 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.deno.Script
- CommandsTrigger wraps io.kestra.plugin.scripts.deno.Commands
- Both default containerImage to 'denoland/deno', matching the existing
  Script/Commands tasks' default

Fixes kestra-io#423
Ports the review fixes from the PowerShell PR and adds the one Deno
specific item the reviewer asked for.

- ScriptTrigger now exposes the Script task's `permissions` property
  (same default: --allow-env, --allow-read, --allow-write) and passes
  it through. Without it a trigger script could never be granted
  --allow-net, so polling an HTTP endpoint, the obvious use of a Deno
  polling trigger, always failed under the sandbox. Added an example
  that polls an endpoint with --allow-net. The task construction moved
  into a package-private buildTask() so the wiring is unit tested
  without Docker.
- 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.

Reviewed-by: Malaydewangan09
@InnoxCodes
InnoxCodes force-pushed the feature/deno-script-commands-triggers branch from e866daf to 936ae92 Compare September 18, 2026 15:01
@InnoxCodes

Copy link
Copy Markdown
Contributor Author

Thanks for the local run and for pointing at the #436 fixes, ported those across (936ae92, rebased onto current main).

Deno specific, permissions: fixed here as you suggested. ScriptTrigger now exposes the Script task's permissions property with the same default (--allow-env, --allow-read, --allow-write) and passes it through, so a trigger script can be granted --allow-net. I added an example that polls an HTTP endpoint with it. To unit test the wiring without Docker I moved the task construction into a package-private buildTask(); there are two tests, one that the default matches Script's own default so they can't drift, and one that a custom value reaches the task. I checked the second one fails if I drop the passthrough. CommandsTrigger needs nothing since Commands takes the raw command line, so deno run --allow-net ... already works there.

Ported from #436: ScriptTriggerTest now calls the real package-private matchesCondition (CsvSource table for exit codes), the "failure logs" claim is gone from the docs (only exit N can match a failed run), the edge limitation is documented in the code comment, schema descriptions and on the edge test, @EqualsAndHashCode.Exclude on lastMatched with the corrected comment, and example intervals are PT60S. I also corrected the spotlessCheck line in the description: it only fails on Commands.java, which is already unformatted on main.

Not changed, deliberately:

  • extractFailure returning a null exit code when there is no TaskException: this is a behaviour choice rather than a bug fix (should a container that never started count as exit 1?), and it is identical in all the copies, so I'd rather you decide it once for the family than have four PRs diverge.
  • Regex recompiled per poll: I left it. Compiling a small pattern once a minute is negligible next to a container run, and a static cache keyed on the rendered condition would need a bound because templated conditions can vary. Happy to add a bounded cache if you'd still like it.

Unit tests pass locally (15/15 in this module). I still don't have Docker, so the container-backed tests are unrun on my side, though nothing in this change touches their paths apart from the new permissions default, which matches what Script already used.

🤖 AI-assisted, as noted in the description.

@Malaydewangan09

Copy link
Copy Markdown
Member

936ae92 is good. 23/23 pass here including the container-backed ones.

Checked the permissions work rather than just reading it:

  • dropped .permissions(this.permissions) from buildTask() and buildTask_passesTriggerPermissionsThroughToTheScriptTask failed, so the passthrough is genuinely covered. The drift test still passes under that mutation, which is correct, it guards the default value rather than the wiring.
  • end to end through evaluate() against a real container:
with --allow-net    fired=true   vars={net=status-200}
default perms       fired=false

So the gap is actually closed, not just wired.

The ported fixes all landed: no "failure logs" left in either class, no unqualified "emit only on transitions", PT60S in all three examples, Exclude on both, matchesCondition package-private on both.

Agreed on both deferrals. The extractFailure one is a real behaviour question (a container that never started isn't obviously exit 1) and should be decided once for the family. And you're right about the regex, a per-poll compile is noise next to a container start, and a naive cache keyed on a templated condition would grow unbounded. Leave it.

Nothing blocking from me.

@Malaydewangan09
Malaydewangan09 merged commit 9f7a1d2 into kestra-io:main Sep 21, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from To review to Done in Pull Requests Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Introduce ScriptTrigger & CommandsTrigger for the Deno plugin

3 participants