Skip to content

Add supoort for os - #53

Merged
snelusha merged 4 commits into
mainfrom
feat/os
Aug 7, 2026
Merged

Add supoort for os#53
snelusha merged 4 commits into
mainfrom
feat/os

Conversation

@snelusha

@snelusha snelusha commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Resolves #42

Summary by CodeRabbit

  • New Features

    • Added cross-platform environment variable access and process execution support.
    • Added configurable runtime environment values for browser and Node.js execution.
    • Added process output, exit status, termination, and user information access.
    • Added browser HTTP service behavior and environment configuration documentation.
  • Bug Fixes

    • Improved runtime cleanup and error handling during WebAssembly execution.
  • Tests

    • Added coverage for environment overrides, OS operations, subprocess execution, and output handling.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@snelusha, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 39 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f07d11f3-4734-4205-9ada-98d39d7441e4

📥 Commits

Reviewing files that changed from the base of the PR and between 4fdcc59 and 0f4412e.

📒 Files selected for processing (5)
  • packages/ballerina-wasm/os_wasm.go
  • packages/balrun/README.md
  • packages/balrun/src/os.ts
  • packages/balrun/src/react.ts
  • packages/balrun/src/wasm-bridge.ts
📝 Walkthrough

Walkthrough

The change adds Node and browser OS platforms, supports environment configuration, connects OS operations to the WebAssembly runtime, and adds subprocess integration tests and runtime documentation.

Changes

OS platform support

Layer / File(s) Summary
Cross-runtime OS platform implementations
packages/balrun/src/os.ts
Adds OS and process contracts with Node and browser implementations for environment access, user information, process execution, output collection, waiting, and termination.
WebAssembly OS proxy wiring
packages/ballerina-wasm/main_wasm.go, packages/ballerina-wasm/os_wasm.go, packages/ballerina-wasm/pal_wasm.go
Passes the JavaScript os proxy through platform options and exposes its environment and process operations through the WebAssembly platform.
Environment option propagation
packages/balrun/src/ballerina-core.ts, packages/balrun/src/ballerina.ts, packages/balrun/src/index.ts, packages/balrun/src/react.ts, packages/balrun/src/wasm-bridge.ts
Adds the public Environment type and env option, preserves constructor and React configuration, and creates OS platform state for each run.
OS integration validation and documentation
packages/balrun/tests/ballerina.test.ts, packages/balrun/tests/wasm-bridge.test.ts, packages/balrun/tests/fixtures/os.bal, packages/balrun/README.md
Tests environment overrides and WebAssembly subprocess operations. Documents browser environment behavior and HTTP service integration.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BallerinaRun
  participant WasmBridge
  participant BallerinaRuntime
  participant OSPlatform
  BallerinaRun->>WasmBridge: start run with env
  WasmBridge->>OSPlatform: create per-run OS platform
  WasmBridge->>BallerinaRuntime: run with OS platform
  BallerinaRuntime->>OSPlatform: execute OS operation
  OSPlatform-->>BallerinaRuntime: return result
  BallerinaRuntime-->>WasmBridge: complete run
  WasmBridge-->>BallerinaRun: finish cleanup
Loading

Possibly related PRs

  • snelusha/balrun#16: Introduced the WasmBridge and BallerinaRunOptions pathways extended here for per-run OS support.
  • snelusha/balrun#52: Modified the same WebAssembly platform-option and runtime initialization paths.
  • snelusha/balrun#23: Changed the React option memoization path that now propagates env.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement OS environment and process support, with tests and documentation, as required by issue [#42].
Out of Scope Changes check ✅ Passed The code, tests, and documentation changes are related to OS support and its runtime integration.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding support for the os module.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/os

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
packages/balrun/src/wasm-bridge.ts (1)

21-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use the exported OSPlatform type directly.

ReturnType<typeof createOSPlatform> resolves to OSPlatform, which ./os already exports. Referencing the named type states the contract directly and does not depend on the factory signature.

♻️ Proposed refactor
-import { createOSPlatform } from "./os";
+import { createOSPlatform, type OSPlatform } from "./os";
 interface WasmPlatform {
 	httpListenerTransport: HTTPListenerTransport;
-	os: ReturnType<typeof createOSPlatform>;
+	os: OSPlatform;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/balrun/src/wasm-bridge.ts` around lines 21 - 24, Update the
WasmPlatform.os property type to use the exported OSPlatform type directly,
importing it from ./os as needed, instead of deriving it with ReturnType<typeof
createOSPlatform>. Preserve the existing interface contract and factory usage
elsewhere.
packages/balrun/src/react.ts (1)

37-42: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Document that env must use a stable reference.

useMemo compares dependencies with Object.is, so <BallerinaProvider env={new Map()} /> creates a new dependency object on every render. opts changes each render, useEffect re-creates the Ballerina instance, and the WASM bridge re-initializes unnecessarily. Note on the env prop that callers should memoize or hoist the value, or accept a plain record and build the Map inside the provider.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/balrun/src/react.ts` around lines 37 - 42, Document on the `env`
prop near the `BallerinaProvider` options that callers must provide a stable
reference, recommending memoizing or hoisting the Map; alternatively, accept a
plain record and construct the Map inside the provider. Preserve the existing
`useMemo` dependency behavior and avoid unrelated changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ballerina-wasm/os_wasm.go`:
- Around line 139-141: Update palProcess.call to validate p.proxy is a non-null
object and that the requested method property is a JavaScript function before
invoking it, returning the validation error through the existing error path.
Apply the same proxy and kill-function guards to palProcess.Kill, returning
without calling JavaScript when validation fails.

In `@packages/balrun/README.md`:
- Around line 135-138: Update the README example around the Ballerina
constructor to define a local fs filesystem instance before it is passed to new
Ballerina({ fs, env }), or provide the filesystem inline, ensuring the copied
sample has no undefined identifiers.

In `@packages/balrun/src/os.ts`:
- Around line 31-44: BrowserOSPlatform currently mutates the caller-owned
environment map, allowing state to leak between runs. In
packages/balrun/src/os.ts#L31-44, copy the supplied Environment in the
BrowserOSPlatform constructor so setEnv and unsetEnv operate on a per-run map;
packages/balrun/src/ballerina.ts#L44-44 and
packages/balrun/src/wasm-bridge.ts#L80-80 require no direct changes once this
copy is in place.
- Around line 50-60: Update getUsername, getUserHome, and exec to be async
methods so unsupportedOS() produces rejected promises rather than synchronous
throws, preserving the existing return types and unsupported-operation behavior.

---

Nitpick comments:
In `@packages/balrun/src/react.ts`:
- Around line 37-42: Document on the `env` prop near the `BallerinaProvider`
options that callers must provide a stable reference, recommending memoizing or
hoisting the Map; alternatively, accept a plain record and construct the Map
inside the provider. Preserve the existing `useMemo` dependency behavior and
avoid unrelated changes.

In `@packages/balrun/src/wasm-bridge.ts`:
- Around line 21-24: Update the WasmPlatform.os property type to use the
exported OSPlatform type directly, importing it from ./os as needed, instead of
deriving it with ReturnType<typeof createOSPlatform>. Preserve the existing
interface contract and factory usage elsewhere.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e36eea1c-5e22-4048-a639-74bf08092631

📥 Commits

Reviewing files that changed from the base of the PR and between 06808dd and 4fdcc59.

📒 Files selected for processing (13)
  • packages/ballerina-wasm/main_wasm.go
  • packages/ballerina-wasm/os_wasm.go
  • packages/ballerina-wasm/pal_wasm.go
  • packages/balrun/README.md
  • packages/balrun/src/ballerina-core.ts
  • packages/balrun/src/ballerina.ts
  • packages/balrun/src/index.ts
  • packages/balrun/src/os.ts
  • packages/balrun/src/react.ts
  • packages/balrun/src/wasm-bridge.ts
  • packages/balrun/tests/ballerina.test.ts
  • packages/balrun/tests/fixtures/os.bal
  • packages/balrun/tests/wasm-bridge.test.ts

Comment thread packages/ballerina-wasm/os_wasm.go
Comment thread packages/balrun/README.md
Comment thread packages/balrun/src/os.ts
Comment thread packages/balrun/src/os.ts Outdated
@snelusha
snelusha merged commit 077b448 into main Aug 7, 2026
2 checks passed
@snelusha
snelusha deleted the feat/os branch August 7, 2026 22:00
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.

Add support for OS

1 participant