Skip to content

Handle boolean flag parameters correctly in CommandExecutor.run_topp()#350

Open
t0mdavid-m wants to merge 2 commits intomainfrom
claude/add-boolean-flag-support-ZFNp4
Open

Handle boolean flag parameters correctly in CommandExecutor.run_topp()#350
t0mdavid-m wants to merge 2 commits intomainfrom
claude/add-boolean-flag-support-ZFNp4

Conversation

@t0mdavid-m
Copy link
Member

@t0mdavid-m t0mdavid-m commented Mar 6, 2026

Summary

This PR adds proper handling for boolean flag parameters in the CommandExecutor.run_topp() method. Boolean parameters are now correctly converted to TOPP command-line flags: True values emit only the flag (no value), while False values omit the flag entirely. This distinguishes them from string-based boolean parameters ("true"/"false") which continue to emit explicit values.

Changes

  • CommandExecutor.py: Added boolean parameter detection and handling logic

    • True boolean values now emit only the flag name (e.g., -enable_feature)
    • False boolean values are skipped entirely (flag not emitted)
    • String values "true"/"false" continue to work as before (emitted with explicit values)
    • Other parameter types (int, float, str, empty, multiline) remain unchanged
  • test_boolean_flag_params.py: Added comprehensive test suite

    • Tests verify correct flag-only emission for bool True
    • Tests verify complete omission for bool False
    • Tests confirm string "true"/"false" still emit explicit values
    • Tests validate all other parameter types work as expected
    • Tests ensure standard flags (-threads, -ini, -in) are still present

Implementation Details

The implementation uses a simple isinstance(v, bool) check before the existing parameter processing logic. When a boolean is detected:

  • If True: append the flag and continue to skip the normal value-appending logic
  • If False: continue to skip the flag entirely
  • Non-boolean values fall through to existing logic unchanged

This approach maintains backward compatibility while adding proper support for registerFlag_ style parameters in TOPP tools.

https://claude.ai/code/session_016pdqzsAKEB6UDBcGM82T6F

Summary by CodeRabbit

  • Bug Fixes
    • Improved boolean parameter handling in workflow command execution. True boolean values now correctly emit flag-only parameters (without accompanying values), while False boolean values are properly omitted entirely from the generated command. This ensures more accurate and efficient command construction for workflow tools that use boolean flags.

claude added 2 commits March 6, 2026 13:56
TOPP tools have two boolean parameter styles: flag-style (registerFlag_)
where presence means enabled, and string-style (registerStringOption_
with valid_strings=["true","false"]) where explicit values are required.

Add isinstance(v, bool) check in the params[tool] loop so that:
- Python bool True emits only the flag (e.g., -flag)
- Python bool False omits the flag entirely
- String "true"/"false" continues to emit -param true / -param false

This fixes tools like FLASHDeconv and FLASHTnT that expect POSIX-style
boolean flags.

https://claude.ai/code/session_016pdqzsAKEB6UDBcGM82T6F
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

📝 Walkthrough

Walkthrough

The pull request modifies CommandExecutor.run_topp to treat boolean parameters as command-line flags: True emits the flag without a value, False omits it entirely. A comprehensive test suite validates the boolean flag behavior alongside other parameter types.

Changes

Cohort / File(s) Summary
Boolean Flag Handling
src/workflow/CommandExecutor.py
Added logic to treat boolean parameters (from registerFlag_ params) as flags: True emits "-" without a value, False omits the flag entirely.
Test Coverage
tests/test_boolean_flag_params.py
New test module validating boolean flag parameter handling in CommandExecutor.run_topp, including tests for bool True/False, string "true"/"false", numeric parameters, empty strings, multiline strings, and command structure verification.

Possibly related PRs

Poem

🐰 With boolish flags now proper and true,
True hops with the dash, False skips through,
The commands now speak the language we choose,
A logic so clean—we simply can't lose! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and accurately reflects the main change: handling boolean flag parameters in CommandExecutor.run_topp(). It is concise, specific, and clearly summarizes the primary objective.
Docstring Coverage ✅ Passed Docstring coverage is 94.12% which is sufficient. The required threshold is 80.00%.

✏️ 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
  • Commit unit tests in branch claude/add-boolean-flag-support-ZFNp4
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_boolean_flag_params.py (1)

71-91: Add one regression test for boolean flags passed via custom_params.

Current tests validate boolean handling from params.json, but not from runtime custom_params. A dedicated test here would lock behavior across both input paths.

🧪 Suggested test addition
@@
 class TestBooleanFlagParams:
@@
     def test_command_starts_with_tool(self, captured_command):
         """Command should start with the tool name."""
         assert captured_command[0] == "FakeTool"
+
+    def test_custom_params_bool_flags(self, workflow_env):
+        """Boolean custom_params should follow flag semantics."""
+        captured = {}
+
+        pm = ParameterManager(workflow_env)
+        logger = MagicMock(spec=Logger)
+        executor = CommandExecutor(workflow_env, logger, pm)
+
+        def fake_run_command(cmd):
+            captured["command"] = cmd
+            return True
+
+        executor.run_command = fake_run_command
+        executor.run_topp(
+            "FakeTool",
+            {"in": ["input.mzML"]},
+            custom_params={"custom_on": True, "custom_off": False},
+        )
+
+        cmd = captured["command"]
+        assert "-custom_on" in cmd
+        assert "-custom_off" not in cmd
+        idx = cmd.index("-custom_on")
+        assert cmd[idx + 1].startswith("-")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_boolean_flag_params.py` around lines 71 - 91, Add a regression
test that verifies boolean flags passed via runtime custom_params are handled
the same as those from params.json by reusing the captured_command helper:
instantiate a workflow_env with custom_params containing a boolean flag, call
captured_command(workflow_env) (which constructs ParameterManager and
CommandExecutor and intercepts run_command), then assert the returned command
list includes or omits the flag appropriately; reference the captured_command
function and the use of ParameterManager, CommandExecutor.run_topp and the
fake_run_command replacement to locate where to plug the new test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/workflow/CommandExecutor.py`:
- Around line 287-292: The boolean flag handling for custom_params is
inconsistent: update the loop that serializes custom_params so booleans follow
the same semantics as the earlier params[tool] block — if a value is a bool and
True, append only the short flag token (e.g., command += [f"-{k}"]); if False,
skip adding anything; otherwise serialize non-bool values as before. Locate the
custom_params serialization loop (the block that iterates over custom_params,
referencing variables like k, v, and command) and apply the same isinstance(v,
bool) check and conditional logic used in the params[tool] boolean handling to
ensure consistent CLI output.

---

Nitpick comments:
In `@tests/test_boolean_flag_params.py`:
- Around line 71-91: Add a regression test that verifies boolean flags passed
via runtime custom_params are handled the same as those from params.json by
reusing the captured_command helper: instantiate a workflow_env with
custom_params containing a boolean flag, call captured_command(workflow_env)
(which constructs ParameterManager and CommandExecutor and intercepts
run_command), then assert the returned command list includes or omits the flag
appropriately; reference the captured_command function and the use of
ParameterManager, CommandExecutor.run_topp and the fake_run_command replacement
to locate where to plug the new test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a9f3a47-fbc9-48f0-9e97-97519674a69d

📥 Commits

Reviewing files that changed from the base of the PR and between c81fee6 and 2d75369.

📒 Files selected for processing (2)
  • src/workflow/CommandExecutor.py
  • tests/test_boolean_flag_params.py

Comment on lines +287 to +292
# Boolean flag handling (from registerFlag_ params):
# True -> emit flag only, False -> skip entirely
if isinstance(v, bool):
if v:
command += [f"-{k}"]
continue
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Boolean flag handling is incomplete for custom_params.

Line 287-Line 292 correctly applies flag semantics for params[tool], but Line 302-Line 310 still serializes booleans in custom_params as values (-flag True / -flag False). This creates inconsistent CLI behavior for the same option source.

🔧 Suggested fix
@@
             # Add custom parameters
             for k, v in custom_params.items():
+                # Keep boolean handling consistent with params[tool]
+                if isinstance(v, bool):
+                    if v:
+                        command += [f"-{k}"]
+                    continue
                 command += [f"-{k}"]
                 # Skip only empty strings (pass flag with no value)
                 # Note: 0 and 0.0 are valid values, so use explicit check
                 if v != "" and v is not None:
                     if isinstance(v, list):
                         command += [str(x) for x in v]
                     else:
                         command += [str(v)]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/workflow/CommandExecutor.py` around lines 287 - 292, The boolean flag
handling for custom_params is inconsistent: update the loop that serializes
custom_params so booleans follow the same semantics as the earlier params[tool]
block — if a value is a bool and True, append only the short flag token (e.g.,
command += [f"-{k}"]); if False, skip adding anything; otherwise serialize
non-bool values as before. Locate the custom_params serialization loop (the
block that iterates over custom_params, referencing variables like k, v, and
command) and apply the same isinstance(v, bool) check and conditional logic used
in the params[tool] boolean handling to ensure consistent CLI output.

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