Skip to content

tests: fixed running with run_code_analysis.sh script#11487

Open
mabrarov wants to merge 1 commit intofluent:masterfrom
mabrarov:feature/runtime_shell_run_code_analysis
Open

tests: fixed running with run_code_analysis.sh script#11487
mabrarov wants to merge 1 commit intofluent:masterfrom
mabrarov:feature/runtime_shell_run_code_analysis

Conversation

@mabrarov
Copy link
Contributor

@mabrarov mabrarov commented Feb 21, 2026

Fixed execution of tests within run_code_analysis.sh script which is recommended in Guide to Contributing to Fluent Bit.

Fixes #11011 (comment) introduced in #11011.


Testing
Before we can approve your change; please submit the following in a comment:

  • [N/A] Example configuration file for the change
  • [N/A] Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found - refer to flb_run_code_analysis.log for the output of command
    TEST_PRESET=valgrind SKIP_TESTS='flb-rt-out_td flb-it-network' ./run_code_analysis.sh
  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • [N/A] Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Tests
    • Test scripts now include conditional privilege handling so install/remove operations run with elevation only when needed—preserving direct execution for root and delegating to sudo for non-root—improving compatibility across root and non-root environments.

@coderabbitai
Copy link

coderabbitai bot commented Feb 21, 2026

📝 Walkthrough

Walkthrough

Added a new sudo_if_not_root() helper in the build script to run commands with sudo when not root; two privileged filesystem operations were updated to use this helper instead of invoking sudo/direct commands.

Changes

Cohort / File(s) Summary
Privilege elevation helper & usage
tests/runtime_shell/go_plugins/build_test_plugins.sh
Added sudo_if_not_root() function. Replaced direct privileged operations (rm -rf /usr/local/go, mv go /usr/local/go) to invoke the helper so commands run with sudo only when the current user is not root.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • edsiper

Poem

🐇 I hop through scripts with gentle cheer,
I add a check when root isn't near.
If you're root I skip the sudo dance,
Else I prepend it—safe advance.
Small patch, big peace for every dev's ear.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title describes fixing test execution with run_code_analysis.sh, which aligns with the PR's primary objective of addressing a regression in the test running process.

✏️ 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.

@mabrarov mabrarov marked this pull request as ready for review February 21, 2026 18:28
Copy link

@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.

🧹 Nitpick comments (1)
tests/runtime_shell/go_plugins/build_test_plugins.sh (1)

110-118: Consider moving sudo_if_not_root before its callers for clearer dependency order.

The function is defined after install_go_if_needed (which calls it at lines 49/51). This works because bash resolves function names at call time, but it's unconventional — a reader skimming top-to-bottom may assume a missing-function error. Moving it to before install_go_if_needed makes the dependency obvious.

♻️ Proposed move
+# Support of environment without sudo, but running as root user.
+# Like container used in run_code_analysis.sh script.
+sudo_if_not_root() {
+    if [ "$(id -u)" -eq 0 ]; then
+        "$@"
+    else
+        sudo "$@"
+    fi
+}
+
 install_go_if_needed() {
 ...
 }
 ...
-# Support of environment without sudo, but running as root user.
-# Like container used in run_code_analysis.sh script.
-sudo_if_not_root() {
-    if [ "$(id -u)" -eq 0 ]; then
-        "$@"
-    else
-        sudo "$@"
-    fi
-}
-
 echo "Setting up Go build environment..."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/runtime_shell/go_plugins/build_test_plugins.sh` around lines 110 - 118,
Move the sudo_if_not_root function definition so it appears before any callers
such as install_go_if_needed; specifically, relocate the sudo_if_not_root
function above the install_go_if_needed function (which calls sudo_if_not_root
at lines referencing its calls) to make the dependency order explicit and avoid
top-to-bottom confusion for readers while leaving the function body and its
behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/runtime_shell/go_plugins/build_test_plugins.sh`:
- Around line 110-118: Move the sudo_if_not_root function definition so it
appears before any callers such as install_go_if_needed; specifically, relocate
the sudo_if_not_root function above the install_go_if_needed function (which
calls sudo_if_not_root at lines referencing its calls) to make the dependency
order explicit and avoid top-to-bottom confusion for readers while leaving the
function body and its behavior unchanged.

Signed-off-by: Marat Abrarov <abrarov@gmail.com>
@mabrarov mabrarov force-pushed the feature/runtime_shell_run_code_analysis branch from aaac15c to 8ff0e7b Compare February 21, 2026 18:36
Copy link

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/runtime_shell/go_plugins/build_test_plugins.sh (1)

57-69: ⚠️ Potential issue | 🟡 Minor

Minor edge-case regression: sudo is called when the user already holds write access.

Both call sites are inside if [ -w "/usr/local" ], which already guarantees that the current user can write to /usr/local. For a non-root user in that branch, sudo_if_not_root will invoke sudo unnecessarily — and will fail if that user has direct write access but no sudo configured, a regression from the previous direct-command behaviour.

The primary use case (root in container without sudo) is handled correctly. If the broader non-root case also matters, consider removing the redundant sudo call for users who already have direct write access:

💡 Suggested alternative — only elevate when write access requires it
     if [ -w "/usr/local" ]; then
         if [ -d /usr/local/go ]; then
-            sudo_if_not_root rm -rf /usr/local/go
+            rm -rf /usr/local/go
         fi
-        sudo_if_not_root mv go /usr/local/go
+        mv go /usr/local/go
         export PATH="/usr/local/go/bin:$PATH"
     else

With this approach, sudo_if_not_root is only needed when the install target requires elevated access (i.e., the user does not have direct write access). For that scenario, a separate writable-path-with-fallback-to-sudo pattern would be needed if privileged install to /usr/local is desired. If the only environments in practice are root-in-container and non-root-with-home-install, the diff above is sufficient and removes the inconsistency.

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

In `@tests/runtime_shell/go_plugins/build_test_plugins.sh` around lines 57 - 69,
The branch that checks if /usr/local is writable should not call
sudo_if_not_root because [ -w "/usr/local" ] already guarantees the current user
can write; update the /usr/local branch to perform rm -rf /usr/local/go and mv
go /usr/local/go directly (use the existing sudo_if_not_root only in the
fallback case where /usr/local is not writable), modifying the logic around the
sudo_if_not_root calls so sudo is only used when write permission is absent
(refer to the sudo_if_not_root helper and the if [ -w "/usr/local" ] branch to
locate the code).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/runtime_shell/go_plugins/build_test_plugins.sh`:
- Around line 57-69: The branch that checks if /usr/local is writable should not
call sudo_if_not_root because [ -w "/usr/local" ] already guarantees the current
user can write; update the /usr/local branch to perform rm -rf /usr/local/go and
mv go /usr/local/go directly (use the existing sudo_if_not_root only in the
fallback case where /usr/local is not writable), modifying the logic around the
sudo_if_not_root calls so sudo is only used when write permission is absent
(refer to the sudo_if_not_root helper and the if [ -w "/usr/local" ] branch to
locate the code).

@cosmo0920 cosmo0920 added this to the Fluent Bit v5.0 milestone Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants