Skip to content

Comments

Improve environment detection for WSO2 Integrator in BallerinaExtension#1532

Merged
kanushka merged 1 commit intowso2:release/bi-1.8.xfrom
gigara:bi-1.8.x
Feb 20, 2026
Merged

Improve environment detection for WSO2 Integrator in BallerinaExtension#1532
kanushka merged 1 commit intowso2:release/bi-1.8.xfrom
gigara:bi-1.8.x

Conversation

@gigara
Copy link
Contributor

@gigara gigara commented Feb 20, 2026

Purpose

$subject

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

UI Component Development

Specify the reason if following are not followed.

  • Added reusable UI components to the ui-toolkit. Follow the intructions when adding the componenent.
  • Use ui-toolkit components wherever possible. Run npm run storybook from the root directory to view current components.
  • Matches with the native VSCode look and feel.

Manage Icons

Specify the reason if following are not followed.

  • Added Icons to the font-wso2-vscode. Follow the instructions.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced environment variable handling for WSO2 Integrator runtime configuration to ensure correct runtime detection and proper precedence when multiple environment settings are present.
    • Optimized the version detection process to eliminate unnecessary environment synchronization steps in WSO2 Integrator scenarios, improving initialization performance while maintaining full backward compatibility.

@gigara gigara requested a review from hevayo as a code owner February 20, 2026 14:45
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

Introduces a pre-check in version detection to prefer BALLERINA_HOME from WSO2 Integrator environment when WSO2_INTEGRATOR_RUNTIME is set. The change short-circuits environment synchronization for this specific runtime scenario while preserving the original fallback path for other cases.

Changes

Cohort / File(s) Summary
Version Detection Logic
workspaces/ballerina/ballerina-extension/src/core/extension.ts
Adds conditional pre-check to prioritize BALLERINA_HOME from WSO2 Integrator environment when WSO2_INTEGRATOR_RUNTIME is set, bypassing environment sync and forcing overrideBallerinaHome to true in this scenario.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A pre-check hops in with eager care,
WSO2's path it'll proudly share,
Short-circuit the sync with a clever bound,
Home sweet BALLERINA home is found!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete with only the Purpose section partially filled (referencing the PR title) and all other required sections containing only template placeholders without substantive content. Complete the Goals, Approach, Release note, Documentation, Test environment, and Security checks sections with specific, substantive information relevant to this change.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: improving environment detection for WSO2 Integrator in the BallerinaExtension, which aligns with the code modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
workspaces/ballerina/ballerina-extension/src/core/extension.ts (1)

1697-1700: Use explicit sentinel value for WSO2_INTEGRATOR_RUNTIME to prevent accidental activation from non-standard environment values

The truthiness check at line 1697 means process.env.WSO2_INTEGRATOR_RUNTIME will activate the WSO2 path for any non-empty string, including "false", "0", or "no". Clarify intent by comparing explicitly: process.env.WSO2_INTEGRATOR_RUNTIME === "true".

Regarding BALLERINA_HOME: while the code validates it's a directory and includes a bin/ subdirectory (lines 1745–1748), confirming with WSO2 Integrator that this variable always points to the distribution root (not a sub-directory) prevents reliance on that downstream validation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@workspaces/ballerina/ballerina-extension/src/core/extension.ts` around lines
1697 - 1700, Change the environment check to use an explicit sentinel value
instead of relying on truthiness: replace the condition using
process.env.WSO2_INTEGRATOR_RUNTIME with a strict comparison
process.env.WSO2_INTEGRATOR_RUNTIME === "true" so the WSO2 path only activates
for that explicit value; continue to read and assign BALLERINA_HOME into
ballerinaHome and set overrideBallerinaHome as before, but keep the existing
directory/bin validation for BALLERINA_HOME (and add a short TODO/confirm that
BALLERINA_HOME is expected to be the distribution root, not a subdirectory, if
you want to avoid relying solely on downstream validation).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@workspaces/ballerina/ballerina-extension/src/core/extension.ts`:
- Around line 1697-1700: The current check for
process.env.WSO2_INTEGRATOR_RUNTIME unconditionally replaces the caller-supplied
ballerinaHome and flips overrideBallerinaHome, which can silently ignore an
explicit VS Code setting; modify the logic in init()/getBallerinaVersion call
site so you only set ballerinaHome = process.env.BALLERINA_HOME and
overrideBallerinaHome = true when ballerinaHome is falsy (i.e., guard with
!ballerinaHome), and if you intentionally want the env to trump a
user-configured path instead, add a clear debug/log line indicating "Overriding
configured ballerinaHome with WSO2_INTEGRATOR_RUNTIME value" before changing
ballerinaHome to make the precedence visible.

---

Nitpick comments:
In `@workspaces/ballerina/ballerina-extension/src/core/extension.ts`:
- Around line 1697-1700: Change the environment check to use an explicit
sentinel value instead of relying on truthiness: replace the condition using
process.env.WSO2_INTEGRATOR_RUNTIME with a strict comparison
process.env.WSO2_INTEGRATOR_RUNTIME === "true" so the WSO2 path only activates
for that explicit value; continue to read and assign BALLERINA_HOME into
ballerinaHome and set overrideBallerinaHome as before, but keep the existing
directory/bin validation for BALLERINA_HOME (and add a short TODO/confirm that
BALLERINA_HOME is expected to be the distribution root, not a subdirectory, if
you want to avoid relying solely on downstream validation).

Comment on lines +1697 to +1700
if (process.env.WSO2_INTEGRATOR_RUNTIME && process.env.BALLERINA_HOME) {
debug(`[VERSION] Detected WSO2 Integrator environment with BALLERINA_HOME: ${process.env.BALLERINA_HOME}`);
ballerinaHome = process.env.BALLERINA_HOME;
overrideBallerinaHome = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

WSO2 env vars unconditionally override an explicitly caller-supplied ballerinaHome

When init() has already set this.ballerinaHome to a user-configured path (because OVERRIDE_BALLERINA_HOME is true in VS Code settings), it passes that non-empty value as ballerinaHome to getBallerinaVersion. The new condition at line 1697 unconditionally replaces that value with process.env.BALLERINA_HOME — silently ignoring the user's explicit VS Code configuration — and flips overrideBallerinaHome without any diagnostic message beyond the single debug line. A user who has a VS Code-configured home and WSO2_INTEGRATOR_RUNTIME set in their global environment would get the WSO2 path with no indication of why their setting was ignored.

Guarding the override behind !ballerinaHome makes the intended precedence explicit (env var wins only when no home was already resolved):

💡 Proposed fix
-        if (process.env.WSO2_INTEGRATOR_RUNTIME && process.env.BALLERINA_HOME) {
+        if (process.env.WSO2_INTEGRATOR_RUNTIME && process.env.BALLERINA_HOME && !ballerinaHome) {
             debug(`[VERSION] Detected WSO2 Integrator environment with BALLERINA_HOME: ${process.env.BALLERINA_HOME}`);
             ballerinaHome = process.env.BALLERINA_HOME;
             overrideBallerinaHome = true;

Alternatively, if WSO2 Integrator is intentionally designed to always win over user configuration, add a debug/log statement so the override is visible:

         if (process.env.WSO2_INTEGRATOR_RUNTIME && process.env.BALLERINA_HOME) {
             debug(`[VERSION] Detected WSO2 Integrator environment with BALLERINA_HOME: ${process.env.BALLERINA_HOME}`);
+            if (ballerinaHome && ballerinaHome !== process.env.BALLERINA_HOME) {
+                debug(`[VERSION] WSO2 Integrator BALLERINA_HOME overrides configured home: '${ballerinaHome}' → '${process.env.BALLERINA_HOME}'`);
+            }
             ballerinaHome = process.env.BALLERINA_HOME;
             overrideBallerinaHome = true;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@workspaces/ballerina/ballerina-extension/src/core/extension.ts` around lines
1697 - 1700, The current check for process.env.WSO2_INTEGRATOR_RUNTIME
unconditionally replaces the caller-supplied ballerinaHome and flips
overrideBallerinaHome, which can silently ignore an explicit VS Code setting;
modify the logic in init()/getBallerinaVersion call site so you only set
ballerinaHome = process.env.BALLERINA_HOME and overrideBallerinaHome = true when
ballerinaHome is falsy (i.e., guard with !ballerinaHome), and if you
intentionally want the env to trump a user-configured path instead, add a clear
debug/log line indicating "Overriding configured ballerinaHome with
WSO2_INTEGRATOR_RUNTIME value" before changing ballerinaHome to make the
precedence visible.

@kanushka kanushka merged commit c287701 into wso2:release/bi-1.8.x Feb 20, 2026
7 checks passed
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.

3 participants