Skip to content

Conversation

@akapug
Copy link
Member

@akapug akapug commented Aug 23, 2025

Ready for review Powered by Pull Request Badge

Summary

This PR implements the Node.js stream/promises functions finished and pipeline in the Elide runtime and expands unit test coverage.

Runtime changes (packages/graalvm/src/main/kotlin/elide/runtime/node/stream/NodeStreamPromises.kt):

  • finished(stream)

    • Resolves on end (readable) or finish (writable)
    • Rejects on error
    • Immediate settle:
      • Reject if stream.errored is non-null
      • Resolve if stream.readableEnded or stream.writableFinished is true
    • Attaches once handlers for end, finish, and error
    • Cleans up listeners on settle using off
  • pipeline(...streams)

    • Chains streams via src.pipe(dest)
    • Resolves when the last stream emits end or finish
    • Rejects on error from any stream
    • Immediate settle based on last stream state:
      • Resolve if already ended/finished
      • Reject if already errored
    • Cleans up all listeners on settle using off

Test changes (packages/graalvm/src/test/kotlin/elide/runtime/node/NodeStreamPromisesTest.kt):

  • finished

    • Resolves on end and finish, cleans listeners
    • Rejects on error, cleans listeners
    • Immediate resolve when readableEnded === true
    • Immediate resolve when writableFinished === true
    • Immediate reject when errored is set
    • Error takes priority over ended state (rejects even if readableEnded === true)
  • pipeline

    • Pipes sequentially and resolves on last stream end, cleans listeners on settle
    • Rejects on intermediate error and cleans listeners
    • Immediate resolve if last stream is already readableEnded
    • Immediate reject if last stream already has errored
    • Resolves immediately when called with no streams
    • Single-stream behavior: resolves on end and cleans listeners
    • Rejection when a pipe() call throws; verifies that no event listeners are attached when piping fails before listener setup

How to run

From repo root:

  • Entire graalvm test suite:
    • ./gradlew :packages:graalvm:test
  • Only this class:
    • ./gradlew :packages:graalvm:test --tests "elide.runtime.node.NodeStreamPromisesTest"

Follow-ups / Improvements

  • Add a test to verify that pipeline(...) also resolves when the last stream emits finish (not just end) and that listeners are cleaned in that path as well. This is pending and not included in this PR.
  • Consider tests for:
    • Multiple error emissions (first error wins, cleanup ensures no further callbacks)
    • Timing nuance: immediate settle when both readableEnded and writableFinished are false vs. toggled after listener attachment
    • Native Node parity by mirroring these guest-side tests in a Node-only suite to catch behavioral drifts.

@akapug akapug requested a review from sgammon as a code owner August 23, 2025 07:44
@codecov
Copy link

codecov bot commented Aug 24, 2025

Codecov Report

❌ Patch coverage is 80.58252% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.80%. Comparing base (fe71087) to head (b6a271a).
⚠️ Report is 146 commits behind head on main.

Files with missing lines Patch % Lines
...in/elide/runtime/node/stream/NodeStreamPromises.kt 80.58% 6 Missing and 14 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1618      +/-   ##
==========================================
+ Coverage   39.68%   39.80%   +0.11%     
==========================================
  Files         781      781              
  Lines       37169    37270     +101     
  Branches     5253     5273      +20     
==========================================
+ Hits        14752    14834      +82     
- Misses      20648    20654       +6     
- Partials     1769     1782      +13     
Flag Coverage Δ
jvm 39.80% <80.58%> (+0.11%) ⬆️
lib 39.80% <80.58%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...in/elide/runtime/node/stream/NodeStreamPromises.kt 82.50% <80.58%> (-6.98%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b72d183...b6a271a. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

akapug added a commit to akapug/elide that referenced this pull request Aug 24, 2025
…conflicts favoring completed finished/pipeline semantics
@akapug akapug marked this pull request as draft August 25, 2025 17:03
@sgammon sgammon closed this Nov 2, 2025
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.

2 participants