mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-12 04:54:27 +00:00
drainStderr discarded all server stderr, so an LSP init failure (e.g. 'command not found', missing module) surfaced as an opaque 'initialization failed'. Retain a bounded tail (StderrCaptureMax=4096B, oldest dropped) under a mutex and attach it to the init-failure error context. Adds TestClientStderrCapture.
29 lines
842 B
Go
29 lines
842 B
Go
package lsp
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// drainStderr retains a bounded tail of server stderr for diagnostics; capture
|
|
// must keep recent bytes and never grow past StderrCaptureMax.
|
|
func TestClientStderrCapture(t *testing.T) {
|
|
c := &Client{}
|
|
|
|
if c.RecentStderr() != "" {
|
|
t.Errorf("expected empty stderr initially, got %q", c.RecentStderr())
|
|
}
|
|
|
|
c.captureStderr([]byte("gopls: command not found\n"))
|
|
if !strings.Contains(c.RecentStderr(), "command not found") {
|
|
t.Errorf("expected captured stderr, got %q", c.RecentStderr())
|
|
}
|
|
|
|
// Exceed the cap: only the most recent StderrCaptureMax bytes are kept.
|
|
big := strings.Repeat("x", StderrCaptureMax*2)
|
|
c.captureStderr([]byte(big))
|
|
if got := len(c.RecentStderr()); got > StderrCaptureMax {
|
|
t.Errorf("stderr tail not bounded: len=%d, want <= %d", got, StderrCaptureMax)
|
|
}
|
|
}
|