Skip to content

Free TUI test renderers that were leaking TextBuffers (CL-5539) - #564

Merged
TheGreatAxios merged 1 commit into
mainfrom
cl-5539-tui-test-renderers-are-never-freed
Aug 23, 2026
Merged

Free TUI test renderers that were leaking TextBuffers (CL-5539)#564
TheGreatAxios merged 1 commit into
mainfrom
cl-5539-tui-test-renderers-are-never-freed

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Closes CL-5539.

Problem

CL-5539: TUI test renderers were never freed in several test files, so a full-suite run leaked native TextBuffer handles until CI ran out and started emitting "Failed to create renderer" / "Failed to create TextBuffer".

src/tui/harness.ts's withTestRenderer already frees correctly via try/finally, and most .test.ts files that call createHarness directly already pair it with a try/finally or beforeAll/afterAll destroy. Four files did not:

  • src/tui/list-modal.test.ts — created a harness per test, never destroyed it.
  • src/tui/provider-connect.test.ts — same, single test.
  • src/tui/provider-setup.test.ts — the big one: ~30 call sites go through mountSetup/mountLogin/createHarness, but the file had exactly one harness.destroy() call. Nearly every test leaked a renderer.
  • src/tui/mouse-reporting-disabled.test.ts — only freed its harness on the happy path (mountedHarnesses.pop()?.destroy() at the end of the test body), so a failing assertion above it would leak.

Fix

In each file, track every harness created and free it in a shared afterEach, so cleanup happens regardless of which assertion fails partway through a test. This matches the pattern already used by files in this suite that share one harness across a describe block via beforeAll/afterAll.

Verification

  • bun test src/tui/list-modal.test.ts src/tui/provider-connect.test.ts src/tui/provider-setup.test.ts src/tui/mouse-reporting-disabled.test.ts — 67 pass, 0 fail.
  • bun test src/tui (full TUI suite, 118 files / 1795 tests) — 0 fail, and grep -c "Failed to create renderer\|Failed to create TextBuffer" on the run's output is 0.
  • Confirmed the leak at the code level before fixing: provider-setup.test.ts had 30 createHarness calls against 1 destroy() call; after the fix the counts balance (every harness created is tracked and destroyed in afterEach).
  • bun run check (lint, typecheck, build, test) — green: 5277 pass, 0 fail across 377 files.

Left out / other issues noticed

  • Did not touch product-level code — this is test-infrastructure only.
  • Did not re-verify the permission-subagent-spans order dependency mentioned in the ticket's "done when" list; that needs a separate pass once this lands.
  • No product bugs found during this investigation.

list-modal.test.ts and provider-connect.test.ts never destroyed the
harness renderer they created. provider-setup.test.ts was worse: ~30
mountSetup/mountLogin/createHarness call sites but only one
harness.destroy() in the whole file, so nearly every test in it leaked
a renderer and its TextBuffer. mouse-reporting-disabled.test.ts only
freed its harness on the happy path, leaking on assertion failure.

Fix: track every harness created in each file and free it in a shared
afterEach, so cleanup happens regardless of which assertion fails
partway through a test, matching the pattern already used elsewhere in
this suite.
@linear-code

linear-code Bot commented Aug 23, 2026

Copy link
Copy Markdown

CL-5539

@TheGreatAxios
TheGreatAxios merged commit 7e08c66 into main Aug 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant