diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 04:33:36 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 04:33:36 +0200 |
| commit | 95b0a9962861b2aef4a3e9538dd38608aca4bcfc (patch) | |
| tree | 534a8c0f2bff31e612a9b12ff4d911bbead61c0c /internal/lsp/chat_context_mode_test.go | |
| parent | f55a1e88ea5948582d0e5a33efea0c5d806e1f4b (diff) | |
Document lock ordering, fix test data races, correct stateMu guard
- Add doc comments clarifying Server.mu and completionState.stateMu are
independent (no ordering constraint).
- Fix test using wrong lock (s.mu instead of stateMu) for lastLLMCall.
- Replace time.Sleep polling in 7 tests with s.inflight.Wait() to
eliminate data races under -race.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/lsp/chat_context_mode_test.go')
| -rw-r--r-- | internal/lsp/chat_context_mode_test.go | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/internal/lsp/chat_context_mode_test.go b/internal/lsp/chat_context_mode_test.go index 895c2f3..876f092 100644 --- a/internal/lsp/chat_context_mode_test.go +++ b/internal/lsp/chat_context_mode_test.go @@ -4,7 +4,6 @@ import ( "bytes" "strings" "testing" - "time" ) // Ensure in-editor chat respects general.context_mode by adding window/full-file context. @@ -25,10 +24,7 @@ func TestChat_RespectsContextModeWindow(t *testing.T) { s.setDocument(uri, src) s.detectAndHandleChat(uri) - // Wait briefly for async goroutine to call Chat - for i := 0; i < 40 && len(cap.msgs) == 0; i++ { - time.Sleep(10 * time.Millisecond) - } + s.inflight.Wait() if len(cap.msgs) == 0 { t.Fatalf("expected Chat to be called") } @@ -64,10 +60,8 @@ func TestChat_ContextModeMinimal_NoExtra(t *testing.T) { uri := "file:///ctx2.go" s.setDocument(uri, "package main\nhelp?>\n") s.detectAndHandleChat(uri) + s.inflight.Wait() - for i := 0; i < 40 && len(cap.msgs) == 0; i++ { - time.Sleep(10 * time.Millisecond) - } if len(cap.msgs) != 2 { t.Fatalf("expected exactly 2 messages (system + user prompt), got %d", len(cap.msgs)) } @@ -88,10 +82,8 @@ func TestChat_ContextModeAlwaysFull_AddsExtra(t *testing.T) { uri := "file:///ctx3.go" s.setDocument(uri, "package main\nline2\nhelp?>\n") s.detectAndHandleChat(uri) + s.inflight.Wait() - for i := 0; i < 40 && len(cap.msgs) == 0; i++ { - time.Sleep(10 * time.Millisecond) - } if len(cap.msgs) < 3 { t.Fatalf("expected >=3 messages (system, extra, user prompt), got %d", len(cap.msgs)) } @@ -118,10 +110,8 @@ func TestChat_ContextModeFileOnNewFunc_NoExtraWithoutSignature(t *testing.T) { uri := "file:///ctx4.go" s.setDocument(uri, "package main\nhelp?>\n") s.detectAndHandleChat(uri) + s.inflight.Wait() - for i := 0; i < 40 && len(cap.msgs) == 0; i++ { - time.Sleep(10 * time.Millisecond) - } if len(cap.msgs) != 2 { t.Fatalf("expected exactly 2 messages (system + user prompt), got %d", len(cap.msgs)) } @@ -141,10 +131,8 @@ func TestChat_ContextModeFileOnNewFunc_WithSignature_AddsExtra(t *testing.T) { src := "package main\n\nfunc add(x int) int\nhelp?>\n" s.setDocument(uri, src) s.detectAndHandleChat(uri) + s.inflight.Wait() - for i := 0; i < 40 && len(cap.msgs) == 0; i++ { - time.Sleep(10 * time.Millisecond) - } if len(cap.msgs) < 3 { t.Fatalf("expected >=3 messages (system, extra, user prompt), got %d", len(cap.msgs)) } |
