mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-09 18:08:31 -10:00
* fix(tui): strip all ANSI escapes from copied transcript text renderAssistantMarkdownText embeds bold markers for prose and ANSI color sequences from chroma for fenced code blocks. stripMarkdownRenderControls only stripped the bold markers, leaking ANSI codes into clipboard text. Switch to ansi.Strip() to remove all escape sequences. * refactor(tui): extract rendering dispatch and add detailed bool to transcriptBodyItems Extract rowRenderFn and transcriptRowDispatchFn types and refactor rendering methods into *Fn variants parameterized by the render function. Add detailed bool parameter to transcriptBodyItems to prepare for the detailed transcript viewport. All callers pass false so there is no behavior change yet. Extract transcriptRowBodyHeightCacheKeyOpts from transcriptRowBodyHeightCacheKey so the body cap can be configured per caller. * feat(tui): scrollable detailed transcript viewport with sidebar suppression Enable keyboard scrolling (PgUp/PgDown/Up/Down) in detailed transcript mode by routing through scrollChat instead of swallowing the keys. Rewrite detailedTranscriptView to use the transcriptBodyItems pipeline so the body renders through the same viewport/scroll engine as the live view. Implement detailedTranscriptFooter with copy-status and jump-to-bottom hint integration. Suppress the sidebar in detailed mode so the full chat width is available for reading uncapped tool output. * test(tui): detailed transcript scroll with PgUp/Down and Up/Down arrows TestPgUpDownScrollsDetailedTranscript verifies that PgUp scrolls toward older content and PgDown returns to the bottom in detailed mode. TestUpDownArrowsScrollDetailedTranscript verifies that arrow keys scroll one line at a time and bottom is clamped at offset 0. * test(tui): ANSI strip verification for markdown rendering controls and selectable text TestStripMarkdownRenderControlsStripsAllANSI verifies bold markers, color sequences, and combined sequences are stripped. TestSelectedTranscriptTextStripsANSIFromHighlightedCode verifies that chroma-highlighted code blocks produce clean plain text in the selectable layer. * fix for coderabit, and better fewer code. * fix(tui): address PR review feedback dead code, hover clear, and rebindable key label * format * addressing the review issue 1. the ctrl + b in detailed mode, added the guard to not be able to do it in detailed mode so it affect its state in the normal mode. 2. added a test coverage for keyDown after `keDown then keyUp` so it covers that. * fix(tui): close file drill-in when entering detailed transcript toggleDetailedTranscript now calls exitFileView before returning, so an active file drill-in is automatically closed when the user enters detailed transcript mode. * test(tui): verify file drill-in closes on detailed toggle Adds TestDetailedTranscriptClosesFileView and TestDetailedTranscriptStaysClosedOnSecondToggle to guard against the file-view bypass bug. * fix(tui): block composer hit-test while detailed transcript is active composerMouseSelectionBlocked and mouseOverComposer now check m.transcriptDetailed so mouse clicks and wheel events in the composer area reach the transcript body instead of being silently consumed. * test(tui): verify composer mouse is ignored in detailed mode Adds TestComposerMouseSelectionBlockedInDetailedMode to guard against composer hit-test swallowing mouse events during detailed transcript viewing.
206 lines
7.4 KiB
Go
206 lines
7.4 KiB
Go
package tui
|
|
|
|
import "testing"
|
|
|
|
func TestTranscriptBodyItemsRepresentEmptyState(t *testing.T) {
|
|
m := mouseTestModel()
|
|
width := m.chatColumnWidth()
|
|
|
|
items := m.transcriptBodyItems(width, "", false)
|
|
layout := layoutTranscriptBodyItems(items)
|
|
|
|
if len(layout.spans) != 1 || layout.spans[0].kind != transcriptBodyItemEmpty {
|
|
t.Fatalf("spans = %#v, want one empty-state item", layout.spans)
|
|
}
|
|
if layout.spans[0].height != len(layout.lines) || layout.spans[0].height == 0 {
|
|
t.Fatalf("empty-state span = %#v lines=%d, want positive span covering all lines", layout.spans[0], len(layout.lines))
|
|
}
|
|
if len(layout.selectable) != 0 {
|
|
t.Fatalf("empty state should not expose selectable transcript text: %#v", layout.selectable)
|
|
}
|
|
}
|
|
|
|
func TestTranscriptBodyItemsShiftSelectableLinesByItemStart(t *testing.T) {
|
|
m := mouseTestModel()
|
|
m.transcript = appendRow(m.transcript, rowUser, "hello")
|
|
width := m.chatColumnWidth()
|
|
|
|
layout := layoutTranscriptBodyItems(m.transcriptBodyItems(width, "", false))
|
|
|
|
if len(layout.spans) != 1 || layout.spans[0].kind != transcriptBodyItemRow {
|
|
t.Fatalf("spans = %#v, want one transcript row item", layout.spans)
|
|
}
|
|
rowSpan := layout.spans[0]
|
|
if rowSpan.height != 2 {
|
|
t.Fatalf("user row height = %d, want blank-delimiter + text", rowSpan.height)
|
|
}
|
|
if len(layout.selectable) != 1 {
|
|
t.Fatalf("selectable lines = %#v, want one user text line", layout.selectable)
|
|
}
|
|
if got, want := layout.selectable[0].bodyY, rowSpan.startY+1; got != want {
|
|
t.Fatalf("selectable bodyY = %d, want item start + user padding = %d", got, want)
|
|
}
|
|
if layout.selectable[0].rowIndex != len(m.transcript)-1 || layout.selectable[0].text != "hello" {
|
|
t.Fatalf("selectable line = %#v, want user row text", layout.selectable[0])
|
|
}
|
|
}
|
|
|
|
func TestTranscriptBodyItemsKeepPendingInterimSelectableLocal(t *testing.T) {
|
|
m := mouseTestModel()
|
|
m.pending = true
|
|
m.streamingReasoning = "private thought"
|
|
width := m.chatColumnWidth()
|
|
|
|
layout := layoutTranscriptBodyItems(m.transcriptBodyItems(width, "", false))
|
|
|
|
if len(layout.spans) != 2 {
|
|
t.Fatalf("spans = %#v, want separator plus pending interim", layout.spans)
|
|
}
|
|
if layout.spans[0].kind != transcriptBodyItemSeparator || layout.spans[0].height != 1 {
|
|
t.Fatalf("first span = %#v, want one-line separator", layout.spans[0])
|
|
}
|
|
pendingSpan := layout.spans[1]
|
|
if pendingSpan.kind != transcriptBodyItemPendingInterim || pendingSpan.height == 0 {
|
|
t.Fatalf("pending span = %#v, want rendered interim item", pendingSpan)
|
|
}
|
|
if len(layout.selectable) != 1 || !layout.selectable[0].live || !layout.selectable[0].toggle {
|
|
t.Fatalf("selectable lines = %#v, want live streaming reasoning toggle", layout.selectable)
|
|
}
|
|
if layout.selectable[0].bodyY != pendingSpan.startY {
|
|
t.Fatalf("streaming selectable bodyY = %d, want pending item start %d", layout.selectable[0].bodyY, pendingSpan.startY)
|
|
}
|
|
}
|
|
|
|
func TestTranscriptBodyLayoutVisibleLinesUsesViewportWindow(t *testing.T) {
|
|
layout := transcriptBodyLayout{lines: []string{"zero", "one", "two", "three"}}
|
|
window := newTranscriptViewport(layout.totalLines(), 2, 1).window()
|
|
|
|
got := layout.visibleLines(window)
|
|
if len(got) != 2 || got[0] != "one" || got[1] != "two" {
|
|
t.Fatalf("visible lines = %#v, want [one two]", got)
|
|
}
|
|
got[0] = "mutated"
|
|
if layout.lines[1] != "one" {
|
|
t.Fatalf("visibleLines should return a copy, layout lines = %#v", layout.lines)
|
|
}
|
|
}
|
|
|
|
func TestMeasureTranscriptBodyItemsUsesHeightCache(t *testing.T) {
|
|
cache := newTranscriptBodyHeightCache(8)
|
|
renders := 0
|
|
item := transcriptBodyItem{
|
|
kind: transcriptBodyItemRow,
|
|
rowIndex: 7,
|
|
heightCacheKey: "stable-row",
|
|
heightCacheStable: true,
|
|
render: func(int) transcriptBodyRenderedItem {
|
|
renders++
|
|
return transcriptBodyRenderedItem{lines: []string{"one", "two"}}
|
|
},
|
|
}
|
|
|
|
first := measureTranscriptBodyItems([]transcriptBodyItem{item}, cache)
|
|
second := measureTranscriptBodyItems([]transcriptBodyItem{item}, cache)
|
|
|
|
if renders != 1 {
|
|
t.Fatalf("renders = %d, want first measure only", renders)
|
|
}
|
|
if first.totalLines() != 2 || second.totalLines() != 2 {
|
|
t.Fatalf("total lines = %d/%d, want cached height 2", first.totalLines(), second.totalLines())
|
|
}
|
|
}
|
|
|
|
func TestVisibleTranscriptBodyLayoutRendersOnlyIntersectingItems(t *testing.T) {
|
|
cache := newTranscriptBodyHeightCache(8)
|
|
renders := [3]int{}
|
|
items := []transcriptBodyItem{
|
|
countingTranscriptBodyItem("a", []string{"a0", "a1"}, &renders[0]),
|
|
countingTranscriptBodyItem("b", []string{"b0", "b1"}, &renders[1]),
|
|
countingTranscriptBodyItem("c", []string{"c0", "c1"}, &renders[2]),
|
|
}
|
|
|
|
metrics := measureTranscriptBodyItems(items, cache)
|
|
window := transcriptViewportWindow{start: 2, end: 4, height: 2}
|
|
layout := layoutVisibleTranscriptBodyItems(items, metrics, window)
|
|
|
|
if got, want := renders, [3]int{1, 2, 1}; got != want {
|
|
t.Fatalf("renders after first visible layout = %#v, want %#v", got, want)
|
|
}
|
|
if len(layout.lines) != 2 || layout.lines[0] != "b0" || layout.lines[1] != "b1" {
|
|
t.Fatalf("visible lines = %#v, want b item only", layout.lines)
|
|
}
|
|
|
|
metrics = measureTranscriptBodyItems(items, cache)
|
|
_ = layoutVisibleTranscriptBodyItems(items, metrics, window)
|
|
|
|
if got, want := renders, [3]int{1, 3, 1}; got != want {
|
|
t.Fatalf("renders after cached measure = %#v, want only visible item rerendered %#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestVisibleTranscriptBodyLayoutKeepsSelectableBodyYAbsolute(t *testing.T) {
|
|
items := []transcriptBodyItem{
|
|
transcriptBlankBodyItem(),
|
|
{
|
|
kind: transcriptBodyItemRow,
|
|
rowIndex: 3,
|
|
heightCacheKey: "selectable-row",
|
|
heightCacheStable: true,
|
|
render: func(startBodyY int) transcriptBodyRenderedItem {
|
|
return transcriptBodyRenderedItem{
|
|
lines: []string{"top", "hit", "bottom"},
|
|
selectable: []transcriptSelectableLine{{
|
|
bodyY: startBodyY + 1,
|
|
rowIndex: 3,
|
|
text: "hit",
|
|
}},
|
|
}
|
|
},
|
|
},
|
|
}
|
|
metrics := measureTranscriptBodyItems(items, newTranscriptBodyHeightCache(8))
|
|
window := transcriptViewportWindow{start: 2, end: 3, height: 1}
|
|
|
|
layout := layoutVisibleTranscriptBodyItems(items, metrics, window)
|
|
|
|
if len(layout.lines) != 1 || layout.lines[0] != "hit" {
|
|
t.Fatalf("visible lines = %#v, want selected item line", layout.lines)
|
|
}
|
|
if len(layout.selectable) != 1 || layout.selectable[0].bodyY != 2 {
|
|
t.Fatalf("selectable = %#v, want absolute bodyY 2", layout.selectable)
|
|
}
|
|
}
|
|
|
|
func TestScrollableTranscriptItemsViewMatchesFullLayout(t *testing.T) {
|
|
m := mouseTestModel()
|
|
m.height = 14
|
|
m.chatScrollOffset = 2
|
|
m.transcript = appendRow(m.transcript, rowUser, "please inspect this request")
|
|
m.transcript = appendRow(m.transcript, rowAssistant, "first response line\nsecond response line\nthird response line")
|
|
m.transcript = appendRow(m.transcript, rowUser, "follow up")
|
|
width := m.chatColumnWidth()
|
|
header := m.pinnedTitleBar(width)
|
|
footer := m.footerView(width)
|
|
items := m.transcriptBodyItems(width, "", false)
|
|
full := layoutTranscriptBodyItems(items)
|
|
|
|
got := m.scrollableTranscriptItemsView(header, items, footer, width, "")
|
|
want := m.scrollableTranscriptLayoutView(header, full, footer, width, "")
|
|
|
|
if got != want {
|
|
t.Fatalf("visible item view changed output\nwant:\n%s\n\ngot:\n%s", want, got)
|
|
}
|
|
}
|
|
|
|
func countingTranscriptBodyItem(key string, lines []string, renders *int) transcriptBodyItem {
|
|
return transcriptBodyItem{
|
|
kind: transcriptBodyItemRow,
|
|
heightCacheKey: key,
|
|
heightCacheStable: true,
|
|
render: func(int) transcriptBodyRenderedItem {
|
|
(*renders)++
|
|
return transcriptBodyRenderedItem{lines: append([]string(nil), lines...)}
|
|
},
|
|
}
|
|
}
|