MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestCancelMidStreamPreservesStreamedText

Function TestCancelMidStreamPreservesStreamedText

internal/tui/tui_test.go:2516–2539  ·  view source on GitHub ↗

TestCancelMidStreamPreservesStreamedText: Ctrl+C while content is streaming keeps the partial response visible (flushed to scroll) and appends the cancelled marker. The user never loses context they've already read.

(t *testing.T)

Source from the content-addressed store, hash-verified

2514 }
2515 if om.streaming.String() != "hello world" {
2516 t.Fatalf("streaming buffer should contain raw content, got %q", om.streaming.String())
2517 }
2518 if om.scroll.Len() != 0 {
2519 t.Fatalf("scroll should still be empty before flush, got %q", om.scroll.String())
2520 }
2521 if !strings.Contains(om.View(), "hello world") {
2522 t.Fatalf("View must show live text during stream: %q", om.View())
2523 }
2524}
2525
2526// TestEventDoneFlushesStreamingThroughGlamour: EventDone moves raw streamed
2527// text into the committed scroll via the Markdown renderer and empties the
2528// streaming buffer. After Done, scroll contains the rendered block and the
2529// streaming buffer is empty.
2530func TestEventDoneFlushesStreamingThroughGlamour(t *testing.T) {
2531 m := newTestModel(t, func(http.ResponseWriter, *http.Request) {})
2532 m.phase = phaseStreaming
2533 m.streaming.WriteString("done message")
2534 out, _ := m.handleStream(llm.Event{Kind: llm.EventDone, Final: &chmctx.Message{Role: chmctx.RoleAssistant, Content: "done message"}})
2535 om := out.(Model)
2536 if om.streaming.Len() != 0 {
2537 t.Fatalf("streaming should be empty after Done, got %q", om.streaming.String())
2538 }
2539 if !strings.Contains(stripANSI(om.scroll.String()), "done message") {
2540 t.Fatalf("rendered content should be in scroll: %q", om.scroll.String())
2541 }
2542}

Callers

nothing calls this directly

Calls 5

newTestModelFunction · 0.85
stripANSIFunction · 0.85
StringMethod · 0.80
activeMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected