Skip to content

Commit 52962ae

Browse files
alexkromanclaude
andauthored
tests: pin render width suite-wide so --help asserts match CI (#147)
The fixed_render_size fixture (COLUMNS=80/LINES=40) was opt-in, used only by the snapshot modules. The ~20 other test files that assert against --help or rendered CLI output ran at whatever width the environment supplied. Rich's no-clip help table ellipsizes a long flag name ("--end-of-turn-c…") once its column overflows, so a substring assert like `"--with-api-key" in help` passes at a contributor's wide local terminal and fails at CI's narrower width. That gap cost one PR three CI rounds on a single test (test_api_key_flag_is_hidden_from_help). Making the fixture autouse pins the render width for every test, so a local green is a CI green for output tests. Tests that need a different width still override it per call (runner.invoke(app, argv, env={"COLUMNS": "300"})). Document the lesson in tests/AGENTS.md. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8e39d2a commit 52962ae

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

tests/AGENTS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ Lessons that cost iterations getting the patch-coverage and mutation tail gates
4040
- **Help text and docstrings are pinned by the syrupy snapshots, not unit asserts** — a
4141
mutated help string is killed by the regenerated `.ambr`, so `--snapshot-update` and commit
4242
rather than adding redundant `--help` substring asserts.
43+
- **Render width is pinned suite-wide (`COLUMNS=80`), so a `--help` substring assert is
44+
deterministic** — the autouse `fixed_render_size` fixture (`conftest.py`) sets `COLUMNS`/`LINES`
45+
for *every* test, because the no-clip help table ellipsizes a long flag name
46+
(`--end-of-turn-c…`) once its column overflows. Without the pin a `--with-api-key`-style
47+
substring assert passes at a wide local terminal and fails at CI's narrower width — that gap
48+
cost a PR three CI rounds. Don't fight it: a local green is now a CI green for output tests.
49+
A test that genuinely needs a different width passes it on the call
50+
(`runner.invoke(app, argv, env={"COLUMNS": "300"})`), which overrides the default.
4351
- **Typer's `CliRunner` merges stderr into `result.output`, and not in call order**, so don't
4452
assume `splitlines()[-1]` is the command payload. In `--json` mode the env-mismatch warning
4553
is its own `{"warning": …}` line, so filter parsed lines by a key the payload carries

tests/conftest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,23 @@ def pin_timezone(monkeypatch):
8787
time.tzset()
8888

8989

90-
@pytest.fixture
90+
@pytest.fixture(autouse=True)
9191
def fixed_render_size(monkeypatch):
92-
# Pin the render width/height so the CLI-surface goldens (the
93-
# test_snapshots_* modules) are byte-identical across machines and CI.
94-
# Named (not autouse): only the snapshot modules opt in via
95-
# `pytestmark = pytest.mark.usefixtures("fixed_render_size")`.
92+
# Pin the render width/height for the *whole* suite so anything that renders
93+
# CLI/help output is byte-identical across machines and CI. Rich/Click derive
94+
# the help width from COLUMNS (falling back to the inherited terminal size),
95+
# and the no-clip table ellipsizes long flag names ("--end-of-turn-c…") once
96+
# the column overflows — so a `--help` substring assertion that passes at a
97+
# contributor's wide local terminal can silently fail at CI's narrower width.
98+
# That exact gap (a hidden `--with-api-key` flag asserted present, clipped away
99+
# in CI) burned three CI rounds on one PR; autouse closes it so a local green
100+
# means a CI green.
101+
#
102+
# Autouse, not opt-in: every test gets the pinned size. A test that needs a
103+
# different width passes it explicitly to the invocation (the canonical pattern
104+
# in test_help_rendering.py: `runner.invoke(app, argv, env={"COLUMNS": "80"})`),
105+
# which CliRunner merges over this default. The snapshot modules still carry an
106+
# explicit `usefixtures("fixed_render_size")` marker to document the dependency.
96107
monkeypatch.setenv("COLUMNS", "80")
97108
monkeypatch.setenv("LINES", "40")
98109

0 commit comments

Comments
 (0)