Skip to content
Merged
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
2 changes: 2 additions & 0 deletions changelog.d/1041.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Fixed
- Test consoles render CLI help at the conftest width (`COLUMNS=250`) in every environment by preventing Typer's GitHub Actions detection from forcing an 80-column terminal under `TERM=dumb`, eliminating width-dependent test discrepancies between local runs and GitHub Actions CI (#1041).
23 changes: 23 additions & 0 deletions docs/agent/tasks/task-1041-ci-test-terminal-width.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Task: CLI help renders at the same width locally and in GitHub CI (#1041)

**Issue**: [#1041](https://github.com/dan-petty/devops-cli/issues/1041)
**Status**: Done
**Milestone**: v0.2.31
**Priority**: priority/p2-medium
**Scope**: type/bug, priority/p2-medium, scope/ci

## Description

Under GitHub Actions, Typer sets `FORCE_TERMINAL = True` at import when `GITHUB_ACTIONS` is set in the environment. In the test suite, `tests/conftest.py` sets `COLUMNS=250`, `NO_COLOR=1`, and `TERM=dumb`. When Rich initializes a console that is forced to be a terminal with `TERM=dumb`, it defaults to an 80x25 terminal size and ignores `COLUMNS`. Without `GITHUB_ACTIONS`, Rich treats the non-terminal console normally and respects `COLUMNS=250`.

This caused CLI help panels invoked via `CliRunner` to wrap at 80 columns in GitHub Actions CI while rendering at 250 columns locally and in DevContainers, creating width-dependent test discrepancies and line-wrap failures.

The fix configures `tests/conftest.py` to set `typer.rich_utils.FORCE_TERMINAL = None` upon import and during `reset_dry_run_state`, ensuring test consoles consistently respect `COLUMNS=250` across all environments.

## Acceptance Criteria

- [x] Tests see one terminal width in every environment: `tests/conftest.py` stops Typer's GitHub Actions detection from forcing a terminal for test consoles by clearing `typer.rich_utils.FORCE_TERMINAL = None`, so Rich always reads `COLUMNS`.
- [x] A test asserts that, with `GITHUB_ACTIONS=true` in the environment, a `CliRunner` render of a help panel uses the conftest width (no line of the help is wrapped at 80 columns): `test_cli_help_panel_renders_at_conftest_width_under_github_actions` in `tests/test_output.py`.
- [x] The full suite passes with `CI=true GITHUB_ACTIONS=true` set locally, and without them.
- [x] `changelog.d/1041.md` records the fix under `### Fixed`. `CHANGELOG.md` is not edited.
- [x] `uv run devops ci` passes.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from unittest.mock import MagicMock, patch

import pytest
import typer.rich_utils

if TYPE_CHECKING:
from devops_cli.ai.spend.ledger import SpendLedger
Expand Down Expand Up @@ -256,6 +257,11 @@ def __init__(self, **kwargs: Any) -> None:
_TERMINAL_ENV = {"COLUMNS": "250", "NO_COLOR": "1", "TERM": "dumb"}
os.environ.update(_TERMINAL_ENV)

# Typer forces a terminal when GITHUB_ACTIONS, FORCE_COLOR or PY_COLORS is set, which under TERM=dumb
# causes Rich to report an 80x25 terminal size and ignore COLUMNS. Clear FORCE_TERMINAL so test
# consoles always honour COLUMNS in every environment (#1041).
typer.rich_utils.FORCE_TERMINAL = None


@pytest.fixture(autouse=True)
def preserve_cwd():
Expand All @@ -276,6 +282,7 @@ def reset_dry_run_state():
import devops_cli.dry_run.state as dry_run_state
import devops_cli.output.console as console_module

typer.rich_utils.FORCE_TERMINAL = None
os.environ.update(_TERMINAL_ENV)
os.environ.pop("DEVOPS_CLI_DRY_RUN", None)
dry_run_state.mark_dry_run_invocation(False)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,3 +1124,22 @@ def test_no_flag_means_the_human_readable_default() -> None:
from devops_cli.output.serialization import resolve_format

assert resolve_format() == "table"


def test_cli_help_panel_renders_at_conftest_width_under_github_actions(monkeypatch) -> None:
"""With GITHUB_ACTIONS=true in the environment, CliRunner renders help at conftest width (#1041)."""
import typer.rich_utils
from typer.testing import CliRunner

from devops_cli.main import app

monkeypatch.setenv("GITHUB_ACTIONS", "true")
result = CliRunner().invoke(app, ["--help"])
lines = [line for line in result.output.splitlines() if line.strip()]

assert (
result.exit_code,
typer.rich_utils.FORCE_TERMINAL is None,
max(len(line) for line in lines),
any(len(line) > 80 for line in lines),
) == (0, True, 250, True)
Loading