Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ with `-S` or `-L`, clear inherited `TMUX` and `TMUX_PANE` for child commands,
and clean up only the server and files created by that run. Never use the
default tmux server or sweep another port's temporary files.

Tests must also pass on macOS; [MACOS_CI.md](MACOS_CI.md) lists what that
requires.

Record the actual tmux version when behavior depends on it. A passing subset
does not establish support for an entire version range.

Expand Down
65 changes: 65 additions & 0 deletions .github/MACOS_CI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# macOS CI

What a test needs so it passes on macOS as well as Linux.

## Waiting

- **Wait for the event, not the clock.** Subscribe, act, then wait for the
notification, `wait-for` channel, hook, or pane output the action causes.
Keep a timeout only as a hang guard. The macOS runner is slower to start
processes, so a deadline tuned on Linux fails there.
- **Read after the change, not after the command.** tmux renames windows,
starts pane processes and draws output after the command returns. Name
windows yourself unless the name is what the test checks.
- **Wait for the shell before typing.** Keys typed before the shell is ready
are echoed back, and a text wait can match a command that never ran.
- **Read control-mode output all the time.** tmux stops reading panes when its
only attached client is a control client nobody reads.

## Paths and sockets

- **Compare physical paths.** tmux reports `/private/tmp/...` for `/tmp/...`.
Resolve the expected path before comparing.
- **Keep socket paths short.** A socket path must fit in 104 bytes, and the
macOS temporary directory is long. Put sockets under a short directory.
- **Poll for a socket; don't watch for it.** Watchers built on FSEvents
(libuv, .NET, Julia) do not report a socket being created.

## Shells and processes

- **`/bin/sh` is bash 3.2.** Pin the pane's shell, avoid bash 4 syntax, and
expect `pane_current_command` to say `bash`.
- **No `/proc`, no `/bin/false`.** Use `ps` or tmux formats, and `false` from
`PATH`.
- **Reap before signalling a process group.** `killpg` fails with EPERM when
every member has exited but has not been reaped.
- **Stay well under 511 terminals.** Past that, tmux reports
`fork failed: Device not configured`. Kill every server a test starts.
- **Keep typed input under 1 KB.** Longer input is dropped. Send long text
through a file or a paste buffer.
- **Read a pane until its process exits.** On macOS a process cannot finish
exiting while its terminal output is unread.

## Building tmux

Configure with `--enable-utf8proc --enable-jemalloc`. Recent tmux refuses to
configure on macOS without a choice for both.

## Reproducing on Linux

- Slow runner: pin the test to one CPU beside busy loops, or put a `tmux`
wrapper that sleeps first on `PATH`.
- Physical paths: point the test's temporary directory at a symlink.
- `/bin/sh` as bash: `set -g default-shell /bin/sh` and
`set -g default-command "/bin/bash -i"`.
- Long socket paths: set `TMPDIR` to a deep directory.

## In this repository

- Event waits in tests and `TmuxFixture` use `HANG_GUARD_SECONDS` from
`test/test_helper.rb`.
- Tests that prove a deadline is enforced advance a clock the code reads, as in
`OperationBudgetTest` and `MCPMutationTest::AdvancingClock`.
- `TmuxFixture` refuses a socket path that does not fit and names the cause.
- `scripts/stress` and the stress workflow repeat the integration suite on
macOS with a Linux control.
91 changes: 91 additions & 0 deletions .github/workflows/stress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: stress

on:
schedule:
- cron: '17 7 * * 1'
workflow_dispatch:
inputs:
repeat:
type: number
description: Repetitions of the real-tmux integration suite per runner
default: 10

permissions:
contents: read

concurrency:
group: stress-${{ github.ref }}
cancel-in-progress: true

jobs:
repeat:
name: ${{ matrix.runner }} / Ruby 4.0.7 / tmux 3.7c
runs-on: ${{ matrix.runner }}
timeout-minutes: 90
strategy:
fail-fast: false
max-parallel: 1
matrix:
runner: [ubuntu-24.04, macos-15]
env:
BUNDLE_FROZEN: 'true'
TMUX_VERSION: 3.7c
TMPDIR: /tmp
REPEAT: ${{ inputs.repeat || 10 }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ruby/setup-ruby@14594264cd68ce8a2345dd349bc3d138a4ef85c8 # v1.327.0
with:
ruby-version: '4.0.7'
bundler-cache: true
- name: Install Linux build dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --yes libevent-dev libncurses-dev bison pkg-config zsh
- name: Install macOS build dependencies
if: runner.os == 'macOS'
run: brew install libevent ncurses bison pkg-config jemalloc
- name: Build the exact tmux release
shell: bash
run: |
set -euo pipefail
archive="$RUNNER_TEMP/tmux-$TMUX_VERSION.tar.gz"
curl --location --fail --silent --show-error \
"https://github.com/tmux/tmux/releases/download/$TMUX_VERSION/tmux-$TMUX_VERSION.tar.gz" \
--output "$archive"
ruby -rjson -rdigest -e 'expected = JSON.parse(File.read("scripts/tmux-releases.json")).fetch(ENV.fetch("TMUX_VERSION")); abort "tmux archive checksum mismatch" unless Digest::SHA256.file(ARGV.fetch(0)).hexdigest == expected' "$archive"
tar -xzf "$archive" -C "$RUNNER_TEMP"
configure_options=(--disable-utf8proc)
if [ "$RUNNER_OS" = macOS ]; then
PATH="$(brew --prefix bison)/bin:$PATH"
PKG_CONFIG_PATH="$(brew --prefix jemalloc)/lib/pkgconfig:$(brew --prefix libevent)/lib/pkgconfig:$(brew --prefix ncurses)/lib/pkgconfig"
CPPFLAGS="-I$(brew --prefix jemalloc)/include -I$(brew --prefix libevent)/include -I$(brew --prefix ncurses)/include"
LDFLAGS="-L$(brew --prefix jemalloc)/lib -L$(brew --prefix libevent)/lib -L$(brew --prefix ncurses)/lib"
configure_options+=(--enable-jemalloc)
export PATH PKG_CONFIG_PATH CPPFLAGS LDFLAGS
fi
cd "$RUNNER_TEMP/tmux-$TMUX_VERSION"
./configure --prefix="$RUNNER_TEMP/tmux-install" "${configure_options[@]}"
make -j2
make install
test "$("$RUNNER_TEMP/tmux-install/bin/tmux" -V)" = "tmux $TMUX_VERSION"
- name: Repeat the integration suite
env:
LIBTMUX_TEST_TMUX_DIR: ${{ runner.temp }}/tmux-install/bin
run: |
export PATH="$LIBTMUX_TEST_TMUX_DIR:$PATH"
export LIBTMUX_TEST_TMUX="$LIBTMUX_TEST_TMUX_DIR/tmux"
bundle exec scripts/stress --repeat "$REPEAT" --output build/stress
- name: Report each test's failure count
if: always()
run: cat build/stress/summary.md >> "$GITHUB_STEP_SUMMARY"
- name: Retain the CSV and run logs
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: stress-${{ matrix.runner }}
path: build/stress/
if-no-files-found: warn
28 changes: 14 additions & 14 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ second = pane.split(direction: :horizontal, size: "40%", command: ["/bin/cat"])
receipt.window.select_layout("tiled")
Example.check(receipt.window.list_panes.map(&:id).sort == [pane.id, second.id].sort, "assigned pane IDs differ")
server.open_control(session: receipt.entity.ref) do |control|
control.exchange("display-message -p ready", timeout: 0.5)
control.exchange("display-message -p ready", timeout: 10)
output = control.subscribe(pane_id: pane.id, max_bytes: 8192, max_events: 32)
literal = "literal; #{'#{pane_id}'} $HOME"
pane.send_text(literal)
bytes = "".b
bytes << output.next(timeout: 0.5).data until bytes.include?(literal)
bytes << output.next(timeout: 10).data until bytes.include?(literal)
Example.check(pane.capture.stdout.include?(literal), "capture lost literal input")
end
payload = "NUL\0\xff\n".b
Expand Down Expand Up @@ -98,11 +98,11 @@ waiting = nil
begin
waiting = Thread.new do
server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"],
timeout: 0.5, cancel: cancellation)
timeout: 10, cancel: cancellation)
rescue LibTmux::Cancelled => error
error
end
server.wait_for("ready", timeout: 0.5)
server.wait_for("ready", timeout: 10)
cancellation.cancel
failure = waiting.value
Example.check(failure.is_a?(LibTmux::Cancelled), "cancellation lost")
Expand Down Expand Up @@ -130,11 +130,11 @@ while another tmux client waits; cancellation retires that client's process.
Async do |parent|
LibTmux::Async.open(parent: parent, server: server) do |scope|
waiting = parent.async do
scope.server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"], timeout: 0.5)
scope.server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"], timeout: 10)
rescue LibTmux::Cancelled => error
error
end
scope.server.wait_for("ready", timeout: 0.5)
scope.server.wait_for("ready", timeout: 10)
Example.check(scope.diagnostics.fetch(:active_process_slots) == 1, "waiting client lost its slot")
captures = scope.map(scope.server.list_panes.map(&:ref), concurrency: 2) do |ref|
scope.server.pane(ref).capture
Expand All @@ -160,18 +160,18 @@ continue to drain.
<!-- example: control_overflow/main -->
```ruby
server.open_control(session: session.ref) do |control|
control.exchange("display-message -p ready", timeout: 0.5)
control.exchange("display-message -p ready", timeout: 10)
reliable = control.subscribe(max_events: 1, max_bytes: 1024)
tail = control.subscribe(mode: :tail, max_events: 1, max_bytes: 1024)
3.times { |index| window.rename("event#{index}") }
reply = control.exchange("display-message -p alive", timeout: 0.5)
reply = control.exchange("display-message -p alive", timeout: 10)
Example.check(reply.blocks.last.body == "alive\n", "slow reader blocked commands")
Example.check(reply.attribution == :boundary_window, "reply overclaims attribution")
Example.check(reliable.diagnostics.fetch(:overflowed), "overflow is missing from diagnostics")
Example.check(control.diagnostics.fetch(:retained_reply_bytes).zero?, "consumed reply remains retained")
reliable.next(timeout: 0.5)
Example.raises(LibTmux::SubscriptionOverflow) { reliable.next(timeout: 0.5) }
gap = tail.next(timeout: 0.5)
reliable.next(timeout: 10)
Example.raises(LibTmux::SubscriptionOverflow) { reliable.next(timeout: 10) }
gap = tail.next(timeout: 10)
Example.check(gap.kind == :gap && gap.dropped_bytes.positive?, "tail hid lost bytes")
end
```
Expand Down Expand Up @@ -231,7 +231,7 @@ Open3.popen3(Gem.ruby, "-W:no-experimental", executable, "--socket", server.endp
"--enable-tool", "tmux_close", "--enable-tool", "tmux_run", *enrollment_arguments) do |input, output, errors, process|
request = lambda do |id, method, params = {}|
input.write(JSON.generate({jsonrpc: "2.0", id: id, method: method, params: params}) + "\n")
Example.check(IO.select([output], nil, nil, id == 1 ? 1.0 : 0.5), "installed MCP did not return a frame")
Example.check(IO.select([output], nil, nil, 10), "installed MCP did not return a frame")
response = JSON.parse(output.gets)
Example.check(response.fetch("id") == id, "MCP response identity changed")
response.fetch("result")
Expand All @@ -253,7 +253,7 @@ Open3.popen3(Gem.ruby, "-W:no-experimental", executable, "--socket", server.endp
if channel
Example.check(File.stat(setup).mode & 0o777 == 0o600, "enrollment setup permissions differ")
channel.puts(setup)
Example.check(IO.select([channel], nil, nil, 0.5) && channel.gets == "ready\n", "shell enrollment was not acknowledged")
Example.check(IO.select([channel], nil, nil, 10) && channel.gets == "ready\n", "shell enrollment was not acknowledged")
target = pane.merge("id" => shell_pane.id)
end
script = 'printf "%s:%s" "$EXAMPLE_CONTEXT" "$TMUX_PANE"; printf "\\000\\377" >&2; exit 9'
Expand All @@ -272,7 +272,7 @@ Open3.popen3(Gem.ruby, "-W:no-experimental", executable, "--socket", server.endp
closed = request.call(6, "tools/call", {name: "tmux_close", arguments: {target: data.fetch("entity")}})
Example.check(closed.fetch("structuredContent").fetch("ok"), "protocol close failed")
input.close
Example.check(process.join(0.5), "MCP EOF did not retire its process")
Example.check(process.join(10), "MCP EOF did not retire its process")
Example.check(process.value.success? && errors.read.empty?, "MCP executable failed")
Example.check(!File.exist?(setup), "enrollment setup survived EOF")
end
Expand Down
6 changes: 3 additions & 3 deletions examples/api/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
)
pane = created.pane
server.open_control(session: created.entity.ref) do |control|
control.exchange("display-message -p ready", timeout: 1)
control.exchange("display-message -p ready", timeout: 10)
output = control.subscribe(pane_id: pane.id, max_bytes: 8192, max_events: 32)
pane.send_text("printf '\\nlibtmux capture ready\\n'")
pane.send_keys("Enter")
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 10
bytes = "".b
until bytes.lines(chomp: true).include?("libtmux capture ready")
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise "Output did not arrive within five seconds" unless remaining.positive?
raise "Output did not arrive within ten seconds" unless remaining.positive?
bytes << output.next(timeout: remaining).data
end
captured = pane.capture.stdout.lines(chomp: true)
Expand Down
4 changes: 2 additions & 2 deletions examples/async_cancel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
Async do |parent|
LibTmux::Async.open(parent: parent, server: server) do |scope|
waiting = parent.async do
scope.server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"], timeout: 0.5)
scope.server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"], timeout: 10)
rescue LibTmux::Cancelled => error
error
end
scope.server.wait_for("ready", timeout: 0.5)
scope.server.wait_for("ready", timeout: 10)
Example.check(scope.diagnostics.fetch(:active_process_slots) == 1, "waiting client lost its slot")
captures = scope.map(scope.server.list_panes.map(&:ref), concurrency: 2) do |ref|
scope.server.pane(ref).capture
Expand Down
4 changes: 2 additions & 2 deletions examples/cancel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
begin
waiting = Thread.new do
server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"],
timeout: 0.5, cancel: cancellation)
timeout: 10, cancel: cancellation)
rescue LibTmux::Cancelled => error
error
end
server.wait_for("ready", timeout: 0.5)
server.wait_for("ready", timeout: 10)
cancellation.cancel
failure = waiting.value
Example.check(failure.is_a?(LibTmux::Cancelled), "cancellation lost")
Expand Down
10 changes: 5 additions & 5 deletions examples/control_overflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
window = session.list_windows.fetch(0)
# docs:begin main
server.open_control(session: session.ref) do |control|
control.exchange("display-message -p ready", timeout: 0.5)
control.exchange("display-message -p ready", timeout: 10)
reliable = control.subscribe(max_events: 1, max_bytes: 1024)
tail = control.subscribe(mode: :tail, max_events: 1, max_bytes: 1024)
3.times { |index| window.rename("event#{index}") }
reply = control.exchange("display-message -p alive", timeout: 0.5)
reply = control.exchange("display-message -p alive", timeout: 10)
Example.check(reply.blocks.last.body == "alive\n", "slow reader blocked commands")
Example.check(reply.attribution == :boundary_window, "reply overclaims attribution")
Example.check(reliable.diagnostics.fetch(:overflowed), "overflow is missing from diagnostics")
Example.check(control.diagnostics.fetch(:retained_reply_bytes).zero?, "consumed reply remains retained")
reliable.next(timeout: 0.5)
Example.raises(LibTmux::SubscriptionOverflow) { reliable.next(timeout: 0.5) }
gap = tail.next(timeout: 0.5)
reliable.next(timeout: 10)
Example.raises(LibTmux::SubscriptionOverflow) { reliable.next(timeout: 10) }
gap = tail.next(timeout: 10)
Example.check(gap.kind == :gap && gap.dropped_bytes.positive?, "tail hid lost bytes")
end
# docs:end main
Expand Down
4 changes: 2 additions & 2 deletions examples/layout_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
receipt.window.select_layout("tiled")
Example.check(receipt.window.list_panes.map(&:id).sort == [pane.id, second.id].sort, "assigned pane IDs differ")
server.open_control(session: receipt.entity.ref) do |control|
control.exchange("display-message -p ready", timeout: 0.5)
control.exchange("display-message -p ready", timeout: 10)
output = control.subscribe(pane_id: pane.id, max_bytes: 8192, max_events: 32)
literal = "literal; #{'#{pane_id}'} $HOME"
pane.send_text(literal)
bytes = "".b
bytes << output.next(timeout: 0.5).data until bytes.include?(literal)
bytes << output.next(timeout: 10).data until bytes.include?(literal)
Example.check(pane.capture.stdout.include?(literal), "capture lost literal input")
end
payload = "NUL\0\xff\n".b
Expand Down
Loading
Loading