Skip to content

feat: Implement pdsh compatibility layer core infrastructure#105

Merged
inureyes merged 3 commits intomainfrom
feature/issue-97-pdsh-compat-layer
Dec 16, 2025
Merged

feat: Implement pdsh compatibility layer core infrastructure#105
inureyes merged 3 commits intomainfrom
feature/issue-97-pdsh-compat-layer

Conversation

@inureyes
Copy link
Member

Summary

  • Implement pdsh compatibility mode allowing bssh to act as a drop-in replacement for pdsh
  • Add binary name detection for pdsh symlink support
  • Add BSSH_PDSH_COMPAT environment variable support
  • Add --pdsh-compat CLI flag
  • Create pdsh CLI parser with option mapping to bssh equivalents
  • Add query mode (-q) for showing target hosts without execution

Changes

New Files

  • src/cli/mod.rs - CLI module exports and pdsh re-exports
  • src/cli/pdsh.rs - pdsh-compatible CLI parser and conversion logic
  • src/cli/mode_detection_tests.rs - Tests for mode detection

Modified Files

  • src/cli/bssh.rs (renamed from src/cli.rs) - Added --pdsh-compat and --any-failure flags
  • src/main.rs - Wire up pdsh mode detection and routing
  • ARCHITECTURE.md - Document pdsh compatibility architecture

Option Mapping

pdsh option bssh option Description
-w hosts -H hosts Target hosts
-x hosts --exclude hosts Exclude hosts
-f N --parallel N Fanout/parallel connections
-l user -l user Remote username
-t N --connect-timeout N Connection timeout
-u N --timeout N Command timeout
-N --no-prefix Disable hostname prefix
-b --batch Batch mode
-k --fail-fast Stop on first failure
-q (query mode) Show hosts and exit
-S --any-failure Return largest exit code

Test plan

  • All 24 new CLI tests pass
  • All existing tests pass (633 total)
  • Cargo clippy passes with no warnings
  • Release build succeeds
  • Functional test: BSSH_PDSH_COMPAT=1 bssh -w hosts -q shows hosts
  • Functional test: bssh --pdsh-compat -w hosts -q shows hosts
  • Functional test: Query mode with exclusions works correctly

Closes #97

Add pdsh compatibility mode allowing bssh to act as a drop-in replacement
for pdsh. This implements Phase 2 of the pdsh compatibility roadmap.

Changes:
- Create CLI module structure: cli/mod.rs, cli/bssh.rs, cli/pdsh.rs
- Add is_pdsh_compat_mode() for binary name and env var detection
- Add PdshCli struct with pdsh-compatible argument parsing
- Implement to_bssh_cli() conversion method for option mapping
- Add --pdsh-compat flag to bssh CLI
- Add --any-failure flag for pdsh -S compatibility
- Wire up mode detection in main.rs entry point
- Add query mode (-q) support to show hosts and exit

Option mapping:
- -w hosts -> -H hosts
- -x hosts -> --exclude hosts
- -f N -> --parallel N
- -l user -> -l user
- -t N -> --connect-timeout N
- -u N -> --timeout N
- -N -> --no-prefix
- -b -> --batch
- -k -> --fail-fast
- -q -> query mode
- -S -> --any-failure

Activation methods:
1. Symlink bssh as "pdsh"
2. Set BSSH_PDSH_COMPAT=1 environment variable
3. Use --pdsh-compat flag

Includes 24 unit tests for mode detection and option mapping.
Updates ARCHITECTURE.md with pdsh compatibility documentation.
@inureyes inureyes added type:enhancement New feature or request pdsh-compat pdsh compatibility mode features labels Dec 16, 2025
@inureyes inureyes self-assigned this Dec 16, 2025
@inureyes inureyes added priority:high High priority issue impact:breaking Breaking change that requires migration status:review Under review labels Dec 16, 2025
- Use glob pattern matching in pdsh query mode (-q) for consistent
  behavior with bssh --exclude option
- Add security validation for exclusion patterns in query mode
  (pattern length, wildcard count limits)
- Replace unwrap() with if-let pattern in get_command() for
  more idiomatic Rust code

Addresses code review feedback on PR #105.
@inureyes
Copy link
Member Author

Code Review Fixes Applied

Fixed issues identified during code review:

MEDIUM Severity (Fixed)

  1. Query Mode Glob Pattern Matching - Implemented glob pattern matching in query mode (-q) to be consistent with the standard --exclude option. Now supports wildcards (*, ?, [abc]) and substring matching.

  2. Security Validation in Query Mode - Added the same security validation as exclude_nodes():

    • Pattern length limit (256 characters)
    • Wildcard count limit (10 max)
    • Invalid pattern detection

LOW Severity (Fixed)

  1. Idiomatic Rust in get_command() - Replaced .is_some() + .unwrap() pattern with if let Some(...) for more idiomatic Rust code.

All tests pass and clippy is clean.

- Add pdsh compatibility section to README.md with activation methods,
  option mapping table, and usage examples
- Add pdsh compatibility section to manpage (docs/man/bssh.1)
- Add comprehensive integration tests for pdsh compatibility
  (tests/pdsh_compat_test.rs - 30 new tests)
- Fix race condition in mode_detection_tests by testing logic directly
  instead of relying on concurrent env var state
- Fix flaky rank_detector test by adding #[serial] and clearing env vars
@inureyes inureyes merged commit b5bb5b9 into main Dec 16, 2025
2 checks passed
@inureyes inureyes deleted the feature/issue-97-pdsh-compat-layer branch December 16, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:breaking Breaking change that requires migration pdsh-compat pdsh compatibility mode features priority:high High priority issue status:review Under review type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Implement pdsh compatibility layer core infrastructure

1 participant