Skip to content

Commit a6a72df

Browse files
committed
tmux_cmd(feat[logging]): Add structured extra to pre-execution log
why: Conform to CLAUDE.md logging standards — structured extra enables assertion on record attributes instead of fragile string matching. what: - Add import shlex to common.py - Replace subprocess.list2cmdline with shlex.join (POSIX quoting) - Add extra={"tmux_cmd": ...} to pre-execution debug log - Update test to assert on caplog.records attributes
1 parent 2cf447f commit a6a72df

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/libtmux/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import logging
1111
import re
12+
import shlex
1213
import shutil
1314
import subprocess
1415
import sys
@@ -259,7 +260,11 @@ def __init__(self, *args: t.Any, tmux_bin: str | None = None) -> None:
259260

260261
self.cmd = cmd
261262

262-
logger.debug("running %s", subprocess.list2cmdline(cmd))
263+
logger.debug(
264+
"running %s",
265+
shlex.join(cmd),
266+
extra={"tmux_cmd": shlex.join(cmd)},
267+
)
263268

264269
try:
265270
self.process = subprocess.Popen(

tests/test_common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,6 @@ def test_tmux_cmd_pre_execution_logging(
519519
"""Verify tmux_cmd logs command before execution."""
520520
with caplog.at_level(logging.DEBUG, logger="libtmux.common"):
521521
server.cmd("list-sessions")
522-
assert any(
523-
"running" in r.message and "list-sessions" in r.message for r in caplog.records
524-
)
522+
running_records = [r for r in caplog.records if hasattr(r, "tmux_cmd")]
523+
assert len(running_records) > 0
524+
assert "list-sessions" in running_records[0].tmux_cmd

0 commit comments

Comments
 (0)