Skip to content

tmuxp load: Load multiple sessions with --append - #839

Open
tony wants to merge 1 commit into
masterfrom
test-cli-load-multiple--append
Open

tmuxp load: Load multiple sessions with --append#839
tony wants to merge 1 commit into
masterfrom
test-cli-load-multiple--append

Conversation

@tony

@tony tony commented Oct 29, 2022

Copy link
Copy Markdown
Member
tmuxp load workspace_1 workspace_2 --append

Loads to the same session_name as workspace_1, or uses the -s new_session_name

Somewhat released (not exactly): #674 #837

@tony
tony force-pushed the test-cli-load-multiple--append branch 2 times, most recently from 5466251 to e090550 Compare October 29, 2022 15:25
@tony
tony force-pushed the test-cli-load-multiple--append branch from e090550 to 4f20ba2 Compare November 13, 2022 14:42
@tony
tony force-pushed the master branch 2 times, most recently from 1989584 to b30a864 Compare May 27, 2023 16:53
tony added a commit that referenced this pull request Apr 26, 2026
why: ``tmuxp load f1 f2 f3 --append`` previously failed on the second
file because each file was loaded against its own config's
``session_name``, and the second file's ``new_session`` would collide
with the session the first file just created. Multi-file ``--append``
should land every workspace in a single shared target session.

The fix has two parts because the old behavior was wrong on two layers:

1. Pre-resolve the target session name once, before the load loop.
   ``--new-session-name`` wins; otherwise fall back to the first
   workspace file's ``session_name`` config key. Apply the resolved
   name to every iteration's ``new_session_name`` so all loads target
   the same session.

2. Make ``_dispatch_build`` honor ``append`` even when the target
   session already exists in detached mode. Previously the ``if
   detached:`` branch unconditionally called ``builder.build()`` (no
   append arg), which re-tried session creation and raised
   ``TmuxSessionExists``. New hoisted check: when ``append=True`` and
   the named session already exists, build windows directly onto the
   existing session via ``builder.build(existing, append=True)``,
   honoring ``detached`` for whether to attach afterwards.

what:
- src/tmuxp/cli/load.py: pre-resolve append_target_session_name in
  command_load when args.append and len(workspace_files) > 1; force
  every loop iteration to use it as new_session_name.
- src/tmuxp/cli/load.py: add session_name kwarg to _dispatch_build;
  hoist an append-to-existing-session branch above the detached/
  attached split so detached + append + session-exists is honored.
- tests/cli/test_load.py: two functional tests covering
  (a) ``load f1 f2 --append`` coalescing into f1's session_name, and
  (b) ``--new-session-name`` overriding the first file's session_name.

Re-ports PR #839 (originally a single 2022 WIP commit). Drops the
WIP's broken in-loop scoping of original_session_name and its type
mismatch between ConfigReader._from_file (returns dict) and
new_session_name (str).
@tony
tony force-pushed the test-cli-load-multiple--append branch from 4f20ba2 to 72fa331 Compare April 26, 2026 11:14
@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.38%. Comparing base (91ac851) to head (8f1aa2a).

Files with missing lines Patch % Lines
src/tmuxp/cli/load.py 62.96% 7 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #839      +/-   ##
==========================================
- Coverage   82.56%   82.38%   -0.19%     
==========================================
  Files          31       31              
  Lines        2770     2798      +28     
  Branches      518      526       +8     
==========================================
+ Hits         2287     2305      +18     
- Misses        346      353       +7     
- Partials      137      140       +3     

☔ View full report in Codecov by Harness.
📢 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.

tony added a commit that referenced this pull request Jun 6, 2026
why: ``tmuxp load f1 f2 f3 --append`` previously failed on the second
file because each file was loaded against its own config's
``session_name``, and the second file's ``new_session`` would collide
with the session the first file just created. Multi-file ``--append``
should land every workspace in a single shared target session.

The fix has two parts because the old behavior was wrong on two layers:

1. Pre-resolve the target session name once, before the load loop.
   ``--new-session-name`` wins; otherwise fall back to the first
   workspace file's ``session_name`` config key. Apply the resolved
   name to every iteration's ``new_session_name`` so all loads target
   the same session.

2. Make ``_dispatch_build`` honor ``append`` even when the target
   session already exists in detached mode. Previously the ``if
   detached:`` branch unconditionally called ``builder.build()`` (no
   append arg), which re-tried session creation and raised
   ``TmuxSessionExists``. New hoisted check: when ``append=True`` and
   the named session already exists, build windows directly onto the
   existing session via ``builder.build(existing, append=True)``,
   honoring ``detached`` for whether to attach afterwards.

what:
- src/tmuxp/cli/load.py: pre-resolve append_target_session_name in
  command_load when args.append and len(workspace_files) > 1; force
  every loop iteration to use it as new_session_name.
- src/tmuxp/cli/load.py: add session_name kwarg to _dispatch_build;
  hoist an append-to-existing-session branch above the detached/
  attached split so detached + append + session-exists is honored.
- tests/cli/test_load.py: two functional tests covering
  (a) ``load f1 f2 --append`` coalescing into f1's session_name, and
  (b) ``--new-session-name`` overriding the first file's session_name.

Re-ports PR #839 (originally a single 2022 WIP commit). Drops the
WIP's broken in-loop scoping of original_session_name and its type
mismatch between ConfigReader._from_file (returns dict) and
new_session_name (str).
@tony
tony force-pushed the test-cli-load-multiple--append branch from 72fa331 to 2f428cb Compare June 6, 2026 12:51
why: ``tmuxp load f1 f2 f3 --append`` previously failed on the second
file because each file was loaded against its own config's
``session_name``, and the second file's ``new_session`` would collide
with the session the first file just created. Multi-file ``--append``
should land every workspace in a single shared target session.

The fix has two parts because the old behavior was wrong on two layers:

1. Pre-resolve the target session name once, before the load loop.
   ``--new-session-name`` wins; otherwise fall back to the first
   workspace file's ``session_name`` config key. Apply the resolved
   name to every iteration's ``new_session_name`` so all loads target
   the same session.

2. Make ``_dispatch_build`` honor ``append`` even when the target
   session already exists in detached mode. Previously the ``if
   detached:`` branch unconditionally called ``builder.build()`` (no
   append arg), which re-tried session creation and raised
   ``TmuxSessionExists``. New hoisted check: when ``append=True`` and
   the named session already exists, build windows directly onto the
   existing session via ``builder.build(existing, append=True)``,
   honoring ``detached`` for whether to attach afterwards.

what:
- src/tmuxp/cli/load.py: pre-resolve append_target_session_name in
  command_load when args.append and len(workspace_files) > 1; force
  every loop iteration to use it as new_session_name.
- src/tmuxp/cli/load.py: add session_name kwarg to _dispatch_build;
  hoist an append-to-existing-session branch above the detached/
  attached split so detached + append + session-exists is honored.
- tests/cli/test_load.py: two functional tests covering
  (a) ``load f1 f2 --append`` coalescing into f1's session_name, and
  (b) ``--new-session-name`` overriding the first file's session_name.

Re-ports PR #839 (originally a single 2022 WIP commit). Drops the
WIP's broken in-loop scoping of original_session_name and its type
mismatch between ConfigReader._from_file (returns dict) and
new_session_name (str).
@tony
tony force-pushed the test-cli-load-multiple--append branch from 2f428cb to 8f1aa2a Compare July 4, 2026 14:11
@tony

tony commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

Automated review finding. Recorded here so it is not lost. Nothing has been pushed to this branch and no fix is applied — this is a note, not a change request.

--append targets by session name, so it can attach to an unrelated session

src/tmuxp/cli/load.py redirects the build onto any pre-existing session sharing the workspace's session_name, rather than specifically the session tmuxp built for an earlier file in the same multi-file load.

Failure scenario: inside tmux session work, running tmuxp load myproj.yaml --append while an unrelated background session is also named myproj builds onto the wrong session.

Recorded rather than patched, because this is not a regression this PR introduces: the same name-only ambiguity exists in the ordinary non-append path a few lines above. A real fix needs session identity tracking beyond name matching, which is a design change worth deciding on deliberately.

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.

1 participant