Shell completions for tmuxp (and tests)

Written early in the morning in English • Tags: , , ,

I updated misc/py-tmuxp to 1.82.0, and the package now installs shell completions for bash, fish and zsh. Getting there took a new package, an update to misc/py-libtmux, and a longer detour through the test suites than I had planned, although I guess I could have just skipped the tests.

Completions

tmuxp generates its completions with shtab, which is not bundled. On Debian I install tmuxp with pipx and inject shtab into the same venv. pkgsrc had no shtab, so I added devel/py-shtab 1.13.0.

tmuxp only imports shtab to mark which arguments take file names, and it carries on without it. The scripts themselves come from running shtab against tmuxp’s argument parser:

shtab --shell=zsh -u tmuxp.cli.create_parser

So there is no need for a run-time dependency. The package runs that at build time for each shell and installs the results:

share/bash-completion/completions/tmuxp
share/fish/vendor_completions.d/tmuxp.fish
share/zsh/site-functions/_tmuxp

pkgsrc has no framework for completions. Those three directories are the convention, and each package fills them by hand.

The paths are not Python-versioned, so two builds of the package for different Python versions can no longer be installed side by side. I set PYTHON_SELF_CONFLICT, as net/py-magic-wormhole does for the same reason.

tmuxp 1.82.0 requires libtmux 0.68, so that was updated from 0.61.0 as well. Both now need tmux 3.3a and Python 3.11.

The tests

The comment in the Makefile recorded the state of the test target as of 1.67.0:

66 failed, 897 passed, 2 skipped, 59 errors, 25 rerun

My first run of 1.82.0 tests stopped at collection, as docs/conf.py imports gp_sphinx, which is not packaged. Skipping that file gave numbers much like the old ones, nearly all of them this:

create window failed: fork failed: No such file or directory

That is tmux failing to get a pty, and it fails the same way with no tmuxp involved:

$ tmux -L ptytest new-session -d
create window failed: fork failed: No such file or directory

I build in a chroot managed with sysutils/sandboxctl, and my configuration bind-mounted the host’s /dev/pts into it. A null mount of a ptyfs is apparently not enough; the chroot needs an instance of its own. I replaced the bind mount in post_mount_hook() with a real one (see mount_ptyfs(8)):

mount -t ptyfs ptyfs "${SANDBOX_ROOT}/dev/pts" ||
shtk_cli_error "Failed to mount ptyfs on ${SANDBOX_ROOT}/dev/pts"

With ptys working, the same tests failed differently:

ValueError: zip() argument 2 is shorter than argument 1

libtmux asks tmux for a long list of format fields separated by ␞ (U+241E) and splits the output on it. In a non-UTF-8 locale tmux prints _ in its place. pkgsrc runs everything with LC_ALL=C.

Adding a locale to TEST_ENV does not help, as pkgsrc appends its own environment after the package’s, and the last assignment wins. The locale has to come after ${TEST_ENV} on the command line, which means replacing the do-test target:

do-test:
        ${RUN} cd ${WRKSRC} && \
        ${SETENV} ${TEST_ENV} LC_ALL=en_US.UTF-8 \
                pytest-${PYVERSSUFFIX}

With the package installed, that leaves two failures, from /bin/bash and /bin/false hard-coded in the tests:

2 failed, 907 passed, 2 skipped, 5 rerun

Testing libtmux

The libtmux test suite needed more.

Its pytest options and test paths depend on gp-libs, which is not packaged either. The doctests use a +HIDE option flag that pytest’s own doctest plugin rejects, and which I take to come from gp-libs too. The docs tests want gp_sphinx and sphinx_ux_badges. I replaced the options and run only the unit tests.

The locale needed a second variable. The tests have a clear_env fixture that removes every environment variable whose name does not contain one of a short list of words. LANG survives it. LC_ALL does not.

Three tests hang: two that call load_buffer and one that calls source_file. All three have tmux read a file through the client, which is as far as I got with the cause. A tmux: client process sits under pytest until it is killed, after which the test fails and the run continues. I tried pytest-timeout, which did not fire, and I don’t know why. The three tests are deselected instead. Because --deselect matches by prefix, one innocent test (named test_source_file_quiet) goes with them.

11 failed, 1376 passed, 62 skipped, 4 deselected, 22 rerun

Six of the remaining failures are panes that have gone away, two are servers that exited, and three are timing assertions that miss a 1.1 second limit by 0.04 seconds. I have not looked into those.

Add a comment