From 65ccc35443ee4462a7d4496c2705f97d7b60a0a3 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 6 Dec 2026 04:34:25 -0600 Subject: [PATCH] docs(contributing): Add breakage graduation policy why: Give contributors and reviewers one repeatable checklist for comparing trunk against new runtime behavior, staging de facto or documented API changes behind warnings and escape hatches, and documenting old-behavior recipes on hard breaks. what: - Add .github/CONTRIBUTING/BREAKING_CHANGES.md with graduation stages, the pull request comparison layout, and the Server.attached_sessions worked example - Update .github/PULL_REQUEST_TEMPLATE.md section 2 to compare trunk against the pull request and record how callers obtain prior behavior - Link .github/CONTRIBUTING/BREAKING_CHANGES.md from .github/CONTRIBUTING.md and REVIEW.md --- .github/CONTRIBUTING.md | 9 +- .github/CONTRIBUTING/BREAKING_CHANGES.md | 177 +++++++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 28 +++- REVIEW.md | 2 +- 4 files changed, 209 insertions(+), 7 deletions(-) create mode 100644 .github/CONTRIBUTING/BREAKING_CHANGES.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 3383ad9190..490b7fa1a9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -224,7 +224,9 @@ pushes, because a tag triggers the publish workflow. See [Release commits](WRITING.md#release-commits). libtmux is pre-1.0: a minor version bump may include breaking API -changes, so downstream projects should pin `>=0.x,<0.y`. +changes, so downstream projects should pin `>=0.x,<0.y`. Warning +floors, escape hatches, `MIGRATION` entries, and hard-break recipes +follow [BREAKING_CHANGES.md](CONTRIBUTING/BREAKING_CHANGES.md). 1. Add the release's entries to `CHANGES`, following [The changelog](WRITING.md#the-changelog). @@ -245,7 +247,10 @@ belongs in its own commit, and usually in its own pull request. Discuss a substantial change via an issue before making it. -Update the docs when a change touches the public interface. +Update the docs when a change touches the public interface. Compare +trunk against the pull request and document how callers obtain prior +behavior per [BREAKING_CHANGES.md](CONTRIBUTING/BREAKING_CHANGES.md) +when runtime behavior or public signatures change. A pull request merges once it has the sign-off of one other developer. If you don't have permission to merge it yourself, ask a maintainer to diff --git a/.github/CONTRIBUTING/BREAKING_CHANGES.md b/.github/CONTRIBUTING/BREAKING_CHANGES.md new file mode 100644 index 0000000000..bd49562435 --- /dev/null +++ b/.github/CONTRIBUTING/BREAKING_CHANGES.md @@ -0,0 +1,177 @@ +# Behavioral changes and API breakages + +How `libtmux` evaluates, stages, and documents changes to observable behavior +and public APIs. Read this alongside [CONTRIBUTING.md](../CONTRIBUTING.md), +[WRITING.md](../WRITING.md), and [REVIEW.md](../../REVIEW.md) before opening a +behavioral or API pull request. + +## Documented contracts and de facto behavior + +Most downstream Python packages depend on `libtmux` without an upper version +bound, so minor releases reach users on reinstall. Downstream callers and test +suites depend on observable runtime behavior — return values, exceptions, +`__repr__` formatting, argument escaping, `$TMUX` inheritance, and `.cmd()` +return attributes — even when that behavior was undocumented or accidental. + +Before changing runtime behavior, separate two cases: + +- Unreachable or dead-code defects, where the existing code path never produced + a working result for any caller. +- De facto or documented behavior, where callers, scripts, or unit-test doubles + can observe and rely on the old output or side effect. + +## Graduation sequence + +When a change alters de facto or documented behavior, graduate it across +releases rather than flipping behavior unannounced. + +### 1. Single-release warning floor + +Keep existing default behavior for at least one minor release while emitting a +warning when the old path runs: + +- Emit `FutureWarning` when a call remains valid syntax while its default + runtime semantics will change (for example, bare `Server()` ignoring `$TMUX`, + or `{Session, Window, Pane}.__exit__()` preserving unowned targets). Python + displays `FutureWarning` by default to end users. +- Emit `DeprecationWarning` when retiring a function, method, property, or + parameter in favor of another public API. +- Ship the public replacement before or alongside the warning. Never emit a + warning message that points callers to `libtmux._internal.*`. +- Add `MIGRATION` notes with `# Before` and `# After` code blocks plus + `warnings.filterwarnings`, `[tool.pytest.ini_options]`, and `PYTHONWARNINGS` + recipes so `pytest -Werror` suites have a documented transition step. + +### 2. Default flip and escape hatches + +Flip the default in a subsequent minor release. When callers cannot migrate +every call site in a single upgrade, keep an explicit escape hatch across a +documented deprecation window: + +- Add a keyword parameter or alternate constructor when the choice belongs at + the call site, such as `kill_on_exit=True`, `raises=False` (returning `[]` + instead of raising), or `Server.from_env()`. +- Add an environment variable (`LIBTMUX_*`) when feasible for ambient defaults + where downstream users invoke `libtmux` indirectly through a CLI, plugin, or + test runner and cannot thread a keyword argument through intermediate layers. +- Promote the option to a permanent public parameter when the old behavior + serves a legitimate use case (for example, lenient non-raising inventory + reads or explicit `$TMUX` attachment). Retire temporary escape hatches only + after their window in `MIGRATION` closes. + +### 3. Hard API breaks + +Some defects and protocol boundaries cannot stage behind a warning or an +environment variable — for instance, repairing a filter that unconditionally +returned `[]`, escaping trailing command separators on the wire, or removing a +destructive side effect. + +When an API requires a hard break: + +- Provide a concrete way to obtain the prior behavior on the public API — a + parameter (`raises=False`, `check=False`), an alternate public method or + property (`server.sessions.filter(...)`, `server.clients`), or a runnable + code example — in both the pull request description and `MIGRATION`. +- Omit an old-behavior recipe only when you prove from source that the prior + behavior was unreachable dead code, and include that trace in the pull + request description. +- Place breaking changes under `### Breaking changes` at the top of the + `CHANGES` release entry per [WRITING.md](../WRITING.md#the-changelog), and + update the summary tables in `MIGRATION`. + +## Pull request comparison layout + +Every behavioral or API pull request fills out `### 2. Behavioral comparison` +in [PULL_REQUEST_TEMPLATE.md](../PULL_REQUEST_TEMPLATE.md) with three parts: + +1. Trace what trunk actually does: cite the baseline release tag or `` + commit, quote the exact expression, and walk through what happens at + runtime, including silent exception catches, type coercion, or accidental + outputs. +2. Compare what the pull request does: quote the replacement logic and compare + trunk against the pull request in a dimension table covering missing or + unreachable servers, primary and boundary inputs, runtime return values or + exceptions, static type annotations, and subprocess or timeout side effects. +3. Show how to get the old behavior and its graduation path: name the stage + (`bug fix on unreachable/dead path`, `warning release`, `default flip with + escape hatch`, or `hard break`) and give the exact parameter, environment + variable, alternate public call, or code snippet that reproduces each + plausible interpretation of the prior behavior. + +## Worked example: `Server.attached_sessions` + +The comparison below shows the expected level of detail using +`Server.attached_sessions` ([PR #949](https://github.com/tmux-python/libtmux/pull/949)) +against [`v0.70.0`](https://github.com/tmux-python/libtmux/releases/tag/v0.70.0). + +### 1. What trunk (`v0.70.0`) actually does + +In [`src/libtmux/server.py` lines 1144-1158](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/server.py#L1144-L1158), +`v0.70.0` runs: + +```python +return self.sessions.filter(session_attached__noeq="1") +``` + +Two interacting defects make `server.attached_sessions` return `QueryList([])` +for every server state: + +1. `"noeq"` is absent from [`LOOKUP_NAME_MAP`](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/_internal/query_list.py#L335-L349). +2. `QueryList.filter()` raises [`OpNotFound(op="noeq")`](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/_internal/query_list.py#L363-L372), + a `ValueError` subclass, and the surrounding [`except ValueError:`](https://github.com/tmux-python/libtmux/blob/v0.70.0/src/libtmux/_internal/query_list.py#L578-L593) + meant for `path.rsplit("__", 1)` catches it and falls back to + `lhs = "session_attached__noeq"` with `op = "exact"`. +3. `keygetter(session, "session_attached__noeq")` reads a non-existent + attribute on `Session`, receives `None`, and returns `False` for every item. +4. Even if `noeq` existed, tmux's `#{session_attached}` format variable reports + the decimal client count (`"0"`, `"1"`, `"2"`, …), so `!= "1"` would match + detached sessions (`"0"`) while excluding single-client sessions (`"1"`). + +### 2. What the PR does + +```python +return self.sessions.filter( + lambda session: session.session_attached not in (None, "", "0"), +) +``` + +| Dimension | Trunk (`v0.70.0`) | PR `#949` | +| --- | --- | --- | +| Missing or unreachable server | `QueryList([])` | `QueryList([])` (unchanged; delegates to `self.sessions`) | +| Detached session (`session_attached == "0"`) | Omitted (`[]`) | Omitted (`[]`) | +| 1 attached client (`session_attached == "1"`) | Omitted (`[]`) | Included once | +| 2+ attached clients (`session_attached == "2"`, …) | Omitted (`[]`) | Included once (not duplicated per client) | +| Runtime return type | `QueryList[Session]` (`list` subclass) | `QueryList[Session]` (unchanged) | +| Static type annotation | `list[Session]` | `QueryList[Session]` (subtype-compatible with `list[Session]`; `.get()` and `.filter()` type-check) | +| Subprocess and timeout behavior | One `list-sessions` call via `self.sessions` | Identical | + +### 3. How to get the old behavior and graduation path + +Stage: bug fix on an unreachable dead-code path; ships without a deprecation +warning or environment flag because `Server.attached_sessions` returning `[]` +when clients were attached never worked. Callers wanting any adjacent session +or client filter can express it directly on the public API: + +Single-client sessions only (`session_attached == "1"`): + +```python +server.sessions.filter(session_attached="1") +``` + +Detached sessions (`session_attached == "0"`): + +```python +server.sessions.filter(session_attached="0") +``` + +Sessions where `session_attached != "1"` literally: + +```python +server.sessions.filter(lambda s: s.session_attached != "1") +``` + +One entry per attached client rather than one per session: + +```python +server.clients +``` diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b224b7b284..e228b9ffd2 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,6 @@ - Sibling entry points checked (`sync`/`async`, CLI/API, single/batch, or `N/A`): - Why this belongs here (owner fix, boundary adapter, or single-PR ownership transfer): -### 2. Failure before the fix (`N/A` for docs, lockfile bumps, or pure refactors) +### 2. Behavioral comparison (`N/A` for docs, lockfile bumps, or pure refactors) -- Baseline (`` commit, or `` SHA if fixing a defect introduced in this PR): -- Failing input or command and observed failure before the fix: + + +#### What trunk (`` / latest release) actually does + +- Baseline (`` commit and latest release tag, or `` SHA if fixing a defect introduced in this PR): +- Failing input or code path and observed runtime behavior (including accidental or de facto behavior): + +#### What this PR does + +| Dimension | Trunk | This PR | +| --- | --- | --- | +| Missing or unreachable server | | | +| Primary and boundary inputs | | | +| Runtime return value or exception | | | +| Static type annotation | | | +| Subprocess, state, or timeout side effects | | | + +#### How to get the old behavior and graduation path + +- Stage (`bug fix on unreachable/dead path`, `warning release`, `default flip with escape hatch`, or `hard break`): +- Warning, keyword parameter (`raises=False`, `kill_on_exit=True`), constructor, environment variable (`LIBTMUX_*`), or code snippet that reproduces the prior behavior: ### 3. Verification and tool disclosure - Gates run (plus production-only revert check for behavioral fixes, or `N/A`): - `.github/workarounds.toml` updates (`None` if none): +- `MIGRATION` and `CHANGES` updates (`None` if none): - Tool use: diff --git a/REVIEW.md b/REVIEW.md index 183ad6adb9..774837d057 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -4,7 +4,7 @@ Posture: `experimental` (pre-1.0 typed Python API over `tmux`; align observable [Posture](https://github.com/tmux-python/.github/blob/HEAD/CONTRIBUTING.md#posture) defines `experimental`, `stable` and `private`. -Review the complete change against ``, including untracked files. Report all findings in one pass without editing files. [Writing conventions](.github/WRITING.md) · [Contributing gates](.github/CONTRIBUTING.md) · [AI policy](https://github.com/tmux-python/.github/blob/HEAD/AI_POLICY.md). +Review the complete change against ``, including untracked files. Report all findings in one pass without editing files. [Writing conventions](.github/WRITING.md) · [Contributing gates](.github/CONTRIBUTING.md) · [Breaking changes](.github/CONTRIBUTING/BREAKING_CHANGES.md) · [AI policy](https://github.com/tmux-python/.github/blob/HEAD/AI_POLICY.md). ## 1. Layer ownership