Skip to content

refactor: consolidate ControlMaster side-channel invocation - #128

Merged
dolonet merged 2 commits into
dolonet:mainfrom
gorevds:refactor/mux-run-helper
Jun 25, 2026
Merged

refactor: consolidate ControlMaster side-channel invocation#128
dolonet merged 2 commits into
dolonet:mainfrom
gorevds:refactor/mux-run-helper

Conversation

@gorevds

@gorevds gorevds commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

What

Seven SSHSession methods hand-built the same one-shot ssh argv (tmux_capture, push_tmux_options, upload_file, finalize_upload, remove_remote_tmp, list_dir, download_file), and five of them repeated the same subprocess.run timeout/exception handling. This folds:

  • the argv into _mux_argv(remote_cmd)
  • the socket-exists guard into _mux_ready()
  • the run + TimeoutExpired/Exception handling into _mux_run(remote_cmd, timeout, timeout_msg, err_prefix)

so a future ssh-option change can't silently miss one of the seven sites. Net −19 lines, and the dangerous duplication (argv drift between sites) is gone.

Behavior preserved byte-for-byte

  • argv element order identical (verified against pre-image at every site)
  • per-site error strings kept: tmux capture timeout / tmux set timeout / finalize timeout / rm timeout / timeout; list_dir keeps its historical bare str(e) via err_prefix=""
  • per-site timeouts kept (30/10/15/10/10); returncode != 0 interpretation stays at the call sites (genuinely differs per operation)
  • Popen sites (upload_file, download_file) keep their exact stdin/stdout/stderr settings and only take the argv helper
  • terminate_remote_tmux deliberately NOT converted — it re-dials with -p/-l/ConnectTimeout because its master may still be authenticating (documented in the new section comment)

One hardening folded in: _mux_run returns str(e) or repr(e) so an exception with an empty message can't produce a falsy error string that callers' if err: would miss.

Tests

Full suite: 486 tests OK (no test changes needed — argv assertions and error-string expectations all still hold).

gorevds and others added 2 commits June 12, 2026 17:59
Seven SSHSession methods built the same one-shot ssh argv by hand
(tmux_capture, push_tmux_options, upload_file, finalize_upload,
remove_remote_tmp, list_dir, download_file) and five of them repeated
the same subprocess.run timeout/exception dance. Fold the argv into
_mux_argv(), the socket guard into _mux_ready(), and the run+error
handling into _mux_run() — so a future ssh option change cannot
silently miss one of the call sites.

Per-site error strings, timeouts, and I/O settings are preserved
byte-for-byte (list_dir keeps its historical bare str(e) message via
err_prefix=""). terminate_remote_tmux is deliberately not converted:
it re-dials with -p/-l/ConnectTimeout because its master may still be
authenticating. No wire-visible change; 486 tests OK.
@dolonet
dolonet merged commit a0a8c23 into dolonet:main Jun 25, 2026
8 checks passed
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