Skip to content

fix(tree): let SetNodes accept a nil root - #1094

Merged
andrinoff merged 1 commit into
charmbracelet:mainfrom
janearc:fix/tree-handle-nil-root
Nov 18, 2026
Merged

andrinoff merged 1 commit into
charmbracelet:mainfrom
janearc:fix/tree-handle-nil-root

Conversation

@janearc

@janearc janearc commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Treat SetNodes(nil) as an empty tree, just like New(nil), so clearing the root doesn't panic when the tree renders.

Add a regression test for clearing the root and check that a supplied root is preserved and rendered.

  • [👩🏻‍🎤] I have read CONTRIBUTING.md.
  • [🚳] I have created a discussion that was approved by a maintainer (for new features).

fix(tree): accept a nil root in SetNodes

SetNodes(nil) reaches code that assumes a root exists. Substitute an empty root, matching New(nil). The regression updates a tree to a nil root and renders it.

Open #1052 updates rendered values in SetValue. This fixes a separate nil-root failure in SetNodes, matching New(nil).

Separate tests cover positive behavior (TestSetNodesRendersReplacement), negative controls (TestSetNodesPreservesSuppliedNode), and the regression (TestSetNodesNil). A representative regression fails on unchanged main and passes with the fix. The positive control passes on main; a deliberate break is also caught by the negative test.

Validation on owner main 1deada954e6e, Go 1.26.10:

  • Full native arm64 race suite passes (-count=1 -cpu=1,4), plus 20 focused race repetitions.
  • Full amd64 tests and race suite pass under Rosetta.
  • Exact CI-pinned golangci-lint v2.13.1, formatting, vet and module tidy pass. Module files are unchanged.
  • Linux/Windows 386 (i386), amd64 and arm64, plus Darwin amd64: build, all-package test compilation, vet and configured lint pass.
  • Aggregate root-module statement coverage: 55.9557% (1818/3249) → 56.3519% (1832/3251); it does not decrease.

Cross-target binaries were compiled rather than executed. These are local results; remote CI remains to be confirmed.

usual disclosure applies; i'm working on my own harness, i use claude, claude root-caused thebug here that usrfaced during my work, i reviewed this, asked codex to review it, the patch is actualy super narrow, let me know if you have questions or mycode smells funny, i am super tired and my brin is a little melted, so i'll leave it here. i have another 8 or 10 to sendtomorrow.

Treat SetNodes(nil) as an empty tree, just like New(nil), so clearing
the root doesn't panic when the tree renders.

Add a regression test for clearing the root and check that a supplied
root is preserved and rendered.
@andrinoff
andrinoff merged commit d4ae900 into charmbracelet:main Nov 18, 2026
11 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.

2 participants