Skip to content

test(lsp): wait on observable conditions instead of fixed sleeps - #325

Merged
0x73746F66 merged 1 commit into
mainfrom
fix/221-lsp-condition-waits
Nov 13, 2026
Merged

0x73746F66 merged 1 commit into
mainfrom
fix/221-lsp-condition-waits

Conversation

@0x73746F66

Copy link
Copy Markdown
Member

Closes #221

What

  • internal/lsp/conformance_test.go
    • waitForWarm(t, c) polls vulnetix/serverInfo with require.Eventually until rulesEmbedded > 0. The warm-up stores the rules and the workspace index together, which is exactly when a didOpen is analysed. Was a fixed 3s sleep.
    • TestDocumentsOutsideTheWorkspaceAreNotScanned: after opening the outside file, opens a vulnerable file inside the workspace and waits for its diagnostics (waitForPublish), then asserts the outside file has none. Was a 500ms sleep, which could pass before a late publish arrived.
  • cmd/lsp_stdio_test.go (TestNoStdoutPollution)
    • stdout/stderr go through a mutex-guarded buffer so the test can read while the process writes.
    • After initialize/initialized it asks vulnetix/serverInfo until the rules are loaded (a document opened during warm-up is not analysed until its next change), then opens/changes/saves the document and waits for its publishDiagnostics, then waits for the shutdown response before exit. Was 6s + 300ms of sleeps. The final strict framing check over all of stdout is unchanged.

Reuses the package's existing waitForPublish, require.Eventually and parseFrames; no production change.

Not changed

TestWorkspaceScanCanBeCancelled keeps its 50ms pause before cancel(). The server emits nothing when a workspace scan starts, so there is no condition to wait on, and the assertion (a cancelled call returns an error) holds whichever side of the start the cancel lands. Adding a progress signal to the server just for this test is out of scope here.

Verified

  • go test -run 'TestDidOpenPublishesDiagnostics|TestClosingADocument|TestDocumentsOutsideTheWorkspace|TestWorkspaceScanCanBeCancelled' ./internal/lsp/: pass (outside-workspace test 0.6s, was >3.5s).
  • go test -run TestNoStdoutPollution ./cmd/: pass, 5 clean frames parsed.
  • go vet, gofmt clean.

@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@0x73746F66 0x73746F66 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reuse review: test-only. The condition waits (waitForMessage, waitForRules, waitForWarm) extend the existing lockedBuffer/testClient harness already used by the LSP stdio and conformance tests rather than adding a second harness; there is no shared polling helper in internal/testutils to reuse. No changes needed.

@0x73746F66 0x73746F66 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reuse review: no reinvented Vulnetix patterns found. The change stays inside the package it covers, uses stdlib/testify helpers already used by the repo's tests, and adds no new client, auth, config-schema or shared-package duplicate (checked internal/testutils and sibling repos). Rebased onto current main locally: go vet and go test pass for every touched package. The earlier red checks (CodeQL Analyze, Install a release with verified provenance, Lockfile) were GitHub API rate-limit failures, not code failures; this will be re-run on a rebased head before merge.

- waitForWarm polls vulnetix/serverInfo until the warm-up has loaded the
  rules (stored together with the workspace index) instead of sleeping 3s.
- The outside-workspace test opens an in-workspace file after the outside
  one and waits for its diagnostics as a barrier, instead of sleeping
  500ms and hoping a late publish would have arrived.
- TestNoStdoutPollution reads stdout through a locked buffer, waits for the
  rules before opening the document, then waits for its publishDiagnostics
  and for the shutdown response, instead of sleeping 6s and 300ms.

Closes #221
@0x73746F66
0x73746F66 force-pushed the fix/221-lsp-condition-waits branch from f63da9e to 97fca6c Compare November 13, 2026 10:42
@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@0x73746F66
0x73746F66 merged commit 9432d08 into main Nov 13, 2026
30 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace fixed warm-up sleeps in LSP tests with condition-based waits

1 participant