Skip to content

feat(compare): restore --command preset for per-stage compare defaults - #307

Merged
nh13 merged 1 commit into
mainfrom
nh13/feat-restore-compare-command-preset
Apr 22, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh13/feat-restore-compare-command-preset

Conversation

@nh13

@nh13 nh13 commented Apr 21, 2026

Copy link
Copy Markdown
Member

Summary

Reintroduce the --command <stage> preset on fgumi compare bams, which was originally added in #276 and unintentionally removed in #296 when that breaking refactor synced src/lib/commands/compare/bams.rs from a pre-#276 backup branch. The compare/bams.rs edits in #296 were absorbed into an "amends to include" bullet alongside the larger bam_codec/simulate scope and the regression slipped through review.

Why this matters

Downstream fgumi-benchmarks relies on this flag for cross-tool equivalency checks between fgumi and fgbio outputs (workflow/rules/benchmark.smk → get_compare_args()). At the current fgumi main, every compare_bams_batch job that hits a stage in the preset set fails immediately with:

error: unexpected argument '--command' found

Other batches (e.g. group.identity) silently run with --mode full and fail on expected cross-tool ordering differences, because the preset that would have set --mode grouping --ignore-order was also lost.

What the preset does

--command <stage> applies canonical --mode and --ignore-order defaults. Adapted to the post-#276 --mode {full,content,grouping} + --ignore-order surface:

stage --mode --ignore-order notes
extract, zipper, sort, correct, dedup, filter content false No MI tags or pass-through; deterministic
group grouping true MI values and record order may legitimately differ (cross-tool)
simplex, duplex, codec grouping true Non-deterministic with --threads

Explicit --mode or --ignore-order flags always override the preset, e.g.:

fgumi compare bams --command group --mode full --ignore-order=false a.bam b.bam

Implementation

  • CommandPreset enum reintroduced with a .defaults() -> (CompareMode, bool) method.
  • mode and ignore_order struct fields changed to Option<T> so the resolver can distinguish "unset" from "explicit value". This is internal — the CLI surface still has --mode / --ignore-order with no default, and the old default-full / default-false behavior is preserved by effective_settings().
  • New effective_settings(&self) -> (CompareMode, bool) resolves precedence: explicit flag > --command preset default > built-in default (full, false).
  • execute() logs Using --command <preset> preset: mode=..., ignore-order=... (with explicit overrides) when --command is in effect.
  • Help text updated with a COMMAND PRESETS section replacing the RECOMMENDED SETTINGS BY COMMAND table (same information, self-documenting now that the preset is back).

Test plan

  • cargo build --release --features compare,simulate — builds clean
  • cargo ci-test — 2458 tests pass, 23 skipped; no regressions
  • cargo ci-fmt — clean
  • cargo ci-lint — clean
  • 6 new unit tests in src/lib/commands/compare/bams.rs::tests:
    • preset_defaults_content_stages_map_to_content_no_ignore_order
    • preset_defaults_grouping_stages_map_to_grouping_with_ignore_order
    • effective_settings_fall_back_to_built_in_defaults
    • effective_settings_use_preset_when_only_command_given
    • effective_settings_explicit_mode_overrides_preset
    • effective_settings_explicit_ignore_order_overrides_preset
  • fgumi compare bams --help — verified --command appears and preset table renders correctly
  • All 14 existing test_compare_bams integration tests still pass

Out of scope

@nh13
nh13 temporarily deployed to github-actions April 21, 2026 19:33 — with GitHub Actions Inactive
@codecov

codecov Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.43243% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.46%. Comparing base (56fe278) to head (853542e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/lib/commands/compare/bams.rs 82.43% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #307      +/-   ##
==========================================
- Coverage   90.47%   90.46%   -0.01%     
==========================================
  Files         101      101              
  Lines       59992    60059      +67     
==========================================
+ Hits        54276    54331      +55     
- Misses       5716     5728      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nh13 nh13 added the bug Something isn't working label Apr 21, 2026
@nh13
nh13 marked this pull request as ready for review April 21, 2026 19:38
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bbf926c5-6665-4ffc-92c9-206f068b2bd1

📥 Commits

Reviewing files that changed from the base of the PR and between d0c48df and 853542e.

📒 Files selected for processing (1)
  • src/lib/commands/compare/bams.rs

📝 Walkthrough

Walkthrough

The change introduces a CommandPreset enum to BAM comparison that encodes default pairs of (CompareMode, ignore_order) for different comparison stages. The CompareBams struct now accepts a --command/-c option to select a preset. Both --mode and --ignore-order fields changed from required with defaults to optional, with a new effective_settings() method that resolves final values using precedence: explicit flag values first, then preset defaults, then built-in defaults (Full, false). Validation and execution logic updated to use resolved settings rather than raw field values. Adds unit tests and structured logging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main change: reintroducing the --command preset feature for per-stage comparison defaults.
Description check ✅ Passed Description clearly explains the feature restoration, its purpose, implementation approach, test validation, and scope limitations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 nh13/feat-restore-compare-command-preset

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.

@nh13

nh13 commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 3

🧹 Nitpick comments (1)
src/lib/commands/compare/bams.rs (1)

958-964: Logged preset name uses Debug casing.

"{:?}" on CommandPreset::Group prints Group, but the user typed group. Implement Display (or use ValueEnum::to_possible_value().unwrap().get_name()) for a log line that matches the CLI surface.

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

In `@src/lib/commands/compare/bams.rs` around lines 958 - 964, The log prints the
preset using Debug ("{:?}") which shows `Group` instead of the CLI-cased
`group`; change the log to emit the CLI name by either implementing Display for
CommandPreset and using "{}" (implement Display for the CommandPreset enum) or
by calling the clap ValueEnum helper on the existing preset variable (e.g., use
preset.to_possible_value().unwrap().get_name() or preset.as_str() if available)
in the info! call so the message matches the CLI surface; update the info!
invocation that references preset to use the chosen method and preserve the rest
of the interpolation.
🤖 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/lib/commands/compare/bams.rs`:
- Around line 210-216: Update the doc comment for the CompareMode `mode` field
to remove stale references to "clip/downsample" and list the current command
presets supported by the enum (extract/zipper/sort/correct/dedup/filter); locate
the doc above the `pub mode: Option<CompareMode>` field and replace the old
preset examples so the comment aligns exactly with the current CompareMode
variants and intended usage.
- Around line 2015-2043: Replace the manual loops in the tests
preset_defaults_content_stages_map_to_content_no_ignore_order and
preset_defaults_grouping_stages_map_to_grouping_with_ignore_order with rstest
parameterized cases: annotate each test function with #[rstest] and add a
#[case] for each CommandPreset variant used (e.g., CommandPreset::Extract,
::Zipper, ::Sort, ::Correct, ::Dedup, ::Filter for the content test and
CommandPreset::Group, ::Simplex, ::Duplex, ::Codec for the grouping test),
change the function signature to accept a single parameter (#[case] stage:
CommandPreset), and keep the assertions that stage.defaults() returns the
expected CompareMode and ignore boolean; this makes each variant an independent
rstest case and removes the for-loop.
- Around line 950-965: The validation currently bails on ignore_order regardless
of whether it was set from a preset or explicitly; update the logic around
effective_settings()/the subsequent check so that if ignore_order is true but it
was inherited from a preset (i.e. self.command.is_some() &&
!self.ignore_order.is_some() && self.mode.is_some()), you either clear
ignore_order when resolved mode != CompareMode::Grouping (set
ignore_order=false) or change the error message to mention the preset origin;
locate the check using effective_settings(), CompareMode::Grouping and the
fields self.command, self.mode, self.ignore_order and implement the chosen fix
so explicit --mode overrides do not produce a misleading "--ignore-order" error.

---

Nitpick comments:
In `@src/lib/commands/compare/bams.rs`:
- Around line 958-964: The log prints the preset using Debug ("{:?}") which
shows `Group` instead of the CLI-cased `group`; change the log to emit the CLI
name by either implementing Display for CommandPreset and using "{}" (implement
Display for the CommandPreset enum) or by calling the clap ValueEnum helper on
the existing preset variable (e.g., use
preset.to_possible_value().unwrap().get_name() or preset.as_str() if available)
in the info! call so the message matches the CLI surface; update the info!
invocation that references preset to use the chosen method and preserve the rest
of the interpolation.
🪄 Autofix (Beta)

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 80306360-34d7-491b-9903-b70704cd01e3

📥 Commits

Reviewing files that changed from the base of the PR and between 56fe278 and d0c48df.

📒 Files selected for processing (1)
  • src/lib/commands/compare/bams.rs

Comment thread src/lib/commands/compare/bams.rs
Comment thread src/lib/commands/compare/bams.rs
Comment thread src/lib/commands/compare/bams.rs Outdated
@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown

Only repository collaborators, contributors, or members can run CodeRabbit commands.

Reintroduce the `--command <stage>` preset on `fgumi compare bams`, which
was originally added in #276 and unintentionally removed in #296 when
that breaking refactor synced compare/bams.rs from a pre-#276 backup
branch.

The preset sets canonical `--mode` and `--ignore-order` defaults for
comparing BAM output from a specific pipeline stage, and is especially
useful for cross-tool comparisons (e.g. fgumi vs. fgbio) where MI values
or record order may legitimately differ.

Adapted to the current `--mode {full,content,grouping}` + `--ignore-order`
API (post-#276), with defaults tuned for benchmarks' cross-tool needs:

  extract/zipper/sort/correct/dedup/filter → content, false
  group/simplex/duplex/codec               → grouping, true

Explicit `--mode` or `--ignore-order` flags override the preset. The
`mode` and `ignore_order` struct fields become `Option<T>` so the
resolver can distinguish "unset" from "explicit default".

- `mode`: logs preset usage when `--command` is provided
- `effective_settings()` resolves explicit > preset > built-in default
- 6 new unit tests cover the resolver and preset defaults; all 2458
  existing tests still pass

Restores the contract that fgumi-benchmarks `compare_bams_batch` relies
on (workflow/rules/benchmark.smk `get_compare_args()`), which currently
fails immediately with "error: unexpected argument '--command' found".
@nh13

nh13 commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 force-pushed the nh13/feat-restore-compare-command-preset branch from d0c48df to 853542e Compare April 21, 2026 20:35
@nh13
nh13 temporarily deployed to github-actions April 21, 2026 20:35 — with GitHub Actions Inactive
@nh13

nh13 commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 merged commit c893602 into main Apr 22, 2026
7 of 9 checks passed
@nh13
nh13 deleted the nh13/feat-restore-compare-command-preset branch April 22, 2026 00:46
This was referenced Apr 22, 2026

This branch was previously deployed

1 inactive deployment
github-actions — 853542ea Deployed Apr 21, 2026 by nh13 via coverage #1289
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant