Skip to content

feat(check_leaks): make memory leak check mandatory to pass CI#578

Merged
Miou-zora merged 2 commits into
mainfrom
566-ci-make-memory-leak-check-mandatory-to-pass-ci
Apr 9, 2026
Merged

feat(check_leaks): make memory leak check mandatory to pass CI#578
Miou-zora merged 2 commits into
mainfrom
566-ci-make-memory-leak-check-mandatory-to-pass-ci

Conversation

@Miou-zora

@Miou-zora Miou-zora commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Description

Force memory leaks to be resolved in CI

Related Issues (Put "None" if there are no related issues)

close #566

Type of Change

Please delete options that are not relevant.

  • Build/CI configuration change

Changes Made

List the main changes in this PR:

  • Raise an error when finding a memory leak

Testing

Describe the tests you ran to verify your changes. Please delete options that are not relevant.

  • None

Test Environment

  • OS: macOS
  • Compiler: Clang

Screenshots/Videos (Put "None" if there are no related issues)

None

Documentation

Please delete options that are not relevant.

  • No documentation changes are required

Checklist (Don't delete any options)

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Breaking Changes (Put "None" if there are no related issues)

None

Additional Notes (Put "None" if there are no related issues)

None

Summary by CodeRabbit

  • Bug Fixes
    • Memory leak detection now fails the run when leaks are found, preventing silent successes and ensuring problems are reported.
    • On macOS, the leak check now aborts immediately if an expected executable is missing, rather than skipping targets.

@Miou-zora Miou-zora self-assigned this Apr 9, 2026
@Miou-zora Miou-zora linked an issue Apr 9, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 982bb8e4-0c47-4f64-9ea7-db1429f6c7dd

📥 Commits

Reviewing files that changed from the base of the PR and between fab11f0 and acd43e0.

📒 Files selected for processing (1)
  • tools/xmake/check_leaks.lua
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/xmake/check_leaks.lua

📝 Walkthrough

Walkthrough

The XMake leak-check script now aborts by raising an error when an expected target executable is missing and raises an exception (failing the run) when any memory leaks are detected; behavior when no leaks are found is unchanged.

Changes

Cohort / File(s) Summary
Memory leak check script
tools/xmake/check_leaks.lua
Replaced prior non-failing skips with exceptions: throw if target executable is missing; print failing targets and then raise an exception when any leaks are found (previously only logged).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #577: Matches the change to tools/xmake/check_leaks.lua making the check fail CI when leaks are detected — likely the same objective.
  • #566: CI should block merges when memory leaks exist — this PR enforces failure on detected leaks, aligning with that objective.

Possibly related PRs

Suggested labels

ci, test

Poem

🐇 I sniff the bytes where shadows creep,
I hop and probe through heap and stack,
If leaks are found I sound the clap —
A raised alarm, no quiet gap,
CI safe now: no rabbit nap.

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making memory leak checks mandatory in CI by raising errors when leaks are found, which aligns with the changeset.
Linked Issues check ✅ Passed The PR implements core functionality from issue #566 by raising errors when memory leaks are detected, making the check mandatory rather than optional.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of making leak checks mandatory by modifying the check_leaks.lua script to raise exceptions on leak detection.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 566-ci-make-memory-leak-check-mandatory-to-pass-ci

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
tools/xmake/check_leaks.lua (1)

11-14: ⚠️ Potential issue | 🔴 Critical

Mandatory leak gate is still bypassable on prerequisite failures.

If executables are missing or leaks is unavailable, the task currently prints and continues/returns, which can still end in a green CI result without performing the mandatory check.

💡 Proposed fix
@@
-        if not os.isfile(bin_path) then
-            print("Executable not found for target: " .. target_name)
-            goto continue
-        end
+        if not os.isfile(bin_path) then
+            table.insert(failing_targets, target_name .. " (executable not found)")
+            goto continue
+        end
@@
             local leaks_tool = find_program("leaks", { check = "--help" })
             if not leaks_tool then
-                print("leaks tool not found!")
-                return
+                raise("leaks tool not found on macOS runner; cannot perform mandatory memory leak check.")
             end

Also applies to: 68-71

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

In `@tools/xmake/check_leaks.lua` around lines 11 - 14, The script currently
prints and uses "goto continue" when os.isfile(bin_path) is false (and similarly
around the availability of the leaks tool), which lets the mandatory leak gate
be bypassed; change those paths in tools/xmake/check_leaks.lua so that when
os.isfile(bin_path) or the leaks check fails you abort with a non-zero exit
(e.g., call error(...) or os.exit(1)) instead of printing and continuing, and
make the same change for the analogous checks around lines 68-71 so missing
prerequisites cause the task to fail CI rather than silently pass.
🧹 Nitpick comments (1)
tools/xmake/check_leaks.lua (1)

9-9: Avoid hardcoded debug; expose task mode and resolve binary path from it.

Hardcoding "debug" makes the task fragile outside CI defaults and can silently miss binaries in other modes.

♻️ Proposed refactor
@@
-local function check_leaks_macos(targets, leaks_tool, project, os, verbose)
+local function check_leaks_macos(targets, leaks_tool, os, verbose, mode)
@@
-        local bin_path = path.join(os.projectdir(), target:targetdir(), "debug", target:filename())
+        local bin_path = path.join(target:targetdir(), mode, target:filename())
@@
         import("lib.detect.find_program")
+        local mode = option.get("mode") or "debug"
@@
-            failing_targets = check_leaks_macos(targets, leaks_tool, project, os, option.get("verbose"))
+            failing_targets = check_leaks_macos(targets, leaks_tool, os, option.get("verbose"), mode)
@@
         options = {
+            {nil, "mode", "kv", "debug", "Build mode to check (debug/release)"},
             {nil, "targets", "vs", nil, "Targets to check for leaks (default: all test targets)"}
         }
     }

Based on learnings: in tools/xmake/check_leaks.lua, task context should use option.get("mode") or "debug" and build the path as path.join(target:targetdir(), mode, target:filename()).

Also applies to: 34-39, 72-72, 90-92

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

In `@tools/xmake/check_leaks.lua` at line 9, Replace hardcoded "debug" mode when
building binary paths by reading the task option mode = option.get("mode") or
"debug" and using that variable in path.join; specifically update the bin_path
construction (local bin_path = path.join(os.projectdir(), target:targetdir(),
"debug", target:filename())) to use path.join(target:targetdir(), mode,
target:filename()) (or include os.projectdir() only where appropriate), and
apply the same change to the other path.join usages in this file that build
binary paths so they all derive the directory from mode instead of the literal
"debug"; ensure you declare mode once (e.g., local mode = option.get("mode") or
"debug") and reference it in every affected expression.
🤖 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 `@tools/xmake/check_leaks.lua`:
- Around line 11-14: The script currently prints and uses "goto continue" when
os.isfile(bin_path) is false (and similarly around the availability of the leaks
tool), which lets the mandatory leak gate be bypassed; change those paths in
tools/xmake/check_leaks.lua so that when os.isfile(bin_path) or the leaks check
fails you abort with a non-zero exit (e.g., call error(...) or os.exit(1))
instead of printing and continuing, and make the same change for the analogous
checks around lines 68-71 so missing prerequisites cause the task to fail CI
rather than silently pass.

---

Nitpick comments:
In `@tools/xmake/check_leaks.lua`:
- Line 9: Replace hardcoded "debug" mode when building binary paths by reading
the task option mode = option.get("mode") or "debug" and using that variable in
path.join; specifically update the bin_path construction (local bin_path =
path.join(os.projectdir(), target:targetdir(), "debug", target:filename())) to
use path.join(target:targetdir(), mode, target:filename()) (or include
os.projectdir() only where appropriate), and apply the same change to the other
path.join usages in this file that build binary paths so they all derive the
directory from mode instead of the literal "debug"; ensure you declare mode once
(e.g., local mode = option.get("mode") or "debug") and reference it in every
affected expression.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9f85f4a-89cc-469d-b9dd-e0dfac2022e3

📥 Commits

Reviewing files that changed from the base of the PR and between 5019723 and fab11f0.

📒 Files selected for processing (1)
  • tools/xmake/check_leaks.lua

@sonarqubecloud

sonarqubecloud Bot commented Apr 9, 2026

Copy link
Copy Markdown

@Miou-zora Miou-zora merged commit 44edf6e into main Apr 9, 2026
29 checks passed
@Miou-zora Miou-zora deleted the 566-ci-make-memory-leak-check-mandatory-to-pass-ci branch April 9, 2026 12:09
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.

[CI] Make memory leak check mandatory to pass CI

1 participant