Skip to content

test: reset the themed console singleton between tests - #4788

Merged
Daniel Meppiel (danielmeppiel) merged 1 commit into
mainfrom
danielmeppiel-fix-4773-console-width
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 1 commit into
mainfrom
danielmeppiel-fix-4773-console-width

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

test_outdated_command.py::TestOutdatedCommand::test_long_package_name_folds_instead_of_clipping fails depending on shard order: it asserts an 80-column fold but sees a table about 124 columns wide.

Root cause: apm outdated renders through commands/_helpers._get_console, which is apm_cli.utils.themed_console._get_console. That returns a module singleton (themed_console._console), and Rich fixes a console's width when it is built. The autouse _reset_console_state fixture in tests/conftest.py resets utils.console._console_instance and rich._console, but not themed_console._console. So the first test on an xdist worker that builds the themed console fixes its width for every later test on that worker. Evidence: CI job 137286964300 (#4758) and #4777 Shard 1, job 137290508485.

Fix (test-only): the shared fixture now calls a reset_console_singletons() helper, which also nulls themed_console._console before and after each test. Because the reset lives in the autouse fixture, it covers every test, not only the outdated one. No product code, CONFORMANCE or lifecycle files change.

Credit: W2b and P3 also identified the themed singleton.

Issue and approved scope

Issue: Fixes #4773

Human scope-approval comment: test-only flake fix assigned by the QL VP under the inherited-red standing rule (#4773 is the tracked flake). No product behaviour changes.

Does this PR complete the issue, or what remains? It completes it.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Regression guard: tests/integration/test_wave6_outdated_view_coverage.py::TestOutdatedParallel::test_console_guard_resets_rich_singleton_before_and_after now sets themed_console._console to a mock and asserts the fixture nulls it before and after. That assertion fails on main's conftest.

The order-dependent repro runs a probe first: a test that sets COLUMNS=200 and calls themed_console._get_console(), followed by the outdated test, with -p no:xdist -p no:randomly. Results are posted in a PR comment.

Lint: uvx [email protected] check and format --check on the changed files pass; scripts/check_test_assertions.py passes; tests.quality.taxonomy --changed passes for the committed files.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding one line: user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes only under upgrade notes; no Highlights; no new lines under ## [Unreleased]. See changelog.d/README.md and .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

The themed console returned by commands/_helpers._get_console is a module
singleton whose width Rich fixes when it is built. The autouse
_reset_console_state fixture reset utils.console and rich._console but not
utils.themed_console._console, so the first test on an xdist worker fixed
the width for every later test. test_outdated_command's 80-column fold
assertion then saw a ~124-column table depending on shard order.

Reset themed_console._console in the shared fixture (now a
reset_console_singletons helper) and extend the existing guard test to
assert it is nulled before and after each test.

Fixes #4773

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 17:59
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the test-only console-state cleanup change.

No open issues 🎉

What changed in this PR

This test-only change addresses the order-dependent apm outdated table-width flake tracked in #4773 by resetting cached console state between tests. Product behavior is unchanged.

Changes:

  • Centralizes console resets in a helper that also clears the themed console singleton before and after each test.
  • Extends the existing regression test to verify themed console cleanup during both fixture setup and teardown.
File Description
tests/​integration/​test_wave6_outdated_view_coverage.py Adds assertions that the fixture clears the themed console singleton.
tests/​conftest.py Adds a shared reset helper and invokes it before and after each test.

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 0a31fd7 into main Nov 22, 2026
103 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-4773-console-width branch November 22, 2026 19:32
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] Flaky: test_long_package_name_folds_instead_of_clipping depends on terminal width

2 participants