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 @@ -280,6 +280,9 @@ that `Endpoint` resolves the default to the same path. Two controls run the
same client with another `TMUX_TMPDIR` and with an inherited `TMUX`, and
require the canary's own test to reject both.

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.
69 changes: 69 additions & 0 deletions .github/workflows/stress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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'
LIBTMUX_VERSION_CHECK_EXPECT: supported
TMPDIR: /tmp
REPEAT: ${{ inputs.repeat || 10 }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ruby/setup-ruby@145243922b4465b78e04dd66294782c7de45901f # v1.345.0
with:
ruby-version: '4.0.7'
bundler-cache: true
- name: Install zsh
if: runner.os == 'Linux'
uses: libtmux/.github/actions/apt-get@30f81842b1e639ea4e25f93f1f2543504178e228
with:
update: 'true'
args: install --yes zsh
- name: Build the exact tmux release
id: tmux
uses: libtmux/setup-tmux@96c8f0d575eae62d1c3419ef919b69ecc43f3cac # v0.1.0
with:
version: 3.7c
configure-args: --disable-utf8proc
add-to-path: 'true'
- name: Repeat the integration suite
env:
LIBTMUX_TEST_TMUX: ${{ steps.tmux.outputs.binary }}
run: 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@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: stress-${{ matrix.runner }}
path: build/stress/
if-no-files-found: warn
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ at one version, so a release has a section in each changelog.

## 0.1.4 (unreleased)

- Test event waits allow slower runners to finish. The weekly stress
workflow reports failures and the slowest run of each test on macOS and
Linux. (#18)

## 0.1.3 (2026-12-05)

Core and Async can wait for visible pane text with a deadline. On tmux 3.7
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require "libtmux"
require "rbconfig"

def wait_until(message)
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 10
loop do
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise message unless remaining.positive?
Expand Down
22 changes: 11 additions & 11 deletions docs/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ LibTmux::Server.start do |server|
pane.send_text("printf '\\n%s %s\\n' 'pane' 'prête'")
pane.send_keys("Enter")
end
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 10
if server.supports_control?
server.open_control(session: receipt.entity.ref) do |control|
control.exchange("display-message -p ready")
control.exchange("display-message -p ready", timeout: 10)
output = control.subscribe(
pane_id: pane.id, max_bytes: 8192, max_events: 32
)
send_command.call
received = +"".b
until received.include?(expected.b)
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise "No pane reply within five seconds" unless remaining.positive?
raise "No pane reply within ten seconds" unless remaining.positive?
event = output.next(timeout: remaining)
received << event.data if event.data
end
Expand All @@ -95,7 +95,7 @@ LibTmux::Server.start do |server|
break if lines.include?(expected)

if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
raise "No captured reply within five seconds"
raise "No captured reply within ten seconds"
end
sleep 0.02
end
Expand Down Expand Up @@ -187,11 +187,11 @@ LibTmux::Server.start do |server|
LibTmux::Async.open(parent: parent, server: server) do |scope|
waiting = parent.async do
scope.server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"],
timeout: 5)
timeout: 10)
rescue LibTmux::Cancelled => error
error
end
scope.server.wait_for("ready", timeout: 5)
scope.server.wait_for("ready", timeout: 10)
panes = scope.server.list_panes.map(&:ref)
captures = scope.map(panes, concurrency: 2) do |ref|
scope.server.pane(ref).capture
Expand Down Expand Up @@ -243,24 +243,24 @@ LibTmux::Server.start do |server|
end

server.open_control(session: session.ref) do |control|
control.exchange("display-message -p ready", timeout: 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: 5)
reply = control.exchange("display-message -p alive", timeout: 10)
raise "Expected the reply alive" unless reply.blocks.last.body == "alive\n"
unless reply.attribution == :boundary_window
raise "Reply names the wrong source"
end

reliable.next(timeout: 5)
reliable.next(timeout: 10)
begin
reliable.next(timeout: 5)
reliable.next(timeout: 10)
raise "Expected the reliable subscriber to report overflow"
rescue LibTmux::SubscriptionOverflow
end
gap = tail.next(timeout: 5)
gap = tail.next(timeout: 10)
raise "Expected an output gap with dropped bytes" unless gap.kind == :gap &&
gap.dropped_bytes.positive?
end
Expand Down
2 changes: 1 addition & 1 deletion examples/api/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "rbconfig"

def wait_until(message)
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 10
loop do
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise message unless remaining.positive?
Expand Down
4 changes: 2 additions & 2 deletions examples/async_cancel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
LibTmux::Async.open(parent: parent, server: server) do |scope|
waiting = parent.async do
scope.server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"],
timeout: 5)
timeout: 10)
rescue LibTmux::Cancelled => error
error
end
scope.server.wait_for("ready", timeout: 5)
scope.server.wait_for("ready", timeout: 10)
panes = scope.server.list_panes.map(&:ref)
captures = scope.map(panes, 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 @@ -17,24 +17,24 @@
end

server.open_control(session: session.ref) do |control|
control.exchange("display-message -p ready", timeout: 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: 5)
reply = control.exchange("display-message -p alive", timeout: 10)
raise "Expected the reply alive" unless reply.blocks.last.body == "alive\n"
unless reply.attribution == :boundary_window
raise "Reply names the wrong source"
end

reliable.next(timeout: 5)
reliable.next(timeout: 10)
begin
reliable.next(timeout: 5)
reliable.next(timeout: 10)
raise "Expected the reliable subscriber to report overflow"
rescue LibTmux::SubscriptionOverflow
end
gap = tail.next(timeout: 5)
gap = tail.next(timeout: 10)
raise "Expected an output gap with dropped bytes" unless gap.kind == :gap &&
gap.dropped_bytes.positive?
end
Expand Down
8 changes: 4 additions & 4 deletions examples/layout_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
pane.send_text("printf '\\n%s %s\\n' 'pane' 'prête'")
pane.send_keys("Enter")
end
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 10
if server.supports_control?
server.open_control(session: receipt.entity.ref) do |control|
control.exchange("display-message -p ready")
control.exchange("display-message -p ready", timeout: 10)
output = control.subscribe(
pane_id: pane.id, max_bytes: 8192, max_events: 32
)
send_command.call
received = +"".b
until received.include?(expected.b)
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise "No pane reply within five seconds" unless remaining.positive?
raise "No pane reply within ten seconds" unless remaining.positive?
event = output.next(timeout: remaining)
received << event.data if event.data
end
Expand All @@ -46,7 +46,7 @@
break if lines.include?(expected)

if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
raise "No captured reply within five seconds"
raise "No captured reply within ten seconds"
end
sleep 0.02
end
Expand Down
8 changes: 4 additions & 4 deletions examples/mcp_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@
Example.check(application.call("tmux_close", {}).structured_content.dig("error", "code") == "policy_denied", "default policy permits mutation")
cancellations = Queue.new
sdk.define_custom_method(method_name: "example/wait") do |_, server_context:|
scope.server.run(["wait-for", "-S", "protocol-ready", ";", "wait-for", "protocol-held"], timeout: 0.5)
scope.server.run(["wait-for", "-S", "protocol-ready", ";", "wait-for", "protocol-held"], timeout: 10)
{finished: true}
rescue LibTmux::Cancelled => failure
cancellations << failure
{cancelled: true}
end
send_request.call(4, "example/wait", {_meta: envelope})
scope.server.wait_for("protocol-ready", timeout: 0.5)
scope.server.wait_for("protocol-ready", timeout: 10)
client_input.write(JSON.generate({jsonrpc: "2.0", method: "notifications/cancelled", params: {requestId: 4}}) + "\n")
send_request.call(5, "tools/call", {name: "tmux_capabilities", arguments: {}, _meta: envelope})
Example.check(receive.call("tmux_capabilities after cancellation").fetch("id") == 5, "cancelled request blocked protocol reader")
failure = parent.with_timeout(0.5) { cancellations.pop }
failure = parent.with_timeout(Example::MCP_RESPONSE_TIMEOUT) { cancellations.pop }
Example.check(failure.delivery == :possibly_sent, "cancellation claimed no dispatch")
Example.raises(Errno::ECHILD) { Process.waitpid(failure.pid, Process::WNOHANG) }
ensure
failure = $!
cleanup = [-> { client_input&.close unless client_input&.closed? },
-> { runner&.wait(timeout: 0.5) }, -> { transport&.close }, -> { application&.close }]
-> { runner&.wait(timeout: 10) }, -> { transport&.close }, -> { application&.close }]
cleanup.concat([input, output, client_output].compact.map { |io| -> { io.close unless io.closed? } })
cleanup.each do |action|
action.call
Expand Down
4 changes: 2 additions & 2 deletions examples/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

module Example
MCP_STARTUP_TIMEOUT = 10
MCP_RESPONSE_TIMEOUT = 5
MCP_SHUTDOWN_TIMEOUT = 2
MCP_RESPONSE_TIMEOUT = 10
MCP_SHUTDOWN_TIMEOUT = 10

class FrameReader
MAX_BYTES = 1 << 20
Expand Down
2 changes: 1 addition & 1 deletion gems/libtmux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ require "libtmux"
require "rbconfig"

def wait_until(message)
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 10
loop do
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
raise message unless remaining.positive?
Expand Down
Loading