elsa-core/test/integration
Marko Lahma ddc95d734d
Stop attaching Array.prototype to dictionary-like objects in JavaScript expressions (#7890)
* fix(javascript): stop attaching Array.prototype to dictionary-like objects

The custom `WrapObjectDelegate` installed by `JintJavaScriptEvaluator` duplicated
what Jint already does, and got it wrong in two ways.

Jint's default wrap handler is `ObjectWrapper.Create(engine, target, type)`, and
`ObjectWrapper` attaches `Array.prototype` to array-like wrappers by itself when
`Options.Interop.AttachArrayPrototype` is enabled (the default). Jint's own
array-likeness test deliberately excludes dictionary-like types, including
string-keyed generic dictionaries.

The handler we installed instead:

* Called `ObjectWrapper.Create(engine, target)`, dropping the declared `type`
  argument, so members were resolved against the runtime type rather than the
  declared one.
* Used `ObjectArrayHelper.DetermineIfObjectIsArrayLikeClrCollection`, which only
  excludes the non-generic `IDictionary`. `ExpandoObject` does not implement
  that interface, so it came out array-like.

Both the `variables` container and the `args` container are `ExpandoObject`
instances, which meant `Object.getPrototypeOf(variables) === Array.prototype`
was true and `variables.map`, `variables.filter`, `variables.reduce` and friends
were all visible on them, with `variables.length` reporting `0` instead of
`undefined`.

Removing the handler restores Jint's default, which handles every case the
custom one was written for: `List<T>`, `T[]`, `HashSet<T>`, `ImmutableArray<T>`,
`Queue<T>` and `Stack<T>` all still get `Array.prototype`, while dictionaries and
`ExpandoObject` no longer do.

`ObjectArrayHelper` is public, so it is marked obsolete rather than deleted.

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

* test(javascript): cast the ExpandoObject to its dictionary interface

`new ExpandoObject() as IDictionary<string, object>` reads as a conversion that
might fail and gives the variable a nullable declared type, when `ExpandoObject`
implements the interface unconditionally. A direct cast states that, and matches
the BCL's `IDictionary<string, object?>` annotation exactly so the value type
argument lines up too.

The two other `as IDictionary<string, object>` uses in this test project
(JintJavaScriptFunctionBehaviorTests) are deliberately left alone: there the
operand is the untyped result of a script evaluation, so the `as` is a genuine
type test paired with `Assert.NotNull`.

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-09-14 03:52:37 +02:00
..
Elsa.Activities.IntegrationTests [codex] Fix ForEach completion from nested flowchart (#7702) 2026-06-08 12:04:55 +02:00
Elsa.AI.IntegrationTests fix(bpmn): make document PUT If-Match and save a compare-and-swap (#8092) 2026-09-13 01:40:43 -07:00
Elsa.Alterations.IntegrationTests fix(alterations): preserve tenant context for background alteration jobs (#7962) 2026-09-06 20:07:36 -07:00
Elsa.Alterations.Persistence.ConformanceTests Fix Alterations ownership parity and MySQL retry (#8133) 2026-09-14 02:51:34 +02:00
Elsa.Bpmn.IntegrationTests fix(bpmn): let a process with only a plain start event publish (#8081) 2026-09-12 11:07:59 -07:00
Elsa.Bpmn.Interchange.IntegrationTests fix(bpmn): make document PUT If-Match and save a compare-and-swap (#8092) 2026-09-13 01:40:43 -07: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 refactor(auth)!: retire the legacy permission constants and duplicate descriptor types (#7987) 2026-08-25 06:04:32 +02:00
Elsa.Diagnostics.OpenTelemetry.IntegrationTests feat(auth)!: structured authorization model, phases 1-6 (#7980) 2026-08-24 23:44:55 +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 Adopt the Jint 4.15 host-integration surface: lazy type globals, enum names, and register-what-is-referenced (#7895) 2026-08-17 01:44:03 +02:00
Elsa.ExternalAuthentication.IntegrationTests test(ext-auth): share store conformance scenarios (#8096) 2026-09-13 15:58:40 +02:00
Elsa.Hosts.SmokeTests test(modular-host): add opt-in role management fixture 2026-09-06 04:25:09 +02:00
Elsa.Http.IntegrationTests Improves HTTP context loss error handling (#7187) 2026-01-12 16:51:30 +01:00
Elsa.JavaScript.IntegrationTests Stop attaching Array.prototype to dictionary-like objects in JavaScript expressions (#7890) 2026-09-14 03:52:37 +02:00
Elsa.Labels.Persistence.ConformanceTests test(labels): share InMemory/EF store conformance scenarios (#8122) 2026-09-13 18:58:36 +02:00
Elsa.Resilience.IntegrationTests [codex] Secure Resilience simulate response endpoint (#7505) 2026-05-22 15:27:13 +02:00
Elsa.Workflows.IntegrationTests fix: preserve single latest draft when saving a new identity (#7918) 2026-09-08 01:03:30 +02:00
Elsa.Workflows.Persistence.ConformanceTests test(workflows): share Memory/EF store conformance scenarios (#8115) 2026-09-13 18:07:09 +02:00
Directory.Build.props Add coverage enforcement for test projects (#6950) 2025-10-07 19:59:53 +02:00