elsa-core/test/integration
Marko Lahma 66b9079d3e
Bound JavaScript expression execution (#7891)
* feat(javascript): bound JavaScript expression execution

JavaScript expressions were evaluated with no execution constraints at all: no
timeout, no statement limit, no memory limit, no recursion limit, and the
ambient `CancellationToken` — already available at the call site and already
passed into `IJavaScriptEvaluator.EvaluateAsync` — was never handed to Jint.
An expression as simple as `while (true) {}` therefore occupied the calling
thread for the lifetime of the process, and cancelling the workflow did not
stop it.

This adds:

* `JintOptions.ExecutionTimeout` — wall-clock limit for a single expression,
  defaulting to 30 seconds. Deliberately generous so that existing expressions
  are unaffected; set to `null` to remove the limit.
* `JintOptions.MaxStatements`, `JintOptions.MemoryLimit` and
  `JintOptions.MaxRecursionDepth` — opt-in resource limits, off by default.
* The cancellation token is now passed to Jint, so cancelling a workflow aborts
  a script that is still running.

The security assessment documents already described a JavaScript execution
timeout as present; they now describe what is actually configurable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0179sA2T7HuRfRfSc2JirFik

* test(javascript): bound the constraint tests and cover the memory limit

Three of the execution-constraint tests removed the execution timeout entirely
and then ran `while (true) {}`, relying solely on the constraint under test to
stop them. If that constraint regressed, the test did not fail — it ran until
the CI job was killed, taking the rest of the suite with it.

Each such test now registers a generous 30 second failsafe timeout instead of
disabling the timeout. That is two orders of magnitude more than any of these
constraints needs (the slowest aborts in ~270 ms), so it cannot become a flaky
failure on a loaded machine, and `AssertAbortedByAsync` reports a failsafe trip
as exactly that rather than as an unexplained exception type mismatch.

The cancellation test also no longer races a wall-clock timer against engine
construction: the script signals the token itself through a host function, so
cancellation is guaranteed to land while the expression is running. The test
went from a 250 ms wall-clock wait to 5 ms and has no timing dependency left.

Adds the missing `MemoryLimit` test — the one configurable limit the suite did
not exercise. Doubling a string crosses the limit within a couple of dozen
statements, so it asserts `MemoryLimitExceededException` in ~40 ms and bounds
how far past the limit the process can get before the check fires.

Finally, the `ExpressionExecutionContext` is now built on the test host's
`IServiceProvider` rather than a throwaway empty one, matching every other test
in this project. An empty provider does not reflect real evaluation and can hide
failures in notification handlers that resolve services.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0179sA2T7HuRfRfSc2JirFik

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-17 01:21:19 +02:00
..
Elsa.Activities.IntegrationTests [codex] Fix ForEach completion from nested flowchart (#7702) 2026-06-08 12:04:55 +02:00
Elsa.AI.IntegrationTests chore: apply safe dependency upgrades (#7896) 2026-07-26 21:42:27 +02:00
Elsa.Alterations.IntegrationTests Address timestamp filter test cleanup review 2026-05-21 02:10:42 +02:00
Elsa.Bpmn.IntegrationTests test(bpmn): prove execution state and the work ledger survive real persistence (#7947) 2026-08-14 20:45:07 +02:00
Elsa.Bpmn.Interchange.IntegrationTests feat(bpmn): the work binder and the elsa: binding format (#7946) 2026-08-14 17:38:03 +02:00
Elsa.Common.IntegrationTests Add unit and integration tests for DownloadHttpFile activity (#7094) 2025-11-24 14:37:06 +01:00
Elsa.Diagnostics.ConsoleLogs.IntegrationTests [codex] Fix diagnostics live feed regressions (#7548) 2026-05-31 09:40:02 +02:00
Elsa.Diagnostics.OpenTelemetry.IntegrationTests [codex] Fix diagnostics live feed regressions (#7548) 2026-05-31 09:40:02 +02:00
Elsa.Diagnostics.StructuredLogs.IntegrationTests [codex] Add live server log streaming diagnostics (#7438) 2026-05-11 00:08:52 +02:00
Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.IntegrationTests Fix SQLite structured log shell lifecycle (#7461) 2026-05-18 01:04:04 +02:00
Elsa.Dsl.ElsaScript.IntegrationTests Add Elsa Script DSL (#7076) 2025-11-25 19:57:50 +01:00
Elsa.ExternalAuthentication.IntegrationTests Add architecture and practices documentation 2026-08-03 23:46:38 +02:00
Elsa.Http.IntegrationTests Improves HTTP context loss error handling (#7187) 2026-01-12 16:51:30 +01:00
Elsa.JavaScript.IntegrationTests Bound JavaScript expression execution (#7891) 2026-08-17 01:21:19 +02:00
Elsa.Resilience.IntegrationTests [codex] Secure Resilience simulate response endpoint (#7505) 2026-05-22 15:27:13 +02:00
Elsa.Workflows.IntegrationTests Merge release/3.8.0 into main 2026-08-14 11:59:35 +02:00
Directory.Build.props