Skip to content

test: reproduction for #4793 - #4794

Closed
worktrunk-bot wants to merge 2 commits into
mainfrom
repro/issue-4793
Closed

worktrunk-bot wants to merge 2 commits into
mainfrom
repro/issue-4793

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

This PR adds a failing reproduction on purpose, without a fix. test_switch_picker_preview_split_follows_terminal_resize boots the picker in a 120-column pty, resizes it to 200 columns, and checks that the list/preview separator stays near the middle. On main the separator stays at column 140: the right:60 window is an absolute width taken from the startup size.

I tried the obvious fix, and it isn't ready to ship. With spec_for emitting right:50%, this test passes, but three existing picker tests fail, and both remaining problems need a decision about how the picker sizes its preview:

  • The startup pane loses a column. At 120 columns the separator moves from column 59 to 60, and skim reports context.width 59 instead of 60. The dimensions_for text width is still 59, so the last painted column is dropped: in switch_picker_abort_escape_preview the tab hint loses its trailing a. test_switch_picker_scrollbar_on_overflow and switch_picker_preview_log_preview move by the same column. The text width would have to be re-derived for skim's percentage geometry, which isn't the same as the Length(N) geometry. A ratatui probe shows Percentage(50) and Length(W/2) split identically, so the difference comes from skim's own handling.
  • skim re-runs the preview with the old width after a resize. skim 5.9's Event::Resize arm calls run_preview before the next render updates preview.cols, so preview() gets the pre-resize context.width. I logged 60, then 60 again after resizing to 200. The new width (100) only arrives with the next keystroke. Adding width to the in-memory PreviewCache key would therefore re-render the pane on the next keystroke, not when the resize happens.
Measurements

All measured in the PTY harness, logging PreviewContext.width from PickerRow::preview:

spec startup separator col startup context.width after resize to 200, before a key after a key
right:60 (main) 59 60 60 (separator 140) 60
right:50% 60 59 59 (separator 100) 100

The in-memory cache key (PickerRowId, PreviewMode) ignores width, and --prs rows fetch their log/comments panes once at the startup width. A width-keyed cache would leave those two tabs on their loading placeholder after a resize unless they are exempted or re-fetched.

Automated triage for #4793

The picker's right preview window is an absolute column count fixed at
startup, so widening the terminal leaves the split at the old position.
The test boots at 120 columns, resizes the pty to 200, and asserts the
separator stays in the middle. It fails on main with the separator at
column 140.

Refs #4793

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

separator_col finds the split by matching the │ border glyph. This file warns against relying on that glyph: the LIST_WIDTH comment says it "renders inconsistently across platforms", and wait_for_stable_with_content says to avoid │ in assertions. On a platform where the glyph doesn't come through as │, expect("startup split") panics before either geometry assertion runs. The test would then keep failing on that platform after #4793 is fixed, for a reason that has nothing to do with the resize. I'll push a version that locates the preview pane by its tab header (1: diff) instead.

…lyph

The │ border glyph renders inconsistently across platforms (see the
LIST_WIDTH comment), so a missing glyph would panic the #4793 repro
before its geometry assertions. Find the preview's "1: diff" tab header
instead; blank cells skim skips with a cursor move read as empty.

Co-Authored-By: Claude <[email protected]>
This was referenced Nov 15, 2026
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot let's fix #4793 rather than leave the workaround:

  • Use right:50%.
  • Put the width in the in-memory cache key.
  • Derive the text width from skim's percentage layout, so the startup pane keeps its last column.

Re-wrapping on the next keystroke is fine for now. Move this repro test into the fix PR and close this one, since a red test can't land.

This was written by Claude Code on behalf of max-sixty

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

The fix is in #4867, with this repro test moved over. The preview spec is now right:50%, and the in-memory cache keys on the pane's text width. The startup text width now comes from skim's own geometry: its startup viewport is one column narrower than the terminal, and the reported pane width includes the separator. So the startup pane no longer loses its last painted column. Closing this one, since its test only goes green together with the fix.

max-sixty pushed a commit that referenced this pull request Nov 20, 2026
…resized (#4867)

The `wt switch` picker's side-by-side preview now keeps its 50/50 split
when the terminal is resized. Before, the split stayed at the startup
column (#4793). The preview window is now `right:50%` instead of an
absolute `right:N`. The in-memory preview cache keys on the pane's text
width, so after a resize a pane misses and is re-rendered at the new
width. `test_switch_picker_preview_split_follows_terminal_resize`, moved
here from #4794, boots the picker at 120 columns, resizes to 200, and
checks that the separator follows.

What changes for users:

- **The startup pane is one column narrower.** skim builds its startup
viewport one column narrower than the terminal and splits that, so a
120-column terminal now splits 60 | 59 instead of 59 | 60. The text
width is now derived from that same geometry
([`dimensions_for`](https://github.com/max-sixty/worktrunk/blob/d3c1697663531d7fcf771197ccde26bc148f70b5/src/commands/picker/preview.rs#L276-L292)
runs ratatui's own `Percentage(50)` split on `term_width - 1`, minus the
border column). `preview()` turns skim's reported pane width into the
same text width with `PreviewLayout::text_width`. So precomputed and
on-demand renders share cache entries, and no line reaches the column
skim leaves unpainted. The four snapshot updates are this one-column
shift. The list gains a column, the preview loses one, and the controls
hint (not width-managed, by design) clips one character sooner.
- **The re-wrap lands on the next keystroke, not on the resize itself.**
skim 5.9's `Event::Resize` handler re-runs the preview before the next
render records the new pane width. So the first preview after a resize
still sees the old width, and the next keystroke brings the new one.
This was agreed as fine for now on #4794.
- **Summary and forge-fetched panes keep their startup wrapping.** A
Summary is stored raw and wrapped at display time. Comments, and a
`--prs` row's Log, are fetched once per session. All three key without a
width
([`preview_cache_key`](https://github.com/max-sixty/worktrunk/blob/d3c1697663531d7fcf771197ccde26bc148f70b5/src/commands/picker/items.rs#L156-L182)).
A resize therefore keeps showing their content rather than a loading
placeholder that nothing would refill. The `pr` pane is width-keyed, and
its invalidation now drops every width (`evict_preview`).

<details><summary>Where the one-column offset comes from</summary>

- `Tui::new_with_height` in skim 5.9's `src/tui/backend.rs` builds the
fixed (non-fullscreen) viewport as `backend.size().width - 1`.
- `LayoutTemplate` in `src/tui/layout.rs` splits it with `[Fill(1),
Percentage(p)]`. A ratatui probe gives the same areas for
`Percentage(50)` and `Length(W/2)`. The difference from the old geometry
comes from the 119-column viewport: `right:60` gives 59 | 60, while
`50%` gives 60 | 59.
- The preview's `cols` (reported as `PreviewContext::width`) is the pane
area including its left-border separator, so the text width is one less.
- After a resize, skim sizes the viewport to the full new width, which
is why the live width comes from skim rather than from startup
arithmetic.

</details>

Fixes #4793

---------

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants