Skip to content

W-23517404: Add integration tests + charset decode fix#132

Open
mlischetti wants to merge 1 commit into
masterfrom
W-23517404-group-b-integration-tests
Open

W-23517404: Add integration tests + charset decode fix#132
mlischetti wants to merge 1 commit into
masterfrom
W-23517404-group-b-integration-tests

Conversation

@mlischetti

Copy link
Copy Markdown
Contributor

What

Closes gaps F3 (concurrency / FFI edge cases) and F5 (error & edge-input matrix) from TESTING_ASSESSMENT.md for the @dataweave/native Node.js binding.

While writing the F5 charset tests, this also fixes a real bug in getString().

Bug fix — src/result.ts

ExecutionResult.getString() passed the runtime's IANA charset name (UTF-16, US-ASCII, ISO-8859-1) straight to Buffer.toString, which threw ERR_UNKNOWN_ENCODING on a successful result. Replaced the unchecked as BufferEncoding cast with a new decodeBytes() that:

  • maps common charsets to valid Node encodings,
  • handles UTF-16 byte order (BOM detection + big-endian byte-swap, since Node only decodes LE),
  • falls back to UTF-8 for unknown charsets instead of throwing.

Backed by 10 new unit tests.

Integration tests — tests/integration/edge-cases.test.ts (20)

  • Concurrency / FFI: runTransform async-iterable input (pre-buffered path), empty & throwing async inputs, multi-instance lifecycle, idempotent initialize, double-cleanup, re-init after cleanup, run-before-init guard, 25 concurrent runs, interleaved concurrent streaming.
  • Error & edge inputs: binary output getBytes round-trip, output charset matrix, unknown input/output mime types, missing input reference, compilation/syntax error, malformed input content.

Known limitation (tracked)

A bad-library-path initialize() throws DataWeaveError only as the first init in a process (the native runtime is ref-counted / process-global), so it can't be asserted in the shared lane without test-order coupling.
Documented in-file and verified manually; tracked as follow-up W-23517830.

Testing

  • tsc --noEmit clean
  • npm run test:unit70 passed
  • npm run test:integration34 passed against the real native library

🤖 Generated with Claude Code

…de fix

Add integration-lane coverage for gaps F3 (concurrency / FFI edge cases)
and F5 (error & edge-input matrix) from TESTING_ASSESSMENT.md, and fix a
real charset bug surfaced while writing the F5 charset tests.

Fix (src/result.ts):
- ExecutionResult.getString() passed the runtime's IANA charset name (e.g.
  UTF-16, US-ASCII, ISO-8859-1) straight to Buffer.toString, which threw
  ERR_UNKNOWN_ENCODING on a successful result. Replace the unchecked
  `as BufferEncoding` cast with decodeBytes(), which maps common charsets to
  valid Node encodings, handles UTF-16 byte order (BOM detection + big-endian
  byte-swap, since Node only decodes LE), and falls back to UTF-8 for unknown
  charsets instead of throwing.
- 10 new unit tests for decodeBytes (BE/LE/BOM, latin1, ascii, unknown
  fallback, no caller-buffer mutation).

Group B integration tests (tests/integration/edge-cases.test.ts, 20):
- Concurrency / FFI: runTransform async-iterable input (pre-buffered path),
  empty and throwing async inputs, multi-instance lifecycle, idempotent
  initialize, double-cleanup, re-init after cleanup, run-before-initialize
  guard, concurrent runs on the singleton, interleaved concurrent streaming.
- Error & edge inputs: binary output getBytes round-trip, output charset
  matrix (UTF-8/16/16LE/16BE/ISO-8859-1 + US-ASCII substitution), unknown
  input/output mime types, missing input reference, compilation/syntax error,
  malformed input content.

Documented (not asserted): a bad-library-path initialize() throws only as the
first init in a process (the native runtime is ref-counted / loaded
process-globally), so it can't be asserted in the shared lane without an
isolated child process — verified manually, tracked as a follow-up.

Verified: tsc clean, 70 unit tests pass, 34 integration tests pass against
the real native library.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mlischetti
mlischetti requested a review from a team as a code owner July 20, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant